Aude has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/367343 )
Change subject: Only add the "wikibase.mobile" module when appropriate
......................................................................
Only add the "wikibase.mobile" module when appropriate
This can't be added to the parser output as we don't differ
by target there.
Bug: T170668
Change-Id: If71d529a7b5782fcba9f1f01319ecbb967c3ba3b
(cherry picked from commit 0d855864db4b2eb0011932543db704d1e9d3461e)
---
M repo/Wikibase.hooks.php
M repo/Wikibase.php
M repo/includes/ParserOutput/EntityParserOutputGenerator.php
M repo/tests/phpunit/includes/RepoHooksTest.php
4 files changed, 62 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/43/367343/1
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index d6563a1..66c20dd 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -57,6 +57,22 @@
}
/**
+ * Handler for the BeforePageDisplayMobile hook that adds the wikibase
mobile styles.
+ *
+ * @param OutputPage $out
+ * @param Skin $skin
+ */
+ public static function onBeforePageDisplayMobile( OutputPage &$out,
Skin &$skin ) {
+ $title = $out->getTitle();
+ $entityNamespaceLookup =
WikibaseRepo::getDefaultInstance()->getEntityNamespaceLookup();
+ $isEntityTitle = $entityNamespaceLookup->isEntityNamespace(
$title->getNamespace() );
+
+ if ( $isEntityTitle ) {
+ $out->addModules( 'wikibase.mobile' );
+ }
+ }
+
+ /**
* Handler for the SetupAfterCache hook, completing the content and
namespace setup.
* This updates the $wgContentHandlers and $wgNamespaceContentModels
registries
* according to information provided by entity type definitions and the
entityNamespaces
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 76a74c9..a5c266f 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -1004,6 +1004,7 @@
$wgHooks['ResourceLoaderRegisterModules'][] =
'Wikibase\RepoHooks::onResourceLoaderRegisterModules';
$wgHooks['BeforeDisplayNoArticleText'][] =
'Wikibase\ViewEntityAction::onBeforeDisplayNoArticleText';
$wgHooks['InfoAction'][] = '\Wikibase\RepoHooks::onInfoAction';
+ $wgHooks['BeforePageDisplayMobile'][] =
'\Wikibase\RepoHooks::onBeforePageDisplayMobile';
// update hooks
$wgHooks['LoadExtensionSchemaUpdates'][] =
'\Wikibase\Repo\Store\Sql\ChangesSubscriptionSchemaUpdater::onSchemaUpdate';
diff --git a/repo/includes/ParserOutput/EntityParserOutputGenerator.php
b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
index 73b1528..0829638 100644
--- a/repo/includes/ParserOutput/EntityParserOutputGenerator.php
+++ b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
@@ -371,10 +371,6 @@
// Then load JavaScript accordingly depending on $editable.
$parserOutput->addModules( 'wikibase.ui.entityViewInit' );
$parserOutput->addModules( 'wikibase.entityPage.entityLoaded' );
-
- // Load mobile styles, which have targets => mobile
- // and will only be loaded on mobile devices
- $parserOutput->addModules( 'wikibase.mobile' );
}
/**
diff --git a/repo/tests/phpunit/includes/RepoHooksTest.php
b/repo/tests/phpunit/includes/RepoHooksTest.php
index bcc1330..c3d0caf 100644
--- a/repo/tests/phpunit/includes/RepoHooksTest.php
+++ b/repo/tests/phpunit/includes/RepoHooksTest.php
@@ -11,6 +11,7 @@
use OutputPage;
use ParserOutput;
use RequestContext;
+use SkinTemplate;
use stdClass;
use Title;
use Wikibase\Repo\WikibaseRepo;
@@ -53,6 +54,50 @@
return WikibaseRepo::getDefaultInstance()->getSettings();
}
+ public function onBeforePageDisplayProviderMobile() {
+ $wikibaseMobile = [ 'wikibase.mobile' ];
+
+ return [
+ 'Mobile entity page' => [
+ $wikibaseMobile,
+ true,
+ ],
+ 'Mobile non-entity page' => [
+ [],
+ false
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider onBeforePageDisplayProviderMobile
+ */
+ public function testOnBeforePageDisplayMobile( $expectedModules,
$isEntityNamespace ) {
+ if ( $isEntityNamespace ) {
+ $namespace = array_values(
WikibaseRepo::getDefaultInstance()->getEntityNamespaces() )[0];
+ } else {
+ $namespace = NS_TALK;
+ }
+
+ $title = $this->getMock( Title::class );
+ $title->expects( $this->once() )
+ ->method( 'getNamespace' )
+ ->willReturn( $namespace );
+
+ $context = new DerivativeContext( RequestContext::getMain() );
+ $context->setTitle( $title );
+
+ $outputPage = new OutputPage( $context );
+
+ $skin = $this->getMock( SkinTemplate::class );
+ RepoHooks::onBeforePageDisplayMobile(
+ $outputPage,
+ $skin
+ );
+
+ $this->assertSame( $expectedModules, $outputPage->getModules()
);
+ }
+
public function testOnAPIQuerySiteInfoGeneralInfo() {
$api = $this->getMockBuilder( ApiQuerySiteinfo::class )
->disableOriginalConstructor()
--
To view, visit https://gerrit.wikimedia.org/r/367343
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If71d529a7b5782fcba9f1f01319ecbb967c3ba3b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.30.0-wmf.10
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits