MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/180895

Change subject: Expose Wikidata descriptions via mobileview
......................................................................

Expose Wikidata descriptions via mobileview

Change-Id: If92e1217e73ea0b6e2d24e6cf0be0dd0fec2c179
---
M includes/MobileFrontend.body.php
M includes/MobileFrontend.hooks.php
M includes/api/ApiMobileView.php
3 files changed, 44 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/95/180895/1

diff --git a/includes/MobileFrontend.body.php b/includes/MobileFrontend.body.php
index 8fb2d23..a76a3f5 100644
--- a/includes/MobileFrontend.body.php
+++ b/includes/MobileFrontend.body.php
@@ -3,6 +3,9 @@
  * MobileFrontend.body.php
  */
 
+use Wikibase\Client\WikibaseClient;
+use Wikibase\DataModel\Entity\ItemId;
+
 /**
  * Implements additional functions to use in MobileFrontend
  */
@@ -66,4 +69,33 @@
                wfProfileOut( __METHOD__ );
                return $contentHtml;
        }
+
+       /**
+        * Returns a short description of a page from Wikidata
+        *
+        * @param string $item Wikibase id of the page
+        * @return string|null
+        */
+       public static function getWikibaseDescription( $item ) {
+               global $wgContLang;
+
+               if ( !class_exists( 'Wikibase\\Client\\WikibaseClient' ) ) {
+                       return null;
+               }
+
+               $profileSection = new ProfileSection( __METHOD__ );
+               try {
+                       $entityLookup = WikibaseClient::getDefaultInstance()
+                               ->getStore()
+                               ->getEntityLookup();
+                       $entity = $entityLookup->getEntity( new ItemId( $item ) 
);
+                       if ( !$entity ) {
+                               return null;
+                       }
+                       return $entity->getFingerprint()->getDescription( 
$wgContLang->getCode() )->getText();
+               } catch ( Exception $ex) {
+                       // Do nothing, exception mostly due to description 
being unavailable in needed language
+               }
+               return null;
+       }
 }
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index ecf82cf..8cb3f7a 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -3,9 +3,6 @@
  * MobileFrontend.hooks.php
  */
 
-use Wikibase\Client\WikibaseClient;
-use Wikibase\DataModel\Entity\ItemId;
-
 /**
  * Hook handlers for MobileFrontend extension
  *
@@ -950,7 +947,7 @@
                        if ( $wgMFUseWikibaseDescription && 
$context->isAlphaGroupMember() ) {
                                $item = $po->getProperty( 'wikibase_item' );
                                if ( $item ) {
-                                       $desc = self::getWikibaseDescription( 
$item );
+                                       $desc = 
ExtMobileFrontend::getWikibaseDescription( $item );
                                        if ( $desc ) {
                                                $outputPage->setProperty( 
'wgMFDescription', $desc );
                                        }
@@ -978,34 +975,5 @@
         */
        public static function onLoginFormValidErrorMessages( &$messages ) {
                $messages[] = 'mobile-frontend-donate-image-anon';
-       }
-
-       /**
-        * Returns a short description of a page from Wikidata
-        *
-        * @param string $item Wikibase id of the page
-        * @return string|null
-        */
-       private static function getWikibaseDescription( $item ) {
-               global $wgContLang;
-
-               if ( !class_exists( 'Wikibase\\Client\\WikibaseClient' ) ) {
-                       return null;
-               }
-
-               $profileSection = new ProfileSection( __METHOD__ );
-               try {
-                       $entityLookup = WikibaseClient::getDefaultInstance()
-                               ->getStore()
-                               ->getEntityLookup();
-                       $entity = $entityLookup->getEntity( new ItemId( $item ) 
);
-                       if ( !$entity ) {
-                               return null;
-                       }
-                       return $entity->getFingerprint()->getDescription( 
$wgContLang->getCode() )->getText();
-               } catch ( Exception $ex) {
-                       // Do nothing, exception mostly due to description 
being unavailable in needed language
-               }
-               return null;
        }
 }
diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index 6868f3f..9424c99 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -139,6 +139,15 @@
                                array( 'pageprops' => $pageProps )
                        );
                }
+               if ( isset( $prop['description'] ) && isset( 
$data['pageprops']['wikibase_item'] ) ) {
+                       $desc
+                               = ExtMobileFrontend::getWikibaseDescription( 
$data['pageprops']['wikibase_item'] );
+                       if ( $desc ) {
+                               $this->getResult()->addValue( null, 
$this->getModuleName(),
+                                       array( 'description' => $desc )
+                               );
+                       }
+               }
                if ( $this->usePageImages ) {
                        $this->addPageImage( $data, $prop, $params['thumbsize'] 
);
                }
@@ -692,6 +701,7 @@
                                        'hasvariants',
                                        'displaytitle',
                                        'pageprops',
+                                       'description',
                                )
                        ),
                        'sectionprop' => array(
@@ -775,6 +785,7 @@
                                ' hasvariants     - whether or not the page is 
available in other language variants',
                                ' displaytitle    - the rendered title of the 
page, with {{DISPLAYTITLE}} and such applied',
                                ' pageprops       - page properties',
+                               ' description     - page description from 
Wikidata',
                        ),
                        'sectionprop' => 'What information about sections to 
get',
                        'pageprops' => 'What page properties to return, a pipe 
(|) separated list or * for'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If92e1217e73ea0b6e2d24e6cf0be0dd0fec2c179
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

Reply via email to