wiki.techinc.nl/includes/resourceloader/ResourceLoaderSpecialCharacterDataModule.php
Andrew Green 7e0d3369c2 resourceloader: Add context param to ResourceLoaderModule::getDependencies
By providing context as a parameter in getDependencies, we allow
modules to dyanamically determine dependencies based on context.
Note: To ease rollout, the parameter is optional in this patch. It is expected
that it will be made non-optional in the near future.

The use case is for CentralNotice campaigns to be able to add special
modules ahead of deciding which banner to show a user. The dynamically
chosen RL modules would replace ad-hoc JS currently sent with some banners.
A list of possible campaigns and banners is already sent as a PHP-
implemented RL module; that's the module that will dynamically choose other
modules as dependencies when appropriate. This approach will save a round
trip as compared to dynamically loading the modules client-side.

For compatibility, extensions that override
ResourceLoaderModule::getDependencies() should be updated with the new
method signature. Here are changes for extensions currently deployed on
Wikimedia wikis:

* CentralNotice: I816bffa3815e2eab7e88cb04d1b345070e6aa15f
* Gadgets: I0a10fb0cbf17d095ece493e744296caf13dcee02
* EventLogging: I67e957f74d6ca48cfb9a41fb5144bcc78f885e50
* PageTriage: Ica3ba32aa2fc76d11a44f391b6edfc871e7fbe0d
* UniversalLanguageSelector: Ic63e617f51702c27104e123d4bed91983a726b7f
* VisualEditor: I0ac775ca286e64825e31a9213b94648e41a5bc30

For more on the CentralNotice use case, please see I9f80edcbcacca2.

Bug: T98924
Change-Id: Iee61e5b527321d01287baa03ad9b4d4f526ff3ef
2015-06-09 03:10:20 +01:00

101 lines
2.9 KiB
PHP

<?php
/**
* Resource loader module for populating special characters data for some
* editing extensions to use.
*
* 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
*/
/**
* Resource loader module for populating special characters data for some
* editing extensions to use.
*/
class ResourceLoaderSpecialCharacterDataModule extends ResourceLoaderModule {
private $path = "resources/src/mediawiki.language/specialcharacters.json";
protected $targets = array( 'desktop', 'mobile' );
/**
* Get all the dynamic data.
*
* @return array
*/
protected function getData() {
global $IP;
return json_decode( file_get_contents( "$IP/{$this->path}" ) );
}
/**
* @param ResourceLoaderContext $context
* @return string JavaScript code
*/
public function getScript( ResourceLoaderContext $context ) {
return Xml::encodeJsCall(
'mw.language.setSpecialCharacters',
array(
$this->getData()
),
ResourceLoader::inDebugMode()
);
}
/**
* @param ResourceLoaderContext $context
* @return string Hash
*/
public function getModifiedHash( ResourceLoaderContext $context ) {
return md5( serialize( $this->getData() ) );
}
/**
* @param ResourceLoaderContext $context
* @return array
*/
public function getDependencies( ResourceLoaderContext $context = null ) {
return array( 'mediawiki.language' );
}
/**
* @return array
*/
public function getMessages() {
return array(
'special-characters-group-latin',
'special-characters-group-latinextended',
'special-characters-group-ipa',
'special-characters-group-symbols',
'special-characters-group-greek',
'special-characters-group-cyrillic',
'special-characters-group-arabic',
'special-characters-group-arabicextended',
'special-characters-group-persian',
'special-characters-group-hebrew',
'special-characters-group-bangla',
'special-characters-group-tamil',
'special-characters-group-telugu',
'special-characters-group-sinhala',
'special-characters-group-devanagari',
'special-characters-group-gujarati',
'special-characters-group-thai',
'special-characters-group-lao',
'special-characters-group-khmer',
'special-characters-title-endash',
'special-characters-title-emdash',
'special-characters-title-minus'
);
}
}