Merge "When file sha1 populator fixes wrong values, make it fix the other metadata."
[lhc/web/wiklou.git] / includes / Skin.php
index cae7878..64cf569 100644 (file)
@@ -1,11 +1,28 @@
 <?php
 /**
- * @defgroup Skins Skins
+ * Base class for all skins.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 1 );
-}
+/**
+ * @defgroup Skins Skins
+ */
 
 /**
  * The main skin class that provide methods and properties for all other skins.
@@ -22,7 +39,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 +72,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 +115,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;
@@ -165,6 +194,9 @@ abstract class Skin extends ContextSource {
                return $this->skinname;
        }
 
+       /**
+        * @param $out OutputPage
+        */
        function initPage( OutputPage $out ) {
                wfProfileIn( __METHOD__ );
 
@@ -284,6 +316,10 @@ abstract class Skin extends ContextSource {
         */
        abstract function outputPage( OutputPage $out = null );
 
+       /**
+        * @param $data array
+        * @return string
+        */
        static function makeVariablesScript( $data ) {
                if ( $data ) {
                        return Html::inlineScript(
@@ -294,6 +330,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
         *
@@ -369,6 +420,9 @@ abstract class Skin extends ContextSource {
                return $wgLogo;
        }
 
+       /**
+        * @return string
+        */
        function getCategoryLinks() {
                global $wgUseCategoryBrowser;
 
@@ -456,6 +510,9 @@ abstract class Skin extends ContextSource {
                return $return;
        }
 
+       /**
+        * @return string
+        */
        function getCategories() {
                $out = $this->getOutput();
 
@@ -518,15 +575,21 @@ 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 string
+        * @return string
+        */
        private function formatDebugHTML( $debugText ) {
                global $wgDebugTimestamps;
 
@@ -601,19 +664,22 @@ 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();
        }
 
+       /**
+        * @return String
+        */
        function getUndeleteLink() {
                $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();
 
 
@@ -635,7 +701,11 @@ abstract class Skin extends ContextSource {
                return '';
        }
 
+       /**
+        * @return string
+        */
        function subPageSubtitle() {
+               global $wgLang;
                $out = $this->getOutput();
                $subpages = '';
 
@@ -666,7 +736,7 @@ abstract class Skin extends ContextSource {
                                                $c++;
 
                                                if ( $c > 1 ) {
-                                                       $subpages .= $this->msg( 'pipe-separator' )->escaped();
+                                                       $subpages .= $wgLang->getDirMarkEntity() . $this->msg( 'pipe-separator' )->escaped();
                                                } else  {
                                                        $subpages .= '&lt; ';
                                                }
@@ -693,15 +763,25 @@ abstract class Skin extends ContextSource {
                return $wgShowIPinHeader && session_id() != '';
        }
 
+       /**
+        * @return String
+        */
        function getSearchLink() {
                $searchPage = SpecialPage::getTitleFor( 'Search' );
                return $searchPage->getLocalURL();
        }
 
+       /**
+        * @return string
+        */
        function escapeSearchLink() {
                return htmlspecialchars( $this->getSearchLink() );
        }
 
+       /**
+        * @param $type string
+        * @return string
+        */
        function getCopyright( $type = 'detect' ) {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgContLang;
 
@@ -740,7 +820,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 {
@@ -748,6 +828,9 @@ abstract class Skin extends ContextSource {
                }
        }
 
+       /**
+        * @return null|string
+        */
        function getCopyrightIcon() {
                global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
 
@@ -790,14 +873,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 ) {
@@ -815,6 +898,10 @@ abstract class Skin extends ContextSource {
                return $s;
        }
 
+       /**
+        * @param $align string
+        * @return string
+        */
        function logoText( $align = '' ) {
                if ( $align != '' ) {
                        $a = " align='{$align}'";
@@ -824,7 +911,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>";
@@ -869,6 +956,11 @@ abstract class Skin extends ContextSource {
                return $s;
        }
 
+       /**
+        * @param $desc
+        * @param $page
+        * @return string
+        */
        public function footerLink( $desc, $page ) {
                // if the link description has been set to "-" in the default language,
                if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) {
@@ -928,6 +1020,10 @@ abstract class Skin extends ContextSource {
                return $options;
        }
 
+       /**
+        * @param $id User|int
+        * @return bool
+        */
        function showEmailUser( $id ) {
                if ( $id instanceof User ) {
                        $targetUser = $id;
@@ -963,6 +1059,11 @@ abstract class Skin extends ContextSource {
        }
 
        /* these are used extensively in SkinTemplate, but also some other places */
+
+       /**
+        * @param $urlaction string
+        * @return String
+        */
        static function makeMainPageUrl( $urlaction = '' ) {
                $title = Title::newMainPage();
                self::checkTitle( $title, '' );
@@ -970,22 +1071,43 @@ abstract class Skin extends ContextSource {
                return $title->getLocalURL( $urlaction );
        }
 
+       /**
+        * @param $name string
+        * @param $urlaction string
+        * @return String
+        */
        static function makeSpecialUrl( $name, $urlaction = '' ) {
                $title = SpecialPage::getSafeTitleFor( $name );
                return $title->getLocalURL( $urlaction );
        }
 
+       /**
+        * @param $name string
+        * @param $subpage string
+        * @param $urlaction string
+        * @return String
+        */
        static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
                $title = SpecialPage::getSafeTitleFor( $name, $subpage );
                return $title->getLocalURL( $urlaction );
        }
 
+       /**
+        * @param $name string
+        * @param $urlaction string
+        * @return String
+        */
        static function makeI18nUrl( $name, $urlaction = '' ) {
                $title = Title::newFromText( wfMsgForContent( $name ) );
                self::checkTitle( $title, $name );
                return $title->getLocalURL( $urlaction );
        }
 
+       /**
+        * @param $name string
+        * @param $urlaction string
+        * @return String
+        */
        static function makeUrl( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
                self::checkTitle( $title, $name );
@@ -1007,7 +1129,13 @@ abstract class Skin extends ContextSource {
                }
        }
 
-       # this can be passed the NS number as defined in Language.php
+       /**
+        * this can be passed the NS number as defined in Language.php
+        * @param $name
+        * @param $urlaction string
+        * @param $namespace int
+        * @return String
+        */
        static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
                $title = Title::makeTitleSafe( $namespace, $name );
                self::checkTitle( $title, $name );
@@ -1015,7 +1143,12 @@ abstract class Skin extends ContextSource {
                return $title->getLocalURL( $urlaction );
        }
 
-       /* these return an array with the 'href' and boolean 'exists' */
+       /**
+        * these return an array with the 'href' and boolean 'exists'
+        * @param $name
+        * @param $urlaction string
+        * @return array
+        */
        static function makeUrlDetails( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
                self::checkTitle( $title, $name );
@@ -1042,7 +1175,12 @@ abstract class Skin extends ContextSource {
                );
        }
 
-       # make sure we have some title to operate on
+       /**
+        * make sure we have some title to operate on
+        *
+        * @param $title Title
+        * @param $name string
+        */
        static function checkTitle( &$title, $name ) {
                if ( !is_object( $title ) ) {
                        $title = Title::newFromText( $name );
@@ -1058,13 +1196,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;
@@ -1076,7 +1214,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__ );
@@ -1088,7 +1226,7 @@ abstract class Skin extends ContextSource {
         *
         * This is just a wrapper around addToSidebarPlain() for backwards compatibility
         *
-        * @param &$bar array
+        * @param $bar array
         * @param $message String
         */
        function addToSidebar( &$bar, $message ) {
@@ -1098,7 +1236,7 @@ abstract class Skin extends ContextSource {
        /**
         * Add content from plain text
         * @since 1.17
-        * @param &$bar array
+        * @param $bar array
         * @param $text string
         * @return Array
         */
@@ -1124,6 +1262,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();
@@ -1135,7 +1279,6 @@ abstract class Skin extends ContextSource {
                                        } else {
                                                $link = $line[0];
                                        }
-
                                        $msgText = $this->msg( $line[1] );
                                        if ( $msgText->exists() ) {
                                                $text = $msgText->text();
@@ -1145,13 +1288,13 @@ abstract class Skin extends ContextSource {
 
                                        if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
                                                $href = $link;
-                                               
+
                                                // Parser::getExternalLinkAttribs won't work here because of the Namespace things
                                                global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
                                                if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
                                                        $extraAttribs['rel'] = 'nofollow';
                                                }
-                                               
+
                                                global $wgExternalLinkTarget;
                                                if ( $wgExternalLinkTarget) {
                                                        $extraAttribs['target'] = $wgExternalLinkTarget;
@@ -1299,7 +1442,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;
        }
@@ -1374,7 +1517,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,
@@ -1386,7 +1529,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;
@@ -1415,6 +1558,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 );