Followup r81583, break some of the long lines and centralize the regex.
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index 9e557ab..6d7057f 100644 (file)
@@ -132,7 +132,7 @@ class SkinTemplate extends Skin {
         * @param $out OutputPage
         */
        function outputPage( OutputPage $out ) {
-               global $wgArticle, $wgUser, $wgLang, $wgContLang;
+               global $wgUser, $wgLang, $wgContLang;
                global $wgScript, $wgStylePath, $wgLanguageCode;
                global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
                global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
@@ -201,6 +201,8 @@ class SkinTemplate extends Skin {
                        $tpl->setRef( 'usercss', $this->usercss );
 
                        $this->userjs = $this->userjsprev = false;
+                       # FIXME: this is the only use of OutputPage::isUserJsAllowed() anywhere; can we
+                       # get rid of it?  For that matter, why is any of this here at all?
                        $this->setupUserJs( $out->isUserJsAllowed() );
                        $tpl->setRef( 'userjs', $this->userjs );
                        $tpl->setRef( 'userjsprev', $this->userjsprev );
@@ -245,7 +247,7 @@ class SkinTemplate extends Skin {
                $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
                $tpl->set( 'titletext', $this->mTitle->getText() );
                $tpl->set( 'articleid', $this->mTitle->getArticleId() );
-               $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
+               $tpl->set( 'currevisionid', $this->mTitle->getLatestRevID() );
 
                $tpl->set( 'isarticle', $out->isArticle() );
 
@@ -345,9 +347,11 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'skin', $this );
                $tpl->set( 'logo', $this->logoText() );
                if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
-                       $wgArticle && 0 != $wgArticle->getID() ){
+                       $this->mTitle->exists() )
+               {
+                       $article = new Article( $this->mTitle, 0 );
                        if ( !$wgDisableCounters ) {
-                               $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
+                               $viewcount = $wgLang->formatNum( $article->getCount() );
                                if ( $viewcount ) {
                                        $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
                                } else {
@@ -383,9 +387,9 @@ class SkinTemplate extends Skin {
                        $this->credits = false;
 
                        if( $wgMaxCredits != 0 ){
-                               $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
+                               $this->credits = Credits::getCredits( $article, $wgMaxCredits, $wgShowCreditsIfMax );
                        } else {
-                               $tpl->set( 'lastmod', $this->lastModified() );
+                               $tpl->set( 'lastmod', $this->lastModified( $article ) );
                        }
 
                        $tpl->setRef( 'credits', $this->credits );
@@ -494,14 +498,14 @@ class SkinTemplate extends Skin {
 
                wfProfileIn( __METHOD__ . '-stuff5' );
                # Personal toolbar
-               $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
-               $content_navigation = $this->buildContentNavigationUrls();
+               $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
+               $content_navigation = $this->buildContentNavigationUrls( $out );
                $content_actions = $this->buildContentActionUrls( $content_navigation );
                $tpl->setRef( 'content_navigation', $content_navigation );
                $tpl->setRef( 'content_actions', $content_actions );
 
                $tpl->set( 'sidebar', $this->buildSidebar() );
-               $tpl->set( 'nav_urls', $this->buildNavUrls() );
+               $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
 
                // Set the head scripts near the end, in case the above actions resulted in added scripts
                if ( $this->useHeadElement ) {
@@ -558,12 +562,11 @@ class SkinTemplate extends Skin {
        /**
         * build array of urls for personal toolbar
         * @return array
-        * @private
         */
-       function buildPersonalUrls() {
-               global $wgOut, $wgRequest;
+       protected function buildPersonalUrls( OutputPage $out ) {
+               global $wgRequest;
 
-               $title = $wgOut->getTitle();
+               $title = $out->getTitle();
                $pageurl = $title->getLocalURL();
                wfProfileIn( __METHOD__ );
 
@@ -706,8 +709,16 @@ class SkinTemplate extends Skin {
                        $query = 'action=edit&redlink=1';
                }
 
-               $text = wfMsg( $message );
-               if ( wfEmptyMsg( $message, $text ) ) {
+               // wfMessageFallback will nicely accept $message as an array of fallbacks
+               // or just a single key
+               $msg = wfMessageFallback( $message );
+               if ( is_array($message) ) {
+                       // for hook compatibility just keep the last message name
+                       $message = end($message);
+               }
+               if ( $msg->exists() ) {
+                       $text = $msg->text();
+               } else {
                        global $wgContLang;
                        $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
                }
@@ -781,10 +792,9 @@ class SkinTemplate extends Skin {
         *                believes that the accesskey should not be added to the tab.
         * 
         * @return array
-        * @private
         */
-       function buildContentNavigationUrls() {
-               global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
+       protected function buildContentNavigationUrls( OutputPage $out ) {
+               global $wgContLang, $wgLang, $wgUser, $wgRequest;
                global $wgDisableLangConversion;
 
                wfProfileIn( __METHOD__ );
@@ -828,12 +838,16 @@ class SkinTemplate extends Skin {
                        }
 
                        // Adds namespace links
+                       $subjectMsg = array( "nstab-$subjectId" );
+                       if ( $subjectPage->isMainPage() ) {
+                               array_unshift($subjectMsg, 'mainpage-nstab');
+                       }
                        $content_navigation['namespaces'][$subjectId] = $this->tabAction(
-                               $subjectPage, 'nstab-' . $subjectId, !$isTalk && !$preventActiveTabs, '', $userCanRead
+                               $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
                        );
                        $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
                        $content_navigation['namespaces'][$talkId] = $this->tabAction(
-                               $talkPage, 'talk', $isTalk && !$preventActiveTabs, '', $userCanRead
+                               $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
                        );
                        $content_navigation['namespaces'][$talkId]['context'] = 'talk';
 
@@ -841,8 +855,8 @@ class SkinTemplate extends Skin {
                        if ( $title->exists() && $userCanRead ) {
                                $content_navigation['views']['view'] = $this->tabAction(
                                        $isTalk ? $talkPage : $subjectPage,
-                                       !wfEmptyMsg( "$skname-view-view" ) ? "$skname-view-view" : 'view',
-                                       ( $onPage && $action == 'view' ), '', true
+                                       array( "$skname-view-view", 'view' ),
+                                       ( $onPage && ($action == 'view' || $action == 'purge' ) ), '', true
                                );
                                $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
                        }
@@ -873,20 +887,20 @@ class SkinTemplate extends Skin {
                                        "edit" : "create";
                                $content_navigation['views']['edit'] = array(
                                        'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
-                                       'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->plain(),
+                                       'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
                                        'href' => $title->getLocalURL( $this->editUrlOptions() ),
                                        'primary' => true, // don't collapse this in vector
                                );
                                // Checks if this is a current rev of talk page and we should show a new
                                // section link
-                               if ( ( $isTalk && $wgArticle && $wgArticle->isCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
+                               if ( ( $isTalk && $this->isRevisionCurrent() ) || ( $out->showNewSectionLink() ) ) {
                                        // Checks if we should ever show a new section link
-                                       if ( !$wgOut->forceHideNewSectionLink() ) {
+                                       if ( !$out->forceHideNewSectionLink() ) {
                                                // Adds new section link
                                                //$content_navigation['actions']['addsection']
                                                $content_navigation['views']['addsection'] = array(
                                                        'class' => $section == 'new' ? 'selected' : false,
-                                                       'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->plain(),
+                                                       'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
                                                        'href' => $title->getLocalURL( 'action=edit&section=new' )
                                                );
                                        }
@@ -896,7 +910,7 @@ class SkinTemplate extends Skin {
                                // Adds view source view link
                                $content_navigation['views']['viewsource'] = array(
                                        'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
-                                       'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->plain(),
+                                       'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
                                        'href' => $title->getLocalURL( $this->editUrlOptions() ),
                                        'primary' => true, // don't collapse this in vector
                                );
@@ -910,7 +924,7 @@ class SkinTemplate extends Skin {
                                // Adds history view link
                                $content_navigation['views']['history'] = array(
                                        'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
-                                       'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->plain(),
+                                       'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
                                        'href' => $title->getLocalURL( 'action=history' ),
                                        'rel' => 'archives',
                                );
@@ -918,7 +932,7 @@ class SkinTemplate extends Skin {
                                if( $wgUser->isAllowed( 'delete' ) ) {
                                        $content_navigation['actions']['delete'] = array(
                                                'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->plain(),
+                                               'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
                                                'href' => $title->getLocalURL( 'action=delete' )
                                        );
                                }
@@ -926,7 +940,7 @@ class SkinTemplate extends Skin {
                                        $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
                                        $content_navigation['actions']['move'] = array(
                                                'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-move", 'move' )->plain(),
+                                               'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
                                                'href' => $moveTitle->getLocalURL()
                                        );
                                }
@@ -935,7 +949,7 @@ class SkinTemplate extends Skin {
                                        $mode = !$title->isProtected() ? 'protect' : 'unprotect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(),
+                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
                                                'href' => $title->getLocalURL( "action=$mode" )
                                        );
                                }
@@ -960,7 +974,7 @@ class SkinTemplate extends Skin {
                                        $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
-                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )->plain(),
+                                               'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
                                                'href' => $title->getLocalURL( "action=$mode" )
                                        );
                                }
@@ -1119,8 +1133,8 @@ class SkinTemplate extends Skin {
         * @return array
         * @private
         */
-       function buildNavUrls() {
-               global $wgUseTrackbacks, $wgOut, $wgUser, $wgRequest;
+       protected function buildNavUrls( OutputPage $out ) {
+               global $wgUseTrackbacks, $wgUser, $wgRequest;
                global $wgUploadNavigationUrl;
 
                wfProfileIn( __METHOD__ );
@@ -1144,7 +1158,7 @@ class SkinTemplate extends Skin {
                // A print stylesheet is attached to all pages, but nobody ever
                // figures that out. :)  Add a link...
                if( $this->iscontent && ( $action == 'view' || $action == 'purge' ) ) {
-                       if ( !$wgOut->isPrintable() ) {
+                       if ( !$out->isPrintable() ) {
                                $nav_urls['print'] = array(
                                        'text' => wfMsg( 'printableversion' ),
                                        'href' => $wgRequest->appendQuery( 'printable=yes' )
@@ -1155,7 +1169,7 @@ class SkinTemplate extends Skin {
                        if ( $this->mRevisionId ) {
                                $nav_urls['permalink'] = array(
                                        'text' => wfMsg( 'permalink' ),
-                                       'href' => $wgOut->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
+                                       'href' => $out->getTitle()->getLocalURL( "oldid=$this->mRevisionId" )
                                );
                        }
 
@@ -1179,7 +1193,7 @@ class SkinTemplate extends Skin {
                        }
                        if( $wgUseTrackbacks )
                                $nav_urls['trackbacklink'] = array(
-                                       'href' => $wgOut->getTitle()->trackbackURL()
+                                       'href' => $out->getTitle()->trackbackURL()
                                );
                }
 
@@ -1243,6 +1257,7 @@ class SkinTemplate extends Skin {
 
        /**
         * @private
+        * FIXME: why is this duplicated in/from OutputPage::getHeadScripts()??
         */
        function setupUserJs( $allowUserJs ) {
                global $wgRequest, $wgJsMimeType;
@@ -1715,7 +1730,6 @@ abstract class BaseTemplate extends QuickTemplate {
                                }
                        }
                } elseif ( $option == 'nocopyright' ) {
-                       $footericons = $this->data['footericons'];
                        unset( $footericons['copyright']['copyright'] );
                        if ( count( $footericons['copyright'] ) <= 0 ) {
                                unset( $footericons['copyright'] );