Is there any way to show the sortkey for a page within the Category?
We changed our defaultsort to be the month and year a comic has been released, and we'd like to show that date tag next to the page link.
Thanks!
Is there any way to show the sortkey for a page within the Category?
We changed our defaultsort to be the month and year a comic has been released, and we'd like to show that date tag next to the page link.
Thanks!
Only because we had it there before and it was requested to be put back. I was using DPL before to make a list, but the limit was 500 pages, and I'm told DPL can be pretty costly on a server.
I could separate the issues by years using the sort keys, but those headers will only show the first character too.
JS isn't much better in terms of load, and it's slow to apply to the page, especially with API calls. It's doable though, one easy way is with /api.php?action=query&prop=pageprops&titles=xyz
. If you don't mind the extra overhead as opposed to, say, a central page listing the release dates, I can work on a quick script in the next day or two.
Yea, I'm not sure we want overhead (at least I don't), which is why I removed the DPL.
I'm interested to see your solution though, and hopeful it's less costly in case my community decides they absolutely need it.
Here's a pretty good example. I was looking for one with just more than 500 pages, but had a hard time finding the best example.
All of our appearances categories end with /Appearances or /Mentions at the moment, and ideally, these are the only ones that would show the sortkeys, but if it's not possible to throttle down that much, that's understandable. Most sortkeys will just be the pagename again, so there's not much benefit on categories that contain more than media entries (comics, episodes, movies, etc.).
Thanks again!
Here's version 1 of the script. You can run it from your browser console. Let know how it performs and how you want the dates to be formatted.
// Release date sortkey display script by User:Bobogoobo $(function() { if (!( mw.config.get('wgCanonicalNamespace') === 'Category' && ['Appearances', 'Mentions'].indexOf(mw.config.get('wgPageName').split('/').slice(-1)[0]) !== -1 )) { return; } // API requires titles 50 at a time, will be 200 titles per category page var requests, $links = $('#mw-pages').find('table').find('a'); pages = $links.toArray().map(function(value) { return encodeURIComponent($(value).attr('title')); }); requests = [pages.slice(0, 50), pages.slice(50, 100), pages.slice(100, 150), pages.slice(150)]; $.each(requests, function(index, value) { $.getJSON( '/api.php?action=query&prop=pageprops&ppprop=defaultsort&format=json&titles=' + value.join('|'), function(data) { data = data.query.pages; $.each(Object.keys(data), function(idx, val) { if (!data[val].pageprops) { return true;// continue } var sort = data[val].pageprops.defaultsort, title = data[val].title; date = sort.match(/\d{8}/); if (date) { $links.filter('[title="' + title + '"]').after(' (' + date[0] + ')'); } }); } ); }); });
Wow! That worked like a charm!
Even on the big categories, it's quick. I figured I would just format the sort key in a way that's readable but still sortable, like YYYY-MM-DD. I assume that makes the code lighter than having to apply extra styling, right?
Sorry for the delay in the reply, I was having issues figuring out how to make it work in the console.
My people will be thrilled! Is it better to have this stored somewhere, like on dev, and call the script through that proxy, rather than installing it locally?
I won't install it until you're happy with it, and I want to be sure to give you credit however you'd like. :)
I don't know what you mean by sortable, since categories are already sorted by the sortkey. Performance of styling vs. string formatting isn't really an issue in this case, I can do whatever you want it to look like.
The best place for it is probably your wiki's MediaWiki:Common.js. Just keeping the // comment with my name at the top is plenty, thanks.
Here's the edit to format dates, doesn't have to be the final version if you want fancier formatting.
// Release date sortkey display script by User:Bobogoobo $(function() { if (!( mw.config.get('wgCanonicalNamespace') === 'Category' && ['Appearances', 'Mentions'].indexOf(mw.config.get('wgPageName').split('/').slice(-1)[0]) !== -1 )) { return; } // API requires titles 50 at a time, will be 200 titles per category page var requests, $links = $('#mw-pages').find('table').find('a'); pages = $links.toArray().map(function(value) { return encodeURIComponent($(value).attr('title')); }); requests = [pages.slice(0, 50), pages.slice(50, 100), pages.slice(100, 150), pages.slice(150)]; $.each(requests, function(index, value) { $.getJSON( '/api.php?action=query&prop=pageprops&ppprop=defaultsort&format=json&titles=' + value.join('|'), function(data) { data = data.query.pages; $.each(Object.keys(data), function(idx, val) { if (!data[val].pageprops) { return true;// continue } var sort = data[val].pageprops.defaultsort, title = data[val].title; date = sort.match(/\d{8}/); if (date) { $links.filter('[title="' + title + '"]').after( ' (' + date[0].replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3') + ')' ); } }); } ); }); });
Thanks again for your help. I've put it into the community.js and am awaiting approval.
Much appreciated! :)
Awesome, happy to help.