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