Skip to content

Instantly share code, notes, and snippets.

@DamianZaremba
Last active April 4, 2024 16:55
Show Gist options
  • Save DamianZaremba/49f56b2f28427fd37923989046af5700 to your computer and use it in GitHub Desktop.
Save DamianZaremba/49f56b2f28427fd37923989046af5700 to your computer and use it in GitHub Desktop.
ClueBot Monitoring Scripts - Wikimedia API compatibility
+sub edit_page {
+ my $logger = shift;
+ my $wiki = shift;
+ my $title = shift;
+ my $text = shift;
+ my $summary = shift;
+
+ my $ref = $wiki->api({action => 'query', meta => 'tokens', type => 'csrf'});
+ if(!$ref) {
+ $logger->error("Could not retrieve CSRF token");
+ return 0;
+ }
+ my $csrftoken = $ref->{'query'}->{'tokens'}->{'csrftoken'};
+ return $wiki->api({action => 'edit', title => $title, text => $text, summary => $summary, token => $csrftoken});
+}
- if(!$wiki->edit({
- action => 'edit',
- title => 'User:' . $config->{'check_user'} . '/running',
- text => $message,
- summary => 'Bot not running',
- })) {
+ if(!edit_page($logger, $wiki, 'User:' . $config->{'check_user'} . '/running', $message, 'Bot not running')) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment