Merge maintenance-work branch:
[lhc/web/wiklou.git] / maintenance / fetchText.php
1 <?php
2 /**
3 * Communications protocol...
4 *
5 * @file
6 * @ingroup Maintenance
7 */
8
9 require_once( "Maintenance.php" );
10
11 class FetchText extends Maintenance {
12 public function __construct() {
13 parent::__construct();
14 $this->mDescription = "Fetch the revision text from an old_id";
15 }
16
17 public function execute() {
18 $db = wfGetDB( DB_SLAVE );
19 $stdin = $this->getStdin();
20 while( !feof( $stdin ) ) {
21 $line = fgets( $stdin );
22 if( $line === false ) {
23 // We appear to have lost contact...
24 break;
25 }
26 $textId = intval( $line );
27 $text = $this->doGetText( $db, $textId );
28 $this->output( strlen( $text ) . "\n". $text );
29 }
30 }
31
32 /**
33 * May throw a database error if, say, the server dies during query.
34 * @param $db Database object
35 * @param $id int The old_id
36 * @return String
37 */
38 private function doGetText( $db, $id ) {
39 $id = intval( $id );
40 $row = $db->selectRow( 'text',
41 array( 'old_text', 'old_flags' ),
42 array( 'old_id' => $id ),
43 'TextPassDumper::getText' );
44 $text = Revision::getRevisionText( $row );
45 if( $text === false ) {
46 return false;
47 }
48 return $text;
49 }
50 }
51
52 $maintClass = "FetchText";
53 require_once( DO_MAINTENANCE );