Extension:DynamicPageListEngine(动态页面列表引擎)
此扩展与MediaWiki 1.45或更高的版本不兼容!
|
发行状态: 稳定版 |
|
|---|---|
| 实现 | 提取数据 |
| 描述 | 提供动态页面列表,为模块和其他扩展提供可配置、可扩充的功能 |
| 作者 | RV1971 (RV1971留言) |
| 最新版本 | 1.1.0 (2018-03-24) |
| MediaWiki | 1.30+ |
| PHP | 7.0+ |
| 数据库更改 | 否 |
|
|
| 许可证 | GNU General Public License 3.0 or later |
| 下載 | 发布说明 |
| 前往translatewiki.net翻譯DynamicPageListEngine扩展 | |
DynamicPageListEngine 擴充功能是一個提供動態頁面清單的後端,可在PHP層級供其他擴充功能使用,或搭配 Scribunto 擴充功能在 Lua層級使用。 頁面的篩選與排序的準則與 DynamicPageList (Wikimedia) 相容。
鑒於現已有DynamicPageList (Wikimedia)和DynamicPageList (第三方)存在,此兩者並不完全相容,您可能會好奇為何還要推出另一個這類擴充功能。 简而言之:
- 我需要在Lua層級上建立動態頁面清單,但現有的兩個擴充套件都無法提供這項功能。
- 由於該功能採用單體式實作,因此無法在 DynamicPageList (Wikimedia) 之上新增此類功能。
- 雖然在DynamicPageList (第三方)的基礎上新增此功能或許可行,但這樣一來,該功能將與部份維基媒體的擴充功能不相容。 更重要的是,正如DPL手冊所言,「目前DPL也相當於一個單體式系統」。
- 因此,唯一的解決方案就是從頭開始開發一個新的擴充功能。
- 第三方擴充功能的功能數量極為龐大,這顯示出需要一個可配置、模組化、且可擴充的後端。
安裝
- 下载文件,并解压
DynamicPageListEngine文件夹到extensions/目录中。
开发者和代码贡献人员应改从Git安装此扩展,输入:cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/DynamicPageListEngine
- 請新增下列代码到您的LocalSettings.php文件的底部:
wfLoadExtension( 'DynamicPageListEngine' );
完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。
尽管该扩展只在MediaWiki的1.30上进行过测试,但它很可能也适用于稍早的版本。
升级
要升级,只需安裝最新版本即可。
升级自0.3版或更早的版本
在1.0.0版中,几乎所有配置参数和信息名称都已更改。如果您对其中任何一项进行了自定义,则需要调整您的配置。
自1.0.0版起,使用DynamicPageListEngine的頁面會被歸類至追蹤分類。
如果您已經有這類頁面,您可以透過在每個頁面執行空編輯,或執行maintenance/refreshLinks.php腳本來修正分類。
請注意,後者可能需要相當長的時間。
配置
LocalSettings.php
There is a number of parameters that can be customized in LocalSettings.php. The default configuration aims at maximum compatibility with DynamicPageList (Wikimedia) and is likely to satisfy your needs if you use this extension for the first time.
- $wgDpleMaxCost
- Maximum cost of a dynamic page list in terms of database load. The default value NULL means that it is automatically set to the corresponding value for DynamicPageList (Wikimedia).
- $wgDpleMaxResultCount
- Maximum number of records to fetch for one list. The default value NULL means that it is automatically set to the corresponding value for DynamicPageList (Wikimedia).
- $wgDpleFeatures
- Features to enable. An associative array between feature name/class and a boolean to indicate enabled (
true) or not (false). See Usage for details. You should always enable at leastDpleFeatureCount, otherwise there is no limit to the number of fetched records, andDpleFeatureCheck, otherwise there is no limit on the complexity of the query. If you want to use Lua, you also needDpleFeatureResults. Each of these may be replaced with a derived class or a class with similar semantics.- The default list of features may be viewed in the extension's extension.json.
- $wgDpleCondCostMap
- Cost of selection conditions in terms of database load. A unit of 1 should correspond to an efficient table join. You can tune this map to reflect the real cost on your particular installation and/or prevent users from excessive use of certain features.
- $wgDpleOrderCostMap
- Cost of order methods in terms of database load, in units which should be vaguely comparable to those of
$wgDpleCondCostMap.
Unless you are very concerned about performance issues, you may simply enable all features in $wgDpleFeatures by copying it from the file DynamicPageListEngine.php any uncommenting everything.
In that case, to limit performance impact, you might decide to set $wgDpleMaxCost to a low value which however permits to use each feature, for instance 3.
信息
由于该扩展定义了大量信息,而这些信息会随着进一步开发而不断变化,因此这里就不一一记录了。请参阅i18n/qqq.json。
用法
For use on php level, please refer to the integrated doxygen documentation. For use on Lua level, see Lua library.
The accepted parameters and other aspects of the behaviour are implemented as features corresponding to php classes.
With the variable $wgDynamicPageListEngineFeatures in LocalSettings.php you can configure which features you want to enable.
The bundled features are described in the following sections, where the titles correspond to the class names without the prefix "DynamicPageListEngineFeature".
Unless otherwise stated, using arrays as parameter values return the intersection of the individual result sets.
If the parameters contradict each other (e.g. the same namespace is nominated in namespace and in not namespace), the results are undefined.
Namespace
Select by namespace.
Recognizes the parameters namespace and notnamespace which may be a namespace name or namespace index or an array thereof.
Any invalid value, including the empty string, is interpreted as the main namespace, for compatibility with DynamicPageList (Wikimedia).
If namespace is an array, the result set consists (obviously) in the pages in any of the namespaces, i.e. the result set is the union of the individual result sets, unlike other parameters (including notnamespace) where the result set is the intersection.
Category
Select by category.
Recognizes the parameters category and notcategory.
Each of them may be a string or an array.
If category is an array, the result set consists in the pages contained in all listed categories.
If notcategory is an array, the result set consists in the pages contained in none of the listed categories.
Redirects
Include or exclude redirects.
Recognizes the parameter redirects, which may be one of exclude|include|only|resolve.
Default is exclude, for compatibility with DynamicPageList (Wikimedia).
This implies that enabling this feature in $wgDynamicPageListEngineFeatures will change the result set of a dynamic page list even for parameter sets which do not contain the redirects parameter, if the result set would contain redirects.
The value resolve selects only redirects just like only, but in addition the target for each redirect is retrieved.
This means that the result object for each page has a property target which is an associative array of properties of the redirect target.
Titlematch
Select by title prefix, suffix or fragment.
Recognizes the parameters titleprefix, nottitleprefix, titlesuffix, nottitlesuffix, titlecontains and nottitlecontains, each of which may be a title substring or an array thereof.
As usual, spaces and underscores in titles are equivalent.
If titleprefix, titlesuffix, titlecontains is an array, the result set consists (obviously) in the pages satisfying any of the conditions, i.e. the result is the union of the individual result sets, unlike other parameters (including nottitleprefix) where the result set is the intersection.
This class implements a [not]title{prefix suffix contains} condition for substrings, but not a general [not]titlematch for LIKE patterns, because escaping of the % and _ characters depends on the database backend and hence it could not be ensured that a condition containing these metacharacters supplies the same result on all database backends.
Subpages
Include or exclude subpages.
Recognizes the parameter subpages, which may be one of exclude|include|only.
Default is exclude, for consistency with the Redirects feature.
This implies that enabling this feature in $wgDynamicPageListEngineFeatures will change the result set of a dynamic page list even for parameter sets which do not contain the subpages parameter, if the result set would contain subpages.
Subpage selection works with a simple LIKE '%/%' expression, regardless of whether the namespace of a page has subpages enabled. To distinguish whether subpages are enabled, a CASE expression or something similar would need to be evaluated for each single row, and it would be difficult to implement this in an efficient and portable way.
Linksto
Select pages linking to the specified pages.
Recognizes the parameters linksto and notlinksto.
Each of them may be a string or an array.
The result set differs from the result of "What links here" because it does not contain redirects, for compatibility with DynamicPageList (third-party).
Linksfrom
Select paged linked from specified pages.
Recognizes the parameters linksfrom and notlinksfrom.
Each of them may be a string or an array.
The names are chosen for compatibility with DynamicPageList (third-party).
Redirectsto
Select pages redirecting to the specified pages.
Recognizes the parameters redirectsto and notredirectsto.
Each of them may be a string or an array.
Uses
Select pages using the specified pages as templates.
Recognizes the parameters uses and notuses.
Each of them may be a string or an array.
The results are the same as with DynamicPageList (third-party).
Usedby
Select pages used as templates by the specified pages.
Recognizes the parameters usedby and notusedby.
Each of them may be a string or an array.
The results are the same as with DynamicPageList (third-party).
Imageused
Select pages that contain the specified images.
Recognizes the parameters imageused and notimageused.
Each of them may be a string or an array.
The names are chosen for compatibility with DynamicPageList (third-party).
Imagecontainer
Select images that are contained in the specified pages.
Recognizes the parameters imagecontainer and notimagecontainer.
Each of them may be a string or an array.
The names are chosen for compatibility with DynamicPageList (third-party).
Contains
Select categories which contain the specified pages.
Recognizes the parameters contains and notcontains.
Each of them may be a string or an array.
Extra
Select pages by extra information in category tags.
You can add extra information in a category sort key, in constructs like [[Category:...|user:{{PAGENAME}}|head of team]].
For MediaWiki, the whole string user:{{PAGENAME}}|head of team is the sort key.
The extension considers the part after the second pipe character (head of team in the example) as extra information.
The feature recognizes the parameters extra and notextra.
extra selects exact matches of the extra information appended to the sort key for the first category specified with the category parameter.
notextra selects the complement of this.
If no categories are selected, these parameters are silently ignored.
If extra is an array, the result set consists (obviously) in the pages satisfying any of the conditions, i.e. the result is the union of the individual record sets, unlike other parameters (including notextra) where the result set is the intersection.
Extrax
Select categories by extra information in category tags.
The feature recognizes the parameters extrax and notextrax.
extrax selects categories with exact matches for the extra information appended to the sort key for the first page specified with the contains parameter.
notextrax selects the complement of this.
If no contains parameter was used, these parameters are silently ignored.
If extrax is an array, the result set consists (obviously) in the pages satisfying any of the conditions, i.e. the result is the union of the individual record sets, unlike other parameters (including notextrax) where the result is the intersection.
User
Selection by modifying user.
Recognizes the parameters createdby, notcreatedby, modifiedby, notmodifiedby, lastmodifiedby and notlastmodifiedby, each of which may be a title substring or an array thereof.
If createdby, modifiedby, lastmodifiedby is an array, the result set consists in the pages satisfying any of the conditions, i.e. the result is the union of the individual record sets, unlike other parameters (including notcreatedby) where the result is the intersection.
Use of [not]modifiedby is likely to create much more database load than the other parameters because the record sets to join may be very large.
This is reflected in $wgDynamicPageListEngineCondCostMap, but you might need to adjust this value.
You can effectively disable these parameters by setting their cost higher than the value of $wgDynamicPageListEngineMaxCost.
Count
Limit the number of records to fetch from the database.
Recognizes the parameter count which gives the limit.
Invalid values (including 0) are interpreted as 1, for compatibility with DynamicPageList (Wikimedia).
In any case, the number is limited to $wgDynamicPageListEngineMaxResultCount.
Order
Sort the result records.
Recognizes the parameters order (default descending) and ordermethod (default categoryadd).
Some values are replaced by fallback values if no category was indicated.
Defaults and fallback values are chosen for compatibility with DynamicPageList (Wikimedia).
In addition to the ordermethod values recognized by DynamicPageList (Wikimedia), the value title is accepted as well.
It sorts by title without namespace prefix.
Check
Check whether the whole specification is acceptable in terms of database load.
Results
Convert query results to other representations. See Lua library for details.
Lua library
All functions explained below take a single argument which is an associative array of parameters. The recognized parameters are explained in Usage.
mw.ext.dpl.getFullpagenames
mw.ext.dpl.getFullpagenames{ parameters }
Select and sort pages according to the parameters and return an array of full page names.
mw.ext.dpl.getPagenames
mw.ext.dpl.getPagenames{ parameters }
Select and sort pages according to the parameters and return an array of page names without namespace. This is useful if you know the namespace in advance because you have specified it in the arguments.
mw.ext.dpl.getPages
mw.ext.dpl.getPages{ parameters }
Select and sort pages according to the parameters and return an array of associative arrays, each of which represents a page. The latter contain the following items which have the same meaning as the corresponding properties of mw.title objects: namespace, nsText, text, prefixedText, baseText, subpageText, canTalk, isContentPage, isSubpage, isTalkPage, isRedirect. In addition, the following items are provided:
- length
- Uncompressed length in bytes of the page's current source text.
- categoryadd
- Timestamp of addition to the first category specified with the
categoryparameter, if any. - categoryaddx
- Timestamp of addition of the first page specified with the
containsparameter, if any, to the selected category. - counter
- Page view counter, unless counters are disabled.
- sortkey
- Sort key in the first category, if any, provided that DynamicPageListEngineFeatureExtra is enabled.
- extra
- Extra information given with sort key, if any, provided that DynamicPageListEngineFeatureExtra is enabled.
- sortkeyx
- Sort key in the category of the first page specified with the
containsparameter, if any, provided that DynamicPageListEngineFeatureExtrax is enabled. - extra
- Extra information given with the sortkeyx sort key, if any, provided that DynamicPageListEngineFeatureExtrax is enabled.
Release notes
These are the release notes for version 1.1. See Extension:DynamicPageListEngine/History for older releases.
New features
- Added the withoutsuffix item to the result records of Extension:DynamicPageListEngine#mw.ext.dpl.getPages.
- Added the resolve option to the Extension:DynamicPageListEngine#Redirects module.
- Added the Extension:DynamicPageListEngine#Redirectsto module.
Bugfixes
- Page titles containing
&characters are now handled correctly.
Bug reports and feature requests
Please report software bugs and feature requests on the talk page.
See also
- Extensions incompatible with 1.45/zh
- Stable extensions/zh
- Data extraction extensions/zh
- ScribuntoExternalLibraries extensions/zh
- GPL licensed extensions/zh
- Extensions in Wikimedia version control/zh
- All extensions/zh
- Pages using deprecated NoteTA template
- Category extensions/zh
- List extensions/zh
- Page content extensions/zh
- Category intersection extensions/zh
