Skin::outputPage: Drop support for specifying a context, deprecated in 1.20
[lhc/web/wiklou.git] / includes / skins / Skin.php
index 3247f1d..05b6297 100644 (file)
@@ -55,7 +55,8 @@ abstract class Skin extends ContextSource {
         * @return array Associative array of strings
         */
        static function getSkinNames() {
-               return SkinFactory::getDefaultInstance()->getSkinNames();
+               $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
+               return $skinFactory->getSkinNames();
        }
 
        /**
@@ -175,7 +176,6 @@ abstract class Skin extends ContextSource {
         */
        public function getDefaultModules() {
                $out = $this->getOutput();
-               $config = $this->getConfig();
                $user = $this->getUser();
 
                // Modules declared in the $modules literal are loaded
@@ -196,14 +196,15 @@ abstract class Skin extends ContextSource {
                        'core' => [
                                'site',
                                'mediawiki.page.startup',
-                               'mediawiki.user',
                        ],
                        // modules that enhance the content in some way
                        'content' => [
                                'mediawiki.page.ready',
                        ],
                        // modules relating to search functionality
-                       'search' => [],
+                       'search' => [
+                               'mediawiki.searchSuggest',
+                       ],
                        // modules relating to functionality relating to watching an article
                        'watch' => [],
                        // modules which relate to the current users preferences
@@ -215,6 +216,7 @@ abstract class Skin extends ContextSource {
                // Preload jquery.tablesorter for mediawiki.page.ready
                if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
                        $modules['content'][] = 'jquery.tablesorter';
+                       $modules['styles']['content'][] = 'jquery.tablesorter.styles';
                }
 
                // Preload jquery.makeCollapsible for mediawiki.page.ready
@@ -242,8 +244,6 @@ abstract class Skin extends ContextSource {
                        $modules['watch'][] = 'mediawiki.page.watch.ajax';
                }
 
-               $modules['search'][] = 'mediawiki.searchSuggest';
-
                if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {
                        $modules['user'][] = 'mediawiki.action.view.rightClickEdit';
                }
@@ -389,9 +389,8 @@ abstract class Skin extends ContextSource {
 
        /**
         * Outputs the HTML generated by other functions.
-        * @param OutputPage|null $out
         */
-       abstract function outputPage( OutputPage $out = null );
+       abstract function outputPage();
 
        /**
         * @param array $data
@@ -497,8 +496,7 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function getLogo() {
-               global $wgLogo;
-               return $wgLogo;
+               return $this->getConfig()->get( 'Logo' );
        }
 
        /**
@@ -518,12 +516,11 @@ abstract class Skin extends ContextSource {
         * @return string HTML
         */
        function getCategoryLinks() {
-               global $wgUseCategoryBrowser;
-
                $out = $this->getOutput();
                $allCats = $out->getCategoryLinks();
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
-               if ( !count( $allCats ) ) {
+               if ( $allCats === [] ) {
                        return '';
                }
 
@@ -534,14 +531,14 @@ abstract class Skin extends ContextSource {
                $colon = $this->msg( 'colon-separator' )->escaped();
 
                if ( !empty( $allCats['normal'] ) ) {
-                       $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
+                       $t = $embed . implode( $pop . $embed, $allCats['normal'] ) . $pop;
 
-                       $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
+                       $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) );
                        $linkPage = $this->msg( 'pagecategorieslink' )->inContentLanguage()->text();
                        $title = Title::newFromText( $linkPage );
-                       $link = $title ? Linker::link( $title, $msg ) : $msg;
+                       $link = $title ? $linkRenderer->makeLink( $title, $msg->text() ) : $msg->escaped();
                        $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
-                               $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
+                               $link . $colon . '<ul>' . $t . '</ul></div>';
                }
 
                # Hidden categories
@@ -556,13 +553,13 @@ abstract class Skin extends ContextSource {
 
                        $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
                                $this->msg( 'hidden-categories' )->numParams( count( $allCats['hidden'] ) )->escaped() .
-                               $colon . '<ul>' . $embed . implode( "{$pop}{$embed}", $allCats['hidden'] ) . $pop . '</ul>' .
+                               $colon . '<ul>' . $embed . implode( $pop . $embed, $allCats['hidden'] ) . $pop . '</ul>' .
                                '</div>';
                }
 
                # optional 'dmoz-like' category browser. Will be shown under the list
                # of categories an article belong to
-               if ( $wgUseCategoryBrowser ) {
+               if ( $this->getConfig()->get( 'UseCategoryBrowser' ) ) {
                        $s .= '<br /><hr />';
 
                        # get a big array of the parents tree
@@ -587,6 +584,7 @@ abstract class Skin extends ContextSource {
         */
        function drawCategoryBrowser( $tree ) {
                $return = '';
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
                foreach ( $tree as $element => $parent ) {
                        if ( empty( $parent ) ) {
@@ -599,7 +597,7 @@ abstract class Skin extends ContextSource {
 
                        # add our current element to the list
                        $eltitle = Title::newFromText( $element );
-                       $return .= Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
+                       $return .= $linkRenderer->makeLink( $eltitle, $eltitle->getText() );
                }
 
                return $return;
@@ -720,10 +718,13 @@ abstract class Skin extends ContextSource {
         */
        function getUndeleteLink() {
                $action = $this->getRequest()->getVal( 'action', 'view' );
+               $title = $this->getTitle();
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
-               if ( $this->getTitle()->userCan( 'deletedhistory', $this->getUser() ) &&
-                       ( !$this->getTitle()->exists() || $action == 'history' ) ) {
-                       $n = $this->getTitle()->isDeleted();
+               if ( ( !$title->exists() || $action == 'history' ) &&
+                       $title->quickUserCan( 'deletedhistory', $this->getUser() )
+               ) {
+                       $n = $title->isDeleted();
 
                        if ( $n ) {
                                if ( $this->getTitle()->quickUserCan( 'undelete', $this->getUser() ) ) {
@@ -733,9 +734,9 @@ abstract class Skin extends ContextSource {
                                }
 
                                return $this->msg( $msg )->rawParams(
-                                       Linker::linkKnown(
+                                       $linkRenderer->makeKnownLink(
                                                SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
-                                               $this->msg( 'restorelink' )->numParams( $n )->escaped() )
+                                               $this->msg( 'restorelink' )->numParams( $n )->text() )
                                        )->escaped();
                        }
                }
@@ -748,6 +749,7 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function subPageSubtitle( $out = null ) {
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                if ( $out === null ) {
                        $out = $this->getOutput();
                }
@@ -758,7 +760,10 @@ abstract class Skin extends ContextSource {
                        return $subpages;
                }
 
-               if ( $out->isArticle() && MWNamespace::hasSubpages( $title->getNamespace() ) ) {
+               if (
+                       $out->isArticle() && MediaWikiServices::getInstance()->getNamespaceInfo()->
+                               hasSubpages( $title->getNamespace() )
+               ) {
                        $ptext = $title->getPrefixedText();
                        if ( strpos( $ptext, '/' ) !== false ) {
                                $links = explode( '/', $ptext );
@@ -774,9 +779,8 @@ abstract class Skin extends ContextSource {
                                        $linkObj = Title::newFromText( $growinglink );
 
                                        if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
-                                               $getlink = Linker::linkKnown(
-                                                       $linkObj,
-                                                       htmlspecialchars( $display )
+                                               $getlink = $linkRenderer->makeKnownLink(
+                                                       $linkObj, $display
                                                );
 
                                                $c++;
@@ -820,8 +824,7 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function getCopyright( $type = 'detect' ) {
-               global $wgRightsPage, $wgRightsUrl, $wgRightsText;
-
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                if ( $type == 'detect' ) {
                        if ( !$this->isRevisionCurrent()
                                && !$this->msg( 'history_copyright' )->inContentLanguage()->isDisabled()
@@ -838,13 +841,17 @@ abstract class Skin extends ContextSource {
                        $msg = 'copyright';
                }
 
-               if ( $wgRightsPage ) {
-                       $title = Title::newFromText( $wgRightsPage );
-                       $link = Linker::linkKnown( $title, $wgRightsText );
-               } elseif ( $wgRightsUrl ) {
-                       $link = Linker::makeExternalLink( $wgRightsUrl, $wgRightsText );
-               } elseif ( $wgRightsText ) {
-                       $link = $wgRightsText;
+               $config = $this->getConfig();
+
+               if ( $config->get( 'RightsPage' ) ) {
+                       $title = Title::newFromText( $config->get( 'RightsPage' ) );
+                       $link = $linkRenderer->makeKnownLink(
+                               $title, new HtmlArmor( $config->get( 'RightsText' ) )
+                       );
+               } elseif ( $config->get( 'RightsUrl' ) ) {
+                       $link = Linker::makeExternalLink( $config->get( 'RightsUrl' ), $config->get( 'RightsText' ) );
+               } elseif ( $config->get( 'RightsText' ) ) {
+                       $link = $config->get( 'RightsText' );
                } else {
                        # Give up now
                        return '';
@@ -866,24 +873,24 @@ abstract class Skin extends ContextSource {
         * @return null|string
         */
        function getCopyrightIcon() {
-               global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgFooterIcons;
-
                $out = '';
+               $config = $this->getConfig();
 
-               if ( $wgFooterIcons['copyright']['copyright'] ) {
-                       $out = $wgFooterIcons['copyright']['copyright'];
-               } elseif ( $wgRightsIcon ) {
-                       $icon = htmlspecialchars( $wgRightsIcon );
+               $footerIcons = $config->get( 'FooterIcons' );
+               if ( $footerIcons['copyright']['copyright'] ) {
+                       $out = $footerIcons['copyright']['copyright'];
+               } elseif ( $config->get( 'RightsIcon' ) ) {
+                       $icon = htmlspecialchars( $config->get( 'RightsIcon' ) );
+                       $url = $config->get( 'RightsUrl' );
 
-                       if ( $wgRightsUrl ) {
-                               $url = htmlspecialchars( $wgRightsUrl );
-                               $out .= '<a href="' . $url . '">';
+                       if ( $url ) {
+                               $out .= '<a href="' . htmlspecialchars( $url ) . '">';
                        }
 
-                       $text = htmlspecialchars( $wgRightsText );
+                       $text = htmlspecialchars( $config->get( 'RightsText' ) );
                        $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
 
-                       if ( $wgRightsUrl ) {
+                       if ( $url ) {
                                $out .= '</a>';
                        }
                }
@@ -896,18 +903,17 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function getPoweredBy() {
-               global $wgResourceBasePath;
-
+               $resourceBasePath = $this->getConfig()->get( 'ResourceBasePath' );
                $url1 = htmlspecialchars(
-                       "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
+                       "$resourceBasePath/resources/assets/poweredby_mediawiki_88x31.png"
                );
                $url1_5 = htmlspecialchars(
-                       "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
+                       "$resourceBasePath/resources/assets/poweredby_mediawiki_132x47.png"
                );
                $url2 = htmlspecialchars(
-                       "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
+                       "$resourceBasePath/resources/assets/poweredby_mediawiki_176x62.png"
                );
-               $text = '<a href="//www.mediawiki.org/"><img src="' . $url1
+               $text = '<a href="https://www.mediawiki.org/"><img src="' . $url1
                        . '" srcset="' . $url1_5 . ' 1.5x, ' . $url2 . ' 2x" '
                        . 'height="31" width="88" alt="Powered by MediaWiki" /></a>';
                Hooks::run( 'SkinGetPoweredBy', [ &$text, $this ] );
@@ -984,9 +990,8 @@ abstract class Skin extends ContextSource {
                                $html = htmlspecialchars( $icon["alt"] );
                        }
                        if ( $url ) {
-                               global $wgExternalLinkTarget;
                                $html = Html::rawElement( 'a',
-                                       [ "href" => $url, "target" => $wgExternalLinkTarget ],
+                                       [ "href" => $url, "target" => $this->getConfig()->get( 'ExternalLinkTarget' ) ],
                                        $html );
                        }
                }
@@ -998,9 +1003,10 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function mainPageLink() {
-               $s = Linker::linkKnown(
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+               $s = $linkRenderer->makeKnownLink(
                        Title::newMainPage(),
-                       $this->msg( 'mainpage' )->escaped()
+                       $this->msg( 'mainpage' )->text()
                );
 
                return $s;
@@ -1014,13 +1020,14 @@ abstract class Skin extends ContextSource {
         */
        public function footerLink( $desc, $page ) {
                $title = $this->footerLinkTitle( $desc, $page );
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                if ( !$title ) {
                        return '';
                }
 
-               return Linker::linkKnown(
+               return $linkRenderer->makeKnownLink(
                        $title,
-                       $this->msg( $desc )->escaped()
+                       $this->msg( $desc )->text()
                );
        }
 
@@ -1113,14 +1120,12 @@ abstract class Skin extends ContextSource {
         * @throws MWException
         */
        function getSkinStylePath( $name ) {
-               global $wgStylePath;
-
                if ( $this->stylename === null ) {
                        $class = static::class;
                        throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
                }
 
-               return "$wgStylePath/{$this->stylename}/$name";
+               return $this->getConfig()->get( 'StylePath' ) . "/{$this->stylename}/$name";
        }
 
        /* these are used extensively in SkinTemplate, but also some other places */
@@ -1287,8 +1292,6 @@ abstract class Skin extends ContextSource {
         * @return array
         */
        public function buildSidebar() {
-               global $wgEnableSidebarCache, $wgSidebarCacheExpiry;
-
                $callback = function ( $old = null, &$ttl = null ) {
                        $bar = [];
                        $this->addToSidebar( $bar, 'sidebar' );
@@ -1302,11 +1305,12 @@ abstract class Skin extends ContextSource {
 
                $msgCache = MessageCache::singleton();
                $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+               $config = $this->getConfig();
 
-               $sidebar = $wgEnableSidebarCache
+               $sidebar = $config->get( 'EnableSidebarCache' )
                        ? $wanCache->getWithSetCallback(
                                $wanCache->makeKey( 'sidebar', $this->getLanguage()->getCode() ),
-                               $wgSidebarCacheExpiry,
+                               $config->get( 'SidebarCacheExpiry' ),
                                $callback,
                                [
                                        'checkKeys' => [
@@ -1349,7 +1353,8 @@ abstract class Skin extends ContextSource {
                $lines = explode( "\n", $text );
 
                $heading = '';
-               $messageTitle = $this->getConfig()->get( 'EnableSidebarCache' )
+               $config = $this->getConfig();
+               $messageTitle = $config->get( 'EnableSidebarCache' )
                        ? Title::newMainPage() : $this->getTitle();
 
                foreach ( $lines as $line ) {
@@ -1397,14 +1402,14 @@ abstract class Skin extends ContextSource {
                                                $href = $link;
 
                                                // Parser::getExternalLinkAttribs won't work here because of the Namespace things
-                                               global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
-                                               if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
+                                               if ( $config->get( 'NoFollowLinks' ) &&
+                                                       !wfMatchesDomainList( $href, $config->get( 'NoFollowDomainExceptions' ) )
+                                               ) {
                                                        $extraAttribs['rel'] = 'nofollow';
                                                }
 
-                                               global $wgExternalLinkTarget;
-                                               if ( $wgExternalLinkTarget ) {
-                                                       $extraAttribs['target'] = $wgExternalLinkTarget;
+                                               if ( $config->get( 'ExternalLinkTarget' ) ) {
+                                                       $extraAttribs['target'] = $config->get( 'ExternalLinkTarget' );
                                                }
                                        } else {
                                                $title = Title::newFromText( $link );
@@ -1442,6 +1447,7 @@ abstract class Skin extends ContextSource {
                $user = $this->getUser();
                $newtalks = $user->getNewMessageLinks();
                $out = $this->getOutput();
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 
                // Allow extensions to disable or modify the new messages alert
                if ( !Hooks::run( 'GetNewMessagesAlert', [ &$newMessagesAlert, $newtalks, $user, $out ] ) ) {
@@ -1472,16 +1478,16 @@ abstract class Skin extends ContextSource {
                        // 999 signifies "more than one revision". We don't know how many, and even if we did,
                        // the number of revisions or authors is not necessarily the same as the number of
                        // "messages".
-                       $newMessagesLink = Linker::linkKnown(
+                       $newMessagesLink = $linkRenderer->makeKnownLink(
                                $uTalkTitle,
-                               $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
+                               $this->msg( 'newmessageslinkplural' )->params( $plural )->text(),
                                [],
                                $uTalkTitle->isRedirect() ? [ 'redirect' => 'no' ] : []
                        );
 
-                       $newMessagesDiffLink = Linker::linkKnown(
+                       $newMessagesDiffLink = $linkRenderer->makeKnownLink(
                                $uTalkTitle,
-                               $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
+                               $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->text(),
                                [],
                                $lastSeenRev !== null
                                        ? [ 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' ]
@@ -1531,14 +1537,11 @@ abstract class Skin extends ContextSource {
         *   should fall back to the next notice in its sequence
         */
        private function getCachedNotice( $name ) {
-               global $wgRenderHashAppend;
-
-               $needParse = false;
+               $config = $this->getConfig();
 
                if ( $name === 'default' ) {
                        // special case
-                       global $wgSiteNotice;
-                       $notice = $wgSiteNotice;
+                       $notice = $config->get( 'SiteNotice' );
                        if ( empty( $notice ) ) {
                                return false;
                        }
@@ -1557,7 +1560,7 @@ abstract class Skin extends ContextSource {
                $parsed = $cache->getWithSetCallback(
                        // Use the extra hash appender to let eg SSL variants separately cache
                        // Key is verified with md5 hash of unparsed wikitext
-                       $cache->makeKey( $name, $wgRenderHashAppend, md5( $notice ) ),
+                       $cache->makeKey( $name, $config->get( 'RenderHashAppend' ), md5( $notice ) ),
                        // TTL in seconds
                        600,
                        function () use ( $notice ) {
@@ -1630,11 +1633,10 @@ abstract class Skin extends ContextSource {
 
                $links = [
                        'editsection' => [
-                               'text' => $this->msg( 'editsection' )->inLanguage( $lang )->escaped(),
+                               'text' => $this->msg( 'editsection' )->inLanguage( $lang )->text(),
                                'targetTitle' => $nt,
                                'attribs' => $attribs,
-                               'query' => [ 'action' => 'edit', 'section' => $section ],
-                               'options' => [ 'noclasses', 'known' ]
+                               'query' => [ 'action' => 'edit', 'section' => $section ]
                        ]
                ];
 
@@ -1642,14 +1644,14 @@ abstract class Skin extends ContextSource {
 
                $result = '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>';
 
+               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
                $linksHtml = [];
                foreach ( $links as $k => $linkDetails ) {
-                       $linksHtml[] = Linker::link(
+                       $linksHtml[] = $linkRenderer->makeKnownLink(
                                $linkDetails['targetTitle'],
                                $linkDetails['text'],
                                $linkDetails['attribs'],
-                               $linkDetails['query'],
-                               $linkDetails['options']
+                               $linkDetails['query']
                        );
                }