X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=d1a0016dce311c46845ad2af8d9de1ac3fe18954;hb=e185e2b9b36babb3db1036e84f2dd2d2bccda304;hp=39d93dd3644825a8802e5986fe54dcaa3271b3f4;hpb=3226ee8f9c83a8fb42fab1bc99fa5c427e8d6ed0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 39d93dd364..d1a0016dce 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -3,8 +3,9 @@ * @defgroup Skins Skins */ -if ( ! defined( 'MEDIAWIKI' ) ) +if ( !defined( 'MEDIAWIKI' ) ) { die( 1 ); +} /** * The main skin class that provide methods and properties for all other skins. @@ -24,14 +25,17 @@ class Skin extends Linker { /**#@-*/ protected $mRevisionId; // The revision ID we're looking at, null if not applicable. protected $skinname = 'standard'; + // @todo Fixme: should be protected :-\ + var $mTitle = null; /** Constructor, call parent constructor */ - function Skin() { parent::__construct(); } + function __construct() { + parent::__construct(); + } /** * Fetch the set of available skins. * @return array of strings - * @static */ static function getSkinNames() { global $wgValidSkinNames; @@ -51,7 +55,7 @@ class Skin extends Linker { $matches = array(); if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) { $aSkin = $matches[1]; - $wgValidSkinNames[strtolower($aSkin)] = $aSkin; + $wgValidSkinNames[strtolower( $aSkin )] = $aSkin; } } $skinDir->close(); @@ -60,7 +64,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 @@ -80,9 +84,8 @@ class Skin extends Linker { * Normalize a skin preference value to a form that can be loaded. * If a skin can't be found, it will fall back to the configured * default (or the old 'Classic' skin if that's broken). - * @param string $key + * @param $key String: 'monobook', 'standard', etc. * @return string - * @static */ static function normalizeKey( $key ) { global $wgDefaultSkin; @@ -103,9 +106,10 @@ class Skin extends Linker { $fallback = array( 0 => $wgDefaultSkin, 1 => 'nostalgia', - 2 => 'cologneblue' ); + 2 => 'cologneblue' + ); - if( isset( $fallback[$key] ) ){ + if( isset( $fallback[$key] ) ) { $key = $fallback[$key]; } @@ -118,9 +122,8 @@ class Skin extends Linker { /** * Factory method for loading a skin of a given type - * @param string $key 'monobook', 'standard', etc + * @param $key String: 'monobook', 'standard', etc. * @return Skin - * @static */ static function &newFromKey( $key ) { global $wgStyleDirectory; @@ -129,13 +132,15 @@ class Skin extends Linker { $skinNames = Skin::getSkinNames(); $skinName = $skinNames[$key]; - $className = 'Skin'.ucfirst($key); + $className = 'Skin' . ucfirst( $key ); # Grab the skin class and initialise it. if ( !class_exists( $className ) ) { // Preload base classes to work around APC/PHP5 bug $deps = "{$wgStyleDirectory}/{$skinName}.deps.php"; - if( file_exists( $deps ) ) include_once( $deps ); + if( file_exists( $deps ) ) { + include_once( $deps ); + } require_once( "{$wgStyleDirectory}/{$skinName}.php" ); # Check if we got if not failback to default skin @@ -166,7 +171,9 @@ class Skin extends Linker { function qbSetting() { global $wgOut, $wgUser; - if ( $wgOut->isQuickbarSuppressed() ) { return 0; } + if ( $wgOut->isQuickbarSuppressed() ) { + return 0; + } $q = $wgUser->getOption( 'quickbar', 0 ); return $q; } @@ -178,7 +185,7 @@ class Skin extends Linker { # 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 + # uses whichever one appears later in the HTML source. Make sure # apple-touch-icon is specified first to avoid this. if( false !== $wgAppleTouchIcon ) { $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) ); @@ -227,6 +234,11 @@ class Skin extends Linker { $lb->execute(); } + /** + * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML + * output. + * @param $out Object: instance of OutputPage + */ function addMetadataLinks( OutputPage $out ) { global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgRightsPage, $wgRightsUrl; @@ -269,13 +281,13 @@ class Skin extends Linker { /** * Set some local variables */ - protected function setMembers(){ + 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 @@ -284,6 +296,15 @@ class Skin extends Linker { $this->mTitle = $t; } + /** Get the title */ + public function getTitle() { + return $this->mTitle; + } + + /** + * Outputs the HTML generated by other functions. + * @param $out Object: instance of OutputPage + */ function outputPage( OutputPage $out ) { global $wgDebugComments; wfProfileIn( __METHOD__ ); @@ -296,12 +317,6 @@ class Skin extends Linker { $out->out( $out->headElement( $this ) ); - $out->out( "\n
getBodyOptions(); - foreach ( $ops as $name => $val ) { - $out->out( " $name='$val'" ); - } - $out->out( ">\n" ); if ( $wgDebugComments ) { $out->out( "\n" ); @@ -312,7 +327,7 @@ class Skin extends Linker { $out->out( $out->mBodytext . "\n" ); $out->out( $this->afterContent() ); - + $out->out( $afterContent ); $out->out( $this->bottomScripts() ); @@ -324,37 +339,42 @@ 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 ) { - $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : ''; - $r[] = ""; - } - if( $allowUserJs && $wgUser->isLoggedIn() ) { - $userpage = $wgUser->getUserPage(); - $userjs = htmlspecialchars( self::makeUrl( - $userpage->getPrefixedText().'/'.$this->getSkinName().'.js', - 'action=raw&ctype='.$wgJsMimeType ) ); - $r[] = '"; - } - return $vars . "\t\t" . implode ( "\n\t\t", $r ); - } - /** * To make it harder for someone to slip a user a fake * user-JavaScript or user-CSS preview, a random token @@ -461,25 +469,30 @@ class Skin extends Linker { * passed back with the preview request, we won't render * the code. * - * @param string $action + * @param $action String: 'edit', 'submit' etc. * @return bool - * @private */ - function userCanPreview( $action ) { + public function userCanPreview( $action ) { global $wgRequest, $wgUser; - if( $action != 'submit' ) + if( $action != 'submit' ) { return false; - if( !$wgRequest->wasPosted() ) + } + if( !$wgRequest->wasPosted() ) { return false; - if( !$this->mTitle->userCanEditCssJsSubpage() ) + } + if( !$this->mTitle->userCanEditCssSubpage() ) { return false; + } + if( !$this->mTitle->userCanEditJsSubpage() ) { + return false; + } return $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); } /** - * generated JavaScript action=raw&gen=js + * Generated JavaScript action=raw&gen=js * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate- * nated together. For some bizarre reason, it does *not* return any * custom user JS from subpages. Huh? @@ -489,27 +502,31 @@ class Skin extends Linker { * top. For now Monobook.js will be maintained, but it should be consi- * dered deprecated. * + * @param $skinName String: If set, overrides 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' ); + $commonJs = wfMsgExt( 'common.js', 'content' ); 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 = wfMsgExt( $msgKey, 'content' ); if ( !wfEmptyMsg( $msgKey, $userJS ) ) { $s .= $userJS; } @@ -528,11 +545,11 @@ class Skin extends Linker { wfProfileOut( __METHOD__ ); return $s; } - + /** * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue */ - protected function reallyGenerateUserStylesheet(){ + protected function reallyGenerateUserStylesheet() { global $wgUser; $s = ''; if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) { @@ -542,7 +559,7 @@ class Skin extends Linker { if( $wgUser->getOption( 'highlightbroken' ) ) { $s .= "a.new, #quickbar a.new { color: #CC2200; }\n"; } else { - $s .= <<" . $this->pageTitleLinks() . "
\n"; + $s .= '' . $this->pageTitleLinks() . "
\n"; - $r = $wgContLang->isRTL() ? 'left' : 'right'; + $r = $wgContLang->alignEnd(); $s .= "