X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSkin.php;h=17da161abe3bfbeba3798e057238d34cb6c5c1ef;hb=9e638dbef402377fb1c02f7228ec2fa611ee7aa0;hp=425aa83ca87152eec70ffdf58b335b13566f5e9e;hpb=d0aeaa55ff1a1fa0aaa554f5b98c5f9c075878f3;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Skin.php b/includes/Skin.php index 425aa83ca8..17da161abe 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 @@ -196,7 +198,7 @@ class Skin extends Linker { 'title' => wfMsgForContent( 'opensearch-desc' ), )); - $this->addMetadataLinks($out); + $this->addMetadataLinks( $out ); $this->mRevisionId = $out->mRevisionId; @@ -209,18 +211,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 +230,7 @@ class Skin extends Linker { } function addMetadataLinks( OutputPage $out ) { - global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; + global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf; global $wgRightsPage, $wgRightsUrl; if( $out->isArticleRelated() ) { @@ -237,13 +239,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 +263,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 +319,7 @@ class Skin extends Linker { $out->out( $out->mBodytext . "\n" ); $out->out( $this->afterContent() ); - + $out->out( $afterContent ); $out->out( $this->bottomScripts() ); @@ -311,36 +331,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 @@ -448,16 +479,17 @@ class Skin extends Linker { * * @param string $action * @return bool - * @private */ - function userCanPreview( $action ) { - global $wgTitle, $wgRequest, $wgUser; + public function userCanPreview( $action ) { + global $wgRequest, $wgUser; if( $action != 'submit' ) return false; if( !$wgRequest->wasPosted() ) return false; - if( !$wgTitle->userCanEditCssJsSubpage() ) + if( !$this->mTitle->userCanEditCssSubpage() ) + return false; + if( !$this->mTitle->userCanEditJsSubpage() ) return false; return $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ); @@ -474,27 +506,32 @@ class Skin extends Linker { * top. For now Monobook.js will be maintained, but it should be consi- * dered deprecated. * + * @param $force_skin 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 = 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 +541,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 +550,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 +588,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; } @@ -571,8 +612,8 @@ END; ); // Add any extension CSS - foreach( $out->getExtStyle() as $tag ) { - $out->addStyle( $tag['href'] ); + foreach ( $out->getExtStyle() as $url ) { + $out->addStyle( $url ); } // If we use the site's dynamic CSS, throw that in, too @@ -608,14 +649,13 @@ 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'); // @FIXME: properly escape the cdata! - $this->usercss = "/**/"; + $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) ); } 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 +675,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() ); + 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 += array( 'ondblclick' => $s ); } $a['onload'] = $wgOut->getOnloadHandler(); $a['class'] = 'mediawiki' . - ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ). - ' '.$this->getPageClasses( $wgTitle ) . - ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) ); + ' '.( $wgContLang->getDir() ). + ' '.$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 +729,7 @@ END; function doBeforeContent() { global $wgContLang; - $fname = 'Skin::doBeforeContent'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); $s = ''; $qb = $this->qbSetting(); @@ -718,13 +756,13 @@ END; } elseif( $left ) { $s .= $this->getQuickbarCompensator( $rows ); } - $l = $wgContLang->isRTL() ? 'right' : 'left'; + $l = $wgContLang->alignStart(); $s .= "
" . $this->pageTitleLinks() . "
\n"; - $r = $wgContLang->isRTL() ? "left" : "right"; + $r = $wgContLang->alignEnd(); $s .= "