/** * Hook function for EditFilterMergedContent * * @param IContextSource $context * @param Content $content * @param Status $status * @param string $summary * @param User $user * @param bool $minoredit * * @return bool */ static function filterMergedContent(IContextSource $context, Content $content, Status $status, $summary, User $user, $minoredit) { $title = $context->getTitle(); if (isset($title->spamBlackListFiltered) && $title->spamBlackListFiltered) { // already filtered return true; } // get the link from the not-yet-saved page content. // no need to generate html to get external links $pout = $content->getParserOutput($title, null, null, false); $links = array_keys($pout->getExternalLinks()); // HACK: treat the edit summary as a link if ($summary !== '') { $links[] = $summary; } $spamObj = BaseBlacklist::getInstance('spam'); $matches = $spamObj->filter($links, $title); if ($matches !== false) { $status->fatal('spamprotectiontext'); foreach ($matches as $match) { $status->fatal('spamprotectionmatch', $match); } } // Always return true, EditPage will look at $status->isOk(). return true; }
/** * Perform one of the "standard" actions * * @param $page Page * @param $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { global $wgUseSquid, $wgSquidMaxage; wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $page); if ($action instanceof Action) { # Let Squid cache things if we can purge them. if ($wgUseSquid && in_array($request->getFullRequestURL(), $requestTitle->getSquidURLs())) { $output->setSquidMaxage($wgSquidMaxage); } $action->show(); wfProfileOut(__METHOD__); return; } if (wfRunHooks('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } wfProfileOut(__METHOD__); }
/** * Perform one of the "standard" actions * * @param Page $page * @param Title $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!Hooks::run('MediaWikiPerformAction', [$output, $page, $title, $user, $request, $this])) { return; } $act = $this->getAction(); $action = Action::factory($act, $page, $this->context); if ($action instanceof Action) { // Narrow DB query expectations for this HTTP request $trxLimits = $this->config->get('TrxProfilerLimits'); $trxProfiler = Profiler::instance()->getTransactionProfiler(); if ($request->wasPosted() && !$action->doesWrites()) { $trxProfiler->setExpectations($trxLimits['POST-nonwrite'], __METHOD__); $request->markAsSafeRequest(); } # Let CDN cache things if we can purge them. if ($this->config->get('UseSquid') && in_array(wfExpandUrl($request->getRequestURL(), PROTO_INTERNAL), $requestTitle->getCdnUrls())) { $output->setCdnMaxage($this->config->get('SquidMaxage')); } $action->show(); return; } if (Hooks::run('UnknownAction', [$request->getVal('action', 'view'), $page])) { $output->setStatusCode(404); $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } }
/** * Perform one of the "standard" actions * * @param $page Page */ private function performAction(Page $page) { wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $page); if ($action instanceof Action) { $action->show(); wfProfileOut(__METHOD__); return; } if (wfRunHooks('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } wfProfileOut(__METHOD__); }
/** * Perform one of the "standard" actions * * @param Page $page * @param Title $requestTitle The original title, before any redirects were applied */ private function performAction(Page $page, Title $requestTitle) { $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!Hooks::run('MediaWikiPerformAction', array($output, $page, $title, $user, $request, $this))) { return; } $act = $this->getAction(); $action = Action::factory($act, $page, $this->context); if ($action instanceof Action) { # Let CDN cache things if we can purge them. if ($this->config->get('UseSquid') && in_array(wfExpandUrl($request->getRequestURL(), PROTO_INTERNAL), $requestTitle->getCdnUrls())) { $output->setCdnMaxage($this->config->get('SquidMaxage')); } $action->show(); return; } if (Hooks::run('UnknownAction', array($request->getVal('action', 'view'), $page))) { $output->setStatusCode(404); $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } }
/** * 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; }
/** * 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; }
/** * Get the Title being used for this instance. * IndexPager extends ContextSource as of 1.19. * * @since 0.1 * * @return Title */ public function getTitle() { return $this->context->getTitle(); }
public static function onInfoAction(IContextSource $ctx, &$pageinfo) { if (!self::$occupationController->isTalkpageOccupied($ctx->getTitle())) { return true; } // All of the info in this section is wrong for Flow pages, // so we'll just remove it. unset($pageinfo['header-edits']); // These keys are wrong on Flow pages, so we'll remove them static $badMessageKeys = array('pageinfo-length', 'pageinfo-content-model'); foreach ($pageinfo['header-basic'] as $num => $val) { if ($val[0] instanceof Message && in_array($val[0]->getKey(), $badMessageKeys)) { unset($pageinfo['header-basic'][$num]); } } return true; }
protected function makeOffsetLink($label, $offset, $nondefaults) { $query = array_merge($nondefaults, array('offset' => $offset)); $link = Linker::link($this->context->getTitle(), $label, array(), $query); return $link; }
/** * Common implementation for the APIEditBeforeSave, EditFilterMerged * and EditFilterMergedContent hooks. * * @param IContextSource $context the context of the edit * @param Content|null $content the new Content generated by the edit * @param string $text new page content (subject of filtering) * @param Status $status Error message to return * @param string $summary Edit summary for page * @param bool $minoredit whether this is a minor edit according to the user. * * @return bool */ public static function filterEdit(IContextSource $context, $content, $text, Status $status, $summary, $minoredit) { // Load vars $vars = new AbuseFilterVariableHolder(); $title = $context->getTitle(); // Some edits are running through multiple hooks, but we only want to filter them once if (isset($title->editAlreadyFiltered)) { return true; } elseif ($title) { $title->editAlreadyFiltered = true; } self::$successful_action_vars = false; self::$last_edit_page = false; $user = $context->getUser(); // Check for null edits. $oldtext = ''; $oldcontent = null; if ($title instanceof Title && $title->canExist() && $title->exists()) { // Make sure we load the latest text saved in database (bug 31656) $page = $context->getWikiPage(); $revision = $page->getRevision(); if (!$revision) { return true; } if (defined('MW_SUPPORTS_CONTENTHANDLER')) { $oldcontent = $revision->getContent(Revision::RAW); $oldtext = AbuseFilter::contentToString($oldcontent); } else { $oldtext = AbuseFilter::revisionToString($revision, Revision::RAW); } // Cache article object so we can share a parse operation $articleCacheKey = $title->getNamespace() . ':' . $title->getText(); AFComputedVariable::$articleCache[$articleCacheKey] = $page; } else { $page = null; } // Don't trigger for null edits. if ($content && $oldcontent && $oldcontent->equals($content)) { // Compare Content objects if available return true; } else { if (strcmp($oldtext, $text) == 0) { // Otherwise, compare strings return true; } } $vars->addHolders(AbuseFilter::generateUserVars($user), AbuseFilter::generateTitleVars($title, 'ARTICLE')); $vars->setVar('action', 'edit'); $vars->setVar('summary', $summary); $vars->setVar('minor_edit', $minoredit); $vars->setVar('old_wikitext', $oldtext); $vars->setVar('new_wikitext', $text); // TODO: set old_content and new_content vars, use them $vars->addHolders(AbuseFilter::getEditVars($title, $page)); $filter_result = AbuseFilter::filterAction($vars, $title); if (!$filter_result->isOK()) { $status->merge($filter_result); return true; // re-show edit form } self::$successful_action_vars = $vars; self::$last_edit_page = $page; return true; }
/** * @param $user User * @param $context IContextSource * @param $defaultPreferences * @return void */ static function profilePreferences($user, IContextSource $context, &$defaultPreferences) { global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode, $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars, $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication, $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress; ## User info ##################################### // Information panel $defaultPreferences['username'] = array('type' => 'info', 'label-message' => 'username', 'default' => $user->getName(), 'section' => 'personal/info'); $defaultPreferences['userid'] = array('type' => 'info', 'label-message' => 'uid', 'default' => $user->getId(), 'section' => 'personal/info'); # Get groups to which the user belongs $userEffectiveGroups = $user->getEffectiveGroups(); $userGroups = $userMembers = array(); foreach ($userEffectiveGroups as $ueg) { if ($ueg == '*') { // Skip the default * group, seems useless here continue; } $groupName = User::getGroupName($ueg); $userGroups[] = User::makeGroupLinkHTML($ueg, $groupName); $memberName = User::getGroupMember($ueg, $user->getName()); $userMembers[] = User::makeGroupLinkHTML($ueg, $memberName); } asort($userGroups); asort($userMembers); $lang = $context->getLanguage(); $defaultPreferences['usergroups'] = array('type' => 'info', 'label' => $context->msg('prefs-memberingroups')->numParams(count($userGroups))->parse(), 'default' => $context->msg('prefs-memberingroups-type', $lang->commaList($userGroups), $lang->commaList($userMembers))->plain(), 'raw' => true, 'section' => 'personal/info'); $defaultPreferences['editcount'] = array('type' => 'info', 'label-message' => 'prefs-edits', 'default' => $lang->formatNum($user->getEditCount()), 'section' => 'personal/info'); if ($user->getRegistration()) { $displayUser = $context->getUser(); $userRegistration = $user->getRegistration(); $defaultPreferences['registrationdate'] = array('type' => 'info', 'label-message' => 'prefs-registration', 'default' => $context->msg('prefs-registration-date-time', $lang->userTimeAndDate($userRegistration, $displayUser), $lang->userDate($userRegistration, $displayUser), $lang->userTime($userRegistration, $displayUser))->parse(), 'section' => 'personal/info'); } // Actually changeable stuff $defaultPreferences['realname'] = array('type' => $wgAuth->allowPropChange('realname') ? 'text' : 'info', 'default' => $user->getRealName(), 'section' => 'personal/info', 'label-message' => 'yourrealname', 'help-message' => 'prefs-help-realname'); $defaultPreferences['gender'] = array('type' => 'select', 'section' => 'personal/info', 'options' => array($context->msg('gender-male')->text() => 'male', $context->msg('gender-female')->text() => 'female', $context->msg('gender-unknown')->text() => 'unknown'), 'label-message' => 'yourgender', 'help-message' => 'prefs-help-gender'); if ($wgAuth->allowPasswordChange()) { $link = Linker::link(SpecialPage::getTitleFor('ChangePassword'), $context->msg('prefs-resetpass')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences'))); $defaultPreferences['password'] = array('type' => 'info', 'raw' => true, 'default' => $link, 'label-message' => 'yourpassword', 'section' => 'personal/info'); } if ($wgCookieExpiration > 0) { $defaultPreferences['rememberpassword'] = array('type' => 'toggle', 'label' => $context->msg('tog-rememberpassword')->numParams(ceil($wgCookieExpiration / (3600 * 24)))->text(), 'section' => 'personal/info'); } // Language $languages = Language::getLanguageNames(false); if (!array_key_exists($wgLanguageCode, $languages)) { $languages[$wgLanguageCode] = $wgLanguageCode; } ksort($languages); $options = array(); foreach ($languages as $code => $name) { $display = wfBCP47($code) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['language'] = array('type' => 'select', 'section' => 'personal/i18n', 'options' => $options, 'label-message' => 'yourlanguage'); /* see if there are multiple language variants to choose from*/ $variantArray = array(); if (!$wgDisableLangConversion) { $variants = $wgContLang->getVariants(); foreach ($variants as $v) { $v = str_replace('_', '-', strtolower($v)); $variantArray[$v] = $wgContLang->getVariantname($v, false); } $options = array(); foreach ($variantArray as $code => $name) { $display = wfBCP47($code) . ' - ' . $name; $options[$display] = $code; } if (count($variantArray) > 1) { $defaultPreferences['variant'] = array('label-message' => 'yourvariant', 'type' => 'select', 'options' => $options, 'section' => 'personal/i18n', 'help-message' => 'prefs-help-variant'); } } if (count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) { $defaultPreferences['noconvertlink'] = array('type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => 'tog-noconvertlink'); } // show a preview of the old signature first $oldsigWikiText = $wgParser->preSaveTransform("~~~", $context->getTitle(), $user, ParserOptions::newFromContext($context)); $oldsigHTML = $context->getOutput()->parseInline($oldsigWikiText, true, true); $defaultPreferences['oldsig'] = array('type' => 'info', 'raw' => true, 'label-message' => 'tog-oldsig', 'default' => $oldsigHTML, 'section' => 'personal/signature'); $defaultPreferences['nickname'] = array('type' => $wgAuth->allowPropChange('nickname') ? 'text' : 'info', 'maxlength' => $wgMaxSigChars, 'label-message' => 'yournick', 'validation-callback' => array('Preferences', 'validateSignature'), 'section' => 'personal/signature', 'filter-callback' => array('Preferences', 'cleanSignature')); $defaultPreferences['fancysig'] = array('type' => 'toggle', 'label-message' => 'tog-fancysig', 'help-message' => 'prefs-help-signature', 'section' => 'personal/signature'); ## Email stuff if ($wgEnableEmail) { $helpMessages[] = $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email'; if ($wgEnableUserEmail) { // additional messages when users can send email to each other $helpMessages[] = 'prefs-help-email-others'; } $link = Linker::link(SpecialPage::getTitleFor('ChangeEmail'), $context->msg($user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences'))); $emailAddress = $user->getEmail() ? htmlspecialchars($user->getEmail()) : ''; if ($wgAuth->allowPropChange('emailaddress')) { $emailAddress .= $emailAddress == '' ? $link : " ({$link})"; } $defaultPreferences['emailaddress'] = array('type' => 'info', 'raw' => true, 'default' => $emailAddress, 'label-message' => 'youremail', 'section' => 'personal/email', 'help-messages' => $helpMessages); $disableEmailPrefs = false; if ($wgEmailAuthentication) { if ($user->getEmail()) { if ($user->getEmailAuthenticationTimestamp()) { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialConfirmemail.php $displayUser = $context->getUser(); $emailTimestamp = $user->getEmailAuthenticationTimestamp(); $time = $lang->userTimeAndDate($emailTimestamp, $displayUser); $d = $lang->userDate($emailTimestamp, $displayUser); $t = $lang->userTime($emailTimestamp, $displayUser); $emailauthenticated = $context->msg('emailauthenticated', $time, $d, $t)->parse() . '<br />'; $disableEmailPrefs = false; } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg('emailnotauthenticated')->parse() . '<br />' . Linker::linkKnown(SpecialPage::getTitleFor('Confirmemail'), $context->msg('emailconfirmlink')->escaped()) . '<br />'; } } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg('noemailprefs')->escaped(); } $defaultPreferences['emailauthentication'] = array('type' => 'info', 'raw' => true, 'section' => 'personal/email', 'label-message' => 'prefs-emailconfirm-label', 'default' => $emailauthenticated); } if ($wgEnableUserEmail && $user->isAllowed('sendemail')) { $defaultPreferences['disablemail'] = array('type' => 'toggle', 'invert' => true, 'section' => 'personal/email', 'label-message' => 'allowemail', 'disabled' => $disableEmailPrefs); $defaultPreferences['ccmeonemails'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-ccmeonemails', 'disabled' => $disableEmailPrefs); } if ($wgEnotifWatchlist) { $defaultPreferences['enotifwatchlistpages'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifwatchlistpages', 'disabled' => $disableEmailPrefs); } if ($wgEnotifUserTalk) { $defaultPreferences['enotifusertalkpages'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifusertalkpages', 'disabled' => $disableEmailPrefs); } if ($wgEnotifUserTalk || $wgEnotifWatchlist) { $defaultPreferences['enotifminoredits'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifminoredits', 'disabled' => $disableEmailPrefs); if ($wgEnotifRevealEditorAddress) { $defaultPreferences['enotifrevealaddr'] = array('type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifrevealaddr', 'disabled' => $disableEmailPrefs); } } } }
function __construct(IContextSource $context, $templatetext, $argv, $parser) { global $wgContLang; $this->title = $context->getTitle(); $this->skin = $context->getSkin(); $this->parser = $parser; $this->templatetext = $templatetext; if (!is_null($this->templatetext)) { $this->templatetext = trim($this->templatetext); if ($this->templatetext == '') { $this->templatetext = null; } } $this->usetemplate = !is_null($this->templatetext); $this->templateparser = null; $this->templateoptions = null; #$template = @$argv['template']; #if ( $this->usetemplate ) { #print "<pre>$templatetitle</pre>"; $this->templateparser = $parser; #$this->templateparser = clone $parser; #$this->templateparser->setOutputType( Parser::OT_HTML ); $this->templateoptions = new ParserOptions(); $this->templateoptions->setEditSection(false); $this->templateoptions->setNumberHeadings(false); $this->templateoptions->setRemoveComments(true); //$this->templateoptions->setUseDynamicDates( false ); // removed in mw 1.21 $this->templateoptions->setInterwikiMagic(true); //strip interlanguage-links $this->templateoptions->setAllowSpecialInclusion(false); #$this->templatetitle = Title::newFromText( $template, NS_TEMPLATE ); #$templatetext = $templateparser->fetchTemplate( $templatetitle ); #print "<pre>$templatetext</pre>"; #$templateoptions->setRemoveComments( true ); #$templateoptions->setMaxIncludeSize( self::MAX_INCLUDE_SIZE ); #} if (!$this->usetemplate) { $this->changelist = new OldChangesList($this->skin); } #$this->feedId = @$argv['id']; $this->prefix = @$argv['prefix']; $this->postfix = @$argv['postfix']; $this->limit = @$argv['limit']; if (!$this->limit) { $this->limit = 10; } elseif ($this->limit > 100) { $this->limit = 100; } $this->unique = @$argv['unique']; if ($this->unique === 'false' || $this->unique === 'no' || $this->unique === '0') { $this->unique = false; } $this->namespaces = @$argv['namespaces']; if (!is_null($this->namespaces)) { $this->namespaces = preg_split('!\\s*(\\|\\s*)+!', trim($this->namespaces)); foreach ($this->namespaces as $i => $ns) { $ns = $wgContLang->lc($ns); if ($ns === '-' || $ns === '0' || $ns === 'main' || $ns === 'article') { $this->namespaces[$i] = 0; } else { $this->namespaces[$i] = MWNamespace::getCanonicalIndex($ns); if ($this->namespaces[$i] === false || $this->namespaces[$i] === null) { $this->namespaces[$i] = $wgContLang->getNsIndex($ns); } } if ($this->namespaces[$i] === false || $this->namespaces[$i] === null) { unset($this->namespaces[$i]); } } } $this->categories = @$argv['categories']; if (!is_null($this->categories)) { $this->categories = preg_split('!\\s*(\\|\\s*)+!', trim($this->categories)); foreach ($this->categories as $i => $n) { $t = Title::makeTitleSafe(NS_CATEGORY, $n); $n = $t->getDBkey(); $this->categories[$i] = $n; } } $this->pubtrigger = @$argv['trigger']; if ($this->pubtrigger) { $this->publication = true; } else { $this->publication = false; } $this->permalinks = @$argv['permalinks']; if ($this->permalinks === 'false' || $this->permalinks === 'no' || $this->permalinks === '0') { $this->permalinks = false; } $this->nominor = @$argv['nominor']; if ($this->nominor === 'false' || $this->nominor === 'no' || $this->nominor === '0') { $this->nominor = false; } $this->nobot = @$argv['nobot']; if ($this->nobot === 'false' || $this->nobot === 'no' || $this->nobot === '0') { $this->nobot = false; } $this->noanon = @$argv['noanon']; if ($this->noanon === 'false' || $this->noanon === 'no' || $this->noanon === '0') { $this->noanon = false; } $this->notalk = @$argv['notalk']; if ($this->notalk === 'false' || $this->notalk === 'no' || $this->notalk === '0') { $this->notalk = false; } $this->onlypatrolled = @$argv['onlypatrolled']; if ($this->onlypatrolled === 'false' || $this->onlypatrolled === 'no' || $this->onlypatrolled === '0') { $this->onlypatrolled = false; } $this->onlynew = @$argv['onlynew']; if ($this->onlynew === 'false' || $this->onlynew === 'no' || $this->onlynew === '0') { $this->onlynew = false; } $this->types = array(RC_EDIT, RC_NEW); /* this doesn't work right if ( $unique ) { $group[] = 'rc_namespace AND rc_title'; } */ }
/** * Read from cache to context output * @param IContextSource $context * @param integer $mode One of the HTMLFileCache::MODE_* constants * @return void */ public function loadFromFileCache(IContextSource $context, $mode = self::MODE_NORMAL) { global $wgContLang; $config = MediaWikiServices::getInstance()->getMainConfig(); wfDebug(__METHOD__ . "()\n"); $filename = $this->cachePath(); if ($mode === self::MODE_OUTAGE) { // Avoid DB errors for queries in sendCacheControl() $context->getTitle()->resetArticleID(0); } $context->getOutput()->sendCacheControl(); header("Content-Type: {$config->get('MimeType')}; charset=UTF-8"); header("Content-Language: {$wgContLang->getHtmlCode()}"); if ($this->useGzip()) { if (wfClientAcceptsGzip()) { header('Content-Encoding: gzip'); readfile($filename); } else { /* Send uncompressed */ wfDebug(__METHOD__ . " uncompressing cache file and sending it\n"); readgzfile($filename); } } else { readfile($filename); } $context->getOutput()->disable(); // tell $wgOut that output is taken care of }
/** * @param $user User * @param $context IContextSource * @param $defaultPreferences * @return void */ static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) { global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode, $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars, $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication, $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress, $wgSecureLogin; // retrieving user name for GENDER and misc. $userName = $user->getName(); ## User info ##################################### // Information panel $defaultPreferences['username'] = array( 'type' => 'info', 'label-message' => array( 'username', $userName ), 'default' => $userName, 'section' => 'personal/info', ); $defaultPreferences['userid'] = array( 'type' => 'info', 'label-message' => array( 'uid', $userName ), 'default' => $user->getId(), 'section' => 'personal/info', ); # Get groups to which the user belongs $userEffectiveGroups = $user->getEffectiveGroups(); $userGroups = $userMembers = array(); foreach ( $userEffectiveGroups as $ueg ) { if ( $ueg == '*' ) { // Skip the default * group, seems useless here continue; } $groupName = User::getGroupName( $ueg ); $userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName ); $memberName = User::getGroupMember( $ueg, $userName ); $userMembers[] = User::makeGroupLinkHTML( $ueg, $memberName ); } asort( $userGroups ); asort( $userMembers ); $lang = $context->getLanguage(); $defaultPreferences['usergroups'] = array( 'type' => 'info', 'label' => $context->msg( 'prefs-memberingroups' )->numParams( count( $userGroups ) )->params( $userName )->parse(), 'default' => $context->msg( 'prefs-memberingroups-type', $lang->commaList( $userGroups ), $lang->commaList( $userMembers ) )->plain(), 'raw' => true, 'section' => 'personal/info', ); $editCount = Linker::link( SpecialPage::getTitleFor( "Contributions", $userName ), $lang->formatNum( $user->getEditCount() ) ); $defaultPreferences['editcount'] = array( 'type' => 'info', 'raw' => true, 'label-message' => 'prefs-edits', 'default' => $editCount, 'section' => 'personal/info', ); if ( $user->getRegistration() ) { $displayUser = $context->getUser(); $userRegistration = $user->getRegistration(); $defaultPreferences['registrationdate'] = array( 'type' => 'info', 'label-message' => 'prefs-registration', 'default' => $context->msg( 'prefs-registration-date-time', $lang->userTimeAndDate( $userRegistration, $displayUser ), $lang->userDate( $userRegistration, $displayUser ), $lang->userTime( $userRegistration, $displayUser ) )->parse(), 'section' => 'personal/info', ); } $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' ); $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' ); // Actually changeable stuff $defaultPreferences['realname'] = array( // (not really "private", but still shouldn't be edited without permission) 'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ? 'text' : 'info', 'default' => $user->getRealName(), 'section' => 'personal/info', 'label-message' => 'yourrealname', 'help-message' => 'prefs-help-realname', ); if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) { $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ), $context->msg( 'prefs-resetpass' )->escaped(), array(), array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) ); $defaultPreferences['password'] = array( 'type' => 'info', 'raw' => true, 'default' => $link, 'label-message' => 'yourpassword', 'section' => 'personal/info', ); } if ( $wgCookieExpiration > 0 ) { $defaultPreferences['rememberpassword'] = array( 'type' => 'toggle', 'label' => $context->msg( 'tog-rememberpassword' )->numParams( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(), 'section' => 'personal/info', ); } // Only show preferhttps if secure login is turned on if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) { $defaultPreferences['prefershttps'] = array( 'type' => 'toggle', 'label-message' => 'tog-prefershttps', 'help-message' => 'prefs-help-prefershttps', 'section' => 'personal/info' ); } // Language $languages = Language::fetchLanguageNames( null, 'mw' ); if ( !array_key_exists( $wgLanguageCode, $languages ) ) { $languages[$wgLanguageCode] = $wgLanguageCode; } ksort( $languages ); $options = array(); foreach ( $languages as $code => $name ) { $display = wfBCP47( $code ) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['language'] = array( 'type' => 'select', 'section' => 'personal/i18n', 'options' => $options, 'label-message' => 'yourlanguage', ); $defaultPreferences['gender'] = array( 'type' => 'radio', 'section' => 'personal/i18n', 'options' => array( $context->msg( 'parentheses', $context->msg( 'gender-unknown' )->text() )->text() => 'unknown', $context->msg( 'gender-female' )->text() => 'female', $context->msg( 'gender-male' )->text() => 'male', ), 'label-message' => 'yourgender', 'help-message' => 'prefs-help-gender', ); // see if there are multiple language variants to choose from if ( !$wgDisableLangConversion ) { foreach ( LanguageConverter::$languagesWithVariants as $langCode ) { if ( $langCode == $wgContLang->getCode() ) { $variants = $wgContLang->getVariants(); if ( count( $variants ) <= 1 ) { continue; } $variantArray = array(); foreach ( $variants as $v ) { $v = str_replace( '_', '-', strtolower( $v ) ); $variantArray[$v] = $lang->getVariantname( $v, false ); } $options = array(); foreach ( $variantArray as $code => $name ) { $display = wfBCP47( $code ) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['variant'] = array( 'label-message' => 'yourvariant', 'type' => 'select', 'options' => $options, 'section' => 'personal/i18n', 'help-message' => 'prefs-help-variant', ); if ( !$wgDisableTitleConversion ) { $defaultPreferences['noconvertlink'] = array( 'type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => 'tog-noconvertlink', ); } } else { $defaultPreferences["variant-$langCode"] = array( 'type' => 'api', ); } } } // Stuff from Language::getExtraUserToggles() // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language $toggles = $wgContLang->getExtraUserToggles(); foreach ( $toggles as $toggle ) { $defaultPreferences[$toggle] = array( 'type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => "tog-$toggle", ); } // show a preview of the old signature first $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions::newFromContext( $context ) ); $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true ); $defaultPreferences['oldsig'] = array( 'type' => 'info', 'raw' => true, 'label-message' => 'tog-oldsig', 'default' => $oldsigHTML, 'section' => 'personal/signature', ); $defaultPreferences['nickname'] = array( 'type' => $wgAuth->allowPropChange( 'nickname' ) ? 'text' : 'info', 'maxlength' => $wgMaxSigChars, 'label-message' => 'yournick', 'validation-callback' => array( 'Preferences', 'validateSignature' ), 'section' => 'personal/signature', 'filter-callback' => array( 'Preferences', 'cleanSignature' ), ); $defaultPreferences['fancysig'] = array( 'type' => 'toggle', 'label-message' => 'tog-fancysig', 'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section 'section' => 'personal/signature' ); ## Email stuff if ( $wgEnableEmail ) { if ( $canViewPrivateInfo ) { $helpMessages[] = $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email'; if ( $wgEnableUserEmail ) { // additional messages when users can send email to each other $helpMessages[] = 'prefs-help-email-others'; } $emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : ''; if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) { $link = Linker::link( SpecialPage::getTitleFor( 'ChangeEmail' ), $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(), array(), array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' )->getPrefixedText() ) ); $emailAddress .= $emailAddress == '' ? $link : ( $context->msg( 'word-separator' )->plain() . $context->msg( 'parentheses' )->rawParams( $link )->plain() ); } $defaultPreferences['emailaddress'] = array( 'type' => 'info', 'raw' => true, 'default' => $emailAddress, 'label-message' => 'youremail', 'section' => 'personal/email', 'help-messages' => $helpMessages, # 'cssclass' chosen below ); } $disableEmailPrefs = false; if ( $wgEmailAuthentication ) { $emailauthenticationclass = 'mw-email-not-authenticated'; if ( $user->getEmail() ) { if ( $user->getEmailAuthenticationTimestamp() ) { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialConfirmemail.php $displayUser = $context->getUser(); $emailTimestamp = $user->getEmailAuthenticationTimestamp(); $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser ); $d = $lang->userDate( $emailTimestamp, $displayUser ); $t = $lang->userTime( $emailTimestamp, $displayUser ); $emailauthenticated = $context->msg( 'emailauthenticated', $time, $d, $t )->parse() . '<br />'; $disableEmailPrefs = false; $emailauthenticationclass = 'mw-email-authenticated'; } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' . Linker::linkKnown( SpecialPage::getTitleFor( 'Confirmemail' ), $context->msg( 'emailconfirmlink' )->escaped() ) . '<br />'; $emailauthenticationclass = "mw-email-not-authenticated"; } } else { $disableEmailPrefs = true; $emailauthenticated = $context->msg( 'noemailprefs' )->escaped(); $emailauthenticationclass = 'mw-email-none'; } if ( $canViewPrivateInfo ) { $defaultPreferences['emailauthentication'] = array( 'type' => 'info', 'raw' => true, 'section' => 'personal/email', 'label-message' => 'prefs-emailconfirm-label', 'default' => $emailauthenticated, # Apply the same CSS class used on the input to the message: 'cssclass' => $emailauthenticationclass, ); $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass; } } if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) { $defaultPreferences['disablemail'] = array( 'type' => 'toggle', 'invert' => true, 'section' => 'personal/email', 'label-message' => 'allowemail', 'disabled' => $disableEmailPrefs, ); $defaultPreferences['ccmeonemails'] = array( 'type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-ccmeonemails', 'disabled' => $disableEmailPrefs, ); } if ( $wgEnotifWatchlist ) { $defaultPreferences['enotifwatchlistpages'] = array( 'type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifwatchlistpages', 'disabled' => $disableEmailPrefs, ); } if ( $wgEnotifUserTalk ) { $defaultPreferences['enotifusertalkpages'] = array( 'type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifusertalkpages', 'disabled' => $disableEmailPrefs, ); } if ( $wgEnotifUserTalk || $wgEnotifWatchlist ) { $defaultPreferences['enotifminoredits'] = array( 'type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifminoredits', 'disabled' => $disableEmailPrefs, ); if ( $wgEnotifRevealEditorAddress ) { $defaultPreferences['enotifrevealaddr'] = array( 'type' => 'toggle', 'section' => 'personal/email', 'label-message' => 'tog-enotifrevealaddr', 'disabled' => $disableEmailPrefs, ); } } } }
/** * RequestContextCreateSkin hook handler * @see https://www.mediawiki.org/wiki/Manual:Hooks/RequestContextCreateSkin * * @param IContextSource $context * @param Skin $skin * @return bool */ public static function onRequestContextCreateSkin($context, &$skin) { // FIXME: This shouldn't be a global, it should be possible for other extensions // to set this via a static variable or set function in ULS global $wgULSPosition; $mobileContext = MobileContext::singleton(); $mobileContext->doToggling(); if (!$mobileContext->shouldDisplayMobileView() || $mobileContext->isBlacklistedPage()) { return true; } // enable wgUseMediaWikiUIEverywhere self::enableMediaWikiUI(); // FIXME: Remove hack around Universal Language selector bug 57091 $wgULSPosition = 'none'; // Handle any X-Analytics header values in the request by adding them // as log items. X-Analytics header values are serialized key=value // pairs, separated by ';', used for analytics purposes. $xanalytics = $mobileContext->getRequest()->getHeader('X-Analytics'); if ($xanalytics) { $xanalytics_arr = explode(';', $xanalytics); if (count($xanalytics_arr) > 1) { foreach ($xanalytics_arr as $xanalytics_item) { $mobileContext->addAnalyticsLogItemFromXAnalytics($xanalytics_item); } } else { $mobileContext->addAnalyticsLogItemFromXAnalytics($xanalytics); } } // log whether user is using beta/stable $mobileContext->logMobileMode(); $skinName = $mobileContext->getMFConfig()->get('MFDefaultSkinClass'); $betaSkinName = $skinName . 'Beta'; // Force beta for test mode to sure all modules can run $name = $context->getTitle()->getDBkey(); $inTestMode = $name === SpecialPage::getTitleFor('JavaScriptTest', 'qunit')->getDBkey(); if ($mobileContext->isBetaGroupMember() && class_exists($betaSkinName)) { $skinName = $betaSkinName; } $skin = new $skinName($context); return false; }
/** * Perform one of the "standard" actions * * @param $article Article */ private function performAction(Page $article) { global $wgSquidMaxage, $wgUseExternalEditor; wfProfileIn(__METHOD__); $request = $this->context->getRequest(); $output = $this->context->getOutput(); $title = $this->context->getTitle(); $user = $this->context->getUser(); if (!wfRunHooks('MediaWikiPerformAction', array($output, $article, $title, $user, $request, $this))) { wfProfileOut(__METHOD__); return; } $act = $this->getAction(); $action = Action::factory($act, $article); if ($action instanceof Action) { $action->show(); wfProfileOut(__METHOD__); return; } switch ($act) { case 'view': $output->setSquidMaxage($wgSquidMaxage); $article->view(); break; case 'raw': // includes JS/CSS wfProfileIn(__METHOD__ . '-raw'); $raw = new RawPage($article); $raw->view(); wfProfileOut(__METHOD__ . '-raw'); break; case 'delete': case 'protect': case 'unprotect': case 'render': $article->{$act}(); break; case 'submit': if (session_id() == '') { // Send a cookie so anons get talk message notifications wfSetupSession(); } // Continue... // Continue... case 'edit': if (wfRunHooks('CustomEditor', array($article, $user))) { $internal = $request->getVal('internaledit'); $external = $request->getVal('externaledit'); $section = $request->getVal('section'); $oldid = $request->getVal('oldid'); if (!$wgUseExternalEditor || $act == 'submit' || $internal || $section || $oldid || !$user->getOption('externaleditor') && !$external) { $editor = new EditPage($article); $editor->submit(); } elseif ($wgUseExternalEditor && ($external || $user->getOption('externaleditor'))) { $mode = $request->getVal('mode'); $extedit = new ExternalEdit($article->getTitle(), $mode); $extedit->edit(); } } break; case 'history': if ($request->getFullRequestURL() == $title->getInternalURL('action=history')) { $output->setSquidMaxage($wgSquidMaxage); } $history = new HistoryPage($article); $history->history(); break; default: if (wfRunHooks('UnknownAction', array($act, $article))) { $output->showErrorPage('nosuchaction', 'nosuchactiontext'); } } wfProfileOut(__METHOD__); }