PageList macro returns a list in alphabetical order only
The PageList macro is often used by me to show similar named pages (e.g. meeting protocols with time stamps). Sometimes it looks better in a reverse order. So I implemented a sort order switch for the PageList macro. This is just meant as a hint and works for my personal use. Maybe someone else is interested in it, that's why I put it in here.
Usage: [PageList(reverse,regex...)]
If reverse, is given, the returned page list will be in reverse alphabetical order. Otherwise without reverse, it works like usual. [PageList(regex...)]
Btw. it should be easy to implement different sort orders, just expand the "if sortorder ==" clause to your needs.
- here's the diff for search.py:
771,772c771,775 < def sortByPagename(self): < """ Sorts a list of found pages alphabetical by page name """ --- > def sortByPagename(self, sortorder=None): > """ Sorts a list of found pages alphabetical by page name > > @param sortorder: which mode to sort the list > """ 774c777,781 < tmp.sort() --- > # define different modes for sorting here e.g. reverse > if sortorder == "reverse": > tmp.sort(reverse=True) > else: > tmp.sort()
- and here the one for wikimacros.py:
471c471 < def _macro_PageList(self, needle): --- > def _macro_PageList(self, args): 475a476 > sortorder = None 476a478,481 > if args.find(',') == -1: > needle = args > else: > sortorder, needle = args.split(',', 1) 479c484 < if not needle: --- > if not args or not needle: 487d491 < 492c496 < results.sortByPagename() --- > results.sortByPagename(sortorder)
Why is this not implemented yet in moinmoin? It is very useful for PageList to have 'reverse' option.
This patch should be done with the current version of moin. Also it should not change the current API. At least not the order of arguments. We want also unified diffs. A similiar macro is in the extensions repo as ListPages.py (reverse is implemented as reverse of sort).