Change quickUserCan( 'edit' ) and getIsPrintable() into setEditSection( false )
authorPlatonides <platonides@users.mediawiki.org>
Thu, 5 Aug 2010 14:37:50 +0000 (14:37 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 5 Aug 2010 14:37:50 +0000 (14:37 +0000)
Follow up r48544. Init ParserOptions::mIsPrintable in initialiseFromUser()
Move the "No edit section it's printable" from Parser to Article.
This leaves getIsPrintable() unused. Left there for extensions (none seems to be using it, could be removed).

The "even if the user has them on" comment wasn't accurate. The user preference only controls them via CSS.
Anyway, it would work as expected now if it got moved into ParserOptions. The setEditSection() no longer set it to true.

Remove the quickUserCan( 'edit' ) which is just a hidden way of calling $wgUser from the Parser to be explicitely
done in Article to disable the editsection. This results in quickUserCan being called once instead of twice if $wgUseETag == true;.

includes/Article.php
includes/parser/Parser.php
includes/parser/ParserCache.php
includes/parser/ParserOptions.php

index 3812658..2614aea 100644 (file)
@@ -826,7 +826,7 @@ class Article {
         */
        public function view() {
                global $wgUser, $wgOut, $wgRequest, $wgParser;
-               global $wgUseFileCache;
+               global $wgUseFileCache, $wgUseETag;
 
                wfProfileIn( __METHOD__ );
 
@@ -838,12 +838,13 @@ class Article {
                # Render printable version, use printable version cache
                if ( $wgOut->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
+                       $parserOptions->setEditSection( false );
+               } else if ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+                       $parserOptions->setEditSection( false );
                }
 
                # Try client and file cache
                if ( $oldid === 0 && $this->checkTouched() ) {
-                       global $wgUseETag;
-
                        if ( $wgUseETag ) {
                                $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
                        }
@@ -888,6 +889,10 @@ class Article {
                        return;
                }
 
+               if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
+                       $parserOptions->setEditSection( false );
+               }
+
                # Should the parser cache be used?
                $useParserCache = $this->useParserCache( $oldid );
                wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
@@ -1471,7 +1476,10 @@ class Article {
                $parserOptions->setIsPrintable( $wgOut->isPrintable() );
 
                # Don't show section-edit links on old revisions... this way lies madness.
-               $parserOptions->setEditSection( $this->isCurrent() );
+               if ( !$this->isCurrent() || $wgOut->isPrintable() ) {
+                       $parserOptions->setEditSection( false );
+               }
+               
                $useParserCache = $this->useParserCache( $oldid );
                $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
        }
@@ -1489,7 +1497,12 @@ class Article {
                global $wgOut;
                $parserCache = ParserCache::singleton();
                $options = $this->getParserOptions();
-               $options->setIsPrintable( $wgOut->isPrintable() );
+               
+               if ( $wgOut->isPrintable() ) {
+                       $options->setIsPrintable( true );
+                       $parserOptions->setEditSection( false );
+               }
+               
                $output = $parserCache->getDirty( $this, $options );
 
                if ( $output ) {
index a4e9058..6efa1f2 100644 (file)
@@ -3700,7 +3700,7 @@ class Parser {
                global $wgMaxTocLevel, $wgContLang, $wgHtml5, $wgExperimentalHtmlIds;
 
                $doNumberHeadings = $this->mOptions->getNumberHeadings();
-               $showEditLink = $this->mOptions->getEditSection();
+               
 
                # Do not call quickUserCan unless necessary
                if ( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
@@ -3708,8 +3708,10 @@ class Parser {
                }
 
                # Inhibit editsection links if requested in the page
-               if ( isset( $this->mDoubleUnderscores['noeditsection'] )  || $this->mOptions->getIsPrintable() ) {
+               if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
                        $showEditLink = 0;
+               } else {
+                       $showEditLink = $this->mOptions->getEditSection();
                }
 
                # Get all headlines for numbering them and adding funky stuff like [edit]
index 20de904..1f0458b 100644 (file)
@@ -41,8 +41,9 @@ class ParserCache {
                $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
+               
+               if( ! $popts->getEditSection() ) {
+                       // section edit links have been suppressed
                        $edit = '!edit=0';
                } else {
                        $edit = '';
index 71377e3..977803f 100644 (file)
@@ -165,6 +165,7 @@ class ParserOptions {
                $this->mExternalLinkTarget = $wgExternalLinkTarget;
                $this->mIsPreview = false;
                $this->mIsSectionPreview = false;
+               $this->mIsPrintable = false;
 
                wfProfileOut( __METHOD__ );
        }