From 3b8b3fd067b4d1483f1482101a85b14ee64b47f5 Mon Sep 17 00:00:00 2001 From: Platonides Date: Thu, 5 Aug 2010 15:24:36 +0000 Subject: [PATCH] Move the math option inside ParserOptions instead of having Math.php directly sneaking into $wgUser. Throw an exception if trying to use the DateFormat ParserOption and the UseDynamicDates option is not set. --- includes/Math.php | 6 +++--- includes/parser/CoreTagHooks.php | 2 +- includes/parser/ParserOptions.php | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/includes/Math.php b/includes/Math.php index acf110fb09..09344afcf8 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -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(); } } diff --git a/includes/parser/CoreTagHooks.php b/includes/parser/CoreTagHooks.php index 7cc8260eb0..422ebaca3d 100644 --- a/includes/parser/CoreTagHooks.php +++ b/includes/parser/CoreTagHooks.php @@ -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 ) { diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 977803f55c..5e4dec5f5d 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -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; -- 2.20.1