2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Module for user preference customizations
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
|
|
|
|
|
|
|
|
|
|
/* Protected Members */
|
|
|
|
|
|
|
|
|
|
protected $modifiedTime = array();
|
|
|
|
|
|
2011-02-04 16:39:17 +00:00
|
|
|
protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
|
|
|
|
|
|
2010-10-19 18:25:42 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
|
|
|
|
* @param $context ResourceLoaderContext
|
|
|
|
|
* @return array|int|Mixed
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getModifiedTime( ResourceLoaderContext $context ) {
|
|
|
|
|
$hash = $context->getHash();
|
|
|
|
|
if ( isset( $this->modifiedTime[$hash] ) ) {
|
|
|
|
|
return $this->modifiedTime[$hash];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
|
|
if ( $context->getUser() === $wgUser->getName() ) {
|
2011-01-13 14:42:19 +00:00
|
|
|
return $this->modifiedTime[$hash] = wfTimestamp( TS_UNIX, $wgUser->getTouched() );
|
2010-10-19 18:25:42 +00:00
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the context's user options, or if it doesn't match current user,
|
|
|
|
|
* the default options.
|
2011-10-14 08:06:54 +00:00
|
|
|
*
|
2010-11-05 18:33:50 +00:00
|
|
|
* @param $context ResourceLoaderContext: Context object
|
|
|
|
|
* @return Array: List of user options keyed by option name
|
2010-10-19 18:25:42 +00:00
|
|
|
*/
|
|
|
|
|
protected function contextUserOptions( ResourceLoaderContext $context ) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
|
|
|
|
|
// Verify identity -- this is a private module
|
|
|
|
|
if ( $context->getUser() === $wgUser->getName() ) {
|
|
|
|
|
return $wgUser->getOptions();
|
|
|
|
|
} else {
|
|
|
|
|
return User::getDefaultOptions();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
|
|
|
|
* @param $context ResourceLoaderContext
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2011-10-14 08:06:54 +00:00
|
|
|
return Xml::encodeJsCall( 'mw.user.options.set',
|
* Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +00:00
|
|
|
array( $this->contextUserOptions( $context ) ) );
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-21 22:08:23 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function supportsURLLoading() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getGroup() {
|
|
|
|
|
return 'private';
|
|
|
|
|
}
|
|
|
|
|
}
|