r70498 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70497‎ | r70498 | r70499 >
Date:14:37, 5 August 2010
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Change quickUserCan( 'edit' ) and getIsPrintable() into setEditSection( false )

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;.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserCache.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -826,7 +826,7 @@
827827 */
828828 public function view() {
829829 global $wgUser, $wgOut, $wgRequest, $wgParser;
830 - global $wgUseFileCache;
 830+ global $wgUseFileCache, $wgUseETag;
831831
832832 wfProfileIn( __METHOD__ );
833833
@@ -838,12 +838,13 @@
839839 # Render printable version, use printable version cache
840840 if ( $wgOut->isPrintable() ) {
841841 $parserOptions->setIsPrintable( true );
 842+ $parserOptions->setEditSection( false );
 843+ } else if ( $wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
 844+ $parserOptions->setEditSection( false );
842845 }
843846
844847 # Try client and file cache
845848 if ( $oldid === 0 && $this->checkTouched() ) {
846 - global $wgUseETag;
847 -
848849 if ( $wgUseETag ) {
849850 $wgOut->setETag( $parserCache->getETag( $this, $parserOptions ) );
850851 }
@@ -888,6 +889,10 @@
889890 return;
890891 }
891892
 893+ if ( !$wgUseETag && !$this->mTitle->quickUserCan( 'edit' ) ) {
 894+ $parserOptions->setEditSection( false );
 895+ }
 896+
892897 # Should the parser cache be used?
893898 $useParserCache = $this->useParserCache( $oldid );
894899 wfDebug( 'Article::view using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
@@ -1471,7 +1476,10 @@
14721477 $parserOptions->setIsPrintable( $wgOut->isPrintable() );
14731478
14741479 # Don't show section-edit links on old revisions... this way lies madness.
1475 - $parserOptions->setEditSection( $this->isCurrent() );
 1480+ if ( !$this->isCurrent() || $wgOut->isPrintable() ) {
 1481+ $parserOptions->setEditSection( false );
 1482+ }
 1483+
14761484 $useParserCache = $this->useParserCache( $oldid );
14771485 $this->outputWikiText( $this->getContent(), $useParserCache, $parserOptions );
14781486 }
@@ -1489,7 +1497,12 @@
14901498 global $wgOut;
14911499 $parserCache = ParserCache::singleton();
14921500 $options = $this->getParserOptions();
1493 - $options->setIsPrintable( $wgOut->isPrintable() );
 1501+
 1502+ if ( $wgOut->isPrintable() ) {
 1503+ $options->setIsPrintable( true );
 1504+ $parserOptions->setEditSection( false );
 1505+ }
 1506+
14941507 $output = $parserCache->getDirty( $this, $options );
14951508
14961509 if ( $output ) {
Index: trunk/phase3/includes/parser/Parser.php
@@ -3700,7 +3700,7 @@
37013701 global $wgMaxTocLevel, $wgContLang, $wgHtml5, $wgExperimentalHtmlIds;
37023702
37033703 $doNumberHeadings = $this->mOptions->getNumberHeadings();
3704 - $showEditLink = $this->mOptions->getEditSection();
 3704+
37053705
37063706 # Do not call quickUserCan unless necessary
37073707 if ( $showEditLink && !$this->mTitle->quickUserCan( 'edit' ) ) {
@@ -3708,8 +3708,10 @@
37093709 }
37103710
37113711 # Inhibit editsection links if requested in the page
3712 - if ( isset( $this->mDoubleUnderscores['noeditsection'] ) || $this->mOptions->getIsPrintable() ) {
 3712+ if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
37133713 $showEditLink = 0;
 3714+ } else {
 3715+ $showEditLink = $this->mOptions->getEditSection();
37143716 }
37153717
37163718 # Get all headlines for numbering them and adding funky stuff like [edit]
Index: trunk/phase3/includes/parser/ParserCache.php
@@ -41,8 +41,9 @@
4242 $user = $popts->mUser;
4343 $printable = ( $popts->getIsPrintable() ) ? '!printable=1' : '';
4444 $hash = $user->getPageRenderingHash();
45 - if( !$article->mTitle->quickUserCan( 'edit' ) ) {
46 - // section edit links are suppressed even if the user has them on
 45+
 46+ if( ! $popts->getEditSection() ) {
 47+ // section edit links have been suppressed
4748 $edit = '!edit=0';
4849 } else {
4950 $edit = '';
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -165,6 +165,7 @@
166166 $this->mExternalLinkTarget = $wgExternalLinkTarget;
167167 $this->mIsPreview = false;
168168 $this->mIsSectionPreview = false;
 169+ $this->mIsPrintable = false;
169170
170171 wfProfileOut( __METHOD__ );
171172 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r70499Follow up r70498. Actually remove the quickUserCan().platonides14:46, 5 August 2010
r70783Use only the page relevant pieces in the parser cache key. Eg. two users with...platonides21:53, 9 August 2010
r79185(Bug 26458) Section edit links appear on pages that user does not have right ...platonides16:42, 29 December 2010
r92703(bug 25355) Parser generates edit section links for special pages...demon22:32, 20 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r48544Fixed bug #11213 - [edit] section links in printable version interfere with c...aboostani23:27, 18 March 2009

Comments

#Comment by Bawolff (talk | contribs)   11:54, 29 December 2010

This causes the section edit links to appear on protected pages even when the user cannot edit them. See bug 26458.


This seems to be due to the ParserOptions object in use by Article::doViewParse being different from the ParserOptions object in Article::view, so the check in Article::view doesn't carry over to Article::doViewParse.

#Comment by Platonides (talk | contribs)   16:42, 29 December 2010

Actually, it seems the fault of r70751 added to r70499. Fixed in r79185.

#Comment by IAlex (talk | contribs)   17:46, 8 February 2011

I'm adding this here, but could also be in r70498.

The quickUserCan() was useful on special pages since nothing sets editsection parser option to 0 for special pages, thus edit section links are added to wikitext headings on special pages, e.g. Special:Code/MediaWiki/status (on a 1.17 install but not here).

#Comment by IAlex (talk | contribs)   17:47, 8 February 2011

Sorry, the link on the first line was meant to be r70499.

#Comment by RobLa-WMF (talk | contribs)   04:46, 11 February 2011

IAlex, we're not seeing this on 1.17wmf1. Given you're not sure which rev is the culprit (and we can't seem to repro), maybe file a bug if this is still an issue?

#Comment by IAlex (talk | contribs)   14:59, 11 February 2011

See bug 25355, where I attached a screenshot.

#Comment by Krinkle (talk | contribs)   20:59, 29 June 2011
  • bump* this is still happening all SpecialPages in 1.17 with headings such as Special:Code/MediaWiki/status and delete/undelete block/unblock pages for the log headings.
#Comment by Platonides (talk | contribs)   22:26, 29 June 2011

I don't see it. I only see an "edit delete reasons" link at deleting a page, but that's for MediaWiki:Deletereason-dropdown, not an edit link triggered by this.

#Comment by Bawolff (talk | contribs)   23:14, 29 June 2011

I also see the edit link at http://en.wikinews.org/wiki/Special:Block (with the href http://en.wikinews.org/w/index.php?title=Special:Block&action=edit&section=1 ) (wiki chosen because that's where I actually have access to that page ;) And i see the edit link on cr status page as well.

#Comment by Platonides (talk | contribs)   21:57, 30 June 2011

Fo you see it on http://test.wikipedia.org/wiki/Special:Block/Bawolff ? (I don't)

Confirmed in [1]

#Comment by Bawolff (talk | contribs)   22:00, 30 June 2011

There's no ==headers== on that page (on testwiki). I think many wiki's put section headers on the relavent message, which is why there's edit links on wikinews.

#Comment by Catrope (talk | contribs)   22:19, 20 July 2011

There should be a parser test for this, that asserts that section edit links do not appear on special pages. Per the comments on r58362, HTML processed by $wgOut should never have edit section links.

Status & tagging log