Sumit has uploaded a new change for review.

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

Change subject: WikidataPageBanner add link to icons
......................................................................

WikidataPageBanner add link to icons

Allow editors to define the article an icon refers to by specifying it in an
optional [] after icon name. Example icons=star[Star article].

Bug: T108207
Change-Id: Ib4494910f68a1d45e470cd5b463a2ab17d3b72b6
---
M includes/WikidataPageBanner.functions.php
M templates/banner.mustache
2 files changed, 22 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/59/229759/1

diff --git a/includes/WikidataPageBanner.functions.php 
b/includes/WikidataPageBanner.functions.php
index fd059c2..44aa364 100644
--- a/includes/WikidataPageBanner.functions.php
+++ b/includes/WikidataPageBanner.functions.php
@@ -30,12 +30,31 @@
                                if ( empty( $iconname ) ) {
                                        continue;
                                }
-                               $iconName = Sanitizer::escapeClass( $iconname );
+                               $iconData[] = $iconname;
+                               // separate the icon name from link present 
within [], if such a link given
+                               if ( strpos( $iconname, '[' ) !== false ) {
+                                       // store name in first index
+                                       $iconData[0] = substr( $iconname, 0, 
strpos( $iconname, '[' ) );
+                                       // take the link as the substring 
within []
+                                       $iconData[1] = substr( $iconname, 
strpos( $iconname, '[' ) + 1, -1 );
+                               }
+
+                               // Generate the icon from the part before []
+                               $iconName = Sanitizer::escapeClass( 
$iconData[0] );
                                $icon = new OOUI\IconWidget( array(
                                        'icon' => $iconName,
                                        'title' => $iconName
                                ) );
-                               $iconsToAdd[] = array( 'icon' => $icon );
+                               // set a default iconurl as '#' in case none is 
provided
+                               $finalIcon = array( 'icon' => $icon, 'iconurl' 
=> '#' );
+                               if ( count( $iconData ) === 2 ) {
+                                       $iconUrl = Title::newFromText( 
$iconData[1] );
+                                       // reference article for icons provided 
and is valid, then add its link
+                                       if ( $iconUrl->exists() ) {
+                                               $finalIcon['iconurl'] = 
$iconUrl->getLocalUrl();
+                                       }
+                               }
+                               $iconsToAdd[] = $finalIcon;
                        }
                        // only set hasIcons to true if parser function gives 
some non-empty icon names
                        if ( !empty( $iconsToAdd ) ) {
diff --git a/templates/banner.mustache b/templates/banner.mustache
index a10996a..663c9e8 100644
--- a/templates/banner.mustache
+++ b/templates/banner.mustache
@@ -5,7 +5,7 @@
                {{#hasIcons}}
                <div class="wpb-iconbox">
                        {{#icons}}
-                               {{{icon}}}
+                               <a href="{{iconurl}}">{{{icon}}}</a>
                        {{/icons}}
                </div>
                {{/hasIcons}}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4494910f68a1d45e470cd5b463a2ab17d3b72b6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <asthana.sumi...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to