Hi,
Is there a function that already exists in the codebase that returns the # of sections in an article? I can't seem to find it. article::getSection takes a parameter for the ith section, but if you want to iterate over an article searching for a particular section, it's not clear how many sections there are. Similarily, it'd be great to have a function that return the section based on the section name, like getSectionByName or similar.
Travis
On Wed, 28 Feb 2007 10:08:26 -0500, Travis Derouin wrote:
Hi,
Is there a function that already exists in the codebase that returns the # of sections in an article? I can't seem to find it.
The problem is that there are two syntaxes for sections. The parser determines the number of sections by converting wiki sections to HTML syntax, then counting the HTML sections.
So the most accurate count is available at that stage of the parsing.
Travis Derouin wrote:
Hi,
Is there a function that already exists in the codebase that returns the # of sections in an article? I can't seem to find it. article::getSection takes a parameter for the ith section, but if you want to iterate over an article searching for a particular section, it's not clear how many sections there are. Similarily, it'd be great to have a function that return the section based on the section name, like getSectionByName or similar.
Travis
Hello Travis,
The parser does not report it. As sections are based on header, you can count the headers, this is done somewhere in the huge Parser::braceSubstitution method.
$m = preg_split( '/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
Fromm there, count($m) gives you the number of heading and thus the number of section. You will have to play with that code a bit :)
cheers,
On 3/1/07, Ashar Voultoiz hashar@altern.org wrote:
Travis Derouin wrote:
Hi,
Is there a function that already exists in the codebase that returns the # of sections in an article? I can't seem to find it. article::getSection takes a parameter for the ith section, but if you want to iterate over an article searching for a particular section, it's not clear how many sections there are. Similarily, it'd be great to have a function that return the section based on the section name, like getSectionByName or similar.
Travis
Hello Travis,
The parser does not report it. As sections are based on header, you can count the headers, this is done somewhere in the huge Parser::braceSubstitution method.
$m = preg_split( '/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
Fromm there, count($m) gives you the number of heading and thus the number of section. You will have to play with that code a bit :)
Actually both headings and blocks (the parts of sections between the headings) are also regexed in a couple of places in Parser.php/formatHeadings
I'm not sure if it should be centralized into a function.
Andrew Dunbar (hippietrail)
cheers,
-- Ashar Voultoiz - WP++++ http://en.wikipedia.org/wiki/User:Hashar http://www.livejournal.com/community/wikitech/ IM: hashar@jabber.org ICQ: 15325080
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 2/28/07, Andrew Dunbar hippytrail@gmail.com wrote:
Actually both headings and blocks (the parts of sections between the headings) are also regexed in a couple of places in Parser.php/formatHeadings
I'm not sure if it should be centralized into a function.
Why not supersede getSection and replaceSection with getSections and replaceSections functions that return/accept arrays of section number => array(section title, section level, section text) or something (could just be section number => text-including-section title/level/text)? That's more flexible, and in many cases it will be a good deal faster as well (if you want to deal with multiple sections on the page).
wikitech-l@lists.wikimedia.org