Merge "jquery.makeCollapsible: Support for .mw-collapsible-toggle inside <li>"
[lhc/web/wiklou.git] / includes / skins / SkinTemplate.php
index 419c4b4..b4be461 100644 (file)
@@ -17,6 +17,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Base class for template-based skins.
@@ -45,6 +46,14 @@ class SkinTemplate extends Skin {
         */
        public $template = 'QuickTemplate';
 
+       public $thispage;
+       public $titletxt;
+       public $userpage;
+       public $thisquery;
+       public $loggedin;
+       public $username;
+       public $userpageUrlDetails;
+
        /**
         * Add specific styles for this skin
         *
@@ -252,6 +261,7 @@ class SkinTemplate extends Skin {
         * Wrap the body text with language information and identifiable element
         *
         * @param Title $title
+        * @param string $html body text
         * @return string html
         */
        protected function wrapHTML( $title, $html ) {
@@ -446,7 +456,6 @@ class SkinTemplate extends Skin {
                $tpl->set( 'indicators', $out->getIndicators() );
 
                $tpl->set( 'sitenotice', $this->getSiteNotice() );
-               $tpl->set( 'bottomscripts', $this->bottomScripts() );
                $tpl->set( 'printfooter', $this->printSource() );
                // Wrap the bodyText with #mw-content-text element
                $out->mBodytext = $this->wrapHTML( $title, $out->mBodytext );
@@ -469,6 +478,9 @@ class SkinTemplate extends Skin {
                $tpl->set( 'sidebar', $this->buildSidebar() );
                $tpl->set( 'nav_urls', $this->buildNavUrls() );
 
+               // Do this last in case hooks above add bottom scripts
+               $tpl->set( 'bottomscripts', $this->bottomScripts() );
+
                // Set the head scripts near the end, in case the above actions resulted in added scripts
                $tpl->set( 'headelement', $out->headElement( $this ) );
 
@@ -650,33 +662,36 @@ class SkinTemplate extends Skin {
                                'active' => false
                        ];
                } else {
-                       // No need to show Talk and Contributions to anons if they can't contribute!
-                       if ( User::groupHasPermission( '*', 'edit' ) ) {
+                       $useCombinedLoginLink = $this->useCombinedLoginLink();
+                       $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
+                               ? 'nav-login-createaccount'
+                               : 'pt-login';
 
-                               // Because of caching, we can't link directly to the anonymous
-                               // user page (for example [[User:127.0.0.1]]), talk page, and
-                               // contributions pages. Instead we use the special page
-                               // shortcuts (which work correctly regardless of caching). This
-                               // means we can't determine whether these links are active or
-                               // not, but since major skins (MonoBook, Vector) don't use this
-                               // information, it's not a huge loss.
-
-                               // Only show (red) link to anon user page if anon users are
-                               // allowed to create that page
-                               if ( User::groupHasPermission( '*', 'createpage' ) ) {
-                                       $personal_urls[ 'anonuserpage' ] = [
-                                               'text'   => $this->msg( 'anonuserpage' )->text(),
-                                               'href'   => self::makeSpecialUrlSubpage( 'Mypage', false ),
-                                               'active' => false
-                                       ];
-                               }
+                       $login_url = [
+                               'text' => $this->msg( $loginlink )->text(),
+                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
+                               'active' => $title->isSpecial( 'Userlogin' )
+                                       || $title->isSpecial( 'CreateAccount' ) && $useCombinedLoginLink,
+                       ];
+                       $createaccount_url = [
+                               'text' => $this->msg( 'pt-createaccount' )->text(),
+                               'href' => self::makeSpecialUrl( 'CreateAccount', $returnto ),
+                               'active' => $title->isSpecial( 'CreateAccount' ),
+                       ];
 
+                       // No need to show Talk and Contributions to anons if they can't contribute!
+                       if ( User::groupHasPermission( '*', 'edit' ) ) {
+                               // Because of caching, we can't link directly to the IP talk and
+                               // contributions pages. Instead we use the special page shortcuts
+                               // (which work correctly regardless of caching). This means we can't
+                               // determine whether these links are active or not, but since major
+                               // skins (MonoBook, Vector) don't use this information, it's not a
+                               // huge loss.
                                $personal_urls['anontalk'] = [
                                        'text' => $this->msg( 'anontalk' )->text(),
                                        'href' => self::makeSpecialUrlSubpage( 'Mytalk', false ),
                                        'active' => false
                                ];
-
                                $personal_urls['anoncontribs'] = [
                                        'text' => $this->msg( 'anoncontribs' )->text(),
                                        'href' => self::makeSpecialUrlSubpage( 'Mycontributions', false ),
@@ -684,21 +699,11 @@ class SkinTemplate extends Skin {
                                ];
                        }
 
-                       $is_signup = $request->getText( 'type' ) === 'signup';
-
-                       if ( $this->getUser()->isAllowed( 'createaccount' ) && !( $this->useCombinedLoginLink() ) ) {
-                               $personal_urls[ 'createaccount' ] = [
-                                       'text' => $this->msg( 'pt-createaccount' )->text(),
-                                       'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
-                                       'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
-                               ];
+                       if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
+                               $personal_urls['createaccount'] = $createaccount_url;
                        }
 
-                       $personal_urls['login'] = [
-                               'text' => $this->msg( 'pt-login' )->text(),
-                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
-                               'active' => $title->isSpecial( 'Userlogin' ) && !$is_signup,
-                       ];
+                       $personal_urls['login'] = $login_url;
                }
 
                Hooks::run( 'PersonalUrls', [ &$personal_urls, &$title, $this ] );
@@ -730,6 +735,8 @@ class SkinTemplate extends Skin {
                        }
                }
 
+               $linkClass = MediaWikiServices::getInstance()->getLinkRenderer()->getLinkClasses( $title );
+
                // wfMessageFallback will nicely accept $message as an array of fallbacks
                // or just a single key
                $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
@@ -752,11 +759,16 @@ class SkinTemplate extends Skin {
                        return $result;
                }
 
-               return [
+               $result = [
                        'class' => implode( ' ', $classes ),
                        'text' => $text,
                        'href' => $title->getLocalURL( $query ),
                        'primary' => true ];
+               if ( $linkClass !== '' ) {
+                       $result['link-class'] = $linkClass;
+               }
+
+               return $result;
        }
 
        function makeTalkUrlDetails( $name, $urlaction = '' ) {