MER-C / wiki-java

A MediaWiki bot framework in Java
GNU Affero General Public License v3.0
66 stars 58 forks source link

Prefix parameter to Wiki.listPages predates provided namespace #163

Closed PeterBowman closed 6 years ago

PeterBowman commented 6 years ago

The namespace parameter is meaningless when a title prefix is provided, see:

https://github.com/MER-C/wiki-java/blob/4026210d8202203e3b1537fcb2b4753b0037cd5d/src/org/wikipedia/Wiki.java#L6179-L6185

This behavior might create confusion. I'm used to omitting the Category: namespace in page titles when using Wiki.categoryMembers. For the sake of clarity, these are the function's internals:

https://github.com/MER-C/wiki-java/blob/4026210d8202203e3b1537fcb2b4753b0037cd5d/src/org/wikipedia/Wiki.java#L5664-L5668

That is, I can invoke wiki.categoryMembers("Foo") and get all members of Category:Foo. In that vein, I expected that wiki.listPages("Foo", null, Wiki.CATEGORY_NAMESPACE) would list all categories starting with Foo, but it shows results from the main namespace only. The behavior I propose here is also consistent with the Special:ApiSandbox interface, which also expects a namespace-less title prefix along with the actual namespace passed on as another query parameter.

Moreover, namespaces could get "stacked" together, see wikt:es:Categoría:Wikcionario:Esbozo. Here, the localized Categoría refers to the category namespace, and Wikcionario to the project namespace.

Wiki wiki = Wikibot.createInstance("es.wiktionary.org");
String[] titles1 = wiki.listPages("Wikcionario:Esbozo", null, Wiki.CATEGORY_NAMESPACE);
System.out.println(Arrays.asList(titles1)); // [] (apnamespace=4)
String[] titles2 = wiki.listPages("Categoría:Wikcionario:Esbozo", null, Wiki.CATEGORY_NAMESPACE);
System.out.println(Arrays.asList(titles2)); // [Categoría:Wikcionario:Esbozo] (apnamespace=14)
MER-C commented 6 years ago

Does #163 fix this? The behavior I want is equivalent to: https://en.wikipedia.org/wiki/Special:PrefixIndex/Wikipedia:Featured_pictures/

PeterBowman commented 6 years ago

That'll do, thanks! You might want to update docs for the overload of listPages(), too.