ImagePage: Inherit parent's handling for action=render
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 18 Oct 2018 03:06:23 +0000 (05:06 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 18 Oct 2018 03:08:11 +0000 (05:08 +0200)
ImagePage::render() was calling parent::view() instead of
parent::render(), thus skipping Article::render() entirely.
Therefore the logic to disable section edit links (and also,
to add an 'X-Robots-Tag: noindex' header) was not being used.
This fixes T65891 and T21415 for pages in 'File:' namespace.

Bug: T206546
Change-Id: I36ae716c9a363ae29b7a785cc41430301250baba

includes/page/Article.php
includes/page/ImagePage.php

index 803bf0a..36632f0 100644 (file)
@@ -120,7 +120,7 @@ class Article implements Page {
         * here, there doesn't seem to be any other way to stop calling
         * OutputPage::enableSectionEditLinks() and still have it work as it did before.
         */
-       private $disableSectionEditForRender = false;
+       protected $viewIsRenderAction = false;
 
        /**
         * Constructor and clear the article
@@ -633,7 +633,7 @@ class Article implements Page {
                if ( $outputPage->isPrintable() ) {
                        $parserOptions->setIsPrintable( true );
                        $poOptions['enableSectionEditLinks'] = false;
-               } elseif ( $this->disableSectionEditForRender
+               } elseif ( $this->viewIsRenderAction
                        || !$this->isCurrent() || !$this->getTitle()->quickUserCan( 'edit', $user )
                ) {
                        $poOptions['enableSectionEditLinks'] = false;
@@ -1735,7 +1735,8 @@ class Article implements Page {
        public function render() {
                $this->getContext()->getRequest()->response()->header( 'X-Robots-Tag: noindex' );
                $this->getContext()->getOutput()->setArticleBodyOnly( true );
-               $this->disableSectionEditForRender = true;
+               // We later set 'enableSectionEditLinks=false' based on this; also used by ImagePage
+               $this->viewIsRenderAction = true;
                $this->view();
        }
 
index bf3eaf4..1773e16 100644 (file)
@@ -86,18 +86,15 @@ class ImagePage extends Article {
                $this->repo = $img->getRepo();
        }
 
-       /**
-        * Handler for action=render
-        * Include body text only; none of the image extras
-        */
-       public function render() {
-               $this->getContext()->getOutput()->setArticleBodyOnly( true );
-               parent::view();
-       }
-
        public function view() {
                global $wgShowEXIF;
 
+               // For action=render, include body text only; none of the image extras
+               if ( $this->viewIsRenderAction ) {
+                       parent::view();
+                       return;
+               }
+
                $out = $this->getContext()->getOutput();
                $request = $this->getContext()->getRequest();
                $diff = $request->getVal( 'diff' );