X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=7ed2626a9ed3ba011e19f471889a88031c774b45;hb=8bc618945da51980ab525cdfc470025cf1ae83f1;hp=5d2f037e73fe0e60e49244cf8a0976f2b967022f;hpb=8fe0d42524116c6935a1574f2928e552e2b11bb5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 5d2f037e73..7ed2626a9e 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. @@ -23,15 +24,18 @@ 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'; + // @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; @@ -46,12 +50,12 @@ 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; + $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 ) ); @@ -196,7 +203,7 @@ class Skin extends Linker { 'title' => wfMsgForContent( 'opensearch-desc' ), )); - $this->addMetadataLinks($out); + $this->addMetadataLinks( $out ); $this->mRevisionId = $out->mRevisionId; @@ -209,26 +216,31 @@ 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 ); $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 $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; + global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgRightsPage, $wgRightsUrl; if( $out->isArticleRelated() ) { @@ -237,13 +249,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 +273,38 @@ 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 $t Title object to use + */ + public function setTitle( $t ) { + $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__ ); @@ -283,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" ); @@ -299,7 +327,7 @@ class Skin extends Linker { $out->out( $out->mBodytext . "\n" ); $out->out( $this->afterContent() ); - + $out->out( $afterContent ); $out->out( $this->bottomScripts() ); @@ -311,36 +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 @@ -446,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 ) { - global $wgTitle, $wgRequest, $wgUser; + 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->userCanEditCssSubpage() ) { return false; - if( !$wgTitle->userCanEditCssJsSubpage() ) + } + 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? @@ -474,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'); - if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) { + $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; } @@ -504,7 +536,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,21 +545,20 @@ class Skin extends Linker { wfProfileOut( __METHOD__ ); return $s; } - + /** * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue + * Anything in here won't be generated if $wgAllowUserCssPrefs is false. */ - protected function reallyGenerateUserStylesheet(){ + 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"; } - if( $wgUser->getOption( 'highlightbroken' ) ) { - $s .= "a.new, #quickbar a.new { color: #CC2200; }\n"; - } else { - $s .= <<" . $this->pageTitleLinks() . "
\n"; + $s .= $this->topLinks(); + $s .= '' . $this->pageTitleLinks() . "
\n"; - $r = $wgContLang->isRTL() ? "left" : "right"; + $r = $wgContLang->alignEnd(); $s .= "