本文整理汇总了PHP中SiteStatsUpdate::doUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteStatsUpdate::doUpdate方法的具体用法?PHP SiteStatsUpdate::doUpdate怎么用?PHP SiteStatsUpdate::doUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteStatsUpdate
的用法示例。
在下文中一共展示了SiteStatsUpdate::doUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMessengerUser
/**
* Sets up the messenger account for our use if it hasn't been already.
* Based on code from AbuseFilter
* https://mediawiki.org/wiki/Extension:AbuseFilter
*
* @return User
*/
public static function getMessengerUser()
{
global $wgMassMessageAccountUsername;
// Function kinda copied from the AbuseFilter
$user = User::newFromName($wgMassMessageAccountUsername);
$user->load();
if ($user->getId() && $user->mPassword == '') {
// We've already stolen the account
return $user;
}
if (!$user->getId()) {
$user->addToDatabase();
$user->saveSettings();
// Increment site_stats.ss_users
$ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssu->doUpdate();
} else {
// Someone already created the account, lets take it over.
$user->setPassword(null);
$user->setEmail(null);
$user->saveSettings();
}
// Make the user a bot so it doesn't look weird
$user->addGroup('bot');
return $user;
}
示例2: execute
public function execute()
{
if (!class_exists('CentralAuthUser')) {
$this->error("CentralAuth isn't enabled on this wiki\n", 1);
}
$username = $this->getArg(0);
$user = User::newFromName($username);
if ($user === false) {
$this->error("'{$username}' is an invalid username\n", 1);
}
// Normalize username
$username = $user->getName();
if ($user->getId()) {
$this->error("User '{$username}' already exists\n", 1);
} else {
global $wgAuth;
$central = CentralAuthUser::getInstance($user);
if (!$central->exists()) {
$this->error("No such global user: '{$username}'\n", 1);
}
$user->loadDefaults($username);
$user->addToDatabase();
$wgAuth->initUser($user, true);
$wgAuth->updateUser($user);
# Notify hooks (e.g. Newuserlog)
Hooks::run('AuthPluginAutoCreate', array($user));
# Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
$this->output("User '{$username}' created\n");
}
}
示例3: go_auth
function go_auth()
{
global $wgUser, $wgLanguageCode, $wgRequest, $wgOut;
// For a few special pages, don't do anything.
$title = $wgRequest->getVal('title');
$lg = Language::factory($wgLanguageCode);
if ($title == $lg->specialPage("Userlogout") || $title == $lg->specialPage("Userlogin")) {
return true;
}
$data = go_getsession();
if ($wgUser->IsAnon() || $data && $wgUser->getName() != $data['username']) {
if (isset($data['user_id'])) {
$wgUser = User::newFromName($data['username']);
// Create a new account if the user does not exists
if ($wgUser->getID() == 0) {
// Create the user
$wgUser->addToDatabase();
$wgUser->setRealName($data['username']);
//$wgUser->setEmail($data['GO_SESSION']['email']);
$wgUser->setPassword(md5($data['username'] . 'zout'));
// do something random
$wgUser->setToken();
$wgUser->saveSettings();
// Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
}
$wgUser->setOption("rememberpassword", 1);
$wgUser->setCookies();
$wgOut->returnToMain();
}
}
return true;
}
示例4: execute
public function execute()
{
$username = $this->getArg(0);
$password = $this->getArg(1);
$this->output(wfWikiID() . ": Creating and promoting User:{$username}...");
$user = User::newFromName($username);
if (!is_object($user)) {
$this->error("invalid username.", true);
} elseif (0 != $user->idForName()) {
$this->error("account exists.", true);
}
# Try to set the password
try {
$user->setPassword($password);
} catch (PasswordError $pwe) {
$this->error($pwe->getText(), true);
}
# Insert the account into the database
$user->addToDatabase();
$user->saveSettings();
# Promote user
if ($this->hasOption('sysop')) {
$user->addGroup('sysop');
}
if ($this->hasOption('bureaucrat')) {
$user->addGroup('bureaucrat');
}
# Increment site_stats.ss_users
$ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssu->doUpdate();
$this->output("done.\n");
}
示例5: execute
public function execute()
{
$name = $this->getArg();
$delete = $this->getOption('delete', false);
$ns = $this->getOption('ns', NS_MAIN);
$dbw = wfGetDB(DB_MASTER);
$dbw->begin();
$tbl_pag = $dbw->tableName('page');
$tbl_rec = $dbw->tableName('recentchanges');
$tbl_rev = $dbw->tableName('revision');
# Get page ID
$this->output("Searching for \"{$name}\"...");
$title = Title::newFromText($name, $ns);
if ($title) {
$id = $title->getArticleID();
$real = $title->getPrefixedText();
$isGoodArticle = $title->isContentPage();
$this->output("found \"{$real}\" with ID {$id}.\n");
# Get corresponding revisions
$this->output("Searching for revisions...");
$res = $dbw->query("SELECT rev_id FROM {$tbl_rev} WHERE rev_page = {$id}");
$revs = array();
foreach ($res as $row) {
$revs[] = $row->rev_id;
}
$count = count($revs);
$this->output("found {$count}.\n");
# Delete the page record and associated recent changes entries
if ($delete) {
$this->output("Deleting page record...");
$dbw->query("DELETE FROM {$tbl_pag} WHERE page_id = {$id}");
$this->output("done.\n");
$this->output("Cleaning up recent changes...");
$dbw->query("DELETE FROM {$tbl_rec} WHERE rc_cur_id = {$id}");
$this->output("done.\n");
}
$dbw->commit();
# Delete revisions as appropriate
if ($delete && $count) {
$this->output("Deleting revisions...");
$this->deleteRevisions($revs);
$this->output("done.\n");
$this->purgeRedundantText(true);
}
# Update stats as appropriate
if ($delete) {
$this->output("Updating site stats...");
$ga = $isGoodArticle ? -1 : 0;
// if it was good, decrement that too
$stats = new SiteStatsUpdate(0, -$count, $ga, -1);
$stats->doUpdate();
$this->output("done.\n");
}
} else {
$this->output("not found in database.\n");
$dbw->commit();
}
}
示例6: wfSpecialStatistics
/**
* constructor
*/
function wfSpecialStatistics()
{
global $wgUser, $wgOut, $wgLang, $wgRequest;
$fname = 'wfSpecialStatistics';
$action = $wgRequest->getVal('action');
$dbr =& wfGetDB(DB_SLAVE);
extract($dbr->tableNames('page', 'site_stats', 'user', 'user_groups'));
$row = $dbr->selectRow('site_stats', '*', false, $fname);
$views = $row->ss_total_views;
$edits = $row->ss_total_edits;
$good = $row->ss_good_articles;
# This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
if (isset($row->ss_total_pages) && $row->ss_total_pages == -1) {
# Update schema
$u = new SiteStatsUpdate(0, 0, 0);
$u->doUpdate();
$row = $dbr->selectRow('site_stats', '*', false, $fname);
}
if (isset($row->ss_total_pages)) {
$total = $row->ss_total_pages;
} else {
$sql = "SELECT COUNT(page_namespace) AS total FROM {$page}";
$res = $dbr->query($sql, $fname);
$pageRow = $dbr->fetchObject($res);
$total = $pageRow->total;
}
if (isset($row->ss_users)) {
$users = $row->ss_users;
} else {
$sql = "SELECT MAX(user_id) AS total FROM {$user}";
$res = $dbr->query($sql, $fname);
$userRow = $dbr->fetchObject($res);
$users = $userRow->total;
}
$sql = "SELECT COUNT(*) AS total FROM {$user_groups} WHERE ug_group='sysop'";
$res = $dbr->query($sql, $fname);
$row = $dbr->fetchObject($res);
$admins = $row->total;
if ($action == 'raw') {
$wgOut->disable();
header('Pragma: nocache');
echo "total={$total};good={$good};views={$views};edits={$edits};users={$users};admins={$admins}\n";
return;
} else {
$text = '==' . wfMsg('sitestats') . "==\n";
$text .= wfMsg('sitestatstext', $wgLang->formatNum($total), $wgLang->formatNum($good), $wgLang->formatNum($views), $wgLang->formatNum($edits), $wgLang->formatNum(sprintf('%.2f', $total ? $edits / $total : 0)), $wgLang->formatNum(sprintf('%.2f', $edits ? $views / $edits : 0)));
$text .= "\n==" . wfMsg('userstats') . "==\n";
$text .= wfMsg('userstatstext', $wgLang->formatNum($users), $wgLang->formatNum($admins), '[[' . wfMsg('administrators') . ']]', $wgLang->formatNum(sprintf('%.2f', $admins / $users * 100)));
$wgOut->addWikiText($text);
}
}
示例7: onOpauthUserAuthorized
public static function onOpauthUserAuthorized($provider, $uid, $info, $raw)
{
global $wgUser, $wgOut;
// Called when user was successfully authenticated from Opauth
// This function should compare UID with internal storage and decide to create new account for this user
// or load existing user from database
if (OpauthLogin::isUidLinked($uid, $provider)) {
// Login existing user into system
$user = OpauthLogin::getUidUser($uid, $provider);
wfRunHooks('OpauthLoginUserAuthorized', array($user, $provider, $uid, $info));
} else {
// Create new user from external data, $info refers to https://github.com/opauth/opauth/wiki/Auth-response
/**
* We set UID based string as user name in mediawiki to avoid
* user nicknames override and collisions problems. We store external user name into
* "real name" field of user object. This should be supported in skin.
*/
$user = User::newFromName(md5($provider . $uid) . '_' . $uid, false);
$user->setRealName($info['name']);
if (array_key_exists('email', $info)) {
if (!OpauthLogin::isEmailCollate($info['email'])) {
$user->setEmail($info['email']);
}
}
$user->setPassword(md5($info['name'] . time()));
$user->setToken();
$user->confirmEmail();
// Mark email address as confirmed by default
$user->addToDatabase();
// Commit changes to database
OpauthLogin::addUidLink($uid, $provider, $user->getId());
// Update site stats
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
// Run AddNewAccount hook for proper handling
wfRunHooks('AddNewAccount', array($user, false));
wfRunHooks('OpauthLoginUserCreated', array($user, $provider, $info, $uid));
}
// Replace current user with new one
$wgUser = $user;
$wgUser->setCookies(null, null, true);
if (array_key_exists('opauth_returnto', $_SESSION) && isset($_SESSION['opauth_returnto'])) {
$returnToTitle = Title::newFromText($_SESSION['opauth_returnto']);
unset($_SESSION['opauth_returnto']);
$wgOut->redirect($returnToTitle->getFullURL());
return true;
}
$wgOut->redirect(Title::newMainPage()->getFullURL());
return true;
}
示例8: load
static function load($recache = false)
{
if (self::$loaded && !$recache) {
return;
}
$dbr =& wfGetDB(DB_SLAVE);
self::$row = $dbr->selectRow('site_stats', '*', false, __METHOD__);
# This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
if (!isset(self::$row->ss_total_pages) && self::$row->ss_total_pages == -1) {
# Update schema
$u = new SiteStatsUpdate(0, 0, 0);
$u->doUpdate();
self::$row = $dbr->selectRow('site_stats', '*', false, __METHOD__);
}
}
示例9: load
/**
* @param $recache bool
*/
static function load($recache = false)
{
if (self::$loaded && !$recache) {
return;
}
self::$row = self::loadAndLazyInit();
# This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
if (!isset(self::$row->ss_total_pages) && self::$row->ss_total_pages == -1) {
# Update schema
$u = new SiteStatsUpdate(0, 0, 0);
$u->doUpdate();
self::$row = self::doLoad(wfGetDB(DB_SLAVE));
}
self::$loaded = true;
}
示例10: attemptAddUser
/**
* @param $user User
* @param $mungedUsername String
* @return bool
*/
public static function attemptAddUser($user, $mungedUsername)
{
/**
* @var $wgAuth LdapAuthenticationPlugin
*/
global $wgAuth;
if (!$wgAuth->autoCreate()) {
$wgAuth->printDebug("Cannot automatically create accounts.", NONSENSITIVE);
return false;
}
$wgAuth->printDebug("User does not exist in local database; creating.", NONSENSITIVE);
// Checks passed, create the user
$user->loadDefaults($mungedUsername);
$user->addToDatabase();
$wgAuth->initUser($user, true);
$user->setCookies();
wfSetupSession();
# Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
# Notify hooks (e.g. Newuserlog)
wfRunHooks('AuthPluginAutoCreate', array($user));
return true;
}
示例11: initUser
/**
* Actually add a user to the database.
* Give it a User object that has been initialised with a name.
*
* This is a custom version of similar code in SpecialUserLogin's LoginForm with differences
* due to the fact that this code doesn't require a password, etc.
*
* @param $u User object.
* @param $autocreate boolean -- true if this is an autocreation via auth plugin
* @return User object.
* @private
*/
function initUser($u, $autocreate)
{
global $wgAuth, $wgExternalAuthType;
if ($wgExternalAuthType) {
$u = ExternalUser::addUser($u, $this->mPassword, $this->mEmail, $this->mRealName);
if (is_object($u)) {
$this->mExtUser = ExternalUser::newFromName($this->mName);
}
} else {
$u->addToDatabase();
}
// No passwords for FBConnect accounts
//if ( $wgAuth->allowPasswordChange() ) {
// $u->setPassword( $this->mPassword );
//}
$u->setEmail($this->mEmail);
$u->setRealName($this->mRealName);
$u->setToken();
$wgAuth->initUser($u, $autocreate);
if (is_object($this->mExtUser)) {
$this->mExtUser->linkToLocal($u->getId());
$email = $this->mExtUser->getPref('emailaddress');
if ($email && !$this->mEmail) {
$u->setEmail($email);
}
}
//$u->setOption( 'rememberpassword', $this->mRemember ? 1 : 0 );
$u->setOption('marketingallowed', $this->mMarketingOptIn ? 1 : 0);
$u->setOption('skinoverwrite', 1);
$u->saveSettings();
# Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
return $u;
}
示例12: userSignup
private function userSignup() {
// Get user input and check the environment
$this->mUserDataChecker->run();
// Throw if data getting or environment checks have failed which indicates that account creation is impossible
$checker_error = $this->mUserDataChecker->getError();
if ( $checker_error ) {
throw new Exception( $checker_error );
}
$user = $this->mUserDataChecker->mUser;
$user->setEmail( $this->mUserDataChecker->mEmail );
$user->setRealName( $this->mUserDataChecker->mRealname );
$abortError = '';
if ( !wfRunHooks( 'AbortNewAccount', array( $user, &$abortError ) ) ) {
// Hook point to add extra creation throttles and blocks
wfDebug( "LoginForm::addNewAccountInternal: a hook blocked creation\n" );
throw new Exception( $abortError );
}
global $wgAccountCreationThrottle;
global $wgUser, $wgRequest;
if ( $wgAccountCreationThrottle && $wgUser->isPingLimitable() ) {
$key = wfMemcKey( 'acctcreate', 'ip', $wgRequest->getIP() );
$value = $wgMemc->incr( $key );
if ( !$value ) {
$wgMemc->set( $key, 1, 86400 );
}
if ( $value > $wgAccountCreationThrottle ) {
throw new Exception( wfMsg( 'ses-throttlehit' ) );
}
}
global $wgAuth;
$addedUser = $wgAuth->addUser(
$user,
$this->mUserDataChecker->mPassword,
$this->mUserDataChecker->mEmail,
$this->mUserDataChecker->mRealname
);
if ( !$addedUser ) {
throw new Exception( 'externaldberror' );
}
$user->addToDatabase();
if ( $wgAuth->allowPasswordChange() ) {
$user->setPassword( $this->mUserDataChecker->mPassword );
}
$user->setToken();
$wgAuth->initUser( $user, false );
$user->setOption( 'rememberpassword', $this->mUserDataChecker->mRemember ? 1 : 0 );
$user->saveSettings();
# Update user count
$ssUpdate = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssUpdate->doUpdate();
global $wgLoginLanguageSelector;
$language = $this->mUserDataChecker->mLanguage;
if ( $wgLoginLanguageSelector && $language ) {
$user->setOption( 'language', $language );
}
global $wgEmailAuthentication;
if ( $wgEmailAuthentication && User::isValidEmailAddr( $user->getEmail() ) ) {
$status = $user->sendConfirmationMail();
if ( !$status->isGood() ) {
throw new Exception( wfMsg( 'ses-emailfailed' ) . "\n" . $status->getMessage() );
}
}
$user->saveSettings();
wfRunHooks( 'AddNewAccount', array( $user ) );
}
示例13: initUser
/**
* Actually add a user to the database.
* Give it a User object that has been initialised with a name.
*
* @param $u User object.
* @param $autocreate boolean -- true if this is an autocreation via auth plugin
* @return User object.
* @private
*/
function initUser($u, $autocreate)
{
global $wgAuth;
$u->addToDatabase();
if ($wgAuth->allowPasswordChange()) {
$u->setPassword($this->mPassword);
}
$u->setEmail($this->mEmail);
$u->setRealName($this->mRealName);
$u->setToken();
$wgAuth->initUser($u, $autocreate);
$u->setOption('rememberpassword', $this->mRemember ? 1 : 0);
$u->saveSettings();
# Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
return $u;
}
示例14: casLogin
function casLogin($user, &$result)
{
global $CASAuth;
global $casIsSetUp;
global $IP, $wgLanguageCode, $wgRequest, $wgOut;
if (isset($_REQUEST["title"])) {
$lg = Language::factory($wgLanguageCode);
if ($_REQUEST["title"] == $lg->specialPage("Userlogin")) {
// Setup for a web request
require_once "{$IP}/includes/WebStart.php";
// Load phpCAS
require_once $CASAuth["phpCAS"] . "/CAS.php";
if (!$casIsSetUp) {
return false;
}
//Will redirect to CAS server if not logged in
phpCAS::forceAuthentication();
// Get username
$username = casNameLookup(phpCAS::getUser());
$email = casEmailLookup(phpCAS::getUser());
// If we are restricting users AND the user is not in
// the allowed users list, lets block the login
if ($CASAuth["RestrictUsers"] == true && !in_array($username, $CASAuth["AllowedUsers"])) {
// redirect user to the RestrictRedirect page
$wgOut->redirect($CASAuth["RestrictRedirect"]);
return true;
}
// Get MediaWiki user
$u = User::newFromName($username);
// Create a new account if the user does not exists
if ($u->getID() == 0 && $CASAuth["CreateAccounts"]) {
// Create the user
$u->addToDatabase();
$u->setRealName($username);
$u->setEmail($email);
// PwdSecret is used to salt the username for an hmac
// hash which becomes the password
$u->setPassword(hash_hmac('sha256', $username, $CASAuth["PwdSecret"]));
$u->setToken();
$u->saveSettings();
// Update user count
$ssUpdate = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssUpdate->doUpdate();
}
// Login successful
if ($CASAuth["RememberMe"]) {
$u->setOption("rememberpassword", 1);
}
$u->setCookies();
$user = $u;
// Redirect if a returnto parameter exists
$returnto = $wgRequest->getVal("returnto");
if ($returnto) {
$target = Title::newFromText($returnto);
if ($target) {
//action=purge is used to purge the cache
$wgOut->redirect($target->getFullUrl('action=purge'));
}
}
} else {
if ($_REQUEST["title"] == $lg->specialPage("Userlogout")) {
// Logout
casLogout();
}
}
}
// Back to MediaWiki home after login
return true;
}
示例15: wfWikiID
* @author Rob Church <robchur@gmail.com>
*/
#ubuntu specific directory:
require_once '/var/www/wiki/maintenance/commandLine.inc';
if (!count($args) == 2) {
echo "Please provide a username and password for the new account.\n";
die(1);
}
$username = $args[0];
$password = $args[1];
echo wfWikiID() . ": Creating wiki User:{$username}...";
# Validate username and check it doesn't exist
$user = User::newFromName($username);
if (!is_object($user)) {
echo "invalid username.\n";
die(1);
} elseif (0 != $user->idForName()) {
echo "Wiki account exists.\n";
die(0);
}
# Insert the account into the database
$user->addToDatabase();
$user->setPassword($password);
$user->setToken();
#this may be readded as an option but probably not
# Promote user
#$user->addGroup( 'sysop' );
# Increment site_stats.ss_users
$ssu = new SiteStatsUpdate(0, 0, 0, 0, 1);
$ssu->doUpdate();
echo "done.\n";