Jason.ji has uploaded a new change for review.

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

Change subject: VikiTitleIcon now supports title icons from a page's category - 
only if it doesn't have its own title icon(s).
......................................................................

VikiTitleIcon now supports title icons from a page's category - only if it 
doesn't have its own title icon(s).

Change-Id: Id1b22dbab821a9ecc14adb605afd606e02889571
---
M ApiGetTitleIcons.php
M VikiTitleIcon.php
2 files changed, 66 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VikiTitleIcon 
refs/changes/79/235079/1

diff --git a/ApiGetTitleIcons.php b/ApiGetTitleIcons.php
index 051acea..3622536 100644
--- a/ApiGetTitleIcons.php
+++ b/ApiGetTitleIcons.php
@@ -65,6 +65,47 @@
                        $key = array_shift( array_keys( 
$data["query"]["results"] ) );
                        $titleIconNames = 
$data["query"]["results"][$key]["printouts"]["$titleIconWithSpaces"];
                }
+
+               if( count( $titleIconNames ) == 0 ) {
+                       // If there are no title icons from the page, then get 
them from the page's categories
+
+                       $api = new ApiMain(
+                               new DerivativeRequest(
+                                       $this->getRequest(),
+                                       array(
+                                               'action' => 'query',
+                                               'titles' => $pageNameWithSpaces,
+                                               'prop' => 'categories'
+                                       )
+                               ),
+                               false
+                       );
+
+                       $api->execute();
+                       $data = $api->getResultData();
+
+                       $keys = array_keys( $data['query']['pages'] );
+                       $key = array_shift( $keys );
+
+
+                       if( array_key_exists( "categories", 
$data["query"]["pages"][$key]) ) {
+                               $categories = array();
+                               
foreach($data["query"]["pages"][$key]["categories"] as $categoryObject) {
+                                       $categories[] = 
$categoryObject["title"];
+                               }
+
+                               foreach( $categories as $category ) {
+                                       $title = Title::newFromText( $category 
);
+
+                                       $discoveredIcons = 
$this->getPropertyValues( $title, $titleIconWithSpaces );
+                                       foreach($discoveredIcons as $icon) {
+                                               $titleIconNames[] = $icon;
+                                       }
+                               }
+                       }
+               }
+
+
                $titleIconURLs = array();
 
                foreach ( $titleIconNames as $name ) {
@@ -98,6 +139,30 @@
                return true;
 
        }
+
+       private function getPropertyValues( Title $title, $propertyname ) {
+
+               $store = \SMW\StoreFactory::getStore();
+
+               // remove fragment
+               $title = Title::newFromText( $title->getPrefixedText() );
+
+               $subject = SMWDIWikiPage::newFromTitle( $title );
+               $data = $store->getSemanticData( $subject );
+               $property = SMWDIProperty::newFromUserLabel( $propertyname );
+               $values = $data->getPropertyValues( $property );
+
+               $strings = array();
+               foreach ( $values as $value ) {
+                       if ( $value->getDIType() == SMWDataItem::TYPE_STRING ||
+                               $value->getDIType() == SMWDataItem::TYPE_BLOB ) 
{
+                               $strings[] = trim( $value->getString() );
+                       }
+               }
+
+               return $strings;
+       }
+
        public function getDescription() {
                return "Get the URLs of all Title Icons for the page, if any 
exist.
 
diff --git a/VikiTitleIcon.php b/VikiTitleIcon.php
index ca23160..3ac6692 100644
--- a/VikiTitleIcon.php
+++ b/VikiTitleIcon.php
@@ -55,7 +55,7 @@
 $wgExtensionCredits['parserhook'][] = array (
        'path' => __FILE__,
        'name' => 'VikiTitleIcon',
-       'version' => '1.0.1',
+       'version' => '1.1',
        'author' => '[http://www.mediawiki.org/wiki/User:Jji Jason Ji]',
        'descriptionmsg' => 'vikititleicon-desc',
        'url' => 'http://www.mediawiki.org/wiki/Extension:VikiTitleIcon'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1b22dbab821a9ecc14adb605afd606e02889571
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VikiTitleIcon
Gerrit-Branch: master
Gerrit-Owner: Jason.ji <[email protected]>

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

Reply via email to