Merge "Fix documentation of Maintenance::updateSearchIndex"
[lhc/web/wiklou.git] / includes / skins / SkinTemplate.php
index b44d409..a7b7569 100644 (file)
@@ -171,6 +171,9 @@ class SkinTemplate extends Skin {
                return $languageLinks;
        }
 
+       /**
+        * @return QuickTemplate
+        */
        protected function setupTemplateForOutput() {
                $request = $this->getRequest();
                $user = $this->getUser();
@@ -385,16 +388,21 @@ class SkinTemplate extends Skin {
                $tpl->set( 'lastmod', false );
                $tpl->set( 'credits', false );
                $tpl->set( 'numberofwatchingusers', false );
-               if ( $out->isArticle() && $title->exists() ) {
-                       if ( $this->isRevisionCurrent() ) {
+               if ( $title->exists() ) {
+                       if ( $out->isArticle() && $this->isRevisionCurrent() ) {
                                if ( $wgMaxCredits != 0 ) {
-                                       $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
-                                               $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
+                                       /** @var CreditsAction $action */
+                                       $action = Action::factory(
+                                               'credits', $this->getWikiPage(), $this->getContext() );
+                                       $tpl->set( 'credits',
+                                               $action->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
                                } else {
                                        $tpl->set( 'lastmod', $this->lastModified() );
                                }
                        }
-                       $tpl->set( 'copyright', $this->getCopyright() );
+                       if ( $out->showsCopyright() ) {
+                               $tpl->set( 'copyright', $this->getCopyright() );
+                       }
                }
 
                $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
@@ -522,7 +530,9 @@ class SkinTemplate extends Skin {
                $html = '';
 
                if ( $personalTools === null ) {
-                       $personalTools = $tpl->getPersonalTools();
+                       $personalTools = ( $tpl instanceof BaseTemplate )
+                               ? $tpl->getPersonalTools()
+                               : [];
                }
 
                foreach ( $personalTools as $key => $item ) {
@@ -543,7 +553,7 @@ class SkinTemplate extends Skin {
                $tpl = $this->setupTemplateForOutput();
                $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
 
-               return $tpl->getPersonalTools();
+               return ( $tpl instanceof BaseTemplate ) ? $tpl->getPersonalTools() : [];
        }
 
        /**
@@ -607,16 +617,17 @@ class SkinTemplate extends Skin {
                        $page = Title::newFromText( $request->getVal( 'title', '' ) );
                }
                $page = $request->getVal( 'returnto', $page );
-               $a = [];
+               $returnto = [];
                if ( strval( $page ) !== '' ) {
-                       $a['returnto'] = $page;
+                       $returnto['returnto'] = $page;
                        $query = $request->getVal( 'returntoquery', $this->thisquery );
+                       $paramsArray = wfCgiToArray( $query );
+                       $query = wfArrayToCgi( $paramsArray );
                        if ( $query != '' ) {
-                               $a['returntoquery'] = $query;
+                               $returnto['returntoquery'] = $query;
                        }
                }
 
-               $returnto = wfArrayToCgi( $a );
                if ( $this->loggedin ) {
                        $personal_urls['userpage'] = [
                                'text' => $this->username,
@@ -681,9 +692,9 @@ class SkinTemplate extends Skin {
                                $personal_urls['logout'] = [
                                        'text' => $this->msg( 'pt-userlogout' )->text(),
                                        'href' => self::makeSpecialUrl( 'Userlogout',
-                                               // userlogout link must always contain an & character, otherwise we might not be able
+                                               // Note: userlogout link must always contain an & character, otherwise we might not be able
                                                // to detect a buggy precaching proxy (T19790)
-                                               $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto ),
+                                               ( $title->isSpecial( 'Preferences' ) ? [] : $returnto ) ),
                                        'active' => false
                                ];
                        }
@@ -777,7 +788,8 @@ class SkinTemplate extends Skin {
                        }
                }
 
-               $linkClass = MediaWikiServices::getInstance()->getLinkRenderer()->getLinkClasses( $title );
+               $services = MediaWikiServices::getInstance();
+               $linkClass = $services->getLinkRenderer()->getLinkClasses( $title );
 
                // wfMessageFallback will nicely accept $message as an array of fallbacks
                // or just a single key
@@ -789,8 +801,9 @@ class SkinTemplate extends Skin {
                if ( $msg->exists() ) {
                        $text = $msg->text();
                } else {
-                       $text = MediaWikiServices::getInstance()->getContentLanguage()->getConverter()->
-                               convertNamespace( MWNamespace::getSubject( $title->getNamespace() ) );
+                       $text = $services->getContentLanguage()->getConverter()->
+                               convertNamespace( $services->getNamespaceInfo()->
+                                       getSubject( $title->getNamespace() ) );
                }
 
                // Avoid PHP 7.1 warning of passing $this by reference
@@ -1055,13 +1068,13 @@ class SkinTemplate extends Skin {
                                        }
                                } else {
                                        // article doesn't exist or is deleted
-                                       if ( $user->isAllowed( 'deletedhistory' ) ) {
+                                       if ( $title->quickUserCan( 'deletedhistory', $user ) ) {
                                                $n = $title->isDeleted();
                                                if ( $n ) {
                                                        $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
                                                        // If the user can't undelete but can view deleted
                                                        // history show them a "View .. deleted" tab instead.
-                                                       $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
+                                                       $msgKey = $title->quickUserCan( 'undelete', $user ) ? 'undelete' : 'viewdeleted';
                                                        $content_navigation['actions']['undelete'] = [
                                                                'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
                                                                'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
@@ -1073,7 +1086,8 @@ class SkinTemplate extends Skin {
                                }
 
                                if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
-                                       MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
+                                       MediaWikiServices::getInstance()->getNamespaceInfo()->
+                                               getRestrictionLevels( $title->getNamespace(), $user ) !== [ '' ]
                                ) {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = [