/** * Check that the user isn't blocked from editing. * * @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 checkUserBlock($action, $user, $errors, $rigor, $short) { // Account creation blocks handled at userlogin. // Unblocking handled in SpecialUnblock if ($rigor === 'quick' || in_array($action, array('createaccount', 'unblock'))) { return $errors; } global $wgEmailConfirmToEdit; if ($wgEmailConfirmToEdit && !$user->isEmailConfirmed()) { $errors[] = array('confirmedittext'); } $useSlave = $rigor !== 'secure'; if (($action == 'edit' || $action == 'create') && !$user->isBlockedFrom($this, $useSlave)) { // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. } elseif ($user->isBlocked() && $user->getBlock()->prevents($action) !== false) { // @todo FIXME: Pass the relevant context into this function. $errors[] = $user->getBlock()->getPermissionsError(RequestContext::getMain()); } return $errors; }
/** * Called from execute() to check if the given user can perform this action. * Failures here must throw subclasses of ErrorPageError. * @param $user User * @return Bool true * @throws ErrorPageError */ protected function checkExecutePermissions(User $user) { $this->checkPermissions(); if ($this->requiresUnblock() && $user->isBlocked()) { $block = $user->getBlock(); throw new UserBlockedError($block); } if ($this->requiresWrite()) { $this->checkReadOnly(); } return true; }
/** * Links to different places. * @param Title $userpage Target user page * @param Title $talkpage Talk page * @param User $target Target user object * @return array */ public function getUserLinks(Title $userpage, Title $talkpage, User $target) { $id = $target->getId(); $username = $target->getName(); $tools[] = Linker::link($talkpage, $this->msg('sp-contributions-talk')->escaped()); if ($id !== null || $id === null && IP::isIPAddress($username)) { if ($this->getUser()->isAllowed('block')) { # Block / Change block / Unblock links if ($target->isBlocked() && $target->getBlock()->getType() != Block::TYPE_AUTO) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $username), $this->msg('change-blocklink')->escaped()); $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Unblock', $username), $this->msg('unblocklink')->escaped()); } else { # User is not blocked $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $username), $this->msg('blocklink')->escaped()); } } # Block log link $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log', 'block'), $this->msg('sp-contributions-blocklog')->escaped(), array(), array('page' => $userpage->getPrefixedText())); # Suppression log link (bug 59120) if ($this->getUser()->isAllowed('suppressionlog')) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log', 'suppress'), $this->msg('sp-contributions-suppresslog')->escaped(), array(), array('offender' => $username)); } } # Uploads $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Listfiles', $username), $this->msg('sp-contributions-uploads')->escaped()); # Other logs link $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log', $username), $this->msg('sp-contributions-logs')->escaped()); # Add link to deleted user contributions for priviledged users if ($this->getUser()->isAllowed('deletedhistory')) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('DeletedContributions', $username), $this->msg('sp-contributions-deleted')->escaped()); } # Add a link to change user rights for privileged users $userrightsPage = new UserrightsPage(); $userrightsPage->setContext($this->getContext()); if ($userrightsPage->userCanChangeRights($target)) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Userrights', $username), $this->msg('sp-contributions-userrights')->escaped()); } Hooks::run('ContributionsToolLinks', array($id, $userpage, &$tools)); return $tools; }
/** * Links to different places. * * @note This function is also called in DeletedContributionsPage * @param SpecialPage $sp SpecialPage instance, for context * @param User $target Target user object * @return array */ public static function getUserLinks(SpecialPage $sp, User $target) { $id = $target->getId(); $username = $target->getName(); $userpage = $target->getUserPage(); $talkpage = $target->getTalkPage(); $linkRenderer = $sp->getLinkRenderer(); $tools['user-talk'] = $linkRenderer->makeLink($talkpage, $sp->msg('sp-contributions-talk')->text()); if ($id !== null || $id === null && IP::isIPAddress($username)) { if ($sp->getUser()->isAllowed('block')) { # Block / Change block / Unblock links if ($target->isBlocked() && $target->getBlock()->getType() != Block::TYPE_AUTO) { $tools['block'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Block', $username), $sp->msg('change-blocklink')->text()); $tools['unblock'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Unblock', $username), $sp->msg('unblocklink')->text()); } else { # User is not blocked $tools['block'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Block', $username), $sp->msg('blocklink')->text()); } } # Block log link $tools['log-block'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Log', 'block'), $sp->msg('sp-contributions-blocklog')->text(), [], ['page' => $userpage->getPrefixedText()]); # Suppression log link (bug 59120) if ($sp->getUser()->isAllowed('suppressionlog')) { $tools['log-suppression'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Log', 'suppress'), $sp->msg('sp-contributions-suppresslog', $username)->text(), [], ['offender' => $username]); } } # Uploads $tools['uploads'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Listfiles', $username), $sp->msg('sp-contributions-uploads')->text()); # Other logs link $tools['logs'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Log', $username), $sp->msg('sp-contributions-logs')->text()); # Add link to deleted user contributions for priviledged users if ($sp->getUser()->isAllowed('deletedhistory')) { $tools['deletedcontribs'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('DeletedContributions', $username), $sp->msg('sp-contributions-deleted', $username)->text()); } # Add a link to change user rights for privileged users $userrightsPage = new UserrightsPage(); $userrightsPage->setContext($sp->getContext()); if ($userrightsPage->userCanChangeRights($target)) { $tools['userrights'] = $linkRenderer->makeKnownLink(SpecialPage::getTitleFor('Userrights', $username), $sp->msg('sp-contributions-userrights')->text()); } Hooks::run('ContributionsToolLinks', [$id, $userpage, &$tools, $sp]); return $tools; }
/** * Generates the subheading with links * @param User $userObj User object for the target * @return string Appropriately-escaped HTML to be output literally * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined. */ function getSubTitle($userObj) { if ($userObj->isAnon()) { $user = htmlspecialchars($userObj->getName()); } else { $user = Linker::link($userObj->getUserPage(), htmlspecialchars($userObj->getName())); } $links = ''; $nt = $userObj->getUserPage(); $id = $userObj->getID(); $talk = $nt->getTalkPage(); if ($talk) { # Talk page link $tools[] = Linker::link($talk, $this->msg('sp-contributions-talk')->escaped()); if ($id !== null || $id === null && IP::isIPAddress($nt->getText())) { # Block / Change block / Unblock links if ($this->getUser()->isAllowed('block')) { if ($userObj->isBlocked() && $userObj->getBlock()->getType() !== Block::TYPE_AUTO) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $nt->getDBkey()), $this->msg('change-blocklink')->escaped()); $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('BlockList'), $this->msg('unblocklink')->escaped(), array(), array('action' => 'unblock', 'ip' => $nt->getDBkey())); } else { # User is not blocked $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Block', $nt->getDBkey()), $this->msg('blocklink')->escaped()); } } # Block log link $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log'), $this->msg('sp-contributions-blocklog')->escaped(), array(), array('type' => 'block', 'page' => $nt->getPrefixedText())); # Suppression log link (bug 59120) if ($this->getUser()->isAllowed('suppressionlog')) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log', 'suppress'), $this->msg('sp-contributions-suppresslog')->escaped(), array(), array('offender' => $userObj->getName())); } } # Uploads $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Listfiles', $userObj->getName()), $this->msg('sp-contributions-uploads')->escaped()); # Other logs link $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Log'), $this->msg('sp-contributions-logs')->escaped(), array(), array('user' => $nt->getText())); # Link to contributions $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Contributions', $nt->getDBkey()), $this->msg('sp-deletedcontributions-contribs')->escaped()); # Add a link to change user rights for privileged users $userrightsPage = new UserrightsPage(); $userrightsPage->setContext($this->getContext()); if ($userrightsPage->userCanChangeRights($userObj)) { $tools[] = Linker::linkKnown(SpecialPage::getTitleFor('Userrights', $nt->getDBkey()), $this->msg('sp-contributions-userrights')->escaped()); } Hooks::run('ContributionsToolLinks', array($id, $nt, &$tools)); $links = $this->getLanguage()->pipeList($tools); // Show a note if the user is blocked and display the last block log entry. $block = Block::newFromTarget($userObj, $userObj); if (!is_null($block) && $block->getType() != Block::TYPE_AUTO) { if ($block->getType() == Block::TYPE_RANGE) { $nt = MWNamespace::getCanonicalName(NS_USER) . ':' . $block->getTarget(); } // LogEventsList::showLogExtract() wants the first parameter by ref $out = $this->getOutput(); LogEventsList::showLogExtract($out, 'block', $nt, '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('sp-contributions-blocked-notice', $userObj->getName()), 'offset' => '')); } } return $this->msg('contribsub2')->rawParams($user, $links)->params($userObj->getName()); }