Merge "Prevent OutputPage::addWikiText and friends from causing UNIQ fails"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 72869e4..2a96891 100644 (file)
@@ -473,8 +473,10 @@ class OutputPage extends ContextSource {
         * Get all registered JS and CSS tags for the header.
         *
         * @return string
+        * @deprecated since 1.24 Use OutputPage::headElement to build the full header.
         */
        function getScript() {
+               wfDeprecated( __METHOD__, '1.24' );
                return $this->mScripts . $this->getHeadItems();
        }
 
@@ -630,8 +632,11 @@ class OutputPage extends ContextSource {
         * Get all header items in a string
         *
         * @return string
+        * @deprecated since 1.24 Use OutputPage::headElement or
+        *   if absolutely necessary use OutputPage::getHeadItemsArray
         */
        function getHeadItems() {
+               wfDeprecated( __METHOD__, '1.24' );
                $s = '';
                foreach ( $this->mHeadItems as $item ) {
                        $s .= $item;
@@ -1603,7 +1608,7 @@ class OutputPage extends ContextSource {
                $oldTidy = $popts->setTidy( $tidy );
                $popts->setInterfaceMessage( (bool)$interface );
 
-               $parserOutput = $wgParser->parse(
+               $parserOutput = $wgParser->getFreshParser()->parse(
                        $text, $title, $popts,
                        $linestart, true, $this->mRevisionId
                );
@@ -1616,11 +1621,24 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add a ParserOutput object, but without Html
+        * Add a ParserOutput object, but without Html.
         *
+        * @deprecated since 1.24, use addParserOutputMetadata() instead.
         * @param ParserOutput $parserOutput
         */
        public function addParserOutputNoText( &$parserOutput ) {
+               $this->addParserOutputMetadata( $parserOutput );
+       }
+
+       /**
+        * Add all metadata associated with a ParserOutput object, but without the actual HTML. This
+        * includes categories, language links, ResourceLoader modules, effects of certain magic words,
+        * and so on.
+        *
+        * @since 1.24
+        * @param ParserOutput $parserOutput
+        */
+       public function addParserOutputMetadata( &$parserOutput ) {
                $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                $this->addCategoryLinks( $parserOutput->getCategories() );
                $this->mNewSectionLink = $parserOutput->getNewSection();
@@ -1668,21 +1686,50 @@ class OutputPage extends ContextSource {
        }
 
        /**
-        * Add a ParserOutput object
+        * Add the HTML and enhancements for it (like ResourceLoader modules) associated with a
+        * ParserOutput object, without any other metadata.
+        *
+        * @since 1.24
+        * @param ParserOutput $parserOutput
+        */
+       public function addParserOutputContent( &$parserOutput ) {
+               $this->addParserOutputText( $parserOutput );
+
+               $this->addModules( $parserOutput->getModules() );
+               $this->addModuleScripts( $parserOutput->getModuleScripts() );
+               $this->addModuleStyles( $parserOutput->getModuleStyles() );
+               $this->addModuleMessages( $parserOutput->getModuleMessages() );
+
+               $this->addJsConfigVars( $parserOutput->getJsConfigVars() );
+       }
+
+       /**
+        * Add the HTML associated with a ParserOutput object, without any metadata.
+        *
+        * @since 1.24
+        * @param ParserOutput $parserOutput
+        */
+       public function addParserOutputText( &$parserOutput ) {
+               $text = $parserOutput->getText();
+               wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
+               $this->addHTML( $text );
+       }
+
+       /**
+        * Add everything from a ParserOutput object.
         *
         * @param ParserOutput $parserOutput
         */
        function addParserOutput( &$parserOutput ) {
-               $this->addParserOutputNoText( $parserOutput );
+               $this->addParserOutputMetadata( $parserOutput );
                $parserOutput->setTOCEnabled( $this->mEnableTOC );
 
                // Touch section edit links only if not previously disabled
                if ( $parserOutput->getEditSectionTokens() ) {
                        $parserOutput->setEditSectionTokens( $this->mEnableSectionEditLinks );
                }
-               $text = $parserOutput->getText();
-               wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
-               $this->addHTML( $text );
+
+               $this->addParserOutputText( $parserOutput );
        }
 
        /**
@@ -1721,7 +1768,7 @@ class OutputPage extends ContextSource {
                        $oldLang = $popts->setTargetLanguage( $language );
                }
 
-               $parserOutput = $wgParser->parse(
+               $parserOutput = $wgParser->getFreshParser()->parse(
                        $text, $this->getTitle(), $popts,
                        $linestart, true, $this->mRevisionId
                );
@@ -1884,7 +1931,12 @@ class OutputPage extends ContextSource {
         *   /w/index.php?title=Main_page&variant=zh-cn should never be served.
         */
        function addAcceptLanguage() {
-               $lang = $this->getTitle()->getPageLanguage();
+               $title = $this->getTitle();
+               if ( !$title instanceof Title ) {
+                       return;
+               }
+
+               $lang = $title->getPageLanguage();
                if ( !$this->getRequest()->getCheck( 'variant' ) && $lang->hasVariants() ) {
                        $variants = $lang->getVariants();
                        $aloption = array();
@@ -2585,15 +2637,18 @@ $templates
 
                $ret .= Html::element( 'title', null, $this->getHTMLTitle() ) . "\n";
 
-               $ret .= (
-                       $this->getHeadLinks() .
-                       "\n" .
-                       $this->buildCssLinks() .
-                       // No newline after buildCssLinks since makeResourceLoaderLink did that already
-                       $this->getHeadScripts() .
-                       "\n" .
-                       $this->getHeadItems()
-               );
+               foreach ( $this->getHeadLinksArray() as $item ) {
+                       $ret .= $item . "\n";
+               }
+
+               // No newline after buildCssLinks since makeResourceLoaderLink did that already
+               $ret .= $this->buildCssLinks();
+
+               $ret .= $this->getHeadScripts() . "\n";
+
+               foreach ( $this->mHeadItems as $item ) {
+                       $ret .= $item . "\n";
+               }
 
                $closeHead = Html::closeElement( 'head' );
                if ( $closeHead ) {
@@ -3269,13 +3324,13 @@ $templates
                                        'rel' => 'alternate',
                                        'type' => 'application/x-wiki',
                                        'title' => $msg,
-                                       'href' => $this->getTitle()->getLocalURL( 'action=edit' )
+                                       'href' => $this->getTitle()->getEditURL(),
                                ) );
                                // Alternate edit link
                                $tags['alternative-edit'] = Html::element( 'link', array(
                                        'rel' => 'edit',
                                        'title' => $msg,
-                                       'href' => $this->getTitle()->getLocalURL( 'action=edit' )
+                                       'href' => $this->getTitle()->getEditURL(),
                                ) );
                        }
                }
@@ -3434,8 +3489,11 @@ $templates
 
        /**
         * @return string HTML tag links to be put in the header.
+        * @deprecated since 1.24 Use OutputPage::headElement or if you have to,
+        *   OutputPage::getHeadLinksArray directly.
         */
        public function getHeadLinks() {
+               wfDeprecated( __METHOD__, '1.24' );
                return implode( "\n", $this->getHeadLinksArray() );
        }