Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -32,9 +32,9 @@ |
33 | 33 | * Removes <noinclude> sections, and <includeonly> tags. |
34 | 34 | * |
35 | 35 | * Globals used: |
36 | | - * objects: $wgLang, $wgContLang |
| 36 | + * object: $wgContLang |
37 | 37 | * |
38 | | - * NOT $wgUser or $wgTitle or $wgRequest. Keep them away! |
| 38 | + * NOT $wgUser or $wgTitle or $wgRequest or $wgLang. Keep them away! |
39 | 39 | * |
40 | 40 | * settings: |
41 | 41 | * $wgUseDynamicDates*, $wgInterwikiMagic*, |
— | — | @@ -698,8 +698,7 @@ |
699 | 699 | if ( $target !== null ) { |
700 | 700 | return $target; |
701 | 701 | } elseif( $this->mOptions->getInterfaceMessage() ) { |
702 | | - global $wgLang; |
703 | | - return $wgLang; |
| 702 | + return $this->mOptions->getUserLangObj(); |
704 | 703 | } elseif( is_null( $this->mTitle ) ) { |
705 | 704 | throw new MWException( __METHOD__.': $this->mTitle is null' ); |
706 | 705 | } |
— | — | @@ -3237,7 +3236,7 @@ |
3238 | 3237 | $context->setTitle( $title ); |
3239 | 3238 | $context->setRequest( new FauxRequest( $pageArgs ) ); |
3240 | 3239 | $context->setUser( $this->getUser() ); |
3241 | | - $context->setLang( Language::factory( $this->mOptions->getUserLang() ) ); |
| 3240 | + $context->setLang( $this->mOptions->getUserLangObj() ); |
3242 | 3241 | $ret = SpecialPageFactory::capturePath( $title, $context ); |
3243 | 3242 | if ( $ret ) { |
3244 | 3243 | $text = $context->getOutput()->getHTML(); |
Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | static function intFunction( $parser, $part1 = '' /*, ... */ ) { |
99 | 99 | if ( strval( $part1 ) !== '' ) { |
100 | 100 | $args = array_slice( func_get_args(), 2 ); |
101 | | - $message = wfMessage( $part1, $args )->inLanguage( $parser->getOptions()->getUserLang() )->plain(); |
| 101 | + $message = wfMessage( $part1, $args )->inLanguage( $parser->getOptions()->getUserLangObj() )->plain(); |
102 | 102 | $message = $parser->replaceVariables( $message ); // like MessageCache::transform() |
103 | 103 | return $message; |
104 | 104 | } else { |
Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | var $mMath; # User math preference (as integer) |
43 | 43 | var $mThumbSize; # Thumb size preferred by the user. |
44 | 44 | private $mStubThreshold; # Maximum article size of an article to be marked as "stub" |
45 | | - var $mUserLang; # Language code of the User language. |
| 45 | + var $mUserLang; # Language object of the User language. |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var User |
— | — | @@ -119,12 +119,23 @@ |
120 | 120 | * You shouldn't use this. Really. $parser->getFunctionLang() is all you need. |
121 | 121 | * Using this fragments the cache and is discouraged. Yes, {{int: }} uses this, |
122 | 122 | * producing inconsistent tables (Bug 14404). |
| 123 | + * |
| 124 | + * @return Language object |
| 125 | + * @since 1.19 |
| 126 | + */ |
| 127 | + function getUserLangObj() { |
| 128 | + $this->optionUsed( 'userlang' ); |
| 129 | + return $this->mUserLang; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Same as getUserLangObj() but returns a string instead. |
| 134 | + * |
123 | 135 | * @return String Language code |
124 | 136 | * @since 1.17 |
125 | 137 | */ |
126 | 138 | function getUserLang() { |
127 | | - $this->optionUsed( 'userlang' ); |
128 | | - return $this->mUserLang; |
| 139 | + return $this->getUserLangObj()->getCode(); |
129 | 140 | } |
130 | 141 | |
131 | 142 | function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); } |
— | — | @@ -153,8 +164,8 @@ |
154 | 165 | function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } |
155 | 166 | function setMath( $x ) { return wfSetVar( $this->mMath, $x ); } |
156 | 167 | function setUserLang( $x ) { |
157 | | - if ( $x instanceof Language ) { |
158 | | - $x = $x->getCode(); |
| 168 | + if ( is_string( $x ) ) { |
| 169 | + $x = Language::factory( $x ); |
159 | 170 | } |
160 | 171 | return wfSetVar( $this->mUserLang, $x ); |
161 | 172 | } |
— | — | @@ -173,42 +184,63 @@ |
174 | 185 | $this->mExtraKey .= '!' . $key; |
175 | 186 | } |
176 | 187 | |
177 | | - function __construct( $user = null ) { |
178 | | - $this->initialiseFromUser( $user ); |
| 188 | + function __construct( $user = null, $lang = null ) { |
| 189 | + if ( $user === null ) { |
| 190 | + global $wgUser; |
| 191 | + if ( $wgUser === null ) { |
| 192 | + $user = new User; |
| 193 | + } else { |
| 194 | + $user = $wgUser; |
| 195 | + } |
| 196 | + } |
| 197 | + if ( $lang === null ) { |
| 198 | + global $wgLang; |
| 199 | + $lang = $wgLang; |
| 200 | + } |
| 201 | + $this->initialiseFromUser( $user, $lang ); |
179 | 202 | } |
180 | 203 | |
181 | 204 | /** |
182 | | - * Get parser options |
| 205 | + * Get a ParserOptions object from a given user. |
| 206 | + * Language will be taken from $wgLang. |
183 | 207 | * |
184 | 208 | * @param $user User object |
185 | 209 | * @return ParserOptions object |
186 | 210 | */ |
187 | | - static function newFromUser( $user ) { |
| 211 | + public static function newFromUser( $user ) { |
188 | 212 | return new ParserOptions( $user ); |
189 | 213 | } |
190 | 214 | |
| 215 | + /** |
| 216 | + * Get a ParserOptions object from a given user and language |
| 217 | + * |
| 218 | + * @param $user User object |
| 219 | + * @param $lang Language object |
| 220 | + * @return ParserOptions object |
| 221 | + */ |
| 222 | + public static function newFromUserAndLang( User $user, Language $lang ) { |
| 223 | + return new ParserOptions( $user, $lang ); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Get a ParserOptions object from a IContextSource object |
| 228 | + * |
| 229 | + * @param $context IContextSource object |
| 230 | + * @return ParserOptions object |
| 231 | + */ |
| 232 | + public static function newFromContext( IContextSource $context ) { |
| 233 | + return new ParserOptions( $context->getUser(), $context->getLang() ); |
| 234 | + } |
| 235 | + |
191 | 236 | /** Get user options */ |
192 | | - function initialiseFromUser( $userInput ) { |
193 | | - global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; |
194 | | - global $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, $wgMaxArticleSize; |
195 | | - global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, $wgCleanSignatures; |
196 | | - global $wgExternalLinkTarget, $wgLang; |
| 237 | + private function initialiseFromUser( $user, $lang ) { |
| 238 | + global $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages, |
| 239 | + $wgAllowExternalImagesFrom, $wgEnableImageWhitelist, $wgAllowSpecialInclusion, |
| 240 | + $wgMaxArticleSize, $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth, |
| 241 | + $wgCleanSignatures, $wgExternalLinkTarget; |
197 | 242 | |
198 | 243 | wfProfileIn( __METHOD__ ); |
199 | 244 | |
200 | | - if ( !$userInput ) { |
201 | | - global $wgUser; |
202 | | - if ( isset( $wgUser ) ) { |
203 | | - $user = $wgUser; |
204 | | - } else { |
205 | | - $user = new User; |
206 | | - } |
207 | | - } else { |
208 | | - $user =& $userInput; |
209 | | - } |
210 | | - |
211 | | - $this->mUser = $user; |
212 | | - |
213 | 245 | $this->mUseDynamicDates = $wgUseDynamicDates; |
214 | 246 | $this->mInterwikiMagic = $wgInterwikiMagic; |
215 | 247 | $this->mAllowExternalImages = $wgAllowExternalImages; |
— | — | @@ -222,11 +254,12 @@ |
223 | 255 | $this->mCleanSignatures = $wgCleanSignatures; |
224 | 256 | $this->mExternalLinkTarget = $wgExternalLinkTarget; |
225 | 257 | |
| 258 | + $this->mUser = $user; |
226 | 259 | $this->mNumberHeadings = $user->getOption( 'numberheadings' ); |
227 | 260 | $this->mMath = $user->getOption( 'math' ); |
228 | 261 | $this->mThumbSize = $user->getOption( 'thumbsize' ); |
229 | 262 | $this->mStubThreshold = $user->getStubThreshold(); |
230 | | - $this->mUserLang = $wgLang->getCode(); |
| 263 | + $this->mUserLang = $lang; |
231 | 264 | |
232 | 265 | wfProfileOut( __METHOD__ ); |
233 | 266 | } |
— | — | @@ -312,7 +345,7 @@ |
313 | 346 | } |
314 | 347 | |
315 | 348 | if ( in_array( 'userlang', $forOptions ) ) { |
316 | | - $confstr .= '!' . $this->mUserLang; |
| 349 | + $confstr .= '!' . $this->mUserLang->getCode(); |
317 | 350 | } else { |
318 | 351 | $confstr .= '!*'; |
319 | 352 | } |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -1249,7 +1249,7 @@ |
1250 | 1250 | */ |
1251 | 1251 | public function parserOptions( $options = null ) { |
1252 | 1252 | if ( !$this->mParserOptions ) { |
1253 | | - $this->mParserOptions = new ParserOptions; |
| 1253 | + $this->mParserOptions = ParserOptions::newFromContext( $this->getContext() ); |
1254 | 1254 | $this->mParserOptions->setEditSection( false ); |
1255 | 1255 | } |
1256 | 1256 | return wfSetVar( $this->mParserOptions, $options ); |
Index: trunk/phase3/includes/installer/Installer.php |
— | — | @@ -1202,7 +1202,7 @@ |
1203 | 1203 | */ |
1204 | 1204 | public function setParserLanguage( $lang ) { |
1205 | 1205 | $this->parserOptions->setTargetLanguage( $lang ); |
1206 | | - $this->parserOptions->setUserLang( $lang->getCode() ); |
| 1206 | + $this->parserOptions->setUserLang( $lang ); |
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | /** |
Index: trunk/phase3/includes/WikiPage.php |
— | — | @@ -1950,7 +1950,7 @@ |
1951 | 1951 | * Returns a stdclass with source, pst and output members |
1952 | 1952 | */ |
1953 | 1953 | public function prepareTextForEdit( $text, $revid = null, User $user = null ) { |
1954 | | - global $wgParser, $wgUser; |
| 1954 | + global $wgParser, $wgContLang, $wgUser; |
1955 | 1955 | $user = is_null( $user ) ? $wgUser : $user; |
1956 | 1956 | // @TODO fixme: check $user->getId() here??? |
1957 | 1957 | if ( $this->mPreparedEdit |
— | — | @@ -1961,7 +1961,7 @@ |
1962 | 1962 | return $this->mPreparedEdit; |
1963 | 1963 | } |
1964 | 1964 | |
1965 | | - $popts = ParserOptions::newFromUser( $user ); |
| 1965 | + $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang ); |
1966 | 1966 | wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) ); |
1967 | 1967 | |
1968 | 1968 | $edit = (object)array(); |
— | — | @@ -2507,12 +2507,11 @@ |
2508 | 2508 | * @return ParserOptions |
2509 | 2509 | */ |
2510 | 2510 | public function makeParserOptions( $user ) { |
2511 | | - global $wgLanguageCode; |
| 2511 | + global $wgContLang; |
2512 | 2512 | if ( $user instanceof User ) { // settings per user (even anons) |
2513 | 2513 | $options = ParserOptions::newFromUser( $user ); |
2514 | 2514 | } else { // canonical settings |
2515 | | - $options = ParserOptions::newFromUser( new User ); |
2516 | | - $options->setUserLang( $wgLanguageCode ); # Must be set explicitily |
| 2515 | + $options = ParserOptions::newFromUserAndLang( new User, $wgContLang ); |
2517 | 2516 | } |
2518 | 2517 | $options->enableLimitReport(); // show inclusion/loop reports |
2519 | 2518 | $options->setTidy( true ); // fix bad HTML |
Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -305,7 +305,7 @@ |
306 | 306 | } |
307 | 307 | |
308 | 308 | // show a preview of the old signature first |
309 | | - $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, new ParserOptions ); |
| 309 | + $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions::newFromContext( $context ) ); |
310 | 310 | $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true ); |
311 | 311 | $defaultPreferences['oldsig'] = array( |
312 | 312 | 'type' => 'info', |