Page MenuHomePhabricator

IP Info: Create a logger function to be used in both the popup and accordion presenters [M]
Closed, ResolvedPublic

Description

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
  1. 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->setTarget( $target );
$logEntry->setComment( 'Reason for performing "foo" action.' );

$id = $logEntry->insert();
  1. 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

Event Timeline

Restricted Application added a subscriber: Aklapper. ยท View Herald TranscriptOct 30 2021, 2:39 AM

the action should be, at the very least, unique on performer and IP. Depending on if we want granularity on how much data someone has access to, it could also be unique based on access level and type (popup or accordion) as well. cc @Niharika?

I think we can keep it unique on all of these.
To make sure I understand correctly: when we say unique on the performer, IP, access level and type (popup or accordion) we mean that if any of these change while the others remain the same during a 24-hour duration, we make another log entry to capture it, correct?

ARamirez_WMF renamed this task from IP Info: Create a logger function to be used in both the popup and accordion presenters to IP Info: Create a logger function to be used in both the popup and accordion presenters [M].Nov 3 2021, 4:20 PM
Niharika renamed this task from IP Info: Create a logger function to be used in both the popup and accordion presenters [M] to IP Info: Create a logger function to be used in both the popup and accordion presenters.Nov 3 2021, 4:20 PM
Niharika updated the task description. (Show Details)
Niharika renamed this task from IP Info: Create a logger function to be used in both the popup and accordion presenters to IP Info: Create a logger function to be used in both the popup and accordion presenters [M].Nov 3 2021, 4:38 PM
Niharika triaged this task as Medium priority.

Change 739521 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/IPInfo@master] Add DebouncingLogger

https://gerrit.wikimedia.org/r/739521

Change 739521 merged by jenkins-bot:

[mediawiki/extensions/IPInfo@master] Add DebouncingLogger

https://gerrit.wikimedia.org/r/739521

Change 744834 had a related patch set uploaded (by Phuedx; author: Phuedx):

[mediawiki/extensions/IPInfo@master] logging: Combine implementation and interface

https://gerrit.wikimedia.org/r/744834

Change 744834 merged by jenkins-bot:

[mediawiki/extensions/IPInfo@master] logging: Combine implementation and interface

https://gerrit.wikimedia.org/r/744834

โ˜๏ธ per the description:

QA

This will be QA'd as part of T294658, T294657, T292842, and T295017.