r88187 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88186‎ | r88187 | r88188 >
Date:14:32, 15 May 2011
Author:demon
Status:ok (Comments)
Tags:
Comment:
Add check for evil, EVIL @
Modified paths:
  • /trunk/phase3/maintenance/checkSyntax.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/checkSyntax.php
@@ -275,7 +275,9 @@
276276 }
277277
278278 $text = file_get_contents( $file );
 279+ $tokens = token_get_all( $text );
279280
 281+ $this->checkEvilToken( $file, $tokens, '@', 'Error supression operator (@)');
280282 $this->checkRegex( $file, $text, '/^[\s\r\n]+<\?/', 'leading whitespace' );
281283 $this->checkRegex( $file, $text, '/\?>[\s\r\n]*$/', 'trailing ?>' );
282284 $this->checkRegex( $file, $text, '/^[\xFF\xFE\xEF]/', 'byte-order mark' );
@@ -292,6 +294,18 @@
293295 $this->mWarnings[$file][] = $desc;
294296 $this->output( "Warning in file $file: $desc found.\n" );
295297 }
 298+
 299+ private function checkEvilToken( $file, $tokens, $evilToken, $desc ) {
 300+ if ( !in_array( $evilToken, $tokens ) ) {
 301+ return;
 302+ }
 303+
 304+ if ( !isset( $this->mWarnings[$file] ) ) {
 305+ $this->mWarnings[$file] = array();
 306+ }
 307+ $this->mWarnings[$file][] = $desc;
 308+ $this->output( "Warning in file $file: $desc found.\n" );
 309+ }
296310 }
297311
298312 $maintClass = "CheckSyntax";

Follow-up revisions

RevisionCommit summaryAuthorDate
r88487Implement in two lines the check for @ that r88187 added to checkSyntax.phpplatonides21:17, 20 May 2011

Comments

#Comment by Hashar (talk | contribs)   17:43, 15 May 2011

Well it would be useful to have an hint at the function / token using the @ operator. Maybe by looking for a method names in the next tokens? And add a line number or something.

Without those, it is pretty useless.

#Comment by 😂 (talk | contribs)   20:14, 15 May 2011

Line number would be hard, since the tokenizer doesn't keep track of those.

I disagree that it's useless, it makes it way easier to find violations :)

#Comment by Nikerabbit (talk | contribs)   10:23, 16 May 2011

I agree with ^demon. Trying to grep for @ is a pain in the horse, except if you know which files to look for (and can use something like grep @ | fgrep -v '* @' to filter out the results.

#Comment by Platonides (talk | contribs)   20:36, 19 May 2011

It will be much easier adding that check to check-vars than trying to get a regex for that.

#Comment by Hashar (talk | contribs)   06:37, 20 May 2011

token_get_all() returns the line number as well since PHP 5.2.2.

Look at /trunk/tools/code-utils/find-long-functions.php

analyze_file() loads up the tokens for a file, filter out unwanted one.

Then _analyze_tokens() loop through the tokens, line 87 you can see we get the line number in $token[2].

#Comment by Platonides (talk | contribs)   14:50, 20 May 2011

The line number is only returned for tokens that aren't a single character.

#Comment by Hashar (talk | contribs)   21:04, 20 May 2011

So you can get a rough line number by looking backward & forward for tokens having a line number. This way you get a rough estimate of the line number which might be a good enough hint :-)

#Comment by 😂 (talk | contribs)   21:06, 20 May 2011

Is it really so hard to press ctrl+F once you know the file?

#Comment by Hashar (talk | contribs)   21:11, 20 May 2011

I use /@, and yes, it got all the @param, @return in the document blocks. So it is useless for me.

(of course /[^\*]\s+@ will probably do it, but I am getting lazy since I am past 30  :-b

#Comment by Platonides (talk | contribs)   21:29, 20 May 2011

Here it is a list for the lazy:

Problems in phase3/includes/GlobalFunctions.php:
 Use of @ operator in function wfHostname
 Use of @ operator in function wfVarDump
 Use of @ operator in function wfAcceptToPrefs
Problems in phase3/includes/profiler/Profiler.php:
 Use of @ operator in function getFunctionReport
Problems in phase3/includes/StreamFile.php:
 Use of @ operator in function wfStreamFile
Problems in phase3/profileinfo.php:
 Use of @ operator in function display
 Use of @ operator in function display
 Use of @ operator in function display
 Use of @ operator in function display
 Use of @ operator in function timePerCall
 Use of @ operator in function memoryPerCall
 Use of @ operator in function callsPerRequest
 Use of @ operator in function timePerRequest
 Use of @ operator in function memoryPerRequest
Problems in phase3/languages/Language.php:
 Use of @ operator in function userAdjust
Problems in phase3/maintenance/Maintenance.php:
 Use of @ operator in function setup
 Use of @ operator in function finalSetup
Problems in phase3/maintenance/backup.inc:
 Use of @ operator in function processArgs
Problems in phase3/maintenance/updateSpecialPages.php:
 Use of @ operator in function execute
Problems in phase3/maintenance/storage/fixBug20757.php:
 Use of @ operator in function isUnbrokenStub
Problems in phase3/maintenance/backup.inc:
 Use of @ operator in function processArgs
Problems in phase3/maintenance/updateSearchIndex.php:
 Use of @ operator in function execute
Problems in phase3/maintenance/Maintenance.php:
 Use of @ operator in function setup
 Use of @ operator in function finalSetup
Problems in phase3/maintenance/checkImages.php:
 Use of @ operator in function execute
Problems in phase3/maintenance/userOptions.inc:
 Use of @ operator in function USAGER
 Use of @ operator in function USAGER
Problems in phase3/maintenance/checkSyntax.php:
 Use of @ operator in function buildFileList
Problems in phase3/maintenance/language/StatOutputs.php:
 Use of @ operator in function formatPercent
 Use of @ operator in function formatPercent
Problems in phase3/maintenance/language/StatOutputs.php:
 Use of @ operator in function formatPercent
 Use of @ operator in function formatPercent
Problems in phase3/languages/Language.php:
 Use of @ operator in function userAdjust
Problems in phase3/maintenance/rebuildFileCache.php:
 Use of @ operator in function execute
Problems in phase3/tests/selenium/SeleniumTestConsoleLogger.php:
 Use of @ operator in function __construct
 Use of @ operator in function __construct
Problems in phase3/includes/templates/Userlogin.php:
 Use of @ operator in function execute
 Use of @ operator in function execute
 Use of @ operator in function execute
 Use of @ operator in function execute
 Use of @ operator in function execute
 Use of @ operator in function execute
Problems in phase3/includes/Sanitizer.php:
 Use of @ operator in function removeHTMLtags
 Use of @ operator in function removeHTMLtags
 Use of @ operator in function removeHTMLtags
 Use of @ operator in function removeHTMLtags
 Use of @ operator in function removeHTMLtags
 Use of @ operator in function removeHTMLtags
Problems in phase3/includes/GlobalFunctions.php:
 Use of @ operator in function wfHostname
 Use of @ operator in function wfVarDump
 Use of @ operator in function wfAcceptToPrefs
Problems in phase3/includes/ConfEditor.php:
 Use of @ operator in function parseScalar
Problems in phase3/includes/GlobalFunctions.php:
 Use of @ operator in function wfHostname
 Use of @ operator in function wfVarDump
 Use of @ operator in function wfAcceptToPrefs
Problems in phase3/includes/db/DatabasePostgres.php:
 Use of @ operator in function freeResult
 Use of @ operator in function fetchObject
 Use of @ operator in function fetchRow
 Use of @ operator in function numRows
Problems in phase3/includes/db/DatabaseMysql.php:
 Use of @ operator in function open
 Use of @ operator in function freeResult
 Use of @ operator in function fetchObject
 Use of @ operator in function fetchRow
 Use of @ operator in function numRows
Problems in phase3/includes/db/DatabaseIbm_db2.php:
 Use of @ operator in function openCataloged
 Use of @ operator in function openUncataloged
 Use of @ operator in function tableExists
 Use of @ operator in function fetchObject
 Use of @ operator in function fetchRow
 Use of @ operator in function freeResult
Problems in phase3/includes/db/Database.php:
 Use of @ operator in function selectSQLText
 Use of @ operator in function selectSQLText
 Use of @ operator in function tableName
 Use of @ operator in function tableName
 Use of @ operator in function searchForm
Problems in phase3/includes/HistoryBlob.php:
 Use of @ operator in function getText
Problems in phase3/maintenance/Maintenance.php:
 Use of @ operator in function setup
 Use of @ operator in function finalSetup
Problems in phase3/includes/media/SVG.php:
 Use of @ operator in function unpackMetadata
Problems in phase3/includes/media/Exif.php:
 Use of @ operator in function isRational
Problems in phase3/includes/media/DjVu.php:
 Use of @ operator in function doTransform
 Use of @ operator in function doTransform
Problems in phase3/includes/StreamFile.php:
 Use of @ operator in function wfStreamFile
Problems in phase3/includes/json/Services_JSON.php:
 Use of @ operator in function isError
Problems in phase3/includes/json/Services_JSON.php:
 Use of @ operator in function isError
Problems in phase3/includes/Revision.php:
 Use of @ operator in function getRevisionText
Problems in phase3/includes/StreamFile.php:
 Use of @ operator in function wfStreamFile
Problems in phase3/includes/specials/SpecialWantedpages.php:
 Use of @ operator in function execute
Problems in phase3/includes/profiler/Profiler.php:
 Use of @ operator in function getFunctionReport
Problems in phase3/includes/cache/MessageCache.php:
 Use of @ operator in function saveToLocal
Problems in phase3/includes/objectcache/SqlBagOStuff.php:
 Use of @ operator in function unserialize
Problems in phase3/includes/parser/Parser_LinkHooks.php:
 Use of @ operator in function replaceInternalLinks2
Problems in phase3/includes/parser/Parser.php:
 Use of @ operator in function formatHeadings
Problems in phase3/includes/diff/DairikiDiff.php:
 Use of @ operator in function format
Problems in phase3/includes/Import.php:
 Use of @ operator in function newFromFile
Problems in phase3/includes/filerepo/ForeignAPIFile.php:
 Use of @ operator in function getWidth
 Use of @ operator in function getHeight
Problems in phase3/includes/filerepo/LocalRepo.php:
 Use of @ operator in function cleanupDeletedBatch
Problems in phase3/includes/filerepo/FSRepo.php:
 Use of @ operator in function deleteBatch
 Use of @ operator in function deleteBatch
Problems in phase3/includes/filerepo/LocalFile.php:
 Use of @ operator in function purgeThumbnails
Problems in phase3/includes/profiler/Profiler.php:
 Use of @ operator in function getFunctionReport
Problems in phase3/includes/User.php:
 Use of @ operator in function pingLimiter
Problems in phase3/includes/search/SearchSqlite.php:
 Use of @ operator in function parseQuery
Problems in phase3/includes/search/SearchMySQL.php:
 Use of @ operator in function parseQuery

Status & tagging log