move newtalk stuff from SkinTemplate to its own function in Skin
authorJack Phoenix <ashley@users.mediawiki.org>
Tue, 23 Mar 2010 16:11:37 +0000 (16:11 +0000)
committerJack Phoenix <ashley@users.mediawiki.org>
Tue, 23 Mar 2010 16:11:37 +0000 (16:11 +0000)
includes/Skin.php
includes/SkinTemplate.php

index 3244573..5c49a1a 100644 (file)
@@ -2181,4 +2181,61 @@ CSS;
        public function commonPrintStylesheet() {
                return true;
        }
+
+       /**
+        * Gets new talk page messages for the current user.
+        * @return MediaWiki message or if no new talk page messages, nothing
+        */
+       function getNewtalks() {
+               global $wgUser, $wgOut;
+               $newtalks = $wgUser->getNewMessageLinks();
+
+               if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
+                       $userTitle = $this->mUser->getUserPage();
+                       $userTalkTitle = $userTitle->getTalkPage();
+
+                       if( !$userTalkTitle->equals( $this->mTitle ) ) {
+                               $newMessagesLink = $this->link(
+                                       $userTalkTitle,
+                                       wfMsgHtml( 'newmessageslink' ),
+                                       array(),
+                                       array( 'redirect' => 'no' ),
+                                       array( 'known', 'noclasses' )
+                               );
+
+                               $newMessagesDiffLink = $this->link(
+                                       $userTalkTitle,
+                                       wfMsgHtml( 'newmessagesdifflink' ),
+                                       array(),
+                                       array( 'diff' => 'cur' ),
+                                       array( 'known', 'noclasses' )
+                               );
+
+                               $ntl = wfMsg(
+                                       'youhavenewmessages',
+                                       $newMessagesLink,
+                                       $newMessagesDiffLink
+                               );
+                               # Disable Squid cache
+                               $wgOut->setSquidMaxage( 0 );
+                       }
+               } elseif( count( $newtalks ) ) {
+                       // _>" " for BC <= 1.16
+                       $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
+                       $msgs = array();
+                       foreach( $newtalks as $newtalk ) {
+                               $msgs[] = Xml::element(
+                                       'a',
+                                       array( 'href' => $newtalk['link'] ), $newtalk['wiki']
+                               );
+                       }
+                       $parts = implode( $sep, $msgs );
+                       $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
+                       $wgOut->setSquidMaxage( 0 );
+               } else {
+                       $ntl = '';
+               }
+               return $ntl;
+       }
+
 }
index 9b4a287..7d45881 100644 (file)
@@ -311,8 +311,8 @@ class SkinTemplate extends Skin {
                // Users can have their language set differently than the
                // content of the wiki. For these users, tell the web browser
                // that interface elements are in a different language.
-               $tpl->set( 'userlangattributes', '');
-               $tpl->set( 'specialpageattributes', '');
+               $tpl->set( 'userlangattributes', '' );
+               $tpl->set( 'specialpageattributes', '' );
 
                $lang = $wgLang->getCode();
                $dir  = $wgLang->getDir();
@@ -323,60 +323,17 @@ class SkinTemplate extends Skin {
 
                        // The content of SpecialPages should be presented in the
                        // user's language. Content of regular pages should not be touched.
-                       if($this->mTitle->isSpecialPage()) {
+                       if( $this->mTitle->isSpecialPage() ) {
                                $tpl->set( 'specialpageattributes', $attrs );
                        }
                }
 
-               $newtalks = $wgUser->getNewMessageLinks();
+               $newtalks = $this->getNewtalks();
 
-               if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
-                       $usertitle = $this->mUser->getUserPage();
-                       $usertalktitle = $usertitle->getTalkPage();
-
-                       if( !$usertalktitle->equals( $this->mTitle ) ) {
-                               $newmessageslink = $this->link(
-                                       $usertalktitle,
-                                       wfMsgHtml( 'newmessageslink' ),
-                                       array(),
-                                       array( 'redirect' => 'no' ),
-                                       array( 'known', 'noclasses' )
-                               );
-
-                               $newmessagesdifflink = $this->link(
-                                       $usertalktitle,
-                                       wfMsgHtml( 'newmessagesdifflink' ),
-                                       array(),
-                                       array( 'diff' => 'cur' ),
-                                       array( 'known', 'noclasses' )
-                               );
-
-                               $ntl = wfMsg(
-                                       'youhavenewmessages',
-                                       $newmessageslink,
-                                       $newmessagesdifflink
-                               );
-                               # Disable Cache
-                               $out->setSquidMaxage( 0 );
-                       }
-               } else if( count( $newtalks ) ) {
-                       // _>" " for BC <= 1.16
-                       $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
-                       $msgs = array();
-                       foreach( $newtalks as $newtalk ) {
-                               $msgs[] = Xml::element('a',
-                                       array( 'href' => $newtalk['link'] ), $newtalk['wiki'] );
-                       }
-                       $parts = implode( $sep, $msgs );
-                       $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
-                       $out->setSquidMaxage( 0 );
-               } else {
-                       $ntl = '';
-               }
                wfProfileOut( __METHOD__ . '-stuff2' );
 
                wfProfileIn( __METHOD__ . '-stuff3' );
-               $tpl->setRef( 'newtalk', $ntl );
+               $tpl->setRef( 'newtalk', $newtalks );
                $tpl->setRef( 'skin', $this );
                $tpl->set( 'logo', $this->logoText() );
                if ( $out->isArticle() and ( !isset( $oldid ) or isset( $diff ) ) and