r70995 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70994‎ | r70995 | r70996 >
Date:21:58, 12 August 2010
Author:platonides
Status:deferred
Tags:
Comment:
Remove some global variables, restrict others to specific files.
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -70,29 +70,19 @@
7171 if ( count( $this->mTokens ) > 0 ) {
7272 $globals = array (
7373 '$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
7775 '$wgCanonicalNamespaceNames', # Namespace.php
7876 '$wgContLang', # Setup.php
79 -
80 - '$wgContLanguageCode', # Should probably be removed
81 - '$wgDatabase', # For update scripts
 77+ '$wgContLanguageCode', # Should probably be removed
8278 '$wgDBcataloged', # http://www.mediawiki.org/wiki/Special:Code/MediaWiki/45755#c7954
8379 '$wgDeferredUpdateList', # Setup.php
84 - '$wgExternalBlobCache', # ExternalStoreDB.php
85 -
8680 '$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
9182 '$wgIP', # Setup.php
9283 '$wgLang', # Setup.php
9384 '$wgLanguageNames', # Language.php, read by others
9485 '$wgMemc', # Setup.php
9586 '$wgMessageCache', # Setup.php
96 -
9787 '$wgNoDBParam', # maintenance, serialized
9888 '$wgOut', # Setup.php
9989 '$wgParser', # Setup.php
@@ -122,6 +112,25 @@
123113 }
124114 }
125115
 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+
126135 function setGenerateDeprecatedList( $bool = true ) {
127136 $this->generateDeprecatedList = $bool;
128137 }
@@ -433,7 +442,15 @@
434443
435444 # Variables that can be used as global, but also as locals
436445 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;
438455 }
439456
440457 private function purgeGlobals() {
@@ -457,7 +474,9 @@
458475 protected function checkGlobalName( $name ) {
459476 if ( substr( $name, 0, 3 ) == '$wg' ) {
460477 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+ }
462481 }
463482 }
464483 }

Status & tagging log