Removing exception in case rev is null
[lhc/web/wiklou.git] / includes / User.php
index 5a525bf..d114b99 100644 (file)
@@ -1807,8 +1807,11 @@ class User {
        }
 
        /**
-        * Return the talk page(s) this user has new messages on.
-        * @return Array of String page URLs
+        * Return the revision and link for the oldest new talk page message for
+        * this user.
+        * Note: This function was designed to accomodate multiple talk pages, but
+        * currently only returns a single link and revision.
+        * @return Array
         */
        public function getNewMessageLinks() {
                $talks = array();
@@ -1828,6 +1831,28 @@ class User {
                return array( array( 'wiki' => wfWikiID(), 'link' => $utp->getLocalURL(), 'rev' => $rev ) );
        }
 
+       /**
+        * Get the revision ID for the oldest new talk page message for this user
+        * @return Integer or null if there are no new messages
+        */
+       public function getNewMessageRevisionId() {
+               $newMessageRevisionId = null;
+               $newMessageLinks = $this->getNewMessageLinks();
+               if ( $newMessageLinks ) {
+                       // Note: getNewMessageLinks() never returns more than a single link
+                       // and it is always for the same wiki, but we double-check here in
+                       // case that changes some time in the future.
+                       if ( count( $newMessageLinks ) === 1
+                               && $newMessageLinks[0]['wiki'] === wfWikiID()
+                               && $newMessageLinks[0]['rev']
+                       ) {
+                               $newMessageRevision = $newMessageLinks[0]['rev'];
+                               $newMessageRevisionId = $newMessageRevision->getId();
+                       }
+               }
+               return $newMessageRevisionId;
+       }
+
        /**
         * Internal uncached check for new messages
         *