ResourceLoader Module for serving json based localization messages

ApiULSLocalization is still present since we have to provide live
language preview feature.

Moved the loading of json file to includes/JsonMessageLoader.php

Also moved all RL modules to includes folder.

Bug: 56509
Change-Id: Ic39dec1c484982fb07edd167e83794c0b5f470ee
This commit is contained in:
Santhosh Thottingal
2013-11-04 16:15:07 +05:30
committed by Niklas Laxström
parent 03dabe1681
commit 76e82e4a9c
7 changed files with 165 additions and 39 deletions

View File

@@ -0,0 +1,84 @@
<?php
/**
* Resource loader 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
*/
/**
* Resource loader module for providing MediaWiki language names.
*/
class ResourceLoaderULSModule extends ResourceLoaderModule {
/**
* @var Language
*/
protected $language;
protected $targets = array( 'desktop', 'mobile' );
/**
* Get all the dynamic data for the content language to an array
*
* @return array
*/
protected function getData() {
$vars = array();
$vars['wgULSLanguages'] = Language::fetchLanguageNames(
$this->language->getCode(), 'mwfile'
);
return $vars;
}
/**
* @param $context ResourceLoaderContext
* @return string: JavaScript code
*/
public function getScript( ResourceLoaderContext $context ) {
$this->language = Language::factory( $context->getLanguage() );
$out = '';
foreach ( $this->getData() as $key => $value ) {
$out .= Xml::encodeJsCall( 'mw.config.set', array( $key, $value ) );
}
return $out;
}
/**
* @param $context ResourceLoaderContext
* @return array|int|Mixed
*/
public function getModifiedTime( ResourceLoaderContext $context ) {
$this->language = Language::factory( $context->getLanguage() );
$cache = wfGetCache( CACHE_ANYTHING );
$key = wfMemcKey( 'resourceloader', 'ulsmodule', 'changeinfo' );
$data = $this->getData();
$hash = md5( serialize( $data ) );
$result = $cache->get( $key );
if ( is_array( $result ) && $result['hash'] === $hash ) {
return $result['timestamp'];
}
$timestamp = wfTimestamp();
$cache->set( $key, array(
'hash' => $hash,
'timestamp' => $timestamp,
) );
return $timestamp;
}
}