Extension:DynamicPageListEngine

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png
DynamicPageListEngine

Release status:Extension status stable

ImplementationTemplate:Extension#type Data extraction
DescriptionTemplate:Extension#description Provides dynamic page lists with configurable and extensible features to modules and to other extensions
Author(s)Template:Extension#username (RV1971talk)
Latest versionTemplate:Extension#version 1.0.0 (2014-08-26)
MediaWikiTemplate:Extension#mediawiki >=1.23
PHPTemplate:Extension#php 5.3+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GPL v3
Download Sourceforge
Release Notes
ParametersTemplate:Extension#parameters
  • $wgDpleMaxCost
  • $wgDpleMaxResultCount
  • $wgDpleFeatures
  • $wgDpleCondCostMap
  • $wgDpleOrderCostMap
Hooks usedTemplate:Extension#hook
ScribuntoExternalLibrariesManual:Hooks/ScribuntoExternalLibraries

Translate the DynamicPageListEngine extension if it is available at translatewiki.net

Check usage and version matrix.

The DynamicPageListEngine extension is a backend providing dynamic page lists, which can be used on php level for other extensions, or on Lua level with the Scribunto extension. The page selection and sorting criteria are compatible with DynamicPageList (Wikimedia).

Given that there are already DynamicPageList (Wikimedia) and DynamicPageList (third-party), which are not completely compatible, you might be wondering why yet another such extension. In short:

  1. I needed dynamic page lists on Lua level, and none of the two existing extensions provided that.
  2. Adding such a feature on top of DynamicPageList (Wikimedia) was not feasible due to its monolithic implementation.
  3. Adding such a feature on top of DynamicPageList (third-party) might have been possible, but then it would have been partially incompatible with the Wikimedia extension. More importantly, as the the DPL manual states, "DPL at the moment is rather monolithic" as well.
  4. Hence the only solution was to create a new extension from scratch.
  5. The extremely high number of features in the third-party extension suggests the need for a configurable, modular and extensible backend.

Installation[edit]

  • Download and place the file(s) in a directory called DynamicPageListEngine in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/DynamicPageListEngine/DynamicPageListEngine.php";
    
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Even though this extension has been tested on MediaWiki 1.23 only, it is likely to work on slightly earlier versions as well.

Upgrading[edit]

To upgrade, simply install the most recent version.

Upgrading from 0.3 or earlier[edit]

With version 1.0.0, almost all configuration parameters and messages names have been changed. If you have customized any of them, you need to adapt your configuration.

Since version 1.0.0, pages using DynamicPageListEngine are assigned to a tracking category. If you already have such pages, you can fix the categories either by performing a null edit on each page or by executing the script maintenance/refreshLinks.php. Note that the latter may take a considerable amount of time.

Configuration[edit]

LocalSettings.php[edit]

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
Maxiumum 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
Maxiumum 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. See Usage for details. You should always enable at least DpleFeatureCount, otherwise there is no limit to the number of fetched records, and DpleFeatureCheck, otherwise there is no limit on the complexity of the query. If you want to use Lua, you also need DpleFeatureResults. Each of these may be replaced with a derived class or a class with similar semantics.
$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.

Messages[edit]

Since the extension defines a lot of messages which are constantly evolving with further development, they are not documented here. Please refer to i18n/qqq.json.

Usage[edit]

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[edit]

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[edit]

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[edit]

Include or exclude redirects. Recognizes the parameter redirects, which may be one of exclude|include|only. 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.

Titlematch[edit]

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[edit]

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[edit]

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[edit]

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).

Uses[edit]

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[edit]

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[edit]

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[edit]

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[edit]

Select categories which contain the specified pages. Recognizes the parameters contains and notcontains. Each of them may be a string or an array.

Extra[edit]

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[edit]

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[edit]

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[edit]

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[edit]

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[edit]

Check whether the whole specification is acceptable in terms of database load.

Results[edit]

Convert query results to other representations. See Lua library fro details.


Lua library[edit]

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[edit]

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[edit]

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[edit]

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 category parameter, if any.
categoryaddx
Timestamp of addition of the first page specified with the contains parameter, 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 contains parameter, 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[edit]

These are the release notes for version 1.0.0. See Extension:DynamicPageListEngine/History for older releases.

Configuration changes[edit]

  • Configuration parameter names have been shortened.
  • Messages have been widely renamed.
  • The messages are now stored in the new JSON format.

New features[edit]

  • Pages using the functions in the Lua interface are now added to the tracking category named by the message dple-tracking-category.
  • An interface class DpleFeatureInterface is provided to facilitate the development of new features.

Languages updated[edit]

  • Support was added for French (fr).
  • Support was added for Italian (it).

Other changes[edit]

  • Filenames and class names have been shortened.
  • The functions in the Lua interface are now marked as expensive.

See also[edit]