Controlling output order

From DynamicPageList3 Manual
Revision as of 01:22, 23 April 2022 by imported>FrozenPlum (Fix (I think) the openreferences statement to make sense, the actual indication of openreferences=yes setting ordermethod=none should live in the openreferences page section.)

Page Template:Purgenote/style.css must have content model "Sanitized CSS" for TemplateStyles (current model is "plain text").

Note: If the examples don't appear embedded within the page, please purge this page.
Manual Parameters Controlling output order

DPL3 allows you to define the sort order of its output, as is explained below.

In some cases, this is not sufficient, however. Think of the following example: You create a list of pages which use a certain template. You want to show the value of the first parameter each page uses when calling that template. This can easily be done with the include feature of DPL. If you now wanted the output to be sorted by the value of that parameter, DPL could not help because it had to analyze all articles before finding those parameter values.

But there is another way: Create a sortable wiki table (using the table option of DPL with 'class=sortable') and you can click on the column headings to sort your output accordingly. However, the initial order shown in that table will still be the order in which DPL parsed the wiki pages (usually an alphabetic order of the page names).

Using a handful of JavaScript lines, you can sort a wikitable on pageLoad by any column. You must insert that JavaScript code AT THE END of your page :

 sortables_init();
 // sort the first sortable table; change [0] to sort other tables.
 tab = document.getElementsByTagName("table")[0];
 // sort by the first column; change [0] to sort by other columns.
 hdr = tab.getElementsByTagName("th")[0];
 // get the sort button link
 lnk = hdr.getElementsByTagName("a")[0];
 ts_resortTable(lnk);

Before version 1.16 of MediaWiki, wikibits.js was typically called at the end of a page and performed sortables_init(). Calling it explicitly did not result in it being recognized, but rather resulted in adding a second set of sort link buttons.


ordermethod

Page Template:DPL parameter/styles.css must have content model "Sanitized CSS" for TemplateStyles (current model is "plain text").

ordermethod Sets the criteria used to order the list, usually combined with order= and ascending or descending; or alternatively combined with headingmode.


Syntax:

ordermethod=method1,method2,... means ordered by method1 first, then by method2, etc. (like the ORDER BY clause in SQL)


methodN can be one of the following single values:

Method Description
categoryadd Outputs list based on most recent addition to the first category (requires to include one category and one only using 'category' parameter).
See sortkey for sorting by page order in a category.
counter Outputs list based on the number of times the page has been viewed (by ~popularity).
Note: Requires the HitCounters extension for wikis on MediaWiki 1.25.0 or higher since the counter feature was removed[1]; this extension is not yet available on Miraheze wikis.
size Outputs list based on the size of the article (bytes of wiki text).
firstedit Outputs list based on first edit to the pages (creation).
lastedit Outputs list based on most recent edit to the pages.
pagetouched Outputs list based on 'page_touched' timestamp. Read comment on page_touched field in Page_table to see the difference from most recent edit by an author.
pagesel Outputs list based on the names of the reference pages which are used in the selection of a linksfrom or linksto statement. pagesel only makes sense if there is more than one page mentioned in the linksfrom or linksto condition.
title Outputs list sorted by article (prefix +) title.
titlewithoutnamespace Outputs list sorted by the article name regardless of namespace.
sortkey Outputs list sorted by (category) sortkey (order by sortkey of the first category specified, if there are multiple); requires at least one category statement. Sortkey serves either the default category sort order (alphabetical), or a sortkey can be manually specified on each page in the category. Since sortkey relates directly to the sorting order of pages in a category, sortkey functions as an alias of sorts for "category".
none Do not apply any ordering (except ordering by timestamp if you requested a list of revisions); this method is set by default if openreferences=yes.


methodN can also be one of the following combination of values (see also headingmode option):

Method Description
category,firstedit Outputs list sorted by category, then by first edit.
category,lastedit Outputs list sorted by category, then by last edit within a category.
category,pagetouched Outputs list sorted by category, then by pagetouched.
category,sortkey Outputs list sorted by title and (category) sortkey; requires at least one category statement and a sortkey must be set on at least one of the output pages.
user,firstedit Outputs list sorted by user, then by firstedit by the user.
user,lastedit Outputs list sorted by user, then by lastedit by the user.


Example:

{{#dpl:
|category=Africa
|ordermethod=lastedit
}}

This list will output pages that have [[Category:Africa]] showing most recently edited articles at the top.


order

Page Template:DPL parameter/styles.css must have content model "Sanitized CSS" for TemplateStyles (current model is "plain text").

order Controls the sort direction of the list, requires ordermethod to be set, so that DPL knows which criterion (or criteria) to sort by.


Syntax: order=orderdirection

orderdirection can be one of:

  • ascending — depending on the critria set, smallest to largest, least to most, 0 to 9 and/or A to Z — (default)
  • descending — depending on the critria set, largest to smallest, most to least, 9 to 0 and/or Z to A


Example:

{{#dpl:
|category    = Africa
|ordermethod = lastedit
|order       = ascending
|addeditdate = true
}}

This will list pages that have [[Category:Africa]] shown, ordered from oldest to newest. In addition, the edit date will be presented with each article.


ordercollation

Page Template:DPL parameter/styles.css must have content model "Sanitized CSS" for TemplateStyles (current model is "plain text").

ordercollation Defines the collating sequence for ordering. Allows individual collations, makes case-insensitive sorting possible.


Syntax: ordercollation=latin1_german_ci


Notes:

  • For case insensitivity during the selection of articles, see ignorecase.
  • You may want to try latin1_swedish_ci or other collation mapping table names as well. If you use a name for the first time, you should make sure that it is spelled correctly. Otherwise, you will see a SQL error message.
  • A very special (proprietary) function can be used to sort card suit symbols according to the rank of suits that is used in the card game of bridge (this cannot be done by standard collating sequences). To trigger this function, set ordercollation=bridge.

References