Extension:WikidataPageBanner

From MediaWiki.org
Jump to: navigation, search


MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
WikidataPageBanner

Release status:Extension status stable

Banner ex.png
ImplementationTemplate:Extension#type Parser function
DescriptionTemplate:Extension#description Adds pagewide banners at the top of pages in specified namespaces on a wiki.
Author(s)Template:Extension#username (under the mentorship of User:Jdlrobson and User:Syced). (Sumittalk)
Latest versionTemplate:Extension#version 0.0.2
MediaWikiTemplate:Extension#mediawiki 1.25+
PHPTemplate:Extension#php 5.4+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later
Download
README
TagsTemplate:Extension#tags
pagebanner
Hooks usedTemplate:Extension#hook
BeforePageDisplayManual:Hooks/BeforePageDisplay
ArticleViewHeaderManual:Hooks/ArticleViewHeader
ParserFirstCallInitManual:Hooks/ParserFirstCallInit

Translate the WikidataPageBanner extension if it is available at translatewiki.net

Check usage and version matrix.

IssuesPhabricator

Open tasks · Report a bug

The WikidataPageBanner extension adds pagewide banners on every page of specified namespaces of the wiki.
Pagewide banners are extensively used on Wikivoyage projects. This extension is majorly inspired by Wikivoyage's Template:pagebanner

Installation[edit]

  • Download and place the file(s) in a directory called WikidataPageBanner in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'WikidataPageBanner' );
    
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Usage[edit]

The extension automatically adds a banner image on pages of specified namespaces. To use a custom banner image, use
{{PAGEBANNER:imagename.jpg}} with a set of parameters explained below.
If the wiki is connected to wikidata, it can also fetch banners from there

Parameters to the {{PAGEBANNER}} function[edit]

The following parameters are supported to the {{PAGEBANNER}} parser function:

  • pgname - Adds a custom title to the banner.
  • To add custom icons, add the parameter icon-icon_name=<Article about icon> to {{PAGEBANNER}}. Then define a background-image on .oo-ui-icon-icon_name, in Mediawiki:Common.css to use as the icon. Do this for any no. of icons to add to the page.
  • tooltip - Use tooltip=image-caption to show image description on hovering over image.
  • toc - Use toc=yes to enable a Table Of Contents within banner.
  • bottomtoc - Use bottomtoc=yes to push Table Of Contents below banner. This will affect only the page on which its used. To set site-wide toc at bottom, see Styling below.
  • origin - Use this parameter to define the focal area of the image. This is used to crop the banner appropriately on small screens. The value of the parameter should consist of an x and a y coordinate separated by a comma. Each coordinate represents the distance from the center of the image as a value from -1 to 1. For example, origin=1,1 is the top left corner and origin=-1,1 is the bottom left corner. See this graphic for more information.
  • extraClass - Use extraClass=name_of_css_classes(separated by space) to add additional classes to banners which can be used to customize it using styles in MediaWiki:Common.css

Configuration parameters for the extension[edit]

Required Settings[edit]

$wgWPBImage is used to set the default banner image to be used. Add image name without prefixing 'File:' namespace. Note that if the wiki does not need default banners, do not edit this field.

$wgWPBImage = "foo.jpg";

$wgWPBBannerProperty (Essential if Wikidata is enabled) - Banner property on wikidata which holds commons media file

$wgWPBBannerProperty = "P948";

To see default banners on pages even without the use of {{PAGEBANNER}}, set $wgWPBEnableDefaultBanner to true

$wgWPBEnableDefaultBanner = true;

Optional Settings[edit]

$wgWPBNamespaces array of namespaces on which to display the banner. Default is Main namespace. It can also be set to true, in which case it'll enable banner on all Namespaces, except those excluded by $wgWPBDisabledNamespaces.

$wgWPBNamespaces = array( NS_MAIN );

$wgWPBDisabledNamespaces excludes certain namespaces from showing banner. Note that this parameter only holds validity, if $wgWPBNamespaces is true. Otherwise, this parameter is disregarded and only namespaces in $wgWPBNamespaces are considered.

$wgWPBDisabledNamespaces = array( NS_FILE );

$wgWPBStandardSizes is an array of standard predefined screen widths in increasing order of size

$wgWPBStandardSizes = array( 320, 640, 1280, 2560 );

$wgWPBEnablePageImagesBannerswhen set to true and Extension:PageImages is installed will use a page image when no Wikidata image or locally defined image is set.

$wgWPBEnablePageImagesBanners = true;

User rights[edit]

Examples[edit]

A few use examples with explanation:

{{PAGEBANNER:Grand_canyon.jpg}}

Will add a banner using image Grand_canyon.jpg as source locally or from wikimedia commons.

{{PAGEBANNER:Grand_canyon.jpg|icon-star=<Name of star article>|icon-unesco=<Name of Unesco Article>}}

Will add a banner using image Grand_canyon.jpg as source locally or from wikimedia commons. Additionally will add icons with class names oo-ui-icon-star, oo-ui-icon-unesco. Set background-image property on theses classes in Mediawiki:Common.css to your desired icon.

{{PAGEBANNER:Grand_canyon.jpg|toc=yes|pgname=Some page}}

Will add a banner using image Grand_canyon.jpg as source locally or from Wikimedia Commons. Additionally adds a Table of Contents inside banner. Sets the name displayed on banner as Some page.

{{PAGEBANNER:Grand_canyon.jpg|extraClass=class1 class2}}

This will add a banner using the Grand_canyon.jpg image as source either locally or from Wikimedia Commons. It additionally adds CSS classes class1 and class2 to the .wpb-topbanner div.

Example usage for banner from wikidata[edit]

Make sure $wgWPBBannerProperty is set to correct wikidata banner property. Just use

{{PAGEBANNER:|other options...}}

Will add a banner trying to fetch banner image from wikidata property specified above if exists. If it does not exist, tries to add a default banner only if $wgWPBEnableDefaultBanner is set to true(default value is false).

Styling[edit]

The extension has ample scope of styling the banner from Mediawiki:Common.css For example, putting the codes given below in Mediawiki:Common.css would result as explained below:

.wpb-topbanner-toc{
    position: relative;
}

This would set the toc to appear just below the banner in case its long. Note that doing this would cause every page on wiki to have toc at bottom. However using bottomtoc=yes as a paramter would only show toc at the bottom on the page its used.

.wpb-topbanner .name{
    font-size: 1em;
}

Would set the font size of Banner Name as 1em.

.wpb-banner-toc{
    line-height: 1.0em;
}

Would reduce the vertcial spacing between lines of Table of contents

.wpb-topbanner-toc{
    margin-top:5px
}

Would set some blank space between banner and toc.

See also[edit]