We need to log whenever someone access but not necessarily every time they see that information. For instance, if I were clicking between IP A and B repeatedly on Special:RecentChanges to see if someone were a sockpuppet, I don't want to spam the log table with every single click. Since we don't know how people will be using this tool necessasrily, we've settled on logging the access once a day and seeing how we like that. We want to be able to adjust that number of necessary. Since there's a logic check before writing to the log table and since both the popup and the accordion will have to use it, it might be sensible to split the function into something both PopupHandler.php and InfoBoxHandler.php can call (API endpoint?)
- <type>Handler.php should just be able to call something like $this->api->logAction( params ) and not care about any conditions to logging
- The debounce time should be configurable
- The logger checks the log table and if it sees that the action has already been logged in the last 24 hours (rolling), does not log again
- If it's unique to the last 24 hours, the logger writes the action to the table
- The action should be unique on all of these: Performer, IP, Access level and type (popup or accordion)
QA
This will be QA'd as part of T294658, T294657, T292842, and T295017.
Notes
- You can read about how to add an entry to that log here: https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Logging_to_Special:Log
// tl;dr: $ip = "xxx.xxx.xxx.xxx"; $_target = TitleValue::tryNew( NS_USER, $ip ); $logEntry = new ManualLogEntry( "ipinfo", "foo" ); // Log action "foo" in the "ipinfo" log $logEntry->setPerformer( $user ); $logEntry->set_target( $_target ); $logEntry->setComment( 'Reason for performing "foo" action.' ); $id = $logEntry->insert();
- During code review, you'll want to test this code end-to-end, which you can do so via MediaWiki's PHP shell. You can start an instance of the shell with the following command:
docker-compose exec mediawiki php maintenance/shell.php
and, once the instance shell has started up you'd write something like the following:
$performer = new \MediaWiki\User\UserIdentityValue( 1, 'Admin' ); $db = wfGetDB( DB_PRIMARY ); $logger = new \MediaWiki\IPInfo\Logging\DebouncingLogger( 10, $db ); $logger->logViewAccordion( $performer, '127.0.0.1' ); $logger->logViewAccordion( $performer, '127.0.0.1' ); // Doesn't log anything to the database $logger->logViewAccordion( $performer, '127.0.0.1' ); // Doesn't log anything to the database