MediaWiki  REL1_20
fetchText.php
Go to the documentation of this file.
00001 <?php
00025 require_once( __DIR__ . '/Maintenance.php' );
00026 
00032 class FetchText extends Maintenance {
00033         public function __construct() {
00034                 parent::__construct();
00035                 $this->mDescription = "Fetch the revision text from an old_id";
00036         }
00037 
00048          public function execute() {
00049                 $db = wfGetDB( DB_SLAVE );
00050                 $stdin = $this->getStdin();
00051                 while ( !feof( $stdin ) ) {
00052                         $line = fgets( $stdin );
00053                         if ( $line === false ) {
00054                                 // We appear to have lost contact...
00055                                 break;
00056                         }
00057                         $textId = intval( $line );
00058                         $text = $this->doGetText( $db, $textId );
00059                         if ($text === false) {
00060                                 # actual error, not zero-length text
00061                                 $textLen = "-1";
00062                         }
00063                         else {
00064                                 $textLen = strlen($text);
00065                         }
00066                         $this->output( $textId . "\n" . $textLen . "\n" . $text );
00067                 }
00068         }
00069 
00076         private function doGetText( $db, $id ) {
00077                 $id = intval( $id );
00078                 $row = $db->selectRow( 'text',
00079                         array( 'old_text', 'old_flags' ),
00080                         array( 'old_id' => $id ),
00081                         __METHOD__ );
00082                 $text = Revision::getRevisionText( $row );
00083                 if ( $text === false ) {
00084                         return false;
00085                 }
00086                 return $text;
00087         }
00088 }
00089 
00090 $maintClass = "FetchText";
00091 require_once( RUN_MAINTENANCE_IF_MAIN );