r74181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74180‎ | r74181 | r74182 >
Date:01:03, 3 October 2010
Author:brion
Status:ok
Tags:
Comment:
Extract common code in ResourceLoaderUserOptionsModule (sloppy copy-pasting of the originals looks like the cause of the bug fixed in r74145)
Modified paths:
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -915,28 +915,34 @@
916916 }
917917 }
918918
919 - public function getScript( ResourceLoaderContext $context ) {
 919+ /**
 920+ * Fetch the context's user options, or if it doesn't match current user,
 921+ * the default options.
 922+ *
 923+ * @param ResourceLoaderContext $context
 924+ * @return array
 925+ */
 926+ protected function contextUserOptions( ResourceLoaderContext $context ) {
920927 global $wgUser;
921928
922929 // Verify identity -- this is a private module
923930 if ( $context->getUser() === $wgUser->getName() ) {
924 - $options = FormatJson::encode( $wgUser->getOptions() );
 931+ return $wgUser->getOptions();
925932 } else {
926 - $options = FormatJson::encode( User::getDefaultOptions() );
 933+ return User::getDefaultOptions();
927934 }
928 - return "mediaWiki.user.options.set( $options );";
929935 }
930936
 937+ public function getScript( ResourceLoaderContext $context ) {
 938+ $encOptions = FormatJson::encode( $this->contextUserOptions( $context ) );
 939+ return "mediaWiki.user.options.set( $encOptions );";
 940+ }
 941+
931942 public function getStyles( ResourceLoaderContext $context ) {
932 - global $wgUser, $wgAllowUserCssPrefs;
 943+ global $wgAllowUserCssPrefs;
933944
934945 if ( $wgAllowUserCssPrefs ) {
935 - // Verify identity -- this is a private module
936 - if ( $context->getUser() === $wgUser->getName() ) {
937 - $options = $wgUser->getOptions();
938 - } else {
939 - $options = User::getDefaultOptions();
940 - }
 946+ $options = $this->contextUserOptions( $context );
941947
942948 // Build CSS rules
943949 $rules = array();

Past revisions this follows-up on

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

Status & tagging log