https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114825
Revision: 114825
Author: aaron
Date: 2012-04-10 18:28:53 +0000 (Tue, 10 Apr 2012)
Log Message:
-----------
Committing live files
Added Paths:
-----------
branches/wmf/1.19wmf1/maintenance/findBlocksBug34955-B.php
branches/wmf/1.19wmf1/maintenance/findFilesBadSha1.php
branches/wmf/1.19wmf1/maintenance/fixBug34995.php
Added: branches/wmf/1.19wmf1/maintenance/findBlocksBug34955-B.php
===================================================================
--- branches/wmf/1.19wmf1/maintenance/findBlocksBug34955-B.php
(rev 0)
+++ branches/wmf/1.19wmf1/maintenance/findBlocksBug34955-B.php 2012-04-10
18:28:53 UTC (rev 114825)
@@ -0,0 +1,51 @@
+<?php
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class FindBug34995 extends Maintenance {
+ public function __construct() {
+ $this->addOption( 'fix', false );
+ }
+
+ public function execute() {
+ $dbw = wfGetDB( DB_MASTER );
+ $dbMeta = wfGetDB( DB_SLAVE, array(), 'metawiki' );
+ $res = $dbw->select( array( 'ipblocks', 'user' ),
+ array( 'ipb_address', 'ipb_timestamp', 'ipb_user',
'ipb_id' ),
+ array( 'ipb_deleted' => 1, 'user_name IS NULL' ),
+ __METHOD__,
+ array(),
+ array( 'user' => array( 'LEFT JOIN', 'user_name =
ipb_address' ) )
+ );
+ foreach ( $res as $row ) {
+ if ( !IP::isIPAddress( $row->ipb_address ) ) {
+ var_dump( $row );
+ if ( $this->getOption( 'fix' ) ) {
+ // Check if ipb_user is correct but
ipb_address is wrong
+ // and actually based on metawiki user
name for the local UID.
+ $badUser = User::newFromId(
$row->ipb_user );
+ $metaUserName = $dbMeta->selectField(
'user', 'user_name', array( 'user_id' => $row->ipb_user ) );
+ if ( $badUser && $row->ipb_address ===
$metaUserName ) {
+ $reblocked = $dbw->selectField(
'ipblocks', '1',
+ array( 'ipb_address' =>
$badUser->getName(), 'ipb_deleted' => 1 ) );
+ if ( $reblocked ) {
+ // The correct user was
reblocked, so just nuke the bad row
+ $dbw->delete(
'ipblocks', array( 'ipb_id' => $row->ipb_id, 'ipb_deleted' => 1 ) );
+ $this->output( "Nuked
redundant block for user ID {$row->ipb_user}\n" );
+ } else {
+ // Nuke conflicting
non-suppress blocks
+ $dbw->delete(
'ipblocks', array( 'ipb_user' => $row->ipb_user, 'ipb_deleted' => 0 ) );
+ // Fix ipb_address to
match with ipb_user
+ $dbw->update(
'ipblocks',
+ array(
'ipb_address' => $badUser->getName() ),
+ array( 'ipb_id'
=> $row->ipb_id, 'ipb_deleted' => 1 ) );
+ $this->output( "Fixed
username to align with ID {$row->ipb_user}\n" );
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+$maintClass = "FindBug34995";
+require_once( RUN_MAINTENANCE_IF_MAIN );
Added: branches/wmf/1.19wmf1/maintenance/findFilesBadSha1.php
===================================================================
--- branches/wmf/1.19wmf1/maintenance/findFilesBadSha1.php
(rev 0)
+++ branches/wmf/1.19wmf1/maintenance/findFilesBadSha1.php 2012-04-10
18:28:53 UTC (rev 114825)
@@ -0,0 +1,65 @@
+<?php
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class FindFilesBadSha1 extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Find files with bad sha1 values.";
+ $this->addOption( 'outdir', 'Output directory', false, true );
+ }
+
+ public function execute() {
+ $dbr = wfGetDB( DB_SLAVE );
+ $repo = RepoGroup::singleton()->getLocalRepo();
+ $backend = $repo->getBackend(); // convenience
+ $blockSize = 86400 * 7; // 1 day = 86400
+
+ $start = wfTimestamp( TS_UNIX, $dbr->selectField( 'image',
'MIN(img_timestamp)' ) );
+ $end = wfTimestamp( TS_UNIX, $dbr->selectField( 'image',
'MAX(img_timestamp)' ) );
+
+ $end += $blockSize; # do remaining chunk
+ $blockStart = $start;
+ $blockEnd = $start + $blockSize;
+
+ while ( $blockStart && $blockEnd <= $end ) {
+ $this->output( "Checking
".wfTimestamp(TS_MW,$blockStart)." to ".wfTimestamp(TS_MW,$blockEnd)."...\n" );
+ $res = $dbr->select( 'image', '*', array(
+ 'img_timestamp >= ' . $dbr->addQuotes(
$dbr->timestamp( $blockStart ) ),
+ 'img_timestamp <= ' . $dbr->addQuotes(
$dbr->timestamp( $blockEnd ) )
+ ) );
+ foreach ( $res as $row ) {
+ $file = $repo->newFileFromRow( $row );
+ // Check current version file...
+ if ( $file->getSize() != $backend->getFileSize(
array( 'src' => $file->getPath() ) )
+ && $file->getSha1() !==
$repo->getFileSha1( $file->getPath() ) )
+ {
+ $this->output( $file->getPath() . "\n"
);
+ $this->outfile( $file->getPath() . "\n"
);
+ }
+ // Check older version files...
+ foreach ( $file->getHistory() as $oFile ) {
+ if ( $oFile->getSize() !=
$backend->getFileSize( array( 'src' => $oFile->getPath() ) )
+ && $oFile->getSha1() !==
$repo->getFileSha1( $oFile->getPath() ) )
+ {
+ $this->output(
$oFile->getPath() . "\n" );
+ $this->outfile(
$oFile->getPath() . "\n" );
+ }
+ }
+ }
+ $blockStart += $blockSize;
+ $blockEnd += $blockSize;
+ #wfWaitForSlaves();
+ }
+ }
+
+ function outfile( $s ) {
+ global $wgDBname;
+ $outdir = $this->getOption( 'outdir' );
+ if ( $outdir ) {
+ file_put_contents( "$outdir/$wgDBname", $s, FILE_APPEND
);
+ }
+ }
+}
+
+$maintClass = "FindFilesBadSha1";
+require_once( RUN_MAINTENANCE_IF_MAIN );
Added: branches/wmf/1.19wmf1/maintenance/fixBug34995.php
===================================================================
--- branches/wmf/1.19wmf1/maintenance/fixBug34995.php
(rev 0)
+++ branches/wmf/1.19wmf1/maintenance/fixBug34995.php 2012-04-10 18:28:53 UTC
(rev 114825)
@@ -0,0 +1,54 @@
+<?php
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+
+class FixBug34995 extends Maintenance {
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "Fix ipb_by for crosswiki suppression
blocks.";
+ $this->setBatchSize( 2000 ); // changed rows are sparse
+ }
+
+ public function execute() {
+ $dbw = wfGetDB( DB_MASTER );
+ $start = $dbw->selectField( 'ipblocks', "MIN(ipb_id)", false,
__METHOD__ );
+ $end = $dbw->selectField( 'ipblocks', "MAX(ipb_id)", false,
__METHOD__ );
+
+ # Do remaining chunk
+ $end += $this->mBatchSize - 1;
+ $blockStart = $start;
+ $blockEnd = $start + $this->mBatchSize - 1;
+
+ $count = 0;
+ while ( $blockStart && $blockEnd <= $end ) {
+ $res = $dbw->select( 'ipblocks',
+ array( 'ipb_id', 'ipb_address', 'ipb_user',
'ipb_timestamp' ),
+ array( 'ipb_deleted' => 1, "ipb_id BETWEEN
$blockStart AND $blockEnd" )
+ );
+ $this->output( "Doing from ipb_id $blockStart to
$blockEnd...\n" );
+ foreach ( $res as $row ) {
+ // Names should be of registed accounts for
suppress blocks
+ $user = User::newFromName( $row->ipb_address );
+ if ( $user && $user->getId() && $row->ipb_user
!= $user->getId() ) {
+ $otherBlock = $dbw->selectField(
'ipblocks', '1',
+ array( 'ipb_user' =>
$user->getId() ) );
+ // Check if another block was done to
avoid duplicate key errors
+ if ( !$otherBlock ) {
+ $dbw->update( 'ipblocks',
array( 'ipb_user' => $user->getId() ), array( 'ipb_id' => $row->ipb_id ) );
+ $this->output( "Fixed block for
`{$row->ipb_address}` [{$row->ipb_timestamp}].\n" );
+ $count++;
+ } else {
+ $this->output( "Duplicate block
for `{$row->ipb_address}` [{$row->ipb_timestamp}].\n" );
+ }
+ }
+ }
+ $blockStart += $this->mBatchSize;
+ $blockEnd += $this->mBatchSize;
+ wfWaitForSlaves();
+ }
+
+ $this->output( "Done (fixed {$count} rows).\n" );
+ }
+}
+
+$maintClass = "FixBug34995";
+require_once( RUN_MAINTENANCE_IF_MAIN );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs