wiki.techinc.nl/maintenance/fetchText.php
Brion Vibber 69dd51f03b Don't fall into an infinite loop o' death if the pipes get broken.
Exit out if we can't read from stdin anymore, instead of interpreting the 'false' error code as text ID 0...
2008-05-19 15:49:05 +00:00

37 lines
743 B
PHP

<?php
/**
* Communications protocol...
*/
require "commandLine.inc";
$db = wfGetDB( DB_SLAVE );
$stdin = fopen( "php://stdin", "rt" );
while( !feof( $stdin ) ) {
$line = fgets( $stdin );
if( $line === false ) {
// We appear to have lost contact...
break;
}
$textId = intval( $line );
$text = doGetText( $db, $textId );
echo strlen( $text ) . "\n";
echo $text;
}
/**
* May throw a database error if, say, the server dies during query.
*/
function doGetText( $db, $id ) {
$id = intval( $id );
$row = $db->selectRow( 'text',
array( 'old_text', 'old_flags' ),
array( 'old_id' => $id ),
'TextPassDumper::getText' );
$text = Revision::getRevisionText( $row );
if( $text === false ) {
return false;
}
return $text;
}