Made DifferenceEngine use a context instead of global variables and updaters calls...
[lhc/web/wiklou.git] / includes / api / ApiParse.php
index 40b90cf..b1e344c 100644 (file)
@@ -62,7 +62,8 @@ class ApiParse extends ApiBase {
 
                // The parser needs $wgTitle to be set, apparently the
                // $title parameter in Parser::parse isn't enough *sigh*
-               global $wgParser, $wgUser, $wgTitle, $wgLang;
+               // TODO: Does this still need $wgTitle?
+               global $wgParser, $wgTitle, $wgLang;
 
                // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang breaks
                $oldLang = null;
@@ -99,6 +100,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,7 +112,7 @@ class ApiParse extends ApiBase {
                                                $this->text = $this->getSectionText( $this->text, 'r' . $rev->getId() );
                                        }
 
-                                       // Do we want to save old revision parses to the parser cache?
+                                       // Should we save old revision parses to the parser cache?
                                        $p_result = $wgParser->parse( $this->text, $titleObj, $popts );
                                }
                        } else { // Not $oldid, but $pageid or $page
@@ -178,10 +180,11 @@ class ApiParse extends ApiBase {
                        }
 
                        if ( $params['pst'] || $params['onlypst'] ) {
-                               $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $wgUser, $popts );
+                               $this->pstText = $wgParser->preSaveTransform( $this->text, $titleObj, $this->getUser(), $popts );
                        }
                        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'] ) ) {
@@ -214,7 +217,7 @@ class ApiParse extends ApiBase {
 
                if ( !is_null( $params['summary'] ) ) {
                        $result_array['parsedsummary'] = array();
-                       $result->setContent( $result_array['parsedsummary'], $wgUser->getSkin()->formatComment( $params['summary'], $titleObj ) );
+                       $result->setContent( $result_array['parsedsummary'], Linker::formatComment( $params['summary'], $titleObj ) );
                }
 
                if ( isset( $prop['langlinks'] ) ) {
@@ -256,7 +259,7 @@ class ApiParse extends ApiBase {
                }
 
                if ( isset( $prop['headitems'] ) || isset( $prop['headhtml'] ) ) {
-                       $context = $this->createContext();
+                       $context = $this->getContext();
                        $context->setTitle( $titleObj );
                        $context->getOutput()->addParserOutputNoText( $p_result );
 
@@ -321,7 +324,7 @@ 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)
@@ -359,7 +362,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;
@@ -379,7 +382,7 @@ class ApiParse extends ApiBase {
        }
 
        private function categoriesHtml( $categories ) {
-               $context = $this->createContext();
+               $context = $this->getContext();
                $context->getOutput()->addCategoryLinks( $categories );
                return $context->getSkin()->getCategories();
        }
@@ -387,6 +390,8 @@ class ApiParse extends ApiBase {
        /**
         * @deprecated since 1.18 No modern skin generates language links this way, please use language links
         *                        data to generate your own HTML.
+        * @param $languages array
+        * @return string
         */
        private function languagesHtml( $languages ) {
                global $wgContLang, $wgHideInterlanguageLinks;
@@ -441,7 +446,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() );
@@ -585,7 +590,7 @@ class ApiParse extends ApiBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=parse&text={{Project:Sandbox}}'
                );