Author: wmf.amgine3691
Description:
An extension to sort articles for the most recent n articles which are in
category x [AND category y [AND category z]].
The extension is vital to automate the main page of Wikinews, to allow
contributors to concentrate on producing articles rather than maintaining a very
rapidly aging news list. It can allow the most current versions of articles to
appear while they are news. Additional applications exist for Wikipedias.
This version has been tested on small-scale installations of mediawiki, 1.4b3
and 1.4b5.
Source:
<pre>
<?php
/*
Contributors: n:User:Amgine, n:User:IlyaHaykinson
To install: add following to LocalSettings.php
include("extensions/dynamicpagelist.php");
*/
$wgExtensionFunctions[] = "wfDynamicPageList";
function wfDynamicPageList() {
global $wgParser; $wgParser->setHook( "DynamicPageList", "DynamicPageList" );
}
The callback function for converting the input text to HTML output
function DynamicPageList( $input ) {
global $wgScriptPath, $wgServer, $wgUser; $aParams = array(); $sTok = strtok($input, "\n"); while ($sTok) { $aParams[] = $sTok; $sTok = strtok("\n"); } foreach($aParams as $sParam) { $aParam = explode("=", $sParam); $sType = $aParam[0]; $sArg = $aParam[1]; if ($sType == 'category') { $sCatName = preg_replace('/[\\\\_\\s]/S','_',$sArg); $sCatName = str_replace('\'','\\\'',$sCatName); $aCategories[] = $sCatName; } else if ('count' == $sType) { $iCount = (1 * $sArg); } } $iCatCount = count($aCategories); if ($iCatCount < 1) return "!!too few categories!!"; if ($iCatCount > 3) return "!!too many categories!!"; if ($iCount < 1) $iCount = 1; if ($iCount > 50) $iCount = 50; $sSql = 'SELECT cur_namespace, cur_title FROM cur'; for ($i = 0; $i < $iCatCount; $i++) { $sSql .= ', categorylinks AS c' . ($i+1); } $sSql .= ' WHERE 1=1 '; for ($i = 0; $i < $iCatCount; $i++) { if ($i > 0) $sSql .= ' AND c1.cl_from = c'.($i+1).'.cl_from'; $sSql .= ' AND c'.($i+1).'.cl_to = \''.$aCategories[$i].'\''; } $sSql .= ' AND cur_id = c1.cl_from ORDER BY cur_timestamp DESC LIMIT 0,' .
$iCount;
//$output .= $sSql . "<br />"; # process the query $res = wfQuery($sSql, DB_READ); $sk =& $wgUser->getSkin(); $output .= "<ul>\n"; # process results of query while ($row = wfFetchObject( $res ) ) { $title = Title::makeTitle( $row->cur_namespace, $row->cur_title); $output .= '<li>' . $sk->makeLinkObj($title) . '</li>' . "\n"; } $output .= "</ul>\n"; return $output;
}
?>
</pre>
Version: unspecified
Severity: enhancement
URL: http://www.ilya.us/wiki/index.php?title=DynamicPageList_extension