Files
mediawiki-extensions-Univer…/includes/ResourceLoaderULSModule.php
Timo Tijhof f06ac3efca Simplify ResourceLoaderULSModule with content-based versioning
* Remove manual tracking of when a hash is first seen.
  ResourceLoader is no longer time-based, rather it is content based.
  Except where a timestamp is actually wanted as key, a hash is all
  we need. The default implementation of simply calling getScript()
  and hashing its output suffices, and isn't a performance problem
  in this case.

* Also simplify getScript() by passing an object to 'mw.config.set'.
  Instead of multiple calls for each key/value. This is a no-op
  now because there is only one key.

* Fix inaccurate class comment that was copied from an unrelated
  module in MediaWiki core.

Change-Id: I9bb82cadd9caa7e584e20dd49ce30b64218326c4
2016-08-23 14:49:16 -07:00

61 lines
1.6 KiB
PHP

<?php
/**
* ResourceLoader module for UniversalLanguageSelector
*
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
* contributors. See CREDITS for a list.
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @author Niklas Laxström
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
/**
* ResourceLoader module for UniversalLanguageSelector
*/
class ResourceLoaderULSModule extends ResourceLoaderModule {
protected $targets = [ 'desktop', 'mobile' ];
/**
* Get all the dynamic data for the content language to an array.
*
* @param string $languageCode Language code
* @return array
*/
private function getData( $languageCode ) {
$vars = [];
$vars['wgULSLanguages'] = Language::fetchLanguageNames(
$languageCode,
'mwfile'
);
return $vars;
}
/**
* @param $context ResourceLoaderContext
* @return string JavaScript code
*/
public function getScript( ResourceLoaderContext $context ) {
$languageCode = $context->getLanguage();
return Xml::encodeJsCall( 'mw.config.set', [
$this->getData( $languageCode )
] );
}
/**
* @return bool
*/
public function enableModuleContentVersion() {
return true;
}
}