clear magicword cache before testing cleanSig
[lhc/web/wiklou.git] / maintenance / storage / dumpRev.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @ingroup Maintenance ExternalStorage
19 */
20
21 require_once( __DIR__ . '/../Maintenance.php' );
22
23 class DumpRev extends Maintenance {
24 public function __construct() {
25 parent::__construct();
26 $this->addArg( 'rev-id', 'Revision ID', true );
27 }
28
29 public function execute() {
30 $dbr = wfGetDB( DB_SLAVE );
31 $row = $dbr->selectRow(
32 array( 'text', 'revision' ),
33 array( 'old_flags', 'old_text' ),
34 array( 'old_id=rev_text_id', 'rev_id' => $this->getArg() )
35 );
36 if ( !$row ) {
37 $this->error( "Row not found", true );
38 }
39
40 $flags = explode( ',', $row->old_flags );
41 $text = $row->old_text;
42 if ( in_array( 'external', $flags ) ) {
43 $this->output( "External $text\n" );
44 if ( preg_match( '!^DB://(\w+)/(\w+)/(\w+)$!', $text, $m ) ) {
45 $es = ExternalStore::getStoreObject( 'DB' );
46 $blob = $es->fetchBlob( $m[1], $m[2], $m[3] );
47 if ( strtolower( get_class( $blob ) ) == 'concatenatedgziphistoryblob' ) {
48 $this->output( "Found external CGZ\n" );
49 $blob->uncompress();
50 $this->output( "Items: (" . implode( ', ', array_keys( $blob->mItems ) ) . ")\n" );
51 $text = $blob->getItem( $m[3] );
52 } else {
53 $this->output( "CGZ expected at $text, got " . gettype( $blob ) . "\n" );
54 $text = $blob;
55 }
56 } else {
57 $this->output( "External plain $text\n" );
58 $text = ExternalStore::fetchFromURL( $text );
59 }
60 }
61 if ( in_array( 'gzip', $flags ) ) {
62 $text = gzinflate( $text );
63 }
64 if ( in_array( 'object', $flags ) ) {
65 $obj = unserialize( $text );
66 $text = $obj->getText();
67 }
68
69 if ( is_object( $text ) ) {
70 $this->error( "Unexpectedly got object of type: " . get_class( $text ) );
71 } else {
72 $this->output( "Text length: " . strlen( $text ) . "\n" );
73 $this->output( substr( $text, 0, 100 ) . "\n" );
74 }
75 }
76 }
77
78 $maintClass = "DumpRev";
79 require_once( RUN_MAINTENANCE_IF_MAIN );