Jump to content

扩展:Popups

From mediawiki.org
This page is a translated version of the page Extension:Popups and the translation is 47% complete.
Outdated translations are marked like this.
关于the feature that is powered by this extension,参见:Page Previews
MediaWiki扩展手册
Popups
发行状态: 稳定版
实现 皮肤
描述 在用户悬停在条目链接及腳註標記时显示弹窗
作者
  • Prateek Saxena (user:Prtksxna),
  • Yair Rand,
  • Sam Smith,
  • Joaquín Oltra Hernández,
  • Bahodir Mansurov,
  • Jon Robson,
  • Piotr Miazga,
  • Jeff Hobson
  • WMDE Engineering
MediaWiki 1.37+
PHP 5.6+
许可协议 GNU通用公眾授權條款2.0或更新版本
下載
示例 English Wikipedia
  • $wgPopupsVirtualPageViews
  • $wgPopupsTextExtractsIntroOnly
  • $wgPopupsStatsvSamplingRate
  • $wgPopupsRestGatewayEndpoint
  • $wgPopupsHideOptInOnPreferencesPage
  • $wgPopupsPageDisabled
  • $wgPopupsGateway
  • $wgPopupsConflictingNavPopupsGadgetName
季度下載量 290 (Ranked 14th)
正在使用的公开wiki数 947 (Ranked 282nd)
前往translatewiki.net翻譯Popups扩展
問題 开启的任务 · 报告错误

当用户将鼠标悬停在一个页面和分别的引用时,弹窗(Popups)扩展会预览一篇文章的内容,对于引用,还会显示引用的完整内容。

这个扩展原始Design team的开始,因著名的Navigation popups(导航弹窗)而作。当前该功能对所有未登录的维基百科用户启用。参见页面预览以了解扩展运作的描述,以及在此维基媒体项目的更多信息。

引用预览功能最终被加入,并用于实现德语社区的愿望。参考文献预览 有更详细的介绍和更多信息。

依赖

mwApiPlain网关一起使用时,本扩展依赖于Extension:TextExtracts Extension:页面图片 测试功能 也有可选的依赖项(如果你想作为 Beta 功能启用参考预览),以及 Extension:EventLogging 扩展:WikimediaEvents (用于检测)。

安裝

  • 下载文件,并将解压后的Popups文件夹移动到extensions/目录中。
    开发者和代码贡献人员应从Git安装扩展,输入:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
  • 将下列代码放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'Popups' );
    
  • Yes 完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。
最终配置示例
wfLoadExtensions( [
    'TextExtracts',
    'PageImages',
    'Popups'
] );
$wgPopupsHideOptInOnPreferencesPage = true;
$wgPopupsReferencePreviewsBetaFeature = false;

配置

选项 默认值 帮助文档
$wgPopupsVirtualPageViews false Whether the extension should log virtual pageviews.
$wgPopupsHideOptInOnPreferencesPage false 是否应在首选项页面上隐藏启用/禁用页面预览的选项。
$wgPopupsOptInDefaultState 1 老账户的页面预览可见性默认值。必须是字符串,以便与beta功能设置兼容。 有关更多信息,请参阅 任务 T191888 This value is internally converted to the Bool type. Therefore, a value greater than or equal to 2 has the same meaning as 1.
$wgPopupsOptInStateForNewAccounts 1 新创建帐户的默认页面预览可见性(从 2018 年第二季度开始)。 有关更多信息,请参阅 任务 T191888
$wgPopupsConflictingNavPopupsGadgetName 'Navigation_popups' 本地 Navigation popups gadget 名称用作 MediaWiki:Gadgets-definition 中的标识符。 此小工具与页面预览不兼容。 对于启用了小工具的用户,该扩展程序将自行禁用。
$wgPopupsConflictingRefTooltipsGadgetName ReferenceTooltips 本地 参考文献提示工具 小工具名称用作 MediaWiki:Gadgets-definition 中的标识符。 此小工具与参考预览不兼容。 对于启用了小工具的用户,参考预览将自行禁用。
$wgPopupsGateway 'mwApiPlain' 用于获取弹出窗口数据的网关。 可用选项:mwApiPlain, restbasePlain, restbaseHTMLsrc/gateway/page.js 中提供了完整且始终最新的列表。
$wgPopupsRestGatewayEndpoint '/api/rest_v1/page/summary/' 指定摘要来源的REST端点。 端点必须符合 Specs/Summary/1.2.0 的规格。
$wgPopupsReferencePreviews true Temporary feature flag to disable reference previews during development.
$wgPopupsReferencePreviewsBetaFeature true 参考预览是否应作为Beta功能提供。如果为false,则默认情况下为所有用户启用参考预览。
$wgPopupsStatsvSamplingRate 0 将性能数据记录到 statsv 的采样率。
$wgPopupsPageDisabled Several special pages. See extension.json for the full list. 不应显示弹出窗口的页面列表。 包含子页面。 这些页面受 wiki 的 HTML 缓存策略的约束。 可能需要清除这些页面才能查看此配置变量的效果。 每个排除的页面都应由规范名称定义,例如:Special:Userlogin

页面预览内容

页面预览弹出窗口会显示一张图像(如果有的话)和一小段文字摘要。

图片

图片来源于Extension:页面图片 ,该图片返回与文章相关的单个最合适的缩略图。 它忽略维护模板,小作品,旗帜图标等。

文本

页面预览可以通过配置$wgPopupsRestGatewayEndpoint使用API,该API需要符合页面内容服务摘要端点规范。对于第三方,我们鼓励使用页面内容服务来在您本地的wiki使用Popups。

您也可以使用Extension:TextExtracts 扩展。 这个扩展有各种警告,我们不积极支持使用这个API。

Renderers

This extensions currently has only one renderer, that is for ordinary pages.

New renderers for different kind of pages, or things like references can be easily added.

One needs to create a new object with the following methods:

  • init
  • createPopup
  • getOffset
  • getClasses
  • processPopup

You can see details of these methods in ext.popups.renderer.article.js or this patch that adds a renderer for references.

Page previews API

Every project is different, and what displays in your previews is highly dependent on the content inside your wiki.

Popups extension has been optimized to work with Wikipedia-like content (e.g. wikitext).

If your wiki is using a different kind of content handler (for example as is the case for Wikibase ) it will need to provide its own API.

The API can be written in any language, but the response of the API must match the spec defined in Specs/Summary/1.2.0 .

Defining new APIs is out of scope for the Popups extension.

Once defined, you can configure page previews to point to your API using $wgPopupsRestGatewayEndpoint configuration option.

已知問題

  • Users of the Translate extension should note that Page Previews requests previews in the content language of the page. If the preview contains a complete translatable block, then it will be translated. If, however, the preview contains an incomplete translateable block – because a sentence is cut off, say – then it isn't translated and will be displayed in the content language of the page. If you are observing this behavior, then you should consider marking up individual sentences in your lead section. T167852 is for a technical audience but has more information on the underlying problem.
  • Longer math formulas cutting off in preview - long math or chemical formulas (formulas wider than the preview width) display as truncated in previews. We were not able to add a gradient in order to indicate that the formula is continued on the article itself.
  • Small files may be in the "Рage information" (action=info), but not in the "Popups". Some requirements are set here - for a portrait image: exact (min) height 250 px & max width 203 px; for a landscape image: exact (min) width 320 px & max height 200 px[1]. To display, images must be able to become a thumbnail that is larger or equal to these "exact" sizes. (If you are cropping a large image to make a leading picture for an article, be sure that the picture you are creating is not smaller than the specified sizes.)

Extensibility

In MediaWiki 1.40, extensions and skins can extend the page previews functionality with their own custom preview types.

It does this by registering a PluginModules attribute in its extension.json or skin.json file that points to a ResourceLoaderModule that can register a preview type.

{
    "attributes": {
        "Popups": {
            "PluginModules": [
              "skins.skinjson.popup"
            ]
        }
    }
}

The plugin module should export information about when the preview should be displayed (via selector), and how the preview data should be retrieved (via gateway library).

module.exports = {
        // a unique ID representing your preview type.
        type,
        // CSS selector that matches your custom preview type
        selector: '.mycustomselector',
        // Gateway
        gateway: {
                fetchPreviewForTitle:  ( title, el ) => {
                	const deferred = $.Deferred();
                	deferred.resolve( {
                		title: 'Hello world',
                		extract: [
                			`Hi`
                		],
                		url: 'https://www.mediawiki.org/wiki/Extension:Popups',
                		type,
                		languageCode: 'en',
                		languageDirection: 'ltr',
                		thumbnail: undefined,
                		pageId: -1
                	} );
                	return deferred;
                }
        }
};

For real world examples, Extension:數學 provide smath tooltips and Extension:引述 provides reference previews.

常见问题

Why can't I copy and paste text from a preview?

At time of writing, the cons of doing so outweigh the pros. Essentially it boils down to decreasing the touch area to read the article in full. Once Page Previews is deployed on English and German Wikipedia, feel free to reopen this task and reignite the discussion, but right now we have no plans.

How can I change the image that I see on preview?

如何从页面预览中移除内容?

Any element marked with the noexcerpt class will be stripped from the summary.

Why is content removed from the summary?

Any HTML element marked with the class noexcerpt, mw-ref, reference, noprint, nomobile or sortkey will be removed from the summary. If the text should be displayed in the summary, you should under no circumstances use these classes in any templates that are used within the beginning section of an article.

摘要来自哪里?

These are provided by the summary REST API (Wikimedia production wikis) or the TextExtracts API in case your wiki is using the default mwApiPlain gateway.

Why are parenthetical phrases stripped?

There's a good discussion going on in T91344 in Phabricator. If you have any views on this or see any problems relating to this, please let us know there.

Why don't I see Popups outside of content namespaces?

Popups appear on links to pages in content namespaces only. This is a limitation of Popups; TextExtracts are available from other namespaces. You may work around this by appending more namespaces into $wgContentNamespaces .

链接

Notes