Don't fall into an infinite loop o' death if the pipes get broken.
[lhc/web/wiklou.git] / maintenance / fetchText.php
1 <?php
2
3 /**
4 * Communications protocol...
5 */
6
7 require "commandLine.inc";
8
9 $db = wfGetDB( DB_SLAVE );
10 $stdin = fopen( "php://stdin", "rt" );
11 while( !feof( $stdin ) ) {
12 $line = fgets( $stdin );
13 if( $line === false ) {
14 // We appear to have lost contact...
15 break;
16 }
17 $textId = intval( $line );
18 $text = doGetText( $db, $textId );
19 echo strlen( $text ) . "\n";
20 echo $text;
21 }
22
23 /**
24 * May throw a database error if, say, the server dies during query.
25 */
26 function doGetText( $db, $id ) {
27 $id = intval( $id );
28 $row = $db->selectRow( 'text',
29 array( 'old_text', 'old_flags' ),
30 array( 'old_id' => $id ),
31 'TextPassDumper::getText' );
32 $text = Revision::getRevisionText( $row );
33 if( $text === false ) {
34 return false;
35 }
36 return $text;
37 }