Mon, 23 Jan 2023 21:39:43 +0100
BotSecrets.pm-sample: add some comments to help to see which variable is what
0
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
1 | #!/usr/bin/perl |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
2 | #$Id$ |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
3 | # |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
4 | # cleanup after delinker |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
5 | # |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
6 | # (c)Peter [[grin]] Gervai, 2022 |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
7 | # cc-by-sa-4.0-int / gplv3+ |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
8 | # |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
9 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
10 | use strict; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
11 | use warnings; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
12 | use utf8; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
13 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
14 | use File::Basename; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
15 | use lib dirname(__FILE__); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
16 | use BotSecrets; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
17 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
18 | use MediaWiki::Bot qw(:constants); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
19 | use DBI; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
20 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
21 | binmode( STDOUT, ':utf8' ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
22 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
23 | $|=1; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
24 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
25 | my ($db_name, $db_host, $db_port) = ("s52421__commonsdelinquent_p", "tools.db.svc.wikimedia.cloud", 3306); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
26 | ## my ($db_user, $db_pw) = ("xxxxxxxxx", "xxxxxxxxxx"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
27 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
28 | &d("Start"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
29 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
30 | ## connect db |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
31 | my $dsn = "DBI:mysql:database=$db_name;host=$db_host;port=$db_port"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
32 | my $dbh = DBI->connect( $dsn, $db_user, $db_pw, { mysql_enable_utf8=>1, RaiseError=>0, AutoCommit=>0 } ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
33 | $dbh->{mysql_enable_utf8} = 1; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
34 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
35 | ## prepare sql |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
36 | #my $sth = $dbh->prepare( "SELECT id,action,file,wiki,page,revision,done,note,replace_with_file FROM event WHERE action=? AND file=? AND done=? AND timestamp BETWEEN ? AND ?" ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
37 | my $sth = $dbh->prepare( "SELECT id,action,file,wiki,page,revision,done,note,replace_with_file FROM event WHERE action=? AND done=? AND timestamp BETWEEN ? AND ?" ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
38 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
39 | my $sth_update = $dbh->prepare( "UPDATE event SET done=? WHERE id=?" ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
40 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
41 | ## connect bot (enwp) |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
42 | #my ($bu,$bp) = ('xxxxxxxxxxxxx', 'xxxxxxxxxxxxxx' ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
43 | our $bot = MediaWiki::Bot->new({ |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
44 | host => 'en.wikipedia.org', |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
45 | login_data => { username => $bu, password=> $bp }, |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
46 | do_sul => 1, |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
47 | operator => 'grin', |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
48 | protocol => 'https', |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
49 | debug => 2, |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
50 | assert => 'user', |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
51 | }); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
52 | my $last_wiki='huwiki'; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
53 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
54 | die "Cannot login" unless $bot; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
55 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
56 | ## rev |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
57 | my $revert_message = "Undoing CommonsDelinker bad replace, will be retried later."; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
58 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
59 | ## prepare search |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
60 | my $action = 'replace'; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
61 | #my $file = 'S-3A_MAD_DN-SC-87-05743.JPEG'; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
62 | my $done = 127; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
63 | my ($ts_from, $ts_to) = ('20220502000000', '20220506130000'); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
64 | #my $res = $sth->execute( $action, $file, $done, $ts_from, $ts_to ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
65 | my $res = $sth->execute( $action, $done, $ts_from, $ts_to ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
66 | if( $dbh->err ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
67 | die "Error doing SQL: " . $dbh->errstr; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
68 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
69 | print $sth->rows . " rows found.\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
70 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
71 | ## results |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
72 | while( my $a = $sth->fetchrow_hashref ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
73 | for my $key (sort keys %$a) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
74 | print "$key=" . $$a{$key} . " "; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
75 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
76 | print "\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
77 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
78 | # check data |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
79 | if( $last_wiki ne $$a{wiki} ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
80 | my $wikidata = &get_wikidata( $$a{wiki} ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
81 | next unless $wikidata; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
82 | $bot->set_wiki( $wikidata ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
83 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
84 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
85 | my $revid = $bot->get_last( $$a{page}, 'CommonsDelinker' ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
86 | if( !defined( $revid ) ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
87 | &d("Revid is missing!! skipping $$a{wiki}:$$a{page}!!"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
88 | #&error("missing revid"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
89 | next; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
90 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
91 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
92 | if( $revid == $$a{revision} ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
93 | &d(" Page unchanged, undo possible! REVERTING $$a{wiki}:$$a{page}"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
94 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
95 | # revert |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
96 | if( $bot->revert( $$a{page}, $$a{revision}, $revert_message ) ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
97 | &d( "Success. Updating."); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
98 | $sth_update->execute( 0, $$a{id} ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
99 | if( $dbh->err ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
100 | &d( "*** Error updating db for $$a{wiki}:$$a{page} id=$$a{id}!!"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
101 | $dbh->commit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
102 | exit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
103 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
104 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
105 | } else { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
106 | &d( " Revert #1 failed, try to login."); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
107 | if( $bot->login( { username=>$bu, password=>$bp } ) ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
108 | if( $bot->revert( $$a{page}, $$a{revision}, $revert_message ) ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
109 | &d( "Success^2. Updating."); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
110 | $sth_update->execute( 0, $$a{id} ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
111 | if( $dbh->err ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
112 | &d( "*** Error updating db for $$a{wiki}:$$a{page} id=$$a{id}!!"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
113 | $dbh->commit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
114 | exit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
115 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
116 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
117 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
118 | } else { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
119 | &d( "Login failed into $$a{wiki}. Skipping"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
120 | &error("login failed"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
121 | $sth_update->execute( 43, $$a{id} ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
122 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
123 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
124 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
125 | } else { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
126 | &d( " Page changed, oldid $$a{revision} - newid $revid; skipping (update db)."); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
127 | $sth_update->execute( 42, $$a{id} ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
128 | if( $dbh->err ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
129 | &d( "*** Error updating db for non-changed $$a{wiki}:$$a{page} id=$$a{id}!!"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
130 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
131 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
132 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
133 | $dbh->commit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
134 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
135 | &d( "Commit."); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
136 | $dbh->commit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
137 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
138 | exit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
139 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
140 | sub d { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
141 | my ($s) = @_; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
142 | print scalar(localtime) . " [$$] $s\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
143 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
144 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
145 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
146 | sub error { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
147 | return; # doesn't work |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
148 | my ($s) = @_; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
149 | print "error: $s; " . $bot->{error}->{code} . "; " . $bot->{error}->{details} . "\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
150 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
151 | #use Data::Dumper; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
152 | #die Dumper($bot); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
153 | #exit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
154 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
155 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
156 | ## decypher short wikinames |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
157 | sub get_wikidata { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
158 | my ($name) = @_; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
159 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
160 | &d("Decode $name"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
161 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
162 | my $host = $bot->db_to_domain( $name ); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
163 | return { host => $host }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
164 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
165 | if( $name =~ /^(.{2,3}|simple)wiki$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
166 | return { host => "$1.wikipedia.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
167 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
168 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
169 | if( $name =~ /^(.{2,3})wikivoyage$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
170 | return { host => "$1.wikivoyage.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
171 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
172 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
173 | if( $name =~ /^(.{2,3})wikisource$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
174 | return { host => "$1.wikisource.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
175 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
176 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
177 | if( $name =~ /^(.{2,3})wikiquote$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
178 | return { host => "$1.wikiquote.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
179 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
180 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
181 | if( $name =~ /^(.{2,3})wikibooks$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
182 | return { host => "$1.wikibooks.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
183 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
184 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
185 | if( $name =~ /^(.{2,3})wiktionary$/ ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
186 | return { host => "$1.wiktionary.org" }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
187 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
188 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
189 | if( $name eq 'wikidatawiki' ) { |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
190 | # wikidata probably not fucked up |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
191 | return undef; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
192 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
193 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
194 | &d("*** $name not implemented yet!!! ***"); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
195 | return undef; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
196 | #die "decode '$name' isn't implemented yet."; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
197 | } |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
198 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
199 | exit; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
200 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
201 | my $article_name = 'a'; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
202 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
203 | my $options = { revid => 13849803 }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
204 | my $txt = $bot->get_text($article_name, $options); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
205 | die "error something" unless defined $options->{pageid}; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
206 | warn "page doesn't exist" if $options->{pageid} == MediaWiki::Bot::PAGE_NONEXISTENT; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
207 | print "Page length is ". length($txt) . "!\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
208 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
209 | my $pageid = $bot->get_id($article_name); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
210 | die "error something else" unless defined $pageid; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
211 | printf "Page id is %s\n", $pageid; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
212 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
213 | # last _not_ by user |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
214 | my $revid = $bot->get_last($article_name,'no such user'); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
215 | printf "Last revid is %s\n", $revid; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
216 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
217 | $revid = $bot->get_last($article_name,'FoBe'); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
218 | printf "Last revid-2 is %s\n", $revid; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
219 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
220 | $options = { oldid=> 20300641, revid=>20300648 }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
221 | my $diff = $bot->diff($options); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
222 | print "Diff: $diff\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
223 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
224 | ## commons |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
225 | $bot->set_wiki({ |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
226 | host => 'commons.wikimedia.org' |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
227 | }); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
228 | die "Cannot login to commons" unless $bot; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
229 | print "Logged over commons.\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
230 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
231 | $options = { revid=> 568734018, oldid=>628016329 }; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
232 | $diff = $bot->diff($options); |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
233 | print "Diff: $diff\n"; |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
234 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
235 | ## a hiba: az elozo sor utolso szava + \n bekerult a replacementbe |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
236 | ## javitas: |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
237 | ## - ha ez az utolso edit |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
238 | ## - revert |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
239 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
240 | __END__ |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
241 | <tr> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
242 | <td class="diff-marker" data-marker="???"></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
243 | <td class="diff-deletedline diff-side-deleted"><div>File:Nestor Lakoba, Nikita Khrushchev, Lavrenti Beria and Aghasi Khanjian.jpg|Nestor Lakoba, Nikita Khrushchev, Lavrenti Beria and Aghasi Khanjian, <del class="diffchange diffchange-inline">1935</del></div></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
244 | <td class="diff-marker" data-marker="+"></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
245 | <td class="diff-addedline diff-side-added"><div>File:Nestor Lakoba, Nikita Khrushchev, Lavrenti Beria and Aghasi Khanjian.jpg|Nestor Lakoba, Nikita Khrushchev, Lavrenti Beria and Aghasi Khanjian,<ins class="diffchange diffchange-inline">|{{c|Georgy</ins> <ins class="diffchange diffchange-inline">Malenkov}} and Beria, 1940</ins></div></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
246 | </tr> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
247 | <tr> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
248 | <td class="diff-marker" data-marker="???"></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
249 | <td class="diff-deletedline diff-side-deleted"><div>File:?????????? ?? ????????.jpg|{{c|Georgy Malenkov}} and Beria, 1940</div></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
250 | <td colspan="2" class="diff-empty diff-side-added"></td> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
251 | </tr> |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
252 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
253 | |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
254 | ## generic revert |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
255 | ## - adatbazisbol ami done=42 |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
256 | ## - revision |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
257 | ## - ha az az utolso akkor: |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
258 | ## - revert |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
259 | ## - done=0 (pending) |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
260 | ## - ha nem akkor |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
261 | ## - done=666 (fixx it felix) |
3b714bbb1347
Add files without passwords and other unwanted fluff.
Peter Gervai <grin@grin.hu>
parents:
diff
changeset
|
262 | ## |