User:Locke Cole/Rand/Rand.php
Appearance
<?php if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is a MediaWiki extension, it is not a valid entry point' ); } /**#@+ * An extension that allows random numbers to be generated in articles. * * @package MediaWiki * @subpackage Extensions * * @link http://meta.wikimedia.org/wiki/Rand/Rand.php Documentation * * @author Locke Cole <locke.cole.wiki@gmail.com> * @copyright Copyright 2006, Locke Cole * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later */ $wgExtensionFunctions[] = 'wfSetupRand'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'Rand', 'version' => '0.9.1', 'author' => 'Locke Cole', 'description' => 'adds {{rand:min|max}} function', 'url' => 'http://meta.wikimedia.org/wiki/User:Locke_Cole/Rand/Rand.php' ); class ExtRand { function randHook( &$parser, $min = '0', $max = '0' ) { $parser->disableCache(); return mt_rand( intval( $min ), intval( $max ) ); } } function wfSetupRand() { global $wgParser, $wgExtRand; $wgExtRand = new ExtRand; $wgParser->setFunctionHook( 'rand', array( &$wgExtRand, 'randHook' ) ); } ?>