Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -53,12 +53,12 @@ |
54 | 54 | static $mKnownFileClassesDefault = array(); |
55 | 55 | static $mKnownFunctionsDefault = array(); |
56 | 56 | static $mConstantsDefault = array(); |
57 | | - |
| 57 | + |
58 | 58 | # Ignore constants with these prefixes: |
59 | 59 | static $constantIgnorePrefixes = array( "PGSQL_", "OCI_", "SQLT_BLOB", "DB2_", "XMLREADER_", "SQLSRV_" ); |
60 | 60 | # Ignore functions with these prefixes: |
61 | 61 | static $functionIgnorePrefixes = array( "pg_", "oci_", "db2_", "gmp_", "sqlsrv_", "exif_", "fss_", "tidy_", |
62 | | - "apc_", "eaccelerator_", "xcache_", "wincache_", "apache_", "xdiff_", "wikidiff2_", "parsekit_", |
| 62 | + "apc_", "eaccelerator_", "xcache_", "wincache_", "apache_", "xdiff_", "wikidiff2_", "parsekit_", |
63 | 63 | "wddx_", "setproctitle", "utf8_", "normalizer_", "dba_", "pcntl_", "finfo_", "mime_content_type", |
64 | 64 | # GD and images functions: |
65 | 65 | "imagecreatetruecolor", "imagecolorallocate", "imagecolortransparent", "imagealphablending", |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | 'addslashes' => 'Replace with Database::addQuotes/strencode', |
74 | 74 | 'mysql_escape_string' => 'Replace with Database::addQuotes/strencode', |
75 | 75 | ); |
76 | | - |
| 76 | + |
77 | 77 | protected $generateDeprecatedList = false; |
78 | 78 | |
79 | 79 | /* Values for status */ |
— | — | @@ -100,12 +100,12 @@ |
101 | 101 | if ( count( $this->mTokens ) > 0 ) { |
102 | 102 | $globals = array ( |
103 | 103 | '$wgArticle', # Setup.php |
104 | | - '$wgAutoloadLocalClasses', # AutoLoader.php, a couple of readers |
| 104 | + '$wgAutoloadLocalClasses', # AutoLoader.php, a couple of readers |
105 | 105 | '$wgCanonicalNamespaceNames', # Namespace.php |
106 | 106 | '$wgContLang', # Setup.php |
107 | 107 | '$wgDeferredUpdateList', # Setup.php |
108 | 108 | '$wgExtModifiedFields', '$wgExtNewFields', '$wgExtNewIndexes', '$wgExtNewTables', # Updates |
109 | | - '$wgFeedClasses', # Defines.php, many uses |
| 109 | + '$wgFeedClasses', # Defines.php, many uses |
110 | 110 | '$wgLang', # Setup.php |
111 | 111 | '$wgLanguageNames', # Language.php, read by others |
112 | 112 | '$wgMemc', # Setup.php |
— | — | @@ -204,12 +204,12 @@ |
205 | 205 | 'FILEINFO_MIME', 'FILEINFO_MIME_TYPE', 'MHASH_ADLER32', |
206 | 206 | 'SIGTERM', 'SIG_DFL', |
207 | 207 | 'SVN_REVISION_HEAD', 'SVN_REVISION_INITIAL', |
208 | | - ) ; |
| 208 | + ) ; |
209 | 209 | } |
210 | | - |
| 210 | + |
211 | 211 | function load( $file, $shortcircuit = true ) { |
212 | 212 | $this->initVars(); |
213 | | - $this->mFilename = $file; |
| 213 | + $this->mFilename = $file; |
214 | 214 | |
215 | 215 | $source = file_get_contents( $file ); |
216 | 216 | if ( substr( $source, 0, 3 ) == "\xEF\xBB\xBF" ) { |
— | — | @@ -294,12 +294,12 @@ |
295 | 295 | $this->mClass = $token[1]; |
296 | 296 | $this->mParent = null; |
297 | 297 | } |
298 | | - |
| 298 | + |
299 | 299 | if ( $token[0] == '}' ) { |
300 | 300 | $this->mClass = null; |
301 | 301 | $this->mParent = null; |
302 | 302 | } |
303 | | - |
| 303 | + |
304 | 304 | if ( ( $lastMeaningfulToken[0] == T_EXTENDS ) && ( $token[0] == T_STRING ) ) { |
305 | 305 | $this->checkClassName( $token ); |
306 | 306 | $this->mParent = $token[1]; |
— | — | @@ -310,7 +310,7 @@ |
311 | 311 | $requirePath = ""; |
312 | 312 | continue; |
313 | 313 | } |
314 | | - |
| 314 | + |
315 | 315 | if ( $token[0] != T_FUNCTION ) |
316 | 316 | continue; |
317 | 317 | $this->mStatus = self::IN_FUNCTION_NAME; |
— | — | @@ -359,7 +359,7 @@ |
360 | 360 | $this->mBraces--; |
361 | 361 | if ( $this->mInSwitch <= $this->mBraces ) |
362 | 362 | $this->mInSwitch = 0; |
363 | | - |
| 363 | + |
364 | 364 | $this->purgeGlobals(); |
365 | 365 | if ( ! $this->mBraces ) { |
366 | 366 | $this->mStatus = self::WAITING_FUNCTION; |
— | — | @@ -503,7 +503,7 @@ |
504 | 504 | case self::IN_FUNCTION_REQUIRE: |
505 | 505 | if ( $token == ';' ) { |
506 | 506 | $requirePath = trim( $requirePath, ')("' ); |
507 | | - |
| 507 | + |
508 | 508 | if ( substr( $requirePath, 0, 8 ) == "PHPUnit/" ) { |
509 | 509 | $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
510 | 510 | continue; |
— | — | @@ -524,7 +524,7 @@ |
525 | 525 | $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
526 | 526 | continue; |
527 | 527 | } |
528 | | - |
| 528 | + |
529 | 529 | if ( ( $requirePath == '' ) || ( !file_exists( $requirePath ) && $requirePath[0] != '/' ) ) { |
530 | 530 | /* Try prepending the script folder, for maintenance scripts (but see Maintenance.php:758) */ |
531 | 531 | $requirePath = dirname( $this->mFilename ) . "/" . $requirePath; |
— | — | @@ -552,10 +552,10 @@ |
553 | 553 | $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
554 | 554 | continue; |
555 | 555 | } |
556 | | - |
| 556 | + |
557 | 557 | if ( $token[0] == T_WHITESPACE ) |
558 | 558 | continue; |
559 | | - |
| 559 | + |
560 | 560 | if ( $token[0] == T_STRING_VARNAME ) { |
561 | 561 | $token[0] = T_VARIABLE; |
562 | 562 | $token[1] = '$' . $token[1]; |
— | — | @@ -604,7 +604,7 @@ |
605 | 605 | $requirePath .= $token[1]; |
606 | 606 | } |
607 | 607 | continue; |
608 | | - |
| 608 | + |
609 | 609 | } |
610 | 610 | } |
611 | 611 | |
— | — | @@ -614,10 +614,10 @@ |
615 | 615 | |
616 | 616 | function checkDeprecation( $token ) { |
617 | 617 | global $mwDeprecatedFunctions; |
618 | | - |
619 | | - if ( $mwDeprecatedFunctions && !in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) && |
| 618 | + |
| 619 | + if ( $mwDeprecatedFunctions && !in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) && |
620 | 620 | isset( $mwDeprecatedFunctions[ $token[1] ] ) ) { |
621 | | - |
| 621 | + |
622 | 622 | if ( isset( $token['class'] ) ) { |
623 | 623 | if ( in_array( $token['class'], $mwDeprecatedFunctions[ $token[1] ] ) ) { |
624 | 624 | $this->warning( "Non deprecated function $this->mFunction calls deprecated function {$token['class']}::{$token[1]} in line {$token[2]}" ); |
— | — | @@ -628,11 +628,11 @@ |
629 | 629 | } |
630 | 630 | } |
631 | 631 | } |
632 | | - |
| 632 | + |
633 | 633 | function checkFunctionName( $token, $warn = 'defer' ) { |
634 | 634 | if ( !isset( $token['base'] ) ) { |
635 | 635 | // Local function |
636 | | - |
| 636 | + |
637 | 637 | if ( substr( $token[1], 0, 2 ) == 'wf' ) { |
638 | 638 | // MediaWiki function |
639 | 639 | // TODO: List them. |
— | — | @@ -641,30 +641,30 @@ |
642 | 642 | if ( $token[1] == 'dieout' && in_array( $this->mFunction, array( 'setup_database', 'initial_setup', 'setup_plpgsql' ) ) ) { |
643 | 643 | return; |
644 | 644 | } |
645 | | - |
| 645 | + |
646 | 646 | if ( isset( self::$poisonedFunctions[ strtolower($token[1]) ] ) ) { |
647 | 647 | $this->warning( "Poisoned function {$token[1]} called from {$this->mFunction} in line {$token[2]}: " . self::$poisonedFunctions[strtolower($token[1])] ); |
648 | 648 | return; |
649 | 649 | } |
650 | | - |
| 650 | + |
651 | 651 | if ( function_exists( $token[1] ) ) { |
652 | 652 | return; |
653 | 653 | } |
654 | 654 | if ( in_array( $token[1], $this->mKnownFunctions ) ) { |
655 | 655 | return; |
656 | 656 | } |
657 | | - |
| 657 | + |
658 | 658 | if ( self::inIgnoreList( $token[1], self::$functionIgnorePrefixes ) ) { |
659 | 659 | return; |
660 | 660 | } |
661 | | - |
| 661 | + |
662 | 662 | if ( $warn == 'now' ) { |
663 | 663 | $this->warning( "Unavailable function {$token[1]} in line {$token[2]}" ); |
664 | 664 | } else if ( $warn == 'defer' ) { |
665 | 665 | // Defer to the end of the file |
666 | 666 | $this->mUnknownFunctions[] = $token; |
667 | 667 | } |
668 | | - |
| 668 | + |
669 | 669 | } |
670 | 670 | } |
671 | 671 | |
— | — | @@ -674,7 +674,7 @@ |
675 | 675 | } |
676 | 676 | $this->mUnknownFunctions = array(); |
677 | 677 | } |
678 | | - |
| 678 | + |
679 | 679 | /* Returns a class name, or null if it couldn't guess */ |
680 | 680 | function guessClassName( $token ) { |
681 | 681 | static $wellKnownVars = array( |
— | — | @@ -691,7 +691,7 @@ |
692 | 692 | '$sk' => 'Skin', |
693 | 693 | '$wgMemc' => 'MWMemcached', |
694 | 694 | ); |
695 | | - |
| 695 | + |
696 | 696 | if ( $token[0] == T_VARIABLE ) { |
697 | 697 | if ( isset( $wellKnownVars[ $token[1] ] ) ) { |
698 | 698 | return $wellKnownVars[ $token[1] ]; |
— | — | @@ -704,9 +704,9 @@ |
705 | 705 | return $this->mClass; |
706 | 706 | if ( ( $token[1] == 'parent' ) && !isset( $token['base'] ) ) |
707 | 707 | return $this->getParentName( $token ); |
708 | | - |
| 708 | + |
709 | 709 | $name = $token[1]; |
710 | | - |
| 710 | + |
711 | 711 | if ( $token[1][0] == 'm' ) // member |
712 | 712 | $name = substr( $token[1], 1 ); |
713 | 713 | } else { |
— | — | @@ -766,7 +766,7 @@ |
767 | 767 | /* Skip the error about $site and $lang in Maintenance.php */ |
768 | 768 | return true; |
769 | 769 | } |
770 | | - |
| 770 | + |
771 | 771 | return false; |
772 | 772 | } |
773 | 773 | |
— | — | @@ -812,7 +812,7 @@ |
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | | - * Returns a |
| 816 | + * Returns a |
817 | 817 | * @param $token Token holding the class name |
818 | 818 | * @param $warn A value from 'no', 'defer', 'now¡ |
819 | 819 | * @return mixed The class name if it is found, false otherwise |
— | — | @@ -860,7 +860,7 @@ |
861 | 861 | } |
862 | 862 | return false; |
863 | 863 | } |
864 | | - |
| 864 | + |
865 | 865 | function getParentName( $token ) { |
866 | 866 | if ( !is_null( $this->mParent ) ) { |
867 | 867 | return $this->mParent; |
— | — | @@ -868,17 +868,17 @@ |
869 | 869 | $this->warning( "Use of parent in orphan class {$this->mClass} in line $token[2]" ); |
870 | 870 | return "-"; |
871 | 871 | } |
872 | | - |
| 872 | + |
873 | 873 | /** |
874 | | - * Sets a number of files which are considered as having always been |
875 | | - * loaded before any loaded one. Any functions/classes defined there |
| 874 | + * Sets a number of files which are considered as having always been |
| 875 | + * loaded before any loaded one. Any functions/classes defined there |
876 | 876 | * will be assumed to be available. |
877 | 877 | */ |
878 | 878 | function preloadFiles( $files ) { |
879 | 879 | $this->initVars(); |
880 | 880 | $this->mFilename = '__preload'; |
881 | 881 | $this->mTokens = array( T_OPEN_TAG, '<?php', 0 ); |
882 | | - |
| 882 | + |
883 | 883 | for ( $i = 1; $i <= count( $files ); $i++ ) { |
884 | 884 | $this->mTokens[] = array( T_REQUIRE, 'require', $i ); |
885 | 885 | $this->mTokens[] = array( T_CONSTANT_ENCAPSED_STRING, "'" . $files[$i - 1] . "'", $i ); |