Page MenuHomePhabricator

Creating edits by random IPs on a devwiki

Authored By
MusikAnimal
Mar 22 2017, 5:57 PM
Size
1 KB
Referenced Files
None
Subscribers
None

Creating edits by random IPs on a devwiki

Creating edits from random IPs for testing the "get edits" feature of the CheckUser extension. See T145912
Mixed languages...
1) Create the page "Test" on your devwiki
2) Log in as an admin or bot
3) Open the JavaScript console and run:
api = new mw.Api();
i = 0;
function testEdit() {
console.log(i);
if (i === 1000) return;
api.postWithToken( "edit", {
action: "edit",
title: "Test",
text: Math.random().toString()
}).then(() => {
i += 1;
testEdit();
});
}
testEdit();
That makes 1,000 random edits on the page "Test". You must be an admin/bot to get around throttling limitations.
4) In vagrant, run `mwscript maintenance/eval.php`
5) Then this code:
use \IP;
$dbr = wfGetDB( DB_MASTER );
/**** FOR TESTING AGAINST CHECKUSER TABLE ****/
// use the ID of the "Test" page. For me it was 3
$res = $dbr->select( 'cu_changes', [ 'cuc_id', 'cuc_this_oldid' ], 'cuc_page_id = 3' );
foreach( $res as $row ) { $randIP = "192.0.0." . mt_rand( 0, 255 ); $dbr->update( 'cu_changes', [ 'cuc_user' => 0, 'cuc_user_text' => $randIP, 'cuc_ip' => $randIP, 'cuc_ip_hex' => IP::toHex( $randIP ) ], [ 'cuc_id' => $row->cuc_id ] ); $dbr->update( 'revision', [ 'rev_user_text' => $randIP, 'rev_user' => 0 ], [ 'rev_id' => $row->cuc_this_oldid ] ); }
/**** FOR TESTING AGAINST NEW ip_changes TABLE (see T156318) ****/
$res = $dbr->select( 'revision', ['*'], 'rev_page = 3' );
foreach( $res as $row ) { $revId = $row->rev_id; $randIP = "192.0.0." . mt_rand( 0, 255 ); $dbr->update( 'revision', [ 'rev_user_text' => $randIP, 'rev_user' => 0, ], [ 'rev_id' => $revId ] ); $dbr->insert( 'ip_changes', ['ipc_rev_id' => $revId, 'ipc_rev_timestamp' => $row->rev_timestamp, 'ipc_hex' => IP::toHex( $randIP ), ], __METHOD__ ); }
Each set of commands is jumbled onto one line because I can't figure out how to do multi-line stuff with maintenance/eval.php...
After the above you'll have 1,000 edits by random IPs in the range 192.0.0.0/24.

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4495460
Default Alt Text
Creating edits by random IPs on a devwiki (1 KB)

Event Timeline