/** * Adds this new notification object to the backend storage. */ protected function insert() { global $wgEchoBackend, $wgEchoNotifications; $row = array('notification_event' => $this->event->getId(), 'notification_user' => $this->user->getId(), 'notification_anon_ip' => $this->user->isAnon() ? $this->user->getName() : $this->user->getId(), 'notification_timestamp' => $this->timestamp, 'notification_read_timestamp' => $this->readTimestamp, 'notification_bundle_hash' => '', 'notification_bundle_display_hash' => ''); // Get the bundle key for this event if web bundling is enabled $bundleKey = ''; if (!empty($wgEchoNotifications[$this->event->getType()]['bundle']['web'])) { wfRunHooks('EchoGetBundleRules', array($this->event, &$bundleKey)); } if ($bundleKey) { $hash = md5($bundleKey); $row['notification_bundle_hash'] = $hash; $lastStat = $wgEchoBackend->getLastBundleStat($this->user, $hash); // Use a new display hash if: // 1. there was no last bundle notification // 2. last bundle notification with the same hash was read if ($lastStat && !$lastStat->notification_read_timestamp) { $row['notification_bundle_display_hash'] = $lastStat->notification_bundle_display_hash; } else { $row['notification_bundle_display_hash'] = md5($bundleKey . '-display-hash-' . wfTimestampNow()); } } $wgEchoBackend->createNotification($row); wfRunHooks('EchoCreateNotificationComplete', array($this)); }
public function hasPersonalAnnotations() { if (!isset($this->hasPersonalAnnotations)) { $this->hasPersonalAnnotations = !$this->viewerUser->isAnon() && $this->viewerUser->getId() == $this->ownerUser->getId() && AchAwardingService::canEarnBadges($this->viewerUser) && !$this->viewerUser->getGlobalPreference('hidepersonalachievements'); } return $this->hasPersonalAnnotations; }
/** * Same as addWatch, only the opposite. * @return bool */ public function removeWatch() { wfProfileIn(__METHOD__); // Only loggedin user can have a watchlist if (wfReadOnly() || $this->mUser->isAnon() || !$this->isAllowed('editmywatchlist')) { wfProfileOut(__METHOD__); return false; } $success = false; $dbw = wfGetDB(DB_MASTER); $dbw->delete('watchlist', array('wl_user' => $this->getUserId(), 'wl_namespace' => MWNamespace::getSubject($this->getTitleNs()), 'wl_title' => $this->getTitleDBkey()), __METHOD__); if ($dbw->affectedRows()) { $success = true; } # the following code compensates the new behavior, introduced by the # enotif patch, that every single watched page needs now to be listed # in watchlist namespace:page and namespace_talk:page had separate # entries: clear them $dbw->delete('watchlist', array('wl_user' => $this->getUserId(), 'wl_namespace' => MWNamespace::getTalk($this->getTitleNs()), 'wl_title' => $this->getTitleDBkey()), __METHOD__); if ($dbw->affectedRows()) { $success = true; } $this->watched = false; wfProfileOut(__METHOD__); return $success; }
/** * Generate the generic "this page has been changed" e-mail text. */ protected function composeCommonMailtext() { global $wgPasswordSender, $wgPasswordSenderName, $wgNoReplyAddress; global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress; global $wgEnotifUseRealName, $wgRequest; $this->composed_common = true; if ($this->editor->isAnon()) { $pageEditor = wfMsgForContent('enotif_anon_editor', $this->editor->getName()); } else { $pageEditor = $wgEnotifUseRealName ? $this->editor->getRealName() : $this->editor->getName(); } // build the subject $this->subject = wfMessage('moodbar-enotif-subject')->params($pageEditor)->escaped(); // build the body $targetUserName = $this->targetUser->getName(); $links = $this->buildEmailLink(); //text version, no need to escape since client will interpret it as plain text $textBody = wfMessage('moodbar-enotif-body')->params($targetUserName, $links['feedbackPageUrl'], $links['editorTalkPageUrl'], $this->response, $links['targetUserTalkPageUrl'], $pageEditor)->text(); //html version, this is a little bit ugly as we have to make wiki link clickable in emails $action = $wgRequest->getVal('action'); $wgRequest->setVal('action', 'render'); $htmlBody = wfMsgExt('moodbar-enotif-body', array('parse'), $targetUserName, $links['feedbackPageUrl'], $links['editorTalkPageUrl'], '<div style="margin-left:20px; margin-right:20px;">"' . $this->response . '"</div>', $links['targetUserTalkPageUrl'], $pageEditor); $wgRequest->setVal('action', $action); // assemble the email body $this->body = <<<HTML --{$this->mime_boundary} Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit {$textBody} --{$this->mime_boundary} Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <html> \t<body> \t\t{$htmlBody} \t</body> </html> --{$this->mime_boundary}-- HTML; # Reveal the page editor's address as REPLY-TO address only if # the user has not opted-out and the option is enabled at the # global configuration level. $adminAddress = new MailAddress($wgPasswordSender, $wgPasswordSenderName); if ($wgEnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getOption('enotifrevealaddr')) { $editorAddress = new MailAddress($this->editor); if ($wgEnotifFromEditor) { $this->from = $editorAddress; } else { $this->from = $adminAddress; $this->replyto = $editorAddress; } } else { $this->from = $adminAddress; $this->replyto = new MailAddress($wgNoReplyAddress); } }
/** * Construct the class * * @param User $user A User object * @throws Exception when used on anonymous user. */ public function __construct(User $user) { if ($user->isAnon()) { throw new Exception(__CLASS__ . ' is intended for logged in users only'); } $this->user = $user; }
/** * @param $thread Thread */ function topLevelThreadCommands($thread) { $commands = array(); $commands['history'] = array('label' => wfMessage('history_short')->parse(), 'href' => self::permalinkUrl($thread, 'thread_history'), 'enabled' => true); if ($this->user->isAllowed('move')) { $move_href = SpecialPage::getTitleFor('MoveThread', $thread->title()->getPrefixedText())->getLocalURL(); $commands['move'] = array('label' => wfMessage('lqt-movethread')->parse(), 'href' => $move_href, 'enabled' => true); } if ($this->user->isAllowed('protect')) { $protect_href = $thread->title()->getLocalURL('action=protect'); // Check if it's already protected if (!$thread->title()->isProtected()) { $label = wfMessage('protect')->parse(); } else { $label = wfMessage('unprotect')->parse(); } $commands['protect'] = array('label' => $label, 'href' => $protect_href, 'enabled' => true); } if (!$this->user->isAnon() && !$thread->title()->userIsWatching()) { $commands['watch'] = array('label' => wfMessage('watch')->parse(), 'href' => self::permalinkUrlWithQuery($thread, array('action' => 'watch', 'token' => WatchAction::getWatchToken($thread->title(), $this->user, 'watch'))), 'enabled' => true); } elseif (!$this->user->isAnon()) { $commands['unwatch'] = array('label' => wfMessage('unwatch')->parse(), 'href' => self::permalinkUrlWithQuery($thread, array('action' => 'unwatch', 'token' => WatchAction::getWatchToken($thread->title(), $this->user, 'unwatch'))), 'enabled' => true); } if (LqtDispatch::isLqtPage($thread->getTitle())) { $summarizeUrl = self::permalinkUrl($thread, 'summarize', $thread->id()); $commands['summarize'] = array('label' => wfMessage('lqt_summarize_link')->parse(), 'href' => $summarizeUrl, 'enabled' => true); } Hooks::run('LiquidThreadsTopLevelCommands', array($thread, &$commands)); return $commands; }
protected function checkCanExecute(User $user) { // Must be logged in if ($user->isAnon()) { throw new UserNotLoggedIn('watchlistanontext', 'watchnologin'); } parent::checkCanExecute($user); }
protected function checkCanExecute(User $user) { // Must be logged in if ($user->isAnon()) { throw new ErrorPageError('watchnologin', 'watchnologintext'); } return parent::checkCanExecute($user); }
public function execute() { // Detect user $this->user = $this->getUser(); if ($this->user->isAnon() || !$this->user) { return false; } $this->params = $this->extractRequestParams(); switch ($this->params['do']) { case 'info': $this->fetchInformation(); break; case 'vote': $this->doVote(); break; } $this->getResult()->addValue(null, $this->getModuleName(), $this->formattedData); }
/** * Decide whether to bother showing the wikitext editor at all. * If not, we expect the VE initialisation JS to activate. * @param $article Article * @param $user User * @return bool Whether to show the wikitext editor or not. */ public static function onCustomEditor(Article $article, User $user) { $req = RequestContext::getMain()->getRequest(); $veConfig = ConfigFactory::getDefaultInstance()->makeConfig('visualeditor'); if (!$user->getOption('visualeditor-enable') || $user->getOption('visualeditor-betatempdisable') || $user->getOption('visualeditor-autodisable') || $user->getOption('visualeditor-tabs') === 'prefer-wt' || $veConfig->get('VisualEditorDisableForAnons') && $user->isAnon() || false) { return true; } $title = $article->getTitle(); $availableNamespaces = $veConfig->get('VisualEditorAvailableNamespaces'); $params = $req->getValueNames(); if ($user->isAnon()) { $editor = $req->getCookie('VEE', '', User::getDefaultOption('visualeditor-editor')); } else { $editor = $user->getOption('visualeditor-editor'); } return $req->getVal('action') !== 'edit' || !$veConfig->get('VisualEditorUseSingleEditTab') || $editor === 'wikitext' || !$title->inNamespaces(array_keys(array_filter($availableNamespaces))) || $title->getContentModel() !== CONTENT_MODEL_WIKITEXT || in_array('undo', $params) || in_array('undoafter', $params) || in_array('editintro', $params) || in_array('preload', $params) || in_array('preloadtitle', $params) || in_array('preloadparams', $params); // Known-good parameters: edit, veaction, section, vesection, veswitched }
protected function checkCanExecute(User $user) { // Must be logged in if ($user->isAnon()) { $loginreqlink = Linker::linkKnown(SpecialPage::getTitleFor('Userlogin'), $this->msg('loginreqlink')->escaped(), array(), array('returnto' => $this->getPageTitle(), 'returntoquery' => 'action=' . $this->getName())); $reasonMsg = $this->msg('watchlistanontext')->rawParams($loginreqlink); throw new UserNotLoggedIn($reasonMsg, 'watchnologin'); } return parent::checkCanExecute($user); }
public function postCreationSetup($params) { global $wgErrorLog, $wgServer, $wgInternalServer, $wgStatsDBEnabled; $wgServer = rtrim($params['url'], '/'); $wgInternalServer = $wgServer; $wgStatsDBEnabled = false; // disable any DW queries/hooks during wiki creation $wgErrorLog = false; if ($params['founderId']) { $this->info('loading founding user', ['founder_id' => $params['founderId']]); $this->founder = \User::newFromId($params['founderId']); $this->founder->load(); } if (!$this->founder || $this->founder->isAnon()) { $this->warning('cannot load founding user', ['founder_id' => $params['founderId']]); if (!empty($params['founderName'])) { $this->founder = \User::newFromName($params['founderName']); $this->founder->load(); } } if (!$this->founder || $this->founder->isAnon()) { global $wgExternalAuthType; if ($wgExternalAuthType) { $extUser = \ExternalUser::newFromName($params['founderName']); if (is_object($extUser)) { $extUser->linkToLocal($extUser->getId()); } } } $this->wikiName = isset($params['sitename']) ? $params['sitename'] : \WikiFactory::getVarValueByName('wgSitename', $params['city_id'], true); $this->wikiLang = isset($params['language']) ? $params['language'] : \WikiFactory::getVarValueByName('wgLanguageCode', $params['city_id']); $this->moveMainPage(); $this->changeStarterContributions($params); $this->setWelcomeTalkPage(); $this->populateCheckUserTables(); $this->protectKeyPages(); $this->sendRevisionToScribe(); $hookParams = ['title' => $params['sitename'], 'url' => $params['url'], 'city_id' => $params['city_id']]; if (empty($params['disableCompleteHook'])) { wfRunHooks('CreateWikiLocalJob-complete', array($hookParams)); } return true; }
public function rate(\User $user, $score) { if ($user->isAnon()) { $userid = $user->getName(); } else { $userid = $user->getId(); } $dbw = wfGetDB(DB_MASTER); $dbw->replace('pagerating_records', array('prr_pageid', 'prr_user'), array('prr_user' => $userid, 'prr_pageid' => $this->pageid, 'prr_score' => $score, 'prr_timestamp' => wfTimestamp(TS_MW))); }
public function execute() { $this->params = $this->extractRequestParams(); $this->user = $this->getUser(); if (!$this->user || $this->user->isAnon()) { return false; } switch ($this->params['do']) { case 'info': $this->info(); break; case 'watch': $this->watch(); break; case 'unwatch': $this->unwatch(); break; } $this->getResult()->addValue(null, $this->getModuleName(), $this->formattedData); }
/** * Get group data for the user object. Needed for removing global group rights. * * @author grunny */ public static function onUserLoadGroups(User $user) { $userId = $user->getId(); if (!self::isCentralWiki() || $user->isAnon()) { return true; } elseif (!isset(self::$globalGroups[$userId])) { // Load the global groups into the class variable self::getGlobalGroups($user); } $user->mGroups = array_merge($user->mGroups, array_diff(self::$globalGroups[$userId], $user->mGroups)); return true; }
/** * area_user * * @access public * @return void */ function area_user() { global $db, $page; $id = Flyspray::ValidUserId(Req::val('user_id')); $theuser = new User($id); if ($theuser->isAnon()) { FlysprayDo::error(array(ERROR_INPUT, L('error5'))); } $page->assign('all_groups', Flyspray::listallGroups($theuser->id)); $page->assign('groups', Flyspray::listGroups()); $page->assign('theuser', $theuser); }
/** * @brief auxiliary method for getting hidden pages/wikis from db * * @param DatabaseBase $dbHandler * * @author ADi * @return array */ private function getHiddenFromDb($dbHandler) { wfProfileIn(__METHOD__); $result = false; if (!$this->user->isAnon()) { $row = $dbHandler->selectRow(array('page_wikia_props'), array('props'), array('page_id' => $this->user->getId(), 'propname' => self::PAGE_WIKIA_PROPS_PROPNAME), __METHOD__, array()); if (!empty($row)) { $result = unserialize($row->props); } $result = empty($result) ? array() : $result; } wfProfileOut(__METHOD__); return $result; }
/** * Utility function that checks whether CX is enabled for a given user. * Currently it checks that if CX is a beta feature, whether the user has * enabled it. Otherwise it is always enabled. * * @param User $user * @return Boolean */ public static function isEnabledForUser(User $user) { global $wgContentTranslationAsBetaFeature; // CX is currently restricted to only logged in users if ($user->isAnon()) { return false; } if ($user->isBlocked()) { return false; } if (!$wgContentTranslationAsBetaFeature) { return true; } return class_exists('BetaFeatures') && BetaFeatures::isFeatureEnabled($user, 'cx'); }
/** * @static * @param User $user * @return array|bool|null */ public static function blockCheck(User $user) { global $wgUser, $wgMemc; wfProfileIn(__METHOD__); // dependancy -- if this doesn't exist, quit early if (!class_exists('AccountCreationTracker')) { wfProfileOut(__METHOD__); return true; } // we don't block anons with this filter if ($user->isAnon()) { wfProfileOut(__METHOD__); return true; } $ret = true; // RT#42011: RegexBlock records strange results // don't write stats for other user than visiting user $isCurrentUser = $user->getName() == $wgUser->getName(); // check cache first before proceeding $cachedState = self::getBlockFromCache($user, $isCurrentUser); if (!is_null($cachedState)) { wfProfileOut(__METHOD__); return $cachedState; } $tracker = F::build('AccountCreationTracker'); /** @var $tracker AccountCreationTracker */ $hashes = $tracker->getHashesByUser($user); $blocksData = Phalanx::getFromFilter(self::TYPE); if (!empty($blocksData) && !empty($hashes)) { foreach ($hashes as $hash) { $ret = self::blockCheckInternal($user, $blocksData, $hash, false, $isCurrentUser); if (!$ret) { // only check until we get first blocking match break; } } } // populate cache if not done before if ($ret) { $cacheKey = self::getCacheKey($user); $cachedState = array('timestamp' => wfTimestampNow(), 'block' => false, 'return' => $ret); $wgMemc->set($cacheKey, $cachedState); } wfProfileOut(__METHOD__); return $ret; }
/** * This method actually generates the output * @param array $aParams not used here * @return string HTML output */ public function execute($aParams = false) { global $wgUser; $sUserName = $this->oUser->getName(); $sUserRealName = $this->oUser->getRealName(); //Fallback for old entries without user_id if ($this->oUser->isAnon()) { $sUserName = $this->sUsername; } $aOut = array(); $aOut[] = '<li class="bs-sb-listitem clearfix" id="bs-sb-' . $this->iShoutID . '">'; $aOut[] = ' <div class="bs-user-image">'; if ($this->oMiniProfile instanceof ViewUserMiniProfile) { $aOut[] = $this->oMiniProfile->execute(); } $aOut[] = ' </div>'; $aOut[] = ' <div class="bs-sb-message">'; $aOut[] = ' <div class="bs-sb-message-head">'; $aOut[] = ' <strong>' . $sUserName . '</strong>'; if (!empty($sUserRealName)) { $aOut[] = ' <span class="bs-sb-meassage-head-small">' . $sUserRealName . '</span>'; } $aOut[] = ' </div>'; if (isset($this->sDate)) { $aOut[] = '<div class="bs-sb-message-time">' . $this->sDate; $aOut[] = '</div> '; } $aOut[] = ' <div class="bs-sb-message-text">' . nl2br($this->sMessage); $aOut[] = ' </div> '; $aOut[] = ' </div>'; $sArchiveButton = ''; $sArchiveButtonEnabled = ' <div class="bs-sb-archive"></div>'; //set button if user has the right to archive if (BsCore::checkAccessAdmission('archiveshoutbox')) { $sArchiveButton = $sArchiveButtonEnabled; } //if setting for "allow own entries to be archived" is set + username == shoutbox-entry-username => set button if (BsConfig::get('MW::ShoutBox::AllowArchive') && $wgUser->getName() == $sUserName) { $sArchiveButton = $sArchiveButtonEnabled; } $aOut[] = $sArchiveButton; $aOut[] = '</li>'; return implode("\n", $aOut); }
/** * Inserts the object into the database. */ protected function insert() { global $wgEchoBackend; if ($this->id) { throw new MWException("Attempt to insert() an existing event"); } $row = array('event_type' => $this->type, 'event_variant' => $this->variant); if ($this->agent) { if ($this->agent->isAnon()) { $row['event_agent_ip'] = $this->agent->getName(); } else { $row['event_agent_id'] = $this->agent->getId(); } } if ($this->pageId) { $row['event_page_id'] = $this->pageId; } $row['event_extra'] = $this->serializeExtra(); $this->id = $wgEchoBackend->createEvent($row); }
/** * Keeps track of recently used message groups per user. */ public static function trackGroup(MessageGroup $group, User $user) { if ($user->isAnon()) { return true; } $groups = $user->getOption('translate-recent-groups', ''); if ($groups === '') { $groups = array(); } else { $groups = explode('|', $groups); } if (isset($groups[0]) && $groups[0] === $group->getId()) { return true; } array_unshift($groups, $group->getId()); $groups = array_unique($groups); $groups = array_slice($groups, 0, 5); $user->setOption('translate-recent-groups', implode('|', $groups)); // Promise to persist the data post-send DeferredUpdates::addCallableUpdate(function () use($user) { $user->saveSettings(); }); return true; }
/** * @desc Keep track of article contribution to update the top contributors data if available * * @param WikiPage $wikiPage * @param User $user * @param $text * @param $summary * @param $minoredit * @param $watchthis * @param $sectionanchor * @param $flags * @param $revision * @param $status * @param $baseRevId * @return bool */ public static function onArticleSaveComplete(WikiPage $wikiPage, User $user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { if (!$user->isAnon()) { $articleId = $wikiPage->getId(); if ($articleId) { $userId = $user->getId(); $key = MercuryApi::getTopContributorsKey($articleId, MercuryApiController::NUMBER_CONTRIBUTORS); $memCache = F::app()->wg->Memc; $contributions = $memCache->get($key); // Update the data only if the key is not empty if ($contributions) { if (isset($contributions[$userId])) { // If user is known increase the number of contributions $contributions[$userId]++; } else { // Get the number User's contributions from database $contributions = self::getNumberOfContributionsForUser($articleId, $userId, $contributions); } $memCache->set($key, $contributions, MercuryApi::CACHE_TIME_TOP_CONTRIBUTORS); } } } return true; }
/** * Permissions checks that fail most often, and which are easiest to test. * * @param string $action The action to check * @param User $user User to check * @param array $errors List of current errors * @param string $rigor Same format as Title::getUserPermissionsErrors() * @param bool $short Short circuit on first error * * @return array List of errors */ private function checkQuickPermissions($action, $user, $errors, $rigor, $short) { if (!Hooks::run('TitleQuickPermissions', array($this, $user, $action, &$errors, $rigor !== 'quick', $short))) { return $errors; } if ($action == 'create') { if ($this->isTalkPage() && !$user->isAllowed('createtalk') || !$this->isTalkPage() && !$user->isAllowed('createpage')) { $errors[] = $user->isAnon() ? array('nocreatetext') : array('nocreate-loggedin'); } } elseif ($action == 'move') { if (!$user->isAllowed('move-rootuserpages') && $this->mNamespace == NS_USER && !$this->isSubpage()) { // Show user page-specific message only if the user can move other pages $errors[] = array('cant-move-user-page'); } // Check if user is allowed to move files if it's a file if ($this->mNamespace == NS_FILE && !$user->isAllowed('movefile')) { $errors[] = array('movenotallowedfile'); } // Check if user is allowed to move category pages if it's a category page if ($this->mNamespace == NS_CATEGORY && !$user->isAllowed('move-categorypages')) { $errors[] = array('cant-move-category-page'); } if (!$user->isAllowed('move')) { // User can't move anything $userCanMove = User::groupHasPermission('user', 'move'); $autoconfirmedCanMove = User::groupHasPermission('autoconfirmed', 'move'); if ($user->isAnon() && ($userCanMove || $autoconfirmedCanMove)) { // custom message if logged-in users without any special rights can move $errors[] = array('movenologintext'); } else { $errors[] = array('movenotallowed'); } } } elseif ($action == 'move-target') { if (!$user->isAllowed('move')) { // User can't move anything $errors[] = array('movenotallowed'); } elseif (!$user->isAllowed('move-rootuserpages') && $this->mNamespace == NS_USER && !$this->isSubpage()) { // Show user page-specific message only if the user can move other pages $errors[] = array('cant-move-to-user-page'); } elseif (!$user->isAllowed('move-categorypages') && $this->mNamespace == NS_CATEGORY) { // Show category page-specific message only if the user can move other pages $errors[] = array('cant-move-to-category-page'); } } elseif (!$user->isAllowed($action)) { $errors[] = $this->missingPermissionError($action, $short); } return $errors; }
/** * Get a link to $user's user page * @param User $user * @return string Html */ protected function link(User $user) { if ($this->canShowRealUserName() && !$user->isAnon()) { $real = $user->getRealName(); } else { $real = false; } $page = $user->isAnon() ? SpecialPage::getTitleFor('Contributions', $user->getName()) : $user->getUserPage(); return Linker::link($page, htmlspecialchars($real ? $real : $user->getName())); }
/** * Fetch the user's signature text, if any, and normalize to * validated, ready-to-insert wikitext. * If you have pre-fetched the nickname or the fancySig option, you can * specify them here to save a database query. * Do not reuse this parser instance after calling getUserSig(), * as it may have changed if it's the $wgParser. * * @param User $user * @param string|bool $nickname Nickname to use or false to use user's default nickname * @param bool|null $fancySig whether the nicknname is the complete signature * or null to use default value * @return string */ public function getUserSig(&$user, $nickname = false, $fancySig = null) { global $wgMaxSigChars; $username = $user->getName(); # If not given, retrieve from the user object. if ($nickname === false) { $nickname = $user->getOption('nickname'); } if (is_null($fancySig)) { $fancySig = $user->getBoolOption('fancysig'); } $nickname = $nickname == null ? $username : $nickname; if (mb_strlen($nickname) > $wgMaxSigChars) { $nickname = $username; wfDebug(__METHOD__ . ": {$username} has overlong signature.\n"); } elseif ($fancySig !== false) { # Sig. might contain markup; validate this if ($this->validateSig($nickname) !== false) { # Validated; clean up (if needed) and return it return $this->cleanSig($nickname, true); } else { # Failed to validate; fall back to the default $nickname = $username; wfDebug(__METHOD__ . ": {$username} has bad XML tags in signature.\n"); } } # Make sure nickname doesnt get a sig in a sig $nickname = self::cleanSigInSig($nickname); # If we're still here, make it a link to the user page $userText = wfEscapeWikiText($username); $nickText = wfEscapeWikiText($nickname); $msgName = $user->isAnon() ? 'signature-anon' : 'signature'; return wfMessage($msgName, $userText, $nickText)->inContentLanguage()->title($this->getTitle())->text(); }
/** * Fetch the user's signature text, if any, and normalize to * validated, ready-to-insert wikitext. * * @param User $user * @return string * @private */ function getUserSig(&$user) { global $wgMaxSigChars; $username = $user->getName(); $nickname = $user->getOption('nickname'); $nickname = $nickname === '' ? $username : $nickname; if (mb_strlen($nickname) > $wgMaxSigChars) { $nickname = $username; wfDebug(__METHOD__ . ": {$username} has overlong signature.\n"); } elseif ($user->getBoolOption('fancysig') !== false) { # Sig. might contain markup; validate this if ($this->validateSig($nickname) !== false) { # Validated; clean up (if needed) and return it return $this->cleanSig($nickname, true); } else { # Failed to validate; fall back to the default $nickname = $username; wfDebug(__METHOD__ . ": {$username} has bad XML tags in signature.\n"); } } // Make sure nickname doesnt get a sig in a sig $nickname = $this->cleanSigInSig($nickname); # If we're still here, make it a link to the user page $userText = wfEscapeWikiText($username); $nickText = wfEscapeWikiText($nickname); if ($user->isAnon()) { return wfMsgExt('signature-anon', array('content', 'parsemag'), $userText, $nickText); } else { return wfMsgExt('signature', array('content', 'parsemag'), $userText, $nickText); } }
/** * This method is called after an article has been saved. * This is the server side of IntraACL protection toolbar, * allowing to modify page SD together with article save. * * No modifications are made if either: * - Page namespace is ACL * - User is anonymous * - Users don't have the right to modify page SD * - 'haloacl_protect_with' request value is invalid * (valid are 'unprotected', or ID/name of predefined right or THIS page SD) * * @param WikiPage $article The article which was saved * @param User $user The user who saved the article * @param string $text The content of the article * * @return true */ public static function articleSaveComplete_SaveSD($article, User $user, $text) { global $wgUser, $wgRequest, $haclgContLang; if ($user->isAnon()) { // Don't handle protection toolbar for anonymous users return true; } if ($article->getTitle()->getNamespace() == HACL_NS_ACL) { // Don't use protection toolbar for articles in the namespace ACL. // Note that embedded content protection toolbar is handled nevertheless. return true; } // Obtain user selection // hacl_protected_with == '<peType>:<peID>' or 'unprotected' $selectedSD = $wgRequest->getVal('hacl_protected_with'); if ($selectedSD && $selectedSD != 'unprotected') { // Some SD is selected by the user // Ignore selection of invalid SDs $selectedSD = array_map('intval', explode('-', $selectedSD, 2)); if (count($selectedSD) != 2) { $selectedSD = NULL; } } if (!$selectedSD) { return true; } if ($selectedSD == 'unprotected') { $selectedSD = NULL; } // Check if current SD must be modified if ($article->exists()) { $pageSD = IACLDefinition::getSDForPE(IACL::PE_PAGE, $article->getId()); if ($pageSD && $selectedSD) { // Check if page's SD ID passed as selected if ($pageSD['pe_type'] == $selectedSD[0] && $pageSD['pe_id'] == $selectedSD[1]) { return true; } // Check if page's SD is single inclusion and it is passed as selected if ($pageSD['single_child'] == $selectedSD) { return true; } } } // Check if no protection selected and no protection exists if (!$selectedSD && !$pageSD) { return true; } // Check if other SD is a predefined right // FIXME Allow selecting non-PE_RIGHTs in quick acl toolbar? if ($selectedSD && $selectedSD[0] != IACL::PE_RIGHT) { return true; } // Check SD modification rights $pageSDName = IACLDefinition::nameOfSD(IACL::PE_PAGE, $article->getTitle()); $etc = haclfDisableTitlePatch(); $pageSDTitle = Title::newFromText($pageSDName); haclfRestoreTitlePatch($etc); if (!$pageSDTitle->userCan('edit')) { return true; } $newSDArticle = new WikiPage($pageSDTitle); if ($selectedSD) { // Create/modify page SD $selectedSDTitle = IACLDefinition::getSDTitle($selectedSD); $content = '{{#predefined right: ' . $selectedSDTitle->getText() . "}}\n" . '{{#manage rights: assigned to = User:'******'hacl_comment_protect_with', $selectedSDTitle->getFullText())); } else { // Remove page SD $newSDArticle->doDeleteArticle(wfMsg('hacl_comment_unprotect')); } // Continue hook processing return true; }
/** * Generate the generic "this page has been changed" e-mail text. */ private function composeCommonMailtext() { global $wgPasswordSender, $wgNoReplyAddress; global $wgEnotifFromEditor, $wgEnotifRevealEditorAddress; global $wgEnotifImpersonal, $wgEnotifUseRealName; $this->composed_common = true; # You as the WikiAdmin and Sysops can make use of plenty of # named variables when composing your notification emails while # simply editing the Meta pages $keys = array(); $postTransformKeys = array(); $pageTitleUrl = $this->title->getCanonicalURL(); $pageTitle = $this->title->getPrefixedText(); if ($this->oldid) { // Always show a link to the diff which triggered the mail. See bug 32210. $keys['$NEWPAGE'] = "\n\n" . wfMessage('enotif_lastdiff', $this->title->getCanonicalURL(array('diff' => 'next', 'oldid' => $this->oldid)))->inContentLanguage()->text(); if (!$wgEnotifImpersonal) { // For personal mail, also show a link to the diff of all changes // since last visited. $keys['$NEWPAGE'] .= "\n\n" . wfMessage('enotif_lastvisited', $this->title->getCanonicalURL(array('diff' => '0', 'oldid' => $this->oldid)))->inContentLanguage()->text(); } $keys['$OLDID'] = $this->oldid; // Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility. $keys['$CHANGEDORCREATED'] = wfMessage('changed')->inContentLanguage()->text(); } else { # clear $OLDID placeholder in the message template $keys['$OLDID'] = ''; $keys['$NEWPAGE'] = ''; // Deprecated since MediaWiki 1.21, not used by default. Kept for backwards-compatibility. $keys['$CHANGEDORCREATED'] = wfMessage('created')->inContentLanguage()->text(); } $keys['$PAGETITLE'] = $this->title->getPrefixedText(); $keys['$PAGETITLE_URL'] = $this->title->getCanonicalURL(); $keys['$PAGEMINOREDIT'] = $this->minorEdit ? wfMessage('minoredit')->inContentLanguage()->text() : ''; $keys['$UNWATCHURL'] = $this->title->getCanonicalURL('action=unwatch'); if ($this->editor->isAnon()) { # real anon (user:xxx.xxx.xxx.xxx) $keys['$PAGEEDITOR'] = wfMessage('enotif_anon_editor', $this->editor->getName())->inContentLanguage()->text(); $keys['$PAGEEDITOR_EMAIL'] = wfMessage('noemailtitle')->inContentLanguage()->text(); } else { $keys['$PAGEEDITOR'] = $wgEnotifUseRealName && $this->editor->getRealName() !== '' ? $this->editor->getRealName() : $this->editor->getName(); $emailPage = SpecialPage::getSafeTitleFor('Emailuser', $this->editor->getName()); $keys['$PAGEEDITOR_EMAIL'] = $emailPage->getCanonicalURL(); } $keys['$PAGEEDITOR_WIKI'] = $this->editor->getUserPage()->getCanonicalURL(); $keys['$HELPPAGE'] = wfExpandUrl(Skin::makeInternalOrExternalUrl(wfMessage('helppage')->inContentLanguage()->text())); # Replace this after transforming the message, bug 35019 $postTransformKeys['$PAGESUMMARY'] = $this->summary == '' ? ' - ' : $this->summary; // Now build message's subject and body // Messages: // enotif_subject_deleted, enotif_subject_created, enotif_subject_moved, // enotif_subject_restored, enotif_subject_changed $this->subject = wfMessage('enotif_subject_' . $this->pageStatus)->inContentLanguage()->params($pageTitle, $keys['$PAGEEDITOR'])->text(); // Messages: // enotif_body_intro_deleted, enotif_body_intro_created, enotif_body_intro_moved, // enotif_body_intro_restored, enotif_body_intro_changed $keys['$PAGEINTRO'] = wfMessage('enotif_body_intro_' . $this->pageStatus)->inContentLanguage()->params($pageTitle, $keys['$PAGEEDITOR'], $pageTitleUrl)->text(); $body = wfMessage('enotif_body')->inContentLanguage()->plain(); $body = strtr($body, $keys); $body = MessageCache::singleton()->transform($body, false, null, $this->title); $this->body = wordwrap(strtr($body, $postTransformKeys), 72); # Reveal the page editor's address as REPLY-TO address only if # the user has not opted-out and the option is enabled at the # global configuration level. $adminAddress = new MailAddress($wgPasswordSender, wfMessage('emailsender')->inContentLanguage()->text()); if ($wgEnotifRevealEditorAddress && $this->editor->getEmail() != '' && $this->editor->getOption('enotifrevealaddr')) { $editorAddress = MailAddress::newFromUser($this->editor); if ($wgEnotifFromEditor) { $this->from = $editorAddress; } else { $this->from = $adminAddress; $this->replyto = $editorAddress; } } else { $this->from = $adminAddress; $this->replyto = new MailAddress($wgNoReplyAddress); } }
} $sql = $db->Query('SELECT project_id, project_title, project_is_active, others_view, default_entry, upper(project_title) AS sort_names FROM {projects} ORDER BY sort_names'); # old: #$fs->projects = array_filter($db->FetchAllArray($sql), array($user, 'can_view_project')); # new: project_id as index for easier access, needs testing and maybe simplification # similiar situation also includes/class.flyspray.php function listProjects() $sres = $db->FetchAllArray($sql); foreach ($sres as $p) { $prs[$p['project_id']] = $p; } $fs->projects = array_filter($prs, array($user, 'can_view_project')); // Get e-mail addresses of the admins if ($user->isAnon() && !$fs->prefs['user_notify']) { $sql = $db->Query('SELECT email_address FROM {users} u LEFT JOIN {users_in_groups} g ON u.user_id = g.user_id WHERE g.group_id = 1'); $page->assign('admin_emails', array_map(create_function('$x', 'return str_replace("@", "#", $x);'), $db->fetchCol($sql))); } // default title $page->setTitle($fs->prefs['page_title'] . $proj->prefs['project_title']); $page->assign('do', $do); $page->assign('supertask_id', $supertask_id); $page->pushTpl('header.tpl'); if (!defined('NO_DO')) { require_once BASEDIR . "/scripts/{$do}.php"; } else { # not nicest solution, NO_DO currently only used on register actions