Revert "merged master"
[lhc/web/wiklou.git] / includes / Skin.php
index 56355bb..3db4cf9 100644 (file)
@@ -72,7 +72,7 @@ abstract class Skin extends ContextSource {
                }
                return $wgValidSkinNames;
        }
+
        /**
         * Fetch the skinname messages for available skins.
         * @return array of strings
@@ -326,7 +326,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * Make a <script> tag containing global variables
+        * Make a "<script>" tag containing global variables
         *
         * @deprecated in 1.19
         * @param $unused
@@ -363,7 +363,7 @@ abstract class Skin extends ContextSource {
         * inside ->getOutput() is deprecated. The $out arg is kept
         * for compatibility purposes with skins.
         * @param $out OutputPage
-        * @delete
+        * @todo delete
         */
        abstract function setupSkinUserCss( OutputPage $out );
 
@@ -397,7 +397,7 @@ abstract class Skin extends ContextSource {
 
        /**
         * This will be called by OutputPage::headElement when it is creating the
-        * <body> tag, skins can override it if they have a need to add in any
+        * "<body>" tag, skins can override it if they have a need to add in any
         * body attributes or classes of their own.
         * @param $out OutputPage
         * @param $bodyAttrs Array
@@ -636,9 +636,9 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * This gets called shortly before the </body> tag.
+        * This gets called shortly before the "</body>" tag.
         *
-        * @return String HTML-wrapped JS code to be put before </body>
+        * @return String HTML-wrapped JS code to be put before "</body>"
         */
        function bottomScripts() {
                // TODO and the suckage continues. This function is really just a wrapper around
@@ -722,7 +722,7 @@ abstract class Skin extends ContextSource {
                                        $display .= $link;
                                        $linkObj = Title::newFromText( $growinglink );
 
-                                       if ( is_object( $linkObj ) && $linkObj->exists() ) {
+                                       if ( is_object( $linkObj ) && $linkObj->isKnown() ) {
                                                $getlink = Linker::linkKnown(
                                                        $linkObj,
                                                        htmlspecialchars( $display )
@@ -1067,13 +1067,23 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name string
-        * @param $urlaction string
+        * Make a URL for a Special Page using the given query and protocol.
+        *
+        * If $proto is set to null, make a local URL. Otherwise, make a full
+        * URL with the protocol specified.
+        *
+        * @param $name string Name of the Special page
+        * @param $urlaction string Query to append
+        * @param $proto Protocol to use or null for a local URL
         * @return String
         */
-       static function makeSpecialUrl( $name, $urlaction = '' ) {
+       static function makeSpecialUrl( $name, $urlaction = '', $proto = null ) {
                $title = SpecialPage::getSafeTitleFor( $name );
-               return $title->getLocalURL( $urlaction );
+               if( is_null( $proto ) ) {
+                       return $title->getLocalURL( $urlaction );
+               } else {
+                       return $title->getFullURL( $urlaction, false, $proto );
+               }
        }
 
        /**
@@ -1342,29 +1352,58 @@ abstract class Skin extends ContextSource {
                $ntl = '';
 
                if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
-                       $userTitle = $this->getUser()->getUserPage();
-                       $userTalkTitle = $userTitle->getTalkPage();
+                       $userTalkTitle = $this->getUser()->getTalkPage();
 
                        if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
+                               $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
+                               $nofAuthors = 0;
+                               if ( $lastSeenRev !== null ) {
+                                       $plural = true; // Default if we have a last seen revision: if unknown, use plural
+                                       $latestRev = Revision::newFromTitle ($userTalkTitle);
+                                       if ( $latestRev !== null ) {
+                                               // Singular if only 1 unseen revision, plural if several unseen revisions.\r
+                                               $plural = $latestRev->getParentId() !== $lastSeenRev->getId();\r
+                                               $nofAuthors = $userTalkTitle->countAuthorsBetween( $lastSeenRev, $latestRev, 10, 'include_new' );
+                                       }
+                               } else {
+                                       // Singular if no revision -> diff link will show latest change only in any case
+                                       $plural = false;
+                               }
+                               $plural = $plural ? 2 : 1;
+                               // 2 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(
                                        $userTalkTitle,
-                                       $this->msg( 'newmessageslink' )->escaped(),
+                                       $this->msg( 'newmessageslinkplural' )->params( $plural )->escaped(),
                                        array(),
                                        array( 'redirect' => 'no' )
                                );
 
                                $newMessagesDiffLink = Linker::linkKnown(
                                        $userTalkTitle,
-                                       $this->msg( 'newmessagesdifflink' )->escaped(),
+                                       $this->msg( 'newmessagesdifflinkplural' )->params( $plural )->escaped(),
                                        array(),
-                                       array( 'diff' => 'cur' )
+                                       $lastSeenRev !== null
+                                               ? array( 'oldid' => $lastSeenRev->getId(), 'diff' => 'cur' )
+                                               : array( 'diff' => 'cur' )
                                );
 
-                               $ntl = $this->msg(
-                                       'youhavenewmessages',
-                                       $newMessagesLink,
-                                       $newMessagesDiffLink
-                               )->text();
+                               if ( $nofAuthors >= 1 && $nofAuthors <= 10 ) {
+                                       $ntl = $this->msg(
+                                               'youhavenewmessagesfromusers',
+                                               $newMessagesLink,
+                                               $newMessagesDiffLink
+                                       )->numParams( $nofAuthors );
+                               } else {
+                                       // $nofAuthors === 11 signifies "11 or more" ("more than 10")
+                                       $ntl = $this->msg(
+                                               $nofAuthors > 10 ? 'youhavenewmessagesmanyusers' : 'youhavenewmessages',
+                                               $newMessagesLink,
+                                               $newMessagesDiffLink
+                                       );
+                               }
+                               $ntl = $ntl->text();
                                # Disable Squid cache
                                $out->setSquidMaxage( 0 );
                        }