Page MenuHomePhabricator

Fix global variable and function prefixes in core
Closed, ResolvedPublic

Description

Global variables need to be prefixed with wg and global functions need to be prefixed with wf. There are some instances in core where this is not being done right now.

Someone familiar with the code should do this - it could break a lot of things.

Current output:

1............................................................ 60 / 1909 (3%)
2............................................................ 120 / 1909 (6%)
3............................................................ 180 / 1909 (9%)
4............................................................ 240 / 1909 (13%)
5............................................................ 300 / 1909 (16%)
6............................................................ 360 / 1909 (19%)
7........................................................E... 420 / 1909 (22%)
8...........................................................E 480 / 1909 (25%)
9.........................................E..E..........E.... 540 / 1909 (28%)
10......E.E..............................E.................... 600 / 1909 (31%)
11.....E...................................................... 660 / 1909 (35%)
12............................................................ 720 / 1909 (38%)
13............................................................ 780 / 1909 (41%)
14............................................................ 840 / 1909 (44%)
15............................................................ 900 / 1909 (47%)
16...................................................E........ 960 / 1909 (50%)
17............................................................ 1020 / 1909 (53%)
18.....................S...................................... 1080 / 1909 (57%)
19............................................................ 1140 / 1909 (60%)
20............................................................ 1200 / 1909 (63%)
21............................................................ 1260 / 1909 (66%)
22............................................................ 1320 / 1909 (69%)
23............................................................ 1380 / 1909 (72%)
24............................................................ 1440 / 1909 (75%)
25............................................................ 1500 / 1909 (79%)
26............................................................ 1560 / 1909 (82%)
27............................................................ 1620 / 1909 (85%)
28............................................................ 1680 / 1909 (88%)
29........................................................E... 1740 / 1909 (91%)
30...........................SS................S.............. 1800 / 1909 (94%)
31......................E......S.............................. 1860 / 1909 (97%)
32.............................................E...
33
34
35FILE: ...cts/mediawiki/maintenance/benchmarks/bench_strtr_str_replace.php
36----------------------------------------------------------------------
37FOUND 2 ERRORS AFFECTING 2 LINES
38----------------------------------------------------------------------
39 28 | ERROR | Global function "bfNormalizeTitleStrTr" is lacking a
40 | | 'wf' prefix. Should be "wfBfNormalizeTitleStrTr".
41 32 | ERROR | Global function "bfNormalizeTitleStrReplace" is lacking
42 | | a 'wf' prefix. Should be
43 | | "wfBfNormalizeTitleStrReplace".
44----------------------------------------------------------------------
45
46
47FILE: ...home/vivek/projects/mediawiki/maintenance/language/transstat.php
48----------------------------------------------------------------------
49FOUND 1 ERROR AFFECTING 1 LINE
50----------------------------------------------------------------------
51 45 | ERROR | Global function "showUsage" is lacking a 'wf' prefix.
52 | | Should be "wfShowUsage".
53----------------------------------------------------------------------
54
55
56FILE: ...me/vivek/projects/mediawiki/maintenance/storage/resolveStubs.php
57----------------------------------------------------------------------
58FOUND 2 ERRORS AFFECTING 2 LINES
59----------------------------------------------------------------------
60 37 | ERROR | Global function "resolveStubs" is lacking a 'wf'
61 | | prefix. Should be "wfResolveStubs".
62 70 | ERROR | Global function "resolveStub" is lacking a 'wf' prefix.
63 | | Should be "wfResolveStub".
64----------------------------------------------------------------------
65
66
67FILE: .../vivek/projects/mediawiki/maintenance/storage/moveToExternal.php
68----------------------------------------------------------------------
69FOUND 1 ERROR AFFECTING 1 LINE
70----------------------------------------------------------------------
71 50 | ERROR | Global function "moveToExternal" is lacking a 'wf'
72 | | prefix. Should be "wfMoveToExternal".
73----------------------------------------------------------------------
74
75
76FILE: /home/vivek/projects/mediawiki/maintenance/importImages.php
77----------------------------------------------------------------------
78FOUND 1 ERROR AFFECTING 1 LINE
79----------------------------------------------------------------------
80 351 | ERROR | Global function "showUsage" is lacking a 'wf' prefix.
81 | | Should be "wfShowUsage".
82----------------------------------------------------------------------
83
84
85FILE: /home/vivek/projects/mediawiki/maintenance/importImages.inc
86----------------------------------------------------------------------
87FOUND 5 ERRORS AFFECTING 5 LINES
88----------------------------------------------------------------------
89 34 | ERROR | Global function "findFiles" is lacking a 'wf' prefix.
90 | | Should be "wfFindFiles".
91 65 | ERROR | Global function "splitFilename" is lacking a 'wf'
92 | | prefix. Should be "wfSplitFilename".
93 88 | ERROR | Global function "findAuxFile" is lacking a 'wf'
94 | | prefix. Should be "wfFindAuxFile".
95 117 | ERROR | Global function "getFileCommentFromSourceWiki" is
96 | | lacking a 'wf' prefix. Should be
97 | | "wfGetFileCommentFromSourceWiki".
98 128 | ERROR | Global function "getFileUserFromSourceWiki" is lacking
99 | | a 'wf' prefix. Should be
100 | | "wfGetFileUserFromSourceWiki".
101----------------------------------------------------------------------
102
103
104FILE: /home/vivek/projects/mediawiki/maintenance/mcc.php
105----------------------------------------------------------------------
106FOUND 2 ERRORS AFFECTING 2 LINES
107----------------------------------------------------------------------
108 61 | ERROR | Global function "mccShowUsage" is lacking a 'wf'
109 | | prefix. Should be "wfMccShowUsage".
110 82 | ERROR | Global function "mccGetHelp" is lacking a 'wf' prefix.
111 | | Should be "wfMccGetHelp".
112----------------------------------------------------------------------
113
114
115FILE: /home/vivek/projects/mediawiki/maintenance/cdb.php
116----------------------------------------------------------------------
117FOUND 1 ERROR AFFECTING 1 LINE
118----------------------------------------------------------------------
119 30 | ERROR | Global function "cdbShowHelp" is lacking a 'wf' prefix.
120 | | Should be "wfCdbShowHelp".
121----------------------------------------------------------------------
122
123
124FILE: ...home/vivek/projects/mediawiki/tests/qunit/data/styleTest.css.php
125----------------------------------------------------------------------
126FOUND 1 ERROR AFFECTING 1 LINE
127----------------------------------------------------------------------
128 35 | ERROR | Global function "cssfilter" is lacking a 'wf' prefix.
129 | | Should be "wfCssfilter".
130----------------------------------------------------------------------
131
132
133FILE: ...me/vivek/projects/mediawiki/tests/phpunit/includes/HooksTest.php
134----------------------------------------------------------------------
135FOUND 2 ERRORS AFFECTING 2 LINES
136----------------------------------------------------------------------
137 160 | ERROR | Global function "NothingFunction" is lacking a 'wf'
138 | | prefix. Should be "wfNothingFunction".
139 166 | ERROR | Global function "NothingFunctionData" is lacking a
140 | | 'wf' prefix. Should be "wfNothingFunctionData".
141----------------------------------------------------------------------
142
143
144FILE: /home/vivek/projects/mediawiki/includes/GlobalFunctions.php
145----------------------------------------------------------------------
146FOUND 1 ERROR AFFECTING 1 LINE
147----------------------------------------------------------------------
148 2258 | ERROR | Global function "mimeTypeMatch" is lacking a 'wf'
149 | | prefix. Should be "wfMimeTypeMatch".
150----------------------------------------------------------------------
151
152
153FILE: .../vivek/projects/mediawiki/includes/libs/normal/UtfNormalUtil.php
154----------------------------------------------------------------------
155FOUND 5 ERRORS AFFECTING 5 LINES
156----------------------------------------------------------------------
157 39 | ERROR | Global function "codepointToUtf8" is lacking a 'wf'
158 | | prefix. Should be "wfCodepointToUtf8".
159 54 | ERROR | Global function "hexSequenceToUtf8" is lacking a 'wf'
160 | | prefix. Should be "wfHexSequenceToUtf8".
161 67 | ERROR | Global function "utf8ToHexSequence" is lacking a 'wf'
162 | | prefix. Should be "wfUtf8ToHexSequence".
163 85 | ERROR | Global function "utf8ToCodepoint" is lacking a 'wf'
164 | | prefix. Should be "wfUtf8ToCodepoint".
165 97 | ERROR | Global function "escapeSingleString" is lacking a 'wf'
166 | | prefix. Should be "wfEscapeSingleString".
167----------------------------------------------------------------------
168
169
170FILE: /home/vivek/projects/mediawiki/profileinfo.php
171----------------------------------------------------------------------
172FOUND 2 ERRORS AFFECTING 2 LINES
173----------------------------------------------------------------------
174 290 | ERROR | Global function "compare_point" is lacking a 'wf'
175 | | prefix. Should be "wfCompare_point".
176 361 | ERROR | Global function "getEscapedProfileUrl" is lacking a
177 | | 'wf' prefix. Should be "wfGetEscapedProfileUrl".
178----------------------------------------------------------------------
179
180Time: 4 mins, 56.21 secs; Memory: 232Mb

Event Timeline

polybuildr raised the priority of this task from to Needs Triage.
polybuildr updated the task description. (Show Details)
polybuildr moved this task from Untriaged to Pass codesniffer on the MediaWiki-Codesniffer board.

As you said, it can easily breaks thing though so I am not sure it is worth updating them just for the sake of it.

We can probably whitelist exceptions in our standard file and reject anything not in that whitelist, that would prevent introduction of new globals that do not match the convention and saves us from having very bad side effects :-D

Can be done in ./MediaWiki/Sniffs/NamingConventions/PrefixedGlobalFunctionsSniff.php and ./MediaWiki/Sniffs/NamingConventions/ValidGlobalNameSniff.php.

class MediaWiki_Sniffs_NamingConventions_ValidGlobalNameSniff implements PHP_CodeSniffer_Sniff {

    private static $mediaWikiValid = array(
        '$messageMemc',
        '$parserMemc',
        '$IP',
    );

The code comes from https://gerrit.wikimedia.org/r/#/c/48353/ by @Umherirrender. I originally only whitelisted $IP, so we can probably add some more variables here.

Yeah, that makes sense. Someone familiar with the code should be able to decide which ones to change and which ones to put in the whitelist. @Legoktm?

polybuildr set Security to None.

I didn't know you could include an entire paste. Nice! :D

Change 237247 had a related patch set uploaded (by Polybuildr):
Add ignore list to PrefixedGlobalFunctionsSniff

https://gerrit.wikimedia.org/r/237247

Change 237269 had a related patch set uploaded (by Polybuildr):
Add ignoreList for prefixed functions sniff in phpcs.xml

https://gerrit.wikimedia.org/r/237269

Change 237247 merged by jenkins-bot:
Add ignore list to PrefixedGlobalFunctionsSniff

https://gerrit.wikimedia.org/r/237247

Change 237328 had a related patch set uploaded (by Polybuildr):
Add ignore list to ValidGlobalNameSniff

https://gerrit.wikimedia.org/r/237328

Change 237329 had a related patch set uploaded (by Polybuildr):
Add ignoreList for valid global variable name sniff in phpcs.xml

https://gerrit.wikimedia.org/r/237329

Change 237328 merged by jenkins-bot:
Add ignore list to ValidGlobalNameSniff

https://gerrit.wikimedia.org/r/237328

Change 237269 merged by jenkins-bot:
Add ignoreList for prefixed functions sniff in phpcs.xml

https://gerrit.wikimedia.org/r/237269

Change 237329 merged by jenkins-bot:
Add ignoreList for valid global variable name sniff in phpcs.xml

https://gerrit.wikimedia.org/r/237329

Change 243420 had a related patch set uploaded (by Umherirrender):
Enable MediaWiki.NamingConventions.PrefixedGlobalFunctions.wfPrefix

https://gerrit.wikimedia.org/r/243420

Change 243420 merged by jenkins-bot:
Enable MediaWiki.NamingConventions.PrefixedGlobalFunctions.wfPrefix

https://gerrit.wikimedia.org/r/243420

@Legoktm Why do we want variables like $IP to only be ignored if whitelisted on a per-project basis? Any extension could potentially want to use variables like this. Should every extension have to whitelist them separately?

In particular, https://gerrit.wikimedia.org/r/502004 and https://gerrit.wikimedia.org/r/502005 use $IP in a way that seems useful for any extension with maintenance scripts that might be included from update.php or similar.