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