From c32a1ef4800a9cda3c61321753fee690516bd47a Mon Sep 17 00:00:00 2001 From: Arash Boostani Date: Wed, 18 Mar 2009 23:27:48 +0000 Subject: [PATCH] Fixed bug #11213 - [edit] section links in printable version interfere with cut-and-paste of article text --- RELEASE-NOTES | 1 + includes/Article.php | 18 +++++++++++++----- includes/OutputPage.php | 6 +++--- includes/api/ApiParse.php | 2 +- includes/parser/Parser.php | 2 +- includes/parser/ParserCache.php | 23 +++++++++++++---------- includes/parser/ParserOptions.php | 9 ++++++--- 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index f201be7568..ad58121b29 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -278,6 +278,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN IS NULL * (bug 18018) Deleting a file redirect leaves behind a malfunctioning redirect * (bug 17537) Disable bad zlib.output_compression output on HTTP 304 responses +* (bug 11213) [edit] section links in printable version no longer appear when you cut-and-paste article text == API changes in 1.15 == * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions diff --git a/includes/Article.php b/includes/Article.php index fdaa241f0e..817c346fe8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -727,6 +727,11 @@ class Article { global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgArticleRobotPolicies; global $wgDefaultRobotPolicy; + # Let the parser know if this is the printable version + if( $wgOut->isPrintable() ) { + $wgOut->parserOptions()->setIsPrintable( true ); + } + wfProfileIn( __METHOD__ ); # Get variables from query string @@ -737,7 +742,7 @@ class Article { global $wgUseETag; if( $wgUseETag ) { $parserCache = ParserCache::singleton(); - $wgOut->setETag( $parserCache->getETag($this,$wgUser) ); + $wgOut->setETag( $parserCache->getETag($this, $wgOut->parserOptions()) ); } # Is is client cached? if( $wgOut->checkLastModified( $this->getTouched() ) ) { @@ -862,7 +867,7 @@ class Article { $outputDone = false; wfRunHooks( 'ArticleViewHeader', array( &$this, &$outputDone, &$pcache ) ); - if( $pcache && $wgOut->tryParserCache( $this, $wgUser ) ) { + if( $pcache && $wgOut->tryParserCache( $this ) ) { // Ensure that UI elements requiring revision ID have // the correct version information. $wgOut->setRevisionId( $this->mLatest ); @@ -939,7 +944,7 @@ class Article { } // Is this the current revision and otherwise cacheable? Try the parser cache... if( $oldid === $this->getLatest() && $this->useParserCache( false ) - && $wgOut->tryParserCache( $this, $wgUser ) ) + && $wgOut->tryParserCache( $this ) ) { $outputDone = true; } @@ -2916,8 +2921,11 @@ class Article { # Save it to the parser cache if( $wgEnableParserCache ) { + $popts = new ParserOptions; + $popts->setTidy( true ); + $popts->enableLimitReport(); $parserCache = ParserCache::singleton(); - $parserCache->save( $editInfo->output, $this, $wgUser ); + $parserCache->save( $editInfo->output, $this, $popts ); } # Update the links tables @@ -3551,7 +3559,7 @@ class Article { $popts->enableLimitReport( false ); if( $wgEnableParserCache && $cache && $this && $parserOutput->getCacheTime() != -1 ) { $parserCache = ParserCache::singleton(); - $parserCache->save( $parserOutput, $this, $wgUser ); + $parserCache->save( $parserOutput, $this, $popts ); } // Make sure file cache is not used on uncacheable content. // Output that has magic words in it can still use the parser cache diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 7fbd77b443..ed9a43d3f5 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -597,7 +597,7 @@ class OutputPage { $popts->setTidy(false); if ( $cache && $article && $parserOutput->getCacheTime() != -1 ) { $parserCache = ParserCache::singleton(); - $parserCache->save( $parserOutput, $article, $wgUser ); + $parserCache->save( $parserOutput, $article, $popts); } $this->addParserOutput( $parserOutput ); @@ -671,9 +671,9 @@ class OutputPage { * * @return bool True if successful, else false. */ - public function tryParserCache( &$article, $user ) { + public function tryParserCache( &$article ) { $parserCache = ParserCache::singleton(); - $parserOutput = $parserCache->get( $article, $user ); + $parserOutput = $parserCache->get( $article, $this->parserOptions() ); if ( $parserOutput !== false ) { $this->addParserOutput( $parserOutput ); return true; diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index e5d1fb9b38..d998070cf8 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -105,7 +105,7 @@ class ApiParse extends ApiBase { $p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts); global $wgUseParserCache; if($wgUseParserCache) - $pcache->save($p_result, $articleObj, $wgUser); + $pcache->save($p_result, $articleObj, $popts); } } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index cec5970ca5..bfff3719e3 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3378,7 +3378,7 @@ class Parser } # Inhibit editsection links if requested in the page - if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) { + if ( isset( $this->mDoubleUnderscores['noeditsection'] ) || $this->mOptions->getIsPrintable() ) { $showEditLink = 0; } diff --git a/includes/parser/ParserCache.php b/includes/parser/ParserCache.php index 7e61157a7d..22a3f7af97 100644 --- a/includes/parser/ParserCache.php +++ b/includes/parser/ParserCache.php @@ -26,8 +26,11 @@ class ParserCache { $this->mMemc =& $memCached; } - function getKey( &$article, &$user ) { - global $action; + function getKey( &$article, $popts ) { + global $wgRequest; + + $user = $popts->mUser; + $printable = ( $popts->getIsPrintable() ) ? '!printable=1' : ''; $hash = $user->getPageRenderingHash(); if( !$article->mTitle->quickUserCan( 'edit' ) ) { // section edit links are suppressed even if the user has them on @@ -36,21 +39,21 @@ class ParserCache { $edit = ''; } $pageid = $article->getID(); - $renderkey = (int)($action == 'render'); - $key = wfMemcKey( 'pcache', 'idhash', "{$pageid}-{$renderkey}!{$hash}{$edit}" ); + $renderkey = (int)($wgRequest->getVal('action') == 'render'); + $key = wfMemcKey( 'pcache', 'idhash', "{$pageid}-{$renderkey}!{$hash}{$edit}{$printable}" ); return $key; } - function getETag( &$article, &$user ) { - return 'W/"' . $this->getKey($article, $user) . "--" . $article->mTouched. '"'; + function getETag( &$article, $popts ) { + return 'W/"' . $this->getKey($article, $popts) . "--" . $article->mTouched. '"'; } - function get( &$article, &$user ) { + function get( &$article, $popts ) { global $wgCacheEpoch; $fname = 'ParserCache::get'; wfProfileIn( $fname ); - $key = $this->getKey( $article, $user ); + $key = $this->getKey( $article, $popts ); wfDebug( "Trying parser cache $key\n" ); $value = $this->mMemc->get( $key ); @@ -86,9 +89,9 @@ class ParserCache { return $value; } - function save( $parserOutput, &$article, &$user ){ + function save( $parserOutput, &$article, $popts ){ global $wgParserCacheExpireTime; - $key = $this->getKey( $article, $user ); + $key = $this->getKey( $article, $popts ); if( $parserOutput->getCacheTime() != -1 ) { diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 577d51f33d..e6a9f3a7ea 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -35,7 +35,8 @@ class ParserOptions var $mUser; # Stored user object, just used to initialise the skin var $mIsPreview; # Parsing the page for a "preview" operation var $mIsSectionPreview; # Parsing the page for a "preview" operation on a single section - + var $mIsPrintable; # Parsing the printable version of the page + function getUseTeX() { return $this->mUseTeX; } function getUseDynamicDates() { return $this->mUseDynamicDates; } function getInterwikiMagic() { return $this->mInterwikiMagic; } @@ -58,7 +59,8 @@ class ParserOptions function getExternalLinkTarget() { return $this->mExternalLinkTarget; } function getIsPreview() { return $this->mIsPreview; } function getIsSectionPreview() { return $this->mIsSectionPreview; } - + function getIsPrintable() { return $this->mIsPrintable; } + function getSkin() { if ( !isset( $this->mSkin ) ) { $this->mSkin = $this->mUser->getSkin(); @@ -105,7 +107,8 @@ class ParserOptions function setExternalLinkTarget( $x ) { return wfSetVar( $this->mExternalLinkTarget, $x ); } function setIsPreview( $x ) { return wfSetVar( $this->mIsPreview, $x ); } function setIsSectionPreview( $x ) { return wfSetVar( $this->mIsSectionPreview, $x ); } - + function setIsPrintable( $x ) { return wfSetVar( $this->mIsPrintable, $x ); } + function __construct( $user = null ) { $this->initialiseFromUser( $user ); } -- 2.20.1