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