Index: trunk/tools/code-utils/check-vars.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | require_once( "$IP/includes/Defines.php" ); # Faster than parsing |
15 | 15 | require_once( "$IP/includes/AutoLoader.php" ); |
16 | 16 | $wgAutoloadClasses = &$wgAutoloadLocalClasses; |
17 | | -require_once( "$IP/tests/TestsAutoLoader.php" ); |
| 17 | +include_once( "$IP/tests/TestsAutoLoader.php" ); |
18 | 18 | |
19 | 19 | $mwDeprecatedFunctions = false; |
20 | 20 | @include( dirname( __FILE__ ) . "/deprecated.functions" ); |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | function saveDeprecatedList( $filename ) { |
203 | 203 | $data = "<?php\n\$mwDeprecatedFunctions = array(\n"; |
204 | 204 | foreach( $this->mDeprecatedFunctionList as $depre => $classes ) { |
205 | | - $data .= "\t'$depre' => array( " . implode( ", ", $classes ) . " ),\n"; |
| 205 | + $data .= "\t'$depre' => array( '" . implode( "', '", $classes ) . "' ),\n"; |
206 | 206 | } |
207 | 207 | $data .= "\n);\n\n"; |
208 | 208 | file_put_contents( $filename, $data ); |
— | — | @@ -217,7 +217,7 @@ |
218 | 218 | global $mwParentClasses; |
219 | 219 | $data = "<?php\n\$mwParentClasses = array(\n"; |
220 | 220 | foreach( $mwParentClasses as $class => $parent ) { |
221 | | - $data .= "\t'$class' => '$parent' ),\n"; |
| 221 | + $data .= "\t'$class' => '$parent' ,\n"; |
222 | 222 | } |
223 | 223 | $data .= "\n);\n\n"; |
224 | 224 | file_put_contents( $filename, $data ); |
— | — | @@ -348,6 +348,7 @@ |
349 | 349 | $this->checkClassName( $token ); |
350 | 350 | $this->mParent = $token[1]; |
351 | 351 | if ( $this->getGenerateParentList() ) { |
| 352 | + global $mwParentClasses; |
352 | 353 | $mwParentClasses[ $this->mClass ] = $this->mParent; |
353 | 354 | } |
354 | 355 | } |
— | — | @@ -371,6 +372,8 @@ |
372 | 373 | $this->mStatus = self::IN_FUNCTION; |
373 | 374 | $this->mBraces = 0; |
374 | 375 | $this->mInSwitch = 0; |
| 376 | + $this->mInProfilingFunction = false; |
| 377 | + $this->mAfterProfileOut = 0; |
375 | 378 | $this->mFunctionGlobals = array(); |
376 | 379 | $currentToken[0] = self::FUNCTION_DEFINITION; |
377 | 380 | $this->mKnownFunctions[] = $this->mClass ? $this->mClass . "::" . $this->mFunction : $this->mFunction; |
— | — | @@ -409,9 +412,22 @@ |
410 | 413 | |
411 | 414 | $this->purgeGlobals(); |
412 | 415 | if ( ! $this->mBraces ) { |
| 416 | + if ( $this->mInProfilingFunction && $this->mAfterProfileOut & 1 ) { |
| 417 | + $this->warning( "Reached end of $this->mClass::$this->mFunction with last statement not being wfProfileOut" ); |
| 418 | + } |
| 419 | + |
413 | 420 | $this->mStatus = self::WAITING_FUNCTION; |
414 | 421 | $this->mFunctionQualifiers = array(); |
415 | 422 | } |
| 423 | + } elseif ( $token == ';' && $this->mInProfilingFunction ) { |
| 424 | + // Check that there's just a return after wfProfileOut. |
| 425 | + if ( $this->mAfterProfileOut == 1 ) { |
| 426 | + $this->mAfterProfileOut = 2; |
| 427 | + } elseif ( $this->mAfterProfileOut == 2 ) { |
| 428 | + // Set to 3 in order to bail out at the return. |
| 429 | + // This way we don't complay about missing return in internal wfProfile sections. |
| 430 | + $this->mAfterProfileOut = 3; |
| 431 | + } |
416 | 432 | } elseif ( is_array ( $token ) ) { |
417 | 433 | if ( $token[0] == T_GLOBAL ) { |
418 | 434 | $this->mStatus = self::IN_GLOBAL; |
— | — | @@ -443,6 +459,12 @@ |
444 | 460 | $this->warning( "{$token[1]} is used as local variable in line $token[2], function {$this->mFunction}" ); |
445 | 461 | } |
446 | 462 | } |
| 463 | + } elseif ( $token[0] == T_RETURN && $this->mInProfilingFunction ) { |
| 464 | + if ( $this->mAfterProfileOut == 2 ) { |
| 465 | + $this->mAfterProfileOut = 0; |
| 466 | + } else { |
| 467 | + $this->warning( "$token[1] in line $token[2] is not preceded by wfProfileOut" ); |
| 468 | + } |
447 | 469 | } elseif ( $token[0] == T_FUNCTION ) { |
448 | 470 | $this->warning( "Uh? Function inside function? A lamda function?" ); |
449 | 471 | $this->error( $token ); |
— | — | @@ -472,7 +494,7 @@ |
473 | 495 | |
474 | 496 | if ( self::isMeaningfulToken( $token ) && ( $lastMeaningfulToken[0] == T_THROW ) ) { |
475 | 497 | if ( $token[0] == T_VARIABLE ) { |
476 | | - // Probbly rethrowing from a catch, skip |
| 498 | + // Probably rethrowing from a catch, skip |
477 | 499 | } elseif ( $token[0] == T_NEW ) { |
478 | 500 | // Correct, a new class instance |
479 | 501 | // TODO: Verify it inherits from Exception |
— | — | @@ -501,6 +523,19 @@ |
502 | 524 | $lastMeaningfulToken[0] = self::FUNCTION_NAME; |
503 | 525 | $this->checkDeprecation( $lastMeaningfulToken ); |
504 | 526 | $this->checkFunctionName( $lastMeaningfulToken ); |
| 527 | + if ( $lastMeaningfulToken[1] == 'wfProfileIn' ) { |
| 528 | + $this->mInProfilingFunction = true; |
| 529 | + $this->mAfterProfileOut = 0; |
| 530 | + } elseif ( $lastMeaningfulToken[1] == 'wfProfileOut' ) { |
| 531 | + global $mwParentClasses;//echo "wfProfileOut $this->mClass " . ( isset( $mwParentClasses[ $this->mClass ] ) ? $mwParentClasses[ $this->mClass ] : "" ). "\n"; |
| 532 | + if ( ( isset( $mwParentClasses[ $this->mClass ] ) && $mwParentClasses[ $this->mClass ] == 'ImageHandler') || |
| 533 | + ( $this->mClass == 'Hooks' && $this->mFunction == 'run' ) ) { |
| 534 | + // Do not treat as profiling any more. ImageHandler sons have profile sections just for their wfShellExec(). wfRunHooks profiles each hook. |
| 535 | + $this->mInProfilingFunction = false; |
| 536 | + } else { |
| 537 | + $this->mAfterProfileOut = 1; |
| 538 | + } |
| 539 | + } |
505 | 540 | } else if ( $lastMeaningfulToken[0] == self::CLASS_MEMBER ) { |
506 | 541 | $this->checkDeprecation( $lastMeaningfulToken ); |
507 | 542 | } |
— | — | @@ -701,7 +736,7 @@ |
702 | 737 | if ( !isset( $mwParentClasses[ $class ] ) ) { |
703 | 738 | return; |
704 | 739 | } |
705 | | - $class = $parentClasses[ $class ]; |
| 740 | + $class = $mwParentClasses[ $class ]; |
706 | 741 | } while( true ); |
707 | 742 | } else if ( isset( $token['base'] ) ) { # Avoid false positives for local functions, see maintenance/rebuildInterwiki.inc |
708 | 743 | $this->warning( "Non deprecated function $this->mFunction may be calling deprecated function " . |