r73024 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73023‎ | r73024 | r73025 >
Date:21:47, 14 September 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
* Added exporting of user preferences
* Renamed user.preferences to user.options
* Fixed bug that caused anonomous usernames (such as IP addresses) to be used in user style and script requests
* Fixed user options styles not loading for anon users
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2300,7 +2300,7 @@
23012301 sort( $modules );
23022302 $query['modules'] = implode( '|', array_unique( (array) $modules ) );
23032303 if ( $group === 'user' ) {
2304 - $query['user'] = $wgUser->getName();
 2304+ $query['user'] = $wgUser->isLoggedIn() ? $wgUser->getName() : null;
23052305 }
23062306 // Users might change their stuff on-wiki like site or user pages, or user preferences; we need to find
23072307 // the highest timestamp of these user-changable modules so we can ensure cache misses upon change
@@ -2382,16 +2382,21 @@
23832383 );
23842384 }
23852385
2386 - // Add user JS if enabled
2387 - if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
 2386+ // Add user JS if enabled - trying to load user.options as a bundle if possible
 2387+ $userOptionsAdded = false;
 2388+ if ( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
23882389 $action = $wgRequest->getVal( 'action', 'view' );
23892390 if( $this->mTitle && $this->mTitle->isJsSubpage() && $sk->userCanPreview( $action ) ) {
23902391 # XXX: additional security check/prompt?
23912392 $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
23922393 } else {
2393 - $scripts .= self::makeResourceLoaderLink( $sk, 'user', 'scripts' );
 2394+ $scripts .= self::makeResourceLoaderLink( $sk, array( 'user', 'user.options' ), 'scripts' );
 2395+ $userOptionsAdded = true;
23942396 }
23952397 }
 2398+ if ( !$userOptionsAdded ) {
 2399+ $scripts .= self::makeResourceLoaderLink( $sk, 'user.options', 'scripts' );
 2400+ }
23962401 $scripts .= "\n" . $this->mScripts;
23972402
23982403 // Add site JS if enabled
Index: trunk/phase3/includes/AutoLoader.php
@@ -203,6 +203,8 @@
204204 'ResourceLoaderWikiModule' => 'includes/ResourceLoaderModule.php',
205205 'ResourceLoaderFileModule' => 'includes/ResourceLoaderModule.php',
206206 'ResourceLoaderSiteModule' => 'includes/ResourceLoaderModule.php',
 207+ 'ResourceLoaderUserModule' => 'includes/ResourceLoaderModule.php',
 208+ 'ResourceLoaderUserOptionsModule' => 'includes/ResourceLoaderModule.php',
207209 'ResourceLoaderStartUpModule' => 'includes/ResourceLoaderModule.php',
208210 'ReverseChronologicalPager' => 'includes/Pager.php',
209211 'Revision' => 'includes/Revision.php',
Index: trunk/phase3/includes/Skin.php
@@ -516,7 +516,7 @@
517517
518518 // Per-user preference styles
519519 if ( $wgAllowUserCssPrefs ) {
520 - $out->addModuleStyles( 'user.preferences' );
 520+ $out->addModuleStyles( 'user.options' );
521521 }
522522
523523 wfProfileOut( __METHOD__ );
Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -813,7 +813,7 @@
814814 /**
815815 * Module for user preference customizations
816816 */
817 -class ResourceLoaderUserPreferencesModule extends ResourceLoaderModule {
 817+class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
818818
819819 /* Protected Members */
820820
@@ -839,40 +839,44 @@
840840 }
841841 }
842842
 843+ public function getScript( ResourceLoaderContext $context ) {
 844+ $user = User::newFromName( $context->getUser() );
 845+ $options = FormatJson::encode( $user instanceof User ? $user->getOptions() : User::getDefaultOptions() );
 846+ return "mediaWiki.user.options.set( $options );";
 847+ }
 848+
843849 public function getStyles( ResourceLoaderContext $context ) {
844850 global $wgAllowUserCssPrefs;
845851 if ( $wgAllowUserCssPrefs ) {
846852 $user = User::newFromName( $context->getUser() );
847 - if ( $user === false ) {
848 - $user = User::newFromId( 0 );
849 - }
850 -
 853+ $options = $user instanceof User ? $user->getOptions() : User::getDefaultOptions();
 854+
851855 $rules = array();
852 - if ( ( $underline = $user->getOption( 'underline' ) ) < 2 ) {
853 - $rules[] = "a { text-decoration: " . ( $underline ? 'underline' : 'none' ) . "; }";
 856+ if ( $options['underline'] < 2 ) {
 857+ $rules[] = "a { text-decoration: " . ( $options['underline'] ? 'underline' : 'none' ) . "; }";
854858 }
855 - if ( $user->getOption( 'highlightbroken' ) ) {
 859+ if ( $options['highlightbroken'] ) {
856860 $rules[] = "a.new, #quickbar a.new { color: #CC2200; }\n";
857861 } else {
858862 $rules[] = "a.new, #quickbar a.new, a.stub, #quickbar a.stub { color: inherit; }";
859863 $rules[] = "a.new:after, #quickbar a.new:after { content: '?'; color: #CC2200; }";
860864 $rules[] = "a.stub:after, #quickbar a.stub:after { content: '!'; color: #772233; }";
861865 }
862 - if ( $user->getOption( 'justify' ) ) {
 866+ if ( $options['justify'] ) {
863867 $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n";
864868 }
865 - if ( !$user->getOption( 'showtoc' ) ) {
 869+ if ( !$options['showtoc'] ) {
866870 $rules[] = "#toc { display: none; }\n";
867871 }
868 - if ( !$user->getOption( 'editsection' ) ) {
 872+ if ( !$options['editsection'] ) {
869873 $rules[] = ".editsection { display: none; }\n";
870874 }
871 - if ( ( $fontstyle = $user->getOption( 'editfont' ) ) !== 'default' ) {
872 - $rules[] = "textarea { font-family: $fontstyle; }\n";
 875+ if ( $options['editfont'] !== 'default' ) {
 876+ $rules[] = "textarea { font-family: {$options['editfont']}; }\n";
873877 }
874878 return array( 'all' => implode( "\n", $rules ) );
875879 }
876 - return array();
 880+ return array( 'all' => 'test { color: pink; }' );
877881 }
878882
879883 public function getFlip( $context ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r74145Fix personal user styles being broken since introduction in r73024nikerabbit16:11, 2 October 2010

Comments

#Comment by Nikerabbit (talk | contribs)   06:24, 15 September 2010

+return array( 'all' => 'test { color: pink; }' ); ???

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:59, 15 September 2010

ARG! Testing code snuck in... r73074 fixes this.

Status & tagging log