r36093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36092‎ | r36093 | r36094 >
Date:17:57, 9 June 2008
Author:ialex
Status:old
Tags:
Comment:
Some tweaks to the {{int:...}} parser function:
* Respect the language given with parser options
* Replace parameters before expanding its own templates/functions, like $wgOut->addWikiMsg() does
* (bug 14404) Force content language when parsing the text to pass to LinksUpdate

And some tweaks at save time:
* Use an anonymous user to get the parser options and the parser cache key, thus wikitext rendering is not depending of some sepcific user options such as lang, ...
* Same for the refresh link job
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/ParserCache.php (modified) (history)
  • /trunk/phase3/includes/ParserOptions.php (modified) (history)
  • /trunk/phase3/includes/RefreshLinksJob.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -2334,11 +2334,13 @@
23352335 * which will give them a chance to modify this key based on their own
23362336 * settings.
23372337 *
 2338+ * @param $content Bool: wheter use the content language to generate the
 2339+ * hash
23382340 * @return string
23392341 */
2340 - function getPageRenderingHash() {
 2342+ function getPageRenderingHash( $content = false ) {
23412343 global $wgContLang, $wgUseDynamicDates, $wgLang;
2342 - if( $this->mHash ){
 2344+ if( $this->mHash && !$content ){
23432345 return $this->mHash;
23442346 }
23452347
@@ -2351,7 +2353,11 @@
23522354 $confstr .= '!' . $this->getDatePreference();
23532355 }
23542356 $confstr .= '!' . ($this->getOption( 'numberheadings' ) ? '1' : '');
2355 - $confstr .= '!' . $wgLang->getCode();
 2357+ if( $content ){
 2358+ $confstr .= '!' . $wgContLang->getCode();
 2359+ } else {
 2360+ $confstr .= '!' . $wgLang->getCode();
 2361+ }
23562362 $confstr .= '!' . $this->getOption( 'thumbsize' );
23572363 // add in language specific options, if any
23582364 $extra = $wgContLang->getExtraHashOptions();
Index: trunk/phase3/includes/Article.php
@@ -541,9 +541,9 @@
542542 */
543543 function isRedirect( $text = false ) {
544544 if ( $text === false ) {
545 - if ( $this->mDataLoaded )
 545+ if ( $this->mDataLoaded )
546546 return $this->mIsRedirect;
547 -
 547+
548548 // Apparently loadPageData was never called
549549 $this->loadContent();
550550 $titleObj = Title::newFromRedirect( $this->fetchContent() );
@@ -922,14 +922,14 @@
923923 $this->viewUpdates();
924924 wfProfileOut( __METHOD__ );
925925 }
926 -
 926+
927927 protected function viewRedirect( $target, $overwriteSubtitle = true, $forceKnown = false ) {
928928 global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser;
929 -
 929+
930930 # Display redirect
931931 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
932932 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
933 -
 933+
934934 if( $overwriteSubtitle ) {
935935 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
936936 }
@@ -941,7 +941,7 @@
942942
943943 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
944944 '<span class="redirectText">'.$link.'</span>' );
945 -
 945+
946946 }
947947
948948 function addTrackbacks() {
@@ -1449,7 +1449,7 @@
14501450
14511451 # Update page
14521452 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1453 -
 1453+
14541454 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, $baseRevId) );
14551455
14561456 if( !$ok ) {
@@ -1521,7 +1521,7 @@
15221522
15231523 # Update the page record with revision data
15241524 $this->updateRevisionOn( $dbw, $revision, 0 );
1525 -
 1525+
15261526 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
15271527
15281528 if( !( $flags & EDIT_SUPPRESS_RC ) ) {
@@ -1881,7 +1881,7 @@
18821882 'page_id' => $id
18831883 ), 'Article::protect'
18841884 );
1885 -
 1885+
18861886 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $nullRevision, false) );
18871887 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
18881888
@@ -2242,7 +2242,7 @@
22432243 function doDelete( $reason, $suppress = false ) {
22442244 global $wgOut, $wgUser;
22452245 wfDebug( __METHOD__."\n" );
2246 -
 2246+
22472247 $id = $this->getId();
22482248
22492249 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
@@ -2514,14 +2514,14 @@
25152515 if( empty( $summary ) ){
25162516 $summary = wfMsgForContent( 'revertpage' );
25172517 }
2518 -
 2518+
25192519 # Allow the custom summary to use the same args as the default message
25202520 $args = array(
25212521 $target->getUserText(), $from, $s->rev_id,
25222522 $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true),
25232523 $current->getId(), $wgLang->timeanddate($current->getTimestamp())
25242524 );
2525 - $summary = wfMsgReplaceArgs( $summary, $args );
 2525+ $summary = wfMsgReplaceArgs( $summary, $args );
25262526
25272527 # Save
25282528 $flags = EDIT_UPDATE;
@@ -2609,7 +2609,7 @@
26102610 . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
26112611 $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
26122612 $wgOut->returnToMain( false, $this->mTitle );
2613 -
 2613+
26142614 if( !$wgRequest->getBool( 'hidediff', false ) ) {
26152615 $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true );
26162616 $de->showDiff( '', '' );
@@ -2640,7 +2640,7 @@
26412641
26422642 /**
26432643 * Prepare text which is about to be saved.
2644 - * Returns a stdclass with source, pst and output members
 2644+ * Returns a stdclass with source, pst, output and user members
26452645 */
26462646 function prepareTextForEdit( $text, $revid=null ) {
26472647 if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
@@ -2652,11 +2652,14 @@
26532653 $edit->revid = $revid;
26542654 $edit->newText = $text;
26552655 $edit->pst = $this->preSaveTransform( $text );
2656 - $options = new ParserOptions;
 2656+ $user = new User();
 2657+ $options = new ParserOptions( $user );
26572658 $options->setTidy( true );
 2659+ $options->setInterfaceMessage( true ); // @bug 14404
26582660 $options->enableLimitReport();
26592661 $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
26602662 $edit->oldText = $this->getContent();
 2663+ $edit->user = $user;
26612664 $this->mPreparedEdit = $edit;
26622665 return $edit;
26632666 }
@@ -2692,7 +2695,7 @@
26932696 # Save it to the parser cache
26942697 if ( $wgEnableParserCache ) {
26952698 $parserCache = ParserCache::singleton();
2696 - $parserCache->save( $editInfo->output, $this, $wgUser );
 2699+ $parserCache->save( $editInfo->output, $this, $editInfo->user, /*content*/true );
26972700 }
26982701
26992702 # Update the links tables
@@ -2981,7 +2984,7 @@
29822985 $revision->insertOn( $dbw );
29832986 $this->updateRevisionOn( $dbw, $revision );
29842987 $dbw->commit();
2985 -
 2988+
29862989 wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) );
29872990
29882991 wfProfileOut( __METHOD__ );
Index: trunk/phase3/includes/RefreshLinksJob.php
@@ -36,7 +36,9 @@
3737 }
3838
3939 wfProfileIn( __METHOD__.'-parse' );
40 - $options = new ParserOptions;
 40+ $user = new User();
 41+ $options = new ParserOptions( $user );
 42+ $options->setInterfaceMessage( true );
4143 $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() );
4244 wfProfileOut( __METHOD__.'-parse' );
4345 wfProfileIn( __METHOD__.'-update' );
Index: trunk/phase3/includes/ParserOptions.php
@@ -5,32 +5,31 @@
66 * @todo document
77 * @ingroup Parser
88 */
9 -class ParserOptions
10 -{
 9+class ParserOptions {
1110 # All variables are supposed to be private in theory, although in practise this is not the case.
12 - var $mUseTeX; # Use texvc to expand <math> tags
13 - var $mUseDynamicDates; # Use DateFormatter to format dates
14 - var $mInterwikiMagic; # Interlanguage links are removed and returned in an array
15 - var $mAllowExternalImages; # Allow external images inline
16 - var $mAllowExternalImagesFrom; # If not, any exception?
17 - var $mSkin; # Reference to the preferred skin
18 - var $mDateFormat; # Date format index
19 - var $mEditSection; # Create "edit section" links
20 - var $mNumberHeadings; # Automatically number headings
21 - var $mAllowSpecialInclusion; # Allow inclusion of special pages
22 - var $mTidy; # Ask for tidy cleanup
23 - var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR
24 - var $mTargetLanguage; # Overrides above setting with arbitrary language
25 - var $mMaxIncludeSize; # Maximum size of template expansions, in bytes
26 - var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand()
27 - var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand()
28 - var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates
29 - var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
30 - var $mTemplateCallback; # Callback for template fetching
31 - var $mEnableLimitReport; # Enable limit report in an HTML comment on output
32 - var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc.
 11+ var $mUseTeX; //!< Use texvc to expand <math> tags
 12+ var $mUseDynamicDates; //!< Use DateFormatter to format dates
 13+ var $mInterwikiMagic; //!< Interlanguage links are removed and returned in an array
 14+ var $mAllowExternalImages; //!< Allow external images inline
 15+ var $mAllowExternalImagesFrom; //!< If not, any exception?
 16+ var $mSkin; //!< Reference to the preferred skin
 17+ var $mDateFormat; //!< Date format index
 18+ var $mEditSection; //!< Create "edit section" links
 19+ var $mNumberHeadings; //!< Automatically number headings
 20+ var $mAllowSpecialInclusion; //!< Allow inclusion of special pages
 21+ var $mTidy; //!< Ask for tidy cleanup
 22+ var $mInterfaceMessage; //!< Which lang to call for PLURAL and GRAMMAR
 23+ var $mTargetLanguage; //!< Overrides above setting with arbitrary language
 24+ var $mMaxIncludeSize; //!< Maximum size of template expansions, in bytes
 25+ var $mMaxPPNodeCount; //!< Maximum number of nodes touched by PPFrame::expand()
 26+ var $mMaxPPExpandDepth; //!< Maximum recursion depth in PPFrame::expand()
 27+ var $mMaxTemplateDepth; //!< Maximum recursion depth for templates within templates
 28+ var $mRemoveComments; //!< Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
 29+ var $mTemplateCallback; //!< Callback for template fetching
 30+ var $mEnableLimitReport; //!< Enable limit report in an HTML comment on output
 31+ var $mTimestamp; //!< Timestamp used for {{CURRENTDAY}} etc.
3332
34 - var $mUser; # Stored user object, just used to initialise the skin
 33+ var $mUser; //!< Stored user object, just used to initialise the skin
3534
3635 function getUseTeX() { return $this->mUseTeX; }
3736 function getUseDynamicDates() { return $this->mUseDynamicDates; }
@@ -98,7 +97,7 @@
9998
10099 /**
101100 * Get parser options
102 - * @static
 101+ * @param $user User
103102 */
104103 static function newFromUser( $user ) {
105104 return new ParserOptions( $user );
@@ -109,8 +108,9 @@
110109 global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
111110 global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
112111 global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
113 - $fname = 'ParserOptions::initialiseFromUser';
114 - wfProfileIn( $fname );
 112+
 113+ wfProfileIn( __METHOD__ );
 114+
115115 if ( !$userInput ) {
116116 global $wgUser;
117117 if ( isset( $wgUser ) ) {
@@ -144,6 +144,7 @@
145145 $this->mRemoveComments = true;
146146 $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );
147147 $this->mEnableLimitReport = false;
148 - wfProfileOut( $fname );
 148+
 149+ wfProfileOut( __METHOD__ );
149150 }
150151 }
Index: trunk/phase3/includes/CoreParserFunctions.php
@@ -56,7 +56,15 @@
5757 static function intFunction( $parser, $part1 = '' /*, ... */ ) {
5858 if ( strval( $part1 ) !== '' ) {
5959 $args = array_slice( func_get_args(), 2 );
60 - return wfMsgReal( $part1, $args, true );
 60+ $opts = array();
 61+ if( ( $langObj = $parser->mOptions->getTargetLanguage() ) !== null ){
 62+ $opts['language'] = $langObj->getCode();
 63+ } else if( $parser->mOptions->getInterfaceMessage() ) {
 64+ $opts[] = 'content';
 65+ }
 66+ $msg = call_user_func_array( 'wfMsgExt',
 67+ array_merge( array( $part1, $opts ), $args ) );
 68+ return $parser->replaceVariables( $msg );
6169 } else {
6270 return array( 'found' => false );
6371 }
Index: trunk/phase3/includes/ParserCache.php
@@ -26,9 +26,9 @@
2727 $this->mMemc =& $memCached;
2828 }
2929
30 - function getKey( &$article, &$user ) {
 30+ function getKey( &$article, &$user, $content = false ) {
3131 global $action;
32 - $hash = $user->getPageRenderingHash();
 32+ $hash = $user->getPageRenderingHash( $content );
3333 if( !$article->mTitle->quickUserCan( 'edit' ) ) {
3434 // section edit links are suppressed even if the user has them on
3535 $edit = '!edit=0';
@@ -86,9 +86,9 @@
8787 return $value;
8888 }
8989
90 - function save( $parserOutput, &$article, &$user ){
 90+ function save( $parserOutput, &$article, &$user, $content = false ){
9191 global $wgParserCacheExpireTime;
92 - $key = $this->getKey( $article, $user );
 92+ $key = $this->getKey( $article, $user, $content );
9393
9494 if( $parserOutput->getCacheTime() != -1 ) {
9595
Index: trunk/phase3/RELEASE-NOTES
@@ -350,6 +350,8 @@
351351 * (bug 14401) Fix Safari access key tooltips for Windows and >3.1 Mac versions
352352 * (bug 14432) Fix notice regression in Special:Newpages feed mode
353353 * (bug 11951) EditPage::getEditToolbar() is now static.
 354+* (bug 14404) Use of {{int:...}} to generate links no longer breaks links table
 355+ if user has a custom interface language
354356
355357
356358 === API changes in 1.13 ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r36185Revert r36093 (bug 14404)....brion02:51, 11 June 2008
r89706Reinstate r79122 (fix for bug 14404), reverting r83868. The real bug seem to ...platonides22:28, 7 June 2011
r97206Follow up r89706, building up on r97091....platonides21:09, 15 September 2011

Status & tagging log