disallow embedded line breaks in ISBNs; allowing them breaks things in a most interes...
[lhc/web/wiklou.git] / includes / Skin.php
index 87dad8f..924deef 100644 (file)
@@ -48,6 +48,7 @@ class Skin extends Linker {
                        # while code from www.php.net
                        while (false !== ($file = $skinDir->read())) {
                                // Skip non-PHP files, hidden files, and '.dep' includes
+                               $matches = array();
                                if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
                                        $aSkin = $matches[1];
                                        $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
@@ -70,7 +71,7 @@ class Skin extends Linker {
         */
        static function normalizeKey( $key ) {
                global $wgDefaultSkin;
-               $skinNames = self::getSkinNames();
+               $skinNames = Skin::getSkinNames();
 
                if( $key == '' ) {
                        // Don't return the default immediately;
@@ -110,16 +111,15 @@ class Skin extends Linker {
        static function &newFromKey( $key ) {
                global $wgStyleDirectory;
                
-               $key = self::normalizeKey( $key );
+               $key = Skin::normalizeKey( $key );
 
-               $skinNames = self::getSkinNames();
+               $skinNames = Skin::getSkinNames();
                $skinName = $skinNames[$key];
 
                # Grab the skin class and initialise it.
-               wfSuppressWarnings();
                // Preload base classes to work around APC/PHP5 bug
-               include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
-               wfRestoreWarnings();
+               $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
+               if( file_exists( $deps ) ) include_once( $deps );
                require_once( "{$wgStyleDirectory}/{$skinName}.php" );
 
                # Check if we got if not failback to default skin
@@ -300,9 +300,9 @@ class Skin extends Linker {
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
                global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
 
-               $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
-               if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
-
+               $ns = $wgTitle->getNamespace();
+               $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
+               
                $vars = array( 
                        'jsmimetype' => $wgJsMimeType,
                        'skinname' => $this->getSkinName(),
@@ -324,6 +324,14 @@ class Skin extends Linker {
                $r = self::makeGlobalVariablesScript( $vars );
 
                $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
+               global $wgUseSiteJs;
+               if ($wgUseSiteJs) {
+                       if ($wgUser->isLoggedIn()) {
+                               $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&smaxage=0&gen=js'))."\"><!-- site js --></script>\n";
+                       } else {
+                               $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n";
+                       }
+               }
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
                        $userjs = htmlspecialchars( self::makeUrl(
@@ -362,7 +370,6 @@ class Skin extends Linker {
        function getUserStylesheet() {
                global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
                $sheet = $this->getStylesheet();
-               $action = $wgRequest->getText('action');
                $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
                $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
                if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
@@ -376,9 +383,27 @@ class Skin extends Linker {
        }
 
        /**
-        * placeholder, returns generated js in monobook
+        * This returns MediaWiki:Common.js.  For some bizarre reason, it does
+        * *not* return any custom user JS from user subpages.  Huh?
+        *
+        * @return string
         */
-       function getUserJs() { return; }
+       function getUserJs() {
+               $fname = 'Skin::getUserJs';
+               wfProfileIn( $fname );
+
+               global $wgStylePath;
+               $s = "/* generated javascript */\n";
+               $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
+               $s .= "\n\n/* MediaWiki:Common.js */\n";
+               $commonJs = wfMsgForContent('Common.js');
+               if ( !wfEmptyMsg ( 'Common.js', $commonJs ) ) {
+                       $s .= $commonJs;
+               }
+
+               wfProfileOut( $fname );
+               return $s;
+    }
 
        /**
         * Return html code that include User stylesheets
@@ -465,7 +490,6 @@ END;
                else $a = array( 'bgcolor' => '#FFFFFF' );
                if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
                  $wgTitle->userCanEdit() ) {
-                       $t = wfMsg( 'editthispage' );
                        $s = $wgTitle->getFullURL( $this->editUrlOptions() );
                        $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
                        $a += array ('ondblclick' => $s);
@@ -579,7 +603,7 @@ END;
                $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
 
                $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
-               $s = self::makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
+               $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
                        . ': ' . $t;
 
                # optional 'dmoz-like' category browser. Will be shown under the list
@@ -591,7 +615,7 @@ END;
                        $parenttree = $wgTitle->getParentCategoryTree();
                        # Skin object passed by reference cause it can not be
                        # accessed under the method subfunction drawCategoryBrowser
-                       $tempout = explode("\n", self::drawCategoryBrowser($parenttree, $this) );
+                       $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
                        # Clean out bogus first entry and sort them
                        unset($tempout[0]);
                        asort($tempout);
@@ -602,14 +626,12 @@ END;
                return $s;
        }
 
-       /**
-        * Render the array as a series of links.
-        * @param $tree Array categories tree returned by Title::getParentCategoryTree
-        * @param &skin Object skin passed by reference
+       /** Render the array as a serie of links.
+        * @param $tree Array: categories tree returned by Title::getParentCategoryTree
+        * @param &skin Object: skin passed by reference
         * @return String separated by &gt;, terminate with "\n"
-        * @static
         */
-       static function drawCategoryBrowser($tree, &$skin) {
+       function drawCategoryBrowser($tree, &$skin) {
                $return = '';
                foreach ($tree as $element => $parent) {
                        if (empty($parent)) {
@@ -617,11 +639,11 @@ END;
                                $return .= "\n";
                        } else {
                                # grab the others elements
-                               $return .= self::drawCategoryBrowser($parent, $skin) . ' &gt; ';
+                               $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
                        }
                        # add our current element to the list
                        $eltitle = Title::NewFromText($element);
-                       $return .= self::makeLinkObj( $eltitle, $eltitle->getText() ) ;
+                       $return .=  $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
                }
                return $return;
        }
@@ -673,7 +695,8 @@ END;
        function pageTitleLinks() {
                global $wgOut, $wgTitle, $wgUser, $wgRequest;
 
-               extract( $wgRequest->getValues( 'oldid', 'diff' ) );
+               $oldid = $wgRequest->getVal( 'oldid' );
+               $diff = $wgRequest->getVal( 'diff' );
                $action = $wgRequest->getText( 'action' );
 
                $s = $this->printableLink();
@@ -692,13 +715,13 @@ END;
                                $image = new Image( $wgTitle );
                                if( $image->exists() ) {
                                        $link = htmlspecialchars( $image->getURL() );
-                                       $style = self::getInternalLinkAttributes( $link, $name );
+                                       $style = $this->getInternalLinkAttributes( $link, $name );
                                        $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
                                }
                        }
                }
                if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
-                       $s .= ' | ' . self::makeKnownLinkObj( $wgTitle,
+                       $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
                                        wfMsg( 'currentrev' ) );
                }
 
@@ -706,8 +729,8 @@ END;
                        # do not show "You have new messages" text when we are viewing our
                        # own talk page
                        if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
-                               $tl = self::makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
-                               $dl = self::makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
+                               $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
+                               $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
                                $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
                                # disable caching
                                $wgOut->setSquidMaxage(0);
@@ -734,7 +757,7 @@ END;
                                $msg = 'viewdeleted';
                        }
                        return wfMsg( $msg,
-                               self::makeKnownLink(
+                               $this->makeKnownLink(
                                        $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
                                        wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
                }
@@ -796,7 +819,7 @@ END;
                                        $c++;
                                        if ($c<count($links)) {
                                                $growinglink .= $link;
-                                               $getlink = self::makeLink( $growinglink, htmlspecialchars( $link ) );
+                                               $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
                                                if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
                                                if ($c>1) {
                                                        $subpages .= ' | ';
@@ -815,7 +838,6 @@ END;
        function nameAndLogin() {
                global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
 
-               $li = $wgContLang->specialPage( 'Userlogin' );
                $lo = $wgContLang->specialPage( 'Userlogout' );
 
                $s = '';
@@ -823,7 +845,7 @@ END;
                        if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
                                $n = wfGetIP();
 
-                               $tl = self::makeKnownLinkObj( $wgUser->getTalkPage(),
+                               $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
                                  $wgLang->getNsText( NS_TALK ) );
 
                                $s .= $n . ' ('.$tl.')';
@@ -836,31 +858,31 @@ END;
                                $q = '';
                        } else { $q = "returnto={$rt}"; }
 
-                       $s .= "\n<br />" . self::makeKnownLinkObj(
+                       $s .= "\n<br />" . $this->makeKnownLinkObj(
                                SpecialPage::getTitleFor( 'Userlogin' ),
                                wfMsg( 'login' ), $q );
                } else {
                        $n = $wgUser->getName();
                        $rt = $wgTitle->getPrefixedURL();
-                       $tl = self::makeKnownLinkObj( $wgUser->getTalkPage(),
+                       $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
                          $wgLang->getNsText( NS_TALK ) );
 
                        $tl = " ({$tl})";
 
-                       $s .= self::makeKnownLinkObj( $wgUser->getUserPage(),
+                       $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
                          $n ) . "{$tl}<br />" .
-                         self::makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
+                         $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
                          "returnto={$rt}" ) . ' | ' .
-                         self::specialLink( 'preferences' );
+                         $this->specialLink( 'preferences' );
                }
-               $s .= ' | ' . self::makeKnownLink( wfMsgForContent( 'helppage' ),
+               $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
                  wfMsg( 'help' ) );
 
                return $s;
        }
 
        function getSearchLink() {
-               $searchPage =& SpecialPage::getTitleFor( 'Search' );
+               $searchPage = SpecialPage::getTitleFor( 'Search' );
                return $searchPage->getLocalURL();
        }
 
@@ -887,7 +909,7 @@ END;
                $sep = " |\n";
 
                $s = $this->mainPageLink() . $sep
-                 . self::specialLink( 'recentchanges' );
+                 . $this->specialLink( 'recentchanges' );
 
                if ( $wgOut->isArticleRelated() ) {
                        $s .=  $sep . $this->editThisPage()
@@ -988,7 +1010,8 @@ END;
                global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
                global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
 
-               extract( $wgRequest->getValues( 'oldid', 'diff' ) );
+               $oldid = $wgRequest->getVal( 'oldid' );
+               $diff = $wgRequest->getVal( 'diff' );
                if ( ! $wgOut->isArticle() ) { return ''; }
                if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
                if ( 0 == $wgArticle->getID() ) { return ''; }
@@ -1010,7 +1033,7 @@ END;
 
                if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
                        $dbr =& wfGetDB( DB_SLAVE );
-                       extract( $dbr->tableNames( 'watchlist' ) );
+                       $watchlist = $dbr->tableName( 'watchlist' );
                        $sql = "SELECT COUNT(*) AS n FROM $watchlist
                                WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
                                "' AND  wl_namespace=" . $wgTitle->getNamespace() ;
@@ -1044,9 +1067,9 @@ END;
 
                $out = '';
                if( $wgRightsPage ) {
-                       $link = self::makeKnownLink( $wgRightsPage, $wgRightsText );
+                       $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
                } elseif( $wgRightsUrl ) {
-                       $link = self::makeExternalLink( $wgRightsUrl, $wgRightsText );
+                       $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
                } else {
                        # Give up now
                        return $out;
@@ -1121,7 +1144,6 @@ END;
         */
        function specialPagesList() {
                global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
-               $a = array();
                $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
                foreach ( $pages as $name => $page ) {
                        $pages[$name] = $page->getDescription();
@@ -1150,12 +1172,12 @@ END;
        function mainPageLink() {
                $mp = wfMsgForContent( 'mainpage' );
                $mptxt = wfMsg( 'mainpage');
-               $s = self::makeKnownLink( $mp, $mptxt );
+               $s = $this->makeKnownLink( $mp, $mptxt );
                return $s;
        }
 
        function copyrightLink() {
-               $s = self::makeKnownLink( wfMsgForContent( 'copyrightpage' ),
+               $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
                  wfMsg( 'copyrightpagename' ) );
                return $s;
        }
@@ -1165,12 +1187,12 @@ END;
                if ($privacy == '-') {
                        return '';
                } else {
-                       return self::makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
+                       return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
                }
        }
 
        function aboutLink() {
-               $s = self::makeKnownLink( wfMsgForContent( 'aboutpage' ),
+               $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
                  wfMsg( 'aboutsite' ) );
                return $s;
        }
@@ -1180,7 +1202,7 @@ END;
                if ($disclaimers == '-') {
                        return '';
                } else {
-                       return self::makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
+                       return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
                                                     $disclaimers );
                }
        }
@@ -1197,7 +1219,7 @@ END;
                                $t = wfMsg( 'viewsource' );
                        }
 
-                       $s = self::makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
+                       $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
                }
                return $s;
        }
@@ -1226,7 +1248,7 @@ END;
                if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
                        $t = wfMsg( 'deletethispage' );
 
-                       $s = self::makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
+                       $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
                } else {
                        $s = '';
                }
@@ -1245,7 +1267,7 @@ END;
                                $t = wfMsg( 'protectthispage' );
                                $q = 'action=protect';
                        }
-                       $s = self::makeKnownLinkObj( $wgTitle, $t, $q );
+                       $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
                } else {
                        $s = '';
                }
@@ -1263,7 +1285,7 @@ END;
                                $t = wfMsg( 'watchthispage' );
                                $q = 'action=watch';
                        }
-                       $s = self::makeKnownLinkObj( $wgTitle, $t, $q );
+                       $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
                } else {
                        $s = wfMsg( 'notanarticle' );
                }
@@ -1274,7 +1296,7 @@ END;
                global $wgTitle;
 
                if ( $wgTitle->userCanMove() ) {
-                       return self::makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
+                       return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
                          wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
                } else {
                        // no message if page is protected - would be redundant
@@ -1285,14 +1307,14 @@ END;
        function historyLink() {
                global $wgTitle;
 
-               return self::makeKnownLinkObj( $wgTitle,
+               return $this->makeKnownLinkObj( $wgTitle,
                  wfMsg( 'history' ), 'action=history' );
        }
 
        function whatLinksHere() {
                global $wgTitle;
 
-               return self::makeKnownLinkObj( 
+               return $this->makeKnownLinkObj( 
                        SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ), 
                        wfMsg( 'whatlinkshere' ) );
        }
@@ -1300,7 +1322,7 @@ END;
        function userContribsLink() {
                global $wgTitle;
 
-               return self::makeKnownLinkObj( 
+               return $this->makeKnownLinkObj( 
                        SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
                        wfMsg( 'contributions' ) );
        }
@@ -1319,7 +1341,7 @@ END;
        function emailUserLink() {
                global $wgTitle;
 
-               return self::makeKnownLinkObj( 
+               return $this->makeKnownLinkObj( 
                        SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
                        wfMsg( 'emailuser' ) );
        }
@@ -1330,7 +1352,7 @@ END;
                if ( ! $wgOut->isArticleRelated() ) {
                        return '(' . wfMsg( 'notanarticle' ) . ')';
                } else {
-                       return self::makeKnownLinkObj( 
+                       return $this->makeKnownLinkObj( 
                                SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ), 
                                wfMsg( 'recentchangeslinked' ) );
                }
@@ -1367,7 +1389,7 @@ END;
                        $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
 
                        if ( '' == $text ) { $text = $l; }
-                       $style = self::getExternalLinkAttributes( $l, $text );
+                       $style = $this->getExternalLinkAttributes( $l, $text );
                        $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
                }
                if($wgContLang->isRTL()) $s .= '</span>';
@@ -1375,7 +1397,7 @@ END;
        }
 
        function bugReportsLink() {
-               $s = self::makeKnownLink( wfMsgForContent( 'bugreportspage' ),
+               $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
                  wfMsg( 'bugreports' ) );
                return $s;
        }
@@ -1387,18 +1409,18 @@ END;
                $id = $t1->getArticleID();
 
                if ( 0 == $id ) {
-                       $s = self::makeBrokenLink( $t1->getText() );
+                       $s = $this->makeBrokenLink( $t1->getText() );
                } else {
-                       $s = self::makeKnownLink( $t1->getText() );
+                       $s = $this->makeKnownLink( $t1->getText() );
                }
                $s .= ', ';
 
                $id = $t2->getArticleID();
 
                if ( 0 == $id ) {
-                       $s .= self::makeBrokenLink( $t2->getText() );
+                       $s .= $this->makeBrokenLink( $t2->getText() );
                } else {
-                       $s .= self::makeKnownLink( $t2->getText() );
+                       $s .= $this->makeKnownLink( $t2->getText() );
                }
                return $s;
        }
@@ -1446,7 +1468,7 @@ END;
                        $text = wfMsg( 'talkpage' );
                }
 
-               $s = self::makeLinkObj( $link, $text );
+               $s = $this->makeLinkObj( $link, $text );
 
                return $s;
        }
@@ -1469,7 +1491,7 @@ END;
                        $title =& $wgTitle->getTalkPage();
                }
                
-               return self::makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
+               return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
        }
 
        /* these are used extensively in SkinTemplate, but also some other places */
@@ -1606,7 +1628,7 @@ END;
                        }
                }
                if ($cacheSidebar)
-                       $cachednotice = $parserMemc->set( $key, $bar, 86400 );
+                       $parserMemc->set( $key, $bar, 86400 );
                wfProfileOut( $fname );
                return $bar;
        }