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