* Returns a stdclass with source, pst and output members
*/
public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
- global $wgParser, $wgUser;
+ global $wgParser, $wgContLang, $wgUser;
$user = is_null( $user ) ? $wgUser : $user;
// @TODO fixme: check $user->getId() here???
if ( $this->mPreparedEdit
return $this->mPreparedEdit;
}
- $popts = ParserOptions::newFromUser( $user );
+ $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
$edit = (object)array();
* @return ParserOptions
*/
public function makeParserOptions( $user ) {
- global $wgLanguageCode;
+ global $wgContLang;
if ( $user instanceof User ) { // settings per user (even anons)
$options = ParserOptions::newFromUser( $user );
} else { // canonical settings
- $options = ParserOptions::newFromUser( new User );
- $options->setUserLang( $wgLanguageCode ); # Must be set explicitily
+ $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
}
$options->enableLimitReport(); // show inclusion/loop reports
$options->setTidy( true ); // fix bad HTML
* Removes <noinclude> sections, and <includeonly> tags.
*
* Globals used:
- * objects: $wgLang, $wgContLang
+ * object: $wgContLang
*
- * NOT $wgUser or $wgTitle or $wgRequest. Keep them away!
+ * NOT $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away!
*
* settings:
* $wgUseDynamicDates*, $wgInterwikiMagic*,
if ( $target !== null ) {
return $target;
} elseif( $this->mOptions->getInterfaceMessage() ) {
- global $wgLang;
- return $wgLang;
+ return $this->mOptions->getUserLangObj();
} elseif( is_null( $this->mTitle ) ) {
throw new MWException( __METHOD__.': $this->mTitle is null' );
}
$context->setTitle( $title );
$context->setRequest( new FauxRequest( $pageArgs ) );
$context->setUser( $this->getUser() );
- $context->setLang( Language::factory( $this->mOptions->getUserLang() ) );
+ $context->setLang( $this->mOptions->getUserLangObj() );
$ret = SpecialPageFactory::capturePath( $title, $context );
if ( $ret ) {
$text = $context->getOutput()->getHTML();
var $mMath; # User math preference (as integer)
var $mThumbSize; # Thumb size preferred by the user.
private $mStubThreshold; # Maximum article size of an article to be marked as "stub"
- var $mUserLang; # Language code of the User language.
+ var $mUserLang; # Language object of the User language.
/**
* @var User
* You shouldn't use this. Really. $parser->getFunctionLang() is all you need.
* Using this fragments the cache and is discouraged. Yes, {{int: }} uses this,
* producing inconsistent tables (Bug 14404).
+ *
+ * @return Language object
+ * @since 1.19
+ */
+ function getUserLangObj() {
+ $this->optionUsed( 'userlang' );
+ return $this->mUserLang;
+ }
+
+ /**
+ * Same as getUserLangObj() but returns a string instead.
+ *
* @return String Language code
* @since 1.17
*/
function getUserLang() {
- $this->optionUsed( 'userlang' );
- return $this->mUserLang;
+ return $this->getUserLangObj()->getCode();
}
function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); }
function setMath( $x ) { return wfSetVar( $this->mMath, $x ); }
function setUserLang( $x ) {
- if ( $x instanceof Language ) {
- $x = $x->getCode();
+ if ( is_string( $x ) ) {
+ $x = Language::factory( $x );
}
return wfSetVar( $this->mUserLang, $x );
}
$this->mExtraKey .= '!' . $key;
}
- function __construct( $user = null ) {
- $this->initialiseFromUser( $user );
+ function __construct( $user = null, $lang = null ) {
+ if ( $user === null ) {
+ global $wgUser;
+ if ( $wgUser === null ) {
+ $user = new User;
+ } else {
+ $user = $wgUser;
+ }
+ }
+ if ( $lang === null ) {
+ global $wgLang;
+ $lang = $wgLang;
+ }
+ $this->initialiseFromUser( $user, $lang );
}
/**
- * Get parser options
+ * Get a ParserOptions object from a given user.
+ * Language will be taken from $wgLang.
*
* @param $user User object
* @return ParserOptions object
*/
- static function newFromUser( $user ) {
+ public static function newFromUser( $user ) {
return new ParserOptions( $user );
}
- /** Get user options */
- function initialiseFromUser( $userInput ) {
- global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
- global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize;
- global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures;
- global $wgExternalLinkTarget, $wgLang;
+ /**
+ * Get a ParserOptions object from a given user and language
+ *
+ * @param $user User object
+ * @param $lang Language object
+ * @return ParserOptions object
+ */
+ public static function newFromUserAndLang( User $user, Language $lang ) {
+ return new ParserOptions( $user, $lang );
+ }
- wfProfileIn( __METHOD__ );
+ /**
+ * Get a ParserOptions object from a IContextSource object
+ *
+ * @param $context IContextSource object
+ * @return ParserOptions object
+ */
+ public static function newFromContext( IContextSource $context ) {
+ return new ParserOptions( $context->getUser(), $context->getLang() );
+ }
- if ( !$userInput ) {
- global $wgUser;
- if ( isset( $wgUser ) ) {
- $user = $wgUser;
- } else {
- $user = new User;
- }
- } else {
- $user =& $userInput;
- }
+ /** Get user options */
+ private function initialiseFromUser( $user, $lang ) {
+ global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages,
+ $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion,
+ $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth,
+ $wgCleanSignatures, $wgExternalLinkTarget;
- $this->mUser = $user;
+ wfProfileIn( __METHOD__ );
$this->mUseDynamicDates = $wgUseDynamicDates;
$this->mInterwikiMagic = $wgInterwikiMagic;
$this->mCleanSignatures = $wgCleanSignatures;
$this->mExternalLinkTarget = $wgExternalLinkTarget;
+ $this->mUser = $user;
$this->mNumberHeadings = $user->getOption( 'numberheadings' );
$this->mMath = $user->getOption( 'math' );
$this->mThumbSize = $user->getOption( 'thumbsize' );
$this->mStubThreshold = $user->getStubThreshold();
- $this->mUserLang = $wgLang->getCode();
+ $this->mUserLang = $lang;
wfProfileOut( __METHOD__ );
}
}
if ( in_array( 'userlang', $forOptions ) ) {
- $confstr .= '!' . $this->mUserLang;
+ $confstr .= '!' . $this->mUserLang->getCode();
} else {
$confstr .= '!*';
}