Pour faire ce handler, j'ai repris le code de l'action backlinks, et je me suis inspiré du handler refferers, dont la philosophie est à peu pres la même...
Dans un fichier backlinks.php (dans le repertoire wikini/handlers/page/), écrire :
<?php
/*
backlinks.php
Copyright 2002 Patrick PAUL
Copyright 2003 David DELON
Copyright 2003 Eric FELDSTEIN
Copyright 2003 Jean-Pascal MILCENT
Copyright 2003 Charles NEPOTE
Copyright 2004 Emmanuel Coirier
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
echo '<div class="page">';
if ($global = $_REQUEST['global'])
{
$title = 'Pages faisant référence à '.$this->getPageTag().' :';
}
else
{
$title = 'Pages internes faisant référence à '.$this->ComposeLinkToPage($this->GetPageTag()).' :';
//$referrers = $this->LoadReferrers($this->GetPageTag());
}
echo "<b>$title</b><br /><br />\n";
if ($pages = $this->LoadPagesLinkingTo($this->getPageTag()))
{
foreach ($pages as $page)
{
echo $this->ComposeLinkToPage($page['tag']),"<br />\n";
}
}
else
{
echo '<i>Aucune page n'a de lien vers ',$this->ComposeLinkToPage($this->getPageTag()),'.</i>';
}
echo '</div>';
?>
On peut également modifier le fichire footer.php (wikini/actions/) en rajoutant l'élement suivant :
<a href="<?php echo $this->href('backlinks') ?>" title="Cliquez pour voir les pages internes faisant référence à cette page.">Rétro-liens</a>
Pour faire appel directement à cette fonction, il suffit de faire suivre l'url de /backlinks (comme cela se fait pour edit, par exemple).
Ces modifications s'adressent à la version stable. Pour la version CVS, il faut rajouter les entêtes/pieds de page ainsi que la vérification de la sécurité.
Il serait peut-être bien de préciser pour ceux qui souhaite intégrer cette contrib :
Voici donc le code complet :
<?php
/*
backlinks.php
Copyright 2002 Patrick PAUL
Copyright 2003 David DELON
Copyright 2003 Eric FELDSTEIN
Copyright 2003 Jean-Pascal MILCENT
Copyright 2003 Charles NEPOTE
Copyright 2004 Emmanuel Coirier
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
if (!defined('WIKINI_VERSION')) {
die ('accès direct interdit');
}
echo $this->Header();
echo '<div class="page">';
if ($global = $_REQUEST['global'])
{
$title = 'Pages faisant référence à '.$this->getPageTag().' :';
}
else
{
$title = 'Pages internes faisant référence à '.$this->ComposeLinkToPage($this->GetPageTag()).' :';
//$referrers = $this->LoadReferrers($this->GetPageTag());
}
echo "<b>$title</b><br /><br />\n";
if ($pages = $this->LoadPagesLinkingTo($this->getPageTag()))
{
foreach ($pages as $page)
{
echo $this->ComposeLinkToPage($page['tag']),"<br />\n";
}
}
else
{
echo '<i>Aucune page n'a de lien vers ',$this->ComposeLinkToPage($this->getPageTag()),'.</i>';
}
echo '</div>';
echo $this->Footer();
?>
A part ca, cette contrib fonctionne très très bien ;-)
--
ThierryBazzanella
Je propose le code suivant, beaucoup plus simple...:
<?php
/*
backlinks.php : handler permettant d'obtenir tous les retro-liens d'un page de WikiNi
Copyright 2004 Didier Loiseau
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if(!defined('WIKINI_VERSION')){
die ('accès direct interdit');
}
echo $this->Header();
echo "<div class=\"page\" style="padding: 1em">\n";
echo $this->Action('backlinks page="' . $this->GetPageTag() . '"');
echo "\n</div>\n";
echo $this->Footer();
?>
NB.:
- ça marche même si la page n'existe pas, et ça a l'avantage de suivre automatiquement les évolutions de l'ActionBacklinks.
- je sais que l'argument "page" est facultatif, surtout dans le cas présent, mais cela permet de placer facilement un lien de "retour" vers la page en question. (d'un autre côté cela utilise une PCRE plus complexe...)
demo:
http://www.notredomaine.org/LordFarquaad/backlinks
telechargement:
http://contributions-wikini.notredomaine.org/HandlerBacklinks-v.0.1.0-20041219.zip
Je vois au moins deux applications importantes au
HandlerBacklinks:
- Pour supprimer une page, cela permet de consulter facilement les rétroliens si la page n'est pas orpheline
- Pour les PagesACreer, on pourrait ajouter un lien vers le HandlerBackLinks sur le nombre de rétrolien, de sorte qu'on trouve facilement où ont été placés les liens vers cette page inexistantes
Je pense qu'il serait bon de l'intégrer dans la prochaine version de
WikiNi, et de modificer le message d'erreur lors d'une tentative de suppression de page non-orpheline ainsi que l'
ActionWantedPages.
- En plus j'ai mis mon code sous GPL lol :p
--
LordFarquaad
- J'aimerais intégrer la version que je propose ici dans le cvs, même si elle pourrait s'améliorer avec ce que je propose pour la MethodeAction (il suffirait de corriger plus tard). Ainsi je pourrais modifier l'ActionWantedPages et le message d'erreur du HandlerDeletepage? comme je l'ai proposé plus haut (et j'en profiterai pour virer ce foreach qui ne sert strictement à rien si ce n'est exécuter plusieurs fois les requêtes de suppression quand on a trouvé deux versions de la même page dont le nom ne diffère que par la casse, ce qui est d'ailleurs normalement impossible...) -- LordFarquaad [Ok en ce qui me concerne. Au passage, c'est pourquoi faire le hr_clear ? -- ProgFou]
- Euh... bonne question... ben en fait c'est hérité d'un copier-coller venant du HandlerEdit?... mais même là je ne sais pas quelle est son utilité... A part peut-être faire un blanc en bas de page ? Dans le cas présent ce serait mieux de le faire tout autour, je modifie ici. -- LordFarquaad