Localization update for he and fixing comment in en.
[lhc/web/wiklou.git] / maintenance / cleanupTable.inc
1 <?php
2
3 require_once( 'FiveUpgrade.inc' );
4
5 /**
6 * @ingroup Maintenance
7 */
8 abstract class TableCleanup extends FiveUpgrade {
9 function __construct( $table, $dryrun = false ) {
10 parent::__construct();
11
12 $this->targetTable = $table;
13 $this->maxLag = 10; # if slaves are lagged more than 10 secs, wait
14 $this->dryrun = $dryrun;
15 }
16
17 function cleanup() {
18 if( $this->dryrun ) {
19 echo "Checking for bad titles...\n";
20 } else {
21 echo "Checking and fixing bad titles...\n";
22 }
23 $this->runTable( $this->targetTable,
24 '', //'WHERE page_namespace=0',
25 array( $this, 'processPage' ) );
26 }
27
28 function init( $count, $table ) {
29 $this->processed = 0;
30 $this->updated = 0;
31 $this->count = $count;
32 $this->startTime = wfTime();
33 $this->table = $table;
34 }
35
36 function progress( $updated ) {
37 $this->updated += $updated;
38 $this->processed++;
39 if( $this->processed % 100 != 0 ) {
40 return;
41 }
42 $portion = $this->processed / $this->count;
43 $updateRate = $this->updated / $this->processed;
44
45 $now = wfTime();
46 $delta = $now - $this->startTime;
47 $estimatedTotalTime = $delta / $portion;
48 $eta = $this->startTime + $estimatedTotalTime;
49
50 printf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
51 wfWikiID(),
52 wfTimestamp( TS_DB, intval( $now ) ),
53 $portion * 100.0,
54 $this->table,
55 wfTimestamp( TS_DB, intval( $eta ) ),
56 $this->processed,
57 $this->count,
58 $this->processed / $delta,
59 $updateRate * 100.0 );
60 flush();
61 }
62
63 function runTable( $table, $where, $callback ) {
64 $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ );
65 $this->init( $count, $table );
66 $this->log( "Processing $table..." );
67
68 $tableName = $this->dbr->tableName( $table );
69 $sql = "SELECT * FROM $tableName $where";
70 $result = $this->dbr->query( $sql, __METHOD__ );
71
72 foreach( $result as $row ) {
73 call_user_func( $callback, $row );
74 }
75 $this->log( "Finished $table... $this->updated of $this->processed rows updated" );
76 $result->free();
77 }
78
79 function hexChar( $matches ) {
80 return sprintf( "\\x%02x", ord( $matches[1] ) );
81 }
82
83 abstract function processPage( $row );
84
85 }