r106310 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106309‎ | r106310 | r106311 >
Date:07:17, 15 December 2011
Author:bawolff
Status:ok
Tags:
Comment:
Throw an exception if Parser::disableCache is called before mOutput initialized (Aka when not parsing something).

So far I've encountered 2 extensions that give fatal errors from calling $wgParser->disableOutput() from hooks that are called at points where parsing is not taking place! Exception with a backtrace is much nicer than "Fatal error: Call to a member function disableCache() on a non-object..."
Modified paths:
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -5122,6 +5122,10 @@
51235123 */
51245124 function disableCache() {
51255125 wfDebug( "Parser output marked as uncacheable.\n" );
 5126+ if ( !$this->mOutput ) {
 5127+ throw new MWException( __METHOD__ .
 5128+ " can only be called when actually parsing something" );
 5129+ }
51265130 $this->mOutput->setCacheTime( -1 ); // old style, for compatibility
51275131 $this->mOutput->updateCacheExpiry( 0 ); // new style, for consistency
51285132 }

Status & tagging log