Page MenuHomePhabricator

Extend the functionality of mw.ext.proofreadPage by getting the label for pages from the pagelist
Open, Needs TriagePublicFeature

Description

Feature summary:
I want to extend the funcionality of the ProofreadPage lua library, to be able to easily get the "label map" of the pages in the index. This is easily and cheaply achieved from parsing the pagelist text and making the same inferences the ProofreadPage extension does to assign each page a label.
I already have a working module at Spanish Wikisource

Use case(s)
This could be used to easily get the file page from the index label page.

image.png (544×426 px, 59 KB)

Benefits:
It's easy and cheap and language communities can come up with their own solutions without importing an additional module.

Event Timeline

Thanks for sharing the module! I had a read through your DJVUpage code.

I think ProofreadPage can actually do this itself already in PHP - the Pagination
and PageNumber classes do the same pagelist label inference internally, so instead
of porting the parser to Lua we could just expose it directly. Something like
mw.ext.proofreadPage.getPageLabels( index ) that returns a { position = label }
table using the exact same logic the extension uses to render <pagelist>.

Two quick things before I start - do you want the formatted label (what shows in
the page header) or the raw value, and would you rather it be keyed by position
number or by the Page: title?

Happy to write the patch once I know which fits your use case :)

Thanks to you for such a positive response!

1- I don't understand the difference between the formatted and the raw value. Can you give me an example?

2- I think position number is the simplest and more intuitive way to deal with the table. I can think of a special case with Index pages without <pagelist> such as collections of JPG files (I think de.wikisource uses a lot of those). Maybe it's best to give both options.

3- Consider making them methods of the Index object. Additional auxilliary methods such as "get page number from label", "get page object from label" would be appreciated.

I'm very happy with the result in my home WS.

Thanks so much for the detailed reply, this really helps

On the formatted vs raw thing - I actually went and looked at the code, and the
two are almost the same. For normal numbers, roman numerals, localised digits and
text labels like "Cover" they give you the exact same string. The only real
difference is in folio / recto-verso mode where the formatted one adds the
recto/verso styling. So for what you want (finding the file page from a label) it
honestly barely matters. One small thing I noticed is that the formatted version
escapes its output since it is meant for rendering on the page, so for a Lua API
we would probably want a plain label instead. I will take care of that when I
write it.

Position keying works great. And good news on the JPG collections without a
pagelist - ProofreadPage already has a separate file based pagination for those,
and the method I have in mind uses that same layer underneath, so it should just
work for both cases without any special handling.

The reverse lookups (page number from label, page object from label) and putting
these on the Index object are really nice ideas. Since this adds new public Lua
API to ProofreadPage though, I would rather start small with just the core
getPageLabels method and check the overall API shape with the ProofreadPage
maintainers, then add the label to number and label to page helpers as follow ups.
That way each change stays small and easy to review. Does that sound okay to you

Really glad it is already working well on es.wikisource :)

Change #1317675 had a related patch set uploaded (by Zaidusyy; author: Zaidusyy):

[mediawiki/extensions/ProofreadPage@master] Add getPageLabels() to the ProofreadPage Lua library

https://gerrit.wikimedia.org/r/1317675

First patch is up - the core getPageLabels() method on the Index object:
https://gerrit.wikimedia.org/r/c/mediawiki/extensions/ProofreadPage/+/1317675

Reverse lookups (label to number, label to page) will follow as separate
patches. I've tagged the ProofreadPage maintainers for the API review.