Fixed bug #11213 - [edit] section links in printable version interfere with cut-and...
authorArash Boostani <aboostani@users.mediawiki.org>
Wed, 18 Mar 2009 23:27:48 +0000 (23:27 +0000)
committerArash Boostani <aboostani@users.mediawiki.org>
Wed, 18 Mar 2009 23:27:48 +0000 (23:27 +0000)
RELEASE-NOTES
includes/Article.php
includes/OutputPage.php
includes/api/ApiParse.php
includes/parser/Parser.php
includes/parser/ParserCache.php
includes/parser/ParserOptions.php

index f201be7..ad58121 100644 (file)
@@ -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
index fdaa241..817c346 100644 (file)
@@ -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
index 7fbd77b..ed9a43d 100644 (file)
@@ -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;
index e5d1fb9..d998070 100644 (file)
@@ -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);
                                }
                        }
                }
index cec5970..bfff371 100644 (file)
@@ -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;
                }
 
index 7e61157..22a3f7a 100644 (file)
@@ -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 ) {
 
index 577d51f..e6a9f3a 100644 (file)
@@ -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 );
        }