Last modified: 2010-02-23 13:13:50 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T18276, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 16276 - API needs an easier way to get section numbers
API needs an easier way to get section numbers
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
API (Other open bugs)
1.14.x
All All
: Normal enhancement with 2 votes (vote)
: ---
Assigned To: Roan Kattouw
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-07 22:37 UTC by Alex Z.
Modified: 2010-02-23 13:13 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Alex Z. 2008-11-07 22:37:14 UTC
Both action=edit and prop=revisions support sections. But, you have to use the section number, and there's no easy way to get it, besides parsing the wikitext yourself or doing something like http://en.wikipedia.org/w/api.php?action=parse&text={{:Page}}__TOC__&prop=sections

(the "__TOC__" is necessary because action=parse won't give the sections if there are less than 4, unless that's preset)

Ideally there should be some way to get the section number given only the page title or id, and the section name, or alternately, modules that allow sections should accept a section name.
Comment 1 Alex Z. 2008-11-07 23:39:17 UTC
And the action=parse method only works as it provides the full list of sections in order, to compare the names. The section numbers that it returns are not the same as the section numbers used for editing/getting revision text.
Comment 2 Roan Kattouw 2008-11-08 07:47:47 UTC
(In reply to comment #1)
> And the action=parse method only works as it provides the full list of sections
> in order, to compare the names. The section numbers that it returns are not the
> same as the section numbers used for editing/getting revision text.
> 

The section numbers it returns aren't the same, that's correct. The right section numbers are easy to get by simply counting (1 is the first section, 2 the second, etc.). Using this method, getting the section number given a section name is trivial.

Allowing section= parameters to take section names in addition to numbers was requested in a more generic fashion in bug 15575. It's far from trivial, since duplicate names need to be handled properly (not to mention sections named "1").
Comment 3 Alex Z. 2009-01-10 18:49:01 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > And the action=parse method only works as it provides the full list of sections
> > in order, to compare the names. The section numbers that it returns are not the
> > same as the section numbers used for editing/getting revision text.
> > 
> 
> The section numbers it returns aren't the same, that's correct. The right
> section numbers are easy to get by simply counting (1 is the first section, 2
> the second, etc.). Using this method, getting the section number given a
> section name is trivial.

That method doesn't work if the page has sections transcluded from templates. 

See for example http://en.wikipedia.org/w/index.php?oldid=263214281 

Sections transcluded from templates are given a different section number and skipped in the normal count. On that page, the first 2 and the fourth section are made on the page itself, the third and last 2 are transcluded from 2 different templates. 

So the actual section numbering goes: 1, 2, template1 T-1, 3, template2 T-1, template2 T-2. The action=parse results don't indicate this - http://en.wikipedia.org/w/api.php?action=parse&text={{User:Mr.Z-man/Sandbox}}__TOC__&prop=sections&oldid=263214281

Just counting them would give wrong numbers for all but the first 2 sections and there doesn't seem to be an easy way to filter out sections from templates. Ideally the API would return the section number used for section editing and indicate which sections come from templates, rather than the TOC section number, which is basically useless.
Comment 4 Roan Kattouw 2010-02-23 13:13:50 UTC
This was fixed some time ago when I changed the parser to always generate a section tree.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links