(bug 30269) Strings like foobar//barfoo are linked to become foobar[//barfoo]
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index aa04445..2268b51 100644 (file)
@@ -145,10 +145,6 @@ class SkinTemplate extends Skin {
                wfProfileIn( __METHOD__ );
                Profiler::instance()->setTemplated( true );
 
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $diff = $wgRequest->getVal( 'diff' );
-               $action = $wgRequest->getVal( 'action', 'view' );
-
                wfProfileIn( __METHOD__ . '-init' );
                $this->initPage( $out );
 
@@ -157,6 +153,7 @@ class SkinTemplate extends Skin {
 
                wfProfileIn( __METHOD__ . '-stuff' );
                $this->thispage = $this->getTitle()->getPrefixedDBkey();
+               $this->userpage = $this->getUser()->getUserPage()->getPrefixedText();
                $query = array();
                if ( !$wgRequest->wasPosted() ) {
                        $query = $wgRequest->getValues();
@@ -166,8 +163,6 @@ class SkinTemplate extends Skin {
                }
                $this->thisquery = wfArrayToCGI( $query );
                $this->loggedin = $wgUser->isLoggedIn();
-               $this->iscontent = ( $this->getTitle()->getNamespace() != NS_SPECIAL );
-               $this->iseditable = ( $this->iscontent and !( $action == 'edit' or $action == 'submit' ) );
                $this->username = $wgUser->getName();
 
                if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
@@ -183,8 +178,6 @@ class SkinTemplate extends Skin {
 
                wfProfileIn( __METHOD__ . '-stuff-head' );
                if ( !$this->useHeadElement ) {
-                       $this->setupUserCss( $out );
-
                        $tpl->set( 'pagecss', false );
                        $tpl->set( 'usercss', false );
 
@@ -208,14 +201,17 @@ class SkinTemplate extends Skin {
                        $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
                        $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
                        $tpl->set( 'html5version', $wgHtml5Version );
-                       $tpl->set( 'headlinks', $out->getHeadLinks( $this ) );
-                       $tpl->set( 'csslinks', $out->buildCssLinks( $this ) );
+                       $tpl->set( 'headlinks', $out->getHeadLinks() );
+                       $tpl->set( 'csslinks', $out->buildCssLinks() );
 
                        if( $wgUseTrackbacks && $out->isArticleRelated() ) {
                                $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
                        } else {
                                $tpl->set( 'trackbackhtml', null );
                        }
+
+                       $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
+                       $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
                }
                wfProfileOut( __METHOD__ . '-stuff-head' );
 
@@ -223,19 +219,10 @@ class SkinTemplate extends Skin {
                $tpl->set( 'title', $out->getPageTitle() );
                $tpl->set( 'pagetitle', $out->getHTMLTitle() );
                $tpl->set( 'displaytitle', $out->mPageLinkTitle );
-               $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
-               $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
 
-               $nsname = MWNamespace::exists( $this->getTitle()->getNamespace() ) ?
-                                       MWNamespace::getCanonicalName( $this->getTitle()->getNamespace() ) :
-                                       $this->getTitle()->getNsText();
-
-               $tpl->set( 'nscanonical', $nsname );
-               $tpl->set( 'nsnumber', $this->getTitle()->getNamespace() );
                $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
                $tpl->set( 'titletext', $this->getTitle()->getText() );
                $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
-               $tpl->set( 'currevisionid', $this->getTitle()->getLatestRevID() );
 
                $tpl->set( 'isarticle', $out->isArticle() );
 
@@ -321,74 +308,49 @@ class SkinTemplate extends Skin {
                        $tpl->set( 'userlangattributes', $attrs );
                }
 
-               $newtalks = $this->getNewtalks( $out );
-
                wfProfileOut( __METHOD__ . '-stuff2' );
 
                wfProfileIn( __METHOD__ . '-stuff3' );
-               $tpl->setRef( 'newtalk', $newtalks );
+               $tpl->set( 'newtalk', $this->getNewtalks() );
                $tpl->setRef( 'skin', $this );
                $tpl->set( 'logo', $this->logoText() );
-               if ( $out->isArticle() && ( !isset( $oldid ) || isset( $diff ) ) &&
-                       $this->getTitle()->exists() )
-               {
-                       $article = new Article( $this->getTitle(), 0 );
-                       if ( !$wgDisableCounters ) {
-                               $viewcount = $wgLang->formatNum( $article->getCount() );
-                               if ( $viewcount ) {
-                                       $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
-                               } else {
-                                       $tpl->set( 'viewcount', false );
+
+               $tpl->set( 'copyright', false );
+               $tpl->set( 'viewcount', false );
+               $tpl->set( 'lastmod', false );
+               $tpl->set( 'credits', false );
+               $tpl->set( 'numberofwatchingusers', false );
+               if ( $out->isArticle() && $this->getTitle()->exists() ) {
+                       if ( $this->isRevisionCurrent() ) {
+                               $article = new Article( $this->getTitle(), 0 );
+                               if ( !$wgDisableCounters ) {
+                                       $viewcount = $wgLang->formatNum( $article->getCount() );
+                                       if ( $viewcount ) {
+                                               $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
+                                       }
                                }
-                       } else {
-                               $tpl->set( 'viewcount', false );
-                       }
 
-                       if( $wgPageShowWatchingUsers ) {
-                               $dbr = wfGetDB( DB_SLAVE );
-                               $res = $dbr->select( 'watchlist',
-                                       array( 'COUNT(*) AS n' ),
-                                       array( 'wl_title' => $dbr->strencode( $this->getTitle()->getDBkey() ), 'wl_namespace' => $this->getTitle()->getNamespace() ),
-                                       __METHOD__
-                               );
-                               $x = $dbr->fetchObject( $res );
-                               $numberofwatchingusers = $x->n;
-                               if( $numberofwatchingusers > 0 ) {
-                                       $tpl->set( 'numberofwatchingusers',
-                                               wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
-                                               $wgLang->formatNum( $numberofwatchingusers ) )
+                               if( $wgPageShowWatchingUsers ) {
+                                       $dbr = wfGetDB( DB_SLAVE );
+                                       $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
+                                               array( 'wl_title' => $this->getTitle()->getDBkey(), 'wl_namespace' => $this->getTitle()->getNamespace() ),
+                                               __METHOD__
                                        );
-                               } else {
-                                       $tpl->set( 'numberofwatchingusers', false );
+                                       if( $num > 0 ) {
+                                               $tpl->set( 'numberofwatchingusers',
+                                                       wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
+                                                       $wgLang->formatNum( $num ) )
+                                               );
+                                       }
                                }
-                       } else {
-                               $tpl->set( 'numberofwatchingusers', false );
-                       }
 
-                       $tpl->set( 'copyright', $this->getCopyright() );
-
-                       $this->credits = false;
-
-                       if( $wgMaxCredits != 0 ){
-                               $this->credits = Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax );
-                       } else {
-                               $tpl->set( 'lastmod', $this->lastModified( $article ) );
+                               if ( $wgMaxCredits != 0 ) {
+                                       $tpl->set( 'credits', Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
+                               } else {
+                                       $tpl->set( 'lastmod', $this->lastModified( $article ) );
+                               }
                        }
-
-                       $tpl->setRef( 'credits', $this->credits );
-
-               } elseif ( isset( $oldid ) && !isset( $diff ) ) {
                        $tpl->set( 'copyright', $this->getCopyright() );
-                       $tpl->set( 'viewcount', false );
-                       $tpl->set( 'lastmod', false );
-                       $tpl->set( 'credits', false );
-                       $tpl->set( 'numberofwatchingusers', false );
-               } else {
-                       $tpl->set( 'copyright', false );
-                       $tpl->set( 'viewcount', false );
-                       $tpl->set( 'lastmod', false );
-                       $tpl->set( 'credits', false );
-                       $tpl->set( 'numberofwatchingusers', false );
                }
                wfProfileOut( __METHOD__ . '-stuff3' );
 
@@ -441,14 +403,14 @@ class SkinTemplate extends Skin {
 
                $tpl->set( 'reporttime', wfReportTime() );
                $tpl->set( 'sitenotice', $this->getSiteNotice() );
-               $tpl->set( 'bottomscripts', $this->bottomScripts( $out ) );
+               $tpl->set( 'bottomscripts', $this->bottomScripts() );
                $tpl->set( 'printfooter', $this->printSource() );
 
                # Add a <div class="mw-content-ltr/rtl"> around the body text
                # not for special pages or file pages AND only when viewing AND if the page exists
                # (or is in MW namespace, because that has default content)
                if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
-                       in_array( $action, array( 'view', 'historysubmit' ) ) &&
+                       in_array( $wgRequest->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
                        ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
                        $pageLang = $this->getTitle()->getPageLanguage();
                        $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
@@ -962,7 +924,7 @@ class SkinTemplate extends Skin {
                                }
                        } else {
                                // article doesn't exist or is deleted
-                               if ( $wgUser->isAllowed( 'deletedhistory' ) ) {
+                               if ( $wgUser->isAllowed( 'deletedhistory' ) && !$wgUser->isBlocked() ) {
                                        $includeSuppressed = $wgUser->isAllowed( 'suppressrevision' );
                                        $n = $title->isDeleted( $includeSuppressed );
                                        if( $n ) {
@@ -1149,8 +1111,6 @@ class SkinTemplate extends Skin {
 
                wfProfileIn( __METHOD__ );
 
-               $action = $wgRequest->getVal( 'action', 'view' );
-
                $nav_urls = array();
                $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
                if( $wgUploadNavigationUrl ) {
@@ -1167,7 +1127,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( $out->isArticle() ) {
                        if ( !$out->isPrintable() ) {
                                $nav_urls['print'] = array(
                                        'text' => wfMsg( 'printableversion' ),
@@ -1278,7 +1238,7 @@ class SkinTemplate extends Skin {
                wfProfileIn( __METHOD__ );
 
                if( $allowUserJs && $this->loggedin ) {
-                       if( $this->getTitle()->isJsSubpage() and $this->userCanPreview() ) {
+                       if( $this->getTitle()->isJsSubpage() and $this->getOutput()->userCanPreview() ) {
                                # XXX: additional security check/prompt?
                                $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
                        } else {
@@ -1377,12 +1337,10 @@ abstract class QuickTemplate {
         * @private
         */
        function msgWiki( $str ) {
-               global $wgParser, $wgOut;
+               global $wgOut;
 
                $text = $this->translator->translate( $str );
-               $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
-                       $wgOut->parserOptions(), true );
-               echo $parserOutput->getText();
+               echo $wgOut->parse( $text );
        }
 
        /**