add Article::setParserOptions
authordaniel <daniel.kinzler@wikimedia.de>
Mon, 6 Aug 2012 13:55:52 +0000 (15:55 +0200)
committerdaniel <daniel.kinzler@wikimedia.de>
Tue, 7 Aug 2012 17:02:24 +0000 (19:02 +0200)
Change-Id: Ica1c0a3c4b5b569c4911d4c1fb0167812f932c20

includes/Article.php

index ec05491..6b2bd4c 100644 (file)
@@ -1699,11 +1699,25 @@ class Article extends Page {
         */
        public function getParserOutput( $oldid = null, User $user = null ) {
                $user = is_null( $user ) ? $this->getContext()->getUser() : $user;
-               $parserOptions = $this->mPage->makeParserOptions( $user );
+               $parserOptions = $this->mPage->makeParserOptions( $user ); //XXX: bypasses mParserOptions and thus setParserOptions()
 
                return $this->mPage->getParserOutput( $parserOptions, $oldid );
        }
 
+       /**
+        * Override the ParserOptions used to render the primary article wikitext.
+        *
+        * @param ParserOptions $options
+        * @throws MWException if the parser options where already initialized.
+        */
+       public function setParserOptions( ParserOptions $options ) {
+               if ( $this->mParserOptions ) {
+                       throw new MWException( "can't change parser options after they have already been set" );
+               }
+
+               $this->mParserOptions = clone $options; // clone, so if $options is modified later, it doesn't confuse the parser cache.
+       }
+
        /**
         * Get parser options suitable for rendering the primary article wikitext
         * @return ParserOptions