MER-C/wiki-java

Prefix parameter to Wiki.listPages predates provided namespace

PeterBowman opened this issue · 2 comments

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

if (!prefix.isEmpty()) // prefix
{
// cull the namespace prefix
namespace = namespace(prefix);
prefix = removeNamespace(prefix);
getparams.put("apprefix", normalize(prefix));
}

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:

name = removeNamespace(name);
Map<String, String> getparams = new HashMap<>();
getparams.put("list", "categorymembers");
getparams.put("cmprop", "title");
getparams.put("cmtitle", "Category:" + removeNamespace(normalize(name)));

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)

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