Index: trunk/phase3/includes/parser/ParserOptions.php |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | var $mThumbSize; # Thumb size preferred by the user. |
42 | 42 | var $mCleanSignatures; # |
43 | 43 | |
44 | | - var $mUser; # Stored user object, just used to initialise the skin |
| 44 | + var $mUser; # Stored user object |
45 | 45 | var $mIsPreview; # Parsing the page for a "preview" operation |
46 | 46 | var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section |
47 | 47 | var $mIsPrintable; # Parsing the printable version of the page |
— | — | @@ -80,6 +80,7 @@ |
81 | 81 | function getIsSectionPreview() { return $this->mIsSectionPreview; } |
82 | 82 | function getIsPrintable() { $this->accessedOptions['printable'] = true; |
83 | 83 | return $this->mIsPrintable; } |
| 84 | + function getUser() { return $this->mUser; } |
84 | 85 | |
85 | 86 | function getSkin( $title = null ) { |
86 | 87 | if ( !isset( $this->mSkin ) ) { |
Index: trunk/phase3/includes/parser/LinkHolderArray.php |
— | — | @@ -105,9 +105,8 @@ |
106 | 106 | * Get the stub threshold |
107 | 107 | */ |
108 | 108 | function getStubThreshold() { |
109 | | - global $wgUser; |
110 | 109 | if ( !isset( $this->stubThreshold ) ) { |
111 | | - $this->stubThreshold = $wgUser->getStubThreshold(); |
| 110 | + $this->stubThreshold = $this->parent->getUser()->getStubThreshold(); |
112 | 111 | } |
113 | 112 | return $this->stubThreshold; |
114 | 113 | } |
Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -103,6 +103,7 @@ |
104 | 104 | var $mTplExpandCache; # empty-frame expansion cache |
105 | 105 | var $mTplRedirCache, $mTplDomCache, $mHeadings, $mDoubleUnderscores; |
106 | 106 | var $mExpensiveFunctionCount; # number of expensive parser function calls |
| 107 | + var $mUser; # User object; only used when doing pre-save transform |
107 | 108 | |
108 | 109 | # Temporary |
109 | 110 | # These are variables reset at least once per parse regardless of $clearState |
— | — | @@ -110,8 +111,10 @@ |
111 | 112 | var $mTitle; # Title context, used for self-link rendering and similar things |
112 | 113 | var $mOutputType; # Output type, one of the OT_xxx constants |
113 | 114 | var $ot; # Shortcut alias, see setOutputType() |
| 115 | + var $mRevisionObject; # The revision object of the specified revision ID |
114 | 116 | var $mRevisionId; # ID to display in {{REVISIONID}} tags |
115 | 117 | var $mRevisionTimestamp; # The timestamp of the specified revision ID |
| 118 | + var $mRevisionUser; # Userto display in {{REVISIONUSER}} tag |
116 | 119 | var $mRevIdForTs; # The revision ID which was used to fetch the timestamp |
117 | 120 | |
118 | 121 | /** |
— | — | @@ -197,8 +200,10 @@ |
198 | 201 | $this->mInPre = false; |
199 | 202 | $this->mLinkHolders = new LinkHolderArray( $this ); |
200 | 203 | $this->mLinkID = 0; |
201 | | - $this->mRevisionTimestamp = $this->mRevisionId = null; |
| 204 | + $this->mRevisionObject = $this->mRevisionTimestamp = |
| 205 | + $this->mRevisionId = $this->mRevisionUser = null; |
202 | 206 | $this->mVarCache = array(); |
| 207 | + $this->mUser = null; |
203 | 208 | |
204 | 209 | /** |
205 | 210 | * Prefix for temporary replacement strings for the multipass parser. |
— | — | @@ -271,10 +276,14 @@ |
272 | 277 | $this->setTitle( $title ); # Page title has to be set for the pre-processor |
273 | 278 | |
274 | 279 | $oldRevisionId = $this->mRevisionId; |
| 280 | + $oldRevisionObject = $this->mRevisionObject; |
275 | 281 | $oldRevisionTimestamp = $this->mRevisionTimestamp; |
| 282 | + $oldRevisionUser = $this->mRevisionUser; |
276 | 283 | if ( $revid !== null ) { |
277 | 284 | $this->mRevisionId = $revid; |
| 285 | + $this->mRevisionObject = null; |
278 | 286 | $this->mRevisionTimestamp = null; |
| 287 | + $this->mRevisionUser = null; |
279 | 288 | } |
280 | 289 | $this->setOutputType( self::OT_HTML ); |
281 | 290 | wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); |
— | — | @@ -422,7 +431,9 @@ |
423 | 432 | $this->mOutput->setText( $text ); |
424 | 433 | |
425 | 434 | $this->mRevisionId = $oldRevisionId; |
| 435 | + $this->mRevisionObject = $oldRevisionObject; |
426 | 436 | $this->mRevisionTimestamp = $oldRevisionTimestamp; |
| 437 | + $this->mRevisionUser = $oldRevisionUser; |
427 | 438 | wfProfileOut( $fname ); |
428 | 439 | wfProfileOut( __METHOD__ ); |
429 | 440 | |
— | — | @@ -499,6 +510,16 @@ |
500 | 511 | } |
501 | 512 | |
502 | 513 | /** |
| 514 | + * Set the current user. |
| 515 | + * Should only be used when doing pre-save transform. |
| 516 | + * |
| 517 | + * @param $user Mixed: User object or null (to reset) |
| 518 | + */ |
| 519 | + function setUser( $user ) { |
| 520 | + $this->mUser = $user; |
| 521 | + } |
| 522 | + |
| 523 | + /** |
503 | 524 | * Accessor for mUniqPrefix. |
504 | 525 | * |
505 | 526 | * @return String |
— | — | @@ -622,6 +643,18 @@ |
623 | 644 | } |
624 | 645 | |
625 | 646 | /** |
| 647 | + * Get a User object either from $this->mUser, if set, or from the |
| 648 | + * ParserOptions object otherwise |
| 649 | + * |
| 650 | + * @return User object |
| 651 | + */ |
| 652 | + function getUser() { |
| 653 | + if( !is_null( $this->mUser ) ) |
| 654 | + return $this->mUser; |
| 655 | + return $this->mOptions->getUser(); |
| 656 | + } |
| 657 | + |
| 658 | + /** |
626 | 659 | * Get a preprocessor object |
627 | 660 | * |
628 | 661 | * @return Preprocessor instance |
— | — | @@ -1842,7 +1875,7 @@ |
1843 | 1876 | |
1844 | 1877 | if ( $ns == NS_CATEGORY ) { |
1845 | 1878 | wfProfileIn( __METHOD__."-category" ); |
1846 | | - $s = rtrim( $s . "\n" ); # bug 87 |
| 1879 | + $s = preg_replace( "/(\s*\n)+\s*$/D", '', $s ); # bug 87 |
1847 | 1880 | |
1848 | 1881 | if ( $wasblank ) { |
1849 | 1882 | $sortkey = $this->getDefaultSort(); |
— | — | @@ -1858,7 +1891,7 @@ |
1859 | 1892 | * Strip the whitespace Category links produce, see bug 87 |
1860 | 1893 | * @todo We might want to use trim($tmp, "\n") here. |
1861 | 1894 | */ |
1862 | | - $s .= trim( $prefix . $trail, "\n" ) == '' ? '': $prefix . $trail; |
| 1895 | + $s .= trim( $prefix . $trail, "\n" ) == '' ? '' : $prefix . $trail; |
1863 | 1896 | |
1864 | 1897 | wfProfileOut( __METHOD__."-category" ); |
1865 | 1898 | continue; |
— | — | @@ -3995,6 +4028,7 @@ |
3996 | 4029 | $options->resetUsage(); |
3997 | 4030 | $this->mOptions = $options; |
3998 | 4031 | $this->setTitle( $title ); |
| 4032 | + $this->setUser( $user ); |
3999 | 4033 | $this->setOutputType( self::OT_WIKI ); |
4000 | 4034 | |
4001 | 4035 | if ( $clearState ) { |
— | — | @@ -4007,6 +4041,9 @@ |
4008 | 4042 | $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text ); |
4009 | 4043 | $text = $this->pstPass2( $text, $user ); |
4010 | 4044 | $text = $this->mStripState->unstripBoth( $text ); |
| 4045 | + |
| 4046 | + $this->setUser( null ); #Reset |
| 4047 | + |
4011 | 4048 | return $text; |
4012 | 4049 | } |
4013 | 4050 | |
— | — | @@ -4941,31 +4978,43 @@ |
4942 | 4979 | } |
4943 | 4980 | |
4944 | 4981 | /** |
| 4982 | + * Get the revision object for $this->mRevisionId |
| 4983 | + * |
| 4984 | + * @return either a Revision object or null |
| 4985 | + */ |
| 4986 | + protected function getRevisionObject() { |
| 4987 | + if ( !is_null( $this->mRevisionObject ) ) |
| 4988 | + return $this->mRevisionObject; |
| 4989 | + if ( is_null( $this->mRevisionId ) ) |
| 4990 | + return null; |
| 4991 | + |
| 4992 | + $this->mRevisionObject = Revision::newFromId( $this->mRevisionId ); |
| 4993 | + return $this->mRevisionObject; |
| 4994 | + } |
| 4995 | + |
| 4996 | + /** |
4945 | 4997 | * Get the timestamp associated with the current revision, adjusted for |
4946 | 4998 | * the default server-local timestamp |
4947 | 4999 | */ |
4948 | 5000 | function getRevisionTimestamp() { |
4949 | 5001 | if ( is_null( $this->mRevisionTimestamp ) ) { |
4950 | 5002 | wfProfileIn( __METHOD__ ); |
4951 | | - global $wgContLang; |
4952 | | - $dbr = wfGetDB( DB_SLAVE ); |
4953 | | - $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', |
4954 | | - array( 'rev_id' => $this->mRevisionId ), __METHOD__ ); |
4955 | 5003 | |
4956 | | - # Normalize timestamp to internal MW format for timezone processing. |
4957 | | - # This has the added side-effect of replacing a null value with |
4958 | | - # the current time, which gives us more sensible behavior for |
4959 | | - # previews. |
4960 | | - $timestamp = wfTimestamp( TS_MW, $timestamp ); |
| 5004 | + $revObject = $this->getRevisionObject(); |
| 5005 | + $timestamp = $revObject ? $revObject->getTimestamp() : false; |
4961 | 5006 | |
4962 | | - # The cryptic '' timezone parameter tells to use the site-default |
4963 | | - # timezone offset instead of the user settings. |
4964 | | - # |
4965 | | - # Since this value will be saved into the parser cache, served |
4966 | | - # to other users, and potentially even used inside links and such, |
4967 | | - # it needs to be consistent for all visitors. |
4968 | | - $this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' ); |
| 5007 | + if( $timestamp !== false ) { |
| 5008 | + global $wgContLang; |
4969 | 5009 | |
| 5010 | + # The cryptic '' timezone parameter tells to use the site-default |
| 5011 | + # timezone offset instead of the user settings. |
| 5012 | + # |
| 5013 | + # Since this value will be saved into the parser cache, served |
| 5014 | + # to other users, and potentially even used inside links and such, |
| 5015 | + # it needs to be consistent for all visitors. |
| 5016 | + $this->mRevisionTimestamp = $wgContLang->userAdjust( $timestamp, '' ); |
| 5017 | + } |
| 5018 | + |
4970 | 5019 | wfProfileOut( __METHOD__ ); |
4971 | 5020 | } |
4972 | 5021 | return $this->mRevisionTimestamp; |
— | — | @@ -4977,16 +5026,18 @@ |
4978 | 5027 | * @return String: user name |
4979 | 5028 | */ |
4980 | 5029 | function getRevisionUser() { |
4981 | | - # if this template is subst: the revision id will be blank, |
4982 | | - # so just use the current user's name |
4983 | | - if ( $this->mRevisionId ) { |
4984 | | - $revision = Revision::newFromId( $this->mRevisionId ); |
4985 | | - $revuser = $revision->getUserText(); |
4986 | | - } else { |
4987 | | - global $wgUser; |
4988 | | - $revuser = $wgUser->getName(); |
| 5030 | + if( is_null( $this->mRevisionUser ) ) { |
| 5031 | + $revObject = $this->getRevisionObject(); |
| 5032 | + |
| 5033 | + # if this template is subst: the revision id will be blank, |
| 5034 | + # so just use the current user's name |
| 5035 | + if( $revObject ) { |
| 5036 | + $this->mRevisionUser = $revObject->getUserText(); |
| 5037 | + } elseif( $this->ot['wiki'] || $this->mOptions->getIsPreview() ) { |
| 5038 | + $this->mRevisionUser = $this->getUser()->getName(); |
| 5039 | + } |
4989 | 5040 | } |
4990 | | - return $revuser; |
| 5041 | + return $this->mRevisionUser; |
4991 | 5042 | } |
4992 | 5043 | |
4993 | 5044 | /** |
Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -244,13 +244,12 @@ |
245 | 245 | if ( is_object( $title ) && $title->getNamespace() == NS_USER ) |
246 | 246 | $user = $title->getText(); |
247 | 247 | |
248 | | - // check parameter, or use $wgUser if in interface message |
| 248 | + // check parameter, or use the ParserOptions if in interface message |
249 | 249 | $user = User::newFromName( $user ); |
250 | 250 | if ( $user ) { |
251 | 251 | $gender = $user->getOption( 'gender' ); |
252 | 252 | } elseif ( $parser->getOptions()->getInterfaceMessage() ) { |
253 | | - global $wgUser; |
254 | | - $gender = $wgUser->getOption( 'gender' ); |
| 253 | + $gender = $parser->getOptions()->getUser()->getOption( 'gender' ); |
255 | 254 | } |
256 | 255 | $ret = $parser->getFunctionLang()->gender( $gender, $forms ); |
257 | 256 | wfProfileOut( __METHOD__ ); |