Anonymous user
Controlling output order: Difference between revisions
m
Move the bit NOT related to DPL3 itself, to the bottom (didn't make sense to have it first, when I'm looking for information about DPL3 use, and this was advice that would work for MW tables in general and was non-specific to DPL3)
imported>FrozenPlum m (Found another multi-value combination buried in a page) |
imported>FrozenPlum m (Move the bit NOT related to DPL3 itself, to the bottom (didn't make sense to have it first, when I'm looking for information about DPL3 use, and this was advice that would work for MW tables in general and was non-specific to DPL3)) |
||
Line 2:
{{DPL manual|section=Parameters|subsection=Controlling output order}}
{{tocright}}
DPL3 allows you to define the sort order of its output, as is explained below.
Line 26 ⟶ 11:
{{DPL Parameter
|name = ordermethod
|purpose= Sets the criteria used to order the list
}}
Line 32 ⟶ 17:
'''Syntax:'''
<code>ordermethod=<i>method1,method2,...</i></code>
'''''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;"
Line 42 ⟶ 27:
|-
|'''''categoryadd'''''
|
{{note|See '''''sortkey''''' for sorting by page order in a category.}}
|-
|'''''counter'''''
|
{{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'''''
|
|-
|'''''firstedit'''''
|
|-
|'''''lastedit'''''
|
|-
|'''''pagetouched'''''
|
|-
|'''''pagesel'''''
|
|-
|'''''title'''''
|
|-
|'''''titlewithoutnamespace'''''
|
|-
|'''''sortkey'''''
|
|-
|'''''none'''''
|Do not apply any ordering (except ordering by timestamp if you requested a list of revisions); this method is
|}
'''''methodN''''' can also be one of the following '''combination''' of values (
{| class="wikitable" style="max-width:1200px;"
! 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'''''
|
|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'''''
|
|-
|'''''category,lastedit'''''
|
|-
|'''''category,pagetouched'''''
|
|-
|'''''category,sortkey'''''
|
|}
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:{{PAGENAME}}/Parameter:_ordermethod_(example 1)|Example}}
{{example|ordermethod|eg=1}}
'''Result:'''<br><!-- transclude example from subpage-->{{#lsth:{{PAGENAME}}/Parameter:_ordermethod_(example 1)|Result}}
Line 123 ⟶ 126:
{{DPL Parameter
|name = order
|purpose= Controls the sort direction of the list
}}
Line 130 ⟶ 133:
''orderdirection'' can be one of:
* ''descending'' — depending on the critria set, largest to smallest, most to least, 9 to 0 and/or Z to A
* ''ascending'' — depending on the critria set, smallest to largest, least to most, 0 to 9 and/or A to Z — ('''default''', needs not be set)
'''Example:'''<br><br><!-- transclude example from subpage-->{{#lsth:{{PAGENAME}}/Parameter:_order_(example 1)|Example}}
{{example|order|eg=1}}
'''Result:'''<br><!-- transclude example from subpage-->{{#lsth:{{PAGENAME}}/Parameter:_order_(example 1)|Result}}
Line 163 ⟶ 159:
* 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 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 <code>ordercollation=bridge</code>.
==Other ways to sort==
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 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:
<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.
==References==
|