Check for Language::getSpecialPageAliases returning null in SpecialPageFactory
authorAlexia E. Smith <washuu@gmail.com>
Tue, 16 Apr 2013 20:55:55 +0000 (15:55 -0500)
committerKrinkle <krinklemail@gmail.com>
Wed, 7 May 2014 18:54:23 +0000 (18:54 +0000)
Language::getSpecialPageAliases can return null causing certain
methods within SpecialPageFactory that rely on it to raise
PHP warnings due to trying to foreach over a non-array.

This change will prevent the PHP warning from being raised and
allow those functions' error handling to occur normally.

Change-Id: I2026c25f12798f699ebc306b12173226270fce2e

includes/specialpage/SpecialPageFactory.php

index 2305f21..7304b6d 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;
@@ -567,13 +570,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 ) {