Controlling output order: Difference between revisions

From DynamicPageList3 Manual
Content added Content deleted
m (Azxiana moved page DPL parameters: Controlling output order to DPL:Parameters: Controlling output order without leaving a redirect)
imported>FrozenPlum
m (Minor cleanup)
 
(47 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{Type Manual|section=Controlling output order}}
{{DPL manual|section=Parameters|subsection=Controlling output order}}
{{tocright}}


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


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


==ordermethod==
Using a handful of javascript lines you can sort a wikitable ''on pageLoad'' by any column. You must use an extension like [[Javascript extension]] or find some other way to insert that javascript code AT THE END of your page :


{{DPL Parameter
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);

The ''wikibits.js'' usually is called at the end of a page and performs ''sortables_init()''. If we call it ourselves it will not recognize this and therefore it will add its sort link buttons a second time (which looks quite funny...). You can teach wikibits.js to be aware of initialized sortable tables by adding the following if-statement around the line where it inserts the href for the sort button (near line 550 in MW 1.13):
if (cell.innerHTML.indexOf("sortheader") < 0) { ... place the original code line here ... }


__TOC__


===ordermethod===

{{DPL parameter
|name = ordermethod
|name = ordermethod
|purpose= Sets the criteria used to order the list by; often combined with <code>{{DPL|order}}{{=}}''descending''</code> for descending sort (otherwise ''ascending'' is default); or, alternatively, may be combined with <code>{{DPL|headingmode}}</code>.
|purpose= Determines what criterium (resp. criteria) is (resp. are) used to order the list.
}}
}}


Syntax:


'''Syntax:'''
<code>ordermethod=<i>method1,method2,...</i></code> means ordered by method1 first, then by method2, etc. (like the ORDER BY clause in SQL)


<code>ordermethod=<i>method1,method2,...</i></code> ordered by ''method1'' first, then by ''method2'', etc., (like the [https://www.w3schools.com/sql/sql_orderby.asp ORDER BY] clause in SQL).
''methodN'' can be one of the following single tokens:


;''categoryadd'': outputs list based on most recent addition to the first category (requires to include one category and one only using 'category' parameter)
;''counter'': outputs list based on the number of times the page has been viewed (by ~popularity)
;''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 <code>page_touched</code> field in [[mw:Page_table|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 <tt>linksfrom</tt> or <tt>linksto</tt> statement. ''pagesel'' only makes sense if there is more than one page mentioned in the <tt>linksfrom</tt> or <tt>linksto</tt> condition.
;''title'': outputs list sorted by article (prefix +) title
;''titlewithoutnamespace'': outputs list sorted by the article name regardless of namespace &mdash; '''(default)'''


''methodN'' can also be one of the following token combinations (see also [[DPL parameters: Controlling output format#headingmode|''headingmode'']] option):
'''''methodN''''' can be one of the following '''single''' values (which will be sorted in ''ascending'' order by default, see <code>{{DPL|order}}</code>):


{| class="wikitable" style="max-width:1200px;"
;''category,firstedit'': outputs list sorted by category, then by first edit
! Method
;''category,lastedit'': outputs list sorted by category, then by last edit within a category
! Description
;''category,pagetouched'': outputs list sorted by category, then by pagetouched
|-
;''category,sortkey''
|'''''categoryadd'''''
;''sortkey'': outputs list sorted by title and sortkey, requires at least one category statement
|Orders list based on the most recent addition to the category specified (requires the 'category' parameter, only one category can be included to work).
;''user,firstedit'': outputs list sorted by user, then by firstedit by the user
{{note|See '''''sortkey''''' for sorting by page order in a category.}}
;''user,lastedit'': outputs list sorted by user, then by lastedit by the user
|-
|'''''counter'''''
|Orders list based on the number of times the page has been viewed (by ~popularity).
{{note|'''Note:''' Requires the [[mw:Extension:HitCounters|HitCounters]] extension for wikis on MediaWiki 1.25.0 or higher since the counter feature was removed<ref>[https://www.mediawiki.org/wiki/Manual:$wgDisableCounters Manual:$wgDisableCounters]</ref>; this extension is not yet available on Miraheze wikis.}}
|-
|'''''size'''''
|Orders list based on the size of the article (bytes of wiki text).
|-
|'''''firstedit'''''
|Orders list based on first edit to the pages (creation).
|-
|'''''lastedit'''''
|Orders list based on the most recent edit to the pages.
|-
|'''''pagetouched'''''
|Orders list based on 'page_touched' timestamp. Read the comment on the page_touched field in [[mw:Page_table|Page_table]] to see the difference from most recent edit by an author.
|-
|'''''pagesel'''''
|Orders list based on the names of the reference pages which are used in the selection of a <code>linksfrom</code> or <code>linksto</code> statement. ''pagesel'' only makes sense if there is more than one page mentioned in the <code>linksfrom</code> or <code>linksto</code> condition.
|-
|'''''title'''''
|Orders list sorted by article (prefix +) title.
|-
|'''''titlewithoutnamespace'''''
|Orders list sorted by the article name regardless of namespace.
|-
|'''''sortkey'''''
|Orders list sorted by [[mw:Help:Categories#Sort key|(category) sortkey]] (is ordered by sortkey of the '''first category specified''', if there are multiple); requires at least one category statement. Sortkey provides 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 one 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 <code>openreferences</code> is set.
|}


;''none'': do not apply any ordering (except ordering by timestamp if you requested a list of revisions); this method '''must be used when you specify '''openreferences=yes'''.


'''''methodN''''' can also be one of the following '''combination''' of values (which will be sorted in ''ascending'' order by default, see <code>{{DPL|order}}</code>):
Note:
For downward compatibility reasons DPL will use 'addfirstcategory' as its default order method if called via the &lt;dynamicPageList&gt;


{| class="wikitable" style="max-width:1200px;"
Example:
! Method
! Description
! Note
|-
|'''''user,firstedit'''''
|Orders list sorted by user, then by last edit.
|rowspan="6"|If the user who did the first or last edit is nonexistent locally (an editor from page import), the user link appears escaped on-page.
|-
|'''''user,lastedit'''''
|Orders list sorted by user, then by first edit.
|-
|'''''title,firstedit'''''
|Orders list sorted by title, then by lastedit by any user.
|-
|'''''title,lastedit'''''
|Orders list sorted by title, then by firstedit by any user.
|-
|'''''titlewithoutnamespace,firstedit'''''
|Orders list sorted by title (without the namespace), then by firstedit by any user.
|-
|'''''titlewithoutnamespace,lastedit'''''
|Orders list sorted by title (without the namespace), then by lastedit by any user.
|-
!colspan="3"|For use with <code>{{DPL|headingmode}}</code>, see {{DPL|headingmode}}.
|-
! Method
! Description
! Use
|-
|'''''category,title'''''
|Orders list sorted by category, then by title.
|rowspan="5"|
* The first argument sets each ''category'' as a heading and orders by
* The second argument sets ''MethodN'' as the order of article results ''under'' each category heading; if used without <code>headingmode</code>, these values will cause unwanted duplication of results. Requires at least one category statement.
'''Note:''' If pages in the result set belong to more than one category, all categories are listed and the results will appear more than once in the output. See {{DPL|headingmode}} for more information.
|-
|'''''category,firstedit'''''
|Orders list sorted by category, then by first edit.
|-
|'''''category,lastedit'''''
|Orders list sorted by category, then by last edit within a category.
|-
|'''''category,pagetouched'''''
|Orders list sorted by category, then by pagetouched.
|-
|'''''category,sortkey'''''
|Orders list sorted by title and [[mw:Help:Categories#Sort key|(category) sortkey]]; requires at least one category statement and a sortkey must be set on at least one of the output pages.
|}


<pre><nowiki>
<DPL>
category=Africa
ordermethod=lastedit
</DPL>
</nowiki></pre>


'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: ordermethod (example 1)|Example}}
This list will output pages that have <nowiki>[[Category:Africa]]</nowiki> showing most recently edited articles at the top.
{{ViewTest|Examples|Parameter: ordermethod (example 1)}}


'''Result:'''<br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: ordermethod (example 1)|Result}}
===order===



{{DPL parameter
==order==

{{DPL Parameter
|name = order
|name = order
|purpose= Controls the sort direction of the list.
|purpose= Controls the sort direction of the list; a value of ''descending'' '''requires''' <code>{{DPL|ordermethod}}</code> to be set, so that DPL3 knows which criterion (or criteria) to sort by.
}}
}}


Example:


<code>order=<i>orderdirection</i></code>
'''Syntax:''' <code>order=<i>orderdirection</i></code>


''orderdirection'' can be one of:
''orderdirection'' can be one of:
* ''descending'' &mdash; outputs list from most recent to least recent
* ''descending'' Depending on the criteria set, largest to smallest, most to least, 9 to 0 and/or Z to A
* ''ascending'' &mdash; outputs list from least recent to most recent &mdash; '''(default)'''
* ''ascending'' Depending on the criteria set, smallest to largest, least to most, 0 to 9 and/or A to Z — ('''default''', need not be set)


Example:


'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: order (example 1)|Example}}
<pre><nowiki>
{{ViewTest|Examples|Parameter: order (example 1)}}
<DPL>
category = Africa
ordermethod = lastedit
order = ascending
addeditdate = true
</DPL>
</nowiki></pre>


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


'''Result:'''<br><!-- transclude example from subpage-->{{#lsth:Examples/Parameter: order (example 1)|Result}}


===ordercollation===


==ordercollation==
{{DPL parameter

{{DPL Parameter
|name = ordercollation
|name = ordercollation
|purpose= Allow individual collations, make case insensitive sorting possible
|purpose= Defines the collating sequence for ordering. Allows individual collations, makes case-insensitive sorting possible.
}}
}}


defines the collating sequence for ordering.


'''Syntax:''' <code>ordercollation=<i>latin1_german_ci</i></code>
Note: A very special (proprietory) 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 <tt>ordercollation=bridge</tt>.


Example:


'''Notes:'''
<code>ordercollation=<i>latin1_german_ci</i></code>
* For case insensitivity during the ''selection'' of articles, see {{DPL|ignorecase}}.
* You may want to try <code>latin1_swedish_ci</code> 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 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 <code>ordercollation=bridge</code>.


==Other ways to sort==
You may want to try <tt>latin1_swedish_ci</tt> or other collation mapping table names as well.

===tablesortcol===
{{#lsth:Examples|tablesortcol}}<!-- transclude from other page -->

===Using JavaScript===

In some cases, DPL3 sorting features are sufficient; 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 {{DPL|include}} feature of DPL.
* If you now wanted the output to be sorted by the ''value'' of that parameter, DPL3 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 {{DPL|table}} option of DPL3 with <code>class="wikitable sortable"</code>) 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 DPL3 parsed the wiki pages (usually an alphabetical 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:

<syntaxhighlight lang="javascript">
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);
</syntaxhighlight>


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.
If you use a name for the first time you should make sure that it is correctly spelt. Otherwise you will see a SQL error message.


==References==
For case insensitivity during the ''selection'' of articles, see [[ignorecase]].
<references />
[[Category:Primary Module|03]]

Latest revision as of 02:48, 1 April 2023

Manual Parameters Controlling output order


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


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 by; often combined with order=descending for descending sort (otherwise ascending is default); or, alternatively, may be combined with headingmode.


Syntax:

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


methodN can be one of the following single values (which will be sorted in ascending order by default, see order):

Method Description
categoryadd Orders list based on the most recent addition to the category specified (requires the 'category' parameter, only one category can be included to work).
See sortkey for sorting by page order in a category.
counter Orders 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 Orders list based on the size of the article (bytes of wiki text).
firstedit Orders list based on first edit to the pages (creation).
lastedit Orders list based on the most recent edit to the pages.
pagetouched Orders list based on 'page_touched' timestamp. Read the comment on the page_touched field in Page_table to see the difference from most recent edit by an author.
pagesel Orders 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 Orders list sorted by article (prefix +) title.
titlewithoutnamespace Orders list sorted by the article name regardless of namespace.
sortkey Orders list sorted by (category) sortkey (is ordered by sortkey of the first category specified, if there are multiple); requires at least one category statement. Sortkey provides 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 one 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 is set.


methodN can also be one of the following combination of values (which will be sorted in ascending order by default, see order):

Method Description Note
user,firstedit Orders list sorted by user, then by last edit. If the user who did the first or last edit is nonexistent locally (an editor from page import), the user link appears escaped on-page.
user,lastedit Orders list sorted by user, then by first edit.
title,firstedit Orders list sorted by title, then by lastedit by any user.
title,lastedit Orders list sorted by title, then by firstedit by any user.
titlewithoutnamespace,firstedit Orders list sorted by title (without the namespace), then by firstedit by any user.
titlewithoutnamespace,lastedit Orders list sorted by title (without the namespace), then by lastedit by any user.
For use with headingmode, see headingmode.
Method Description Use
category,title Orders list sorted by category, then by title.
  • The first argument sets each category as a heading and orders by
  • The second argument sets MethodN as the order of article results under each category heading; if used without headingmode, these values will cause unwanted duplication of results. Requires at least one category statement.

Note: If pages in the result set belong to more than one category, all categories are listed and the results will appear more than once in the output. See headingmode for more information.

category,firstedit Orders list sorted by category, then by first edit.
category,lastedit Orders list sorted by category, then by last edit within a category.
category,pagetouched Orders list sorted by category, then by pagetouched.
category,sortkey Orders 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.


Example:

{{#lsth:Examples/Parameter: ordermethod (example 1)|Example}}

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

Result:
{{#lsth:Examples/Parameter: ordermethod (example 1)|Result}}


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; a value of descending requires ordermethod to be set, so that DPL3 knows which criterion (or criteria) to sort by.


Syntax: order=orderdirection

orderdirection can be one of:

  • descending — Depending on the criteria set, largest to smallest, most to least, 9 to 0 and/or Z to A
  • ascending — Depending on the criteria set, smallest to largest, least to most, 0 to 9 and/or A to Z — (default, need not be set)


Example:

{{#lsth:Examples/Parameter: order (example 1)|Example}}

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


Result:
{{#lsth:Examples/Parameter: order (example 1)|Result}}


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

Other ways to sort

tablesortcol

{{#lsth:Examples|tablesortcol}}

Using JavaScript

In some cases, DPL3 sorting features are sufficient; 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, DPL3 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 DPL3 with class="wikitable 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 DPL3 parsed the wiki pages (usually an alphabetical 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.

References