Pgehres has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53683
Change subject: Initial commit of Extension:AccountAudit.
......................................................................
Initial commit of Extension:AccountAudit.
The extension adds a table for tracking the timestamp of the most recent
login for a user. This will allow us to determine the (in)activity of a
user and thusly whether or not we can unilaterally rename the user in the
event of clashing local accounts during unification.
Change-Id: I163682c55031e77bba02d67cd62839f9541adc99
---
A .gitreview
A AccountAudit.body.php
A AccountAudit.hooks.php
A AccountAudit.i18n.php
A AccountAudit.php
A accountaudit.sql
6 files changed, 132 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AccountAudit
refs/changes/83/53683/1
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..1f89536
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.wikimedia.org
+port=29418
+project=mediawiki/extensions/AccountAudit.git
+defaultbranch=master
diff --git a/AccountAudit.body.php b/AccountAudit.body.php
new file mode 100644
index 0000000..4c469b7
--- /dev/null
+++ b/AccountAudit.body.php
@@ -0,0 +1,36 @@
+<?php
+
+class AccountAudit {
+
+ /**
+ * Updates the aa_lastlogin value for the specified user
+ *
+ * @param $user User the user that just logged in
+ *
+ * @return bool
+ */
+ static function updateLastLogin( $user ) {
+
+ $now = wfTimestamp( TS_MW, time() );
+
+ $db = wfGetDB( DB_MASTER );
+ $db->insert(
+ 'accountaudit_login',
+ array( 'aa_user' => $user->mId, 'aa_lastlogin' => $now
),
+ __METHOD__,
+ array( 'IGNORE' )
+ );
+
+ if ( $db->affectedRows() == 0 ) { // duplicate key existed
+ $db->update(
+ 'accountaudit_login',
+ array( 'aa_lastlogin' => $now, ),
+ array( 'aa_user' => $user->mId, ),
+ __METHOD__
+ );
+ }
+
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/AccountAudit.hooks.php b/AccountAudit.hooks.php
new file mode 100644
index 0000000..9dae851
--- /dev/null
+++ b/AccountAudit.hooks.php
@@ -0,0 +1,23 @@
+<?php
+
+class AccountAuditHooks {
+
+ /**
+ * Implementation of the hook for onUserLoginComplete.
+ *
+ * Calls AccountAudit::updateLastLogin to update the timestamp of the
last
+ * login for the user
+ *
+ * @param User $user
+ * @param $inject_html
+ *
+ * @return bool
+ */
+ function onUserLoginComplete( User &$user, &$inject_html ) {
+
+ AccountAudit::updateLastLogin( $user );
+
+ // Always return true, we should never block execution on
failure
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/AccountAudit.i18n.php b/AccountAudit.i18n.php
new file mode 100644
index 0000000..7d81dd3
--- /dev/null
+++ b/AccountAudit.i18n.php
@@ -0,0 +1,13 @@
+<?php
+
+$messages = array();
+
+$messages['en'] = array(
+ 'accountaudit-desc' => 'This extension is used to assist the WMF in
completing the audit an unification of non-global accounts that exist across
the WMF\'s projects',
+);
+
+/** Message documentation (Message documentation)
+ */
+$messages['qqq'] = array(
+ 'accountaudit-desc' => '{{desc}}',
+);
\ No newline at end of file
diff --git a/AccountAudit.php b/AccountAudit.php
new file mode 100644
index 0000000..780042b
--- /dev/null
+++ b/AccountAudit.php
@@ -0,0 +1,42 @@
+<?php
+/*
+ * Extension:AccountAudit. This extension is used to assist the WMF in
completing the audit
+ * an unification of non-global accounts that exist across the WMF's projects.
+ *
+ * @author Peter Gehres <[email protected]>
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+ echo <<<EOT
+To install the AccountAudit extension, put the following line in
LocalSettings.php:
+require_once( "\$IP/extensions/AccountAudit/AccountAudit.php" );
+EOT;
+ exit( 1 );
+}
+
+$wgExtensionCredits[ 'other' ][ ] = array(
+ 'path' => __FILE__,
+ 'name' => 'AccountAudit',
+ 'author' => array( 'Peter Gehres', ),
+ 'url' =>
'https://www.mediawiki.org/wiki/Extension:AccountAudit',
+ 'descriptionmsg' => 'accountaudit-desc',
+ 'version' => '1.0.0',
+);
+
+$dir = dirname( __FILE__ ) . '/';
+
+$wgAutoloadClasses[ 'AccountAudit' ] = $dir . 'AccountAudit.body.php';
+$wgAutoloadClasses[ 'AccountAuditHooks' ] = $dir . 'AccountAudit.hooks.php';
+
+$wgHooks['UserLoginComplete'][] = 'AccountAuditHooks::onUserLoginComplete';
+
+$wgExtensionMessagesFiles['AccountAudit'] = $dir . 'AccountAudit.i18n.php';
+
+// Schema updates for update.php
+$wgHooks['LoadExtensionSchemaUpdates'][] = 'fnInstallDB';
+
+function fnInstallDB( DatabaseUpdater $updater ) {
+ $updater->addExtensionTable( 'accountaudit_login',
+ dirname( __FILE__ ) . '/accountaudit.sql', true );
+ return true;
+}
\ No newline at end of file
diff --git a/accountaudit.sql b/accountaudit.sql
new file mode 100644
index 0000000..95c6984
--- /dev/null
+++ b/accountaudit.sql
@@ -0,0 +1,13 @@
+--
+-- This tables tracks the most recent login action for a user
+-- user_id is an effective foreign key to the user table
+--
+CREATE TABLE accountaudit_login (
+ -- Key to user_id
+ aa_user int unsigned NOT NULL PRIMARY KEY,
+
+ -- This is a timestamp which is updated when a user logs in
+ aa_lastlogin varbinary(14) default null
+) /*$wgDBTableOptions*/;
+
+CREATE INDEX /*i*/aa_lastlogin ON /*_*/accountaudit_login (aa_lastlogin);
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/53683
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I163682c55031e77bba02d67cd62839f9541adc99
Gerrit-PatchSet: 1
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: Jforrester <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits