Merge "Add missing return value"
[lhc/web/wiklou.git] / includes / specials / SpecialRandomInCategory.php
index 2e4bf20..14123a8 100644 (file)
@@ -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;
                        }