Find and fix places where globals were being used without declaring them.
All the places were found using a script, reproduced below, in case
anyone wants to reuse it.
But beware: The script produces a lot of false positives, because it
doesn't fully parse PHP and is fooled e.g. by javascript functions
inside of <<<HERE documents.
#!/usr/bin/perl -0777 -n
#
# find functions where variables starting with $wg are used without declaring them as globals
# should be given a list of files on the command line
#
# first remove all comments
# Warning: this may remove too much, e.g. if /* is inside a string
s,/\*.*?\*/,,sg; # remove multiline comments
s,#.*,,g; # remove single line comments starting with #
s,//.*,,g; # and the ones starting with //
s,(?<!\\)'.*?(?<!\\)',,g; # remove 'single quoted single-line strings'; may again remove too much
# now process each function one by one
# does not deal correctly with javascript functions embedded in <<HERE documents, unfortunately
#
while (/(^\s*)(?:(?:private|public|protected|static)\s+)*function\s+(\w+)\s*\((.*?)\)\s*\{(.*?)\1\}/msg) {
$fname = $2; $farg = $3; $fbody = $4;
%globals = ();
while ($farg =~ /(\$\w+)/g) { # treat arguments to functions as globals here
$globals{$1} = 1;
}
while ($fbody =~ /^\s*global\s+([^;]+?)\s*;/msg) { # find all global vars
for (split /\s*,\s*/, $1) {
$globals{$_} = 1;
}
}
while ($fbody =~ /(?<!\\)(\$wg\w+)\b/g) { # search for all variables starting with $wg and see if they are declared as globals
if (not $globals{$1}) {
print "Global $1 not declared in function $fname, file $ARGV\n";
$globals{$1} = 1; # warn only once
}
}
}
This commit is contained in:
parent
5b6127b8bf
commit
a4f99d65dc
3 changed files with 3 additions and 2 deletions
|
|
@ -1345,7 +1345,7 @@ class OutputPage {
|
|||
* for when rate limiting has triggered.
|
||||
*/
|
||||
public function rateLimited() {
|
||||
global $wgOut;
|
||||
global $wgOut, $wgTitle;
|
||||
|
||||
$this->setPageTitle(wfMsg('actionthrottled'));
|
||||
$this->setRobotPolicy( 'noindex,follow' );
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class LanguageKk_cyrl extends Language {
|
|||
}
|
||||
|
||||
function convertGrammarKk_cyrl( $word, $case ) {
|
||||
|
||||
global $wgGrammarForms;
|
||||
if ( isset( $wgGrammarForms['kk-kz'][$case][$word] ) ) {
|
||||
return $wgGrammarForms['kk-kz'][$case][$word];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ function addWiki( $lang, $site, $dbName )
|
|||
}
|
||||
}
|
||||
|
||||
global $wgTitle, $wgArticle;
|
||||
$wgTitle = Title::newMainPage();
|
||||
$wgArticle = new Article( $wgTitle );
|
||||
$ucsite = ucfirst( $site );
|
||||
|
|
|
|||
Loading…
Reference in a new issue