50 $offset = $this->
getArg( 0 ) * 3600;
51 $start = $this->
getArg( 1 );
56 # Find bounding revision IDs
58 $revisionTable = $dbw->tableName(
'revision' );
59 $res = $dbw->query(
"SELECT MIN(rev_id) as minrev, MAX(rev_id) as maxrev FROM $revisionTable " .
60 "WHERE rev_timestamp BETWEEN '{$start}' AND '{$end}'", __METHOD__ );
61 $row = $res->fetchObject();
63 if ( $row->minrev ===
null ) {
64 $this->
fatalError(
"No revisions in search period." );
67 $minRev = $row->minrev;
68 $maxRev = $row->maxrev;
70 # Select all timestamps and IDs
71 $sql =
"SELECT rev_id, rev_timestamp FROM $revisionTable " .
72 "WHERE rev_id BETWEEN $minRev AND $maxRev";
74 $sql .=
" ORDER BY rev_id DESC";
80 $res = $dbw->query( $sql, __METHOD__ );
86 foreach ( $res as $row ) {
87 $timestamp = (int)
wfTimestamp( TS_UNIX, $row->rev_timestamp );
88 $delta = $timestamp - $lastNormal;
89 $sign = $delta == 0 ? 0 : $delta / abs( $delta );
90 if ( $sign == 0 || $sign == $expectedSign ) {
92 $lastNormal = $timestamp;
94 } elseif ( abs( $delta ) <= $grace ) {
99 $badRevs[] = $row->rev_id;
103 $numBadRevs = count( $badRevs );
104 if ( $numBadRevs > $numGoodRevs ) {
106 "The majority of revisions in the search interval are marked as bad.
108 Are you sure the offset ($offset) has the right sign? Positive means the clock
109 was incorrectly set forward, negative means the clock was incorrectly set back.
111 If the offset is right, then increase the search interval until there are enough
112 good revisions to provide a majority reference." );
113 } elseif ( $numBadRevs == 0 ) {
114 $this->
output(
"No bad revisions found.\n" );
118 $this->
output( sprintf(
"Fixing %d revisions (%.2f%% of revisions in search interval)\n",
119 $numBadRevs, $numBadRevs / ( $numGoodRevs + $numBadRevs ) * 100 ) );
122 $sql =
"UPDATE $revisionTable " .
124 .
"DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
125 "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) .
')';
126 $dbw->query( $sql, __METHOD__ );
127 $this->
output(
"Done\n" );