Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -2681,6 +2681,8 @@ |
2682 | 2682 | ); |
2683 | 2683 | |
2684 | 2684 | // 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 |
2685 | 2687 | $embedScripts = array( 'user.options', 'user.tokens' ); |
2686 | 2688 | $scripts .= $this->makeResourceLoaderLink( $embedScripts, ResourceLoaderModule::TYPE_COMBINED ); |
2687 | 2689 | |
— | — | @@ -3268,7 +3270,7 @@ |
3269 | 3271 | |
3270 | 3272 | // Per-user preference styles |
3271 | 3273 | if ( $wgAllowUserCssPrefs ) { |
3272 | | - $moduleStyles[] = 'user.options'; |
| 3274 | + $moduleStyles[] = 'user.cssprefs'; |
3273 | 3275 | } |
3274 | 3276 | |
3275 | 3277 | 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 |
1 | 138 | + native |
Index: trunk/phase3/includes/resourceloader/ResourceLoaderUserOptionsModule.php |
— | — | @@ -80,58 +80,6 @@ |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
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 | | - /** |
136 | 84 | * @return string |
137 | 85 | */ |
138 | 86 | public function getGroup() { |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -724,6 +724,7 @@ |
725 | 725 | 'ResourceLoaderNoscriptModule' => 'includes/resourceloader/ResourceLoaderNoscriptModule.php', |
726 | 726 | 'ResourceLoaderSiteModule' => 'includes/resourceloader/ResourceLoaderSiteModule.php', |
727 | 727 | 'ResourceLoaderStartUpModule' => 'includes/resourceloader/ResourceLoaderStartUpModule.php', |
| 728 | + 'ResourceLoaderUserCSSPrefsModule' => 'includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php', |
728 | 729 | 'ResourceLoaderUserGroupsModule' => 'includes/resourceloader/ResourceLoaderUserGroupsModule.php', |
729 | 730 | 'ResourceLoaderUserModule' => 'includes/resourceloader/ResourceLoaderUserModule.php', |
730 | 731 | 'ResourceLoaderUserOptionsModule' => 'includes/resourceloader/ResourceLoaderUserOptionsModule.php', |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -10,6 +10,7 @@ |
11 | 11 | 'user' => array( 'class' => 'ResourceLoaderUserModule' ), |
12 | 12 | 'user.groups' => array( 'class' => 'ResourceLoaderUserGroupsModule' ), |
13 | 13 | 'user.options' => array( 'class' => 'ResourceLoaderUserOptionsModule' ), |
| 14 | + 'user.cssprefs' => array( 'class' => 'ResourceLoaderUserCSSPrefsModule' ), |
14 | 15 | 'user.tokens' => array( 'class' => 'ResourceLoaderUserTokensModule' ), |
15 | 16 | 'filepage' => array( 'class' => 'ResourceLoaderFilePageModule' ), |
16 | 17 | |