Last modified: 2010-02-23 13:13:50 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.
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.
(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").
(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.
This was fixed some time ago when I changed the parser to always generate a section tree.