Make RandomInCat work for cats starting with namespace
authorBrian Wolff <bawolff+wn@gmail.com>
Fri, 23 Aug 2013 20:02:49 +0000 (13:02 -0700)
committerBrian Wolff <bawolff+wn@gmail.com>
Fri, 23 Aug 2013 20:02:49 +0000 (13:02 -0700)
So if someone has Category:User:Foo, they can go to
both Special:RandomInCategory/Category:User:Foo, or
just Special:RandomInCategory/User:Foo.

Bug: 53239
Change-Id: I2e67f0463b725ce297eeb5a5de73ccbad826907a

includes/specials/SpecialRandomInCategory.php

index 2e4bf20..fd554e6 100644 (file)
@@ -76,6 +76,11 @@ 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 );
                }