r92958 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92957‎ | r92958 | r92959 >
Date:19:50, 23 July 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Changed Maintenance::shouldExecute() to allow for multiple requires() in the stack. This avoids failing over requires due to Het wrappers.
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/Maintenance.php
@@ -133,18 +133,25 @@
134134 /**
135135 * Should we execute the maintenance script, or just allow it to be included
136136 * as a standalone class? It checks that the call stack only includes this
137 - * function and a require (meaning was called from the file scope)
 137+ * function and "requires" (meaning was called from the file scope)
138138 *
139139 * @return Boolean
140140 */
141141 public static function shouldExecute() {
142142 $bt = debug_backtrace();
143 - if( count( $bt ) !== 2 ) {
144 - return false;
 143+ if ( count( $bt ) < 2 ) {
 144+ return false; // sanity
145145 }
146 - return in_array( $bt[1]['function'], array( 'require_once', 'require', 'include' ) ) &&
147 - $bt[0]['class'] == 'Maintenance' &&
148 - $bt[0]['function'] == 'shouldExecute';
 146+ if ( $bt[0]['class'] !== 'Maintenance' || $bt[0]['function'] !== 'shouldExecute' ) {
 147+ return false; // last call should be to this function
 148+ }
 149+ $includeFuncs = array( 'require_once', 'require', 'include' );
 150+ for( $i=1; $i < count( $bt ); $i++ ) {
 151+ if ( !in_array( $bt[$i]['function'], $includeFuncs ) ) {
 152+ return false; // previous calls should all be "requires"
 153+ }
 154+ }
 155+ return true;
149156 }
150157
151158 /**

Sign-offs

UserFlagDate
Aaron Schulztested19:39, 25 July 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r93099MFT r92958 (handled conflict)aaron19:57, 25 July 2011
r93426MFT to REL1_18...hashar20:20, 28 July 2011

Comments

#Comment by 😂 (talk | contribs)   19:52, 25 July 2011

Two minor things, otherwise this is ok:

  • We should probably add include_once, just for safety. That was my fault anyway, you just copied it.
  • Move the count() near the beginning and reuse it

Status & tagging log