Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -70,29 +70,19 @@ |
71 | 71 | if ( count( $this->mTokens ) > 0 ) { |
72 | 72 | $globals = array ( |
73 | 73 | '$wgArticle', # Setup.php |
74 | | - '$wgAutoloadLocalClasses', # AutoLoader.php, a couple of readers |
75 | | - '$wgBlobCache', # HistoryBlob.php |
76 | | - '$wgCaches', # ObjectCache.php |
| 74 | + '$wgAutoloadLocalClasses', # AutoLoader.php, a couple of readers |
77 | 75 | '$wgCanonicalNamespaceNames', # Namespace.php |
78 | 76 | '$wgContLang', # Setup.php |
79 | | - |
80 | | - '$wgContLanguageCode', # Should probably be removed |
81 | | - '$wgDatabase', # For update scripts |
| 77 | + '$wgContLanguageCode', # Should probably be removed |
82 | 78 | '$wgDBcataloged', # http://www.mediawiki.org/wiki/Special:Code/MediaWiki/45755#c7954 |
83 | 79 | '$wgDeferredUpdateList', # Setup.php |
84 | | - '$wgExternalBlobCache', # ExternalStoreDB.php |
85 | | - |
86 | 80 | '$wgExtModifiedFields', '$wgExtNewFields', '$wgExtNewIndexes', '$wgExtNewTables', # Updates |
87 | | - |
88 | | - '$wgFeedClasses', # Defines.php, many uses |
89 | | - '$wgFullyInitialised', # Set by Setup.php, read by Exception |
90 | | - '$wgHtmlEntities', '$wgHtmlEntityAliases', # Sanitizer.php |
| 81 | + '$wgFeedClasses', # Defines.php, many uses |
91 | 82 | '$wgIP', # Setup.php |
92 | 83 | '$wgLang', # Setup.php |
93 | 84 | '$wgLanguageNames', # Language.php, read by others |
94 | 85 | '$wgMemc', # Setup.php |
95 | 86 | '$wgMessageCache', # Setup.php |
96 | | - |
97 | 87 | '$wgNoDBParam', # maintenance, serialized |
98 | 88 | '$wgOut', # Setup.php |
99 | 89 | '$wgParser', # Setup.php |
— | — | @@ -122,6 +112,25 @@ |
123 | 113 | } |
124 | 114 | } |
125 | 115 | |
| 116 | + protected static $mGlobalsPerFile = array( # Variables which are OK, but only on a few files |
| 117 | + '$wgCaches' => array( 'ObjectCache.php', 'phpunit', 'ForkController.php' ), |
| 118 | + '$wgDatabase' => array( 'updaters.inc', 'Installer.php', 'install-utils.inc', 'update.php', 'SqliteInstaller.php' ), # For update scripts |
| 119 | + '$wgHtmlEntities' => array( 'Sanitizer.php' ), |
| 120 | + '$wgHtmlEntityAliases' => array( 'Sanitizer.php' ), |
| 121 | + '$wgFullyInitialised' => array( /* Set */ 'Setup.php', /* read */ 'Exception.php' ), |
| 122 | + '$wgUseLatin1' => array( 'FiveUpgrade.inc' ), # If you upgrade from MW < 1.5 it will be there |
| 123 | + '$errs' => array( 'Installer.php' ), |
| 124 | + '$mainListOpened' => array( 'Installer.php' ), |
| 125 | + '$optionsWithArgs' => array( 'commandLine.inc' ), |
| 126 | + '$args' => array( 'commandLine.inc' ), |
| 127 | + '$options' => array( 'commandLine.inc', 'FiveUpgrade.inc' ), |
| 128 | + '$canonicalDecomp' => array( 'UtfNormalGenerate.php' ), |
| 129 | + '$compatibilityDecomp' => array( 'UtfNormalGenerate.php' ), |
| 130 | + '$mmfl' => array( 'mergeMessageFileList.php' ), |
| 131 | + '$checkBlacklist' => array( 'checkLanguage.inc' ), |
| 132 | + '$stderr' => array( 'serialize.php' ), |
| 133 | + ); |
| 134 | + |
126 | 135 | function setGenerateDeprecatedList( $bool = true ) { |
127 | 136 | $this->generateDeprecatedList = $bool; |
128 | 137 | } |
— | — | @@ -433,7 +442,15 @@ |
434 | 443 | |
435 | 444 | # Variables that can be used as global, but also as locals |
436 | 445 | function canBeGlobal( $name ) { |
437 | | - return $name == '$argv'; /* Used as global by maintenance scripts, but also common as function var */ |
| 446 | + if ( $name == '$argv' ) { |
| 447 | + /* Used as global by maintenance scripts, but also common as function var */ |
| 448 | + return true; |
| 449 | + } |
| 450 | + if ( isset( self::$mGlobalsPerFile[$name] ) && in_array( basename( $this->mFilename ) , self::$mGlobalsPerFile[$name] ) ) { |
| 451 | + return true; |
| 452 | + } |
| 453 | + |
| 454 | + return false; |
438 | 455 | } |
439 | 456 | |
440 | 457 | private function purgeGlobals() { |
— | — | @@ -457,7 +474,9 @@ |
458 | 475 | protected function checkGlobalName( $name ) { |
459 | 476 | if ( substr( $name, 0, 3 ) == '$wg' ) { |
460 | 477 | if ( ( self::$mDefaultSettingsGlobals != null ) && !in_array( $name, self::$mDefaultSettingsGlobals ) ) { |
461 | | - $this->warning( "Global variable $name is not present in DefaultSettings" ); |
| 478 | + if ( !isset( self::$mGlobalsPerFile[$name] ) || !in_array( basename( $this->mFilename ) , self::$mGlobalsPerFile[$name] ) ) { |
| 479 | + $this->warning( "Global variable $name is not present in DefaultSettings" ); |
| 480 | + } |
462 | 481 | } |
463 | 482 | } |
464 | 483 | } |