37 $offset = $this->
getArg( 0 ) * 3600;
38 $start = $this->
getArg( 1 );
43 # Find bounding revision IDs
45 $revisionTable = $dbw->tableName(
'revision' );
46 $res = $dbw->query(
"SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
47 "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__ );
48 $row = $res->fetchObject();
50 if ( $row->minrev ===
null ) {
51 $this->
fatalError(
"No revisions in search period." );
54 $minRev = $row->minrev;
55 $maxRev = $row->maxrev;
57 # Select all timestamps and IDs
58 $sql =
"SELECT rev_id, rev_timestamp FROM $revisionTable " .
59 "WHERE rev_id BETWEEN $minRev AND $maxRev";
61 $sql .=
" ORDER BY rev_id DESC";
67 $res = $dbw->query( $sql, __METHOD__ );
73 foreach ( $res as $row ) {
74 $timestamp = (int)
wfTimestamp( TS::UNIX, $row->rev_timestamp );
75 $delta = $timestamp - $lastNormal;
76 $sign = $delta == 0 ? 0 : $delta / abs( $delta );
77 if ( $sign == 0 || $sign == $expectedSign ) {
79 $lastNormal = $timestamp;
81 } elseif ( abs( $delta ) <= $grace ) {
86 $badRevs[] = $row->rev_id;
90 $numBadRevs = count( $badRevs );
91 if ( $numBadRevs > $numGoodRevs ) {
93 "The majority of revisions in the search interval are marked as bad.
95 Are you sure the offset ($offset) has the right sign? Positive means the clock
96 was incorrectly set forward, negative means the clock was incorrectly set back.
98 If the offset is right, then increase the search interval until there are enough
99 good revisions to provide a majority reference." );
100 } elseif ( $numBadRevs == 0 ) {
101 $this->
output(
"No bad revisions found.\n" );
105 $this->
output( sprintf(
"Fixing %d revisions (%.2f%% of revisions in search interval)\n",
106 $numBadRevs, $numBadRevs / ( $numGoodRevs + $numBadRevs ) * 100 ) );
109 $sql =
"UPDATE $revisionTable " .
111 .
"DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
112 "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) .
')';
113 $dbw->query( $sql, __METHOD__ );
114 $this->
output(
"Done\n" );