Initial implementation of restartable subprocess for text fetching in dumpTextPass.php
[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 $textId = intval( $line );
14 $text = doGetText( $db, $textId );
15 echo strlen( $text ) . "\n";
16 echo $text;
17 }
18
19 /**
20 * May throw a database error if, say, the server dies during query.
21 */
22 function doGetText( $db, $id ) {
23 $id = intval( $id );
24 $row = $db->selectRow( 'text',
25 array( 'old_text', 'old_flags' ),
26 array( 'old_id' => $id ),
27 'TextPassDumper::getText' );
28 $text = Revision::getRevisionText( $row );
29 if( $text === false ) {
30 return false;
31 }
32 $stripped = str_replace( "\r", "", $text );
33 $normalized = UtfNormal::cleanUp( $stripped );
34 return $normalized;
35 }
36
37
38 ?>