Merge "Revert "Use display name in category page subheadings if provided""
[lhc/web/wiklou.git] / maintenance / storage / dumpRev.php
1 <?php
2 /**
3 * Get the text of a revision, resolving external storage if needed.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Maintenance ExternalStorage
22 */
23
24 require_once __DIR__ . '/../Maintenance.php';
25
26 /**
27 * Maintenance script that gets the text of a revision,
28 * resolving external storage if needed.
29 *
30 * @ingroup Maintenance ExternalStorage
31 */
32 class DumpRev extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addArg( 'rev-id', 'Revision ID', true );
36 }
37
38 public function execute() {
39 $dbr = $this->getDB( DB_REPLICA );
40 $row = $dbr->selectRow(
41 [ 'text', 'revision' ],
42 [ 'old_flags', 'old_text' ],
43 [ 'old_id=rev_text_id', 'rev_id' => $this->getArg() ]
44 );
45 if ( !$row ) {
46 $this->error( "Row not found", true );
47 }
48
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;
64 }
65 } else {
66 $this->output( "External plain $text\n" );
67 $text = ExternalStore::fetchFromURL( $text );
68 }
69 }
70 if ( in_array( 'gzip', $flags ) ) {
71 $text = gzinflate( $text );
72 }
73 if ( in_array( 'object', $flags ) ) {
74 $obj = unserialize( $text );
75 $text = $obj->getText();
76 }
77
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" );
83 }
84 }
85 }
86
87 $maintClass = "DumpRev";
88 require_once RUN_MAINTENANCE_IF_MAIN;