r93099 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93098‎ | r93099 | r93100 >
Date:19:57, 25 July 2011
Author:aaron
Status:ok
Tags:
Comment:
MFT r92958 (handled conflict)
Modified paths:
  • /branches/wmf/1.17wmf1/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/maintenance/Maintenance.php
@@ -121,18 +121,25 @@
122122 /**
123123 * Should we execute the maintenance script, or just allow it to be included
124124 * as a standalone class? It checks that the call stack only includes this
125 - * function and a require (meaning was called from the file scope)
 125+ * function and "requires" (meaning was called from the file scope)
126126 *
127127 * @return Boolean
128128 */
129129 public static function shouldExecute() {
130130 $bt = debug_backtrace();
131 - if( count( $bt ) !== 2 ) {
132 - return false;
 131+ if ( count( $bt ) < 2 ) {
 132+ return false; // sanity
133133 }
134 - return $bt[1]['function'] == 'require_once' &&
135 - $bt[0]['class'] == 'Maintenance' &&
136 - $bt[0]['function'] == 'shouldExecute';
 134+ if ( $bt[0]['class'] !== 'Maintenance' || $bt[0]['function'] !== 'shouldExecute' ) {
 135+ return false; // last call should be to this function
 136+ }
 137+ $includeFuncs = array( 'require_once', 'require', 'include' );
 138+ for( $i=1; $i < count( $bt ); $i++ ) {
 139+ if ( !in_array( $bt[$i]['function'], $includeFuncs ) ) {
 140+ return false; // previous calls should all be "requires"
 141+ }
 142+ }
 143+ return true;
137144 }
138145
139146 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92958Changed Maintenance::shouldExecute() to allow for multiple requires() in the ...aaron19:50, 23 July 2011

Status & tagging log