Lea Linux:Listsubpages
Description
Cette extension ListSubPages, permet d'afficher pour la page sur laquelle elle est utilisée, la liste de toutes les sous pages de celle-ci.
Syntaxe : <listsubpages [paramètres]>[entête]</listsubpages>
Où :
- [paramètres] est une combinaison de :
showns
: affiche les espaces de nom avec le nom des pages,error='...'
: si aucune sous page n'est trouvée, affiche le message d'erreur spécifié au lieu de celui par défaut, préciser : '' comme message d'erreur pour le désactiver,orderby=name|date
: affiche les sous pages triées par nom (name) ou par date d'édition (date),ordermode=asc|desc
: siorderby
est spécifié et valide,ordermode
précise s'il faut utiliser l'ordre croissant (asc) ou décroissant (desc),max=...
: indique le nombre maximum d'entrées à afficher,
- [entête] est un message annonçant les différentes sous pages. Dans cette chaine, l'utilisation de %1 affiche le nombre d'entrées.
Code
<?
- This code is copyright (C) by Juho Ville Heikkurinen (2005) and is licensed under the
- terms of the GNU General Public License, version 2
- (see http://www.fsf.org/licenses/gpl.html). Derivative works and later versions of
- the code will also be considered free software licensed under the same terms.
- version 0.1.3 Fixed an problem for mediawiki installation using db-prefix
- This version uses the $input parameter to I18N the "This page has xxxx subpages"
- This version uses "error" parameter to I18N/customize the error message
- Setting "real" path of mediawiki isn't needed any more
- This version uses "orderby" parameter to order by 'date' or 'name'
- This version uses "ordermode" parameter to order 'asc' or 'desc'
- This version uses "max" parameter to limit the shown entries
- This version uses "showns" parameter to enable showing the namespace of shown pages
- (code from fred@lea-linux.org)
- version 0.1.2 Fixed a bug that caused the program to always say that there are no subpages
- version 0.1.1 outputs "This page doesn't have any sub-pages" if there are none
- version 0.1 Lists all sub-pages if there are any. If there are none it outputs nothing.
- NOTE: you must change $wikipath to reflect your installation.
- for example for Wikipedia you would use
- $wikipath = "../wiki/"
- Known bugs:
- 'order by page_title' gives capital B before lowercase A
- TODO (or actually just ideas):
- 1) Enable the use of regular expressions to limit subpages to be viewed
$wgExtensionFunctions[] = "wfListSubPages";
function wfListSubPages ()
{
global $wgParser ;
global $wgTitle;
$wgParser->setHook ( "ListSubPages" , parse_subs );
}
- First extension written from scratch
function parse_subs ($input, $argv)
{
global $wgTitle;
global $wgContLang;
$dbr =& wfGetDB( DB_MASTER ); #Get a REFERENCE to a database connection (I suppose)
$output =""; #initialise output variable
$title = $wgTitle->getDBkey(); #get the pagename (without namespace)
$ns = $wgTitle->getNamespace(); # get the namespace as a number
if (($argv['ordermode'] == 'asc') || ($argv['ordermode'] == 'desc')) {
$ordertype = $argv['ordermode'] ;
} else {
$ordertype = ;
}
if ($argv['orderby'] == 'name') {
$order = 'ORDER BY page_title '.$ordertype ;
} elseif ($argv['orderby'] == 'date') {
$order = 'ORDER BY page_touched '.$ordertype ;
} else {
$order = ;
}
if ($argv['max']) {
$limit = ' LIMIT '.(int)$argv['max'] ;
} else {
$limit = ;
}
$sql = "SELECT page_title FROM ".$dbr->tableName( 'page' )." where page_namespace='". $ns ."' and page_title LIKE '". $title."/%' ".$order.$limit;
$res = $dbr->query( $sql);
$rowCount = $dbr->numRows($res);
if ($rowCount == 0) {
if ($argv["error"])
return $argv["error"] ;
else
return "This page doesn't have any sub-pages";
}
else {
$output = str_replace("%1", $rowCount, $input);
$output .= "
";
# Make sure $ns is definitely a number and $title is encoded with wfStrencode()
# (above comment by TimStarling) I suppose that $wgTitle->getDBkey(); gives the title encoded.
$namespace = ($argv['showns']?$wgContLang->getNsText($ns).':':) ;
while ( $myrow = $dbr->fetchRow( $res ) ) {
$title = Title::newFromText($myrow[0], $ns ) ;
if (is_object($title)) // may be useless but, just in case ...
$output .= '- <a href="' .$title->escapeLocalURL() . '">'.
$namespace.$myrow[0] . "</a>
\n";
}
$output .= "
";
}
if ($argv['nocache']) {
# Do not cache this wiki page.
# for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions
global $wgTitle, $wgDBprefix;
global $wgVersion;
$ts = mktime();
$now = gmdate("YmdHis", $ts + 120);
$ns = $wgTitle->getNamespace();
$ti = wfStrencode($wgTitle->getDBkey());
$version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion);
if ($version>14) $sql = "UPDATE $wgDBprefix"."page SET page_touched='$now' WHERE page_namespace=$ns AND page_title='$ti'";
else $sql = "UPDATE $wgDBprefix"."cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'";
wfQuery($sql, DB_WRITE, "");
}
return $output;
}
?>
Code original
Cette extension est directement dérivée de celle écrite par : Juxo disponible ici