X-Git-Url: http://git.cyclocoop.org/%28?a=blobdiff_plain;f=includes%2FSkin.php;h=8f7a950077d2e132a2fd6ed5c7164f5c8f63c7f3;hb=4c2d645ef3966dc75fa4c4aa6cbe2b5d87c60c69;hp=42d3e962719ae944c68ad6e34fec56d0f2354a9c;hpb=af10d342867fa603945651c1a4e74df9ae319957;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 42d3e96271..8f7a950077 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -23,7 +23,9 @@ class Skin extends Linker { protected $searchboxes = ''; /**#@-*/ protected $mRevisionId; // The revision ID we're looking at, null if not applicable. - protected $skinname = 'standard' ; + protected $skinname = 'standard'; + // @fixme Should be protected :-\ + var $mTitle = null; /** Constructor, call parent constructor */ function Skin() { parent::__construct(); } @@ -46,10 +48,10 @@ class Skin extends Linker { $skinDir = dir( $wgStyleDirectory ); # while code from www.php.net - while (false !== ($file = $skinDir->read())) { + while( false !== ( $file = $skinDir->read() ) ) { // Skip non-PHP files, hidden files, and '.dep' includes $matches = array(); - if(preg_match('/^([^.]*)\.php$/',$file, $matches)) { + if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { $aSkin = $matches[1]; $wgValidSkinNames[strtolower($aSkin)] = $aSkin; } @@ -60,7 +62,7 @@ class Skin extends Linker { } return $wgValidSkinNames; } - + /** * Fetch the list of usable skins in regards to $wgSkipSkins. * Useful for Special:Preferences and other places where you @@ -176,15 +178,17 @@ class Skin extends Linker { wfProfileIn( __METHOD__ ); + # Add favicons and Apple touch icons, if they're not the defaults + # # Generally the order of the favicon and apple-touch-icon links # should not matter, but Konqueror (3.5.9 at least) incorrectly # uses whichever one appears later in the HTML source. Make sure # apple-touch-icon is specified first to avoid this. - if( false !== $wgAppleTouchIcon ) { + if( false !== $wgAppleTouchIcon && wfExpandUrl('/apple-touch-icon.png') != wfExpandUrl($wgAppleTouchIcon) ) { $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); } - if( false !== $wgFavicon ) { + if( false !== $wgFavicon && wfExpandUrl('/favicon.ico') != wfExpandUrl($wgFavicon) ) { $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) ); } @@ -196,7 +200,7 @@ class Skin extends Linker { 'title' => wfMsgForContent( 'opensearch-desc' ), )); - $this->addMetadataLinks($out); + $this->addMetadataLinks( $out ); $this->mRevisionId = $out->mRevisionId; @@ -209,18 +213,18 @@ class Skin extends Linker { * Preload the existence of three commonly-requested pages in a single query */ function preloadExistence() { - global $wgUser, $wgTitle; + global $wgUser; // User/talk link $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() ); // Other tab link - if ( $wgTitle->getNamespace() == NS_SPECIAL ) { + if ( $this->mTitle->getNamespace() == NS_SPECIAL ) { // nothing - } elseif ( $wgTitle->isTalkPage() ) { - $titles[] = $wgTitle->getSubjectPage(); + } elseif ( $this->mTitle->isTalkPage() ) { + $titles[] = $this->mTitle->getSubjectPage(); } else { - $titles[] = $wgTitle->getTalkPage(); + $titles[] = $this->mTitle->getTalkPage(); } $lb = new LinkBatch( $titles ); @@ -228,7 +232,7 @@ class Skin extends Linker { } function addMetadataLinks( OutputPage $out ) { - global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; + global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgRightsPage, $wgRightsUrl; if( $out->isArticleRelated() ) { @@ -237,13 +241,15 @@ class Skin extends Linker { $out->addMetadataLink( array( 'title' => 'Creative Commons', 'type' => 'application/rdf+xml', - 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) ); + 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) ) + ); } if( $wgEnableDublinCoreRdf ) { $out->addMetadataLink( array( 'title' => 'Dublin Core', 'type' => 'application/rdf+xml', - 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) ); + 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) ) + ); } } $copyright = ''; @@ -259,18 +265,34 @@ class Skin extends Linker { if( $copyright ) { $out->addLink( array( 'rel' => 'copyright', - 'href' => $copyright ) ); + 'href' => $copyright ) + ); } } - function setMembers(){ - global $wgTitle, $wgUser; - $this->mTitle = $wgTitle; + /** + * Set some local variables + */ + protected function setMembers(){ + global $wgUser; $this->mUser = $wgUser; $this->userpage = $wgUser->getUserPage()->getPrefixedText(); $this->usercss = false; } + /** + * Set the title + * @param Title $t The title to use + */ + public function setTitle( $t ) { + $this->mTitle = $t; + } + + /** Get the title */ + public function getTitle() { + return $this->mTitle; + } + function outputPage( OutputPage $out ) { global $wgDebugComments; wfProfileIn( __METHOD__ ); @@ -299,7 +321,7 @@ class Skin extends Linker { $out->out( $out->mBodytext . "\n" ); $out->out( $this->afterContent() ); - + $out->out( $afterContent ); $out->out( $this->bottomScripts() ); @@ -313,26 +335,29 @@ class Skin extends Linker { static function makeVariablesScript( $data ) { global $wgJsMimeType; - $r = array( "\n"; - return implode( "\n\t\t", $r ); } /** * Make a " ); - global $wgUseSiteJs; - if ($wgUseSiteJs) { + //moved wikibits to be called earlier on + //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" ); + if( $wgUseSiteJs ) { $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; - $r[] = ""; + urlencode( $this->getSkinName() ) + ) + ); } - if( $allowUserJs && $wgUser->isLoggedIn() ) { + if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); - $userjs = htmlspecialchars( self::makeUrl( + $userjs = self::makeUrl( $userpage->getPrefixedText().'/'.$this->getSkinName().'.js', - 'action=raw&ctype='.$wgJsMimeType)); - $r[] = '"; + 'action=raw&ctype='.$wgJsMimeType ); + $wgOut->addScriptFile( $userjs ); } - return $vars . "\t\t" . implode ( "\n\t\t", $r ); + return "\t" . $vars . "\t" . $out->mScripts; } /** @@ -451,13 +499,13 @@ class Skin extends Linker { * @private */ function userCanPreview( $action ) { - global $wgTitle, $wgRequest, $wgUser; + global $wgRequest, $wgUser; if( $action != 'submit' ) return false; if( !$wgRequest->wasPosted() ) return false; - if( !$wgTitle->userCanEditCssJsSubpage() ) + if( !$this->mTitle->userCanEditCssJsSubpage() ) return false; return $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); @@ -474,27 +522,32 @@ class Skin extends Linker { * top. For now Monobook.js will be maintained, but it should be consi- * dered deprecated. * + * @param force_skin lets you override the skin name + * * @return string */ - public function generateUserJs() { + public function generateUserJs( $skinName = null) { global $wgStylePath; wfProfileIn( __METHOD__ ); + if(!$skinName){ + $skinName = $this->getSkinName(); + } $s = "/* generated javascript */\n"; - $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n"; + $s .= "var skin = '" . Xml::escapeJsString($skinName ) . "';\n"; $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';"; $s .= "\n\n/* MediaWiki:Common.js */\n"; - $commonJs = wfMsgForContent('common.js'); - if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) { + $commonJs = wfMsgForContent( 'common.js' ); + if ( !wfEmptyMsg( 'common.js', $commonJs ) ) { $s .= $commonJs; } - $s .= "\n\n/* MediaWiki:".ucfirst( $this->getSkinName() ).".js */\n"; + $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n"; // avoid inclusion of non defined user JavaScript (with custom skins only) // by checking for default message content - $msgKey = ucfirst( $this->getSkinName() ).'.js'; - $userJS = wfMsgForContent($msgKey); + $msgKey = ucfirst( $skinName ).'.js'; + $userJS = wfMsgForContent( $msgKey ); if ( !wfEmptyMsg( $msgKey, $userJS ) ) { $s .= $userJS; } @@ -504,7 +557,7 @@ class Skin extends Linker { } /** - * generate user stylesheet for action=raw&gen=css + * Generate user stylesheet for action=raw&gen=css */ public function generateUserStylesheet() { wfProfileIn( __METHOD__ ); @@ -513,14 +566,14 @@ class Skin extends Linker { wfProfileOut( __METHOD__ ); return $s; } - + /** * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue */ protected function reallyGenerateUserStylesheet(){ global $wgUser; $s = ''; - if (($undopt = $wgUser->getOption("underline")) < 2) { + if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) { $underline = $undopt ? 'underline' : 'none'; $s .= "a { text-decoration: $underline; }\n"; } @@ -551,6 +604,10 @@ END; if( !$wgUser->getOption( 'editsection' ) ) { $s .= ".editsection { display: none; }\n"; } + $fontstyle = $wgUser->getOption( 'editfont' ); + if ( $fontstyle !== 'default' ) { + $s .= "textarea { font-family: $fontstyle; }\n"; + } return $s; } @@ -608,14 +665,14 @@ END; // Per-user custom style pages if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { - $action = $wgRequest->getVal('action'); + $action = $wgRequest->getVal( 'action' ); # If we're previewing the CSS page, use it if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) { - $previewCss = $wgRequest->getText('wpTextbox1'); + $previewCss = $wgRequest->getText( 'wpTextbox1' ); // @FIXME: properly escape the cdata! $this->usercss = "/**/"; } else { - $out->addStyle( self::makeUrl($this->userpage . '/' . $this->getSkinName() .'.css', + $out->addStyle( self::makeUrl( $this->userpage . '/' . $this->getSkinName() .'.css', 'action=raw&ctype=text/css' ) ); } } @@ -635,38 +692,37 @@ END; } function getBodyOptions() { - global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang; + global $wgUser, $wgOut, $wgRequest, $wgContLang; extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) ); - if ( 0 != $wgTitle->getNamespace() ) { + if ( 0 != $this->mTitle->getNamespace() ) { $a = array( 'bgcolor' => '#ffffec' ); } else $a = array( 'bgcolor' => '#FFFFFF' ); - if($wgOut->isArticle() && $wgUser->getOption('editondblclick') && - $wgTitle->quickUserCan( 'edit' ) ) { - $s = $wgTitle->getFullURL( $this->editUrlOptions() ); - $s = 'document.location = "' .wfEscapeJSString( $s ) .'";'; - $a += array ('ondblclick' => $s); - + if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) && + $this->mTitle->quickUserCan( 'edit' ) ) { + $s = $this->mTitle->getFullURL( $this->editUrlOptions() ); + $s = 'document.location = "' .Xml::escapeJsString( $s ) .'";'; + $a += array( 'ondblclick' => $s ); } $a['onload'] = $wgOut->getOnloadHandler(); $a['class'] = 'mediawiki' . - ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ). - ' '.$this->getPageClasses( $wgTitle ) . - ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) ); + ' '.( $wgContLang->isRTL() ? 'rtl' : 'ltr' ). + ' '.$this->getPageClasses( $this->mTitle ) . + ' skin-'. Sanitizer::escapeClass( $this->getSkinName() ); return $a; } - + function getPageClasses( $title ) { $numeric = 'ns-'.$title->getNamespace(); if( $title->getNamespace() == NS_SPECIAL ) { - $type = "ns-special"; + $type = 'ns-special'; } elseif( $title->isTalkPage() ) { - $type = "ns-talk"; + $type = 'ns-talk'; } else { - $type = "ns-subject"; + $type = 'ns-subject'; } $name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() ); return "$numeric $type $name"; @@ -690,8 +746,7 @@ END; function doBeforeContent() { global $wgContLang; - $fname = 'Skin::doBeforeContent'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); $s = ''; $qb = $this->qbSetting(); @@ -721,10 +776,10 @@ END; $l = $wgContLang->isRTL() ? 'right' : 'left'; $s .= "
" . $this->pageTitleLinks() . "
\n"; - $r = $wgContLang->isRTL() ? "left" : "right"; + $r = $wgContLang->isRTL() ? 'left' : 'right'; $s .= "