begin cleanup on magnus' url upload thingy
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index cff4212..a3580d9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 if ( ! defined( 'MEDIAWIKI' ) )
-       die( -1 );
+       die( 1 );
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -31,13 +31,11 @@ if ( ! defined( 'MEDIAWIKI' ) )
  * @subpackage Skins
  */
 
-require_once 'GlobalFunctions.php';
-
 /**
  * Wrapper object for MediaWiki's localization functions,
  * to be passed to the template engine.
  *
- * @access private
+ * @private
  * @package MediaWiki
  */
 class MediaWiki_I18N {
@@ -74,7 +72,7 @@ class MediaWiki_I18N {
  */
 class SkinTemplate extends Skin {
        /**#@+
-        * @access private
+        * @private
         */
 
        /**
@@ -120,7 +118,7 @@ class SkinTemplate extends Skin {
         * @param string $repository subdirectory where we keep template files
         * @param string $cache_dir
         * @return object
-        * @access private
+        * @private
         */
        function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
                return new $classname();
@@ -130,7 +128,7 @@ class SkinTemplate extends Skin {
         * initialize various variables and generate the template
         *
         * @param OutputPage $out
-        * @access public
+        * @public
         */
        function outputPage( &$out ) {
                global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
@@ -141,10 +139,15 @@ class SkinTemplate extends Skin {
                global $wgPageShowWatchingUsers;
                global $wgUseTrackbacks;
                global $wgDBname;
+               global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
 
                $fname = 'SkinTemplate::outputPage';
                wfProfileIn( $fname );
 
+               // Hook that allows last minute changes to the output page, e.g.
+               // adding of CSS or Javascript by extensions.
+               wfRunHooks( 'BeforePageDisplay', array( &$out ) );
+
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
 
                wfProfileIn( "$fname-init" );
@@ -189,6 +192,14 @@ class SkinTemplate extends Skin {
                $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
                $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
 
+               $nsname = @$wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ];
+               if ( $nsname === NULL ) $nsname = $this->mTitle->getNsText();
+               
+               $tpl->set( 'nscanonical', $nsname );
+               $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
+               $tpl->set( 'titletext', $this->mTitle->getText() );
+               $tpl->set( 'articleid', $this->mTitle->getArticleId() );
+                               
                $tpl->setRef( "thispage", $this->thispage );
                $subpagestr = $this->subPageSubtitle();
                $tpl->set(
@@ -226,6 +237,7 @@ class SkinTemplate extends Skin {
                $tpl->set('headscripts', $out->getScript() );
                $tpl->setRef( 'wgScript', $wgScript );
                $tpl->setRef( 'skinname', $this->skinname );
+               $tpl->set( 'skinclass', get_class( $this ) );
                $tpl->setRef( 'stylename', $this->stylename );
                $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
                $tpl->setRef( 'loggedin', $this->loggedin );
@@ -241,15 +253,19 @@ class SkinTemplate extends Skin {
                $tpl->set( 'searchaction', $this->escapeSearchLink() );
                $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
                $tpl->setRef( 'stylepath', $wgStylePath );
+               $tpl->setRef( 'articlepath', $wgArticlePath );
+               $tpl->setRef( 'scriptpath', $wgScriptPath );
+               $tpl->setRef( 'serverurl', $wgServer );
                $tpl->setRef( 'logopath', $wgLogo );
                $tpl->setRef( "lang", $wgContLanguageCode );
                $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
                $tpl->set( 'rtl', $wgContLang->isRTL() );
                $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
                $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
-               $tpl->setRef( 'username', $this->username );
+               $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
                $tpl->setRef( 'userpage', $this->userpage);
                $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
+               $tpl->set( 'userlang', $wgLang->getCode() );
                $tpl->set( 'pagecss', $this->setupPageCss() );
                $tpl->setRef( 'usercss', $this->usercss);
                $tpl->setRef( 'userjs', $this->userjs);
@@ -304,11 +320,13 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'newtalk', $ntl );
                $tpl->setRef( 'skin', $this);
                $tpl->set( 'logo', $this->logoText() );
-               if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 0 != $wgArticle->getID() ) {
+               if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and 
+                       $wgArticle and 0 != $wgArticle->getID() ) 
+               {
                        if ( !$wgDisableCounters ) {
                                $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
                                if ( $viewcount ) {
-                                       $tpl->set('viewcount', wfMsg( "viewcount", $viewcount ));
+                                       $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
                                } else {
                                        $tpl->set('viewcount', false);
                                }
@@ -372,6 +390,7 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'debug', $out->mDebugtext );
                $tpl->set( 'reporttime', $out->reportTime() );
                $tpl->set( 'sitenotice', wfGetSiteNotice() );
+               $tpl->set( 'bottomscripts', $this->bottomScripts() );
 
                $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
                $out->mBodytext .= $printfooter ;
@@ -436,7 +455,7 @@ class SkinTemplate extends Skin {
         * For the base class, assume strings all around.
         *
         * @param mixed $str
-        * @access private
+        * @private
         */
        function printOrError( &$str ) {
                echo $str;
@@ -445,7 +464,7 @@ class SkinTemplate extends Skin {
        /**
         * build array of urls for personal toolbar
         * @return array
-        * @access private
+        * @private
         */
        function buildPersonalUrls() {
                global $wgTitle, $wgShowIPinHeader;
@@ -525,6 +544,8 @@ class SkinTemplate extends Skin {
                                );
                        }
                }
+
+               wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );              
                wfProfileOut( $fname );
                return $personal_urls;
        }
@@ -582,10 +603,10 @@ class SkinTemplate extends Skin {
        /**
         * an array of edit links by default used for the tabs
         * @return array
-        * @access private
+        * @private
         */
        function buildContentActionUrls () {
-               global $wgContLang;
+               global $wgContLang, $wgOut;
                $fname = 'SkinTemplate::buildContentActionUrls';
                wfProfileIn( $fname );
 
@@ -616,7 +637,7 @@ class SkinTemplate extends Skin {
                                true);
 
                        wfProfileIn( "$fname-edit" );
-                       if ( $this->mTitle->userCanEdit() ) {
+                       if ( $this->mTitle->userCanEdit() && ( $this->mTitle->exists() || $this->mTitle->userCanCreate() ) ) {
                                $istalk = $this->mTitle->isTalkPage();
                                $istalkclass = $istalk?' istalk':'';
                                $content_actions['edit'] = array(
@@ -625,7 +646,7 @@ class SkinTemplate extends Skin {
                                        'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
                                );
 
-                               if ( $istalk ) {
+                               if ( $istalk || $wgOut->showNewSectionLink() ) {
                                        $content_actions['addsection'] = array(
                                                'class' => $section == 'new'?'selected':false,
                                                'text' => wfMsg('addsection'),
@@ -688,7 +709,7 @@ class SkinTemplate extends Skin {
                                                $undelTitle = Title::makeTitle( NS_SPECIAL, 'Undelete' );
                                                $content_actions['undelete'] = array(
                                                        'class' => false,
-                                                       'text' => ($n == 1) ? wfMsg( 'undelete_short1' ) : wfMsg('undelete_short', $n ),
+                                                       'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $n ),
                                                        'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
                                                        #'href' => $this->makeSpecialUrl("Undelete/$this->thispage")
                                                );
@@ -743,7 +764,7 @@ class SkinTemplate extends Skin {
                                $content_actions['varlang-' . $vcount] = array(
                                                'class' => $selected,
                                                'text' => $varname,
-                                               'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . $code )
+                                               'href' => $this->mTitle->getLocalUrl( $actstr . 'variant=' . urlencode( $code ) )
                                        );
                                $vcount ++;
                        }
@@ -760,7 +781,7 @@ class SkinTemplate extends Skin {
        /**
         * build array of common navigation links
         * @return array
-        * @access private
+        * @private
         */
        function buildNavUrls () {
                global $wgUseTrackbacks, $wgTitle, $wgArticle;
@@ -795,7 +816,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 == '' || $action == 'view' || $action == 'purge' ) ) {
-                       $revid = $wgArticle->getLatest();
+                       $revid = $wgArticle ? $wgArticle->getLatest() : 0;
                        if ( !( $revid == 0 )  )
                                $nav_urls['print'] = array(
                                        'text' => wfMsg( 'printableversion' ),
@@ -868,14 +889,14 @@ class SkinTemplate extends Skin {
        /**
         * Generate strings used for xml 'id' names
         * @return string
-        * @access private
+        * @private
         */
        function getNameSpaceKey () {
                return $this->mTitle->getNamespaceKey();
        }
 
        /**
-        * @access private
+        * @private
         */
        function setupUserCss() {
                $fname = 'SkinTemplate::setupUserCss';
@@ -924,7 +945,7 @@ class SkinTemplate extends Skin {
        }
 
        /**
-        * @access private
+        * @private
         */
        function setupUserJs() {
                $fname = 'SkinTemplate::setupUserJs';
@@ -948,7 +969,7 @@ class SkinTemplate extends Skin {
         * Code for extensions to hook into to provide per-page CSS, see
         * extensions/PageCSS/PageCSS.php for an implementation of this.
         *
-        * @access private
+        * @private
         */
        function setupPageCss() {
                $fname = 'SkinTemplate::setupPageCss';
@@ -962,7 +983,7 @@ class SkinTemplate extends Skin {
 
        /**
         * returns css with user-specific options
-        * @access public
+        * @public
         */
 
        function getUserStylesheet() {
@@ -976,7 +997,7 @@ class SkinTemplate extends Skin {
        }
 
        /**
-        * @access public
+        * @public
         */
        function getUserJs() {
                $fname = 'SkinTemplate::getUserJs';
@@ -1008,7 +1029,7 @@ class SkinTemplate extends Skin {
  */
 class QuickTemplate {
        /**
-        * @access public
+        * @public
         */
        function QuickTemplate() {
                $this->data = array();
@@ -1016,28 +1037,28 @@ class QuickTemplate {
        }
 
        /**
-        * @access public
+        * @public
         */
        function set( $name, $value ) {
                $this->data[$name] = $value;
        }
 
        /**
-        * @access public
+        * @public
         */
        function setRef($name, &$value) {
                $this->data[$name] =& $value;
        }
 
        /**
-        * @access public
+        * @public
         */
        function setTranslator( &$t ) {
                $this->translator = &$t;
        }
 
        /**
-        * @access public
+        * @public
         */
        function execute() {
                echo "Override this function.";
@@ -1045,28 +1066,35 @@ class QuickTemplate {
 
 
        /**
-        * @access private
+        * @private
         */
        function text( $str ) {
                echo htmlspecialchars( $this->data[$str] );
        }
 
        /**
-        * @access private
+        * @private
+        */
+       function jstext( $str ) {
+               echo Xml::escapeJsString( $this->data[$str] );
+       }
+
+       /**
+        * @private
         */
        function html( $str ) {
                echo $this->data[$str];
        }
 
        /**
-        * @access private
+        * @private
         */
        function msg( $str ) {
                echo htmlspecialchars( $this->translator->translate( $str ) );
        }
 
        /**
-        * @access private
+        * @private
         */
        function msgHtml( $str ) {
                echo $this->translator->translate( $str );
@@ -1074,26 +1102,26 @@ class QuickTemplate {
 
        /**
         * An ugly, ugly hack.
-        * @access private
+        * @private
         */
        function msgWiki( $str ) {
                global $wgParser, $wgTitle, $wgOut;
 
                $text = $this->translator->translate( $str );
                $parserOutput = $wgParser->parse( $text, $wgTitle,
-                       $wgOut->mParserOptions, true );
+                       $wgOut->parserOptions(), true );
                echo $parserOutput->getText();
        }
 
        /**
-        * @access private
+        * @private
         */
        function haveData( $str ) {
                return $this->data[$str];
        }
 
        /**
-        * @access private
+        * @private
         */
        function haveMsg( $str ) {
                $msg = $this->translator->translate( $str );