X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialRandompage.php;h=9f7ef6690e03846a01a7fba4e31da31b7367d9fc;hb=6b758fc982972ee60856af0b766383f3aae97f65;hp=086193e14aeaba66ab5a3b9ccde9ef8f0bb37c0a;hpb=a3f615aa25c145cf98573574de2e258174c0c31d;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialRandompage.php b/includes/specials/SpecialRandompage.php index 086193e14a..9f7ef6690e 100644 --- a/includes/specials/SpecialRandompage.php +++ b/includes/specials/SpecialRandompage.php @@ -56,7 +56,9 @@ class RandomPage extends SpecialPage { public function execute( $par ) { global $wgContLang; - if ( $par ) { + if ( is_string( $par ) ) { + // Testing for stringiness since we want to catch + // the empty string to mean main namespace only. $this->setNamespace( $wgContLang->getNsIndex( $par ) ); } @@ -80,7 +82,7 @@ class RandomPage extends SpecialPage { /** * Get a comma-delimited list of namespaces we don't have * any pages in - * @return String + * @return string */ private function getNsList() { global $wgContLang; @@ -98,13 +100,13 @@ class RandomPage extends SpecialPage { /** * Choose a random title. - * @return Title object (or null if nothing to choose from) + * @return Title|null Title object (or null if nothing to choose from) */ public function getRandomTitle() { $randstr = wfRandom(); $title = null; - if ( !wfRunHooks( + if ( !Hooks::run( 'SpecialRandomGetRandomTitle', array( &$randstr, &$this->isRedir, &$this->namespaces, &$this->extra, &$title ) ) ) { @@ -133,20 +135,26 @@ class RandomPage extends SpecialPage { protected function getQueryInfo( $randstr ) { $redirect = $this->isRedirect() ? 1 : 0; + $tables = array( 'page' ); + $conds = array_merge( array( + 'page_namespace' => $this->namespaces, + 'page_is_redirect' => $redirect, + 'page_random >= ' . $randstr + ), $this->extra ); + $joinConds = array(); + + // Allow extensions to modify the query + Hooks::run( 'RandomPageQuery', array( &$tables, &$conds, &$joinConds ) ); return array( - 'tables' => array( 'page' ), + 'tables' => $tables, 'fields' => array( 'page_title', 'page_namespace' ), - 'conds' => array_merge( array( - 'page_namespace' => $this->namespaces, - 'page_is_redirect' => $redirect, - 'page_random >= ' . $randstr - ), $this->extra ), + 'conds' => $conds, 'options' => array( 'ORDER BY' => 'page_random', 'LIMIT' => 1, ), - 'join_conds' => array() + 'join_conds' => $joinConds ); }