(bug 32748) unicode URL for articles print version
[lhc/web/wiklou.git] / includes / Skin.php
index d69408f..8b10d7f 100644 (file)
@@ -22,7 +22,7 @@ abstract class Skin extends ContextSource {
 
        /**
         * Fetch the set of available skins.
-        * @return array of strings
+        * @return array associative array of strings
         */
        static function getSkinNames() {
                global $wgValidSkinNames;
@@ -55,6 +55,18 @@ abstract class Skin extends ContextSource {
                }
                return $wgValidSkinNames;
        }
+       /**
+        * Fetch the skinname messages for available skins.
+        * @return array of strings
+        */
+       static function getSkinNameMessages() {
+               $messages = array();
+               foreach( self::getSkinNames() as $skinKey => $skinName ) {
+                       $messages[] = "skinname-$skinKey";
+               }
+               return $messages;
+       }
 
        /**
         * Fetch the list of usable skins in regards to $wgSkipSkins.
@@ -86,7 +98,7 @@ abstract class Skin extends ContextSource {
 
                $skinNames = Skin::getSkinNames();
 
-               if ( $key == '' ) {
+               if ( $key == '' || $key == 'default' ) {
                        // Don't return the default immediately;
                        // in a misconfiguration we need to fall back.
                        $key = $wgDefaultSkin;
@@ -288,7 +300,7 @@ abstract class Skin extends ContextSource {
        abstract function outputPage( OutputPage $out = null );
 
        /**
-        * @param $data
+        * @param $data array
         * @return string
         */
        static function makeVariablesScript( $data ) {
@@ -301,6 +313,21 @@ abstract class Skin extends ContextSource {
                }
        }
 
+       /**
+        * Make a <script> tag containing global variables
+        *
+        * @deprecated in 1.19
+        * @param $unused
+        * @return string HTML fragment
+        */
+       public static function makeGlobalVariablesScript( $unused ) {
+               global $wgOut;
+
+               wfDeprecated( __METHOD__, '1.19' );
+
+               return self::makeVariablesScript( $wgOut->getJSVars() );
+       }
+
        /**
         * Get the query to generate a dynamic stylesheet
         *
@@ -531,17 +558,19 @@ abstract class Skin extends ContextSource {
        protected function generateDebugHTML() {
                global $wgShowDebug;
 
+               $html = MWDebug::getDebugHTML( $this->getContext() );
+
                if ( $wgShowDebug ) {
                        $listInternals = $this->formatDebugHTML( $this->getOutput()->mDebugtext );
-                       return "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
+                       $html .= "\n<hr />\n<strong>Debug data:</strong><ul id=\"mw-debug-html\">" .
                                $listInternals . "</ul>\n";
                }
 
-               return '';
+               return $html;
        }
 
        /**
-        * @param $debugText
+        * @param $debugText string
         * @return string
         */
        private function formatDebugHTML( $debugText ) {
@@ -618,10 +647,10 @@ abstract class Skin extends ContextSource {
        function printSource() {
                $oldid = $this->getRevisionId();
                if ( $oldid ) {
-                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
+                       $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) ) );
                } else {
                        // oldid not available for non existing pages
-                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
+                       $url = htmlspecialchars( wfExpandIRI( $this->getTitle()->getCanonicalURL() ) );
                }
                return $this->msg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' )->text();
        }
@@ -633,7 +662,7 @@ abstract class Skin extends ContextSource {
                $action = $this->getRequest()->getVal( 'action', 'view' );
 
                if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
-                       ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
+                       ( $this->getTitle()->getArticleID() == 0 || $action == 'history' ) ) {
                        $n = $this->getTitle()->isDeleted();
 
 
@@ -732,7 +761,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param string $type
+        * @param $type string
         * @return string
         */
        function getCopyright( $type = 'detect' ) {
@@ -773,7 +802,7 @@ abstract class Skin extends ContextSource {
                if ( $forContent ) {
                        $msg = $msgObj->inContentLanguage()->text();
                        if ( $this->getLanguage()->getCode() !== $wgContLang->getCode() ) {
-                               $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $msg );
+                               $msg = Html::rawElement( 'span', array( 'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $msg );
                        }
                        return $msg;
                } else {
@@ -826,14 +855,14 @@ abstract class Skin extends ContextSource {
        /**
         * Get the timestamp of the latest revision, formatted in user language
         *
-        * @param $page WikiPage object. Used if we're working with the current revision
         * @return String
         */
-       protected function lastModified( $page ) {
-               if ( !$this->isRevisionCurrent() ) {
+       protected function lastModified() {
+               $timestamp = $this->getOutput()->getRevisionTimestamp();
+
+               # No cached timestamp, load it from the database
+               if ( $timestamp === null ) {
                        $timestamp = Revision::getTimestampFromId( $this->getTitle(), $this->getRevisionId() );
-               } else {
-                       $timestamp = $page->getTimestamp();
                }
 
                if ( $timestamp ) {
@@ -864,7 +893,7 @@ abstract class Skin extends ContextSource {
 
                $mp = $this->msg( 'mainpage' )->escaped();
                $mptitle = Title::newMainPage();
-               $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
+               $url = ( is_object( $mptitle ) ? htmlspecialchars( $mptitle->getLocalURL() ) : '' );
 
                $logourl = $this->getLogo();
                $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
@@ -974,7 +1003,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $id
+        * @param $id User|int
         * @return bool
         */
        function showEmailUser( $id ) {
@@ -1025,7 +1054,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name
+        * @param $name string
         * @param $urlaction string
         * @return String
         */
@@ -1035,8 +1064,8 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name
-        * @param $subpage
+        * @param $name string
+        * @param $subpage string
         * @param $urlaction string
         * @return String
         */
@@ -1046,7 +1075,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name
+        * @param $name string
         * @param $urlaction string
         * @return String
         */
@@ -1057,7 +1086,7 @@ abstract class Skin extends ContextSource {
        }
 
        /**
-        * @param $name
+        * @param $name string
         * @param $urlaction string
         * @return String
         */
@@ -1132,7 +1161,7 @@ abstract class Skin extends ContextSource {
         * make sure we have some title to operate on
         *
         * @param $title Title
-        * @param $name
+        * @param $name string
         */
        static function checkTitle( &$title, $name ) {
                if ( !is_object( $title ) ) {
@@ -1149,13 +1178,13 @@ abstract class Skin extends ContextSource {
         * @return array
         */
        function buildSidebar() {
-               global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
+               global $wgMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
                wfProfileIn( __METHOD__ );
 
                $key = wfMemcKey( 'sidebar', $this->getLanguage()->getCode() );
 
                if ( $wgEnableSidebarCache ) {
-                       $cachedsidebar = $parserMemc->get( $key );
+                       $cachedsidebar = $wgMemc->get( $key );
                        if ( $cachedsidebar ) {
                                wfProfileOut( __METHOD__ );
                                return $cachedsidebar;
@@ -1167,7 +1196,7 @@ abstract class Skin extends ContextSource {
 
                wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
                if ( $wgEnableSidebarCache ) {
-                       $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
+                       $wgMemc->set( $key, $bar, $wgSidebarCacheExpiry );
                }
 
                wfProfileOut( __METHOD__ );
@@ -1215,6 +1244,12 @@ abstract class Skin extends ContextSource {
                                if ( strpos( $line, '|' ) !== false ) { // sanity check
                                        $line = MessageCache::singleton()->transform( $line, false, null, $this->getTitle() );
                                        $line = array_map( 'trim', explode( '|', $line, 2 ) );
+                                       if ( count( $line ) !== 2 ) {
+                                               // Second sanity check, could be hit by people doing
+                                               // funky stuff with parserfuncs... (bug 33321)
+                                               continue;
+                                       }
+
                                        $extraAttribs = array();
 
                                        $msgLink = $this->msg( $line[0] )->inContentLanguage();
@@ -1226,7 +1261,6 @@ abstract class Skin extends ContextSource {
                                        } else {
                                                $link = $line[0];
                                        }
-
                                        $msgText = $this->msg( $line[1] );
                                        if ( $msgText->exists() ) {
                                                $text = $msgText->text();
@@ -1390,7 +1424,7 @@ abstract class Skin extends ContextSource {
                }
 
                $notice = Html::rawElement( 'div', array( 'id' => 'localNotice',
-                       'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), $notice );
+                       'lang' => $wgContLang->getHtmlCode(), 'dir' => $wgContLang->getDir() ), $notice );
                wfProfileOut( __METHOD__ );
                return $notice;
        }
@@ -1465,7 +1499,7 @@ abstract class Skin extends ContextSource {
                if ( !is_null( $tooltip ) ) {
                        # Bug 25462: undo double-escaping.
                        $tooltip = Sanitizer::decodeCharReferences( $tooltip );
-                       $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag' ), $tooltip );
+                       $attribs['title'] = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'replaceafter' ), $tooltip );
                }
                $link = Linker::link( $nt, wfMsgExt( 'editsection', array( 'language' => $lang ) ),
                        $attribs,
@@ -1477,7 +1511,7 @@ abstract class Skin extends ContextSource {
                # we can rid of it someday.
                $attribs = '';
                if ( $tooltip ) {
-                       $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape' ), $tooltip );
+                       $attribs = wfMsgExt( 'editsectionhint', array( 'language' => $lang, 'parsemag', 'escape', 'replaceafter' ), $tooltip );
                        $attribs = " title=\"$attribs\"";
                }
                $result = null;
@@ -1506,6 +1540,7 @@ abstract class Skin extends ContextSource {
         *
         * @param $fname String Name of called method
         * @param $args Array Arguments to the method
+        * @return mixed
         */
        function __call( $fname, $args ) {
                $realFunction = array( 'Linker', $fname );