* Parser now returns list of sections (for API; some extensions probably also need it)
authorVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 27 Dec 2007 20:14:07 +0000 (20:14 +0000)
committerVictor Vasiliev <vasilievvv@users.mediawiki.org>
Thu, 27 Dec 2007 20:14:07 +0000 (20:14 +0000)
* Add list of sections to action=parse output

RELEASE-NOTES
includes/Parser.php
includes/ParserOutput.php
includes/api/ApiParse.php

index 0eba7fb..fed43fd 100644 (file)
@@ -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 <query> tag
+* Add list of sections to action=parse output
 
 === Languages updated in 1.12 ===
 
index 97e18f5..3cad35a 100644 (file)
@@ -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 <h#> 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;
index e7164f3..313b5ea 100644 (file)
@@ -21,7 +21,8 @@ class ParserOutput
                $mNoGallery,        # No gallery on category page? (__NOGALLERY__)
                $mHeadItems,        # Items to put in the <head> 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; }
index a6aa52e..39382f3 100644 (file)
@@ -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() );