本文整理汇总了PHP中Language::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::factory方法的具体用法?PHP Language::factory怎么用?PHP Language::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$langObj = Language::factory('en');
$localZone = 'UTC';
$localOffset = date('Z') / 60;
$this->setMwGlobals(array('wgMemc' => new EmptyBagOStuff(), 'wgContLang' => $langObj, 'wgLang' => $langObj, 'wgLocaltimezone' => $localZone, 'wgLocalTZoffset' => $localOffset, 'wgNamespaceProtection' => array(NS_MEDIAWIKI => 'editinterface')));
$this->userName = 'Useruser';
$this->altUserName = 'Altuseruser';
date_default_timezone_set($localZone);
$this->title = Title::makeTitle(NS_MAIN, "Main Page");
if (!isset($this->userUser) || !$this->userUser instanceof User) {
$this->userUser = User::newFromName($this->userName);
if (!$this->userUser->getID()) {
$this->userUser = User::createNew($this->userName, array("email" => "test@example.com", "real_name" => "Test User"));
$this->userUser->load();
}
$this->altUser = User::newFromName($this->altUserName);
if (!$this->altUser->getID()) {
$this->altUser = User::createNew($this->altUserName, array("email" => "alttest@example.com", "real_name" => "Test User Alt"));
$this->altUser->load();
}
$this->anonUser = User::newFromId(0);
$this->user = $this->userUser;
}
}
示例2: initLanguage
/**
* Internal utility function for initialising the global entity language
* fallback sequence.
*/
function initLanguage( $user, $election ) {
global $wgRequest, $wgLang;
$uselang = $wgRequest->getVal( 'uselang' );
if ( $uselang !== null ) {
$userLang = $uselang;
} elseif ( $user instanceof SecurePoll_Voter ) {
$userLang = $user->getLanguage();
} else {
$userLang = $user->getOption( 'language' );
}
$wgLang = Language::factory( $userLang );
$languages = array( $userLang );
$fallback = $userLang;
while ( $fallback = Language::getFallbackFor( $fallback ) ) {
$languages[] = $fallback;
}
if ( $fallback != $election->getLanguage() ) {
$fallback = $election->getLanguage();
$languages[] = $fallback;
}
if ( $fallback != 'en' ) {
$languages[] = 'en';
}
$this->context->setLanguages( $languages );
}
示例3: execute
/**
* Generates the html snippet for ajax edit. Echoes it to the output and
* disabled all other output.
*/
public function execute()
{
global $wgServer, $wgScriptPath;
$context = RequestContext::getMain();
$context->getOutput()->disable();
$data = $this->getEditInfo();
$helpers = new TranslationHelpers($this->getTitle(), '');
$id = "tm-target-{$helpers->dialogID()}";
$helpers->setTextareaId($id);
if ($this->suggestions === 'checks') {
echo $helpers->getBoxes($this->suggestions);
return;
}
$handle = new MessageHandle($this->getTitle());
$groupId = MessageIndex::getPrimaryGroupId($handle);
$translation = '';
if ($groupId) {
$translation = $helpers->getTranslation();
}
$targetLang = Language::factory($helpers->getTargetLanguage());
$textareaParams = array('name' => 'text', 'class' => 'mw-translate-edit-area', 'id' => $id, 'lang' => $targetLang->getCode(), 'dir' => $targetLang->getDir());
if (!$groupId || !$context->getUser()->isAllowed('translate')) {
$textareaParams['readonly'] = 'readonly';
}
$extraInputs = '';
Hooks::run('TranslateGetExtraInputs', array(&$translation, &$extraInputs));
$textarea = Html::element('textarea', $textareaParams, $translation);
$hidden = array();
$hidden[] = Html::hidden('title', $this->getTitle()->getPrefixedDbKey());
if (isset($data['revisions'][0]['timestamp'])) {
$hidden[] = Html::hidden('basetimestamp', $data['revisions'][0]['timestamp']);
}
$hidden[] = Html::hidden('starttimestamp', $data['starttimestamp']);
if (isset($data['edittoken'])) {
$hidden[] = Html::hidden('token', $data['edittoken']);
}
$hidden[] = Html::hidden('format', 'json');
$hidden[] = Html::hidden('action', 'edit');
$summary = Xml::inputLabel($context->msg('translate-js-summary')->text(), 'summary', 'summary', 40);
$save = Xml::submitButton($context->msg('translate-js-save')->text(), array('class' => 'mw-translate-save'));
$saveAndNext = Xml::submitButton($context->msg('translate-js-next')->text(), array('class' => 'mw-translate-next'));
$skip = Html::element('input', array('class' => 'mw-translate-skip', 'type' => 'button', 'value' => $context->msg('translate-js-skip')->text()));
if ($this->getTitle()->exists()) {
$history = Html::element('input', array('class' => 'mw-translate-history', 'type' => 'button', 'value' => $context->msg('translate-js-history')->text()));
} else {
$history = '';
}
$support = $this->getSupportButton($this->getTitle());
if ($context->getUser()->isAllowed('translate')) {
$bottom = "{$summary}{$save}{$saveAndNext}{$skip}{$history}{$support}";
} else {
$text = $context->msg('translate-edit-nopermission')->escaped();
$button = $this->getPermissionPageButton();
$bottom = "{$text} {$button}{$skip}{$history}{$support}";
}
// Use the api to submit edits
$formParams = array('action' => "{$wgServer}{$wgScriptPath}/api.php", 'method' => 'post');
$form = Html::rawElement('form', $formParams, implode("\n", $hidden) . "\n" . $helpers->getBoxes($this->suggestions) . "\n" . Html::rawElement('div', array('class' => 'mw-translate-inputs'), "{$textarea}\n{$extraInputs}") . "\n" . Html::rawElement('div', array('class' => 'mw-translate-bottom'), $bottom));
echo Html::rawElement('div', array('class' => 'mw-ajax-dialog'), $form);
}
示例4: setUp
protected function setUp()
{
parent::setUp();
$langObj = Language::factory('en');
$langObj->setNamespaces([-2 => 'Media', -1 => 'Special', 0 => '', 1 => 'Talk', 2 => 'User', 3 => 'User_talk', 4 => 'MyWiki', 5 => 'MyWiki_Talk', 6 => 'File', 7 => 'File_talk', 8 => 'MediaWiki', 9 => 'MediaWiki_talk', 10 => 'Template', 11 => 'Template_talk', 100 => 'Custom', 101 => 'Custom_talk']);
$this->setMwGlobals(['wgLang' => $langObj, 'wgUseMediaWikiUIEverywhere' => false]);
}
示例5: wfInstallerMain
function wfInstallerMain()
{
global $wgRequest, $wgLang, $wgMetaNamespace, $wgCanonicalNamespaceNames;
$installer = new WebInstaller($wgRequest);
if (!$installer->startSession()) {
$installer->finish();
exit;
}
$fingerprint = $installer->getFingerprint();
if (isset($_SESSION['installData'][$fingerprint])) {
$session = $_SESSION['installData'][$fingerprint];
} else {
$session = array();
}
if (!is_null($wgRequest->getVal('uselang'))) {
$langCode = $wgRequest->getVal('uselang');
} elseif (isset($session['settings']['_UserLang'])) {
$langCode = $session['settings']['_UserLang'];
} else {
$langCode = 'en';
}
$wgLang = Language::factory($langCode);
$installer->setParserLanguage($wgLang);
$wgMetaNamespace = $wgCanonicalNamespaceNames[NS_PROJECT];
$session = $installer->execute($session);
$_SESSION['installData'][$fingerprint] = $session;
}
示例6: setUp
function setUp()
{
global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
parent::setUp();
if (!$wgMemc) {
$wgMemc = new EmptyBagOStuff();
}
$wgContLang = $wgLang = Language::factory('en');
$this->userName = "Useruser";
$this->altUserName = "Altuseruser";
date_default_timezone_set($wgLocaltimezone);
$wgLocalTZoffset = date("Z") / 60;
$this->title = Title::makeTitle(NS_MAIN, "Main Page");
if (!isset($this->userUser) || !$this->userUser instanceof User) {
$this->userUser = User::newFromName($this->userName);
if (!$this->userUser->getID()) {
$this->userUser = User::createNew($this->userName, array("email" => "test@example.com", "real_name" => "Test User"));
$this->userUser->load();
}
$this->altUser = User::newFromName($this->altUserName);
if (!$this->altUser->getID()) {
$this->altUser = User::createNew($this->altUserName, array("email" => "alttest@example.com", "real_name" => "Test User Alt"));
$this->altUser->load();
}
$this->anonUser = User::newFromId(0);
$this->user = $this->userUser;
}
}
示例7: execute
public function execute()
{
global $wgMessageCache;
$params = $this->extractRequestParams();
if (!is_null($params['lang'])) {
global $wgLang;
$wgLang = Language::factory($params['lang']);
}
//Determine which messages should we print
$messages_target = array();
if ($params['messages'] == '*') {
$wgMessageCache->loadAllMessages();
$message_names = array_keys(array_merge(Language::getMessagesFor('en'), $wgMessageCache->getExtensionMessagesFor('en')));
sort($message_names);
$messages_target = $message_names;
} else {
$messages_target = explode('|', $params['messages']);
}
//Filter messages
if (isset($params['filter'])) {
$messages_filtered = array();
foreach ($messages_target as $message) {
if (strpos($message, $params['filter']) !== false) {
//!== is used because filter can be at the beginnig of the string
$messages_filtered[] = $message;
}
}
$messages_target = $messages_filtered;
}
//Get all requested messages
$messages = array();
$skip = !is_null($params['from']);
foreach ($messages_target as $message) {
// Skip all messages up to $params['from']
if ($skip && $message === $params['from']) {
$skip = false;
}
if (!$skip) {
$messages[$message] = wfMsg($message);
}
}
//Print the result
$result = $this->getResult();
$messages_out = array();
foreach ($messages as $name => $value) {
$message = array();
$message['name'] = $name;
if (wfEmptyMsg($name, $value)) {
$message['missing'] = '';
} else {
$result->setContent($message, $value);
}
$fit = $result->addValue(array('query', $this->getModuleName()), null, $message);
if (!$fit) {
$this->setContinueEnumParameter('from', $name);
break;
}
}
$result->setIndexedTagName_internal(array('query', $this->getModuleName()), 'message');
}
示例8: __construct
public function __construct()
{
// This will set $locale and collators, which affect the actual sorting order
parent::__construct('fa');
// Override the 'fa' language set by parent constructor, which affects #getFirstLetterData()
$this->digitTransformLanguage = Language::factory('ckb');
}
示例9: testGetpageviewlanguage
/**
* @dataProvider provideCasesForGetpageviewlanguage
*/
function testGetpageviewlanguage($expected, $titleText, $contLang, $lang, $variant, $msg = '')
{
// Save globals
global $wgContLang, $wgLang, $wgAllowUserJs, $wgLanguageCode, $wgDefaultLanguageVariant;
$save['wgContLang'] = $wgContLang;
$save['wgLang'] = $wgLang;
$save['wgAllowUserJs'] = $wgAllowUserJs;
$save['wgLanguageCode'] = $wgLanguageCode;
$save['wgDefaultLanguageVariant'] = $wgDefaultLanguageVariant;
// Setup test environnement:
$wgContLang = Language::factory($contLang);
$wgLang = Language::factory($lang);
# To test out .js titles:
$wgAllowUserJs = true;
$wgLanguageCode = $contLang;
$wgDefaultLanguageVariant = $variant;
$title = Title::newFromText($titleText);
$this->assertInstanceOf('Title', $title, "Test must be passed a valid title text, you gave '{$titleText}'");
$this->assertEquals($expected, $title->getPageViewLanguage()->getCode(), $msg);
// Restore globals
$wgContLang = $save['wgContLang'];
$wgLang = $save['wgLang'];
$wgAllowUserJs = $save['wgAllowUserJs'];
$wgLanguageCode = $save['wgLanguageCode'];
$wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant'];
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->initMessagesHref();
$this->skin = new SkinTemplate();
$this->skin->getContext()->setLanguage(Language::factory('en'));
}
示例11: getFeedsInternal
/**
* @param $langCode string
* @return array
* @throws MWException
*/
private static function getFeedsInternal($langCode)
{
global $wgFeaturedFeeds, $wgFeaturedFeedsDefaults, $wgContLang;
wfProfileIn(__METHOD__);
$feedDefs = $wgFeaturedFeeds;
wfRunHooks('FeaturedFeeds::getFeeds', array(&$feedDefs));
// fill defaults
foreach ($feedDefs as $name => $opts) {
foreach ($wgFeaturedFeedsDefaults as $setting => $value) {
if (!isset($opts[$setting])) {
$feedDefs[$name][$setting] = $value;
}
}
}
$feeds = array();
$requestedLang = Language::factory($langCode);
$parser = new Parser();
foreach ($feedDefs as $name => $opts) {
$feed = new FeaturedFeedChannel($name, $opts, $requestedLang);
if (!$feed->isOK()) {
continue;
}
$feed->getFeedItems();
$feeds[$name] = $feed;
}
wfProfileOut(__METHOD__);
return $feeds;
}
示例12: setUp
/**
* Anything that needs to happen before your tests should go here.
*/
function setUp()
{
global $wgContLang;
parent::setUp();
/* For example, we need to set $wgContLang for creating a new Title */
$wgContLang = Language::factory('en');
}
示例13: setUp
public function setUp()
{
global $wgLang, $wgLanguageCode;
self::$oldLang = $wgLang;
$wgLanguageCode = 'en';
$wgLang = Language::factory($wgLanguageCode);
}
示例14: go_auth
function go_auth()
{
global $wgUser, $wgLanguageCode, $wgRequest, $wgOut;
// For a few special pages, don't do anything.
$title = $wgRequest->getVal('title');
$lg = Language::factory($wgLanguageCode);
if ($title == $lg->specialPage("Userlogout") || $title == $lg->specialPage("Userlogin")) {
return true;
}
$data = go_getsession();
if ($wgUser->IsAnon() || $data && $wgUser->getName() != $data['username']) {
if (isset($data['user_id'])) {
$wgUser = User::newFromName($data['username']);
// Create a new account if the user does not exists
if ($wgUser->getID() == 0) {
// Create the user
$wgUser->addToDatabase();
$wgUser->setRealName($data['username']);
//$wgUser->setEmail($data['GO_SESSION']['email']);
$wgUser->setPassword(md5($data['username'] . 'zout'));
// do something random
$wgUser->setToken();
$wgUser->saveSettings();
// Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
}
$wgUser->setOption("rememberpassword", 1);
$wgUser->setCookies();
$wgOut->returnToMain();
}
}
return true;
}
示例15: getTestContext
public function getTestContext(User $user)
{
$context = new RequestContext();
$context->setLanguage(Language::factory('en'));
$context->setUser($user);
return $context;
}