Extension:RandomPages

The Random Pages extension returns one or more randomly selected pages. The original version 0.2 doesn't work with MediaWiki 1.25+ (Original URL: http://locknet.ro/).

Usage
RandomPages adds a new MediaWiki wiki parser tag: &lt;randompages /&gt;


 * Available options
 * limit int, to control how many links should be fetched randomly from the database, defaults to 150
 * namespace bool, true to restrict only to the global namspace, defaults to false
 * levels int, levels of CSS applyed to each entry, defaluts to 5

&lt;randompages limit="10" namespace="true" levels="10" /&gt;

Gets 10 random pages from the global namespace with 10 levels of style

Code
* * Gets 10 random pages from the global namespace with 10 levels of style * * @param $text string, it should be null * @param $params array, additional parameters passed as attributes to randompages tag * @param $parser Parser, the Wiki Parser Object */ function aoRandomPagesHook($text, $params, $parser) { global $wgDBprefix; // prevent caching for this wiki page $parser->disableCache; // get parameters $limit = isset($params['limit']) ? (int)$params['limit'] : 150; $namespaced = isset($params['namespace']) ? $params['namespace'] == 'true' : false; $levels = isset($params['levels']) ? (int)$params['levels'] : 5; // build sql query $sql = sprintf('select * from %spage where', $wgDBprefix); $sql .= $namespaced ? ' page_namespace = 0 ' : ' 1=1 '; $sql .= sprintf('order by rand limit %d', $limit); // execute that. $dbr = wfGetDB( DB_SLAVE ); $rs = $dbr->query( $sql ); $buff = ' '; while( $row = $rs->fetchObject( $rs ) ) { $buff .= ''; #KKM commnet out as it is now working. https://www.mediawiki.org/wiki/Extension_talk:SearchBox $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); // manually call __toString for php < 5.2 $buff .= sprintf('%s', $title->getLocalURL, $title->__toString, $title->__toString); #$buff .= sprintf('%s', $title->escapeLocalURL, $title->__toString, $title->__toString); $buff .= ' '; } return $buff. ' '; }
 * RandomPages.php