本文整理汇总了PHP中User::getCanonicalName方法的典型用法代码示例。如果您正苦于以下问题:PHP User::getCanonicalName方法的具体用法?PHP User::getCanonicalName怎么用?PHP User::getCanonicalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类User
的用法示例。
在下文中一共展示了User::getCanonicalName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wfSpecialRestrictUser
function wfSpecialRestrictUser($par = null)
{
global $wgOut, $wgRequest;
$user = $userOrig = null;
if ($par) {
$userOrig = $par;
} elseif ($wgRequest->getVal('user')) {
$userOrig = $wgRequest->getVal('user');
} else {
$wgOut->addHTML(RestrictUserForm::selectUserForm());
return;
}
$isIP = User::isIP($userOrig);
$user = $isIP ? $userOrig : User::getCanonicalName($userOrig);
$uid = User::idFromName($user);
if (!$uid && !$isIP) {
$err = '<strong class="error">' . wfMsgHtml('restrictuser-notfound') . '</strong>';
$wgOut->addHTML(RestrictUserForm::selectUserForm($userOrig, $err));
return;
}
$wgOut->addHTML(RestrictUserForm::selectUserForm($user));
UserRestriction::purgeExpired();
$old = UserRestriction::fetchForUser($user, true);
RestrictUserForm::pageRestrictionForm($uid, $user, $old);
RestrictUserForm::namespaceRestrictionForm($uid, $user, $old);
// Renew it after possible changes in previous two functions
$old = UserRestriction::fetchForUser($user, true);
if ($old) {
$wgOut->addHTML(RestrictUserForm::existingRestrictions($old));
}
}
示例2: execute
public function execute()
{
$params = $this->extractRequestParams();
$titleObj = null;
if (!isset($params['title'])) {
$this->dieUsageMsg(array('missingparam', 'title'));
}
if (!isset($params['user'])) {
$this->dieUsageMsg(array('missingparam', 'user'));
}
$titleObj = Title::newFromText($params['title']);
if (!$titleObj) {
$this->dieUsageMsg(array('invalidtitle', $params['title']));
}
if (!$titleObj->exists()) {
$this->dieUsageMsg(array('notanarticle'));
}
// We need to be able to revert IPs, but getCanonicalName rejects them
$username = User::isIP($params['user']) ? $params['user'] : User::getCanonicalName($params['user']);
if (!$username) {
$this->dieUsageMsg(array('invaliduser', $params['user']));
}
$articleObj = new Article($titleObj);
$summary = isset($params['summary']) ? $params['summary'] : "";
$details = null;
$retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
if ($retval) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg(reset($retval));
}
$info = array('title' => $titleObj->getPrefixedText(), 'pageid' => intval($details['current']->getPage()), 'summary' => $details['summary'], 'revid' => intval($details['newid']), 'old_revid' => intval($details['current']->getID()), 'last_revid' => intval($details['target']->getID()));
$this->getResult()->addValue(null, $this->getModuleName(), $info);
}
示例3: getUserDetails
public function getUserDetails()
{
if (is_null($this->usersData)) {
$users = preg_split("/[\r\n]+/", $this->users);
foreach ($users as $k => $v) {
if (trim($v) == '') {
unset($users[$k]);
}
}
$users = array_values($users);
foreach ($users as $k => $name) {
$userName = User::isIP($name) ? $name : User::getCanonicalName($name);
$user = null;
if ($userName !== false) {
$user = F::build('User', array($userName), 'newFromName');
if (empty($user) || $user->getId() == 0) {
$user = null;
}
}
$users[$k] = array('id' => !empty($user) ? $user->getId() : 0, 'ip' => User::isIP($name) ? $name : '', 'name' => $name, 'canonical' => $userName);
}
$this->usersData = $users;
}
return $this->usersData;
}
示例4: doCreate
protected function doCreate()
{
$params = $this->extractRequestParams();
// Do validations
foreach (explode('|', 'username|password|email') as $field) {
if (!isset($params[$field])) {
$this->dieUsage("Missing parameter {$field}", 'missingparam');
}
}
$username = $params['username'];
if (User::getCanonicalName($username, 'creatable') === false) {
$this->dieUsage("User name is not acceptable", 'invalidusername');
}
$user = User::newFromName($username);
if ($user->getID() !== 0) {
$this->dieUsage("User name is in use", 'nonfreeusername');
}
$password = $params['password'];
if (!$user->isValidPassword($password)) {
$this->dieUsage("Password is not acceptable", 'invalidpassword');
}
$email = $params['email'];
if (!Sanitizer::validateEmail($email)) {
$this->dieUsage("Email is not acceptable", 'invalidemail');
}
$user = TranslateSandbox::addUser($username, $email, $password);
$output = array('user' => array('name' => $user->getName(), 'id' => $user->getId()));
$user->setOption('language', $this->getContext()->getLanguage()->getCode());
$user->saveSettings();
$this->getResult()->addValue(null, $this->getModuleName(), $output);
}
示例5: authenticate
/**
* Check if a username+password pair is a valid login.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* @param $username String: username.
* @param $password String: user password.
* @return bool
* @public
*/
function authenticate($username, $password)
{
global $wgCentralAuthAutoMigrate, $wgCentralAuthCheckSULMigration;
global $wgCentralAuthAutoMigrateNonGlobalAccounts;
global $wgCentralAuthStrict;
$central = new CentralAuthUser($username);
$passwordMatch = self::checkPassword($central, $password);
if (!$passwordMatch && $wgCentralAuthCheckSULMigration) {
// Check to see if this is a user who was affected by a global username
// collision during a forced migration to central auth accounts.
$renamedUsername = User::getCanonicalName($username . '~' . str_replace('_', '-', wfWikiID()));
if ($renamedUsername !== false) {
wfDebugLog('CentralAuth', "CentralAuthMigration: Checking for migration of '{$username}' to '{$renamedUsername}'");
$renamed = new CentralAuthUser($renamedUsername);
$passwordMatch = self::checkPassword($renamed, $password);
// Remember that the user was authenticated under a different name.
if ($passwordMatch) {
$this->sulMigrationName = $renamedUsername;
} elseif ($wgCentralAuthStrict) {
// Will also create log entry
$this->checkAttached($central, $username);
}
// Since we are falling back to check a force migrated user, we are done
// regardless of password match status. We don't want to try to
// automigrate or check detached accounts.
return $passwordMatch;
}
}
if (!$central->exists()) {
wfDebugLog('CentralAuth', "plugin: no global account for '{$username}'");
// See if all the unattached accounts match passwords
// and can be globalized. (bug 70392)
if ($wgCentralAuthAutoMigrateNonGlobalAccounts) {
$ok = $central->storeAndMigrate(array($password), true, true, true);
if ($ok) {
wfDebugLog('CentralAuth', "wgCentralAuthAutoMigrateNonGlobalAccounts successful in creating a global account for '{$username}'");
return true;
}
}
return false;
}
if ($passwordMatch && $wgCentralAuthAutoMigrate) {
// If the user passed in the global password, we can identify
// any remaining local accounts with a matching password
// and migrate them in transparently.
//
// That may or may not include the current wiki.
//
wfDebugLog('CentralAuth', "plugin: attempting wgCentralAuthAutoMigrate for '{$username}'");
$central->attemptPasswordMigration($password);
}
// Will also create log entry
if ($this->checkAttached($central, $username) === false) {
return false;
}
return $passwordMatch;
}
示例6: initFromName
protected function initFromName($name)
{
wfDebug(__METHOD__ . ": init User from name: {$name} \n");
$name = User::getCanonicalName($name, 'usable');
if (!is_string($name)) {
return false;
}
return $this->initFromCond(array('user_name' => $name));
}
示例7: onSubmit
function onSubmit(array $data)
{
if (!isset($data['username'])) {
$this->showCurrentRenames();
return false;
}
$name = User::getCanonicalName($data['username'], 'usable');
if (!$name) {
$this->showCurrentRenames();
return false;
}
$out = $this->getOutput();
$this->renameuserStatus = new GlobalRenameUserStatus($name);
$names = $this->renameuserStatus->getNames();
if (!$names) {
$this->checkCachePurge($name);
$out->addWikiMsg('centralauth-rename-notinprogress', $name);
$this->getForm()->displayForm(false);
$this->showLogExtract($name);
return true;
}
list($oldName, $newName) = $names;
$statuses = $this->renameuserStatus->getStatuses();
$this->getForm()->displayForm(false);
// $newname will always be defined since we check
// for 0 result rows above
$caUser = new CentralAuthUser($newName);
$attached = $caUser->listAttached();
foreach ($attached as $wiki) {
// If it's not in the db table, and there is
// an attached acount, assume it's done.
if (!isset($statuses[$wiki])) {
$statuses[$wiki] = 'done';
}
}
ksort($statuses);
$table = Html::openElement('table', array('class' => 'wikitable sortable'));
$table .= Html::openElement('tr');
$table .= Html::element('th', array(), $this->msg('centralauth-rename-table-domain')->text());
$table .= Html::element('th', array(), $this->msg('centralauth-rename-table-status')->text());
$table .= Html::closeElement('tr');
foreach ($statuses as $wiki => $status) {
$table .= Html::openElement('tr');
$table .= Html::element('td', array(), WikiMap::getWiki($wiki)->getDisplayName());
// Messages used: centralauth-rename-table-status-inprogress
// centralauth-rename-table-status-queued, centralauth-rename-table-status-done
$table .= Html::rawElement('td', array(), $this->msg("centralauth-rename-table-status-{$status}")->parse());
$table .= Html::closeElement('tr');
}
$table .= Html::closeElement('table');
$fieldset = Xml::fieldset($this->msg('centralauth-rename-progress-fieldset')->text(), $table);
$this->showLogExtract($newName);
$out->addHTML($fieldset);
return true;
}
示例8: execute
public function execute()
{
global $wgUser, $wgSharedDB;
if ($this->getOption('onlyshared', false) && empty($wgSharedDB)) {
$this->output("Skipping wiki due to non-shared users database\n");
return;
}
$wgUser = User::newFromName(self::USER_NAME);
$bot = true;
$time = $this->getOption('time');
$time = wfTimestamp(TS_UNIX, $time);
if (!$time) {
$this->error('Invalid time', true);
}
$time = wfTimestamp(TS_MW, $time);
$users = explode('|', $this->getOption('users'));
foreach ($users as $user) {
$username = User::isIP($user) ? $user : User::getCanonicalName($user);
if (!$username) {
$this->error('Invalid username', true);
}
}
$summary = $this->getOption('summary', 'mass rollback');
$titles = array();
$results = array();
if ($this->hasOption('titles')) {
foreach (explode('|', $this->getOption('titles')) as $title) {
$t = Title::newFromText($title);
if (!$t) {
$this->error('Invalid title, ' . $title);
} else {
$titles[] = $t;
}
}
} else {
$titles = $this->getRollbackTitles($users, $time);
}
if (!$titles) {
$this->output("No suitable titles to be rolled back\n");
return;
}
$this->output("Found " . count($titles) . " title(s) to process\n");
global $wgTitle;
foreach ($titles as $t) {
$wgTitle = $t;
$this->output('Processing ' . $t->getPrefixedText() . '...');
$messages = '';
$status = $this->rollbackTitle($t, $users, $time, $summary, $messages);
if ($status) {
$this->output("done ({$messages})\n");
} else {
$this->output("failed ({$messages})\n");
}
}
}
示例9: initFromName
/**
* @param $name string
* @return bool
*/
protected function initFromName($name)
{
# We might not need the 'usable' bit, but let's be safe. Theoretically
# this might return wrong results for old versions, but it's probably
# good enough.
$name = User::getCanonicalName($name, 'usable');
if (!is_string($name)) {
return false;
}
return $this->initFromCond(array('user_name' => $name));
}
示例10: execute
public function execute()
{
global $wgUser;
$this->getMain()->requestWriteMode();
$params = $this->extractRequestParams();
$titleObj = NULL;
if (!isset($params['title'])) {
$this->dieUsageMsg(array('missingparam', 'title'));
}
if (!isset($params['user'])) {
$this->dieUsageMsg(array('missingparam', 'user'));
}
if (!isset($params['token'])) {
$this->dieUsageMsg(array('missingparam', 'token'));
}
$titleObj = Title::newFromText($params['title']);
if (!$titleObj) {
$this->dieUsageMsg(array('invalidtitle', $params['title']));
}
if (!$titleObj->exists()) {
$this->dieUsageMsg(array('notanarticle'));
}
$username = User::getCanonicalName($params['user']);
if (!$username) {
$this->dieUsageMsg(array('invaliduser', $params['user']));
}
$articleObj = new Article($titleObj);
$summary = isset($params['summary']) ? $params['summary'] : "";
$details = null;
$dbw = wfGetDb(DB_MASTER);
$dbw->begin();
$retval = $articleObj->doRollback($username, $summary, $params['token'], $params['markbot'], $details);
if (!empty($retval)) {
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg(current($retval));
}
$dbw->commit();
$current = $target = $summary = NULL;
extract($details);
$info = array('title' => $titleObj->getPrefixedText(), 'pageid' => $current->getPage(), 'summary' => $summary, 'revid' => $titleObj->getLatestRevID(), 'old_revid' => $current->getID(), 'last_revid' => $target->getID());
$this->getResult()->addValue(null, $this->getModuleName(), $info);
}
示例11: show
function show()
{
$out = $this->getOutput();
$filter = $this->mFilter;
if ($filter) {
$out->setPageTitle($this->msg('abusefilter-history', $filter));
} else {
$out->setPageTitle($this->msg('abusefilter-filter-log'));
}
# Check perms
if ($filter && !$this->getUser()->isAllowed('abusefilter-modify') && AbuseFilter::filterHidden($filter)) {
$out->addWikiMsg('abusefilter-history-error-hidden');
return;
}
# Useful links
$links = array();
if ($filter) {
$links['abusefilter-history-backedit'] = $this->getTitle($filter);
}
foreach ($links as $msg => $title) {
$links[$msg] = Linker::link($title, $this->msg($msg)->parse());
}
$backlinks = $this->getLanguage()->pipeList($links);
$out->addHTML(Xml::tags('p', null, $backlinks));
# For user
$user = User::getCanonicalName($this->getRequest()->getText('user'), 'valid');
if ($user) {
$out->addSubtitle($this->msg('abusefilter-history-foruser', Linker::userLink(1, $user), $user)->text());
}
// Add filtering of changes et al.
$fields['abusefilter-history-select-user'] = Xml::input('user', 45, $user);
$filterForm = Xml::buildForm($fields, 'abusefilter-history-select-submit');
$filterForm .= "\n" . Html::hidden('title', $this->getTitle("history/{$filter}"));
$filterForm = Xml::tags('form', array('action' => $this->getTitle("history/{$filter}")->getLocalURL(), 'method' => 'get'), $filterForm);
$filterForm = Xml::fieldset($this->msg('abusefilter-history-select-legend')->text(), $filterForm);
$out->addHTML($filterForm);
$pager = new AbuseFilterHistoryPager($filter, $this, $user);
$table = $pager->getBody();
$out->addHTML($pager->getNavigationBar() . $table . $pager->getNavigationBar());
}
示例12: execute
public function execute()
{
$user = $this->getOption('user');
$username = User::isIP($user) ? $user : User::getCanonicalName($user);
if (!$username) {
$this->error('Invalid username', true);
}
$bot = $this->hasOption('bot');
$summary = $this->getOption('summary', $this->mSelf . ' mass rollback');
$titles = array();
$results = array();
if ($this->hasOption('titles')) {
foreach (explode('|', $this->getOption('titles')) as $title) {
$t = Title::newFromText($title);
if (!$t) {
$this->error('Invalid title, ' . $title);
} else {
$titles[] = $t;
}
}
} else {
$titles = $this->getRollbackTitles($user);
}
if (!$titles) {
$this->output('No suitable titles to be rolled back');
return;
}
$doer = User::newFromName('Maintenance script');
foreach ($titles as $t) {
$page = WikiPage::factory($t);
$this->output('Processing ' . $t->getPrefixedText() . '... ');
if (!$page->commitRollback($user, $summary, $bot, $results, $doer)) {
$this->output("done\n");
} else {
$this->output("failed\n");
}
}
}
示例13: rename
protected function rename($row, DatabaseBase $dbw)
{
$wiki = $row->utr_wiki;
$name = $row->utr_name;
$newNamePrefix = User::getCanonicalName($name . '~' . str_replace('_', '-', $wiki), 'usable');
if (!$newNamePrefix) {
$this->log("ERROR: New name '{$name}~{$wiki}' is not valid");
return;
}
$this->log("Beginning rename of {$newNamePrefix}");
$newCAUser = new CentralAuthUser($newNamePrefix);
$count = 0;
// Edge case: Someone created User:Foo~wiki manually.
// So just start appending numbers to the end of the name
// until we get one that isn't used.
while ($newCAUser->exists()) {
$count++;
$newCAUser = new CentralAuthUser($newNamePrefix . (string) $count);
}
if ($newNamePrefix !== $newCAUser->getName()) {
$this->log("WARNING: New name is now {$newCAUser->getName()}");
}
$this->log("Renaming {$name} to {$newCAUser->getName()}.");
$statuses = new GlobalRenameUserStatus($name);
$success = $statuses->setStatuses(array(array('ru_wiki' => $wiki, 'ru_oldname' => $name, 'ru_newname' => $newCAUser->getName(), 'ru_status' => 'queued')));
if (!$success) {
$this->log("WARNING: Race condition, renameuser_status already set for {$newCAUser->getName()}. Skipping.");
return;
}
$this->log("Set renameuser_status for {$newCAUser->getName()}.");
$job = new LocalRenameUserJob(Title::newFromText('Global rename job'), array('from' => $name, 'to' => $newCAUser->getName(), 'renamer' => 'Maintenance script', 'movepages' => true, 'suppressredirects' => true, 'promotetoglobal' => true, 'reason' => $this->getOption('reason')));
JobQueueGroup::singleton($row->utr_wiki)->push($job);
$this->log("Submitted job for {$newCAUser->getName()}.");
$updates = new UsersToRenameDatabaseUpdates($dbw);
$updates->markRenamed($row->utr_name, $row->utr_wiki);
}
示例14: clearLoginThrottle
/**
* @deprecated since 1.27 - don't use LoginForm, use AuthManager instead
*/
public static function clearLoginThrottle($username)
{
wfDeprecated(__METHOD__, "1.27");
global $wgRequest;
$username = User::getCanonicalName($username, 'usable') ?: $username;
$throttler = new Throttler();
return $throttler->clear($username, $wgRequest->getIP());
}
示例15: prepareUsername
/**
* Validate the 'user' parameter and set the value to compare
* against `revision`.`rev_user_text`
*
* @param $user string
*/
private function prepareUsername($user)
{
if (!is_null($user) && $user !== '') {
$name = User::isIP($user) ? $user : User::getCanonicalName($user, 'valid');
if ($name === false) {
$this->dieUsage("User name {$user} is not valid", 'param_user');
} else {
$this->usernames[] = $name;
}
} else {
$this->dieUsage('User parameter may not be empty', 'param_user');
}
}