Merge "tests: speed up fetchTextTest"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 43d71ab..f140f54 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Session\SessionManager;
 use WrappedString\WrappedString;
 use WrappedString\WrappedStringList;
@@ -1010,8 +1011,9 @@ class OutputPage extends ContextSource {
                if ( $title->isRedirect() ) {
                        $query['redirect'] = 'no';
                }
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                return wfMessage( 'backlinksubtitle' )
-                       ->rawParams( Linker::link( $title, null, [], $query ) );
+                       ->rawParams( $linkRenderer->makeLink( $title, null, [], $query ) );
        }
 
        /**
@@ -1264,11 +1266,14 @@ class OutputPage extends ContextSource {
                        }
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                # Add the remaining categories to the skin
                if ( Hooks::run(
                        'OutputPageMakeCategoryLinks',
-                       [ &$this, $categories, &$this->mCategoryLinks ] )
+                       [ &$outputPage, $categories, &$this->mCategoryLinks ] )
                ) {
+                       $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                        foreach ( $categories as $category => $type ) {
                                // array keys will cast numeric category names to ints, so cast back to string
                                $category = (string)$category;
@@ -1283,7 +1288,7 @@ class OutputPage extends ContextSource {
                                }
                                $text = $wgContLang->convertHtml( $title->getText() );
                                $this->mCategories[$type][] = $title->getText();
-                               $this->mCategoryLinks[$type][] = Linker::link( $title, $text );
+                               $this->mCategoryLinks[$type][] = $linkRenderer->makeLink( $title, new HtmlArmor( $text ) );
                        }
                }
        }
@@ -1807,8 +1812,10 @@ class OutputPage extends ContextSource {
                // Link flags are ignored for now, but may in the future be
                // used to mark individual language links.
                $linkFlags = [];
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
                Hooks::run( 'LanguageLinks', [ $this->getTitle(), &$this->mLanguageLinks, &$linkFlags ] );
-               Hooks::run( 'OutputPageParserOutput', [ &$this, $parserOutput ] );
+               Hooks::run( 'OutputPageParserOutput', [ &$outputPage, $parserOutput ] );
        }
 
        /**
@@ -1836,7 +1843,9 @@ class OutputPage extends ContextSource {
         */
        public function addParserOutputText( $parserOutput ) {
                $text = $parserOutput->getText();
-               Hooks::run( 'OutputPageBeforeHTML', [ &$this, &$text ] );
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $outputPage = $this;
+               Hooks::run( 'OutputPageBeforeHTML', [ &$outputPage, &$text ] );
                $this->addHTML( $text );
        }
 
@@ -2173,7 +2182,7 @@ class OutputPage extends ContextSource {
         * if there isn't one. This is used by Skin to determine whether to enable
         * JavaScript frame-breaking, for clients that don't support X-Frame-Options.
         *
-        * @return string
+        * @return string|false
         */
        public function getFrameOptions() {
                $config = $this->getConfig();
@@ -2300,7 +2309,7 @@ class OutputPage extends ContextSource {
                                $response->header( "Content-Type: text/html; charset=utf-8" );
                                if ( $config->get( 'DebugRedirects' ) ) {
                                        $url = htmlspecialchars( $redirect );
-                                       print "<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
+                                       print "<!DOCTYPE html>\n<html>\n<head>\n<title>Redirect</title>\n</head>\n<body>\n";
                                        print "<p>Location: <a href=\"$url\">$url</a></p>\n";
                                        print "</body>\n</html>\n";
                                } else {
@@ -2355,9 +2364,11 @@ class OutputPage extends ContextSource {
                        }
                        MWDebug::addModules( $this );
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $outputPage = $this;
                        // Hook that allows last minute changes to the output page, e.g.
                        // adding of CSS or Javascript by extensions.
-                       Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] );
+                       Hooks::run( 'BeforePageDisplay', [ &$outputPage, &$sk ] );
 
                        try {
                                $sk->outputPage();
@@ -2653,8 +2664,10 @@ class OutputPage extends ContextSource {
         * @param array $options Options array to pass to Linker
         */
        public function addReturnTo( $title, array $query = [], $text = null, $options = [] ) {
+               $linkRenderer = MediaWikiServices::getInstance()
+                       ->getLinkRendererFactory()->createFromLegacyOptions( $options );
                $link = $this->msg( 'returnto' )->rawParams(
-                       Linker::link( $title, $text, [], $query, $options ) )->escaped();
+                       $linkRenderer->makeLink( $title, $text, [], $query ) )->escaped();
                $this->addHTML( "<p id=\"mw-returnto\">{$link}</p>\n" );
        }
 
@@ -2735,7 +2748,6 @@ class OutputPage extends ContextSource {
                                'site.styles',
                                'noscript',
                                'user.styles',
-                               'user.cssprefs',
                        ] );
                        $this->getSkin()->setupSkinUserCss( $this );
 
@@ -2848,6 +2860,14 @@ class OutputPage extends ContextSource {
                $bodyClasses[] = $userdir;
                $bodyClasses[] = "sitedir-$sitedir";
 
+               $underline = $this->getUser()->getOption( 'underline' );
+               if ( $underline < 2 ) {
+                       // The following classes can be used here:
+                       // * mw-underline-always
+                       // * mw-underline-never
+                       $bodyClasses[] = 'mw-underline-' . ( $underline ? 'always' : 'never' );
+               }
+
                if ( $this->getLanguage()->capitalizeAllNouns() ) {
                        # A <body> class is probably not the best way to do this . . .
                        $bodyClasses[] = 'capitalize-all-nouns';