Page MenuHomePhabricator
Paste P18710

undelete-pagelinks.pl
ActivePublic

Authored by tstarling on Thu, Jan 13, 1:26 AM.
#!/usr/bin/perl -w
$db = $ARGV[0];
$table = 'pagelinks';
while (<STDIN>) {
if (/DELETE FROM `$db`.`$table`/) {
<STDIN>; # where
@values = [];
$ok = 1;
for ( $i = 1; $i <= 4; $i++ ) {
$valueLine = <STDIN>;
if ($valueLine =~ /\@$i=([0-9]+)/) {
$values[$i] = $1;
} elsif ( $valueLine =~ /\@$i='(.*)'/ ) {
$str = $1;
$str =~ s/'/\\'/g;
$values[$i] = "'$str'";
} else {
$ok = 0;
}
}
if ( $ok ) {
print "INSERT IGNORE INTO pagelinks (pl_from, pl_namespace, pl_title, pl_from_namespace) " .
"VALUES ($values[1], $values[2], $values[3], $values[4]);\n";
}
}
}