r80467 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80466‎ | r80467 | r80468 >
Date:21:40, 17 January 2011
Author:platonides
Status:ok
Tags:
Comment:
Check deprecation from ancestors, too.
Modified paths:
  • /trunk/tools/code-utils/check-vars.php (modified) (history)

Diff [purge]

Index: trunk/tools/code-utils/check-vars.php
@@ -12,12 +12,17 @@
1313
1414 require_once( "$IP/includes/Defines.php" ); # Faster than parsing
1515 require_once( "$IP/includes/AutoLoader.php" );
 16+$wgAutoloadClasses = &$wgAutoloadLocalClasses;
 17+require_once( "$IP/tests/TestsAutoLoader.php" );
1618
1719 $mwDeprecatedFunctions = false;
1820 @include( dirname( __FILE__ ) . "/deprecated.functions" );
 21+$mwParentClasses = array();
 22+@include( dirname( __FILE__ ) . "/parent.classes" );
1923
2024 if ( !extension_loaded( 'sockets' ) ) dl( 'sockets.so' );
2125 if ( !extension_loaded( 'PDO' ) ) dl( 'pdo.so' );
 26+if ( !extension_loaded( 'zip' ) ) dl( 'zip.so' );
2227
2328 $wgAutoloadLocalClasses += array(
2429 'DBAccessError' => 'LBFactory',
@@ -59,7 +64,7 @@
6065 # Ignore functions with these prefixes:
6166 static $functionIgnorePrefixes = array( "pg_", "oci_", "db2_", "gmp_", "sqlsrv_", "exif_", "fss_", "tidy_",
6267 "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_",
6469 # GD and images functions:
6570 "imagecreatetruecolor", "imagecolorallocate", "imagecolortransparent", "imagealphablending",
6671 "imagecopyresized", "imagesx", "imagesy", "imagecopyresampled", "imagesavealpha",
@@ -76,6 +81,7 @@
7782 );
7883
7984 protected $generateDeprecatedList = false;
 85+ protected $generateParentList = false;
8086
8187 /* Values for status */
8288 const WAITING_FUNCTION = 0;
@@ -181,6 +187,22 @@
182188 file_put_contents( $filename, $data );
183189 }
184190
 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+
185207 private function initVars() {
186208 $this->mProblemCount = 0;
187209
@@ -305,6 +327,9 @@
306328 if ( ( $lastMeaningfulToken[0] == T_EXTENDS ) && ( $token[0] == T_STRING ) ) {
307329 $this->checkClassName( $token );
308330 $this->mParent = $token[1];
 331+ if ( $this->getGenerateParentList() ) {
 332+ $mwParentClasses[ $this->mClass ] = $this->mParent;
 333+ }
309334 }
310335
311336 if ( in_array( $token[0], array( T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE ) ) ) {
@@ -538,6 +563,14 @@
539564 $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING;
540565 continue;
541566 }
 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+ }
542575 if ( $requirePath == "Mail.php" ) { # PEAR mail
543576 $this->mStatus = $this->mStatus - self::IN_REQUIRE_WAITING;
544577 continue;
@@ -618,6 +651,8 @@
619652 }
620653 } elseif ( $token[0] == T_STRING && $token[1] == 'DO_MAINTENANCE' ) {
621654 $requirePath .= "$IP/maintenance/doMaintenance.php";
 655+ } elseif ( $token[0] == T_STRING && $token[1] == 'MW_CONFIG_FILE' ) {
 656+ $requirePath .= "$IP/LocalSettings.php";
622657 } else {
623658 $requirePath .= $token[1];
624659 }
@@ -631,15 +666,23 @@
632667 }
633668
634669 function checkDeprecation( $token ) {
635 - global $mwDeprecatedFunctions;
 670+ global $mwDeprecatedFunctions, $mwParentClasses;
636671
637672 if ( $mwDeprecatedFunctions && !in_array( self::FUNCTION_DEPRECATED, $this->mFunctionQualifiers ) &&
638673 isset( $mwDeprecatedFunctions[ $token[1] ] ) ) {
639674
640675 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 );
644687 } else if ( isset( $token['base'] ) ) { # Avoid false positives for local functions, see maintenance/rebuildInterwiki.inc
645688 $this->warning( "Non deprecated function $this->mFunction may be calling deprecated function " .
646689 implode( '/', $mwDeprecatedFunctions[ $token[1] ] ) . "::" . $token[1] . " in line {$token[2]}" );
@@ -910,7 +953,7 @@
911954 }
912955
913956 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");
915958 }
916959
917960 $cv = new CheckVars();
@@ -920,6 +963,10 @@
921964 $cv->setGenerateDeprecatedList( true );
922965 array_shift( $argv );
923966 }
 967+if ( $argv[0] == '--generate-parent-list' ) {
 968+ $cv->setGenerateParentList( true );
 969+ array_shift( $argv );
 970+}
924971 $cv->preloadFiles( array( $IP . '/includes/GlobalFunctions.php' ) );
925972
926973 foreach ( $argv as $arg ) {
@@ -929,3 +976,6 @@
930977 if ( $cv->getGenerateDeprecatedList( ) ) {
931978 $cv->saveDeprecatedList( dirname( __FILE__ ) . "/deprecated.functions" );
932979 }
 980+if ( $cv->getGenerateParentList( ) ) {
 981+ $cv->saveParentList( dirname( __FILE__ ) . "/parent.classes" );
 982+}

Status & tagging log