dokufreaks/plugin-blog

Problems with Sorting

Closed this issue · 14 comments

Hi,

I try to explain. 1st my settings in configuration:
Blogeinträge sortieren nach: Seitenname
Sortierrichtung: absteigend

my blog startig page has this code: {{blog>blog?5&firstsectiononly&order=title&rsort&depth=0}}

My pages have a H1 with YYYY.MM.DD Title in the 1st row. But the sort order is not fine.

May be You like to see my blog: https://kaineugebauer.de/doku.php?id=mein_blog

Can anybody help me?

fiwswe commented

My pages have a H1 with YYYY.MM.DD Title in the 1st row.

Not true. The first visible entry has DD.MM.YYYY.

Did you try the documented option sortby (instead of order)? See https://www.dokuwiki.org/plugin:blog and https://www.dokuwiki.org/plugin:pagelist#flags

My pages have a H1 with YYYY.MM.DD Title in the 1st row.

Not true. The first visible entry has DD.MM.YYYY.
Sorry, I corrected this.

Did you try the documented option sortby (instead of order)? See https://www.dokuwiki.org/plugin:blog and https://www.dokuwiki.org/plugin:pagelist#flags

You mean this way? --> {{blog>blog?5&firstsectiononly&sortby=title&rsort}}

Thanks for any idea.

For the {{blog syntax the include plugin is used. https://www.dokuwiki.org/plugin:blog#blog, which has different flags than the pagelist plugin.

Now I tried this way: The blog plugin can be configured using the DokuWiki configuration manager available in the admin menu.

Blogeinträge sortieren nach: Seitenname ---> Name of page, like [[[blog:2022.11.30_blacky_wird_geboren]]
Sortierrichtung: absteigend ---> descending

The result is no sorting. :-(

Result is:

  1. 2022.11.30 Blacky wird geboren
  2. 2023.04.17 Einzug in Gößweinstein
  3. 2022.10.16 - Film über CRPS

What is my mistake, please.

fiwswe commented

For the {{blog syntax the include plugin is used

Oops, sorry. You are correct.

The result is no sorting. :-(

Not quite correct. It is sorting by last modified date/time. However I don't know why it is ignoring the order=title flag. So it seems to be acting as if order=modified was set?

I can reproduce this in a test Wiki of mine.
In my case the global settings are:

  • plugin»blog»sortkey = creation date
  • plugin»blog»sortorder = descending

I tried to switch off the configuration manager by removing the name blog name space field. After that I tried to use different sort orders. No changes in the sorting.

Here the list of sorted blog entries is created:

if ($my = plugin_load('helper', 'blog')) $entries = $my->getBlog($ns);

If nothing is set in the config setting, then it falls back to date:

plugin-blog/helper.php

Lines 94 to 99 in 27d2011

// determine the sort key
if ($this->sort == 'id') $key = $id;
elseif ($this->sort == 'pagename') $key = noNS($id);
elseif ($this->sort == 'title') $key = $title;
else $key = $date;

I think the sorting key can only be set in the config settings in the field sort key. I guess that if you set it to title in the config settings, it should sort by title.

$this->sort = $this->getConf('sortkey');

If it listens also to flags, I have not yet seen where that is set in this processing. So my understanding now is that the order flags is not used here.

I tried to switch off the configuration manager by removing the name blog name space field. After that I tried to use different sort orders. No changes in the sorting.

I do not understand yet what you did here. Please try setting sortkey to title instead.

I testet this: 1st blog page: {{blog>}}
Config Page is set in blog area sortig to title. Nothing changed. I tried all other sorting types. Nothing changed.

At last I changed in helper.php this lines:

// determine the sort key
//if ($this->sort == 'id') $key = $id;
//elseif ($this->sort == 'pagename') $key = noNS($id);
//elseif ($this->sort == 'title') $key = $title;
//else $key = $date;
$key=$title;

This works.

Therefore I think the data of the config page may be stored wrong. Do You have an idea, where I can look for the results?

fiwswe commented

Look in ./conf/local.php. You should find entries for $conf['plugin']['blog']['sortkey'] = 'title';, etc. (But the problem is likely somewhere else.)

In fact I think the problem is that the constructor for helper_plugin_blog is not called, because the constructor needs to be named __construct not helper_plugin_blog starting with PHP 8.0.0. So either renaming the present constructor (giving up pre-PHP 8.0 compatibility) or adding:

    function __construct() {
        $this->helper_plugin_blog();
    }

should do the trick. Seems to work in my test Wiki.

Ok, thanks. I added the constructor.

fiwswe commented

Actually the bit about giving up backwards compatibility by renaming the constructor may be wrong. I just did a test with PHP 7.4.33 where the __construct() constructor was called:

$ php-7.4 -r 'class Test { function __construct(){echo "YES\n";} } $x=new Test();'
YES
$ 

I don't have any older versions of PHP to test with.

fiwswe commented

Update: found this website: https://3v4l.org

__construct() works starting with PHP 5.0.0.

fiwswe commented

I have filed PR #121