Update cssjanus/cssjanus to v1.1.2
[mediawiki.git] / maintenance / fetchText.php
blob983b772515d1483af268cdeb125baf83f6c19e16
1 <?php
2 /**
3 * Communications protocol.
4 * This is used by dumpTextPass.php when the --spawn option is present.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
21 * @file
22 * @ingroup Maintenance
25 require_once __DIR__ . '/Maintenance.php';
27 /**
28 * Maintenance script used to fetch page text in a subprocess.
30 * @ingroup Maintenance
32 class FetchText extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->mDescription = "Fetch the raw revision blob from an old_id.\n" .
36 "NOTE: Export transformations are NOT applied. " .
37 "This is left to backupTextPass.php";
40 /**
41 * returns a string containing the following in order:
42 * textid
43 * \n
44 * length of text (-1 on error = failure to retrieve/unserialize/gunzip/etc)
45 * \n
46 * text (may be empty)
48 * note that the text string itself is *not* followed by newline
50 public function execute() {
51 $db = wfGetDB( DB_SLAVE );
52 $stdin = $this->getStdin();
53 while ( !feof( $stdin ) ) {
54 $line = fgets( $stdin );
55 if ( $line === false ) {
56 // We appear to have lost contact...
57 break;
59 $textId = intval( $line );
60 $text = $this->doGetText( $db, $textId );
61 if ( $text === false ) {
62 # actual error, not zero-length text
63 $textLen = "-1";
64 } else {
65 $textLen = strlen( $text );
67 $this->output( $textId . "\n" . $textLen . "\n" . $text );
71 /**
72 * May throw a database error if, say, the server dies during query.
73 * @param DatabaseBase $db
74 * @param int $id The old_id
75 * @return string
77 private function doGetText( $db, $id ) {
78 $id = intval( $id );
79 $row = $db->selectRow( 'text',
80 array( 'old_text', 'old_flags' ),
81 array( 'old_id' => $id ),
82 __METHOD__ );
83 $text = Revision::getRevisionText( $row );
84 if ( $text === false ) {
85 return false;
88 return $text;
92 $maintClass = "FetchText";
93 require_once RUN_MAINTENANCE_IF_MAIN;