/** * 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; }
/** * @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); }
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; }
/** * 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; }
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; }
/** * @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; }
/** * 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; }
/** * 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())); }
/** * 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)); }
/** * 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)); }
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; }
/** * 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>'; }
/** * 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))); }
/** * 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(); }
/** * 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; }
protected static function addContext(Message $message, IContextSource $context = null) { if ($context) { $message->inLanguage($context->getLanguage()); } return $message; }
/** * Check if pages can be cached for this request/user * @param IContextSource $context * @param integer $mode One of the HTMLFileCache::MODE_* constants (since 1.28) * @return bool */ public static function useFileCache(IContextSource $context, $mode = self::MODE_NORMAL) { $config = MediaWikiServices::getInstance()->getMainConfig(); if (!$config->get('UseFileCache') && $mode !== self::MODE_REBUILD) { return false; } elseif ($config->get('DebugToolbar')) { wfDebug("HTML file cache skipped. \$wgDebugToolbar on\n"); return false; } // Get all query values $queryVals = $context->getRequest()->getValues(); foreach ($queryVals as $query => $val) { if ($query === 'title' || $query === 'curid') { continue; // note: curid sets title // Normal page view in query form can have action=view. } elseif ($query === 'action' && in_array($val, self::cacheablePageActions())) { continue; // Below are header setting params } elseif ($query === 'maxage' || $query === 'smaxage') { continue; } return false; } $user = $context->getUser(); // Check for non-standard user language; this covers uselang, // and extensions for auto-detecting user language. $ulang = $context->getLanguage(); // Check that there are no other sources of variation if ($user->getId() || $ulang->getCode() !== $config->get('LanguageCode')) { return false; } if ($mode === self::MODE_NORMAL) { if ($user->getNewtalk()) { return false; } } // Allow extensions to disable caching return Hooks::run('HTMLFileCache::useFileCache', [$context]); }
/** * Check if pages can be cached for this request/user * @param $context IContextSource * @return bool */ public static function useFileCache(IContextSource $context) { global $wgUseFileCache, $wgShowIPinHeader, $wgDebugToolbar, $wgContLang; if (!$wgUseFileCache) { return false; } if ($wgShowIPinHeader || $wgDebugToolbar) { wfDebug("HTML file cache skipped. Either \$wgShowIPinHeader and/or \$wgDebugToolbar on\n"); return false; } // Get all query values $queryVals = $context->getRequest()->getValues(); foreach ($queryVals as $query => $val) { if ($query === 'title' || $query === 'curid') { continue; // note: curid sets title // Normal page view in query form can have action=view. } elseif ($query === 'action' && in_array($val, self::cacheablePageActions())) { continue; // Below are header setting params } elseif ($query === 'maxage' || $query === 'smaxage') { continue; } return false; } $user = $context->getUser(); // Check for non-standard user language; this covers uselang, // and extensions for auto-detecting user language. $ulang = $context->getLanguage()->getCode(); $clang = $wgContLang->getCode(); // Check that there are no other sources of variation return !$user->getId() && !$user->getNewtalk() && $ulang == $clang; }
/** * Generate help for the specified modules * * Help is placed into the OutputPage object returned by * $context->getOutput(). * * Recognized options include: * - headerlevel: (int) Header tag level * - nolead: (bool) Skip the inclusion of api-help-lead * - noheader: (bool) Skip the inclusion of the top-level section headers * - submodules: (bool) Include help for submodules of the current module * - recursivesubmodules: (bool) Include help for submodules recursively * - helptitle: (string) Title to link for additional modules' help. Should contain $1. * - toc: (bool) Include a table of contents * * @param IContextSource $context * @param ApiBase[]|ApiBase $modules * @param array $options Formatting options (described above) * @return string */ public static function getHelp(IContextSource $context, $modules, array $options) { global $wgContLang; if (!is_array($modules)) { $modules = array($modules); } $out = $context->getOutput(); $out->addModuleStyles('mediawiki.hlist'); $out->addModuleStyles('mediawiki.apihelp'); if (!empty($options['toc'])) { $out->addModules('mediawiki.toc'); } $out->setPageTitle($context->msg('api-help-title')); $cache = ObjectCache::getMainWANInstance(); $cacheKey = null; if (count($modules) == 1 && $modules[0] instanceof ApiMain && $options['recursivesubmodules'] && $context->getLanguage() === $wgContLang) { $cacheHelpTimeout = $context->getConfig()->get('APICacheHelpTimeout'); if ($cacheHelpTimeout > 0) { // Get help text from cache if present $cacheKey = wfMemcKey('apihelp', $modules[0]->getModulePath(), (int) (!empty($options['toc'])), str_replace(' ', '_', SpecialVersion::getVersion('nodb'))); $cached = $cache->get($cacheKey); if ($cached) { $out->addHTML($cached); return; } } } if ($out->getHTML() !== '') { // Don't save to cache, there's someone else's content in the page // already $cacheKey = null; } $options['recursivesubmodules'] = !empty($options['recursivesubmodules']); $options['submodules'] = $options['recursivesubmodules'] || !empty($options['submodules']); // Prepend lead if (empty($options['nolead'])) { $msg = $context->msg('api-help-lead'); if (!$msg->isDisabled()) { $out->addHTML($msg->parseAsBlock()); } } $haveModules = array(); $html = self::getHelpInternal($context, $modules, $options, $haveModules); if (!empty($options['toc']) && $haveModules) { $out->addHTML(Linker::generateTOC($haveModules, $context->getLanguage())); } $out->addHTML($html); $helptitle = isset($options['helptitle']) ? $options['helptitle'] : null; $html = self::fixHelpLinks($out->getHTML(), $helptitle, $haveModules); $out->clearHTML(); $out->addHTML($html); if ($cacheKey !== null) { $cache->set($cacheKey, $out->getHTML(), $cacheHelpTimeout); } }
/** * Get a ParserOptions object from a IContextSource object * * @param IContextSource $context * @return ParserOptions */ public static function newFromContext(IContextSource $context) { return new ParserOptions($context->getUser(), $context->getLanguage()); }
/** * Returns the HTML to add to the page for the toolbar * * @param $context IContextSource * @return string */ public static function getDebugHTML(IContextSource $context) { if (!self::$enabled) { return ''; } global $wgVersion, $wgRequestTime; MWDebug::log('MWDebug output complete'); $request = $context->getRequest(); $debugInfo = array('mwVersion' => $wgVersion, 'phpVersion' => PHP_VERSION, 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $_SERVER['REQUEST_METHOD'], '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)); // Cannot use OutputPage::addJsConfigVars because those are already outputted // by the time this method is called. $html = Html::inlineScript(ResourceLoader::makeLoaderConditionalScript(ResourceLoader::makeConfigSetScript(array('debugInfo' => $debugInfo)))); return $html; }
/** * Just like executePath() but will override global variables and execute * the page in "inclusion" mode. Returns true if the execution was * successful or false if there was no such special page, or a title object * if it was a redirect. * * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang * variables so that the special page will get the context it'd expect on a * normal request, and then restores them to their previous values after. * * @param Title $title * @param IContextSource $context * @return string HTML fragment */ public static function capturePath(Title $title, IContextSource $context) { global $wgTitle, $wgOut, $wgRequest, $wgUser, $wgLang; $main = RequestContext::getMain(); // Save current globals and main context $glob = ['title' => $wgTitle, 'output' => $wgOut, 'request' => $wgRequest, 'user' => $wgUser, 'language' => $wgLang]; $ctx = ['title' => $main->getTitle(), 'output' => $main->getOutput(), 'request' => $main->getRequest(), 'user' => $main->getUser(), 'language' => $main->getLanguage()]; // Override $wgTitle = $title; $wgOut = $context->getOutput(); $wgRequest = $context->getRequest(); $wgUser = $context->getUser(); $wgLang = $context->getLanguage(); $main->setTitle($title); $main->setOutput($context->getOutput()); $main->setRequest($context->getRequest()); $main->setUser($context->getUser()); $main->setLanguage($context->getLanguage()); // The useful part $ret = self::executePath($title, $context, true); // Restore old globals and context $wgTitle = $glob['title']; $wgOut = $glob['output']; $wgRequest = $glob['request']; $wgUser = $glob['user']; $wgLang = $glob['language']; $main->setTitle($ctx['title']); $main->setOutput($ctx['output']); $main->setRequest($ctx['request']); $main->setUser($ctx['user']); $main->setLanguage($ctx['language']); return $ret; }
/** * Build the input form * * @return string HTML form */ function buildForm() { $user = $this->mContext->getUser(); $output = $this->mContext->getOutput(); $lang = $this->mContext->getLanguage(); $cascadingRestrictionLevels = $this->mContext->getConfig()->get('CascadingRestrictionLevels'); $out = ''; if (!$this->disabled) { $output->addModules('mediawiki.legacy.protect'); $output->addJsConfigVars('wgCascadeableLevels', $cascadingRestrictionLevels); $out .= Xml::openElement('form', array('method' => 'post', 'action' => $this->mTitle->getLocalURL('action=protect'), 'id' => 'mw-Protect-Form')); } $out .= Xml::openElement('fieldset') . Xml::element('legend', null, wfMessage('protect-legend')->text()) . Xml::openElement('table', array('id' => 'mwProtectSet')) . Xml::openElement('tbody'); $scExpiryOptions = wfMessage('protect-expiry-options')->inContentLanguage()->text(); $showProtectOptions = $scExpiryOptions !== '-' && !$this->disabled; // Not all languages have V_x <-> N_x relation foreach ($this->mRestrictions as $action => $selected) { // Messages: // restriction-edit, restriction-move, restriction-create, restriction-upload $msg = wfMessage('restriction-' . $action); $out .= "<tr><td>" . Xml::openElement('fieldset') . Xml::element('legend', null, $msg->exists() ? $msg->text() : $action) . Xml::openElement('table', array('id' => "mw-protect-table-{$action}")) . "<tr><td>" . $this->buildSelector($action, $selected) . "</td></tr><tr><td>"; $mProtectexpiry = Xml::label(wfMessage('protectexpiry')->text(), "mwProtectExpirySelection-{$action}"); $mProtectother = Xml::label(wfMessage('protect-othertime')->text(), "mwProtect-{$action}-expires"); $expiryFormOptions = ''; if ($this->mExistingExpiry[$action] && $this->mExistingExpiry[$action] != 'infinity') { $timestamp = $lang->timeanddate($this->mExistingExpiry[$action], true); $d = $lang->date($this->mExistingExpiry[$action], true); $t = $lang->time($this->mExistingExpiry[$action], true); $expiryFormOptions .= Xml::option(wfMessage('protect-existing-expiry', $timestamp, $d, $t)->text(), 'existing', $this->mExpirySelection[$action] == 'existing') . "\n"; } $expiryFormOptions .= Xml::option(wfMessage('protect-othertime-op')->text(), "othertime") . "\n"; foreach (explode(',', $scExpiryOptions) as $option) { if (strpos($option, ":") === false) { $show = $value = $option; } else { list($show, $value) = explode(":", $option); } $show = htmlspecialchars($show); $value = htmlspecialchars($value); $expiryFormOptions .= Xml::option($show, $value, $this->mExpirySelection[$action] === $value) . "\n"; } # Add expiry dropdown if ($showProtectOptions && !$this->disabled) { $out .= "\n\t\t\t\t\t<table><tr>\n\t\t\t\t\t\t<td class='mw-label'>\n\t\t\t\t\t\t\t{$mProtectexpiry}\n\t\t\t\t\t\t</td>\n\t\t\t\t\t\t<td class='mw-input'>" . Xml::tags('select', array('id' => "mwProtectExpirySelection-{$action}", 'name' => "wpProtectExpirySelection-{$action}", 'tabindex' => '2') + $this->disabledAttrib, $expiryFormOptions) . "</td>\n\t\t\t\t\t</tr></table>"; } # Add custom expiry field $attribs = array('id' => "mwProtect-{$action}-expires") + $this->disabledAttrib; $out .= "<table><tr>\n\t\t\t\t\t<td class='mw-label'>" . $mProtectother . '</td> <td class="mw-input">' . Xml::input("mwProtect-expiry-{$action}", 50, $this->mExpiry[$action], $attribs) . '</td> </tr></table>'; $out .= "</td></tr>" . Xml::closeElement('table') . Xml::closeElement('fieldset') . "</td></tr>"; } # Give extensions a chance to add items to the form wfRunHooks('ProtectionForm::buildForm', array($this->mArticle, &$out)); $out .= Xml::closeElement('tbody') . Xml::closeElement('table'); // JavaScript will add another row with a value-chaining checkbox if ($this->mTitle->exists()) { $out .= Xml::openElement('table', array('id' => 'mw-protect-table2')) . Xml::openElement('tbody'); $out .= '<tr> <td></td> <td class="mw-input">' . Xml::checkLabel(wfMessage('protect-cascade')->text(), 'mwProtect-cascade', 'mwProtect-cascade', $this->mCascade, $this->disabledAttrib) . "</td>\n\t\t\t\t</tr>\n"; $out .= Xml::closeElement('tbody') . Xml::closeElement('table'); } # Add manual and custom reason field/selects as well as submit if (!$this->disabled) { $mProtectreasonother = Xml::label(wfMessage('protectcomment')->text(), 'wpProtectReasonSelection'); $mProtectreason = Xml::label(wfMessage('protect-otherreason')->text(), 'mwProtect-reason'); $reasonDropDown = Xml::listDropDown('wpProtectReasonSelection', wfMessage('protect-dropdown')->inContentLanguage()->text(), wfMessage('protect-otherreason-op')->inContentLanguage()->text(), $this->mReasonSelection, 'mwProtect-reason', 4); $out .= Xml::openElement('table', array('id' => 'mw-protect-table3')) . Xml::openElement('tbody'); $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='mw-label'>\n\t\t\t\t\t\t{$mProtectreasonother}\n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>\n\t\t\t\t\t\t{$reasonDropDown}\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td class='mw-label'>\n\t\t\t\t\t\t{$mProtectreason}\n\t\t\t\t\t</td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::input('mwProtect-reason', 60, $this->mReason, array('type' => 'text', 'id' => 'mwProtect-reason', 'maxlength' => 180)) . "</td>\n\t\t\t\t</tr>"; # Disallow watching is user is not logged in if ($user->isLoggedIn()) { $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td class='mw-input'>" . Xml::checkLabel(wfMessage('watchthis')->text(), 'mwProtectWatch', 'mwProtectWatch', $user->isWatched($this->mTitle) || $user->getOption('watchdefault')) . "</td>\n\t\t\t\t</tr>"; } $out .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td></td>\n\t\t\t\t\t<td class='mw-submit'>" . Xml::submitButton(wfMessage('confirm')->text(), array('id' => 'mw-Protect-submit')) . "</td>\n\t\t\t\t</tr>\n"; $out .= Xml::closeElement('tbody') . Xml::closeElement('table'); } $out .= Xml::closeElement('fieldset'); if ($user->isAllowed('editinterface')) { $title = Title::makeTitle(NS_MEDIAWIKI, 'Protect-dropdown'); $link = Linker::link($title, wfMessage('protect-edit-reasonlist')->escaped(), array(), array('action' => 'edit')); $out .= '<p class="mw-protect-editreasons">' . $link . '</p>'; } if (!$this->disabled) { $out .= Html::hidden('wpEditToken', $user->getEditToken(array('protect', $this->mTitle->getPrefixedDBkey()))); $out .= Xml::closeElement('form'); } return $out; }
/** * Just like executePath() but will override global variables and execute * the page in "inclusion" mode. Returns true if the execution was * successful or false if there was no such special page, or a title object * if it was a redirect. * * Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang * variables so that the special page will get the context it'd expect on a * normal request, and then restores them to their previous values after. * * @param $title Title * @param $context IContextSource * * @return String: HTML fragment */ static function capturePath(Title $title, IContextSource $context) { global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang; // Save current globals $oldTitle = $wgTitle; $oldOut = $wgOut; $oldRequest = $wgRequest; $oldUser = $wgUser; $oldLang = $wgLang; // Set the globals to the current context $wgTitle = $title; $wgOut = $context->getOutput(); $wgRequest = $context->getRequest(); $wgUser = $context->getUser(); $wgLang = $context->getLanguage(); // The useful part $ret = self::executePath($title, $context, true); // And restore the old globals $wgTitle = $oldTitle; $wgOut = $oldOut; $wgRequest = $oldRequest; $wgUser = $oldUser; $wgLang = $oldLang; return $ret; }
/** * Get the Language being used for this instance. * IndexPager extends ContextSource as of 1.19. * * @since 0.1 * * @return Language */ public function getLanguage() { return method_exists($this->context, 'getLanguage') ? $this->context->getLanguage() : $this->context->getLang(); }
/** * @param $context IContextSource * @return array */ static function getDateOptions( IContextSource $context ) { $lang = $context->getLanguage(); $dateopts = $lang->getDatePreferences(); $ret = array(); if ( $dateopts ) { if ( !in_array( 'default', $dateopts ) ) { $dateopts[] = 'default'; // Make sure default is always valid // Bug 19237 } // KLUGE: site default might not be valid for user language global $wgDefaultUserOptions; if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) { $wgDefaultUserOptions['date'] = 'default'; } $epoch = wfTimestampNow(); foreach ( $dateopts as $key ) { if ( $key == 'default' ) { $formatted = $context->msg( 'datedefault' )->escaped(); } else { $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) ); } $ret[$formatted] = $key; } } return $ret; }
/** * Returns a message that notifies the user he/she is looking at * a cached version of the page, including a refresh link. * * @since 1.20 * * @param IContextSource $context * @param boolean $includePurgeLink * * @return string */ public function getCachedNotice(IContextSource $context, $includePurgeLink = true) { if ($this->cacheExpiry < 86400 * 3650) { $message = $context->msg('cachedspecial-viewing-cached-ttl', $context->getLanguage()->formatDuration($this->cacheExpiry))->escaped(); } else { $message = $context->msg('cachedspecial-viewing-cached-ts')->escaped(); } if ($includePurgeLink) { $refreshArgs = $context->getRequest()->getQueryValues(); unset($refreshArgs['title']); $refreshArgs['action'] = 'purge'; $subPage = $context->getTitle()->getFullText(); $subPage = explode('/', $subPage, 2); $subPage = count($subPage) > 1 ? $subPage[1] : false; $message .= ' ' . Linker::link($context->getTitle($subPage), $context->msg('cachedspecial-refresh-now')->escaped(), array(), $refreshArgs); } return $message; }