jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394973 )

Change subject: Never show edit section links in entity diffs
......................................................................


Never show edit section links in entity diffs

Bug: T181807
Change-Id: Iad4f8f8458a4d4d38b4874df86191c30f2ac5229
---
M repo/Wikibase.hooks.php
M repo/includes/Actions/ViewEntityAction.php
M repo/includes/Diff/EntityContentDiffView.php
M repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
M view/src/ToolbarEditSectionGenerator.php
5 files changed, 35 insertions(+), 16 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified
  Anomie: Looks good to me, but someone else must approve



diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 8fb1aad..ee2304b 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -43,6 +43,7 @@
 use Wikibase\Repo\Search\Elastic\StatementBoostScoreBuilder;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Store\Sql\SqlSubscriptionLookup;
+use Wikibase\View\ToolbarEditSectionGenerator;
 use WikiPage;
 
 /**
@@ -1011,13 +1012,14 @@
         * @param array &$options Transformation options
         */
        public static function onParserOutputPostCacheTransform(
-               ParserOutput $out, &$text, array &$options
+               ParserOutput $out,
+               &$text,
+               array &$options
        ) {
-               if ( $options['enableSectionEditLinks'] ) {
-                       $text = str_replace( [ '<wb:sectionedit>', 
'</wb:sectionedit>' ], '', $text );
-               } else {
-                       $text = preg_replace( 
'#<wb:sectionedit>.*?</wb:sectionedit>#s', '', $text );
-               }
+               $text = ToolbarEditSectionGenerator::enableSectionEditLinks(
+                       $text,
+                       $options['enableSectionEditLinks']
+               );
        }
 
        /**
diff --git a/repo/includes/Actions/ViewEntityAction.php 
b/repo/includes/Actions/ViewEntityAction.php
index 88946ce..6bb538f 100644
--- a/repo/includes/Actions/ViewEntityAction.php
+++ b/repo/includes/Actions/ViewEntityAction.php
@@ -54,15 +54,13 @@
        }
 
        /**
-        * Returns true if this view action is performing a plain view (not a 
diff, print version, etc.)
-        * of the page's current revision.
-        *
-        * @return bool
+        * @return bool False for older revisions, or if this is for sure not a 
plain view (e.g. diff or
+        *  print view).
         */
        private function isEditable() {
-               return !$this->isDiff()
-                       && !$this->getOutput()->isPrintable()
-                       && $this->page->isCurrent();
+               return $this->page->isCurrent()
+                       && !$this->isDiff()
+                       && !$this->getOutput()->isPrintable();
        }
 
        /**
@@ -74,10 +72,9 @@
 
        private function showEntityPage() {
                $outputPage = $this->getOutput();
-               $editable = $this->isEditable();
 
                // NOTE: page-wide property, independent of user permissions
-               $outputPage->addJsConfigVars( 'wbIsEditView', $editable );
+               $outputPage->addJsConfigVars( 'wbIsEditView', 
$this->isEditable() );
                $this->page->view();
 
                $this->overridePageMetaTags( $outputPage );
diff --git a/repo/includes/Diff/EntityContentDiffView.php 
b/repo/includes/Diff/EntityContentDiffView.php
index d7852ac..136f428 100644
--- a/repo/includes/Diff/EntityContentDiffView.php
+++ b/repo/includes/Diff/EntityContentDiffView.php
@@ -13,6 +13,7 @@
 use Revision;
 use Wikibase\EntityContent;
 use Wikibase\Repo\WikibaseRepo;
+use Wikibase\View\ToolbarEditSectionGenerator;
 use WikiPage;
 
 /**
@@ -153,6 +154,12 @@
                $parserOptions->addExtraKey( 'diff=1' );
 
                $parserOutput = $page->getParserOutput( $parserOptions, 
$rev->getId() );
+
+               $parserOutput->setText( 
ToolbarEditSectionGenerator::enableSectionEditLinks(
+                       $parserOutput->getRawText(),
+                       false
+               ) );
+
                return $parserOutput;
        }
 
diff --git a/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php 
b/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
index d58d3d1..73b6e88 100644
--- a/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
+++ b/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
@@ -102,7 +102,6 @@
                $output = $this->executeViewAction( $page, $params );
 
                $this->assertContains( 'diff-currentversion-title', 
$output->getHTML(), 'is diff view' );
-               $this->markTestSkipped( 'Diff page is currently editable, needs 
fixing: T181807' );
                $this->assertNotEditable( $output );
        }
 
diff --git a/view/src/ToolbarEditSectionGenerator.php 
b/view/src/ToolbarEditSectionGenerator.php
index 8df0026..9b93c31 100644
--- a/view/src/ToolbarEditSectionGenerator.php
+++ b/view/src/ToolbarEditSectionGenerator.php
@@ -39,6 +39,20 @@
                $this->textProvider = $textProvider;
        }
 
+       /**
+        * @param string $text
+        * @param bool $isEditable
+        *
+        * @return string
+        */
+       public static function enableSectionEditLinks( $text, $isEditable ) {
+               if ( $isEditable ) {
+                       return str_replace( [ '<wb:sectionedit>', 
'</wb:sectionedit>' ], '', $text );
+               } else {
+                       return preg_replace( 
'#<wb:sectionedit>.*?</wb:sectionedit>#s', '', $text );
+               }
+       }
+
        public function getSiteLinksEditSection( EntityId $entityId = null ) {
                $specialPageUrlParams = [];
 

-- 
To view, visit https://gerrit.wikimedia.org/r/394973
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iad4f8f8458a4d4d38b4874df86191c30f2ac5229
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to