Asher has submitted this change and it was merged.
Change subject: Adding aa_method field to track login method.
......................................................................
Adding aa_method field to track login method.
Change-Id: I823c873da8670ee158eee0b00759e2df8d5ef5b2
---
M AccountAudit.body.php
M AccountAudit.hooks.php
M accountaudit.sql
A patches/add_method.sql
4 files changed, 32 insertions(+), 11 deletions(-)
Approvals:
Asher: Verified; Looks good to me, approved
diff --git a/AccountAudit.body.php b/AccountAudit.body.php
index 4fe05b6..8ce14f2 100644
--- a/AccountAudit.body.php
+++ b/AccountAudit.body.php
@@ -2,6 +2,9 @@
class AccountAudit {
+ const ACCESS_METHOD_DEFAULT = 0;
+ const ACCESS_METHOD_MOBILE = 1;
+
/**
* Updates the aa_lastlogin value for the specified user
*
@@ -19,12 +22,18 @@
$db = wfGetDB( DB_MASTER );
$method = __METHOD__;
- $db->onTransactionIdle( function() use ( $user, $now, $db,
$method ) {
+ $requestMethod = self::ACCESS_METHOD_DEFAULT;
+ if ( class_exists( "MobileContext" ) &&
MobileContext::singleton()->shouldDisplayMobileView() ) {
+ $requestMethod = self::ACCESS_METHOD_MOBILE;
+ }
+
+ $db->onTransactionIdle( function() use ( $user, $requestMethod,
$now, $db, $method ) {
if ( $db->getType() === 'mysql' ) { // MySQL-specific
implementation
$db->query(
"INSERT INTO " . $db->tableName(
'accountaudit_login' ) .
- "( aa_user, aa_lastlogin )
VALUES (" .
+ "( aa_user, aa_method,
aa_lastlogin ) VALUES (" .
$db->addQuotes( $user->getId()
) . ", " .
+ $db->addQuotes( $requestMethod
) . ", " .
$db->addQuotes( $db->timestamp(
$now ) ) .
") ON DUPLICATE KEY UPDATE
aa_lastlogin = " .
$db->addQuotes( $db->timestamp(
$now ) ),
@@ -34,13 +43,17 @@
$db->update(
'accountaudit_login',
array( 'aa_lastlogin' =>
$db->timestamp( $now ) ),
- array( 'aa_user' => $user->getId() ),
+ array( 'aa_user' => $user->getId(),
'aa_method' => $requestMethod ),
$method
);
- if ( $db->affectedRows() == 0 ) { // no row
existed for that user
+ if ( $db->affectedRows() == 0 ) { // no row
existed for that user, method
$db->insert(
'accountaudit_login',
- array( 'aa_user' =>
$user->getId(), 'aa_lastlogin' => $db->timestamp( $now ) ),
+ array(
+ 'aa_user' =>
$user->getId(),
+ 'aa_method' =>
$requestMethod,
+ 'aa_lastlogin' =>
$db->timestamp( $now )
+ ),
$method,
array( 'IGNORE', )
);
diff --git a/AccountAudit.hooks.php b/AccountAudit.hooks.php
index 8867a60..a625e9c 100644
--- a/AccountAudit.hooks.php
+++ b/AccountAudit.hooks.php
@@ -31,8 +31,9 @@
* @return bool
*/
static function loadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
- $updater->addExtensionTable( 'accountaudit_login',
- __DIR__ . '/accountaudit.sql', true );
+ $updater->addExtensionTable( 'accountaudit_login', __DIR__ .
'/accountaudit.sql' );
+ $updater->addExtensionField( 'accountaudit_login', 'aa_method',
+ __DIR__ . '/patches/add_method.sql' );
return true;
}
}
\ No newline at end of file
diff --git a/accountaudit.sql b/accountaudit.sql
index f228ffc..ef309c9 100644
--- a/accountaudit.sql
+++ b/accountaudit.sql
@@ -4,10 +4,12 @@
--
CREATE TABLE /*$wgDBprefix*/accountaudit_login (
-- Key to user_id
- aa_user int unsigned NOT NULL PRIMARY KEY,
+ aa_user int unsigned NOT NULL,
+ aa_method tinyint unsigned NOT NULL DEFAULT 0,
-- This is a timestamp which is updated when a user logs in
- aa_lastlogin varbinary(14) default null
-) /*$wgDBTableOptions*/;
+ aa_lastlogin varbinary(14) default null,
-CREATE INDEX /*i*/aa_lastlogin ON /*_*/accountaudit_login (aa_lastlogin);
\ No newline at end of file
+ PRIMARY KEY (aa_user, aa_method),
+ INDEX /*i*/aa_lastlogin (aa_lastlogin)
+) /*$wgDBTableOptions*/;
diff --git a/patches/add_method.sql b/patches/add_method.sql
new file mode 100644
index 0000000..bd40b73
--- /dev/null
+++ b/patches/add_method.sql
@@ -0,0 +1,5 @@
+ALTER TABLE /*$wgDBprefix*/accountaudit_login
+ ADD COLUMN aa_method tinyint unsigned NOT NULL DEFAULT 0 AFTER aa_user,
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (aa_user, aa_method)
+;
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/61801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I823c873da8670ee158eee0b00759e2df8d5ef5b2
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/AccountAudit
Gerrit-Branch: master
Gerrit-Owner: Pgehres <[email protected]>
Gerrit-Reviewer: Asher <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Maryana <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Pgehres <[email protected]>
Gerrit-Reviewer: Pyoungmeister <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits