本文整理汇总了PHP中IContextSource::getLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP IContextSource::getLanguage方法的具体用法?PHP IContextSource::getLanguage怎么用?PHP IContextSource::getLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContextSource
的用法示例。
在下文中一共展示了IContextSource::getLanguage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRestrictionsText
/**
* If the page is protected, get the relevant text
* for those restrictions
*
* @param array $restrictions
* @return string
*/
private function getRestrictionsText(array $restrictions)
{
$protected = '';
if (!$restrictions) {
return $protected;
}
// Check backwards-compatible messages
$msg = null;
if ($restrictions === ['sysop']) {
$msg = $this->context->msg('template-protected');
} elseif ($restrictions === ['autoconfirmed']) {
$msg = $this->context->msg('template-semiprotected');
}
if ($msg && !$msg->isDisabled()) {
$protected = $msg->parse();
} else {
// Construct the message from restriction-level-*
// e.g. restriction-level-sysop, restriction-level-autoconfirmed
$msgs = [];
foreach ($restrictions as $r) {
$msgs[] = $this->context->msg("restriction-level-{$r}")->parse();
}
$protected = $this->context->msg('parentheses')->rawParams($this->context->getLanguage()->commaList($msgs))->escaped();
}
return $protected;
}
示例2: addNavigationLinks
/**
* @param $context IContextSource
* @param $pageType
*/
public static function addNavigationLinks(IContextSource $context, $pageType)
{
$linkDefs = array('home' => 'Special:AbuseFilter', 'recentchanges' => 'Special:AbuseFilter/history', 'examine' => 'Special:AbuseFilter/examine', 'log' => 'Special:AbuseLog');
if ($context->getUser()->isAllowed('abusefilter-modify')) {
$linkDefs = array_merge($linkDefs, array('test' => 'Special:AbuseFilter/test', 'tools' => 'Special:AbuseFilter/tools', 'import' => 'Special:AbuseFilter/import'));
}
// Save some translator work
$msgOverrides = array('recentchanges' => 'abusefilter-filter-log');
$links = array();
foreach ($linkDefs as $name => $page) {
// Give grep a chance to find the usages:
// abusefilter-topnav-home, abusefilter-topnav-test, abusefilter-topnav-examine
// abusefilter-topnav-log, abusefilter-topnav-tools, abusefilter-topnav-import
$msgName = "abusefilter-topnav-{$name}";
if (isset($msgOverrides[$name])) {
$msgName = $msgOverrides[$name];
}
$msg = wfMessage($msgName)->parse();
$title = Title::newFromText($page);
if ($name == $pageType) {
$links[] = Xml::tags('strong', null, $msg);
} else {
$links[] = Linker::link($title, $msg);
}
}
$linkStr = wfMessage('parentheses', $context->getLanguage()->pipeList($links))->text();
$linkStr = wfMessage('abusefilter-topnav')->parse() . " {$linkStr}";
$linkStr = Xml::tags('div', array('class' => 'mw-abusefilter-navigation'), $linkStr);
$context->getOutput()->setSubtitle($linkStr);
}
示例3: contents
public function contents()
{
$optional = $this->context->msg('translate-optional')->escaped();
$this->doLinkBatch();
$sourceLang = Language::factory($this->group->getSourceLanguage());
$targetLang = Language::factory($this->collection->getLanguage());
$titleMap = $this->collection->keys();
$output = '';
$this->collection->initMessages();
// Just to be sure
/**
* @var TMessage $m
*/
foreach ($this->collection as $key => $m) {
$tools = array();
/**
* @var Title $title
*/
$title = $titleMap[$key];
$original = $m->definition();
$translation = $m->translation();
$hasTranslation = $translation !== null;
if ($hasTranslation) {
$message = $translation;
$extraAttribs = self::getLanguageAttributes($targetLang);
} else {
$message = $original;
$extraAttribs = self::getLanguageAttributes($sourceLang);
}
Hooks::run('TranslateFormatMessageBeforeTable', array(&$message, $m, $this->group, $targetLang, &$extraAttribs));
// Using Html::element( a ) because Linker::link is memory hog.
// It takes about 20 KiB per call, and that times 5000 is quite
// a lot of memory.
$niceTitle = htmlspecialchars($this->context->getLanguage()->truncate($title->getPrefixedText(), -35));
$linkAttribs = array('href' => $title->getLocalUrl(array('action' => 'edit')));
$linkAttribs += TranslationEditPage::jsEdit($title, $this->group->getId());
$tools['edit'] = Html::element('a', $linkAttribs, $niceTitle);
$anchor = 'msg_' . $key;
$anchor = Xml::element('a', array('id' => $anchor, 'href' => "#{$anchor}"), "↓");
$extra = '';
if ($m->hasTag('optional')) {
$extra = '<br />' . $optional;
}
$tqeData = $extraAttribs + array('data-title' => $title->getPrefixedText(), 'data-group' => $this->group->getId(), 'id' => 'tqe-anchor-' . substr(sha1($title->getPrefixedText()), 0, 12), 'class' => 'tqe-inlineeditable ' . ($hasTranslation ? 'translated' : 'untranslated'));
$button = $this->getReviewButton($m);
$status = $this->getReviewStatus($m);
$leftColumn = $button . $anchor . $tools['edit'] . $extra . $status;
if ($this->reviewMode) {
$output .= Xml::tags('tr', array('class' => 'orig'), Xml::tags('td', array('rowspan' => '2'), $leftColumn) . Xml::tags('td', self::getLanguageAttributes($sourceLang), TranslateUtils::convertWhiteSpaceToHTML($original)));
$output .= Xml::tags('tr', null, Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
} else {
$output .= Xml::tags('tr', array('class' => 'def'), Xml::tags('td', null, $leftColumn) . Xml::tags('td', $tqeData, TranslateUtils::convertWhiteSpaceToHTML($message)));
}
$output .= "\n";
}
return $output;
}
示例4: getDescription
/**
* MediaWiki extensions all should have key in their i18n files
* describing them. This override method implements the logic
* to retrieve them. Also URLs are included if available.
* Needs the Configure extension.
* @param IContextSource $context
* @return string
*/
public function getDescription(IContextSource $context = null)
{
$language = $this->getSourceLanguage();
if ($context) {
$language = $context->getLanguage()->getCode();
}
$msgkey = $this->getFromConf('BASIC', 'descriptionmsg');
$desc = '';
if ($msgkey) {
$desc = $this->getMessage($msgkey, $language);
if (strval($desc) === '') {
$desc = $this->getMessage($msgkey, $this->getSourceLanguage());
}
}
if (strval($desc) === '') {
// That failed, default to 'description'
$desc = parent::getDescription($context);
}
$url = $this->getFromConf('BASIC', 'extensionurl');
if ($url) {
$desc .= "\n\n{$url}";
}
return $desc;
}
示例5: onGetEmailAuthentication
public static function onGetEmailAuthentication(User &$user, IContextSource $context, &$disableEmailPrefs, &$emailauthenticated)
{
if ($user->getEmail()) {
$emailTimestamp = $user->getEmailAuthenticationTimestamp();
$optionNewEmail = $user->getGlobalAttribute('new_email');
$msgKeyPrefixEmail = empty($optionNewEmail) && !$emailTimestamp ? 'usersignup-user-pref-unconfirmed-' : 'usersignup-user-pref-';
if (empty($optionNewEmail) && $emailTimestamp) {
$lang = $context->getLanguage();
$displayUser = $context->getUser();
$time = $lang->userTimeAndDate($emailTimestamp, $displayUser);
$d = $lang->userDate($emailTimestamp, $displayUser);
$t = $lang->userTime($emailTimestamp, $displayUser);
$emailauthenticated = $context->msg($msgKeyPrefixEmail . 'emailauthenticated', $time, $d, $t)->parse() . '<br />';
$disableEmailPrefs = false;
} else {
$disableEmailPrefs = true;
$emailauthenticated = $context->msg($msgKeyPrefixEmail . 'emailnotauthenticated', array($optionNewEmail))->parse() . '<br />' . Linker::linkKnown(SpecialPage::getTitleFor('Confirmemail'), $context->msg('usersignup-user-pref-emailconfirmlink')->escaped()) . '<br />';
}
} else {
$disableEmailPrefs = true;
$emailauthenticated = $context->msg('usersignup-user-pref-noemailprefs')->escaped();
}
return true;
}
示例6: getTimezoneOptions
/**
* @param IContextSource $context
* @return array
*/
static function getTimezoneOptions(IContextSource $context)
{
$opt = array();
$localTZoffset = $context->getConfig()->get('LocalTZoffset');
$timeZoneList = self::getTimeZoneList($context->getLanguage());
$timestamp = MWTimestamp::getLocalInstance();
// Check that the LocalTZoffset is the same as the local time zone offset
if ($localTZoffset == $timestamp->format('Z') / 60) {
$timezoneName = $timestamp->getTimezone()->getName();
// Localize timezone
if (isset($timeZoneList[$timezoneName])) {
$timezoneName = $timeZoneList[$timezoneName]['name'];
}
$server_tz_msg = $context->msg('timezoneuseserverdefault', $timezoneName)->text();
} else {
$tzstring = sprintf('%+03d:%02d', floor($localTZoffset / 60), abs($localTZoffset) % 60);
$server_tz_msg = $context->msg('timezoneuseserverdefault', $tzstring)->text();
}
$opt[$server_tz_msg] = "System|{$localTZoffset}";
$opt[$context->msg('timezoneuseoffset')->text()] = 'other';
$opt[$context->msg('guesstimezone')->text()] = 'guess';
foreach ($timeZoneList as $timeZoneInfo) {
$region = $timeZoneInfo['region'];
if (!isset($opt[$region])) {
$opt[$region] = array();
}
$opt[$region][$timeZoneInfo['name']] = $timeZoneInfo['timecorrection'];
}
return $opt;
}
示例7: setContext
/**
* Set the language and the title from a context object
*
* @since 1.19
*
* @param IContextSource $context
*
* @return Message $this
*/
public function setContext(IContextSource $context)
{
$this->inLanguage($context->getLanguage());
$this->title($context->getTitle());
$this->interface = true;
return $this;
}
示例8: getPermissionsError
/**
* Get the key and parameters for the corresponding error message.
*
* @since 1.22
* @param IContextSource $context
* @return array
*/
public function getPermissionsError(IContextSource $context)
{
$blocker = $this->getBlocker();
if ($blocker instanceof User) {
// local user
$blockerUserpage = $blocker->getUserPage();
$link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]";
} else {
// foreign user
$link = $blocker;
}
$reason = $this->mReason;
if ($reason == '') {
$reason = $context->msg('blockednoreason')->text();
}
/* $ip returns who *is* being blocked, $intended contains who was meant to be blocked.
* This could be a username, an IP range, or a single IP. */
$intended = $this->getTarget();
$lang = $context->getLanguage();
return array($this->mAuto ? 'autoblockedtext' : 'blockedtext', $link, $reason, $context->getRequest()->getIP(), $this->getByName(), $this->getId(), $lang->formatExpiry($this->mExpiry), (string) $intended, $lang->userTimeAndDate($this->mTimestamp, $context->getUser()));
}
示例9: getDebugInfo
/**
* Returns the HTML to add to the page for the toolbar
*
* @param $context IContextSource
* @return array
*/
public static function getDebugInfo(IContextSource $context)
{
if (!self::$enabled) {
return array();
}
global $wgVersion, $wgRequestTime;
$request = $context->getRequest();
return array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage()), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage()), 'includes' => self::getFilesIncluded($context));
}
示例10: getDebugInfo
/**
* Returns the HTML to add to the page for the toolbar
*
* @param IContextSource $context
* @return array
*/
public static function getDebugInfo(IContextSource $context)
{
if (!self::$enabled) {
return array();
}
global $wgVersion, $wgRequestTime;
$request = $context->getRequest();
// HHVM's reported memory usage from memory_get_peak_usage()
// is not useful when passing false, but we continue passing
// false for consistency of historical data in zend.
// see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246
$realMemoryUsage = wfIsHHVM();
return array('mwVersion' => $wgVersion, 'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP', 'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage($realMemoryUsage)), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage($realMemoryUsage)), 'includes' => self::getFilesIncluded($context));
}
示例11: getDescription
public function getDescription(IContextSource $context = null)
{
$title = $this->getTitle()->getPrefixedText();
$target = ":{$title}";
$pageLanguageCode = $this->getSourceLanguage();
$inLanguageCode = $context ? $context->getLanguage()->getCode() : null;
$languageName = Language::fetchLanguageName($pageLanguageCode, $inLanguageCode);
// Allow for adding a custom group description by using
// "MediaWiki:Tp-custom-<group ID>".
$customText = '';
$msg = wfMessage('tp-custom-' . $this->id);
self::addContext($msg, $context);
if ($msg->exists()) {
$customText = $msg->plain();
}
$msg = wfMessage('translate-tag-page-desc', $title, $target, $languageName, $pageLanguageCode);
self::addContext($msg, $context);
return $msg->plain() . $customText;
}
示例12: getToolLinks
/**
* Returns the tool links for this mentor.
*
* @since 0.1
*
* @param IContextSource $context
* @param EPCourse|null $course
*
* @return string
*/
public function getToolLinks(IContextSource $context, EPCourse $course = null)
{
$links = array();
$links[] = Linker::userTalkLink($this->getUser()->getId(), $this->getUser()->getName());
$links[] = Linker::link(SpecialPage::getTitleFor('Contributions', $this->getUser()->getName()), wfMsgHtml('contribslink'));
if (!is_null($course) && ($context->getUser()->isAllowed('ep-instructor') || $this->getUser()->getId() == $context->getUser()->getId())) {
$links[] = Html::element('a', array('href' => '#', 'class' => 'ep-instructor-remove', 'data-courseid' => $course->getId(), 'data-coursename' => $course->getField('name'), 'data-userid' => $this->getUser()->getId(), 'data-username' => $this->getUser()->getName(), 'data-bestname' => $this->getName()), wfMsg('ep-instructor-remove'));
$context->getOutput()->addModules('ep.instructor');
}
return ' <span class="mw-usertoollinks">(' . $context->getLanguage()->pipeList($links) . ')</span>';
}
示例13: displayNavigation
/**
* Adds a navigation menu with the provided links.
* Links should be provided in an array with:
* label => Title (object)
*
* @since 0.1
*
* @param IContextSource $context
* @param array $items
*/
public static function displayNavigation(IContextSource $context, array $items = array())
{
$links = array();
foreach ($items as $label => $data) {
if (is_array($data)) {
$target = array_shift($data);
$attribs = $data;
} else {
$target = $data;
$attribs = array();
}
$links[] = Linker::linkKnown($target, htmlspecialchars($label), $attribs);
}
$context->getOutput()->addHTML(Html::rawElement('p', array(), $context->getLanguage()->pipeList($links)));
}
示例14: getLanguage
/**
* Get the Language being used for this instance.
* IndexPager extends ContextSource as of 1.19.
*
* @since 0.1
*
* @return Language
*/
public function getLanguage()
{
return $this->context->getLanguage();
}
示例15: formatStatusErrors
/**
* Wrap status errors in an errorbox for increased visiblity
*
* @param Status $status
* @return string
*/
private function formatStatusErrors(Status $status)
{
$errmsg = $status->getHTML('edit-error-short', 'edit-error-long', $this->context->getLanguage());
return <<<ERROR
<div class="errorbox">
{$errmsg}
</div>
<br clear="all" />
ERROR;
}