From 53668e31430ba92198dd8ff9f9833fe82fed1cd6 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 9 Jun 2008 17:57:18 +0000 Subject: [PATCH] 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 --- RELEASE-NOTES | 2 ++ includes/Article.php | 37 +++++++++++---------- includes/CoreParserFunctions.php | 10 +++++- includes/ParserCache.php | 8 ++--- includes/ParserOptions.php | 57 ++++++++++++++++---------------- includes/RefreshLinksJob.php | 4 ++- includes/User.php | 12 +++++-- 7 files changed, 76 insertions(+), 54 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f0c74ed2e8..08c100f9df 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -350,6 +350,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 14401) Fix Safari access key tooltips for Windows and >3.1 Mac versions * (bug 14432) Fix notice regression in Special:Newpages feed mode * (bug 11951) EditPage::getEditToolbar() is now static. +* (bug 14404) Use of {{int:...}} to generate links no longer breaks links table + if user has a custom interface language === API changes in 1.13 === diff --git a/includes/Article.php b/includes/Article.php index d709f62730..0fa49e41f6 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -541,9 +541,9 @@ class Article { */ function isRedirect( $text = false ) { if ( $text === false ) { - if ( $this->mDataLoaded ) + if ( $this->mDataLoaded ) return $this->mIsRedirect; - + // Apparently loadPageData was never called $this->loadContent(); $titleObj = Title::newFromRedirect( $this->fetchContent() ); @@ -922,14 +922,14 @@ class Article { $this->viewUpdates(); wfProfileOut( __METHOD__ ); } - + protected function viewRedirect( $target, $overwriteSubtitle = true, $forceKnown = false ) { global $wgParser, $wgOut, $wgContLang, $wgStylePath, $wgUser; - + # Display redirect $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; - + if( $overwriteSubtitle ) { $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) ); } @@ -941,7 +941,7 @@ class Article { $wgOut->addHTML( '#REDIRECT ' . ''.$link.'' ); - + } function addTrackbacks() { @@ -1449,7 +1449,7 @@ class Article { # Update page $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision ); - + wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, $baseRevId) ); if( !$ok ) { @@ -1521,7 +1521,7 @@ class Article { # Update the page record with revision data $this->updateRevisionOn( $dbw, $revision, 0 ); - + wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) ); if( !( $flags & EDIT_SUPPRESS_RC ) ) { @@ -1881,7 +1881,7 @@ class Article { 'page_id' => $id ), 'Article::protect' ); - + wfRunHooks( 'NewRevisionFromEditComplete', array($this, $nullRevision, false) ); wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) ); @@ -2242,7 +2242,7 @@ class Article { function doDelete( $reason, $suppress = false ) { global $wgOut, $wgUser; wfDebug( __METHOD__."\n" ); - + $id = $this->getId(); if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) { @@ -2514,14 +2514,14 @@ class Article { if( empty( $summary ) ){ $summary = wfMsgForContent( 'revertpage' ); } - + # Allow the custom summary to use the same args as the default message $args = array( $target->getUserText(), $from, $s->rev_id, $wgLang->timeanddate(wfTimestamp(TS_MW, $s->rev_timestamp), true), $current->getId(), $wgLang->timeanddate($current->getTimestamp()) ); - $summary = wfMsgReplaceArgs( $summary, $args ); + $summary = wfMsgReplaceArgs( $summary, $args ); # Save $flags = EDIT_UPDATE; @@ -2609,7 +2609,7 @@ class Article { . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() ); $wgOut->addHtml( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) ); $wgOut->returnToMain( false, $this->mTitle ); - + if( !$wgRequest->getBool( 'hidediff', false ) ) { $de = new DifferenceEngine( $this->mTitle, $current->getId(), 'next', false, true ); $de->showDiff( '', '' ); @@ -2640,7 +2640,7 @@ class Article { /** * Prepare text which is about to be saved. - * Returns a stdclass with source, pst and output members + * Returns a stdclass with source, pst, output and user members */ function prepareTextForEdit( $text, $revid=null ) { if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) { @@ -2652,11 +2652,14 @@ class Article { $edit->revid = $revid; $edit->newText = $text; $edit->pst = $this->preSaveTransform( $text ); - $options = new ParserOptions; + $user = new User(); + $options = new ParserOptions( $user ); $options->setTidy( true ); + $options->setInterfaceMessage( true ); // @bug 14404 $options->enableLimitReport(); $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid ); $edit->oldText = $this->getContent(); + $edit->user = $user; $this->mPreparedEdit = $edit; return $edit; } @@ -2692,7 +2695,7 @@ class Article { # Save it to the parser cache if ( $wgEnableParserCache ) { $parserCache = ParserCache::singleton(); - $parserCache->save( $editInfo->output, $this, $wgUser ); + $parserCache->save( $editInfo->output, $this, $editInfo->user, /*content*/true ); } # Update the links tables @@ -2981,7 +2984,7 @@ class Article { $revision->insertOn( $dbw ); $this->updateRevisionOn( $dbw, $revision ); $dbw->commit(); - + wfRunHooks( 'NewRevisionFromEditComplete', array($this, $revision, false) ); wfProfileOut( __METHOD__ ); diff --git a/includes/CoreParserFunctions.php b/includes/CoreParserFunctions.php index d9072e9310..60dce1929a 100644 --- a/includes/CoreParserFunctions.php +++ b/includes/CoreParserFunctions.php @@ -56,7 +56,15 @@ class CoreParserFunctions { static function intFunction( $parser, $part1 = '' /*, ... */ ) { if ( strval( $part1 ) !== '' ) { $args = array_slice( func_get_args(), 2 ); - return wfMsgReal( $part1, $args, true ); + $opts = array(); + if( ( $langObj = $parser->mOptions->getTargetLanguage() ) !== null ){ + $opts['language'] = $langObj->getCode(); + } else if( $parser->mOptions->getInterfaceMessage() ) { + $opts[] = 'content'; + } + $msg = call_user_func_array( 'wfMsgExt', + array_merge( array( $part1, $opts ), $args ) ); + return $parser->replaceVariables( $msg ); } else { return array( 'found' => false ); } diff --git a/includes/ParserCache.php b/includes/ParserCache.php index bf11da2eeb..72d4c60e26 100644 --- a/includes/ParserCache.php +++ b/includes/ParserCache.php @@ -26,9 +26,9 @@ class ParserCache { $this->mMemc =& $memCached; } - function getKey( &$article, &$user ) { + function getKey( &$article, &$user, $content = false ) { global $action; - $hash = $user->getPageRenderingHash(); + $hash = $user->getPageRenderingHash( $content ); if( !$article->mTitle->quickUserCan( 'edit' ) ) { // section edit links are suppressed even if the user has them on $edit = '!edit=0'; @@ -86,9 +86,9 @@ class ParserCache { return $value; } - function save( $parserOutput, &$article, &$user ){ + function save( $parserOutput, &$article, &$user, $content = false ){ global $wgParserCacheExpireTime; - $key = $this->getKey( $article, $user ); + $key = $this->getKey( $article, $user, $content ); if( $parserOutput->getCacheTime() != -1 ) { diff --git a/includes/ParserOptions.php b/includes/ParserOptions.php index 330ec446cb..4fd7ca289b 100644 --- a/includes/ParserOptions.php +++ b/includes/ParserOptions.php @@ -5,32 +5,31 @@ * @todo document * @ingroup Parser */ -class ParserOptions -{ +class ParserOptions { # All variables are supposed to be private in theory, although in practise this is not the case. - var $mUseTeX; # Use texvc to expand tags - var $mUseDynamicDates; # Use DateFormatter to format dates - var $mInterwikiMagic; # Interlanguage links are removed and returned in an array - var $mAllowExternalImages; # Allow external images inline - var $mAllowExternalImagesFrom; # If not, any exception? - var $mSkin; # Reference to the preferred skin - var $mDateFormat; # Date format index - var $mEditSection; # Create "edit section" links - var $mNumberHeadings; # Automatically number headings - var $mAllowSpecialInclusion; # Allow inclusion of special pages - var $mTidy; # Ask for tidy cleanup - var $mInterfaceMessage; # Which lang to call for PLURAL and GRAMMAR - var $mTargetLanguage; # Overrides above setting with arbitrary language - var $mMaxIncludeSize; # Maximum size of template expansions, in bytes - var $mMaxPPNodeCount; # Maximum number of nodes touched by PPFrame::expand() - var $mMaxPPExpandDepth; # Maximum recursion depth in PPFrame::expand() - var $mMaxTemplateDepth; # Maximum recursion depth for templates within templates - var $mRemoveComments; # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS - var $mTemplateCallback; # Callback for template fetching - var $mEnableLimitReport; # Enable limit report in an HTML comment on output - var $mTimestamp; # Timestamp used for {{CURRENTDAY}} etc. + var $mUseTeX; //!< Use texvc to expand tags + var $mUseDynamicDates; //!< Use DateFormatter to format dates + var $mInterwikiMagic; //!< Interlanguage links are removed and returned in an array + var $mAllowExternalImages; //!< Allow external images inline + var $mAllowExternalImagesFrom; //!< If not, any exception? + var $mSkin; //!< Reference to the preferred skin + var $mDateFormat; //!< Date format index + var $mEditSection; //!< Create "edit section" links + var $mNumberHeadings; //!< Automatically number headings + var $mAllowSpecialInclusion; //!< Allow inclusion of special pages + var $mTidy; //!< Ask for tidy cleanup + var $mInterfaceMessage; //!< Which lang to call for PLURAL and GRAMMAR + var $mTargetLanguage; //!< Overrides above setting with arbitrary language + var $mMaxIncludeSize; //!< Maximum size of template expansions, in bytes + var $mMaxPPNodeCount; //!< Maximum number of nodes touched by PPFrame::expand() + var $mMaxPPExpandDepth; //!< Maximum recursion depth in PPFrame::expand() + var $mMaxTemplateDepth; //!< Maximum recursion depth for templates within templates + var $mRemoveComments; //!< Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS + var $mTemplateCallback; //!< Callback for template fetching + var $mEnableLimitReport; //!< Enable limit report in an HTML comment on output + var $mTimestamp; //!< Timestamp used for {{CURRENTDAY}} etc. - var $mUser; # Stored user object, just used to initialise the skin + var $mUser; //!< Stored user object, just used to initialise the skin function getUseTeX() { return $this->mUseTeX; } function getUseDynamicDates() { return $this->mUseDynamicDates; } @@ -98,7 +97,7 @@ class ParserOptions /** * Get parser options - * @static + * @param $user User */ static function newFromUser( $user ) { return new ParserOptions( $user ); @@ -109,8 +108,9 @@ class ParserOptions global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages; global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize; global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth; - $fname = 'ParserOptions::initialiseFromUser'; - wfProfileIn( $fname ); + + wfProfileIn( __METHOD__ ); + if ( !$userInput ) { global $wgUser; if ( isset( $wgUser ) ) { @@ -144,6 +144,7 @@ class ParserOptions $this->mRemoveComments = true; $this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' ); $this->mEnableLimitReport = false; - wfProfileOut( $fname ); + + wfProfileOut( __METHOD__ ); } } diff --git a/includes/RefreshLinksJob.php b/includes/RefreshLinksJob.php index f95e5a505e..d435e7d630 100644 --- a/includes/RefreshLinksJob.php +++ b/includes/RefreshLinksJob.php @@ -36,7 +36,9 @@ class RefreshLinksJob extends Job { } wfProfileIn( __METHOD__.'-parse' ); - $options = new ParserOptions; + $user = new User(); + $options = new ParserOptions( $user ); + $options->setInterfaceMessage( true ); $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options, true, true, $revision->getId() ); wfProfileOut( __METHOD__.'-parse' ); wfProfileIn( __METHOD__.'-update' ); diff --git a/includes/User.php b/includes/User.php index 5db907cb4b..0ba92e205e 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2334,11 +2334,13 @@ class User { * which will give them a chance to modify this key based on their own * settings. * + * @param $content Bool: wheter use the content language to generate the + * hash * @return string */ - function getPageRenderingHash() { + function getPageRenderingHash( $content = false ) { global $wgContLang, $wgUseDynamicDates, $wgLang; - if( $this->mHash ){ + if( $this->mHash && !$content ){ return $this->mHash; } @@ -2351,7 +2353,11 @@ class User { $confstr .= '!' . $this->getDatePreference(); } $confstr .= '!' . ($this->getOption( 'numberheadings' ) ? '1' : ''); - $confstr .= '!' . $wgLang->getCode(); + if( $content ){ + $confstr .= '!' . $wgContLang->getCode(); + } else { + $confstr .= '!' . $wgLang->getCode(); + } $confstr .= '!' . $this->getOption( 'thumbsize' ); // add in language specific options, if any $extra = $wgContLang->getExtraHashOptions(); -- 2.20.1