(bug 19591) Move setBigSelects() to DatabaseMysql
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index a08d2fb..3c48582 100644 (file)
@@ -112,7 +112,7 @@ class SkinTemplate extends Skin {
                $out->addStyle( 'common/shared.css', 'screen' );
                $out->addStyle( 'common/commonPrint.css', 'print' );    
        }
-
+       
        /**
         * Create the template engine object; we feed it a bunch of data
         * and eventually it spits out some HTML. Should have interface
@@ -270,6 +270,7 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'lang', $wgContLanguageCode );
                $tpl->set( 'dir', $wgContLang->isRTL() ? 'rtl' : 'ltr' );
                $tpl->set( 'rtl', $wgContLang->isRTL() );
+               $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
                $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
                $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
                $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
@@ -290,23 +291,34 @@ class SkinTemplate extends Skin {
                } else {
                        $tpl->set( 'jsvarurl', false );
                }
+
                $newtalks = $wgUser->getNewMessageLinks();
 
                if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
                        $usertitle = $this->mUser->getUserPage();
                        $usertalktitle = $usertitle->getTalkPage();
+
                        if( !$usertalktitle->equals( $this->mTitle ) ) {
-                               $ntl = wfMsg( 'youhavenewmessages',
-                                       $this->makeKnownLinkObj(
-                                               $usertalktitle,
-                                               wfMsgHtml( 'newmessageslink' ),
-                                               'redirect=no'
-                                       ),
-                                       $this->makeKnownLinkObj(
-                                               $usertalktitle,
-                                               wfMsgHtml( 'newmessagesdifflink' ),
-                                               'diff=cur'
-                                       )
+                               $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 );
@@ -651,7 +663,7 @@ class SkinTemplate extends Skin {
         * @private
         */
        function buildContentActionUrls() {
-               global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest;
+               global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
 
                wfProfileIn( __METHOD__ );
 
@@ -694,15 +706,16 @@ class SkinTemplate extends Skin {
                                        'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
                                );
 
-                               if ( $istalk || $wgOut->showNewSectionLink() ) {
+                               // adds new section link if page is a current revision of a talk page or 
+                               if ( ( $wgArticle && $wgArticle->isCurrent() && $istalk ) || $wgOut->showNewSectionLink() ) {
                                        if ( !$wgOut->forceHideNewSectionLink() ) {
                                                $content_actions['addsection'] = array(
                                                        'class' => $section == 'new' ? 'selected' : false,
                                                        'text' => wfMsg( 'addsection' ),
                                                        'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
-                                               );
+                                               );                                      
                                        }
-                               }
+                               }  
                        } elseif ( $this->mTitle->isKnown() ) {
                                $content_actions['viewsource'] = array(
                                        'class' => ($action == 'edit') ? 'selected' : false,
@@ -819,9 +832,9 @@ class SkinTemplate extends Skin {
                }
 
                /* show links to different language variants */
-               global $wgEnableVariants;
+               global $wgDisableLangConversion;
                $variants = $wgContLang->getVariants();
-               if( $wgEnableVariants && sizeof( $variants ) > 1 ) {
+               if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
                        $preferred = $wgContLang->getPreferredVariant();
                        $vcount=0;
                        foreach( $variants as $code ) {
@@ -874,10 +887,12 @@ 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' ) ) {
-                       $nav_urls['print'] = array(
-                               'text' => wfMsg( 'printableversion' ),
-                               'href' => $wgRequest->appendQuery( 'printable=yes' )
-                       );
+                       if ( !$wgRequest->getBool( 'printable' ) ) {
+                               $nav_urls['print'] = array(
+                                       'text' => wfMsg( 'printableversion' ),
+                                       'href' => $wgRequest->appendQuery( 'printable=yes' )
+                               );
+                       }
 
                        // Also add a "permalink" while we're at it
                        if ( $this->mRevisionId ) {
@@ -926,8 +941,13 @@ class SkinTemplate extends Skin {
 
                        if( $id ) {
                                $logPage = SpecialPage::getTitleFor( 'Log' );
-                               $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
-                                       . $this->mTitle->getPartialUrl() ) );
+                               $nav_urls['log'] = array(
+                                       'href' => $logPage->getLocalUrl(
+                                               array(
+                                                       'user' => $this->mTitle->getText()
+                                               )
+                                       )
+                               );
                        } else {
                                $nav_urls['log'] = false;
                        }
@@ -954,6 +974,298 @@ class SkinTemplate extends Skin {
                return $nav_urls;
        }
 
+       /**
+        * Builds a structured array of links used for tabs and menus
+        * @return array
+        * @private
+        */
+       function buildNavigationUrls() {
+               global $wgContLang, $wgLang, $wgOut, $wgUser, $wgRequest, $wgArticle;
+               global $wgDisableLangConversion;
+
+               wfProfileIn( __METHOD__ );
+
+               $links = array(
+                       'namespaces' => array(),
+                       'views' => array(),
+                       'actions' => array(),
+                       'variants' => array()
+               );
+               
+               // Detects parameters
+               $action = $wgRequest->getVal( 'action', 'view' );
+               $section = $wgRequest->getVal( 'section' );
+
+               // Checks if page is some kind of content
+               if( $this->iscontent ) {
+
+                       // Gets page objects for the related namespaces
+                       $subjectPage = $this->mTitle->getSubjectPage();
+                       $talkPage = $this->mTitle->getTalkPage();
+
+                       // Determines if this is a talk page
+                       $isTalk = $this->mTitle->isTalkPage();
+
+                       // Generates XML IDs from namespace names
+                       $subjectId = $this->mTitle->getNamespaceKey( '' );
+                       
+                       if ( $subjectId == 'main' ) {
+                               $talkId = 'talk';
+                       } else {
+                               $talkId = "{$subjectId}_talk";
+                       }
+                       $currentId = $isTalk ? $talkId : $subjectId;
+                       
+                       // Adds namespace links
+                       $links['namespaces'][$subjectId] = $this->tabAction(
+                               $subjectPage, 'vector-namespace-' . $subjectId, !$isTalk, '', true
+                       );
+                       $links['namespaces'][$subjectId]['context'] = 'subject';
+                       $links['namespaces'][$talkId] = $this->tabAction(
+                               $talkPage, 'vector-namespace-talk', $isTalk, '', true
+                       );
+                       $links['namespaces'][$talkId]['context'] = 'talk';
+                       
+                       // Adds view view link
+                       if ( $this->mTitle->exists() ) {
+                               $links['views']['view'] = $this->tabAction(
+                                       $isTalk ? $talkPage : $subjectPage,
+                                               'vector-view-view', ( $action == 'view' ), '', true
+                               );
+                       }
+                       
+                       wfProfileIn( __METHOD__ . '-edit' );
+                       
+                       // Checks if user can...
+                       if (
+                               // edit the current page
+                               $this->mTitle->quickUserCan( 'edit' ) &&
+                               (
+                                       // if it exists
+                                       $this->mTitle->exists() ||
+                                       // or they can create one here
+                                       $this->mTitle->quickUserCan( 'create' )
+                               )
+                       ) {
+                               // Builds CSS class for talk page links
+                               $isTalkClass = $isTalk ? ' istalk' : '';
+
+                               // Determines if we're in edit mode
+                               $selected = (
+                                       ( $action == 'edit' || $action == 'submit' ) &&
+                                       ( $section != 'new' )
+                               );
+                               $links['views']['edit'] = array(
+                                       'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
+                                       'text' => $this->mTitle->exists()
+                                               ? wfMsg( 'vector-view-edit' )
+                                               : wfMsg( 'vector-view-create' ),
+                                       'href' =>
+                                               $this->mTitle->getLocalUrl( $this->editUrlOptions() )
+                               );
+                               // Checks if this is a current rev of talk page and we should show a new
+                               // section link
+                               if ( ( $isTalk && $wgArticle->isCurrent() ) || ( $wgOut->showNewSectionLink() ) ) {
+                                       // Checks if we should ever show a new section link
+                                       if ( !$wgOut->forceHideNewSectionLink() ) {
+                                               // Adds new section link
+                                               $links['actions']['addsection'] = array(
+                                                       'class' => $section == 'new' ? 'selected' : false,
+                                                       'text' => wfMsg( 'vector-action-addsection' ),
+                                                       'href' => $this->mTitle->getLocalUrl(
+                                                               'action=edit&section=new'
+                                                       )
+                                               );
+                                       }
+                               }
+                       // Checks if the page is known (some kind of viewable content)
+                       } elseif ( $this->mTitle->isKnown() ) {
+                               // Adds view source view link
+                               $links['views']['viewsource'] = array(
+                                       'class' => ( $action == 'edit' ) ? 'selected' : false,
+                                       'text' => wfMsg( 'vector-view-viewsource' ),
+                                       'href' =>
+                                               $this->mTitle->getLocalUrl( $this->editUrlOptions() )
+                               );
+                       }
+                       wfProfileOut( __METHOD__ . '-edit' );
+
+                       wfProfileIn( __METHOD__ . '-live' );
+
+                       // Checks if the page exists
+                       if ( $this->mTitle->exists() ) {
+                               // Adds history view link
+                               $links['views']['history'] = array(
+                                       'class' => ($action == 'history') ? 'selected' : false,
+                                       'text' => wfMsg( 'vector-view-history' ),
+                                       'href' => $this->mTitle->getLocalUrl( 'action=history' ),
+                                       'rel' => 'archives',
+                               );
+
+                               if( $wgUser->isAllowed( 'delete' ) ) {
+                                       $links['actions']['delete'] = array(
+                                               'class' => ($action == 'delete') ? 'selected' : false,
+                                               'text' => wfMsg( 'vector-action-delete' ),
+                                               'href' => $this->mTitle->getLocalUrl( 'action=delete' )
+                                       );
+                               }
+                               if ( $this->mTitle->quickUserCan( 'move' ) ) {
+                                       $moveTitle = SpecialPage::getTitleFor(
+                                               'Movepage', $this->thispage
+                                       );
+                                       $links['actions']['move'] = array(
+                                               'class' => $this->mTitle->isSpecial( 'Movepage' ) ?
+                                                                               'selected' : false,
+                                               'text' => wfMsg( 'vector-action-move' ),
+                                               'href' => $moveTitle->getLocalUrl()
+                                       );
+                               }
+
+                               if (
+                                       $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
+                                       $wgUser->isAllowed( 'protect' )
+                               ) {
+                                       if ( !$this->mTitle->isProtected() ){
+                                               $links['actions']['protect'] = array(
+                                                       'class' => ($action == 'protect') ?
+                                                                                       'selected' : false,
+                                                       'text' => wfMsg( 'vector-action-protect' ),
+                                                       'href' =>
+                                                               $this->mTitle->getLocalUrl( 'action=protect' )
+                                               );
+
+                                       } else {
+                                               $links['actions']['unprotect'] = array(
+                                                       'class' => ($action == 'unprotect') ?
+                                                                                       'selected' : false,
+                                                       'text' => wfMsg( 'vector-action-unprotect' ),
+                                                       'href' =>
+                                                               $this->mTitle->getLocalUrl( 'action=unprotect' )
+                                               );
+                                       }
+                               }
+                       } else {
+                               // article doesn't exist or is deleted
+                               if (
+                                       $wgUser->isAllowed( 'deletedhistory' ) &&
+                                       $wgUser->isAllowed( 'undelete' )
+                               ) {
+                                       if( $n = $this->mTitle->isDeleted() ) {
+                                               $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
+                                               $links['actions']['undelete'] = array(
+                                                       'class' => false,
+                                                       'text' => wfMsgExt(
+                                                               'vector-action-undelete',
+                                                               array( 'parsemag' ),
+                                                               $wgLang->formatNum( $n )
+                                                       ),
+                                                       'href' => $undelTitle->getLocalUrl(
+                                                               'target=' . urlencode( $this->thispage )
+                                                       )
+                                               );
+                                       }
+                               }
+
+                               if (
+                                       $this->mTitle->getNamespace() !== NS_MEDIAWIKI &&
+                                       $wgUser->isAllowed( 'protect' )
+                               ) {
+                                       if ( !$this->mTitle->getRestrictions( 'create' ) ) {
+                                               $links['actions']['protect'] = array(
+                                                       'class' => ($action == 'protect') ?
+                                                                                       'selected' : false,
+                                                       'text' => wfMsg( 'vector-action-protect' ),
+                                                       'href' =>
+                                                               $this->mTitle->getLocalUrl( 'action=protect' )
+                                               );
+
+                                       } else {
+                                               $links['actions']['unprotect'] = array(
+                                                       'class' => ($action == 'unprotect') ?
+                                                                                       'selected' : false,
+                                                       'text' => wfMsg( 'vector-action-unprotect' ),
+                                                       'href' =>
+                                                               $this->mTitle->getLocalUrl( 'action=unprotect' )
+                                               );
+                                       }
+                               }
+                       }
+                       wfProfileOut( __METHOD__ . '-live' );
+                       
+                       /**
+                        * The following actions use messages which, if made particular to
+                        * the Vector skin, would break the Ajax code which makes this
+                        * action happen entirely inline. Skin::makeGlobalVariablesScript
+                        * defines a set of messages in a javascript object - and these
+                        * messages are assumed to be global for all skins. Without making
+                        * a change to that procedure these messages will have to remain as
+                        * the global versions.
+                        */
+                       // Checks if the user is logged in
+                       if( $this->loggedin ) {
+                               // Checks if the user is watching this page
+                               if( !$this->mTitle->userIsWatching() ) {
+                                       // Adds watch action link
+                                       $links['actions']['watch'] = array(
+                                               'class' =>
+                                                       ( $action == 'watch' or $action == 'unwatch' ) ?
+                                                               'selected' : false,
+                                               'text' => wfMsg( 'watch' ),
+                                               'href' => $this->mTitle->getLocalUrl( 'action=watch' )
+                                       );
+                               } else {
+                                       // Adds unwatch action link
+                                       $links['actions']['unwatch'] = array(
+                                               'class' =>
+                                                       ($action == 'unwatch' or $action == 'watch') ?
+                                                               'selected' : false,
+                                               'text' => wfMsg( 'unwatch' ),
+                                               'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
+                                       );
+                               }
+                       }
+                       
+                       // This is instead of SkinTemplateTabs - which uses a flat array
+                       wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$links ) );
+               
+               // If it's not content, it's got to be a special page
+               } else {
+                       $links['namespaces']['special'] = array(
+                               'class' => 'selected',
+                               'text' => wfMsg( 'vector-namespace-special' ),
+                               'href' => $wgRequest->getRequestURL()
+                       );
+               }
+
+               // Gets list of language variants
+               $variants = $wgContLang->getVariants();
+               // Checks that language conversion is enabled and variants exist
+               if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
+                       // Gets preferred variant
+                       $preferred = $wgContLang->getPreferredVariant();
+                       // Loops over each variant
+                       foreach( $variants as $code ) {
+                               // Gets variant name from language code
+                               $varname = $wgContLang->getVariantname( $code );
+                               // Checks if the variant is marked as disabled
+                               if( $varname == 'disable' ) {
+                                       // Skips this variant
+                                       continue;
+                               }
+                               // Appends variant link
+                               $links['variants'][] = array(
+                                       'class' => ( $code == $preferred ) ? 'selected' : false,
+                                       'text' => $varname,
+                                       'href' => $this->mTitle->getLocalURL( '', $code )
+                               );
+                       }
+               }
+
+               wfProfileOut( __METHOD__ );
+
+               return $links;
+       }
+       
        /**
         * Generate strings used for xml 'id' names
         * @return string
@@ -997,6 +1309,10 @@ class SkinTemplate extends Skin {
                wfProfileOut( __METHOD__ );
                return $out;
        }
+
+       public function commonPrintStylesheet() {
+               return false;
+       }
 }
 
 /**