Anomie has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/394642 )
Change subject: Remove 'wbIsEditView' JS config var
......................................................................
Remove 'wbIsEditView' JS config var
The PHP code doesn't know any longer whether the output will eventually
be editable or not, since that's determine post-cache when something
calls ParserOutput::getText(). Instead, have the JS code check for an
element with class wikibase-toolbar-button-edit directly.
Follows up I140ff32373430b61b92226689ef9b58cca317450, which brought
Wikibase's behavior when previewing a diff to the current revision in
line with MediaWiki core's behavior.
Bug: T181807
Change-Id: I342cc900bd3fb8aaede97820d96a3488e3db0dff
---
M repo/includes/Actions/ViewEntityAction.php
M repo/resources/wikibase.ui.entityViewInit.js
M repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
3 files changed, 21 insertions(+), 24 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/42/394642/1
diff --git a/repo/includes/Actions/ViewEntityAction.php
b/repo/includes/Actions/ViewEntityAction.php
index 88946ce..89f5c9c 100644
--- a/repo/includes/Actions/ViewEntityAction.php
+++ b/repo/includes/Actions/ViewEntityAction.php
@@ -54,18 +54,6 @@
}
/**
- * 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
- */
- private function isEditable() {
- return !$this->isDiff()
- && !$this->getOutput()->isPrintable()
- && $this->page->isCurrent();
- }
-
- /**
* @return bool
*/
private function isDiff() {
@@ -74,10 +62,7 @@
private function showEntityPage() {
$outputPage = $this->getOutput();
- $editable = $this->isEditable();
- // NOTE: page-wide property, independent of user permissions
- $outputPage->addJsConfigVars( 'wbIsEditView', $editable );
$this->page->view();
$this->overridePageMetaTags( $outputPage );
diff --git a/repo/resources/wikibase.ui.entityViewInit.js
b/repo/resources/wikibase.ui.entityViewInit.js
index b6c1382..96f09b0 100644
--- a/repo/resources/wikibase.ui.entityViewInit.js
+++ b/repo/resources/wikibase.ui.entityViewInit.js
@@ -11,8 +11,8 @@
* @return {boolean}
*/
function isEditable() {
- return mw.config.get( 'wbIsEditView' )
- && mw.config.get( 'wgRelevantPageIsProbablyEditable' );
+ return mw.config.get( 'wgRelevantPageIsProbablyEditable' )
+ && $( '.wikibase-toolbar-button-edit' ).length;
}
/**
diff --git a/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
b/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
index 73b6e88..6d7d89a 100644
--- a/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
+++ b/repo/tests/phpunit/includes/Actions/ViewEntityActionTest.php
@@ -88,7 +88,7 @@
], $metaTags );
}
- public function testShowDiff() {
+ public function testShowDiff_latest() {
$page = $this->getTestItemPage( 'Berlin' );
$latest = $page->getRevision();
@@ -97,6 +97,23 @@
$params = [
'diff' => $latest->getId(),
'oldid' => $previous->getId()
+ ];
+
+ $output = $this->executeViewAction( $page, $params );
+
+ $this->assertContains( 'diff-currentversion-title',
$output->getHTML(), 'is diff view' );
+ $this->assertEditable( $output );
+ }
+
+ public function testShowDiff_notLatest() {
+ $page = $this->getTestItemPage( 'Berlin' );
+
+ $previous = $page->getRevision()->getPrevious();
+ $previousPrevious = $latest->getPrevious();
+
+ $params = [
+ 'diff' => $previous->getId(),
+ 'oldid' => $previousPrevious->getId()
];
$output = $this->executeViewAction( $page, $params );
@@ -181,9 +198,8 @@
$jsConfigVars = $output->getJSVars();
// This mirrors the check the front does in isEditable() in
wikibase.ui.entityViewInit.js.
- $this->assertArrayHasKey( 'wbIsEditView', $jsConfigVars );
+ $this->assertContains( 'wikibase-toolbar-button-edit', $html );
$this->assertArrayHasKey( 'wgRelevantPageIsProbablyEditable',
$jsConfigVars );
- $this->assertTrue( $jsConfigVars['wbIsEditView'], 'wbIsEditView
is enabled' );
$this->assertTrue(
$jsConfigVars['wgRelevantPageIsProbablyEditable'],
'wgRelevantPageIsProbablyEditable is enabled'
@@ -194,10 +210,6 @@
$html = $output->getHTML();
$this->assertNotContains( 'wikibase-edittoolbar-container',
$html );
$this->assertNotContains( 'wikibase-toolbar-button-edit', $html
);
-
- $jsConfigVars = $output->getJsConfigVars();
- $this->assertArrayHasKey( 'wbIsEditView', $jsConfigVars );
- $this->assertFalse( $jsConfigVars['wbIsEditView'],
'wbIsEditView is disabled' );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/394642
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I342cc900bd3fb8aaede97820d96a3488e3db0dff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits