delinquent_files/demon.php

changeset 6
8b4e205ffc94
parent 3
24d8f83459b3
child 8
38415be9f910
equal deleted inserted replaced
5:ff125aa259db 6:8b4e205ffc94
1 #!/usr/bin/php 1 #!/usr/bin/php
2 #$Id$
3 #
4
2 <?PHP 5 <?PHP
6
3 7
4 chdir ( '/data/project/commons-delinquent' ) ; 8 chdir ( '/data/project/commons-delinquent' ) ;
5 9
6 error_reporting(E_ERROR|E_CORE_ERROR|E_COMPILE_ERROR); # E_ALL| 10 error_reporting(E_ERROR|E_CORE_ERROR|E_COMPILE_ERROR); # E_ALL|
7 ini_set('display_errors', 'On'); 11 ini_set('display_errors', 'On');
8 12
9 require_once ( './shared.inc' ) ; 13 require_once ( './shared.inc' ) ;
10 require_once( './matcher.inc' ); 14 require_once( './matcher.inc' );
11 require_once( './debug.inc' ); 15 require_once( './debug.inc' );
16
17 print "Bot startup in progress...\n";
12 18
13 class CommonsDelinquentDemon extends CommonsDelinquent { 19 class CommonsDelinquentDemon extends CommonsDelinquent {
14 20
15 var $avoidNamespaceOnWiki = [ 21 var $avoidNamespaceOnWiki = [
16 'dewiki' => [4] 22 'dewiki' => [4]
153 159
154 160
155 function getTextFromWiki ( $wiki , $pagename ) { 161 function getTextFromWiki ( $wiki , $pagename ) {
156 $ret = false ; 162 $ret = false ;
157 $this->d->debug( "Getting api of " . $wiki) ; 163 $this->d->debug( "Getting api of " . $wiki) ;
164 // temp workaround 3/22/2023
165 //if ($wiki === 'bclwiktionary' || $wiki === 'bjnwiktionary' || $wiki === 'gorwiktionary') {
166 // return false;
167 //}
158 $api = $this->getAPI ( $wiki ) ; 168 $api = $this->getAPI ( $wiki ) ;
159 if ( $api ) { 169 if ( $api ) {
160 $services = new \Mediawiki\Api\MediawikiFactory( $api ); 170 $services = new \Mediawiki\Api\MediawikiFactory( $api );
161 $page = $services->newPageGetter()->getFromTitle( $pagename ); 171 $page = $services->newPageGetter()->getFromTitle( $pagename );
162 $revision = $page->getRevisions()->getLatest(); 172 $revision = $page->getRevisions()->getLatest();
163 173
164 if ( $revision ) { 174 if ( $revision ) {
165 $ret = $revision->getContent()->getData() ; 175 $ret = $revision->getContent()->getData() ;
166 } 176 }
167 } 177 }
168 return $ret ; 178 return $ret ;
473 die ( "Unknown action " . $e->action ) ; 483 die ( "Unknown action " . $e->action ) ;
474 } 484 }
475 } 485 }
476 486
477 function clearBogusIssues ( $db ) { 487 function clearBogusIssues ( $db ) {
488
489 $ts = date ( 'YmdHis' , time() - 60*60*24*7 ); # look back 7 days only
490
478 # Clear some previous issues 491 # Clear some previous issues
479 // 0=pending 492 // 0=pending
480 // 1=done 493 // 1=done
481 // 2=skipped 494 // 2=skipped
482 $sql = "update `event` set done=0,note='' where note like '%rate limit%' and done=2" ; 495 $sql = "update `event` set done=0,note='' where note like '%rate limit%' and done=2 and timestamp>'$ts'" ;
483 $this->d->debug("Set done=0 (pending) on 'rate limit' events where done=2(skipped)"); 496 $this->d->debug("Set done=0 (pending) on 'rate limit' events where done=2(skipped)");
484 $this->runQuery ( $db , $sql ) ; 497 $this->runQuery ( $db , $sql ) ;
485 $sql = "update `event` set done=0,note='' where note like '%edit conflict%' and done=2" ; 498 $sql = "update `event` set done=0,note='' where note like '%edit conflict%' and done=2 and timestamp>'$ts'" ;
486 $this->d->debug("Set done=0 (pending) on 'edit conflict' events where done=2(skipped)"); 499 $this->d->debug("Set done=0 (pending) on 'edit conflict' events where done=2(skipped)");
487 $this->runQuery ( $db , $sql ) ; 500 $this->runQuery ( $db , $sql ) ;
488 } 501 }
489 502
490 function performEdits () { 503 function performEdits () {
507 if ( $last_wiki == $o->wiki ) sleep ( 2 ) ; // Edit rate limiter 520 if ( $last_wiki == $o->wiki ) sleep ( 2 ) ; // Edit rate limiter
508 $this->d->debug("Perform an edit in $o->wiki"); 521 $this->d->debug("Perform an edit in $o->wiki");
509 try { 522 try {
510 $this->performEdit ( $o ) ; 523 $this->performEdit ( $o ) ;
511 } catch (Exception $e) { 524 } catch (Exception $e) {
512 echo 'Caught exception: ', $e->getMessage(), "\n"; 525 echo 'Caught exception: ', $e->getMessage(), "\n";
513 } 526 }
514 $last_wiki = $o->wiki ; 527 $last_wiki = $o->wiki ;
515 } 528 }
516 529
517 $this->d->debug("Connecting to DB"); 530 $this->d->debug("Connecting to DB");

mercurial