From: Victor Vasiliev Date: Thu, 27 Dec 2007 20:14:07 +0000 (+0000) Subject: * Parser now returns list of sections (for API; some extensions probably also need it) X-Git-Tag: 1.31.0-rc.0~50257 X-Git-Url: https://git.cyclocoop.org/admin/%7B%7Blocalurl:Special:UserLogin%7D%7D?a=commitdiff_plain;h=7847494e5df4d4ca897e29f11548c525b98c189a;p=lhc%2Fweb%2Fwiklou.git * Parser now returns list of sections (for API; some extensions probably also need it) * Add list of sections to action=parse output --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 0eba7fb022..fed43fd578 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -111,6 +111,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN extension * Add HTML ID's mw-read-only-warning and mw-anon-edit-warning to warnings when editing to allow CSS styling. +* Parser now returns list of sections === Bug fixes in 1.12 === @@ -385,6 +386,7 @@ Full API documentation is available at http://www.mediawiki.org/wiki/API * (bug 12321) API list=blocks reveals private data * Fix output of wfSajaxSearch * (bug 12413) meta=userinfo missing tag +* Add list of sections to action=parse output === Languages updated in 1.12 === diff --git a/includes/Parser.php b/includes/Parser.php index 97e18f5733..3cad35aa3b 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -48,7 +48,7 @@ class Parser * changes in an incompatible way, so the parser cache * can automatically discard old data. */ - const VERSION = '1.6.2'; + const VERSION = '1.6.3'; # Flags for Parser::setFunctionHook # Also available as global constants from Defines.php @@ -3816,6 +3816,7 @@ class Parser $prevtoclevel = 0; $markerRegex = "{$this->mUniqPrefix}-h-(\d+)-{$this->mMarkerSuffix}"; $baseTitleText = $this->mTitle->getPrefixedDBkey(); + $tocraw = array(); foreach( $matches[3] as $headline ) { $isTemplate = false; @@ -3949,6 +3950,7 @@ class Parser } if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) { $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel); + $tocraw[] = array( 'toclevel' => $toclevel, 'level' => $level, 'line' => $tocline, 'number' => $numbering ); } # give headline the correct tag if( $showEditLink && $sectionIndex !== false ) { @@ -3964,6 +3966,8 @@ class Parser $headlineCount++; } + $this->mOutput->setSections( $tocraw ); + # Never ever show TOC if no headers if( $numVisible < 1 ) { $enoughToc = false; diff --git a/includes/ParserOutput.php b/includes/ParserOutput.php index e7164f3549..313b5ea174 100644 --- a/includes/ParserOutput.php +++ b/includes/ParserOutput.php @@ -21,7 +21,8 @@ class ParserOutput $mNoGallery, # No gallery on category page? (__NOGALLERY__) $mHeadItems, # Items to put in the section $mOutputHooks, # Hook tags as per $wgParserOutputHooks - $mWarnings; # Warning text to be returned to the user. Wikitext formatted. + $mWarnings, # Warning text to be returned to the user. Wikitext formatted. + $mSections; # Table of contents /** * Overridden title for display @@ -38,6 +39,7 @@ class ParserOutput $this->mCacheTime = ''; $this->mVersion = Parser::VERSION; $this->mTitleText = $titletext; + $this->mSections = ''; $this->mLinks = array(); $this->mTemplates = array(); $this->mImages = array(); @@ -56,6 +58,7 @@ class ParserOutput function &getCategories() { return $this->mCategories; } function getCacheTime() { return $this->mCacheTime; } function getTitleText() { return $this->mTitleText; } + function getSections() { return $this->mSections; } function &getLinks() { return $this->mLinks; } function &getTemplates() { return $this->mTemplates; } function &getImages() { return $this->mImages; } @@ -71,7 +74,8 @@ class ParserOutput function setCategoryLinks( $cl ) { return wfSetVar( $this->mCategories, $cl ); } function setContainsOldMagic( $com ) { return wfSetVar( $this->mContainsOldMagic, $com ); } function setCacheTime( $t ) { return wfSetVar( $this->mCacheTime, $t ); } - function setTitleText( $t ) { return wfSetVar($this->mTitleText, $t); } + function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); } + function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); } function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; } function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; } diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index a6aa52ed64..39382f3a3e 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -63,6 +63,7 @@ class ApiParse extends ApiBase { 'templates' => $this->formatLinks( $p_result->getTemplates() ), 'images' => array_keys( $p_result->getImages() ), 'externallinks' => array_keys( $p_result->getExternalLinks() ), + 'sections' => $p_result->getSections(), ); $result_mapping = array( 'langlinks' => 'll', @@ -71,6 +72,7 @@ class ApiParse extends ApiBase { 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', + 'sections' => 's', ); $this->setIndexedTagNames( $result_array, $result_mapping ); $result->setContent( $result_array['text'], $p_result->getText() );