jenkins-bot has submitted this change and it was merged.
Change subject: WikidataPageBanner redefine icons and add links
......................................................................
WikidataPageBanner redefine icons and add links
Allows editors to define the article an icon refers to. As a result, icons have
been redefined as separate parameters. Each icon parameter is of the form
icon-<iconname>=<Related Article Name>. Example icon-star=Star
Article|icon-unesco=Unesco.
This is important to let the readers know what the icons stand for and is
provided in the current Wikivoyage pagebanner template.
Corresponding tests added.
Bug: T108207
Change-Id: Ib4494910f68a1d45e470cd5b463a2ab17d3b72b6
---
M includes/WikidataPageBanner.functions.php
M templates/banner.mustache
M tests/phpunit/BannerOptionsTest.php
3 files changed, 33 insertions(+), 18 deletions(-)
Approvals:
Jdlrobson: Looks good to me, approved
Nicolas Raoul: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/includes/WikidataPageBanner.functions.php
b/includes/WikidataPageBanner.functions.php
index ee9b0ff..374e20c 100644
--- a/includes/WikidataPageBanner.functions.php
+++ b/includes/WikidataPageBanner.functions.php
@@ -22,26 +22,37 @@
*/
public static function addIcons( &$paramsForBannerTemplate,
$argumentsFromParserFunction ) {
$iconsToAdd = array();
- if ( isset( $argumentsFromParserFunction['icons'] ) ) {
- $icons = explode( ',',
$argumentsFromParserFunction['icons'] );
- foreach ( $icons as $iconname ) {
- // avoid icon generation when empty iconname
- // @FIXME don't use empty here
- if ( empty( $iconname ) ) {
+ // check all parameters and look for one's starting with icon-
+ // The old format of icons=star,unesco would not generate any
icons
+ foreach ( $argumentsFromParserFunction as $key => $value ) {
+ // found a valid icon parameter, so process it
+ if ( substr( $key, 0, 5 ) === 'icon-' ) {
+ // extract iconname after 'icon-' til the end
of key
+ $iconname = substr( $key, 5 );
+ if ( !isset( $iconname, $value ) ) {
continue;
}
$iconName = Sanitizer::escapeClass( $iconname );
- $icon = new OOUI\IconWidget( array(
+ $iconUrl = Title::newFromText( $value );
+ $iconTitleText = $iconName;
+ $finalIcon = array( 'iconurl' => '#' );
+ // reference article for icons provided and is
valid, then add its link
+ if ( $iconUrl ) {
+ $finalIcon['iconurl'] =
$iconUrl->getLocalUrl();
+ // set icon title to title of referring
article
+ $iconTitleText = $iconUrl->getText();
+ }
+ $finalIcon['icon'] = new OOUI\IconWidget( array(
'icon' => $iconName,
- 'title' => $iconName
- ) );
- $iconsToAdd[] = array( 'icon' => $icon );
+ 'title' => $iconTitleText,
+ ) );;
+ $iconsToAdd[] = $finalIcon;
}
- // only set hasIcons to true if parser function gives
some non-empty icon names
- if ( $iconsToAdd ) {
- $paramsForBannerTemplate['hasIcons'] = true;
- $paramsForBannerTemplate['icons'] = $iconsToAdd;
- }
+ }
+ // only set hasIcons to true if parser function gives some
non-empty icon names
+ if ( $iconsToAdd ) {
+ $paramsForBannerTemplate['hasIcons'] = true;
+ $paramsForBannerTemplate['icons'] = $iconsToAdd;
}
}
diff --git a/templates/banner.mustache b/templates/banner.mustache
index e6e9c62..96b78f8 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}}
diff --git a/tests/phpunit/BannerOptionsTest.php
b/tests/phpunit/BannerOptionsTest.php
index 92028b1..3daf8c2 100644
--- a/tests/phpunit/BannerOptionsTest.php
+++ b/tests/phpunit/BannerOptionsTest.php
@@ -71,14 +71,18 @@
$pOut->setProperty( 'wpb-banner-options', null );
$output = WikidataPageBanner::addCustomBanner( $parser,
'Banner1',
- 'pgname=Banner2', 'icons=unesco,star' );
+ 'pgname=Banner2', 'icon-unesco=', 'icon-star=Main Page'
);
$bannerparams = $pOut->getProperty( 'wpb-banner-options' );
$this->assertEquals( $bannerparams['title'], 'Banner2',
'pgname must be set' );
$this->assertEquals(
$bannerparams['icons'][0]['icon']->getTitle(), 'unesco',
'unesco icon must be set' );
- $this->assertEquals(
$bannerparams['icons'][1]['icon']->getTitle(), 'star',
+ $this->assertEquals( '#', $bannerparams['icons'][0]['iconurl'],
+ 'iconurl must be a default #' );
+ $this->assertEquals(
$bannerparams['icons'][1]['icon']->getTitle(), 'Main Page',
'star icon must be set' );
+ $this->assertContains( 'Main_Page',
$bannerparams['icons'][1]['iconurl'],
+ 'iconurl must be a valid main page url' );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/229759
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib4494910f68a1d45e470cd5b463a2ab17d3b72b6
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Nicolas Raoul <[email protected]>
Gerrit-Reviewer: Sumit <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits