function newAttachmentData($id) { $obj = $this->cacheManager->retrieveAtachmentData($id); if ($obj instanceof \PageAttachment\Attachment\AttachmentData) { $pageAttachmentData = $obj; } else { $title = \Title::newFromID($id); $article = new \Article($title, NS_FILE); $file = \wfFindFile($title); $size = $file->getSize(); $description = $this->replaceHtmlTags($file->getDescriptionText()); $dateUploaded = $article->getTimestamp(); $uploadedBy = null; if ($this->runtimeConfig->isShowUserRealName()) { $uploadedBy = \User::whoIsReal($article->getUser()); } if ($uploadedBy == null) { $uploadedBy = \User::whoIs($article->getUser()); } $attachedToPages = null; if ($this->securityManager->isRemoveAttachmentPermanentlyEnabled()) { $attachedToPages = $this->getAttachedToPages($id); } $pageAttachmentData = new AttachmentData($id, $title, $size, $description, $dateUploaded, $uploadedBy, $attachedToPages); $this->cacheManager->storeAttachmentData($pageAttachmentData); } return $pageAttachmentData; }
/** * */ function getAuthorCredits($article) { global $wgLang, $wgAllowRealName; $last_author = $article->getUser(); if ($last_author == 0) { $author_credit = wfMsg('anonymous'); } else { if ($wgAllowRealName) { $real_name = User::whoIsReal($last_author); } $user_name = User::whoIs($last_author); if (!empty($real_name)) { $author_credit = creditLink($user_name, $real_name); } else { $author_credit = wfMsg('siteuser', creditLink($user_name)); } } $timestamp = $article->getTimestamp(); if ($timestamp) { $d = $wgLang->date($article->getTimestamp(), true); $t = $wgLang->time($article->getTimestamp(), true); } else { $d = ''; $t = ''; } return wfMsg('lastmodifiedatby', $d, $t, $author_credit); }
function wfContributionseditcount($uid) { if ($uid != 0) { global $wgOut, $wgLang; $wgOut->addWikiText(wfMsgExt('contributionseditcount', array('parsemag'), $wgLang->formatNum(User::edits($uid)), User::whoIs($uid))); } return true; }
public static function getCommunityUser($name, $noRedirect = false) { if (is_int($name)) { $name = User::whoIs($name); } $title = GlobalTitle::newFromText($name, NS_USER, COMMUNITY_CENTRAL_CITY_ID); return Xml::element('a', array('href' => $title->getFullURL($noRedirect ? 'redirect=no' : '')), $name, false); }
protected function getCurrentUserInfo() { global $wgUser; $result = $this->getResult(); $vals = array(); $vals['id'] = intval($wgUser->getId()); $vals['name'] = $wgUser->getName(); if ($wgUser->isAnon()) { $vals['anon'] = ''; } if (isset($this->prop['blockinfo'])) { if ($wgUser->isBlocked()) { $vals['blockedby'] = User::whoIs($wgUser->blockedBy()); $vals['blockreason'] = $wgUser->blockedFor(); } } if (isset($this->prop['hasmsg']) && $wgUser->getNewtalk()) { $vals['messages'] = ''; } if (isset($this->prop['groups'])) { $vals['groups'] = $wgUser->getGroups(); $result->setIndexedTagName($vals['groups'], 'g'); // even if empty } if (isset($this->prop['rights'])) { // User::getRights() may return duplicate values, strip them $vals['rights'] = array_values(array_unique($wgUser->getRights())); $result->setIndexedTagName($vals['rights'], 'r'); // even if empty } if (isset($this->prop['changeablegroups'])) { $vals['changeablegroups'] = $wgUser->changeableGroups(); $result->setIndexedTagName($vals['changeablegroups']['add'], 'g'); $result->setIndexedTagName($vals['changeablegroups']['remove'], 'g'); $result->setIndexedTagName($vals['changeablegroups']['add-self'], 'g'); $result->setIndexedTagName($vals['changeablegroups']['remove-self'], 'g'); } if (isset($this->prop['options'])) { $vals['options'] = $wgUser->getOptions(); } if (isset($this->prop['preferencestoken']) && is_null($this->getMain()->getRequest()->getVal('callback'))) { $vals['preferencestoken'] = $wgUser->editToken(); } if (isset($this->prop['editcount'])) { $vals['editcount'] = intval($wgUser->getEditCount()); } if (isset($this->prop['ratelimits'])) { $vals['ratelimits'] = $this->getRateLimits(); } if (isset($this->prop['email'])) { $vals['email'] = $wgUser->getEmail(); $auth = $wgUser->getEmailAuthenticationTimestamp(); if (!is_null($auth)) { $vals['emailauthenticated'] = wfTimestamp(TS_ISO_8601, $auth); } } return $vals; }
/** * Initialise a user from an identifier or a username * * @param mixed $spec User identifier or name * @return User */ private function makeUser($spec) { $name = is_integer($spec) ? User::whoIs($spec) : $spec; $user = User::newFromName($name); if ($user instanceof User && $user->getId() > 0) { return $user; } return null; }
function getEdits() { global $wgRequest, $wgLang; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('logging', array("*"), array("log_timestamp >= '{$this->ts}'", "log_type = 'methedit'", "log_action='Added'"), __METHOD__, array('ORDER BY' => 'log_timestamp DESC')); $edits = array(); while ($row = $dbr->fetchObject($res)) { $edit = get_object_vars($row); $edit['log_user_name'] = User::whoIs($row->log_user); $title = Title::newFromText($row->log_title); $edit['title_url'] = $title->getFullURL(); $edit['date'] = $wgLang->timeanddate(wfTimestamp(TS_MW, $row->log_timestamp), true); $edits[] = $edit; } return $edits; }
protected function getCurrentUserInfo() { global $wgUser; $result = $this->getResult(); $vals = array(); $vals['id'] = $wgUser->getId(); $vals['name'] = $wgUser->getName(); if ($wgUser->isAnon()) { $vals['anon'] = ''; } if (isset($this->prop['blockinfo'])) { if ($wgUser->isBlocked()) { $vals['blockedby'] = User::whoIs($wgUser->blockedBy()); $vals['blockreason'] = $wgUser->blockedFor(); } } if (isset($this->prop['hasmsg']) && $wgUser->getNewtalk()) { $vals['messages'] = ''; } if (isset($this->prop['groups'])) { $vals['groups'] = $wgUser->getGroups(); $result->setIndexedTagName($vals['groups'], 'g'); // even if empty } if (isset($this->prop['rights'])) { // User::getRights() may return duplicate values, strip them $vals['rights'] = array_values(array_unique($wgUser->getRights())); $result->setIndexedTagName($vals['rights'], 'r'); // even if empty } if (isset($this->prop['options'])) { $vals['options'] = is_null($wgUser->mOptions) ? User::getDefaultOptions() : $wgUser->mOptions; } if (isset($this->prop['preferencestoken']) && is_null($this->getMain()->getRequest()->getVal('callback'))) { $vals['preferencestoken'] = $wgUser->editToken(); } if (isset($this->prop['editcount'])) { $vals['editcount'] = $wgUser->getEditCount(); } if (isset($this->prop['ratelimits'])) { $vals['ratelimits'] = $this->getRateLimits(); } return $vals; }
protected function getCurrentUserInfo() { global $wgUser; $result = $this->getResult(); $vals = array(); $vals['id'] = $wgUser->getId(); $vals['name'] = $wgUser->getName(); if ($wgUser->isAnon()) { $vals['anon'] = ''; } if (isset($this->prop['blockinfo'])) { if ($wgUser->isBlocked()) { $vals['blockedby'] = User::whoIs($wgUser->blockedBy()); $vals['blockreason'] = $wgUser->blockedFor(); } } if (isset($this->prop['hasmsg']) && $wgUser->getNewtalk()) { $vals['messages'] = ''; } if (isset($this->prop['groups'])) { $vals['groups'] = $wgUser->getGroups(); $result->setIndexedTagName($vals['groups'], 'g'); // even if empty } if (isset($this->prop['rights'])) { $vals['rights'] = $wgUser->getRights(); $result->setIndexedTagName($vals['rights'], 'r'); // even if empty } if (isset($this->prop['options'])) { $vals['options'] = is_null($wgUser->mOptions) ? User::getDefaultOptions() : $wgUser->mOptions; } if (isset($this->prop['editcount'])) { $vals['editcount'] = $wgUser->getEditCount(); } if (isset($this->prop['ratelimits'])) { $vals['ratelimits'] = $this->getRateLimits(); } return $vals; }
function execute($par) { $this->setHeaders(); global $wgRequest; if ($uid = $wgRequest->getVal('uid')) { global $wgOut, $wgUser; $wgOut->disable(); $user = User::newFromName($name = User::whoIs($uid)); if (!$user) { $enabled = false; } else { $enabled = $user->getGlobalPreference("enableWatchlistFeed") == "yes" ? true : false; $wgUser = $user; } $feed = $this->createFeed(); if (!$enabled) { $this->displayDisabledFeed($feed); } else { $this->displayWatchlist($feed, $user); } } else { # not a feed link global $wgUser; if ($wgUser->isAnon()) { global $wgOut; $wgOut->loginToUse(); } else { if ($wgRequest->getVal("wpenable")) { $this->enableFeed(); } else { if ($wgRequest->getVal("wpdisable")) { $this->disableFeed(); } } $this->displayConfigurationForm(); } } }
function execute($par) { global $wgOut, $wgRequest, $wgUser, $wgLang; if (!in_array('staff', $wgUser->getGroups())) { $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext'); return; } $target = $wgRequest->getVal("target"); if ($target && is_numeric($target)) { $target = User::whoIs(intval($target)); } $wgOut->addHTML("\n\t\t\t<form action='/Special:UnpatrolTips' method='POST'>\n\t\t\t\tUsername: <input type='text' name='username' value='{$target}'/> <br/><br/>\n\t\t\t\tStart date: Year: " . date("Y") . " Month: <input type='text' name='month_1' size='2' value='" . date("m") . "'/>\n\t\t\t\t\t\tDay: <input type='text' name='day_1' size='2' value='" . date("d") . "'>\n\t\t\t\t\t\tHour (GMT): <input type='text' name='hour_1' size='2' value='00'> <br/><br/>\n\t\t\t\tEnd date (optional): Year: " . date("Y") . " <input type='text' name='month_2' size='2'>\n\t\t\t\t\t\tDay: <input type='text' name='day_2' size='2'>\n\t\t\t\t\t\tHour (GMT): <input type='text' name='hour_2' size='2' value='00'> <br/><br/>\n\t\t\t\t<input type='submit'/>\n\t\t\t</form>\t"); if ($wgRequest->wasPosted()) { $user = $wgRequest->getVal('username'); $start = date("Y") . $this->padVar('month_1') . $this->padVar('day_1') . $this->padVar('hour_1') . "0000"; $end = $wgRequest->getVal('month_2') ? date("Y") . $this->padVar('month_2') . $this->padVar('day_2') . $this->padVar('hour_2') . "0000" : null; $cutoff = wfTimestamp(TS_MW, $start); $cutoff2 = null; if (!$end) { $wgOut->addHTML("reverting changes by {$user} since {$cutoff}<br/>"); } else { $cutoff2 = wfTimestamp(TS_MW, $end); $wgOut->addHTML("reverting changes by {$user} between {$cutoff} and {$cutoff2} <br/>"); } $user = User::newFromName($user); if ($user->getID() == 0) { $wgOut->addHTML("<b>There is no user with this name {$wgRequest->getVal('username', '')}, bailing.</b>"); return; } $unpatrolled = $this->revertTips($user, $cutoff, $cutoff2, false); if ($unpatrolled > 0) { $wgOut->addHTML("Reverted " . $unpatrolled . " tips patrolled by {$user->getName()}\n"); } else { $wgOut->addHTML("There were no tips patrolled to undo for this time frame.<br/>"); } } return; }
/** * Map an existing Wikia user to a Facebook id * If an exact or partial match of the map already exists, OR * if creation of mapping does not succeed, returns not-OK Status * * @param int $wikiaUserId * @param int $fbUserId * @return \Status (status value will be null or \FacebookMapModel if successfully created) */ public function connectToFacebook($wikiaUserId, $fbUserId) { $status = new Status(); try { $map = \FacebookMapModel::getUserMapping($wikiaUserId, $fbUserId); if ($map) { // Error! There is already a mapping $status->setResult(false); $status->error('fbconnect-error-already-connected'); } else { $bizToken = \FacebookClient::getInstance()->getBizToken(); $map = \FacebookMapModel::createUserMapping($wikiaUserId, $fbUserId, $bizToken); if ($map instanceof \FacebookMapModel) { $status->setResult(true, $map); } else { $status->setResult(false); $status->error('fbconnect-error'); } } } catch (\Exception $e) { $messageParams = []; switch ($e->getCode()) { case \FacebookMapModel::ERROR_WIKIA_USER_ID_MISMATCH: $messageParams[] = 'fbconnect-error-fb-account-in-use'; $messageParams[] = \User::whoIs($wikiaUserId); break; case \FacebookMapModel::ERROR_FACEBOOK_USER_ID_MISMATCH: $messageParams[] = 'fbconnect-error-already-connected'; break; default: $messageParams[] = 'fbconnect-error'; } $status->setResult(false); call_user_func_array([$status, 'error'], $messageParams); } return $status; }
function PersonToResource($userid, $username = null, $realname = null) { if ($userid == 0) { return self::LiteralNode('anonymous'); } if (!$realname) { $realname = User::whoIsReal($userid); } if ($realname) { return self::LiteralNode($realname); } if (!$username) { $username = User::whoIs($userid); } $user = User::newFromName($username); if (!$user) { return self::LiteralNode('anonymous'); } if ($user->getUserPage()->exists()) { $mf = self::ModelingAgent($user->getUserPage()); return $mf->titleResource(); } return self::LiteralNode(wfMsg('siteuser', $user->getName())); }
/** * @param $row * @return string */ public function formatRow($row) { global $wgMemc; if ($this->showRejects || $this->showStale) { $link = Linker::makeKnownLinkObj($this->getFullTitle(), $this->msg('confirmaccount-review')->escaped(), 'acrid=' . (int) $row->acr_id . '&wpShowRejects=1'); } else { $link = Linker::makeKnownLinkObj($this->getFullTitle(), $this->msg('confirmaccount-review')->escaped(), 'acrid=' . (int) $row->acr_id); } $time = $this->getLanguage()->timeanddate(wfTimestamp(TS_MW, $row->acr_registration), true); $r = "<li class='mw-confirmaccount-type-{$this->queueType}'>"; $r .= $time . " (<strong>{$link}</strong>)"; # Auto-rejected accounts have a user ID of zero if ($row->acr_rejected && $row->acr_user) { $datim = $this->getLanguage()->timeanddate(wfTimestamp(TS_MW, $row->acr_rejected), true); $date = $this->getLanguage()->date(wfTimestamp(TS_MW, $row->acr_rejected), true); $time = $this->getLanguage()->time(wfTimestamp(TS_MW, $row->acr_rejected), true); $r .= ' <b>' . $this->msg('confirmaccount-reject', $row->user_name, $datim, $date, $time)->parse() . '</b>'; } elseif ($row->acr_held && !$row->acr_rejected) { $datim = $this->getLanguage()->timeanddate(wfTimestamp(TS_MW, $row->acr_held), true); $date = $this->getLanguage()->date(wfTimestamp(TS_MW, $row->acr_held), true); $time = $this->getLanguage()->time(wfTimestamp(TS_MW, $row->acr_held), true); $r .= ' <b>' . $this->msg('confirmaccount-held', User::whoIs($row->acr_user), $datim, $date, $time)->parse() . '</b>'; } # Check if someone is viewing this request $key = wfMemcKey('acctrequest', 'view', $row->acr_id); $value = $wgMemc->get($key); if ($value) { $r .= ' <b>' . $this->msg('confirmaccount-viewing', User::whoIs($value))->parse() . '</b>'; } $r .= "<br /><table class='mw-confirmaccount-body-{$this->queueType}' cellspacing='1' cellpadding='3' border='1' width='100%'>"; if ($this->hasItem('UserName')) { $r .= '<tr><td><strong>' . $this->msg('confirmaccount-name')->escaped() . '</strong></td><td width=\'100%\'>' . htmlspecialchars($row->acr_name) . '</td></tr>'; } if ($this->hasItem('RealName')) { $hasCV = $row->acr_filename ? ' <strong>' . $this->msg('confirmaccount-withcv')->escaped() . '</strong>' : ''; $r .= '<tr><td><strong>' . $this->msg('confirmaccount-real-q')->escaped() . '</strong></td><td width=\'100%\'>' . htmlspecialchars($row->acr_real_name) . $hasCV . '</td></tr>'; } $econf = $row->acr_email_authenticated ? ' <strong>' . $this->msg('confirmaccount-econf')->escaped() . '</strong>' : ''; $r .= '<tr><td><strong>' . $this->msg('confirmaccount-email-q')->escaped() . '</strong></td><td width=\'100%\'>' . htmlspecialchars($row->acr_email) . $econf . '</td></tr>'; # Truncate this, blah blah... $bio = htmlspecialchars($row->acr_bio); $preview = $this->getLanguage()->truncate($bio, 400, ''); if (strlen($preview) < strlen($bio)) { $preview = substr($preview, 0, strrpos($preview, ' ')); $preview .= " . . ."; } $r .= '<tr><td><strong>' . $this->msg('confirmaccount-bio-q')->escaped() . '</strong></td><td width=\'100%\'><i>' . $preview . '</i></td></tr>'; $r .= '</table>'; $r .= '</li>'; return $r; }
/** * Check that the user isn't blocked from editting. * * @param $action String the action to check * @param $user User to check * @param $errors Array list of current errors * @param $doExpensiveQueries Boolean whether or not to perform expensive queries * @param $short Boolean short circuit on first error * * @return Array list of errors */ private function checkUserBlock($action, $user, $errors, $doExpensiveQueries, $short) { if (!$doExpensiveQueries) { return $errors; } global $wgContLang, $wgLang, $wgEmailConfirmToEdit; if ($wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount') { $errors[] = array('confirmedittext'); } if (in_array($action, array('read', 'createaccount', 'unblock'))) { // Edit blocks should not affect reading. // Account creation blocks handled at userlogin. // Unblocking handled in SpecialUnblock } elseif (($action == 'edit' || $action == 'create') && !$user->isBlockedFrom($this)) { // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. } elseif ($user->isBlocked() && $user->mBlock->prevents($action) !== false) { $block = $user->mBlock; // This is from OutputPage::blockedPage // Copied at r23888 by werdna $id = $user->blockedBy(); $reason = $user->blockedFor(); if ($reason == '') { $reason = wfMsg('blockednoreason'); } $ip = wfGetIP(); if (is_numeric($id)) { $name = User::whoIs($id); } else { $name = $id; } $link = '[[' . $wgContLang->getNsText(NS_USER) . ":{$name}|{$name}]]"; $blockid = $block->getId(); $blockExpiry = $user->mBlock->mExpiry; $blockTimestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $user->mBlock->mTimestamp), true); if ($blockExpiry == 'infinity') { $blockExpiry = wfMessage('infiniteblock')->text(); } else { $blockExpiry = $wgLang->timeanddate(wfTimestamp(TS_MW, $blockExpiry), true); } $intended = strval($user->mBlock->getTarget()); $errors[] = array($block->mAuto ? 'autoblockedtext' : 'blockedtext', $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp); } return $errors; }
private function getUserFromFB($fb_userid) { global $wgSharedDB, $wgDBprefix; if (isset($wgSharedDB)) { $tableName = "`{$wgSharedDB}`.{$wgDBprefix}user_facebook"; } else { $tableName = 'user_facebook'; } $dbr =& wfGetDB(DB_SLAVE); $id = $dbr->selectField($tableName, 'user', array('fb_userid' => $fb_userid)); if ($id) { $name = User::whoIs($id); return User::newFromName($name); } else { return NULL; } }
/** * Can $user perform $action on this page? This is an internal function, * which checks ONLY that previously checked by userCan (i.e. it leaves out * checks on wfReadOnly() and blocks) * * @param string $action action that permission needs to be checked for * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries. * @return array Array of arrays of the arguments to wfMsg to explain permissions problems. */ private function getUserPermissionsErrorsInternal($action, $user, $doExpensiveQueries = true) { wfProfileIn(__METHOD__); $errors = array(); // Use getUserPermissionsErrors instead if (!wfRunHooks('userCan', array(&$this, &$user, $action, &$result))) { return $result ? array() : array(array('badaccess-group0')); } if (!wfRunHooks('getUserPermissionsErrors', array(&$this, &$user, $action, &$result))) { if ($result != array() && is_array($result) && !is_array($result[0])) { $errors[] = $result; } else { if (is_array($result) && is_array($result[0])) { $errors = array_merge($errors, $result); } else { if ($result != '' && $result != null && $result !== true && $result !== false) { $errors[] = array($result); } else { if ($result === false) { $errors[] = array('badaccess-group0'); } } } } # a generic "We don't want them to do that" } if ($doExpensiveQueries && !wfRunHooks('getUserPermissionsErrorsExpensive', array(&$this, &$user, $action, &$result))) { if ($result != array() && is_array($result) && !is_array($result[0])) { $errors[] = $result; } else { if (is_array($result) && is_array($result[0])) { $errors = array_merge($errors, $result); } else { if ($result != '' && $result != null && $result !== true && $result !== false) { $errors[] = array($result); } else { if ($result === false) { $errors[] = array('badaccess-group0'); } } } } # a generic "We don't want them to do that" } if (NS_SPECIAL == $this->mNamespace) { $errors[] = array('ns-specialprotected'); } if ($this->isNamespaceProtected() && $action != 'patrol') { $ns = $this->getNamespace() == NS_MAIN ? wfMsg('nstab-main') : $this->getNsText(); $errors[] = NS_MEDIAWIKI == $this->mNamespace ? array('protectedinterface') : array('namespaceprotected', $ns); } if ($this->mDbkeyform == '-') { # FIXME: Is this necessary? Shouldn't be allowed anyway... $errors[] = array('badaccess-group0'); } # protect css/js subpages of user pages # XXX: this might be better using restrictions # XXX: Find a way to work around the php bug that prevents using $this->userCanEditCssJsSubpage() from working if ($this->isCssJsSubpage() && !$user->isAllowed('editusercssjs') && !preg_match('/^' . preg_quote($user->getName(), '/') . '\\//', $this->mTextform)) { $errors[] = array('customcssjsprotected'); } if ($doExpensiveQueries && !$this->isCssJsSubpage()) { # We /could/ use the protection level on the source page, but it's fairly ugly # as we have to establish a precedence hierarchy for pages included by multiple # cascade-protected pages. So just restrict it to people with 'protect' permission, # as they could remove the protection anyway. list($cascadingSources, $restrictions) = $this->getCascadeProtectionSources(); # Cascading protection depends on more than this page... # Several cascading protected pages may include this page... # Check each cascading level # This is only for protection restrictions, not for all actions if ($cascadingSources > 0 && isset($restrictions[$action])) { foreach ($restrictions[$action] as $right) { $right = $right == 'sysop' ? 'protect' : $right; if ('' != $right && !$user->isAllowed($right)) { $pages = ''; foreach ($cascadingSources as $page) { $pages .= '* [[:' . $page->getPrefixedText() . "]]\n"; } $errors[] = array('cascadeprotected', count($cascadingSources), $pages); } } } } foreach ($this->getRestrictions($action) as $right) { // Backwards compatibility, rewrite sysop -> protect if ($right == 'sysop') { $right = 'protect'; } if ('' != $right && !$user->isAllowed($right)) { $errors[] = array('protectedpagetext', $right); } } if ($action == 'protect') { if ($this->getUserPermissionsErrors('edit', $user) != array()) { $errors[] = array('protect-cantedit'); // If they can't edit, they shouldn't protect. } } if ($action == 'create') { $title_protection = $this->getTitleProtection(); if (is_array($title_protection)) { extract($title_protection); if ($pt_create_perm == 'sysop') { $pt_create_perm = 'protect'; } if ($pt_create_perm == '' || !$user->isAllowed($pt_create_perm)) { $errors[] = array('titleprotected', User::whoIs($pt_user), $pt_reason); } } if ($this->isTalkPage() && !$user->isAllowed('createtalk') || !$this->isTalkPage() && !$user->isAllowed('createpage')) { $errors[] = $user->isAnon() ? array('nocreatetext') : array('nocreate-loggedin'); } } elseif ($action == 'move' && !($this->isMovable() && $user->isAllowed('move'))) { $errors[] = $user->isAnon() ? array('movenologintext') : array('movenotallowed'); } elseif (!$user->isAllowed($action)) { $return = null; $groups = array(); global $wgGroupPermissions; foreach ($wgGroupPermissions as $key => $value) { if (isset($value[$action]) && $value[$action] == true) { $groupName = User::getGroupName($key); $groupPage = User::getGroupPage($key); if ($groupPage) { $groups[] = '[[' . $groupPage->getPrefixedText() . '|' . $groupName . ']]'; } else { $groups[] = $groupName; } } } $n = count($groups); $groups = implode(', ', $groups); switch ($n) { case 0: case 1: case 2: $return = array("badaccess-group{$n}", $groups); break; default: $return = array('badaccess-groups', $groups); } $errors[] = $return; } wfProfileOut(__METHOD__); return $errors; }
/** * Initialise a user from an identifier or a username * * @param $spec User identifier or name * @return mixed */ function makeUser($spec) { $name = is_integer($spec) ? User::whoIs($spec) : $spec; $user = User::newFromName($name); if (is_object($user)) { $user->loadFromDatabase(); if ($user->getId() > 0) { return $user; } } return false; }
/** * Produce a "user is blocked" page. * * @param bool $return Whether to have a "return to $wgTitle" message or not. * @return nothing */ function blockedPage($return = true) { global $wgUser, $wgContLang, $wgTitle, $wgLang; $this->setPageTitle(wfMsg('blockedtitle')); $this->setRobotPolicy('noindex,nofollow'); $this->setArticleRelated(false); $name = User::whoIs($wgUser->blockedBy()); $reason = $wgUser->blockedFor(); if ($reason == '') { $reason = wfMsg('blockednoreason'); } $blockTimestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $wgUser->mBlock->mTimestamp), true); $ip = wfGetIP(); $link = '[[' . $wgContLang->getNsText(NS_USER) . ":{$name}|{$name}]]"; $blockid = $wgUser->mBlock->mId; $blockExpiry = $wgUser->mBlock->mExpiry; if ($blockExpiry == 'infinity') { // Entry in database (table ipblocks) is 'infinity' but 'ipboptions' uses 'infinite' or 'indefinite' // Search for localization in 'ipboptions' $scBlockExpiryOptions = wfMsg('ipboptions'); foreach (explode(',', $scBlockExpiryOptions) as $option) { if (strpos($option, ":") === false) { continue; } list($show, $value) = explode(":", $option); if ($value == 'infinite' || $value == 'indefinite') { $blockExpiry = $show; break; } } } else { $blockExpiry = $wgLang->timeanddate(wfTimestamp(TS_MW, $blockExpiry), true); } if ($wgUser->mBlock->mAuto) { $msg = 'autoblockedtext'; } else { $msg = 'blockedtext'; } /* $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 = $wgUser->mBlock->mAddress; $this->addWikiMsg($msg, $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp); # Don't auto-return to special pages if ($return) { $return = $wgTitle->getNamespace() > -1 ? $wgTitle : NULL; $this->returnToMain(null, $return); } }
/** * Fetch revision's username without regard for view restrictions * * @return String */ public function getRawUserText() { if ($this->mUserText === null) { $this->mUserText = User::whoIs($this->mUser); // load on demand if ($this->mUserText === false) { # This shouldn't happen, but it can if the wiki was recovered # via importing revs and there is no user table entry yet. $this->mUserText = $this->mOrigUserText; } } return $this->mUserText; }
/** * @private */ function dcPerson($name, $id, $user_name = '', $user_real_name = '') { global $wgContLang; if ($id == 0) { dcElement($name, wfMsg('anonymous')); } else { if (!empty($user_real_name)) { dcElement($name, $user_real_name); } else { # XXX: This shouldn't happen. if (empty($user_name)) { $user_name = User::whoIs($id); } dcPageOrString($name, $wgContLang->getNsText(NS_USER) . ':' . $user_name, wfMsg('siteuser', $user_name)); } } }
/** * @todo document */ function blockedIPpage() { global $wgOut, $wgUser, $wgContLang, $wgIP; $wgOut->setPageTitle(wfMsg('blockedtitle')); $wgOut->setRobotpolicy('noindex,nofollow'); $wgOut->setArticleRelated(false); $id = $wgUser->blockedBy(); $reason = $wgUser->blockedFor(); $ip = $wgIP; if (is_numeric($id)) { $name = User::whoIs($id); } else { $name = $id; } $link = '[[' . $wgContLang->getNsText(NS_USER) . ":{$name}|{$name}]]"; $wgOut->addWikiText(wfMsg('blockedtext', $link, $reason, $ip, $name)); $wgOut->returnToMain(false); }
/** */ function userBlockedMessage() { global $wgOut, $wgUser; # Let's be nice about this, it's likely that this feature will be used # for blocking large numbers of innocent people, e.g. range blocks on # schools. Don't blame it on the user. There's a small chance that it # really is the user's fault, i.e. the username is blocked and they # haven't bothered to log out before trying to create an account to # evade it, but we'll leave that to their guilty conscience to figure # out. $wgOut->setPageTitle(wfMsg('cantcreateaccounttitle')); $wgOut->setRobotPolicy('noindex,nofollow'); $wgOut->setArticleRelated(false); $ip = wfGetIP(); $blocker = User::whoIs($wgUser->mBlock->mBy); $block_reason = $wgUser->mBlock->mReason; if (strval($block_reason) === '') { $block_reason = wfMsg('blockednoreason'); } $wgOut->addWikiMsg('cantcreateaccount-text', $ip, $block_reason, $blocker); $wgOut->returnToMain(false); }
/** * blockedPage -- return HTML code for displaying reason of user block * * @access public * * @return String HTML text */ public function blockedPage() { global $wgUser, $wgLang, $wgContLang, $wgRequest; // macbre: prevent fatals in code below if (empty($wgUser->mBlock)) { return ''; } list($blockerName, $reason, $ip, $blockid, $blockTimestamp, $blockExpiry, $intended) = array(User::whoIs($wgUser->blockedBy()), $wgUser->blockedFor() ? $wgUser->blockedFor() : wfMsg('blockednoreason'), $wgRequest->getIP(), $wgUser->getBlockId(), $wgLang->timeanddate(wfTimestamp(TS_MW, $wgUser->mBlock->mTimestamp), true), $wgUser->mBlock->mExpiry, $wgUser->mBlock->mAddress); $blockerLink = '[[' . $wgContLang->getNsText(NS_USER) . ":{$blockerName}|{$blockerName}]]"; if ($blockExpiry == 'infinity') { $scBlockExpiryOptions = wfMsg('ipboptions'); foreach (explode(',', $scBlockExpiryOptions) as $option) { if (strpos($option, ":") === false) { continue; } list($show, $value) = explode(":", $option); if ($value == 'infinite' || $value == 'indefinite') { $blockExpiry = $show; break; } } } else { $blockExpiry = $wgLang->timeanddate(wfTimestamp(TS_MW, $blockExpiry), true); } if ($wgUser->mBlock->mAuto) { $msg = 'autoblockedtext'; } else { $msg = 'blockedtext'; } return wfMsgExt($msg, array('parse'), $blockerLink, $reason, $ip, $blockerName, $blockid, $blockExpiry, $intended, $blockTimestamp); }
function formatValue( $field, $value ) { switch ( $field ) { case 'thumb': $opt = array( 'time' => $this->mCurrentRow->img_timestamp ); $file = RepoGroup::singleton()->getLocalRepo()->findFile( $value, $opt ); // If statement for paranoia if ( $file ) { $thumb = $file->transform( array( 'width' => 180, 'height' => 360 ) ); return $thumb->toHtml( array( 'desc-link' => true ) ); } else { return htmlspecialchars( $value ); } case 'img_timestamp': // We may want to make this a link to the "old" version when displaying old files return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) ); case 'img_name': static $imgfile = null; if ( $imgfile === null ) { $imgfile = $this->msg( 'imgfile' )->text(); } // Weird files can maybe exist? Bug 22227 $filePage = Title::makeTitleSafe( NS_FILE, $value ); if ( $filePage ) { $link = Linker::linkKnown( $filePage, htmlspecialchars( $filePage->getText() ) ); $download = Xml::element( 'a', array( 'href' => wfLocalFile( $filePage )->getURL() ), $imgfile ); $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped(); return "$link $download"; } else { return htmlspecialchars( $value ); } case 'img_user_text': if ( $this->mCurrentRow->img_user ) { $name = User::whoIs( $this->mCurrentRow->img_user ); $link = Linker::link( Title::makeTitle( NS_USER, $name ), htmlspecialchars( $name ) ); } else { $link = htmlspecialchars( $value ); } return $link; case 'img_size': return htmlspecialchars( $this->getLanguage()->formatSize( $value ) ); case 'img_description': return Linker::formatComment( $value ); case 'count': return intval( $value ) + 1; case 'top': // Messages: listfiles-latestversion-yes, listfiles-latestversion-no return $this->msg( 'listfiles-latestversion-' . $value ); } }
/** * Check that the user isn't blocked from editting. * * @param $action String the action to check * @param $user User to check * @param $errors Array list of current errors * @param $doExpensiveQueries Boolean whether or not to perform expensive queries * @param $short Boolean short circuit on first error * * @return Array list of errors */ private function checkUserBlock($action, $user, $errors, $doExpensiveQueries, $short) { // Account creation blocks handled at userlogin. // Unblocking handled in SpecialUnblock if (!$doExpensiveQueries || in_array($action, array('createaccount', 'unblock'))) { return $errors; } global $wgContLang, $wgLang, $wgEmailConfirmToEdit; if ($wgEmailConfirmToEdit && !$user->isEmailConfirmed()) { $errors[] = array('confirmedittext'); } if (($action == 'edit' || $action == 'create') && !$user->isBlockedFrom($this)) { // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. } elseif ($user->isBlocked() && $user->mBlock->prevents($action) !== false) { $block = $user->mBlock; // This is from OutputPage::blockedPage // Copied at r23888 by werdna $id = $user->blockedBy(); $reason = $user->blockedFor(); if ($reason == '') { $reason = wfMsg('blockednoreason'); } $ip = $user->getRequest()->getIP(); if (is_numeric($id)) { $name = User::whoIs($id); } else { $name = $id; } $link = '[[' . $wgContLang->getNsText(NS_USER) . ":{$name}|{$name}]]"; $blockid = $block->getId(); $blockExpiry = $user->mBlock->mExpiry; $blockTimestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $user->mBlock->mTimestamp), true); if ($blockExpiry == 'infinity') { $blockExpiry = wfMessage('infiniteblock')->text(); } else { $blockExpiry = $wgLang->timeanddate(wfTimestamp(TS_MW, $blockExpiry), true); } # Wikia change - begin # @author macbre (BAC-535) $blocker = $block->getBlocker(); if ($blocker instanceof User) { // user groups to be displayed instead of user name $groups = ['staff', 'vstf']; $blockerGroups = $blocker->getEffectiveGroups(); foreach ($groups as $group) { if (in_array($group, $blockerGroups)) { $link = wfMessage("group-{$group}")->plain(); } } } # Wikia change - end $intended = strval($user->mBlock->getTarget()); $errors[] = array($block->mAuto ? 'autoblockedtext' : 'blockedtext', $link, $reason, $ip, $name, $blockid, $blockExpiry, $intended, $blockTimestamp); } return $errors; }
/** * Normalize the input username, which may be local or remote, and * return a user (or proxy) object for manipulating it. * * Side effects: error output for invalid access * @return mixed User, UserRightsProxy, or null */ function fetchUser($username) { global $wgOut, $wgUser; $parts = explode('@', $username); if (count($parts) < 2) { $name = trim($username); $database = ''; } else { list($name, $database) = array_map('trim', $parts); if (!$wgUser->isAllowed('userrights-interwiki')) { $wgOut->addWikiMsg('userrights-no-interwiki'); return null; } if (!UserRightsProxy::validDatabase($database)) { $wgOut->addWikiMsg('userrights-nodatabase', $database); return null; } } if ($name == '') { $wgOut->addWikiMsg('nouserspecified'); return false; } if ($name[0] == '#') { // Numeric ID can be specified... // We'll do a lookup for the name internally. $id = intval(substr($name, 1)); if ($database == '') { $name = User::whoIs($id); } else { $name = UserRightsProxy::whoIs($database, $id); } if (!$name) { $wgOut->addWikiMsg('noname'); return null; } } if ($database == '') { $user = User::newFromName($name); } else { $user = UserRightsProxy::newFromName($database, $name); } if (!$user || $user->isAnon()) { $wgOut->addWikiMsg('nosuchusershort', $username); return null; } return $user; }
/** * Fetch revision's username if it's available to the specified audience. * If the specified audience does not have access to the username, an * empty string will be returned. * * @param int $audience One of: * Revision::FOR_PUBLIC to be displayed to all users * Revision::FOR_THIS_USER to be displayed to the given user * Revision::RAW get the text regardless of permissions * @param User $user User object to check for, only if FOR_THIS_USER is passed * to the $audience parameter * @return string */ public function getUserText($audience = self::FOR_PUBLIC, User $user = null) { if ($audience == self::FOR_PUBLIC && $this->isDeleted(self::DELETED_USER)) { return ''; } elseif ($audience == self::FOR_THIS_USER && !$this->userCan(self::DELETED_USER, $user)) { return ''; } else { if ($this->mUserText === null) { $this->mUserText = User::whoIs($this->mUser); // load on demand if ($this->mUserText === false) { # This shouldn't happen, but it can if the wiki was recovered # via importing revs and there is no user table entry yet. $this->mUserText = $this->mOrigUserText; } } return $this->mUserText; } }
/** * Check action permissions not already checked in checkQuickPermissions * * @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 checkActionPermissions($action, $user, $errors, $rigor, $short) { global $wgDeleteRevisionsLimit, $wgLang; if ($action == 'protect') { if (count($this->getUserPermissionsErrorsInternal('edit', $user, $rigor, true))) { // If they can't edit, they shouldn't protect. $errors[] = array('protect-cantedit'); } } elseif ($action == 'create') { $title_protection = $this->getTitleProtection(); if ($title_protection) { if ($title_protection['permission'] == '' || !$user->isAllowed($title_protection['permission'])) { $errors[] = array('titleprotected', User::whoIs($title_protection['user']), $title_protection['reason']); } } } elseif ($action == 'move') { // Check for immobile pages if (!MWNamespace::isMovable($this->mNamespace)) { // Specific message for this case $errors[] = array('immobile-source-namespace', $this->getNsText()); } elseif (!$this->isMovable()) { // Less specific message for rarer cases $errors[] = array('immobile-source-page'); } } elseif ($action == 'move-target') { if (!MWNamespace::isMovable($this->mNamespace)) { $errors[] = array('immobile-target-namespace', $this->getNsText()); } elseif (!$this->isMovable()) { $errors[] = array('immobile-target-page'); } } elseif ($action == 'delete') { $tempErrors = $this->checkPageRestrictions('edit', $user, array(), $rigor, true); if (!$tempErrors) { $tempErrors = $this->checkCascadingSourcesRestrictions('edit', $user, $tempErrors, $rigor, true); } if ($tempErrors) { // If protection keeps them from editing, they shouldn't be able to delete. $errors[] = array('deleteprotected'); } if ($rigor !== 'quick' && $wgDeleteRevisionsLimit && !$this->userCan('bigdelete', $user) && $this->isBigDeletion()) { $errors[] = array('delete-toobig', $wgLang->formatNum($wgDeleteRevisionsLimit)); } } return $errors; }
function getTests() { global $wgRequest; $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('tipspatrol_test', '*', '', __METHOD__, array("ORDER BY" => "tpt_id DESC")); $tests = array(); while ($row = $dbr->fetchObject($res)) { $test = get_object_vars($row); $t = Title::newFromID($row->tpt_page_id); $test['page'] = (string) $t; $test['user'] = User::whoIs($row->tpt_user_id); if ($row->tpt_difficulty == TipsPatrol::TPC_DIFFICULTY_EASY) { $test['difficulty'] = "Easy"; } if ($row->tpt_answer == TipsPatrol::TIP_ACTION_DELETE) { $test['answer'] = "Delete"; } else { if ($row->tpt_answer == TipsPatrol::TIP_ACTION_KEEP) { $test['answer'] = "Keep"; } else { if ($row->tpt_answer == TipsPatrol::TIP_ACTION_SKIP) { $test['answer'] = "Skip"; } } } $tests[$test['tpt_id']] = $test; } return $tests; }