Move the math option inside ParserOptions instead of having Math.php directly sneakin...
authorPlatonides <platonides@users.mediawiki.org>
Thu, 5 Aug 2010 15:24:36 +0000 (15:24 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 5 Aug 2010 15:24:36 +0000 (15:24 +0000)
Throw an exception if trying to use the DateFormat ParserOption and the UseDynamicDates option is not set.

includes/Math.php
includes/parser/CoreTagHooks.php
includes/parser/ParserOptions.php

index acf110f..09344af 100644 (file)
@@ -324,10 +324,10 @@ class MathRenderer {
                                        .'/'. substr($this->hash, 2, 1);
        }
 
-       public static function renderMath( $tex, $params=array() ) {
-               global $wgUser;
+       public static function renderMath( $tex, $params=array(), ParserOptions $parserOptions = null ) {
                $math = new MathRenderer( $tex, $params );
-               $math->setOutputMode( $wgUser->getOption('math'));
+               if ( $parserOptions )
+                       $math->setOutputMode( $parserOptions->getMath() );
                return $math->render();
        }
 }
index 7cc8260..422ebac 100644 (file)
@@ -40,7 +40,7 @@ class CoreTagHooks {
 
        static function math( $content, $attributes, $parser ) {
                global $wgContLang;
-               return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes ) );
+               return $wgContLang->armourMath( MathRenderer::renderMath( $content, $attributes, $parser->mOptions ) );
        }
 
        static function gallery( $content, $attributes, $parser ) {
index 977803f..5e4dec5 100644 (file)
@@ -54,6 +54,8 @@ class ParserOptions {
        function getEnableLimitReport()             { return $this->mEnableLimitReport; }
        function getCleanSignatures()               { return $this->mCleanSignatures; }
        function getExternalLinkTarget()            { return $this->mExternalLinkTarget; }
+       function getMath()                          { return $this->mMath; }
+       
        function getIsPreview()                     { return $this->mIsPreview; }
        function getIsSectionPreview()              { return $this->mIsSectionPreview; }
        function getIsPrintable()                   { return $this->mIsPrintable; }
@@ -66,6 +68,10 @@ class ParserOptions {
        }
 
        function getDateFormat() {
+               if ( !$this->getUseDynamicDates() ) {
+                       throw new MWException( 'Getting DateFormat option without UseDynamicDates.' );
+               }
+               
                if ( !isset( $this->mDateFormat ) ) {
                        $this->mDateFormat = $this->mUser->getDatePreference();
                }
@@ -101,6 +107,8 @@ class ParserOptions {
        function setTimestamp( $x )                 { return wfSetVar( $this->mTimestamp, $x ); }
        function setCleanSignatures( $x )           { return wfSetVar( $this->mCleanSignatures, $x ); }
        function setExternalLinkTarget( $x )        { return wfSetVar( $this->mExternalLinkTarget, $x ); }
+       function setMath( $x )                      { return wfSetVar( $this->mMath, $x ); }
+       
        function setIsPreview( $x )                 { return wfSetVar( $this->mIsPreview, $x ); }
        function setIsSectionPreview( $x )          { return wfSetVar( $this->mIsSectionPreview, $x ); }
        function setIsPrintable( $x )               { return wfSetVar( $this->mIsPrintable, $x ); }
@@ -163,6 +171,8 @@ class ParserOptions {
                $this->mEnableLimitReport = false;
                $this->mCleanSignatures = $wgCleanSignatures;
                $this->mExternalLinkTarget = $wgExternalLinkTarget;
+               $this->mMath = $user->getOption( 'math' );
+               
                $this->mIsPreview = false;
                $this->mIsSectionPreview = false;
                $this->mIsPrintable = false;