Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -12,12 +12,17 @@ |
13 | 13 | |
14 | 14 | require_once( "$IP/includes/Defines.php" ); # Faster than parsing |
15 | 15 | require_once( "$IP/includes/AutoLoader.php" ); |
| 16 | +$wgAutoloadClasses = &$wgAutoloadLocalClasses; |
| 17 | +require_once( "$IP/tests/TestsAutoLoader.php" ); |
16 | 18 | |
17 | 19 | $mwDeprecatedFunctions = false; |
18 | 20 | @include( dirname( __FILE__ ) . "/deprecated.functions" ); |
| 21 | +$mwParentClasses = array(); |
| 22 | +@include( dirname( __FILE__ ) . "/parent.classes" ); |
19 | 23 | |
20 | 24 | if ( !extension_loaded( 'sockets' ) ) dl( 'sockets.so' ); |
21 | 25 | if ( !extension_loaded( 'PDO' ) ) dl( 'pdo.so' ); |
| 26 | +if ( !extension_loaded( 'zip' ) ) dl( 'zip.so' ); |
22 | 27 | |
23 | 28 | $wgAutoloadLocalClasses += array( |
24 | 29 | 'DBAccessError' => 'LBFactory', |
— | — | @@ -59,7 +64,7 @@ |
60 | 65 | # Ignore functions with these prefixes: |
61 | 66 | static $functionIgnorePrefixes = array( "pg_", "oci_", "db2_", "gmp_", "sqlsrv_", "exif_", "fss_", "tidy_", |
62 | 67 | "apc_", "eaccelerator_", "xcache_", "wincache_", "apache_", "xdiff_", "wikidiff2_", "parsekit_", |
63 | | - "wddx_", "setproctitle", "utf8_", "normalizer_", "dba_", "pcntl_", "finfo_", "mime_content_type", |
| 68 | + "wddx_", "setproctitle", "utf8_", "normalizer_", "dba_", "pcntl_", "finfo_", "mime_content_type", "curl_", |
64 | 69 | # GD and images functions: |
65 | 70 | "imagecreatetruecolor", "imagecolorallocate", "imagecolortransparent", "imagealphablending", |
66 | 71 | "imagecopyresized", "imagesx", "imagesy", "imagecopyresampled", "imagesavealpha", |
— | — | @@ -76,6 +81,7 @@ |
77 | 82 | ); |
78 | 83 | |
79 | 84 | protected $generateDeprecatedList = false; |
| 85 | + protected $generateParentList = false; |
80 | 86 | |
81 | 87 | /* Values for status */ |
82 | 88 | const WAITING_FUNCTION = 0; |
— | — | @@ -181,6 +187,22 @@ |
182 | 188 | file_put_contents( $filename, $data ); |
183 | 189 | } |
184 | 190 | |
| 191 | + function setGenerateParentList( $bool = true ) { |
| 192 | + $this->generateParentList = $bool; |
| 193 | + } |
| 194 | + function getGenerateParentList() { |
| 195 | + return $this->generateParentList; |
| 196 | + } |
| 197 | + function saveParentList( $filename ) { |
| 198 | + global $mwParentClasses; |
| 199 | + $data = "<?php\n\$mwParentClasses = array(\n"; |
| 200 | + foreach( $mwParentClasses as $class => $parent ) { |
| 201 | + $data .= "\t'$class' => '$parent' ),\n"; |
| 202 | + } |
| 203 | + $data .= "\n);\n\n"; |
| 204 | + file_put_contents( $filename, $data ); |
| 205 | + } |
| 206 | + |
185 | 207 | private function initVars() { |
186 | 208 | $this->mProblemCount = 0; |
187 | 209 | |
— | — | @@ -305,6 +327,9 @@ |
306 | 328 | if ( ( $lastMeaningfulToken[0] == T_EXTENDS ) && ( $token[0] == T_STRING ) ) { |
307 | 329 | $this->checkClassName( $token ); |
308 | 330 | $this->mParent = $token[1]; |
| 331 | + if ( $this->getGenerateParentList() ) { |
| 332 | + $mwParentClasses[ $this->mClass ] = $this->mParent; |
| 333 | + } |
309 | 334 | } |
310 | 335 | |
311 | 336 | if ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) { |
— | — | @@ -538,6 +563,14 @@ |
539 | 564 | $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
540 | 565 | continue; |
541 | 566 | } |
| 567 | + if ( substr( $requirePath, -18 ) == "/StartProfiler.php" ) { |
| 568 | + $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
| 569 | + continue; |
| 570 | + } |
| 571 | + if ( strpos( $requirePath, '/wmf-config/' ) !== false ) { |
| 572 | + $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
| 573 | + continue; |
| 574 | + } |
542 | 575 | if ( $requirePath == "Mail.php" ) { # PEAR mail |
543 | 576 | $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING; |
544 | 577 | continue; |
— | — | @@ -618,6 +651,8 @@ |
619 | 652 | } |
620 | 653 | } elseif ( $token[0] == T_STRING && $token[1] == 'DO_MAINTENANCE' ) { |
621 | 654 | $requirePath .= "$IP/maintenance/doMaintenance.php"; |
| 655 | + } elseif ( $token[0] == T_STRING && $token[1] == 'MW_CONFIG_FILE' ) { |
| 656 | + $requirePath .= "$IP/LocalSettings.php"; |
622 | 657 | } else { |
623 | 658 | $requirePath .= $token[1]; |
624 | 659 | } |
— | — | @@ -631,15 +666,23 @@ |
632 | 667 | } |
633 | 668 | |
634 | 669 | function checkDeprecation( $token ) { |
635 | | - global $mwDeprecatedFunctions; |
| 670 | + global $mwDeprecatedFunctions, $mwParentClasses; |
636 | 671 | |
637 | 672 | if ( $mwDeprecatedFunctions && !in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) && |
638 | 673 | isset( $mwDeprecatedFunctions[ $token[1] ] ) ) { |
639 | 674 | |
640 | 675 | if ( isset( $token['class'] ) ) { |
641 | | - if ( in_array( $token['class'], $mwDeprecatedFunctions[ $token[1] ] ) ) { |
642 | | - $this->warning( "Non deprecated function $this->mFunction calls deprecated function {$token['class']}::{$token[1]} in line {$token[2]}" ); |
643 | | - } |
| 676 | + $class = $token['class']; |
| 677 | + do { |
| 678 | + if ( in_array( $class, $mwDeprecatedFunctions[ $token[1] ] ) ) { |
| 679 | + $this->warning( "Non deprecated function $this->mFunction calls deprecated function {$token['class']}::{$token[1]} in line {$token[2]}" ); |
| 680 | + return; |
| 681 | + } |
| 682 | + if ( !isset( $mwParentClasses[ $class ] ) ) { |
| 683 | + return; |
| 684 | + } |
| 685 | + $class = $parentClasses[ $class ]; |
| 686 | + } while( true ); |
644 | 687 | } else if ( isset( $token['base'] ) ) { # Avoid false positives for local functions, see maintenance/rebuildInterwiki.inc |
645 | 688 | $this->warning( "Non deprecated function $this->mFunction may be calling deprecated function " . |
646 | 689 | implode( '/', $mwDeprecatedFunctions[ $token[1] ] ) . "::" . $token[1] . " in line {$token[2]}" ); |
— | — | @@ -910,7 +953,7 @@ |
911 | 954 | } |
912 | 955 | |
913 | 956 | if( $argc < 2 ) { |
914 | | - die ("Usage: php $argv[0] [--generate-deprecated-list] <PHP_source_file1> <PHP_source_file2> ...\n"); |
| 957 | + die ("Usage: php $argv[0] [--generate-deprecated-list] [--generate-parent-list] <PHP_source_file1> <PHP_source_file2> ...\n"); |
915 | 958 | } |
916 | 959 | |
917 | 960 | $cv = new CheckVars(); |
— | — | @@ -920,6 +963,10 @@ |
921 | 964 | $cv->setGenerateDeprecatedList( true ); |
922 | 965 | array_shift( $argv ); |
923 | 966 | } |
| 967 | +if ( $argv[0] == '--generate-parent-list' ) { |
| 968 | + $cv->setGenerateParentList( true ); |
| 969 | + array_shift( $argv ); |
| 970 | +} |
924 | 971 | $cv->preloadFiles( array( $IP . '/includes/GlobalFunctions.php' ) ); |
925 | 972 | |
926 | 973 | foreach ( $argv as $arg ) { |
— | — | @@ -929,3 +976,6 @@ |
930 | 977 | if ( $cv->getGenerateDeprecatedList( ) ) { |
931 | 978 | $cv->saveDeprecatedList( dirname( __FILE__ ) . "/deprecated.functions" ); |
932 | 979 | } |
| 980 | +if ( $cv->getGenerateParentList( ) ) { |
| 981 | + $cv->saveParentList( dirname( __FILE__ ) . "/parent.classes" ); |
| 982 | +} |