diff --git a/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/README.md b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/README.md new file mode 100644 index 0000000..69c2880 --- /dev/null +++ b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/README.md @@ -0,0 +1,37 @@ +# 2021-03 Wikimedia CH's members wiki OAuth analysis + +This is a small script for [Wikimedia CH](https://wikimedia.ch/)'s members wiki OAuth analysis. + +https://members.wikimedia.ch/ + +## Technical details + +https://phabricator.wikimedia.org/T278140 + +## Installation + +``` +git clone --recurse-submodules https://gitpull.it/source/Wikimedia-Valerio-Bozzolan-bot-tasks/ +``` + +## Usage + +``` +cd here + +./step-1-download-wmch-users.php +./step-2-check-wmch-users.php +./step-3-print-wikitable.php +``` + +Then do something with your `report.wiki`. + +## License + +Copyright (C) 2021 Valerio Bozzolan + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see . diff --git a/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/load.php b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/load.php new file mode 100644 index 0000000..0307b91 --- /dev/null +++ b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/load.php @@ -0,0 +1,6 @@ +login(); + +$wmch_users_queries = $wmch->createQuery( [ + 'action' => 'query', + 'list' => 'allusers', + 'aulimit' => 500, +] ); + +$users = []; + +foreach( $wmch_users_queries as $wmch_user_query_batches ) { + + foreach( $wmch_user_query_batches as $wmch_user_query_batch ) { + + $allusers = $wmch_user_query_batch->allusers ?? []; + foreach( $allusers as $user ) { + + $users[] = $user; + + } + } + +} + +file_put_data( 'wmch-users.data', $users ); diff --git a/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-2-check-wmch-users.php b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-2-check-wmch-users.php new file mode 100755 index 0000000..ff0c658 --- /dev/null +++ b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-2-check-wmch-users.php @@ -0,0 +1,56 @@ +#!/usr/bin/php +registration ) ) { + $my_user->registration = $response_user->registration; + } + + // inherit Meta user ID if provided + if( isset( $response_user->userid ) ) { + $my_user->metauserid = $response_user->userid; + } +}; + +$get_name = function ( $a ) { + return $a->name; +}; + +do { + + // process some each time + $batch = []; + for( $i = 0; $i < $BATCH && $users; $i++ ) { + $batch[] = array_pop( $users )->name; + } + + $queries = meta()->createQuery( [ + 'action' => 'query', + 'list' => 'users', + 'ususers' => $batch, + 'usprop' => 'registration', + ] ); + foreach( $queries as $query ) { + + // match results + response_matcher( $query, $all_users, 'query', 'users' ) + ->matchByCustomJoin( $matched_callback, $get_name ); + } + +} while( $users ); + +// save the merged data +file_put_data( 'wmch-users-checked.data', $all_users ); diff --git a/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-3-print-wikitable.php b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-3-print-wikitable.php new file mode 100755 index 0000000..2503864 --- /dev/null +++ b/2021-03-Wikimedia-CH-members-wiki-OAuth-analysis/step-3-print-wikitable.php @@ -0,0 +1,54 @@ +#!/usr/bin/php +name === $b->name ) { + return 0; + } + + return $a->name < $b->name ? -1 : 1; +} ); + +$print_table = function( $users, $condition = null ) { + + echo "{| class=\"wikitable\"\n"; + echo "! Line\n"; + echo "! Username WMCH\n"; + echo "! Link Meta (assumed)\n"; + echo "! Meta\n"; + + $i = 1; + foreach( $users as $user ) { + + $user->metauserid = $user->metauserid ?? ''; + + if( !$condition || $condition( $user ) ) { + + echo "|-\n"; + echo "| $i\n"; + printf( "| [[User:%s]]\n", $user->name ); + printf( "| [[metawikipedia:User:%s]]\n", $user->name ); + echo "| {$user->metauserid}\n"; + + $i++; + } + } + + echo "|}\n"; +}; + +echo "== Matching users ==\n"; +$print_table( $users, function( $user ) { + return !empty( $user->metauserid ); +} ); +echo "\n"; + +echo "== Missing users ==\n"; +$print_table( $users, function( $user ) { + return empty( $user->metauserid ); +} ); diff --git a/includes/boz-mw b/includes/boz-mw index bbe6f1d..51936f6 160000 --- a/includes/boz-mw +++ b/includes/boz-mw @@ -1 +1 @@ -Subproject commit bbe6f1d36e9bc172ff6d83db4d1c6436c50950cb +Subproject commit 51936f610239938ac7f63f097752784097f09417