Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for -excludeOnTitle ? #53

Open
roadrunnerjb opened this issue Dec 6, 2023 · 5 comments
Open

Example for -excludeOnTitle ? #53

roadrunnerjb opened this issue Dec 6, 2023 · 5 comments
Assignees
Labels

Comments

@roadrunnerjb
Copy link

roadrunnerjb commented Dec 6, 2023

HI,

thank you for your work on this usefull plugin.

I have a problem understanding the -excludeOnTitle option. Where do I specify what titles are to be excluded ?

I tried this to exclude pages in ns1:ns2 with first title starting with "Z_"

====== Test catlist plugin ======

<catlist ns1:ns2  -maxDepth:1 -sortAscending -sortByTitle -excludeOnTitle -exclupage:"^Z_.*">

but it does not work.
I think the example excludes pagenames starting wit "Z_*" but no glue how to specify to exclude based on the first title.

Any help will be welcome.

@xif-fr
Copy link
Owner

xif-fr commented Dec 16, 2023

Hi,

I don't really know, what you've done should work. There may be a bug.

As I don't use DokuWiki anymore I'm not willing to try to debug. If you want to try, you can add, in the function _isExcluded of syntax.php around the preg_match call, some echo $item[$exclutype]; and var_dump($match); to check what's really going on.

Sorry for not being able to really help.

@roadrunnerjb
Copy link
Author

Hi,

I don't really know, what you've done should work. There may be a bug.

As I don't use DokuWiki anymore I'm not willing to try to debug. If you want to try, you can add, in the function _isExcluded of syntax.php around the preg_match call, some echo $item[$exclutype]; and var_dump($match); to check what's really going on.

Sorry for not being able to really help.

OK, I understand, thank you for your replay anyway.

I'm not familiar with dokuwiki internals and php but I put in some echo statements and found out that my problem is a bit more complicated as my page content and so the title to be filtered is in the start page of a spereate namespace.

So the -maxDepth:1 prevents catlist to look into the start page but is showing the title of the namespace start page. This confused me.

To explain with an example:

ns1:ns2:ns3:start contains first title hugo
ns1:ns2:ns4:start contains first title emma
ns1:ns2:ns5:start contains first title Z_paul

and I want to exclude all Z_ so in the example Z_hugo

So any idea how to tell this to catlist correctly ?

@xif-fr
Copy link
Owner

xif-fr commented Dec 29, 2023

Oh, I see, you want to filter namespaces based on the title of their start page.

It should work if you use -excluns and if you move the code

if ($index_exists) {
	$item['metadata'] = $this->_getMetadata($index_id, $index_filepath);
	if ($data['nsuseheading'] && isset($item['metadata']['title']))
		$item['title'] = $item['metadata']['title'];
}
if (is_null($item['title']))
	$item['title'] = $name;

(line 386 of syntex.php) above the line

if ($this->_isExcluded($item, $data['exclutype'], $data['excluns'])) continue;

Hope it works

@xif-fr xif-fr self-assigned this Dec 29, 2023
@xif-fr xif-fr added the todo label Dec 29, 2023
@roadrunnerjb
Copy link
Author

roadrunnerjb commented Dec 29, 2023

yes, that's the point. Thank you for your suggestion. I moved the lines like this:

root@xxxxx:/var/www/dokuwiki/lib/plugins/catlist # diff syntax.php syntax.php.ori
381a382,384
>                                       // Exclusion
>                               if ($excluNS) continue;
>                               if ($this->_isExcluded($item, $data['exclutype'], $data['excluns'])) continue;
388,390d390
<                                       // Exclusion
<                               if ($excluNS) continue;
<                               if ($this->_isExcluded($item, $data['exclutype'], $data['excluns'])) continue;

And it works for the titles in the startpages of a namespace as you expected. But one thing I miss now is that I want to combine
the exclude options i.E.:

<catlist ns1:ns2 -maxDepth:1 -exclupage -excluns:".*-ms" -excludeOnTitle -excluns:"^Z_.*">
I expected that this excludes all startpages with Title starting with "Z_" AND excludes all namespaces ending with "-ms" but this seems not to work, result list is empty.

ns1:ns2:ns3:start contains first title hugo
ns1:ns2:ns4:start contains first title emma
ns1:ns2:ns5:start contains first title Z_paul
ns1:ns2:ns6-ms contains first title (does not matter)

I want to see hugo,emma and not Z_paul and not whatever title ns6-ms has...

Any idea on how to achieve this ?

@xif-fr
Copy link
Owner

xif-fr commented Dec 30, 2023

Well, first I don't know why the resulting list is empty, it should not exclude all namespaces...

Then, my suggestion was to move code related to the start page title before the exclusion test, like that :

if (is_dir($path.'/'.$file)) {
		// Exclusion
	if ($excluNS) continue;
		// Index page of the namespace -> namespace title
	list($index_exists, $index_id, $index_filepath) = $this->_getStartPage($data['index_priority'], $ns, $path, $name, ($data['nsLinks']==CATLIST_NSLINK_FORCE));
	if ($index_exists) {
		$data['index_pages'][] = $index_id;
		$item['metadata'] = $this->_getMetadata($index_id, $index_filepath);
		if ($data['nsuseheading'] && isset($item['metadata']['title']))
			$item['title'] = $item['metadata']['title'];
	}
	if (is_null($item['title'])) $item['title'] = $name;
		// Exclusion
	if ($this->_isExcluded($item, $data['exclutype'], $data['excluns'])) continue;

Finally, the exclusion with catlist only works on title or name for all exclusion options at the same time. You cannot exclude on page name for one (-excluns:"^Z_.*") and on name (-excluns:".*-ms") at the same time. To do that, the whole exclusion logic should be rewritten.

If you disregard -excluns:".*-ms", then
<catlist ns1:ns2 -maxDepth:1 -excludeOnTitle -excluns:"^Z_.*">
should do what you want, given that you modified the code as above.
You can add -exclupage to exclude all pages if you want, it should still work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants