本文整理汇总了PHP中Language::isValidBuiltInCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::isValidBuiltInCode方法的具体用法?PHP Language::isValidBuiltInCode怎么用?PHP Language::isValidBuiltInCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::isValidBuiltInCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadLanguage
/**
* Load country names localized for a particular language.
*
* @param string $code The language to return the list in
* @return an associative array of country codes and localized country names
*/
private static function loadLanguage($code)
{
if (!isset(self::$cache[$code])) {
wfProfileIn(__METHOD__ . '-recache');
/* Load override for wrong or missing entries in cldr */
$override = dirname(__FILE__) . '/LocalNames/' . self::getOverrideFileName($code);
if (Language::isValidBuiltInCode($code) && file_exists($override)) {
$countryNames = false;
require $override;
if (is_array($countryNames)) {
self::$cache[$code] = $countryNames;
}
}
$filename = dirname(__FILE__) . '/CldrNames/' . self::getFileName($code);
if (Language::isValidBuiltInCode($code) && file_exists($filename)) {
$countryNames = false;
require $filename;
if (is_array($countryNames)) {
if (isset(self::$cache[$code])) {
// Add to existing list of localized country names
self::$cache[$code] = self::$cache[$code] + $countryNames;
} else {
// No list exists, so create it
self::$cache[$code] = $countryNames;
}
}
} else {
wfDebug(__METHOD__ . ": Unable to load country names for {$filename}\n");
}
wfProfileOut(__METHOD__ . '-recache');
}
return isset(self::$cache[$code]) ? self::$cache[$code] : array();
}
示例2: loadLanguage
/**
* Load time units localized for a particular language. Helper function for getUnits.
*
* @param string $code The language to return the list in
* @return array an associative array of time unit codes and localized time units
*/
private static function loadLanguage($code)
{
if (!isset(self::$cache[$code])) {
/* Load override for wrong or missing entries in cldr */
$override = __DIR__ . '/LocalNames/' . self::getOverrideFileName($code);
if (Language::isValidBuiltInCode($code) && file_exists($override)) {
$timeUnits = false;
require $override;
if (is_array($timeUnits)) {
self::$cache[$code] = $timeUnits;
}
}
$filename = __DIR__ . '/CldrNames/' . self::getFileName($code);
if (Language::isValidBuiltInCode($code) && file_exists($filename)) {
$timeUnits = false;
require $filename;
if (is_array($timeUnits)) {
if (isset(self::$cache[$code])) {
// Add to existing list of localized time units
self::$cache[$code] = self::$cache[$code] + $timeUnits;
} else {
// No list exists, so create it
self::$cache[$code] = $timeUnits;
}
}
} else {
wfDebug(__METHOD__ . ": Unable to load time units for {$filename}\n");
}
if (!isset(self::$cache[$code])) {
self::$cache[$code] = array();
}
}
return self::$cache[$code];
}
示例3: execute
public function execute()
{
$commonContent = "{}";
$configuration = null;
$this->getMain()->setCacheMode('public');
$this->getMain()->setCacheMaxAge(2419200);
$params = $this->extractRequestParams();
$source = $params['from'];
$target = $params['to'];
if (!Language::isValidBuiltInCode($source) || !Language::isValidBuiltInCode($target)) {
$this->dieUsage('Invalid language', 'invalidlanguage');
}
// Read common configuraiton
$commonFileName = __DIR__ . "/../modules/source/conf/common.json";
if (is_readable($commonFileName)) {
$commonContent = file_get_contents($commonFileName);
}
$commonConfiguration = json_decode($commonContent, false);
// Read configuraiton for language pair
$filename = __DIR__ . "/../modules/source/conf/{$source}-{$target}.json";
if (is_readable($filename)) {
$contents = file_get_contents($filename);
$configuration = json_decode($contents, false);
}
if (!$configuration) {
// No language specific configuration.
$configuration = $commonConfiguration;
} else {
// For now, we use only templates in configuration.
// If we have more keys in configuration, this must be
// a separate method to merge configurations
$configuration->templates = (object) array_merge((array) $commonConfiguration->templates, (array) $configuration->templates);
}
$this->getResult()->addValue(null, 'configuration', $configuration);
}
开发者ID:Rjaylyn,项目名称:mediawiki-extensions-ContentTranslation,代码行数:35,代码来源:ApiContentTranslationConfiguration.php
示例4: execute
public function execute()
{
$result = $this->getResult();
$params = $this->extractRequestParams();
$source = $target = null;
if (isset($params['source']) && Language::isValidBuiltInCode($params['source'])) {
$source = $params['source'];
}
if (isset($params['target']) && Language::isValidBuiltInCode($params['target'])) {
$target = $params['target'];
}
$interval = $params['interval'];
$result->addValue(array('query'), 'contenttranslationlangtrend', ContentTranslation\Translation::getTrend($source, $target, $interval));
}
开发者ID:Wikia,项目名称:mediawiki-extensions-ContentTranslation,代码行数:14,代码来源:ApiQueryContentTranslationLanguageTrend.php
示例5: execute
public function execute()
{
$result = $this->getResult();
$params = $this->extractRequestParams();
$source = $target = null;
if (isset($params['source']) && Language::isValidBuiltInCode($params['source'])) {
$source = $params['source'];
}
if (isset($params['target']) && Language::isValidBuiltInCode($params['target'])) {
$target = $params['target'];
}
$interval = $params['interval'];
$data = array('translations' => Translation::getTrendByStatus($source, $target, 'published', $interval), 'drafts' => Translation::getTrendByStatus($source, $target, 'draft', $interval));
if ($target !== null) {
// We can give deletion rates for only local wiki. We cannot give
// deletion stats for all wikis.
$data['deletions'] = Translation::getDeletionTrend($interval);
}
$out = $this->addMissingDates($data, $interval);
$result->addValue(array('query'), 'contenttranslationlangtrend', $out);
}
开发者ID:Rjaylyn,项目名称:mediawiki-extensions-ContentTranslation,代码行数:21,代码来源:ApiQueryContentTranslationLanguageTrend.php
示例6: execute
public function execute()
{
$from = $to = null;
$params = $this->extractRequestParams();
$result = $this->getResult();
$user = $this->getUser();
if (isset($params['from'])) {
$from = $params['from'];
}
if (isset($params['to'])) {
$to = $params['to'];
}
$limit = $params['limit'];
$offset = $params['offset'];
if ($from !== null && !Language::isValidBuiltInCode($from)) {
$this->dieUsage('Invalid language', 'invalidlanguage');
}
if ($to !== null && !Language::isValidBuiltInCode($to)) {
$this->dieUsage('Invalid language', 'invalidlanguage');
}
$translations = ContentTranslation\Translation::getAllPublishedTranslations($from, $to, $limit, $offset);
$resultSize = count($translations);
$result->addValue(array('result'), 'translations', $translations);
}
开发者ID:Rjaylyn,项目名称:mediawiki-extensions-ContentTranslation,代码行数:24,代码来源:ApiQueryPublishedTranslations.php
示例7: time
public static function time($parser, $format = '', $date = '', $language = '', $local = false)
{
global $wgLang, $wgContLang, $wgLocaltimezone;
self::registerClearHook();
if (isset(self::$mTimeCache[$format][$date][$language][$local])) {
return self::$mTimeCache[$format][$date][$language][$local];
}
# compute the timestamp string $ts
# PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
# PHP < 5.2 is limited to dates between 1970 and 2038
$invalidTime = false;
if (class_exists('DateTime')) {
# PHP >= 5.2
# the DateTime constructor must be used because it throws exceptions
# when errors occur, whereas date_create appears to just output a warning
# that can't really be detected from within the code
try {
# Determine timezone
if ($local) {
# convert to MediaWiki local timezone if set
if (isset($wgLocaltimezone)) {
$tz = new DateTimeZone($wgLocaltimezone);
} else {
$tz = new DateTimeZone(date_default_timezone_get());
}
} else {
# if local time was not requested, convert to UTC
$tz = new DateTimeZone('UTC');
}
# Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
if (preg_match('/^[0-9]{4}$/', $date)) {
$date = '00:00 ' . $date;
}
# Parse date
if ($date !== '') {
$dateObject = new DateTime($date, $tz);
} else {
# use current date and time
$dateObject = new DateTime('now', $tz);
}
# Generate timestamp
$ts = $dateObject->format('YmdHis');
} catch (Exception $ex) {
$invalidTime = true;
}
} else {
# PHP < 5.2
if ($date !== '') {
$unix = @strtotime($date);
} else {
$unix = time();
}
if ($unix == -1 || $unix == false) {
$invalidTime = true;
} else {
if ($local) {
# Use the time zone
if (isset($wgLocaltimezone)) {
$oldtz = getenv('TZ');
putenv('TZ=' . $wgLocaltimezone);
}
wfSuppressWarnings();
// E_STRICT system time bitching
$ts = date('YmdHis', $unix);
wfRestoreWarnings();
if (isset($wgLocaltimezone)) {
putenv('TZ=' . $oldtz);
}
} else {
$ts = wfTimestamp(TS_MW, $unix);
}
}
}
# format the timestamp and return the result
if ($invalidTime) {
$result = '<strong class="error">' . wfMsgForContent('pfunc_time_error') . '</strong>';
} else {
self::$mTimeChars += strlen($format);
if (self::$mTimeChars > self::$mMaxTimeChars) {
return '<strong class="error">' . wfMsgForContent('pfunc_time_too_long') . '</strong>';
} else {
if ($ts < 100000000000000) {
// Language can't deal with years after 9999
if ($language !== '' && Language::isValidBuiltInCode($language)) {
// use whatever language is passed as a parameter
$langObject = Language::factory($language);
$result = $langObject->sprintfDate($format, $ts);
} else {
// use wiki's content language
$result = $parser->getFunctionLang()->sprintfDate($format, $ts);
}
} else {
return '<strong class="error">' . wfMsgForContent('pfunc_time_too_big') . '</strong>';
}
}
}
self::$mTimeCache[$format][$date][$language][$local] = $result;
return $result;
}
示例8: validateParam
/**
* @param string $name Parameter name
* @param mixed $value Parameter value
* @return bool Validity
*/
public function validateParam($name, $value)
{
if (in_array($name, ['width', 'height'])) {
// Reject negative heights, widths
return $value > 0;
} elseif ($name == 'lang') {
// Validate $code
if ($value === '' || !Language::isValidBuiltInCode($value)) {
wfDebug("Invalid user language code\n");
return false;
}
return true;
}
// Only lang, width and height are acceptable keys
return false;
}
示例9: timeCommon
/**
* @param $parser Parser
* @param $frame PPFrame
* @param $format string
* @param $date string
* @param $language string
* @param $local string|bool
* @return string
*/
public static function timeCommon($parser, $frame = null, $format = '', $date = '', $language = '', $local = false)
{
global $wgLocaltimezone;
self::registerClearHook();
if ($date === '') {
$cacheKey = $parser->getOptions()->getTimestamp();
$timestamp = new MWTimestamp($cacheKey);
$date = $timestamp->getTimestamp(TS_ISO_8601);
$useTTL = true;
} else {
$cacheKey = $date;
$useTTL = false;
}
if (isset(self::$mTimeCache[$format][$cacheKey][$language][$local])) {
$cachedVal = self::$mTimeCache[$format][$cacheKey][$language][$local];
if ($useTTL && $cachedVal[1] !== null && $frame && is_callable(array($frame, 'setTTL'))) {
$frame->setTTL($cachedVal[1]);
}
return $cachedVal[0];
}
# compute the timestamp string $ts
# PHP >= 5.2 can handle dates before 1970 or after 2038 using the DateTime object
$invalidTime = false;
# the DateTime constructor must be used because it throws exceptions
# when errors occur, whereas date_create appears to just output a warning
# that can't really be detected from within the code
try {
# Default input timezone is UTC.
$utc = new DateTimeZone('UTC');
# Correct for DateTime interpreting 'XXXX' as XX:XX o'clock
if (preg_match('/^[0-9]{4}$/', $date)) {
$date = '00:00 ' . $date;
}
# Parse date
# UTC is a default input timezone.
$dateObject = new DateTime($date, $utc);
# Set output timezone.
if ($local) {
if (isset($wgLocaltimezone)) {
$tz = new DateTimeZone($wgLocaltimezone);
} else {
$tz = new DateTimeZone(date_default_timezone_get());
}
} else {
$tz = $utc;
}
$dateObject->setTimezone($tz);
# Generate timestamp
$ts = $dateObject->format('YmdHis');
} catch (Exception $ex) {
$invalidTime = true;
}
$ttl = null;
# format the timestamp and return the result
if ($invalidTime) {
$result = '<strong class="error">' . wfMessage('pfunc_time_error')->inContentLanguage()->escaped() . '</strong>';
} else {
self::$mTimeChars += strlen($format);
if (self::$mTimeChars > self::$mMaxTimeChars) {
return '<strong class="error">' . wfMessage('pfunc_time_too_long')->inContentLanguage()->escaped() . '</strong>';
} else {
if ($ts < 0) {
// Language can't deal with BC years
return '<strong class="error">' . wfMessage('pfunc_time_too_small')->inContentLanguage()->escaped() . '</strong>';
} elseif ($ts < 100000000000000) {
// Language can't deal with years after 9999
if ($language !== '' && Language::isValidBuiltInCode($language)) {
// use whatever language is passed as a parameter
$langObject = Language::factory($language);
} else {
// use wiki's content language
$langObject = $parser->getFunctionLang();
StubObject::unstub($langObject);
// $ttl is passed by reference, which doesn't work right on stub objects
}
$result = $langObject->sprintfDate($format, $ts, $tz, $ttl);
} else {
return '<strong class="error">' . wfMessage('pfunc_time_too_big')->inContentLanguage()->escaped() . '</strong>';
}
}
}
self::$mTimeCache[$format][$cacheKey][$language][$local] = array($result, $ttl);
if ($useTTL && $ttl !== null && $frame && is_callable(array($frame, 'setTTL'))) {
$frame->setTTL($ttl);
}
return $result;
}
示例10: testBuiltInCodeValidationRejectUnderscore
/**
* @covers Language::isValidBuiltInCode
*/
public function testBuiltInCodeValidationRejectUnderscore()
{
$this->assertFalse((bool) Language::isValidBuiltInCode('be_tarask'), "reject underscore in language code");
}
示例11: isValidBuiltInLanguageCode
static function isValidBuiltInLanguageCode($code)
{
return Language::isValidBuiltInCode($code);
}
示例12: initLanguage
/**
* Initialise a language in this object. Rebuild the cache if necessary.
* @param $code
* @throws MWException
*/
protected function initLanguage($code)
{
if (isset($this->initialisedLangs[$code])) {
return;
}
$this->initialisedLangs[$code] = true;
# If the code is of the wrong form for a Messages*.php file, do a shallow fallback
if (!Language::isValidBuiltInCode($code)) {
$this->initShallowFallback($code, 'en');
return;
}
# Recache the data if necessary
if (!$this->manualRecache && $this->isExpired($code)) {
if (Language::isSupportedLanguage($code)) {
$this->recache($code);
} elseif ($code === 'en') {
throw new MWException('MessagesEn.php is missing.');
} else {
$this->initShallowFallback($code, 'en');
}
return;
}
# Preload some stuff
$preload = $this->getItem($code, 'preload');
if ($preload === null) {
if ($this->manualRecache) {
// No Messages*.php file. Do shallow fallback to en.
if ($code === 'en') {
throw new MWException('No localisation cache found for English. ' . 'Please run maintenance/rebuildLocalisationCache.php.');
}
$this->initShallowFallback($code, 'en');
return;
} else {
throw new MWException('Invalid or missing localisation cache.');
}
}
$this->data[$code] = $preload;
foreach ($preload as $key => $item) {
if (in_array($key, self::$splitKeys)) {
foreach ($item as $subkey => $subitem) {
$this->loadedSubitems[$code][$key][$subkey] = true;
}
} else {
$this->loadedItems[$code][$key] = true;
}
}
}
示例13: getFallbacksFor
/**
* Get the ordered list of fallback languages.
*
* @since 1.19
* @param string $code Language code
* @return array Non-empty array, ending in "en"
*/
public static function getFallbacksFor($code)
{
if ($code === 'en' || !Language::isValidBuiltInCode($code)) {
return array();
}
// For unknown languages, fallbackSequence returns an empty array,
// hardcode fallback to 'en' in that case.
return self::getLocalisationCache()->getItem($code, 'fallbackSequence') ?: array('en');
}
示例14: execute
/**
* main function
*/
public function execute()
{
$wikia = null;
extract($this->extractRequestParams());
/**
* database instance
*/
$db = $this->getDB();
$activeonly = false;
if (isset($active)) {
$activeonly = true;
}
/**
* query builder
*/
$this->addTables(array('city_list'));
if ($activeonly) {
$this->addWhereFld('city_public', 1);
}
if ($wikia) {
$this->addWhereFld('city_id', $wikia);
}
if (empty($wikia)) {
if (!empty($to)) {
if ($to && is_int($to)) {
$this->addWhere('city_id <= ' . intval($to));
}
}
if (!empty($from)) {
if ($from && is_int($from)) {
$this->addWhere('city_id >= ' . intval($from));
}
}
}
if (!empty($lang)) {
if (!Language::isValidBuiltInCode($lang)) {
// FIXME add proper error msg
$this->dieUsageMsg(array('invalidtitle', $lang));
}
$this->addWhereFld('city_lang', $lang);
}
if (isset($countonly)) {
/**
* query builder
*/
$this->addFields(array('count(*) as cnt'));
$data = array();
$res = $this->select(__METHOD__);
if ($row = $db->fetchObject($res)) {
$data['count'] = $row->cnt;
ApiResult::setContent($data, $row->cnt);
}
$db->freeResult($res);
} else {
$this->addFields(array('city_id', 'city_url', 'city_lang'));
$this->addOption("ORDER BY ", "city_id");
#--- result builder
$data = array();
$res = $this->select(__METHOD__);
while ($row = $db->fetchObject($res)) {
$domain = $row->city_url;
$domain = preg_replace('/^http:\\/\\//', '', $domain);
$domain = preg_replace('/\\/$/', '', $domain);
if ($domain) {
$data[$row->city_id] = array("id" => $row->city_id, "domain" => $domain, "lang" => $row->city_lang);
ApiResult::setContent($data[$row->city_id], $domain);
}
}
$db->freeResult($res);
}
$this->getResult()->setIndexedTagName($data, 'variable');
$this->getResult()->addValue('query', $this->getModuleName(), $data);
}
示例15: testBuiltInCodeValidation
/**
* Test Language::isValidBuiltInCode()
* @dataProvider provideLanguageCodes
* @covers Language::isValidBuiltInCode
*/
public function testBuiltInCodeValidation($code, $expected, $message = '')
{
$this->assertEquals($expected, (bool) Language::isValidBuiltInCode($code), "validating code {$code} {$message}");
}