Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15173623
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/bot.php b/bot.php
index 8956491..7245d9f 100755
--- a/bot.php
+++ b/bot.php
@@ -1,118 +1,129 @@
#!/usr/bin/php
<?php
# Copyright (C) 2018 Valerio Bozzolan
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
// autoload boz-mw
include 'boz-mw/autoload.php';
// load configuration
include 'config.php';
// groups on Meta
$META_GROUPS = [
'S' => 'steward',
];
// groups on Italian Wikipedia
$WIT_GROUPS = [
'B' => 'bureaucrat',
'CU' => 'checkuser',
'A' => 'sysop',
'AI' => 'interface-admin',
];
// legend
$LEGEND = [
'B' => "burocrate",
'CU' => "check user",
'A' => "amministratore",
'AI' => "amministratore dell'interfaccia",
];
// all groups
$GROUPS = array_merge( $META_GROUPS, $WIT_GROUPS );
// user list
$users = [];
// counter indexed by group name
$counts = [];
foreach( $GROUPS as $group ) {
$counts[ $group ] = 0;
}
// choosen wikis
$wit = \wm\WikipediaIt::instance();
$lists = [
'allusers',
'globalallusers',
];
// fetch all the sysops, checkusers, etc. from Italian wikipedia
// https://it.wikipedia.org/w/api.php?action=help&modules=query%2Ballusers
$results = $wit->createQuery( [
'action' => 'query',
'list' => $lists,
// allusers
'auprop' => 'groups',
'augroup' => array_values( $WIT_GROUPS ),
'aulimit' => 400,
// globalallusers
'aguprop' => 'groups',
'agugroup' => array_values( $META_GROUPS ),
'agulimit' => 200,
] );
// query continuation
foreach( $results->getGenerator() as $result ) {
foreach( $lists as $list ) {
foreach( $result->query->{ $list } as $user ) {
$name = $user->name;
if( ! isset( $users[ $name ] ) ) {
$users[ $name ] = [];
}
if( isset( $user->groups ) ) {
foreach( $user->groups as $group ) {
$legend = array_search( $group, $GROUPS, true );
if( $legend ) {
$users[ $name ][] = $legend;
$counts[ $group ]++;
}
}
}
}
}
}
// stats message
$stats = [];
foreach( $counts as $group => $count ) {
$stats[] = "$group: $count";
}
$stats = implode( ", ", $stats );
-$wit->login();
-$wit->edit( [
- 'title' => MARKADMINS_PAGE,
- 'summary' => "Bot: aggiornamento elenco utenti: $stats",
- 'text' => json_encode( [ 'legend' => $LEGEND, 'users' => $users ] ),
- 'contentformat' => 'application/json',
- 'bot' => 1,
-] );
+try {
+
+ $wit->login();
+
+ $wit->edit( [
+ 'title' => MARKADMINS_PAGE,
+ 'summary' => "Bot: aggiornamento elenco utenti: $stats",
+ 'text' => json_encode( [ 'legend' => $LEGEND, 'users' => $users ] ),
+ 'contentformat' => 'application/json',
+ 'bot' => 1,
+ ] );
+
+} catch( Exception $e ) {
+
+ \cli\Log::error( sprintf(
+ "something bad happened: %s",
+ $e->getMessage()
+ ) );
+}
\cli\Log::info( $stats );
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 01:59 (5 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2263721
Default Alt Text
(3 KB)
Attached To
Mode
R31 Italian Wikipedia Mark Admins (backup)
Attached
Detach File
Event Timeline