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

|category=+ and |category=- behavior inverted? Also, |category=+ gives no results. #164

Open
CrystalClearGal opened this issue Apr 9, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@CrystalClearGal
Copy link

CrystalClearGal commented Apr 9, 2022

DynamicPageList3 version: 3.4.5
MediaWiki version: 1.37.2 (Miraheze)
PHP version: 7.4.28

TLDR: Problem observed directly here:
https://dpl3.miraheze.org/wiki/User:FrozenPlum/Sandbox/Issues

List of steps to reproduce (step by step, including full links if applicable):

  • Use the following statement with pages in both categories:
{{#dpl:
|category=+Countries in Europe¦Countries in North America
|headingmode=ordered
|ordermethod=category,firstedit
|noresultsheader=<br>''no result returned''
}}
  • Preview or save the page

What happens?:
No results are displayed for |category=+. Using |category=- the expected result for |category=+(categories specified in the headings) are included in the result, the direct opposite of what the manual text states. I gather this has been broken for quite some time before you took over the extension, since the old manuals had the same stated outcome but no actual working result pages.

What should have happened instead?:

|category=+ should show the result stated in the example given in the manual, or the behaviour removed (showing category headings in the result is useful, but not terribly practical when the result appears multiple times in the output if in multiple categories)
|category=- should be removed because the stated behaviour is the default anyhow, thus is redundant.

Browser information, screenshots and other applicable information:
Not related, happens irregardless of browser

@CrystalClearGal CrystalClearGal added the bug Something isn't working label Apr 9, 2022
@Universal-Omega
Copy link
Owner

Looks like

$db->query( "CREATE VIEW {$db->tablePrefix()}dpl_clview AS SELECT $sqlNullMethod(cl_from, page_id) AS cl_from, $sqlNullMethod(cl_to, '') AS cl_to, cl_sortkey FROM {$db->tablePrefix()}page LEFT OUTER JOIN {$db->tablePrefix()}categorylinks ON {$db->tablePrefix()}page.page_id=cl_from;" );
needs ran for this (which it has never been on Miraheze it seems)

@CrystalClearGal
Copy link
Author

CrystalClearGal commented Apr 11, 2022

Ah, so it is a database view that needed to be created. Also, I had a typo in my above report, to clarify, putting a minus ("-") in front of the category shows the output expected for the "+" value.

In googling the error, I see it is also needed for DPL Wikimedia version as well (though neither extension page mentions this).

That wikimedia-DPL section said the view would have needed to be created at the time of database creation (suggesting it couldn't be created later?) Yet I also found a DPL third-party reference to just creating this view after the fact (and that not having this may cause category:none to fail also, which I will test).

Also, would it be possible for DPL3 to give a similar output error/warning to the one given in that followthescore site link, if that needed db view does not exist, so users get an explanation and potential remedy when this doesn't functions as expected?

@CrystalClearGal
Copy link
Author

And, should I request this view be created (if it can be created after the fact)? Though I may way to do this until after I have test the rest of the provided examples, that way I can better know which of these require the view, to mark them as such. It seems odd to have an extra requirement to functionality not stated on the extension page.

@Universal-Omega
Copy link
Owner

Universal-Omega commented Apr 14, 2022

I have now created the VIEW on Miraheze. It now seems to work (as long as ordermethod is not using category as well)

@j-easton
Copy link

I have recently encountered this issue as well. Even testing on an empty wiki I was able to reproduce this error, although I should note I am using MediaWiki 1.35 and DPL 3.3.5 so do not know how it works on the most recent versions.

In trying to figure out what was causing the issue I discovered that the generated SQL returned a query which included cl_head.cl_to = 'Array'. This array should have been the list of categories. The below is where this part of the SQL is generated.

if ( is_array( $this->parameters->getParameter( 'catheadings' ) ) && count( $this->parameters->getParameter( 'catheadings' ) ) ) {
$this->addWhere(
[
'cl_head.cl_to' => $this->parameters->getParameter( 'catheadings' )
]
);
}
if ( is_array( $this->parameters->getParameter( 'catnotheadings' ) ) && count( $this->parameters->getParameter( 'catnotheadings' ) ) ) {
$this->addNotWhere(
[
'cl_head.cl_to' => $this->parameters->getParameter( 'catnotheadings' )
]
);
}

I discovered that if I expanded the category array first, and passed this array the problem appears to be resolved. My code (which may be somewhat hacky) is below:

	if ( is_array( $this->parameters->getParameter( 'catheadings' ) ) && count( $this->parameters->getParameter( 'catheadings' ) ) ) {
		$catHeadings = $this->parameters->getParameter('catheadings');
		$catHeadings = array_pop($catHeadings);
		$this->addWhere(
			"cl_head.cl_to " . ( count($catHeadings) > 1 ? ' IN (' . $this->DB->makeList($catHeadings) . ')' : ' = ' . $this->DB->addQuotes(current($catHeadings)))
		);
	}
	if ( is_array( $this->parameters->getParameter( 'catnotheadings' ) ) && count( $this->parameters->getParameter( 'catnotheadings' ) ) ) {
		$catHeadings = $this->parameters->getParameter('catnotheadings');
		$catHeadings = array_pop($catHeadings);
		$this->addNotWhere(
			[
				'cl_head.cl_to' => $catHeadings
			]
		);
	}

I suspect this is not the best way to fix the issue, but in my limited testing, it does look like it is working. Hopefully, this helps anyone who is looking for a temporary fix to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants