Make the PROTO_ parameter to wfExpandUrl() explicit in all calls. There are now no...
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 60b1714..d963f8c 100644 (file)
@@ -99,6 +99,7 @@ class ApiParse extends ApiBase {
                                if ( $titleObj->getLatestRevID() === intval( $oldid ) )  {
                                        $articleObj = new Article( $titleObj, 0 );
 
+                                       // May get from/save to parser cache
                                        $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
                                                 isset( $prop['wikitext'] ) ) ;
                                } else { // This is an old revision, so get the text differently
@@ -110,9 +111,10 @@ class ApiParse extends ApiBase {
                                                $this->text = $this->getSectionText( $this->text, 'r' . $rev->getId() );
                                        }
 
+                                       // Should we save old revision parses to the parser cache?
                                        $p_result = $wgParser->parse( $this->text, $titleObj, $popts );
                                }
-                       } else { // Not $oldid
+                       } else { // Not $oldid, but $pageid or $page
                                if ( $params['redirects'] ) {
                                        $reqParams = array(
                                                'action' => 'query',
@@ -159,6 +161,7 @@ class ApiParse extends ApiBase {
                                        $oldid = $articleObj->getRevIdFetched();
                                }
 
+                               // Potentially cached
                                $p_result = $this->getParsedSectionOrText( $articleObj, $titleObj, $popts, $pageid,
                                         isset( $prop['wikitext'] ) ) ;
                        }
@@ -180,6 +183,7 @@ class ApiParse extends ApiBase {
                        }
                        if ( $params['onlypst'] ) {
                                // Build a result and bail out
+                               $result_array = array();
                                $result_array['text'] = array();
                                $result->setContent( $result_array['text'], $this->pstText );
                                if ( isset( $prop['wikitext'] ) ) {
@@ -189,6 +193,7 @@ class ApiParse extends ApiBase {
                                $result->addValue( null, $this->getModuleName(), $result_array );
                                return;
                        }
+                       // Not cached (save or load)
                        $p_result = $wgParser->parse( $params['pst'] ? $this->pstText : $this->text, $titleObj, $popts );
                }
 
@@ -253,16 +258,16 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
-                       $context = new RequestContext;
+                       $context = $this->createContext();
+                       $context->setTitle( $titleObj );
                        $context->getOutput()->addParserOutputNoText( $p_result );
 
                        if ( isset( $prop['headitems'] ) ) {
                                $headItems = $this->formatHeadItems( $p_result->getHeadItems() );
 
-                               $context->getSkin()->setupUserCss( $context->getOutput() );
                                $css = $this->formatCss( $context->getOutput()->buildCssLinksArray() );
 
-                               $scripts = array( $context->getOutput()->getHeadScripts( $context->getSkin() ) );
+                               $scripts = array( $context->getOutput()->getHeadScripts() );
 
                                $result_array['headitems'] = array_merge( $headItems, $css, $scripts );
                        }
@@ -318,12 +323,14 @@ class ApiParse extends ApiBase {
                if ( $this->section !== false ) {
                        global $wgParser;
 
-                       $this->text = $this->getSectionText( $articleObj->getRawText(), !is_null ( $pageId )
+                       $this->text = $this->getSectionText( $articleObj->getRawText(), !is_null( $pageId )
                                        ? 'page id ' . $pageId : $titleObj->getText() );
 
+                       // Not cached (save or load)
                        return $wgParser->parse( $this->text, $titleObj, $popts );
                } else {
                        // Try the parser cache first
+                       // getParserOutput will save to Parser cache if able
                        $pout = $articleObj->getParserOutput();
                        if ( $getWikitext ) {
                                $rev = Revision::newFromTitle( $titleObj );
@@ -337,6 +344,7 @@ class ApiParse extends ApiBase {
 
        private function getSectionText( $text, $what ) {
                global $wgParser;
+               // Not cached (save or load)
                $text = $wgParser->getSection( $text, $this->section, false );
                if ( $text === false ) {
                        $this->dieUsage( "There is no section {$this->section} in " . $what, 'nosuchsection' );
@@ -353,7 +361,7 @@ class ApiParse extends ApiBase {
 
                        $entry['lang'] = $bits[0];
                        if ( $title ) {
-                               $entry['url'] = wfExpandUrl( $title->getFullURL() );
+                               $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
                        }
                        $this->getResult()->setContent( $entry, $bits[1] );
                        $result[] = $entry;
@@ -435,7 +443,7 @@ class ApiParse extends ApiBase {
 
                                $title = Title::newFromText( "{$prefix}:{$title}" );
                                if ( $title ) {
-                                       $entry['url'] = wfExpandUrl( $title->getFullURL() );
+                                       $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
                                }
 
                                $this->getResult()->setContent( $entry, $title->getFullText() );
@@ -579,14 +587,14 @@ class ApiParse extends ApiBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=parse&text={{Project:Sandbox}}'
                );
        }
 
        public function getHelpUrls() {
-               return '';
+               return 'http://www.mediawiki.org/wiki/API:Parsing_wikitext#parse';
        }
 
        public function getVersion() {