3 * Communications protocol...
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 * @ingroup Maintenance
23 require_once( dirname( __FILE__
) . '/Maintenance.php' );
25 class FetchText
extends Maintenance
{
26 public function __construct() {
27 parent
::__construct();
28 $this->mDescription
= "Fetch the revision text from an old_id";
32 * returns a string containing the following in order:
35 * length of text (-1 on error = failure to retrieve/unserialize/gunzip/etc)
39 * note that that the text string itself is *not* followed by newline
41 public function execute() {
42 $db = wfGetDB( DB_SLAVE
);
43 $stdin = $this->getStdin();
44 while ( !feof( $stdin ) ) {
45 $line = fgets( $stdin );
46 if ( $line === false ) {
47 // We appear to have lost contact...
50 $textId = intval( $line );
51 $text = $this->doGetText( $db, $textId );
52 if ($text === false) {
53 # actual error, not zero-length text
57 $textLen = strlen($text);
59 $this->output( $textId . "\n" . $textLen . "\n" . $text );
64 * May throw a database error if, say, the server dies during query.
65 * @param $db DatabaseBase object
66 * @param $id int The old_id
69 private function doGetText( $db, $id ) {
71 $row = $db->selectRow( 'text',
72 array( 'old_text', 'old_flags' ),
73 array( 'old_id' => $id ),
75 $text = Revision
::getRevisionText( $row );
76 if ( $text === false ) {
83 $maintClass = "FetchText";
84 require_once( RUN_MAINTENANCE_IF_MAIN
);