User:PerfektesChaos/js/resultListSort
JavaScript gadget to sort page lists on special pages.
On pages like âWhatlinkshereâ several hundred results may occur in any order dropped from database query. Name spaces are mixed randomly, no one gets a survey.
Usage
[edit]- If your project has registered this as a gadget, just activate on your Preferences page.
- Otherwise include the following lines into your common.js or skin dependant like vector.js, or even global.js:
mw.loader.load("https://www.mediawiki.org/w/index.php?title=User:PerfektesChaos/js/resultListSort/r.js&action=raw&bcache=1&maxage=86400&ctype=text/javascript");
- If you are blocking scripts from sites other than your local Wiki you might need to put www.mediawiki.org on the whitelist.
- The gadget works also with non-WMF sites using MediaWiki.
- The script may be loaded by anonymous users, e.g. via greasemonkey.
Effects
[edit]By default there is just a link added to the content actions of portlet. If sorting is needed it may be requested manually.
However, some types of special pages may be configured by user to perform sorting automatically, if machine is fast enough and response time acceptable to the user.
Standard collation is by namespace and page title.
Some pages get a second and even more action links: Sort by URL, and Watchlist and Recentchanges may be sorted by user or summary, Newpages also by size.
Canonical name | Regular output |
---|---|
Contributions |
most recent on top |
LinkSearch |
unsorted |
Newpages |
most recent on top |
Recentchanges |
most recent on top |
Search |
best match on top |
Watchlist |
most recent on top |
Whatlinkshere |
unsorted |
Other pages may be added if meaningful use has been found. Some 20 maintenance page lists are available right now.
For Allpages
and Prefixindex
it is offered to convert the three column table into a list. With long page names (perhaps caused by subpage path) they may be confusing to read.
The server provides unordered lists. These are always turned into numbered lists, since a larger number of pages sharing the same property can be derived easily.
Note that the information is gained by screengrabbing. If some details in formatting change, extraction of sortkey might fail. Please notify me.
Customization
[edit]Quick interactive configuration
[edit]Options can be set interactively on Special:Blankpage, if the script has been loaded before.
They are the same as described in next section:
- Automatic sorting for specified special pages
- Insertion of portlet-link: always, never, on particular pages only
- Ignore case on sorting
- Keep page together with talk page
These requests are stored together with user preferences on Wiki server and will be in effect on all browsers. They are overriding settings from the following section.
Anonymous users can use this mode, too; options will be stored in browser profile rather than on wiki server.
Javascript object
[edit]Insert code similar to the following lines into common.js etc. before mw.loader.load:
var myListOpts = { }; // use any name you like
myListOpts.key1 = value1; // example
// ... etc.
mw.hook( "resultListSort.before" ).fire( myListOpts );
mw.loader.load( /* ... */ ); // as shown above
Key | Value | Meaning |
---|---|---|
auto
|
|
Perform sorting automatically when matching wgCanonicalSpecialPageName.true â all unsorted pagesDefault: false â No automatism; trigger by portlet or other
|
portlet
|
Create portlet link when matching wgCanonicalSpecialPageName.true â all supported pagesDefault: all supported pages | |
casing
|
true
|
Perform case-insensitive sorting. Default: false â case-sensitive
|
group
|
true
|
Keep page together with talk page. Default: false â namespace by namespace
|
API
[edit]Two functions are exposed to users. They are available if the current page is a special page.
If you want to make use of the API you may place the following call wherever you want:
mw.hook( "resultListSort.ready" ).add( myTask );
When loading of all components has been completed, the resultListSort.ready
hook will be fired.
Here is myTask
a callback function with the actual functionality of the user application.
function myTask( application )
may use one parameter. That is the application object for the API. It provides some version information as well as functions on special pages.
Function | Effect |
---|---|
.fresh(apply)
|
Restart the entire gadget Parameter (optional): number with distinguisher for alternative collation. Possible values may be grabbed from portlet links. Dependency: mediawiki.util
|
.flip(apply)
|
Update portlet links Parameter (optional): same as above. Dependency: mediawiki.util
|
mw.libs
[edit]The application object will be mapped into mw.libs.resultListSort
component.
Option values may be assigned to this object before loading.
Selective loading
[edit]Since the gadget is meaningful on special pages only, loading may be limited to such pages:
if ( mw.config.get( "wgNamespaceNumber" ) === -1 ) {
mw.loader.load(...);
}
Codes
[edit]Source code |
|
ResourceLoader |
|
Namespaces | -1
|
mw.hook
|
|
mw.libs
|
resultListSort
|
Cookies | Anonymous users only:
|
MediaWiki |
|
Browser |
|
Other languages
[edit]This gadget is prepared for multilingual support.
- If you like a version in your own language, please forward translations to me:
- This documentation page.
- The
RLS.texts
mapping on top of source code. - Further ISO 639 language codes your translation might support.