Throw an exception if Parser::disableCache is called before mOutput initialized ...
authorBrian Wolff <bawolff@users.mediawiki.org>
Thu, 15 Dec 2011 07:17:29 +0000 (07:17 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Thu, 15 Dec 2011 07:17:29 +0000 (07:17 +0000)
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..."

includes/parser/Parser.php

index ca02d6b..3c3d59d 100644 (file)
@@ -5122,6 +5122,10 @@ class Parser {
         */
        function disableCache() {
                wfDebug( "Parser output marked as uncacheable.\n" );
+               if ( !$this->mOutput ) {
+                       throw new MWException( __METHOD__ .
+                               " can only be called when actually parsing something" );
+               }
                $this->mOutput->setCacheTime( -1 ); // old style, for compatibility
                $this->mOutput->updateCacheExpiry( 0 ); // new style, for consistency
        }