3 * Makes the required database updates for rev_len
4 * to be of any use. It can be used for some simple tracking
5 * and to find new page edits by users.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup Maintenance
25 require_once( dirname(__FILE__
) . '/Maintenance.php' );
27 class PopulateRevisionLength
extends Maintenance
{
28 public function __construct() {
29 parent
::__construct();
30 $this->mDescription
= "Populates rev_len";
31 $this->setBatchSize( 200 );
34 public function execute() {
35 $db = wfGetDB( DB_MASTER
);
36 if ( !$db->tableExists( 'revision' ) ) {
37 $this->error( "revision table does not exist", true );
39 $this->output( "Populating rev_len column\n" );
40 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__
);
41 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__
);
42 if( is_null( $start ) ||
is_null( $end ) ){
43 $this->output( "...revision table seems to be empty.\n" );
44 $db->insert( 'updatelog',
45 array( 'ul_key' => 'populate rev_len' ),
51 $blockStart = intval( $start );
52 $blockEnd = intval( $start ) +
$this->mBatchSize
- 1;
54 while( $blockStart <= $end ) {
55 $this->output( "...doing rev_id from $blockStart to $blockEnd\n" );
56 $res = $db->select( 'revision',
57 Revision
::selectFields(),
58 array( "rev_id >= $blockStart",
59 "rev_id <= $blockEnd",
62 # Go through and update rev_len from these rows.
63 foreach( $res as $row ) {
64 $rev = new Revision( $row );
65 $text = $rev->getRawText();
67 $db->update( 'revision',
68 array( 'rev_len' => strlen( $text ) ),
69 array( 'rev_id' => $row->rev_id
),
73 $blockStart +
= $this->mBatchSize
;
74 $blockEnd +
= $this->mBatchSize
;
77 $logged = $db->insert( 'updatelog',
78 array( 'ul_key' => 'populate rev_len' ),
82 $this->output( "rev_len population complete ... {$count} rows changed\n" );
85 $this->output( "Could not insert rev_len population row.\n" );
91 $maintClass = "PopulateRevisionLength";
92 require_once( DO_MAINTENANCE
);