Make the deprecation notice actually useful by listing the class
[lhc/web/wiklou.git] / includes / specialpage / SpecialPageFactory.php
index 2305f21..f5e4f0e 100644 (file)
@@ -243,11 +243,14 @@ class SpecialPageFactory {
                        $missingPages = clone self::getList();
 
                        self::$aliases = array();
-                       foreach ( $aliases as $realName => $aliasList ) {
-                               foreach ( $aliasList as $alias ) {
-                                       self::$aliases[$wgContLang->caseFold( $alias )] = $realName;
+                       // Check for $aliases being an array since Language::getSpecialPageAliases can return null
+                       if ( is_array( $aliases ) ) {
+                               foreach ( $aliases as $realName => $aliasList ) {
+                                       foreach ( $aliasList as $alias ) {
+                                               self::$aliases[$wgContLang->caseFold( $alias )] = $realName;
+                                       }
+                                       unset( $missingPages->$realName );
                                }
-                               unset( $missingPages->$realName );
                        }
                        foreach ( $missingPages as $name => $stuff ) {
                                self::$aliases[$wgContLang->caseFold( $name )] = $name;
@@ -344,10 +347,10 @@ class SpecialPageFactory {
 
                                return new $className;
                        } elseif ( is_array( $rec ) ) {
-                               // @deprecated, officially since 1.18, unofficially since forever
-                               wfDebug( "Array syntax for \$wgSpecialPages is deprecated, " .
-                                       "define a subclass of SpecialPage instead." );
                                $className = array_shift( $rec );
+                               // @deprecated, officially since 1.18, unofficially since forever
+                               wfDeprecated( "Array syntax for \$wgSpecialPages is deprecated ($className), " .
+                                       "define a subclass of SpecialPage instead.", '1.18' );
                                self::getList()->$realName = MWFunction::newObj( $className, $rec );
                        }
 
@@ -407,17 +410,21 @@ class SpecialPageFactory {
         * Return categorised listable special pages which are available
         * for the current user, but not for everyone
         *
+        * @param User|null $user User object to use or null for $wgUser
         * @return array ( string => Specialpage )
         */
-       public static function getRestrictedPages() {
-               global $wgUser;
+       public static function getRestrictedPages( User $user = null ) {
                $pages = array();
+               if ( $user === null ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
                foreach ( self::getList() as $name => $rec ) {
                        $page = self::getPage( $name );
                        if (
                                $page->isListed()
                                && $page->isRestricted()
-                               && $page->userCanExecute( $wgUser )
+                               && $page->userCanExecute( $user )
                        ) {
                                $pages[$name] = $page;
                        }
@@ -567,13 +574,16 @@ class SpecialPageFactory {
                } else {
                        // Try harder in case someone misspelled the correct casing
                        $found = false;
-                       foreach ( $aliases as $n => $values ) {
-                               if ( strcasecmp( $name, $n ) === 0 ) {
-                                       wfWarn( "Found alias defined for $n when searching for " .
-                                               "special page aliases for $name. Case mismatch?" );
-                                       $name = $values[0];
-                                       $found = true;
-                                       break;
+                       // Check for $aliases being an array since Language::getSpecialPageAliases can return null
+                       if ( is_array( $aliases ) ) {
+                               foreach ( $aliases as $n => $values ) {
+                                       if ( strcasecmp( $name, $n ) === 0 ) {
+                                               wfWarn( "Found alias defined for $n when searching for " .
+                                                       "special page aliases for $name. Case mismatch?" );
+                                               $name = $values[0];
+                                               $found = true;
+                                               break;
+                                       }
                                }
                        }
                        if ( !$found ) {