Extension:Display Title

This page is a translated version of the page Extension:Display Title and the translation is 88% 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
季度下載量 63 (Ranked 89th)
翻译Display Title扩展
問題 开启的任务 · 报告错误

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

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

安裝

  • 下载文件,并将其放置在您extensions/文件夹中的DisplayTitle目录内。
    开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/DisplayTitle
  • 将下列代码放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'DisplayTitle' );
    
  • 按需求配置。
  •   完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。

配置

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

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

$wgAllowDisplayTitle = true; // 默认为 true
$wgRestrictDisplayTitle = false; // 默认为 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

<span id="#getdisplaytitle_parser_function">

#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的显示标题。

重定向

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

请注意,这有两个影响,会使用户初次看到它们时可能会有意想不到的情况。 当带有显示标题的页面被移动并保留重定向时,在指示移动成功的页面上,源页面和目标页面的链接文本将相同。 而且,对于显示标题为重定向目标的页面,在 Special:WhatLinksHere 页面上,重定向页面的链接文本将是目标页面的显示标题。

将遵循单一级别的重定向。

历史

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

Display Title 仅依赖于 MediaWiki 核心中的功能;它不依赖于任何其他扩展名。 Display Title 中的功能已从 Semantic Title 中删除,现在仅保留了从 Semantic MediaWiki 属性或 Cargo 字段设置页面显示标题的功能。 但是建议使用 {{DISPLAYTITLE:...}} 而不是 Semantic Title 的功能来设置页面的显示标题。 为了向后兼容,将维护 Semantic Title

发行说明

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
  • 添加 $wgDisplayTitleExcludes 数组以定义链接不应使用 DisplayTitle 的页面列表
  • 修复链接文本中出现下划线时的行为
  • 不要使用已弃用的 ParserBeforeStrip 钩子
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 将会失效。 因此原始页面标题将不会显示在标题栏下方。

参见