Sumit has uploaded a new change for review.

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

Change subject: WikidataPageBanner option to add icons added
......................................................................

WikidataPageBanner option to add icons added

The extension now supports defining new icons in its configuration, which can
then be activated by parameters to {{PAGEBANNER...}} to render on the banner.
The icons are represented as an array of key=>value pairs with keys representing
parameter names and values representing details about the icon. The
getBannerIcons() traverses this array, checks if its set as a parameter to
{{PAGEBANNER...}} and returns the icons array to insert into the banner
template. The parameter is of the form 'star=yes', to render a star icon.
depends on I1e67311e76c66c26bd8b1f2dc22856dffd98c99a

Bug: T100486
Change-Id: I36471b826e7cce9405c8d135bb3934bb0214170c
---
M WikidataPageBanner.php
A includes/WikidataPageBanner.functions.php
M includes/WikidataPageBanner.hooks.php
M resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
M templates/banner.mustache
5 files changed, 77 insertions(+), 2 deletions(-)


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

diff --git a/WikidataPageBanner.php b/WikidataPageBanner.php
index c634f5b..0c2a1ff 100644
--- a/WikidataPageBanner.php
+++ b/WikidataPageBanner.php
@@ -27,10 +27,31 @@
  *
  * $wgPBImage - static pagebanner image url, use only filename, do not prefix 
'File:'
  * $wgBannerNamespace - Namespaces on which to display banner
+ * $wgBannerIcons - array of icons with keys representing parameter names and
+ * values representing an array of values as
+ * (icon-file-name, icon-name, url of page about icon)
+ * $wgBannerIconSize - Size of each banner icon
  */
 $wgPBImage = "";
 $wgBannerNamespaces = array( NS_MAIN );
-
+$wgBannerIcons = array(
+               'star' => array(
+                               'Cscr-featured.svg', 'Star Article', 
'http://localhost:8080/wiki/Main_Page'
+                       ),
+               'unesco' => array(
+                               'WorldHeritageBlanc.svg', 'UNESCO World 
Heritage Site', 'http://localhost:8080/wiki/Main_Page'
+                       ),
+               'otbp' => array(
+                               'Yes_Check_Circle.svg', 'Previously Off the 
beaten path', 'http://localhost:8080/wiki/Main_Page'
+                       ),
+               'dotm' => array(
+                               'Yes_Check_Circle.svg', 
'Previous_Destinations_of_the_month', 'http://localhost:8080/wiki/Main_Page'
+                       ),
+               'ftt' => array(
+                               'Yes_Check_Circle.svg', 'Previously featured 
travel topic', 'http://localhost:8080/wiki/Main_Page'
+                       ),
+       );
+$wgBannerIconSize = 27;
 /* Setup */
 // autoloader
 $wgAutoloadClasses['WikidataPageBanner'] = __DIR__ . 
'includes/WikidataPageBanner.hooks.php';
@@ -49,5 +70,7 @@
 
 // include WikidataPageBanner class file
 require_once __DIR__ . "/includes/WikidataPageBanner.hooks.php";
+require_once __DIR__ . "/includes/WikidataPageBanner.functions.php";
 require_once __DIR__ . "/resources/Resources.php";
 
+
diff --git a/includes/WikidataPageBanner.functions.php 
b/includes/WikidataPageBanner.functions.php
new file mode 100644
index 0000000..31cdc18
--- /dev/null
+++ b/includes/WikidataPageBanner.functions.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * getBannerIcons Returns an array of icons with their url, name, and url of
+ * article they refer to
+ * @param $options array options passed as arguments to {{PAGEBANNER}} function
+ * @return array Array of icons with their url, name and and url of
+ * article they refer to.
+ */
+public function getBannerIcons( $options ) {
+       global $wgBannerIconSize, $wgBannerIcons;
+       $icons = array();
+       $i = 0;
+       foreach ( $wgBannerIcons as $key => $value ) {
+               if ( isset( $options[$key] ) && $options[$key] == 'yes' ) {
+                       $size = $wgBannerIconSize;
+                       $icon = $value;
+                       $iconfilename = $icon[0];
+                       $iconname = $icon[1];
+                       $iconurl = $icon[2];
+                       $url = WikidataPageBanner::getBannerUrl( $iconfilename, 
$size );
+                       if ( $url !== null ) {
+                               $icons[$i++] = array(
+                                               'iconfileurl' => $url,
+                                               'iconname' => $iconname,
+                                               'iconurl' => $iconurl
+                                       );
+                       }
+               }
+       }
+       return $icons;
+}
diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
index 522cc0e..6829e6c 100644
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -72,6 +72,7 @@
                $banner = '';
                $title = $parser->getTitle();
                $ns = $title->getNamespace();
+               $params['icon'] = getBannerIcons( $opts );
                if ( in_array( $ns, $wgBannerNamespaces ) && 
!$title->isMainPage() ) {
                        $banner = self::getBannerHtml( $fileurl, $title );
                        // Set 'articlebanner' property for future reference
diff --git 
a/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less 
b/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
index a6628a8..67d63ea 100644
--- a/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
+++ b/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
@@ -27,3 +27,17 @@
 h1.firstHeading {
        display: none;
 }
+
+.iconbox{
+       position: absolute;
+       margin-top: -1px;
+       right: 0px;
+       padding: 3px;
+       z-index: 3;
+       background: rgba(0, 0, 0, 0.7) none repeat scroll 0% 0%;
+       border-bottom-left-radius: 5px;
+}
+
+.iconbox p{
+       margin: 0.5em 0;
+}
diff --git a/templates/banner.mustache b/templates/banner.mustache
index cec3226..773a9e8 100644
--- a/templates/banner.mustache
+++ b/templates/banner.mustache
@@ -2,7 +2,13 @@
        <div class="ext-wpb-pagebanner" 
style="background-image:url({{banner}})">
                <div class="topbanner">
                        <div class="name">{{title}}</div>
-                       <div class="iconbox"></div>
+                       <div class="iconbox">
+                               <p>
+                               {{#icon}}
+                                       <a href={{iconurl}} 
title={{iconname}}><img src={{iconfileurl}}></a>
+                               {{/icon}}
+                               </p>
+                       </div>
                </div>
        </div>
 </div>

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

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