r111029 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111028‎ | r111029 | r111030 >
Date:11:04, 9 February 2012
Author:catrope
Status:ok
Tags:
Comment:
(bug 34289) user.options CSS loaded twice. Fixed by splitting off the CSS part of user.options into a separate module (user.cssprefs), as per the fixme comment added in r93363. No RELEASE-NOTEs because this is a regression fix that I'm gonna tag for backporting to 1.19
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php (added) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php (modified) (history)
  • /trunk/phase3/resources/Resources.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2681,6 +2681,8 @@
26822682 );
26832683
26842684 // Load embeddable private modules before any loader links
 2685+ // This needs to be TYPE_COMBINED so these modules are properly wrapped
 2686+ // in mw.loader.implement() calls and deferred until mw.user is available
26852687 $embedScripts = array( 'user.options', 'user.tokens' );
26862688 $scripts .= $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED );
26872689
@@ -3268,7 +3270,7 @@
32693271
32703272 // Per-user preference styles
32713273 if ( $wgAllowUserCssPrefs ) {
3272 - $moduleStyles[] = 'user.options';
 3274+ $moduleStyles[] = 'user.cssprefs';
32733275 }
32743276
32753277 foreach ( $moduleStyles as $name ) {
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
@@ -0,0 +1,136 @@
 2+<?php
 3+/**
 4+ * This program is free software; you can redistribute it and/or modify
 5+ * it under the terms of the GNU General Public License as published by
 6+ * the Free Software Foundation; either version 2 of the License, or
 7+ * (at your option) any later version.
 8+ *
 9+ * This program is distributed in the hope that it will be useful,
 10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 12+ * GNU General Public License for more details.
 13+ *
 14+ * You should have received a copy of the GNU General Public License along
 15+ * with this program; if not, write to the Free Software Foundation, Inc.,
 16+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 17+ * http://www.gnu.org/copyleft/gpl.html
 18+ *
 19+ * @file
 20+ * @author Trevor Parscal
 21+ * @author Roan Kattouw
 22+ */
 23+
 24+/**
 25+ * Module for user preference customizations
 26+ */
 27+class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule {
 28+
 29+ /* Protected Members */
 30+
 31+ protected $modifiedTime = array();
 32+
 33+ protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
 34+
 35+ /* Methods */
 36+
 37+ /**
 38+ * @param $context ResourceLoaderContext
 39+ * @return array|int|Mixed
 40+ */
 41+ public function getModifiedTime( ResourceLoaderContext $context ) {
 42+ $hash = $context->getHash();
 43+ if ( isset( $this->modifiedTime[$hash] ) ) {
 44+ return $this->modifiedTime[$hash];
 45+ }
 46+
 47+ global $wgUser;
 48+
 49+ if ( $context->getUser() === $wgUser->getName() ) {
 50+ return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
 51+ } else {
 52+ return 1;
 53+ }
 54+ }
 55+
 56+ /**
 57+ * Fetch the context's user options, or if it doesn't match current user,
 58+ * the default options.
 59+ *
 60+ * @param $context ResourceLoaderContext: Context object
 61+ * @return Array: List of user options keyed by option name
 62+ */
 63+ protected function contextUserOptions( ResourceLoaderContext $context ) {
 64+ global $wgUser;
 65+
 66+ // Verify identity -- this is a private module
 67+ if ( $context->getUser() === $wgUser->getName() ) {
 68+ return $wgUser->getOptions();
 69+ } else {
 70+ return User::getDefaultOptions();
 71+ }
 72+ }
 73+
 74+ /**
 75+ * @param $context ResourceLoaderContext
 76+ * @return array
 77+ */
 78+ public function getStyles( ResourceLoaderContext $context ) {
 79+ global $wgAllowUserCssPrefs;
 80+
 81+ if ( $wgAllowUserCssPrefs ) {
 82+ $options = $this->contextUserOptions( $context );
 83+
 84+ // Build CSS rules
 85+ $rules = array();
 86+
 87+ // Underline: 2 = browser default, 1 = always, 0 = never
 88+ if ( $options['underline'] < 2 ) {
 89+ $rules[] = "a { text-decoration: " .
 90+ ( $options['underline'] ? 'underline' : 'none' ) . "; }";
 91+ } else {
 92+ # The scripts of these languages are very hard to read with underlines
 93+ $rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' .
 94+ 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
 95+ }
 96+ if ( $options['highlightbroken'] ) {
 97+ $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
 98+ } else {
 99+ $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
 100+ $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
 101+ $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
 102+ }
 103+ if ( $options['justify'] ) {
 104+ $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
 105+ }
 106+ if ( !$options['showtoc'] ) {
 107+ $rules[] = "#toc { display: none; }\n";
 108+ }
 109+ if ( !$options['editsection'] ) {
 110+ $rules[] = ".editsection { display: none; }\n";
 111+ }
 112+ if ( $options['editfont'] !== 'default' ) {
 113+ $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
 114+ }
 115+ $style = implode( "\n", $rules );
 116+ if ( $this->getFlip( $context ) ) {
 117+ $style = CSSJanus::transform( $style, true, false );
 118+ }
 119+ return array( 'all' => $style );
 120+ }
 121+ return array();
 122+ }
 123+
 124+ /**
 125+ * @return string
 126+ */
 127+ public function getGroup() {
 128+ return 'private';
 129+ }
 130+
 131+ /**
 132+ * @return array
 133+ */
 134+ public function getDependencies() {
 135+ return array( 'mediawiki.user' );
 136+ }
 137+}
Property changes on: trunk/phase3/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php
___________________________________________________________________
Added: svn:eol-style
1138 + native
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php
@@ -80,58 +80,6 @@
8181 }
8282
8383 /**
84 - * @param $context ResourceLoaderContext
85 - * @return array
86 - */
87 - public function getStyles( ResourceLoaderContext $context ) {
88 - // FIXME: This stuff should really be in its own module, because it gets double-loaded otherwise
89 - // (once through a <link>, once when embedded as JS)
90 - global $wgAllowUserCssPrefs;
91 -
92 - if ( $wgAllowUserCssPrefs ) {
93 - $options = $this->contextUserOptions( $context );
94 -
95 - // Build CSS rules
96 - $rules = array();
97 -
98 - // Underline: 2 = browser default, 1 = always, 0 = never
99 - if ( $options['underline'] < 2 ) {
100 - $rules[] = "a { text-decoration: " .
101 - ( $options['underline'] ? 'underline' : 'none' ) . "; }";
102 - } else {
103 - # The scripts of these languages are very hard to read with underlines
104 - $rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' .
105 - 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }';
106 - }
107 - if ( $options['highlightbroken'] ) {
108 - $rules[] = "a.new, #quickbar a.new { color: #ba0000; }\n";
109 - } else {
110 - $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
111 - $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #ba0000; }";
112 - $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
113 - }
114 - if ( $options['justify'] ) {
115 - $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
116 - }
117 - if ( !$options['showtoc'] ) {
118 - $rules[] = "#toc { display: none; }\n";
119 - }
120 - if ( !$options['editsection'] ) {
121 - $rules[] = ".editsection { display: none; }\n";
122 - }
123 - if ( $options['editfont'] !== 'default' ) {
124 - $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
125 - }
126 - $style = implode( "\n", $rules );
127 - if ( $this->getFlip( $context ) ) {
128 - $style = CSSJanus::transform( $style, true, false );
129 - }
130 - return array( 'all' => $style );
131 - }
132 - return array();
133 - }
134 -
135 - /**
13684 * @return string
13785 */
13886 public function getGroup() {
Index: trunk/phase3/includes/AutoLoader.php
@@ -724,6 +724,7 @@
725725 'ResourceLoaderNoscriptModule' => 'includes/resourceloader/ResourceLoaderNoscriptModule.php',
726726 'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php',
727727 'ResourceLoaderStartUpModule' => 'includes/resourceloader/ResourceLoaderStartUpModule.php',
 728+ 'ResourceLoaderUserCSSPrefsModule' => 'includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php',
728729 'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php',
729730 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php',
730731 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php',
Index: trunk/phase3/resources/Resources.php
@@ -10,6 +10,7 @@
1111 'user' => array( 'class' => 'ResourceLoaderUserModule' ),
1212 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ),
1313 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ),
 14+ 'user.cssprefs' => array( 'class' => 'ResourceLoaderUserCSSPrefsModule' ),
1415 'user.tokens' => array( 'class' => 'ResourceLoaderUserTokensModule' ),
1516 'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ),
1617

Follow-up revisions

RevisionCommit summaryAuthorDate
r111175REL1_19: MFT r111029, r111034, r111067, r111076, r111085, r111128, r111144reedy18:37, 10 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93363Make mw.user.options and mw.user.tokens work in debug mode in IE. Now that mw...catrope05:48, 28 July 2011
r111023(bug 34289) user.options CSS loaded twice. Caused by r107534. Made embedded p...catrope10:36, 9 February 2012

Status & tagging log