[pmwiki-users] PageList sort order (numerical values)
ABClf
languefrancaise at gmail.com
Sun Apr 5 00:59:32 CDT 2015
Thank you Petko.
First solution working as expected ;
second one is failing somewhere : encoding is not utf8 anymore (title is :
détester, haïr, ne pas aimer instead of détester, haïr, ne pas aimer), no
values printed out, and I get this error message :
Warning: Illegal string offset 'targets' in
/homepages/18/d269604285/htdocs/dev6/scripts/pagelist.php(476) :
runtime-created function on line 1
Warning: Cannot modify header information - headers already sent by (output
started at /homepages/18/d269604285/htdocs/dev6/scripts/pagelist.php(476) :
runtime-created function:1) in
/homepages/18/d269604285/htdocs/dev6/pmwiki.php on line 1220
Code in local.php is :
function NbSource($targets) {
return substr_count($targets, "Source.");
}
# permute $x and $y to have it sort the other way
$PageListSortCmp['nbsource'] =
'NbSource($x["targets"])-NbSource($y["targets"])';
and pagelist is :
(:pagelist group=Bob link={*$FullName} fmt=#description2 order=nbsource:)
2015-04-04 16:48 GMT+02:00 Petko Yotov <5ko at 5ko.fr>:
> On 2015-04-04 11:05, ABClf wrote:
>
>> I am willing to get pagelist results sorted by popularity : i.e. count
>> backlinks (targets). That way, most linked pages will be shown first.
>>
>> For counting, targets, in config, I have :
>>
>> # NbSource
>> $FmtPV['$NbSource'] = 'NbSource($page["targets"])';
>> function NbSource($targets) {
>> $cnt = substr_count($targets, "Source.");
>> return $cnt>0? "$cnt" : '';
>> }
>>
>
> The entry $page["targets"] contains "frontlinks" not backlinks, these are
> internal pages to where the page from the pagelist links.
>
> (:pagelist group=Bob link={*$FullName} fmt=#description2 order=$NbSource:)
>>
>> Problem now, is how to make value 2 before value 11, and so on (natural
>> order).
>>
>
> I assume you want to make pages with more (11) links to appear before
> pages with less (2) links?
>
> To order correctly with the PmWiki pagelist sort, you can convert the
> numbers to padded strings:
>
> function NbSource($targets) {
> $cnt = substr_count($targets, "Source.");
> return sprintf('%08d', $cnt); # see php.net/sprintf
> # or: return sprintf('%08d', 9999999-$cnt); # in decremental order
> }
>
> Alternatively, it is possible to write your own pagelist sort function
> which may perform faster. On pmwiki.org the string sorting takes most of
> the pagelist processing time. Something like this:
>
> function NbSource($targets) {
> return substr_count($targets, "Source.");
> }
>
> # permute $x and $y to have it sort the other way
> $PageListSortCmp['nbsource'] = 'NbSource($x["targets"])-
> NbSource($y["targets"])';
>
> Then in the wiki, use (:pagelist ... order=nbsource:) or order=-nbsource
>
> Petko
>
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20150405/4b9418cd/attachment.html>
More information about the pmwiki-users
mailing list