MaxSem has uploaded a new change for review.
https://gerrit.wikimedia.org/r/171767
Change subject: WIP: add wikidata descriptions... somewhere
......................................................................
WIP: add wikidata descriptions... somewhere
Change-Id: I90d72c3485a35d12774a6c24659a609765405582
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
2 files changed, 46 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend
refs/changes/67/171767/1
diff --git a/MobileFrontend.php b/MobileFrontend.php
index fc01c44..a5bc82f 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -559,3 +559,8 @@
// Just don't
NS_MEDIA,
);
+
+/**
+ * If set to true will DO STUFF, EXPLAIN WHICH
+ */
+$wgMFUseWikibaseDescription = false;
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index 989d855..c87a62d 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -1,7 +1,7 @@
<?php
-/**
- * MobileFrontend.hooks.php
- */
+
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\ItemId;
/**
* Hook handlers for MobileFrontend extension
@@ -929,9 +929,21 @@
* @return bool
*/
public static function onOutputPageParserOutput( $outputPage,
ParserOutput $po ) {
+ global $wgMFUseWikibaseDescription;
+
if ( MobileContext::singleton()->shouldDisplayMobileView() ) {
$outputPage->enableTOC( false );
$outputPage->setProperty( 'MinervaTOC',
$po->getTOCHTML() !== '' );
+
+ if ( $wgMFUseWikibaseDescription ) {
+ $item = $po->getProperty( 'wikibase_item' );
+ if ( $item ) {
+ $desc = self::getWikibaseDescription(
$item, $outputPage->getLanguage()->getCode() );
+ if ( $desc ) {
+ $outputPage->setProperty(
'mf-wikibase-description', $desc );
+ }
+ }
+ }
}
return true;
}
@@ -953,4 +965,30 @@
public static function onLoginFormValidErrorMessages( &$messages ) {
$messages[] = 'mobile-frontend-donate-image-anon';
}
+
+ /**
+ * @param string $item
+ * @param string $langCode
+ * @return string|null
+ */
+ private static function getWikibaseDescription( $item, $langCode ) {
+ if ( !class_exists( 'Wikibase\\Client\\WikibaseClient' ) ) {
+ return null;
+ }
+
+ $profileSection = new ProfileSection( __METHOD__ );
+ $entityLookup = WikibaseClient::getDefaultInstance()
+ ->getStore()
+ ->getEntityLookup();
+ $entity = $entityLookup->getEntity( new ItemId( $item ) );
+ if ( !$entity ) {
+ return null;
+ }
+ try {
+ return $entity->getFingerprint()->getDescription(
$langCode )->getText();
+ } catch ( Exception $ex) {
+ // Do nothing
+ }
+ return null;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/171767
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I90d72c3485a35d12774a6c24659a609765405582
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits