Add tests for SkinTemplate::setupSkinUserCss
[lhc/web/wiklou.git] / includes / skins / SkinTemplate.php
index 9c5600d..578d418 100644 (file)
@@ -61,7 +61,7 @@ class SkinTemplate extends Skin {
         *
         * @param OutputPage $out
         */
-       function setupSkinUserCss( OutputPage $out ) {
+       public function setupSkinUserCss( OutputPage $out ) {
                $moduleStyles = [
                        'mediawiki.legacy.shared',
                        'mediawiki.legacy.commonPrint',
@@ -489,8 +489,10 @@ class SkinTemplate extends Skin {
                $tpl->set( 'debughtml', $this->generateDebugHTML() );
                $tpl->set( 'reporttime', wfReportTime() );
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $skinTemplate = $this;
                // original version by hansm
-               if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', [ &$this, &$tpl ] ) ) {
+               if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', [ &$skinTemplate, &$tpl ] ) ) {
                        wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
                }
 
@@ -768,8 +770,10 @@ class SkinTemplate extends Skin {
                                MWNamespace::getSubject( $title->getNamespace() ) );
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $skinTemplate = $this;
                $result = [];
-               if ( !Hooks::run( 'SkinTemplateTabAction', [ &$this,
+               if ( !Hooks::run( 'SkinTemplateTabAction', [ &$skinTemplate,
                                $title, $message, $selected, $checkEdit,
                                &$classes, &$query, &$text, &$result ] ) ) {
                        return $result;
@@ -870,8 +874,10 @@ class SkinTemplate extends Skin {
 
                $userCanRead = $title->quickUserCan( 'read', $user );
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $skinTemplate = $this;
                $preventActiveTabs = false;
-               Hooks::run( 'SkinTemplatePreventOtherActiveTabs', [ &$this, &$preventActiveTabs ] );
+               Hooks::run( 'SkinTemplatePreventOtherActiveTabs', [ &$skinTemplate, &$preventActiveTabs ] );
 
                // Checks if page is some kind of content
                if ( $title->canExist() ) {
@@ -919,19 +925,18 @@ class SkinTemplate extends Skin {
                                        $content_navigation['views']['view']['redundant'] = true;
                                }
 
-                               $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
-                                       $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
+                               $page = $this->canUseWikiPage() ? $this->getWikiPage() : false;
+                               $isRemoteContent = $page && !$page->isLocal();
 
                                // If it is a non-local file, show a link to the file in its own repository
                                // @todo abstract this for remote content that isn't a file
-                               if ( $isForeignFile ) {
-                                       $file = $this->getWikiPage()->getFile();
+                               if ( $isRemoteContent ) {
                                        $content_navigation['views']['view-foreign'] = [
                                                'class' => '',
                                                'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
                                                        setContext( $this->getContext() )->
-                                                       params( $file->getRepo()->getDisplayName() )->text(),
-                                               'href' => $file->getDescriptionUrl(),
+                                                       params( $page->getWikiDisplayName() )->text(),
+                                               'href' => $page->getSourceURL(),
                                                'primary' => false,
                                        ];
                                }
@@ -955,9 +960,9 @@ class SkinTemplate extends Skin {
                                                        && $title->getDefaultMessageText() !== false
                                                )
                                        ) {
-                                               $msgKey = $isForeignFile ? 'edit-local' : 'edit';
+                                               $msgKey = $isRemoteContent ? 'edit-local' : 'edit';
                                        } else {
-                                               $msgKey = $isForeignFile ? 'create-local' : 'create';
+                                               $msgKey = $isRemoteContent ? 'create-local' : 'create';
                                        }
                                        $content_navigation['views']['edit'] = [
                                                'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
@@ -967,7 +972,7 @@ class SkinTemplate extends Skin {
                                                'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
                                                        ->setContext( $this->getContext() )->text(),
                                                'href' => $title->getLocalURL( $this->editUrlOptions() ),
-                                               'primary' => !$isForeignFile, // don't collapse this in vector
+                                               'primary' => !$isRemoteContent, // don't collapse this in vector
                                        ];
 
                                        // section link
@@ -1075,7 +1080,9 @@ class SkinTemplate extends Skin {
                                }
                        }
 
-                       Hooks::run( 'SkinTemplateNavigation', [ &$this, &$content_navigation ] );
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $skinTemplate = $this;
+                       Hooks::run( 'SkinTemplateNavigation', [ &$skinTemplate, &$content_navigation ] );
 
                        if ( $userCanRead && !$wgDisableLangConversion ) {
                                $pageLang = $title->getPageLanguage();
@@ -1117,12 +1124,16 @@ class SkinTemplate extends Skin {
                                'context' => 'subject'
                        ];
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $skinTemplate = $this;
                        Hooks::run( 'SkinTemplateNavigation::SpecialPage',
-                               [ &$this, &$content_navigation ] );
+                               [ &$skinTemplate, &$content_navigation ] );
                }
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $skinTemplate = $this;
                // Equiv to SkinTemplateContentActions
-               Hooks::run( 'SkinTemplateNavigation::Universal', [ &$this, &$content_navigation ] );
+               Hooks::run( 'SkinTemplateNavigation::Universal', [ &$skinTemplate, &$content_navigation ] );
 
                // Setup xml ids and tooltip info
                foreach ( $content_navigation as $section => &$links ) {
@@ -1255,9 +1266,11 @@ class SkinTemplate extends Skin {
                                ];
                        }
 
+                       // Avoid PHP 7.1 warning of passing $this by reference
+                       $skinTemplate = $this;
                        // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
                        Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
-                               [ &$this, &$nav_urls, &$revid, &$revid ] );
+                               [ &$skinTemplate, &$nav_urls, &$revid, &$revid ] );
                }
 
                if ( $out->isArticleRelated() ) {
@@ -1309,12 +1322,14 @@ class SkinTemplate extends Skin {
                        if ( !$user->isAnon() ) {
                                $sur = new UserrightsPage;
                                $sur->setContext( $this->getContext() );
-                               if ( $sur->userCanExecute( $this->getUser() ) ) {
-                                       $nav_urls['userrights'] = [
-                                               'text' => $this->msg( 'tool-link-userrights', $this->getUser()->getName() )->text(),
-                                               'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
-                                       ];
-                               }
+                               $canChange = $sur->userCanChangeRights( $this->getUser(), false );
+                               $nav_urls['userrights'] = [
+                                       'text' => $this->msg(
+                                               $canChange ? 'tool-link-userrights' : 'tool-link-userrights-readonly',
+                                               $this->getUser()->getName()
+                                       )->text(),
+                                       'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
+                               ];
                        }
                }