00001 <?php
00021 require_once( dirname(__FILE__) . '/../Maintenance.php' );
00022
00023 class DumpRev extends Maintenance {
00024 public function __construct() {
00025 parent::__construct();
00026 $this->addArg( 'rev-id', 'Revision ID', true );
00027 }
00028
00029 public function execute() {
00030 $dbr = wfGetDB( DB_SLAVE );
00031 $row = $dbr->selectRow(
00032 array( 'text', 'revision' ),
00033 array( 'old_flags', 'old_text' ),
00034 array( 'old_id=rev_text_id', 'rev_id' => $this->getArg() )
00035 );
00036 if ( !$row ) {
00037 $this->error( "Row not found", true );
00038 }
00039
00040 $flags = explode( ',', $row->old_flags );
00041 $text = $row->old_text;
00042 if ( in_array( 'external', $flags ) ) {
00043 $this->output( "External $text\n" );
00044 if ( preg_match( '!^DB://(\w+)/(\w+)/(\w+)$!', $text, $m ) ) {
00045 $es = ExternalStore::getStoreObject( 'DB' );
00046 $blob = $es->fetchBlob( $m[1], $m[2], $m[3] );
00047 if ( strtolower( get_class( $blob ) ) == 'concatenatedgziphistoryblob' ) {
00048 $this->output( "Found external CGZ\n" );
00049 $blob->uncompress();
00050 $this->output( "Items: (" . implode( ', ', array_keys( $blob->mItems ) ) . ")\n" );
00051 $text = $blob->getItem( $m[3] );
00052 } else {
00053 $this->output( "CGZ expected at $text, got " . gettype( $blob ) . "\n" );
00054 $text = $blob;
00055 }
00056 } else {
00057 $this->output( "External plain $text\n" );
00058 $text = ExternalStore::fetchFromURL( $text );
00059 }
00060 }
00061 if ( in_array( 'gzip', $flags ) ) {
00062 $text = gzinflate( $text );
00063 }
00064 if ( in_array( 'object', $flags ) ) {
00065 $obj = unserialize( $text );
00066 $text = $obj->getText();
00067 }
00068
00069 if ( is_object( $text ) ) {
00070 $this->error( "Unexpectedly got object of type: " . get_class( $text ) );
00071 } else {
00072 $this->output( "Text length: " . strlen( $text ) ."\n" );
00073 $this->output( substr( $text, 0, 100 ) . "\n" );
00074 }
00075 }
00076 }
00077
00078 $maintClass = "DumpRev";
00079 require_once( DO_MAINTENANCE );