Extension:维基数据页面横幅
| This code base is maintained by the Reader Experience team. Code review only for UBNs or security fixes. |
发行状态: 稳定版 |
|
|---|---|
| 实现 | 解析器函数 |
| 描述 | 在wiki页面的顶部添加多個寬的横幅影像。 |
| 作者 | (under the mentorship of User:Jdlrobson and User:Syced). (Sumit留言) |
| 最新版本 | 0.0.3 |
| MediaWiki | >= 1.46 |
| PHP | 5.4+ |
|
|
|
pagebanner |
|
| 许可证 | GNU General Public License 2.0 or later |
| 下載 | README |
| 前往translatewiki.net翻譯WikidataPageBanner扩展 | |
| 問題 | 开启的任务 · 报告错误 |
WikidataPageBanner扩展会在wiki页面的顶部增加横幅影像。它可將橫幅影像增加至指定命名空間中的每一個頁面,或是僅新增至特定頁面。 這些影像的檔名可以儲存於維基數據(以page banner (P948))而非本地維基。
页面横幅广泛用于维基导游的项目。 此扩展主要受维基导游的頁面橫幅模板的启发。
安裝
- 下载文件,并解压
WikidataPageBanner文件夹到extensions/目录中。
开发者和代码贡献人员应改从Git安装此扩展,输入:cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/WikidataPageBanner
- 請新增下列代码到您的LocalSettings.php文件的底部:
wfLoadExtension( 'WikidataPageBanner' );
完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。
用法
在頁面中設定橫幅影像有幾種不同的方法:
- 若要將
File:Image_name.jpg設為自訂橫幅影像,請在頁面中設定:{{PAGEBANNER:Image_name.jpg}} - 该扩展可以自动添加相同的横幅影像到指定名字空间中的所有页面上。
- 如果维基已连接到维基数据,则它也可以从那里获取每一個頁面横幅。 在此情況下,Template:PAGEBANNER必須存在(但內容可以為空)。 英文版維基導遊(Wikivoyage)提供了一個帶有渲染邏輯及額外模板依赖項的複雜 Template:Pagebanner 範例。
傳入{{PAGEBANNER}}函式的參數
{{PAGEBANNER}}解析器功能支持以下参数:
|pgname=— 在横幅裏添加一個自定义标题。|icon-*=— To add custom icons, add the parameter|icon-<icon_name>=<Article about icon>(where<icon_name>is any icon name that you want). Then define a background-image on.oo-ui-icon-<icon_name>, in MediaWiki:Common.css to use as the icon. Do this for any number of icons to add to the page.|tooltip=— Use|tooltip=image-captionto show image description on hovering over image.|toc=— Use|toc=yesto enable a Table Of Contents within banner.|bottomtoc=— Use|bottomtoc=yesto push Table Of Contents below banner. This will affect only the page on which its used. To set site-wide ToC at bottom, see section #Styling below.|extraClass=— Use|extraClass=<css-class names>(separated by spaces) to add additional classes to banners which can be used to customize it using styles in MediaWiki:Common.css|origin=— See section #origin below.|link=— Sets the target of the banner link and operates the same as the link parameter for images (e.g.|link=Event namewill link to the 'Event name' page rather than the banner image page). Set to no value to remove the link, i.e.|link=.
'origin' 参数

Use this parameter to define a suggested 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 right corner and |origin=-1,1 is the bottom right corner.
See the image at right for a graphical representation of the coordinates.
Note that |origin= is meant for images that are much larger than the target banner (e.g. panoramas or portrait photos).
It will not reposition banners where the repositioning leads to empty whitespace within the banner space.
For example, if the banner is being rendered at 320px width and 180px height, an image that is also 320px and 180px cannot be repositioned at all; an image that is 600px width by 180px height can be repositioned horizontally and an image that is 320px width and 1000px height can be repositioned vertically.
配置的变量
| Name | Description | Default |
|---|---|---|
$wgWPBImage
|
used to set the default banner image to be used. Add image name without prefixing 'File:' namespace. If the wiki does not need default banners, do not edit this field.
$wgWPBImage = "foo.jpg";
|
""
|
$wgWPBBannerProperty
|
Banner property on Wikidata which holds a commons media file. Essential if Wikidata is enabled.
$wgWPBBannerProperty = "P948";
|
""
|
$wgWPBEnableDefaultBanner
|
enables the default banner image on pages without the use of {{PAGEBANNER}}.
|
false
|
$wgWPBNamespaces
|
array of namespaces on which to display the banner. It can also be set to true(), in which case it'll enable banner on all Namespaces, except those excluded by $wgWPBDisabledNamespaces. | [ NS_MAIN ]
|
$wgWPBDisabledNamespaces
|
excludes certain namespaces from showing banner. Note that this parameter only has effect if $wgWPBNamespaces is true. Otherwise, this parameter is disregarded and only namespaces in $wgWPBNamespaces are considered.
$wgWPBDisabledNamespaces = [ NS_FILE ];
|
[]
|
$wgWPBStandardSizes
|
an array of standard predefined screen widths in increasing order of size. | [ 640, 1280, 2560 ]
|
$wgWPBEnablePageImagesBanners
|
when set to true and Extension:PageImages(页面图片) is installed will use a page image when no Wikidata image or locally defined image is set. | false
|
$wgWPBDisplaySubtitleAfterBannerSkins
|
an array of names of skins that should have the banner displayed in the site-notice area, instead of in the page subtitle (which is the default). | [ 'minerva' ]
|
$wgWPBEnableHeadingOverride
|
determines whether the page title is displayed overlayed on the banner image. | true
|
$wgWPBEnableMainPage
|
determines whether a banner is allowed to be shown on the 首页. | false
|
示例
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.
來自維基數據的橫幅使用範例
Make sure $wgWPBBannerProperty is set to correct Wikidata banner property.
Then leave the image name empty, and set any other required parameters:
{{PAGEBANNER:|other options...}}
This will use the banner image as set on the page's Wikidata item.
If there is no banner image set for that item, or the page doesn't have a Wikidata item, a default image may be used (if $wgWPBImage is set).
样式設定
The extension has ample scope for styling the banner via Common.css. Here are some examples of common CSS changes.
.wpb-topbanner-toc {
position: relative;
}
This sets the ToC to appear just below the banner in case it's long.
Note that doing this would cause every banner page on a wiki to have the ToC at the bottom of the banner.
However, using bottomtoc=yes as a paramter would only show the ToC at the bottom on the page it's used.
.wpb-topbanner .wpb-name {
font-size: 1em;
}
Would set the font size of the banner name to 1 em (smaller than the default 2.2 em).
.wpb-banner-toc {
line-height: 1em;
}
Would reduce the vertical spacing between lines of the ToC.
.wpb-topbanner-toc {
margin-top: 5px;
}
Would set some blank space between the banner and ToC.
| 此扩展用于一个或多个维基媒体项目。 这可能意味着扩展足够稳定、运作足够良好,可以用在这样的高流量的网站上。 请在维基媒体的CommonSettings.php和InitialiseSettings.php配置文件中查找此扩展的名称以查看哪些网站安装了该扩展。 特定wiki上的已安装的扩展的完整列表位于Special:Version页面。 |
| 此扩展在以下wiki农场/托管网站和/或软件包中提供: |
- Stable extensions/zh
- Parser function extensions/zh
- BeforePageDisplay extensions/zh
- OutputPageParserOutput extensions/zh
- ParserFirstCallInit extensions/zh
- ParserOutputPostCacheTransform extensions/zh
- SiteNoticeAfter extensions/zh
- GPL licensed extensions/zh
- Extensions in Wikimedia version control/zh
- All extensions/zh
- Pages using deprecated NoteTA template
- Extensions used on Wikimedia/zh
- Extensions included in Miraheze/zh
- Advertising extensions/zh
- Notification extensions/zh
- Wikibase extensions/zh
