Stylize maintenance folder..
[lhc/web/wiklou.git] / maintenance / fetchText.php
1 <?php
2 /**
3 * Communications protocol...
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 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class FetchText extends Maintenance {
26 public function __construct() {
27 parent::__construct();
28 $this->mDescription = "Fetch the revision text from an old_id";
29 }
30
31 public function execute() {
32 $db = wfGetDB( DB_SLAVE );
33 $stdin = $this->getStdin();
34 while ( !feof( $stdin ) ) {
35 $line = fgets( $stdin );
36 if ( $line === false ) {
37 // We appear to have lost contact...
38 break;
39 }
40 $textId = intval( $line );
41 $text = $this->doGetText( $db, $textId );
42 $this->output( strlen( $text ) . "\n" . $text );
43 }
44 }
45
46 /**
47 * May throw a database error if, say, the server dies during query.
48 * @param $db Database object
49 * @param $id int The old_id
50 * @return String
51 */
52 private function doGetText( $db, $id ) {
53 $id = intval( $id );
54 $row = $db->selectRow( 'text',
55 array( 'old_text', 'old_flags' ),
56 array( 'old_id' => $id ),
57 'TextPassDumper::getText' );
58 $text = Revision::getRevisionText( $row );
59 if ( $text === false ) {
60 return false;
61 }
62 return $text;
63 }
64 }
65
66 $maintClass = "FetchText";
67 require_once( DO_MAINTENANCE );