r56770 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56769‎ | r56770 | r56771 >
Date:16:52, 22 September 2009
Author:ialex
Status:ok
Tags:
Comment:
* (bug 20631) Preview of personal JavaScript and CSS pages now works again
* introduced SkinTemplate::$useHeadElement as switch for backward compatibility for extension skins using the old way of generating the <head> element:
** false (default): no change from previous version
** true: <head> specific items set in SkinTemplate::outputPage() are no longer generated (avoid double execution of some functions) and the result of OutputPage::headElement() is stored in the 'headelement' item
* updated all core skin to use this new method, some extensions using MonoBookTemplate but not extending SkinMonoBook (or for other core skins) will need to set $useHeadElement to true to work properly though
* Made Skin::userCanPreview() public since it's needed in OutputPage::getHeadScripts()
* Pass the Skin object from OutputPage::headElement() to OutputPage::getHeadScripts() rather than getting it from $wgUser
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/Chick.php (modified) (history)
  • /trunk/phase3/skins/Modern.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)
  • /trunk/phase3/skins/MySkin.php (modified) (history)
  • /trunk/phase3/skins/Simple.php (modified) (history)
  • /trunk/phase3/skins/Vector.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Simple.php
@@ -19,7 +19,7 @@
2020 */
2121 class SkinSimple extends SkinTemplate {
2222 var $skinname = 'simple', $stylename = 'simple',
23 - $template = 'MonoBookTemplate';
 23+ $template = 'MonoBookTemplate', $useHeadElement = true;
2424
2525 function setupSkinUserCss( OutputPage $out ){
2626 $out->addStyle( 'simple/main.css', 'screen' );
Index: trunk/phase3/skins/Vector.php
@@ -19,7 +19,7 @@
2020
2121 /* Functions */
2222 var $skinname = 'vector', $stylename = 'vector',
23 - $template = 'VectorTemplate';
 23+ $template = 'VectorTemplate', $useHeadElement = true;
2424
2525 /**
2626 * Initializes output page and sets up skin-specific parameters
@@ -459,7 +459,7 @@
460460 array_reverse( $this->data['personal_urls'] );
461461 }
462462 // Output HTML Page
463 - echo $wgOut->headElement( $this->skin );
 463+ $this->html( 'headelement' );
464464 ?>
465465 <body<?php if ( $this->data['body_ondblclick'] ): ?> ondblclick="<?php $this->text( 'body_ondblclick' ) ?>"<?php endif; ?> <?php if ( $this->data['body_onload'] ): ?> onload="<?php $this->text( 'body_onload' ) ?>"<?php endif; ?> class="mediawiki <?php $this->text( 'dir' ) ?> <?php $this->text( 'pageclass' ) ?> <?php $this->text( 'skinnameclass' ) ?>" dir="<?php $this->text( 'dir' ) ?>">
466466 <div id="page-base" class="noprint"></div>
Index: trunk/phase3/skins/MySkin.php
@@ -16,5 +16,5 @@
1717 */
1818 class SkinMySkin extends SkinTemplate {
1919 var $skinname = 'myskin', $stylename = 'myskin',
20 - $template = 'MonoBookTemplate';
 20+ $template = 'MonoBookTemplate', $useHeadElement = true;
2121 }
Index: trunk/phase3/skins/Chick.php
@@ -18,12 +18,8 @@
1919 * @ingroup Skins
2020 */
2121 class SkinChick extends SkinTemplate {
22 - function initPage( OutputPage $out ) {
23 - parent::initPage( $out );
24 - $this->skinname = 'chick';
25 - $this->stylename = 'chick';
26 - $this->template = 'MonoBookTemplate';
27 - }
 22+ var $skinname = 'chick', $stylename = 'chick',
 23+ $template = 'MonoBookTemplate', $useHeadElement = true;
2824
2925 function setupSkinUserCss( OutputPage $out ){
3026 parent::setupSkinUserCss( $out );
Index: trunk/phase3/skins/MonoBook.php
@@ -21,10 +21,10 @@
2222 class SkinMonoBook extends SkinTemplate {
2323 /** Using monobook. */
2424 var $skinname = 'monobook', $stylename = 'monobook',
25 - $template = 'MonoBookTemplate';
 25+ $template = 'MonoBookTemplate', $useHeadElement = true;
2626
2727 function setupSkinUserCss( OutputPage $out ) {
28 - global $wgHandheldStyle;
 28+ global $wgHandheldStyle, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
2929
3030 parent::setupSkinUserCss( $out );
3131
@@ -42,14 +42,13 @@
4343
4444 $out->addStyle( 'monobook/rtl.css', 'screen', '', 'rtl' );
4545
46 -
47 - // @todo We can move this to the parent once we update all the skins
48 - if( isset( $this->pagecss ) && $this->pagecss )
49 - $out->addInlineStyle( $this->pagecss );
50 -
51 - if( isset( $this->usercss ) && $this->usercss )
52 - $out->addInlineStyle( $this->usercss );
53 -
 46+ # FIXME: What is this? Should it apply to all skins?
 47+ $path = htmlspecialchars( $wgStylePath );
 48+ $out->addScript( <<<HTML
 49+<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
 50+ <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
 51+HTML
 52+ );
5453 }
5554 }
5655
@@ -68,23 +67,15 @@
6968 * @access private
7069 */
7170 function execute() {
72 - global $wgRequest, $wgOut, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
 71+ global $wgRequest;
 72+
7373 $this->skin = $skin = $this->data['skin'];
7474 $action = $wgRequest->getText( 'action' );
7575
7676 // Suppress warnings to prevent notices about missing indexes in $this->data
7777 wfSuppressWarnings();
7878
79 - # FIXME: What is this? Should it apply to all skins?
80 - $path = htmlspecialchars( $wgStylePath );
81 - $wgOut->addScript( <<<HTML
82 -<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
83 - <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
84 -HTML
85 - );
86 -
87 - echo $wgOut->headElement( $this->skin );
88 -
 79+ $this->html( 'headelement' );
8980 ?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
9081 <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
9182 class="mediawiki <?php $this->text('dir'); $this->text('capitalizeallnouns') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
Index: trunk/phase3/skins/Modern.php
@@ -17,7 +17,7 @@
1818 */
1919 class SkinModern extends SkinTemplate {
2020 var $skinname = 'modern', $stylename = 'modern',
21 - $template = 'ModernTemplate';
 21+ $template = 'ModernTemplate', $useHeadElement = true;
2222
2323 /*
2424 * We don't like the default getPoweredBy, the icon clashes with the
@@ -29,11 +29,20 @@
3030 }
3131
3232 function setupSkinUserCss( OutputPage $out ){
 33+ global $wgStyleVersion, $wgJsMimeType, $wgStylePath;
 34+
3335 // Do not call parent::setupSkinUserCss(), we have our own print style
3436 $out->addStyle( 'common/shared.css', 'screen' );
3537 $out->addStyle( 'modern/main.css', 'screen' );
3638 $out->addStyle( 'modern/print.css', 'print' );
3739 $out->addStyle( 'modern/rtl.css', 'screen', '', 'rtl' );
 40+
 41+ $path = htmlspecialchars( $wgStylePath );
 42+ $out->addScript( <<<HTML
 43+<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
 44+ <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
 45+HTML
 46+ );
3847 }
3948 }
4049
@@ -59,13 +68,7 @@
6069 // Suppress warnings to prevent notices about missing indexes in $this->data
6170 wfSuppressWarnings();
6271
63 - $wgOut->addScript( <<<HTML
64 -<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
65 - <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
66 -HTML
67 - );
68 -
69 - echo $wgOut->headElement( $this->skin );
 72+ $this->html( 'headelement' );
7073 ?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
7174 <?php if($this->data['body_onload' ]) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
7275 class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
Index: trunk/phase3/includes/OutputPage.php
@@ -1724,7 +1724,7 @@
17251725 *
17261726 * @param $sk Skin The given Skin
17271727 */
1728 - public function headElement( Skin $sk , $includeStyle = true ) {
 1728+ public function headElement( Skin $sk, $includeStyle = true ) {
17291729 global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
17301730 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
17311731 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgEnableScriptLoader, $wgHtml5;
@@ -1764,7 +1764,7 @@
17651765 $ret .= implode( "\n", array(
17661766 $this->getHeadLinks(),
17671767 $this->buildCssLinks(),
1768 - $this->getHeadScripts(),
 1768+ $this->getHeadScripts( $sk ),
17691769 $this->getHeadItems(),
17701770 ));
17711771 if( $sk->usercss ){
@@ -1786,19 +1786,24 @@
17871787 *
17881788 * also adds userjs to the end if enabled:
17891789 */
1790 - function getHeadScripts() {
1791 - global $wgUser, $wgJsMimeType;
1792 - $sk = $wgUser->getSkin();
 1790+ function getHeadScripts( Skin $sk ) {
 1791+ global $wgUser, $wgRequest, $wgJsMimeType;
17931792
17941793 $vars = Skin::makeGlobalVariablesScript( $sk->getSkinName() );
17951794
17961795 //add user js if enabled:
17971796 if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
1798 - $userpage = $wgUser->getUserPage();
1799 - $userjs = Skin::makeUrl(
1800 - $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
1801 - 'action=raw&ctype=' . $wgJsMimeType );
1802 - $this->addScriptFile( $userjs );
 1797+ $action = $wgRequest->getVal( 'action', 'view' );
 1798+ if( $this->mTitle->isJsSubpage() and $sk->userCanPreview( $action ) ) {
 1799+ # XXX: additional security check/prompt?
 1800+ $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
 1801+ } else {
 1802+ $userpage = $wgUser->getUserPage();
 1803+ $userjs = Skin::makeUrl(
 1804+ $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
 1805+ 'action=raw&ctype=' . $wgJsMimeType );
 1806+ $this->addScriptFile( $userjs );
 1807+ }
18031808 }
18041809
18051810 return $vars . "\n" . $this->mScripts;
Index: trunk/phase3/includes/SkinTemplate.php
@@ -87,6 +87,12 @@
8888 */
8989 var $template = 'QuickTemplate';
9090
 91+ /**
 92+ * Whether this skin use OutputPage::headElement() to generate the <head>
 93+ * tag
 94+ */
 95+ var $useHeadElement = false;
 96+
9197 /**#@-*/
9298
9399 /**
@@ -171,12 +177,48 @@
172178 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
173179 }
174180
175 - $this->userjs = $this->userjsprev = false;
176 - $this->setupUserCss( $out );
177 - $this->setupUserJs( $out->isUserJsAllowed() );
178181 $this->titletxt = $this->mTitle->getPrefixedText();
179182 wfProfileOut( __METHOD__ . '-stuff' );
180183
 184+ wfProfileIn( __METHOD__ . '-stuff-head' );
 185+ if ( $this->useHeadElement ) {
 186+ $pagecss = $this->setupPageCss();
 187+ if( $pagecss )
 188+ $out->addInlineStyle( $pagecss );
 189+ } else {
 190+ $this->setupUserCss( $out );
 191+
 192+ $tpl->set( 'pagecss', $this->setupPageCss() );
 193+ $tpl->setRef( 'usercss', $this->usercss );
 194+
 195+ $this->userjs = $this->userjsprev = false;
 196+ $this->setupUserJs( $out->isUserJsAllowed() );
 197+ $tpl->setRef( 'userjs', $this->userjs );
 198+ $tpl->setRef( 'userjsprev', $this->userjsprev );
 199+
 200+ if( $wgUseSiteJs ) {
 201+ $jsCache = $this->loggedin ? '&smaxage=0' : '';
 202+ $tpl->set( 'jsvarurl',
 203+ self::makeUrl( '-',
 204+ "action=raw$jsCache&gen=js&useskin=" .
 205+ urlencode( $this->getSkinName() ) ) );
 206+ } else {
 207+ $tpl->set( 'jsvarurl', false );
 208+ }
 209+
 210+ $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
 211+ $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
 212+ $tpl->set( 'headlinks', $out->getHeadLinks() );
 213+ $tpl->set( 'csslinks', $out->buildCssLinks() );
 214+
 215+ if( $wgUseTrackbacks && $out->isArticleRelated() ) {
 216+ $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
 217+ } else {
 218+ $tpl->set( 'trackbackhtml', null );
 219+ }
 220+ }
 221+ wfProfileOut( __METHOD__ . '-stuff-head' );
 222+
181223 wfProfileIn( __METHOD__ . '-stuff2' );
182224 $tpl->set( 'title', $out->getPageTitle() );
183225 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
@@ -224,19 +266,10 @@
225267 } else {
226268 $tpl->set( 'feeds', false );
227269 }
228 - if( $wgUseTrackbacks && $out->isArticleRelated() ) {
229 - $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
230 - } else {
231 - $tpl->set( 'trackbackhtml', null );
232 - }
233270
234 - $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
235 - $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
236271 $tpl->setRef( 'mimetype', $wgMimeType );
237272 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
238273 $tpl->setRef( 'charset', $wgOutputEncoding );
239 - $tpl->set( 'headlinks', $out->getHeadLinks() );
240 - $tpl->set( 'csslinks', $out->buildCssLinks() );
241274 $tpl->setRef( 'wgScript', $wgScript );
242275 $tpl->setRef( 'skinname', $this->skinname );
243276 $tpl->set( 'skinclass', get_class( $this ) );
@@ -271,19 +304,6 @@
272305 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
273306 $tpl->set( 'userlang', $wgLang->getCode() );
274307 $tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
275 - $tpl->set( 'pagecss', $this->setupPageCss() );
276 - $tpl->setRef( 'usercss', $this->usercss );
277 - $tpl->setRef( 'userjs', $this->userjs );
278 - $tpl->setRef( 'userjsprev', $this->userjsprev );
279 - if( $wgUseSiteJs ) {
280 - $jsCache = $this->loggedin ? '&smaxage=0' : '';
281 - $tpl->set( 'jsvarurl',
282 - self::makeUrl( '-',
283 - "action=raw$jsCache&gen=js&useskin=" .
284 - urlencode( $this->getSkinName() ) ) );
285 - } else {
286 - $tpl->set( 'jsvarurl', false );
287 - }
288308
289309 $newtalks = $wgUser->getNewMessageLinks();
290310
@@ -463,7 +483,11 @@
464484 $tpl->set( 'nav_urls', $this->buildNavUrls() );
465485
466486 // Set the head scripts near the end, in case the above actions resulted in added scripts
467 - $tpl->set( 'headscripts', $out->getScript() );
 487+ if ( $this->useHeadElement ) {
 488+ $tpl->set( 'headelement', $out->headElement( $this ) );
 489+ } else {
 490+ $tpl->set( 'headscripts', $out->getScript() );
 491+ }
468492
469493 // original version by hansm
470494 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
Index: trunk/phase3/includes/Skin.php
@@ -463,9 +463,8 @@
464464 *
465465 * @param string $action
466466 * @return bool
467 - * @private
468467 */
469 - function userCanPreview( $action ) {
 468+ public function userCanPreview( $action ) {
470469 global $wgRequest, $wgUser;
471470
472471 if( $action != 'submit' )
@@ -637,9 +636,8 @@
638637 $action = $wgRequest->getVal( 'action' );
639638 # If we're previewing the CSS page, use it
640639 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
641 - $previewCss = $wgRequest->getText( 'wpTextbox1' );
642640 // @FIXME: properly escape the cdata!
643 - $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
 641+ $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
644642 } else {
645643 $out->addStyle( self::makeUrl( $this->userpage . '/' . $this->getSkinName() .'.css',
646644 'action=raw&ctype=text/css' ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r61728MonoBook: remove three unused globals which were added in r56770 to support l...ashley20:26, 30 January 2010

Status & tagging log