X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialRandomInCategory.php;h=14123a8be3e9a8bb57f339a853fa65354d2644e1;hb=b95a775c9855f7b7d781240e1062cc014957d703;hp=2e4bf2009f0c2956a625036abb99e7296c32992e;hpb=9ff819b8b7764101367432c9f9419b893aee97aa;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialRandomInCategory.php b/includes/specials/SpecialRandomInCategory.php index 2e4bf2009f..14123a8be3 100644 --- a/includes/specials/SpecialRandomInCategory.php +++ b/includes/specials/SpecialRandomInCategory.php @@ -68,6 +68,8 @@ class SpecialRandomInCategory extends SpecialPage { } public function execute( $par ) { + global $wgScript; + $cat = false; $categoryStr = $this->getRequest()->getText( 'category', $par ); @@ -76,11 +78,15 @@ class SpecialRandomInCategory extends SpecialPage { $cat = Title::newFromText( $categoryStr, NS_CATEGORY ); } + if ( $cat && $cat->getNamespace() !== NS_CATEGORY ) { + // Someone searching for something like "Wikipedia:Foo" + $cat = Title::makeTitleSafe( NS_CATEGORY, $categoryStr ); + } + if ( $cat ) { $this->setCategory( $cat ); } - if ( !$this->category && $categoryStr ) { $this->setHeaders(); $this->getOutput()->addWikiMsg( 'randomincategory-invalidcategory', @@ -94,7 +100,8 @@ class SpecialRandomInCategory extends SpecialPage { $submit = Html::input( '', $submitText, 'submit' ); $msg = $this->msg( 'randomincategory-selectcategory' ); - $form = Html::rawElement( 'form', array( 'action' => $this->getTitle()->getLocalUrl() ), + $form = Html::rawElement( 'form', array( 'action' => $wgScript ), + Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . $msg->rawParams( $input, $submit )->parse() ); $this->getOutput()->addHtml( $form ); @@ -124,7 +131,7 @@ class SpecialRandomInCategory extends SpecialPage { */ public function getRandomTitle() { // Convert to float, since we do math with the random number. - $rand = (float) wfRandom(); + $rand = (float)wfRandom(); $title = null; // Given that timestamps are rather unevenly distributed, we also @@ -215,7 +222,7 @@ class SpecialRandomInCategory extends SpecialPage { if ( !$this->minTimestamp || !$this->maxTimestamp ) { try { list( $this->minTimestamp, $this->maxTimestamp ) = $this->getMinAndMaxForCat( $this->category ); - } catch( MWException $e ) { + } catch ( MWException $e ) { // Possibly no entries in category. return false; }