Implement a number of namespace related equals functions:
[mediawiki.git] / maintenance / fetchText.php
blob3b43bcd503cb781d852f80a53f742779000e5e20
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 * @ingroup Maintenance
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
26 class FetchText extends Maintenance {
27 public function __construct() {
28 parent::__construct();
29 $this->mDescription = "Fetch the revision text from an old_id";
32 /**
33 * returns a string containing the following in order:
34 * textid
35 * \n
36 * length of text (-1 on error = failure to retrieve/unserialize/gunzip/etc)
37 * \n
38 * text (may be empty)
40 * note that that the text string itself is *not* followed by newline
42 public function execute() {
43 $db = wfGetDB( DB_SLAVE );
44 $stdin = $this->getStdin();
45 while ( !feof( $stdin ) ) {
46 $line = fgets( $stdin );
47 if ( $line === false ) {
48 // We appear to have lost contact...
49 break;
51 $textId = intval( $line );
52 $text = $this->doGetText( $db, $textId );
53 if ($text === false) {
54 # actual error, not zero-length text
55 $textLen = "-1";
57 else {
58 $textLen = strlen($text);
60 $this->output( $textId . "\n" . $textLen . "\n" . $text );
64 /**
65 * May throw a database error if, say, the server dies during query.
66 * @param $db DatabaseBase object
67 * @param $id int The old_id
68 * @return String
70 private function doGetText( $db, $id ) {
71 $id = intval( $id );
72 $row = $db->selectRow( 'text',
73 array( 'old_text', 'old_flags' ),
74 array( 'old_id' => $id ),
75 __METHOD__ );
76 $text = Revision::getRevisionText( $row );
77 if ( $text === false ) {
78 return false;
80 return $text;
84 $maintClass = "FetchText";
85 require_once( RUN_MAINTENANCE_IF_MAIN );