Extension:Display Title

From mediawiki.org
This page is a translated version of the page Extension:Display Title and the translation is 77% complete.
MediaWiki扩展手册
Display Title
发行状态: 稳定版
实现 用户界面, 解析器函数
描述 在链接文本和讨论页标题中使用displaytitle页面属性,(可选)将原始页面标题显示为副标题,并提供解析器函数用于查询displaytitle。
作者
最新版本 4.0.2 (2023-07-26)
兼容性政策 快照跟随MediaWiki发布。 master分支不向后兼容。
MediaWiki 1.39+
PHP 7.4+
Composer mediawiki/display-title
许可协议 MIT授權條款
下載
  • $wgDisplayTitleFollowRedirects
  • $wgDisplayTitleExcludes
  • $wgDisplayTitleHideSubtitle
季度下載量 91 (Ranked 84th)
翻译Display Title扩展
問題 开启的任务 · 报告错误

Display Title扩展允许将页面的显示标题用作页面链接中的默认链接文本——这既包括来自其它页面的链接,也包括页面上的自链接。 Display Title还使用页面的显示标题作为其讨论页标题的一部分。 它可以选择性将原始页面标题显示为页面上的副标题。 而且他还提供了一个解析器函数用于查询页面的显示标题。

此扩展建立在MediaWiki的核心功能之上,支持通过使用DISPLAYTITLE魔术字设置页面的显示标题。 在页面上添加{{DISPLAYTITLE:我的显示标题}}会将显示标题(本例中为我的显示标题)存储在MediaWiki的page_props表的displaytitle页面属性中,如果配置得当,则会在页面上显示此值作为标题栏中的标题。 Display Title扩展通过查询page_props表中的displaytitle值以提供相关功能。

安裝

  • 下载文件,并将其放置在您extensions/文件夹中的DisplayTitle目录内。
  • 将下列代码放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'DisplayTitle' );
    
  • 按需求配置。
  • Yes 完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。

配置

配置标志 默认值 描述
$wgDisplayTitleHideSubtitle false 如果为false,将会让页面原来的标题作为副标题显示在标题栏下方。
$wgDisplayTitleExcludes [ ] 一个包含页面名称的数组,这些名称不应在指向页面的链接中替换为其显示标题。
$wgDisplayTitleFollowRedirects true 定义在显示标题时是否应遵循重定向规则。

虽然对于Display Title的功能来说并不是绝对必要的,但为了让{{DISPLAYTITLE:...}}魔术字按预期运行,请设置一下MediaWiki核心配置变量:

$wgAllowDisplayTitle = true; // defaults to true
$wgRestrictDisplayTitle = false; // defaults to true

在编辑页面和链接中显示标题

为了在编辑页面和指向它们的链接上使用Display Title,请在您的wiki上编辑以下系统消息(在适当的情况下替换wiki的本地语言):

系统消息页面名称 旧的页面内容 新的页面内容
MediaWiki:Editing Editing $1 Editing {{#if: {{NAMESPACE}} | {{NAMESPACE}}: |}}{{#getdisplaytitle:{{SUBJECTPAGENAME}}}}
MediaWiki:Editingcomment Editing $1 (new section) Editing {{#if: {{NAMESPACE}} | {{NAMESPACE}}: |}}{{#getdisplaytitle:{{SUBJECTPAGENAME}}}} (new section)
MediaWiki:Editingsection Editing $1 (section) Editing {{#if: {{NAMESPACE}} | {{NAMESPACE}}: |}}{{#getdisplaytitle:{{SUBJECTPAGENAME}}}} (section)
MediaWiki:Editsectionhint Edit section: $1 Edit section: {{#if: {{NAMESPACE}} | {{NAMESPACE}}: |}}{{#getdisplaytitle:{{SUBJECTPAGENAME}}}}
MediaWiki:Creating Creating $1 Creating {{#if:{{NAMESPACE}}|{{NAMESPACE}}:}} {{#getdisplaytitle: {{SUBJECTPAGENAME}} }}

如果您还使用Page Forms。

系统消息页面名称 旧的页面内容 新的页面内容
MediaWiki:Pf formedit createtitle Create $1: $2 Create $1: {{#if:{{NAMESPACE}}|{{NAMESPACE}}:}} {{#getdisplaytitle: {{SUBJECTPAGENAME}} }}
MediaWiki:Pf formedit edittitle Edit $1: $2 Edit $1: {{#if:{{NAMESPACE}}|{{NAMESPACE}}:}} {{#getdisplaytitle: {{SUBJECTPAGENAME}} }}


用法

链接

下表总结了不同链接类型的Display Title扩展的行为。该表显示了不同情况下的链接文本。 在表格中,A表示页面标题,a表示页面标题(如果有命名空间则是“Namespace:”之后的部分),其第一个字符为小写。 需要注意的是如果某个页面是重定向页面(即下方的“页面A重定向到页面B”一列)并设置了显示标题,则此扩展将忽略该显示标题。

源页面包含的链接: 页面A没有重定向 页面A重定向到页面B
页面A没有显示标题 页面A有显示标题Z 页面B没有显示标题 页面B有显示标题Y
[[A]] A Z B Y
[[a]] a
[[A | A]] A Z B Y
[[a | A]] A Z B Y
[[A | a]] a
[[a | a]] a
[[A | X]] X
[[a | X]] X

#getdisplaytitle解析器函数

#getdisplaytitle解析器函数能获取页面提供的显示标题。 例如:

{{#getdisplaytitle:Book:42}}

将会显示页面Book:42的显示标题。 要获取当前页面的显示标题,请使用:

{{#getdisplaytitle:{{FULLPAGENAME}}}}

Lua/Scribunto支持

有两个Lua(参见Extension:Scribunto )函数用于获取和设置页面的显示标题:mw.ext.displaytitle.get()mw.ext.displaytitle.set()。 要使用它们,您可以创建一个包含以下内容的页面Module:DisplayTitle

local p = {}

function p.set(frame)
	return mw.ext.displaytitle.set(frame.args[1])
end

function p.get(frame)
	return mw.ext.displaytitle.get(frame.args[1])
end

return p

然后您可以在一个页面上使用{{#invoke:DisplayTitle|set|My Display Title}}将页面的显示标题设置为My Display Title,并使用{{#invoke:DisplayTitle|get|My Page}}获取页面My Page的显示标题。

重定向

对于重定向页面,如果目标页面具有显示标题,则该页面将用作重定向页面的显示标题。

请注意,这有两个影响,会使用户初次看到它们时可能会有意想不到的情况。 When a page with a display title is moved leaving a redirect, on the page indicating that the move was a success the link text will be the same for both the source and target pages. And, on the Special:WhatLinksHere page for a page with a display title that is the target of a redirect, the link text of the redirect page will be the display title of the target page.

单次的重定向将会被遵循。

历史

此扩展的功能是从Semantic Title扩展的一部分发展而来的。 特别感谢1.0版本的Semantic Title的作者Van de Bugger

Display Title relies only on functionality in MediaWiki core; it does not depend on any other extension. The functionality in Display Title has been removed from Semantic Title, which now retains solely the functionality to set a page's display title from a Semantic MediaWiki property or Cargo field. However, it is recommended that a page's display title be set using {{DISPLAYTITLE:...}} rather than the functionality in Semantic Title. Semantic Title is being maintained for backward compatibility.

发行说明

Version 4.0.2
Version 4.0.1
  • Fix title handling in hooks (T342672)
  • Revert user preference to disable the extension due to a bug (T342727) and since the current approach introduces latency and risk
Version 4.0.0
  • Drop support for MediaWiki 1.38 and earlier
  • Add mw-displaytitle-subtitle class to subtitle (T205250)
  • Fix subpage subtitles for subpages more than two levels deep (T188872)
  • Fix redirect subtitle so it does not use the displaytitle (T306459)
  • Add name and description properties to composer.json (T311321)
  • Add a user preference to disable the extension (T217179)
  • Coding style and test improvements
Version 3.3
  • Do not remove fragments if not proper part of text
  • Change PersonalUrls hook to SkinTemplateNavigation::Universal hook
  • Replace deprecated WikiPage::factory/Use WikiPageFactory
Version 3.2
  • Add config option for changing redirect display ($wgDisplayTitleFollowRedirects)
  • Replace deprecated PageProps::getInstance
Version 3.1
  • Fix incompatibility with the Cite extension
Version 3.0
  • Several fixes to anchor/fragment behavior
  • Updates due to code deprecations in MediaWiki
  • Compatibility dropped with MW 1.34 and lower
Version 2.2.0
  • Add $wgDisplayTitleExcludes array to define a list of pages on which links should not use DisplayTitle
  • Fix behavior when there are underscores in the link text
  • Don't use deprecated ParserBeforeStrip hook
Version 2.1.0
  • Added tests
  • Added null title check
Version 2.0.0
  • Compatibility dropped with MW 1.28 and lower
  • Bug fixes:
    • T181669: Handle integers passed as link text
    • Fixed bug introduced in version 1.5.2 that caused self links to be wrapped in HtmlArmor
Version 1.5.3
  • On redirect pages, show display title of target page
    • Follows a single level of redirect
Version 1.5.2
  • Bug fixes:
    • T180413: Use supplied link text rather than display title when link text matches page title except for case of first character
    • T180409: Undefined variable: found in "DisplayTitleHooks.php" on line 152
    • T181228: Display titles with italics show as HTML
Version 1.5.1
  • Fixed issue for logged-in users on using action "info"
Version 1.5
  • Text that should have overridden link text was being ignored
  • Fix link to user page in header (personal URLs)
Version 1.4
  • Updated to work with MediaWiki 1.28+
Version 1.3
  • Modified self-links to determine display text identically to non-self-links
Version 1.2
  • Added mw.ext.displaytitle.get() and mw.ext.displaytitle.get() Lua functions written by User:Oetterer
Version 1.1
  • Added check for title with only fragment when creating link
Version 1.0
  • 初始发行

已知冲突

  • 如果您还安装了低于1.5.0版本的Semantic Breadcrumb Links扩展,则配置参数$wgDisplayTitleHideSubtitle将会失效。 因此原始页面标题将不会显示在标题栏下方。

参见