~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to include/SpecialRenameuser_body.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
if ( !defined( 'MEDIAWIKI' ) ) {
4
 
        echo "RenameUser extension\n";
5
 
        exit( 1 );
6
 
}
7
 
 
8
 
# Add messages
9
 
wfLoadExtensionMessages( 'Renameuser' );
10
 
 
11
 
/**
12
 
 * Special page allows authorised users to rename
13
 
 * user accounts
14
 
 */
15
 
class SpecialRenameuser extends SpecialPage {
16
 
 
17
 
        /**
18
 
         * Constructor
19
 
         */
20
 
        public function __construct() {
21
 
                parent::__construct( 'Renameuser', 'renameuser' );
22
 
        }
23
 
 
24
 
        /**
25
 
         * Show the special page
26
 
         *
27
 
         * @param mixed $par Parameter passed to the page
28
 
         */
29
 
        public function execute( $par ) {
30
 
                global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang;
31
 
                global $wgVersion, $wgMaxNameChars, $wgCapitalLinks;
32
 
 
33
 
                $this->setHeaders();
34
 
                $wgOut->addWikiMsg( 'renameuser-summary' );
35
 
 
36
 
                if( !$wgUser->isAllowed( 'renameuser' ) ) {
37
 
                        $wgOut->permissionRequired( 'renameuser' );
38
 
                        return;
39
 
                }
40
 
                if( wfReadOnly() ) {
41
 
                        $wgOut->readOnlyPage();
42
 
                        return;
43
 
                }
44
 
 
45
 
                $showBlockLog = $wgRequest->getBool( 'submit-showBlockLog' );
46
 
                $oldnamePar = trim( str_replace( '_', ' ', $wgRequest->getText( 'oldusername' ) ) );
47
 
                $oldusername = Title::makeTitle( NS_USER, $oldnamePar );
48
 
                // Force uppercase of newusername, otherwise wikis with wgCapitalLinks=false can create lc usernames
49
 
                $newusername = Title::makeTitleSafe( NS_USER, $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ) );
50
 
                $oun = is_object( $oldusername ) ? $oldusername->getText() : '';
51
 
                $nun = is_object( $newusername ) ? $newusername->getText() : '';
52
 
                $token = $wgUser->editToken();
53
 
                $reason = $wgRequest->getText( 'reason' );
54
 
                // If nothing given for these flags, assume they are checked
55
 
                // unless this is a POST submission.
56
 
                $move_checked = true;
57
 
                if( $wgRequest->wasPosted() ) {
58
 
                        if( !$wgRequest->getCheck( 'movepages' ) ) {
59
 
                                $move_checked = false;
60
 
                        }
61
 
                }
62
 
                $warnings = array();
63
 
                if( $oun && $nun && !$wgRequest->getCheck( 'confirmaction' )  ) {
64
 
                        wfRunHooks( 'RenameUserWarning', array( $oun, $nun, &$warnings ) );
65
 
                }
66
 
 
67
 
                $wgOut->addHTML( "
68
 
                        <!-- Current contributions limit is " . RENAMEUSER_CONTRIBLIMIT . " -->" .
69
 
                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $wgTitle->getLocalUrl(), 'id' => 'renameuser' ) ) .
70
 
                        Xml::openElement( 'fieldset' ) .
71
 
                        Xml::element( 'legend', null, wfMsg( 'renameuser' ) ) .
72
 
                        Xml::openElement( 'table', array( 'id' => 'mw-renameuser-table' ) ) .
73
 
                        "<tr>
74
 
                                <td class='mw-label'>" .
75
 
                                        Xml::label( wfMsg( 'renameuserold' ), 'oldusername' ) .
76
 
                                "</td>
77
 
                                <td class='mw-input'>" .
78
 
                                        Xml::input( 'oldusername', 20, $oun, array( 'type' => 'text', 'tabindex' => '1' ) ) . ' ' .
79
 
                                "</td>
80
 
                        </tr>
81
 
                        <tr>
82
 
                                <td class='mw-label'>" .
83
 
                                        Xml::label( wfMsg( 'renameusernew' ), 'newusername' ) .
84
 
                                "</td>
85
 
                                <td class='mw-input'>" .
86
 
                                        Xml::input( 'newusername', 20, $nun, array( 'type' => 'text', 'tabindex' => '2' ) ) .
87
 
                                "</td>
88
 
                        </tr>
89
 
                        <tr>
90
 
                                <td class='mw-label'>" .
91
 
                                        Xml::label( wfMsg( 'renameuserreason' ), 'reason' ) .
92
 
                                "</td>
93
 
                                <td class='mw-input'>" .
94
 
                                        Xml::input( 'reason', 40, $reason, array( 'type' => 'text', 'tabindex' => '3', 'maxlength' => 255 ) ) .
95
 
                                "</td>
96
 
                        </tr>"
97
 
                );
98
 
                if( $wgUser->isAllowed( 'move' ) ) {
99
 
                        $wgOut->addHTML( "
100
 
                                <tr>
101
 
                                        <td>&nbsp;
102
 
                                        </td>
103
 
                                        <td class='mw-input'>" .
104
 
                                                Xml::checkLabel( wfMsg( 'renameusermove' ), 'movepages', 'movepages', 
105
 
                                                        $move_checked, array( 'tabindex' => '4' ) ) .
106
 
                                        "</td>
107
 
                                </tr>"
108
 
                        );
109
 
                }
110
 
                if( $warnings ) {
111
 
                        $warningsHtml = array();
112
 
                        foreach( $warnings as $warning )
113
 
                                $warningsHtml[] = is_array( $warning ) ?
114
 
                                        call_user_func_array( 'wfMsgWikiHtml', $warning ) :
115
 
                                        wfMsgHtml( $warning );
116
 
                        $wgOut->addHTML( "
117
 
                                <tr>
118
 
                                        <td class='mw-label'>" . wfMsgWikiHtml( 'renameuserwarnings' ) . "
119
 
                                        </td>
120
 
                                        <td class='mw-input'>" .
121
 
                                                '<ul style="color: red; font-weight: bold"><li>'.
122
 
                                                        implode( '</li><li>', $warningsHtml ).'</li></ul>'.
123
 
                                        "</td>
124
 
                                </tr>"
125
 
                        );
126
 
                        $wgOut->addHTML( "
127
 
                                <tr>
128
 
                                        <td>&nbsp;
129
 
                                        </td>
130
 
                                        <td class='mw-input'>" .
131
 
                                                Xml::checkLabel( wfMsg( 'renameuserconfirm' ), 'confirmaction', 'confirmaction', 
132
 
                                                        false, array( 'tabindex' => '6' ) ) .
133
 
                                        "</td>
134
 
                                </tr>"
135
 
                        );
136
 
                }
137
 
                $wgOut->addHTML( "
138
 
                        <tr>
139
 
                                <td>&nbsp;
140
 
                                </td>
141
 
                                <td class='mw-submit'>" .
142
 
                                        Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 
143
 
                                                'tabindex' => '7', 'id' => 'submit' ) ) .
144
 
                                        ' ' .
145
 
                                        Xml::submitButton( wfMsg( 'blocklogpage' ), array ( 'name' => 'submit-showBlockLog', 
146
 
                                                'id' => 'submit-showBlockLog', 'tabindex' => '8' ) ) .
147
 
                                "</td>
148
 
                        </tr>" .
149
 
                        Xml::closeElement( 'table' ) .
150
 
                        Xml::closeElement( 'fieldset' ) .
151
 
                        Xml::hidden( 'token', $token ) .
152
 
                        Xml::closeElement( 'form' ) . "\n"
153
 
                );
154
 
 
155
 
                // Show block log if requested
156
 
                if( $showBlockLog && is_object( $oldusername ) ) {
157
 
                        $this->showLogExtract( $oldusername, 'block', $wgOut ) ;
158
 
                        return;
159
 
                }
160
 
 
161
 
                if( $wgRequest->getText( 'token' ) === '' ) {
162
 
                        # They probably haven't even submitted the form, so don't go further.
163
 
                        return;
164
 
                } elseif( $warnings ) {
165
 
                        # Let user read warnings
166
 
                        return;
167
 
                } elseif( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
168
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameuser-error-request' ) . "</div>" );
169
 
                        return;
170
 
                } elseif( !is_object( $oldusername ) ) {
171
 
                        $wgOut->addWikiText(
172
 
                                "<div class=\"errorbox\">"
173
 
                                . wfMsg( 'renameusererrorinvalid', $wgRequest->getText( 'oldusername' ) )
174
 
                                . "</div>"
175
 
                        );
176
 
                        return;
177
 
                } elseif( !is_object( $newusername ) ) {
178
 
                        $wgOut->addWikiText(
179
 
                                "<div class=\"errorbox\">"
180
 
                                . wfMsg( 'renameusererrorinvalid', $wgRequest->getText( 'newusername' ) )
181
 
                                . "</div>"
182
 
                        );
183
 
                        return;
184
 
                } elseif( $oldusername->getText() == $newusername->getText() ) {
185
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameuser-error-same-user' ) . "</div>" );
186
 
                        return;
187
 
                }
188
 
 
189
 
                // Suppress username validation of old username
190
 
                $olduser = User::newFromName( $oldusername->getText(), false );
191
 
                $newuser = User::newFromName( $newusername->getText(), 'creatable' );
192
 
 
193
 
                // It won't be an object if for instance "|" is supplied as a value
194
 
                if( !is_object( $olduser ) ) {
195
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', 
196
 
                                $oldusername->getText() ) . "</div>" );
197
 
                        return;
198
 
                }
199
 
                if( !is_object( $newuser ) || !User::isCreatableName( $newuser->getName() ) ) {
200
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', 
201
 
                                $newusername->getText() ) . "</div>" );
202
 
                        return;
203
 
                }
204
 
 
205
 
                // Check for the existence of lowercase oldusername in database.
206
 
                // Until r19631 it was possible to rename a user to a name with first character as lowercase
207
 
                if( $oldusername->getText() !== $wgContLang->ucfirst( $oldusername->getText() ) ) {
208
 
                        // oldusername was entered as lowercase -> check for existence in table 'user'
209
 
                        $dbr = wfGetDB( DB_SLAVE );
210
 
                        $uid = $dbr->selectField( 'user', 'user_id', 
211
 
                                array( 'user_name' => $oldusername->getText() ), 
212
 
                                __METHOD__ );
213
 
                        if( $uid === false ) {
214
 
                                if( !$wgCapitalLinks ) {
215
 
                                        $uid = 0; // We are on a lowercase wiki but lowercase username does not exists
216
 
                                } else {
217
 
                                        // We are on a standard uppercase wiki, use normal
218
 
                                        $uid = $olduser->idForName();
219
 
                                        $oldusername = Title::makeTitleSafe( NS_USER, $olduser->getName() );
220
 
                                }
221
 
                        }
222
 
                } else {
223
 
                        // oldusername was entered as upperase -> standard procedure
224
 
                        $uid = $olduser->idForName();
225
 
                }
226
 
 
227
 
                if( $uid == 0 ) {
228
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrordoesnotexist' , 
229
 
                                $oldusername->getText() ) . "</div>" );
230
 
                        return;
231
 
                }
232
 
 
233
 
                if( $newuser->idForName() != 0 ) {
234
 
                        $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorexists', 
235
 
                                $newusername->getText() ) . "</div>" );
236
 
                        return;
237
 
                }
238
 
 
239
 
                // Always get the edits count, it will be used for the log message
240
 
                $contribs = User::edits( $uid );
241
 
 
242
 
                // Check edit count
243
 
                if( !$wgUser->isAllowed( 'siteadmin' ) ) {
244
 
                        if ( RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT ) {
245
 
                                $wgOut->addWikiText( "<div class=\"errorbox\">" . 
246
 
                                        wfMsg( 'renameusererrortoomany',
247
 
                                                $oldusername->getText(),
248
 
                                                $wgLang->formatNum( $contribs ),
249
 
                                                $wgLang->formatNum( RENAMEUSER_CONTRIBLIMIT )
250
 
                                        )
251
 
                                 . "</div>" );
252
 
                                return;
253
 
                        }
254
 
                }
255
 
 
256
 
                // Give other affected extensions a chance to validate or abort
257
 
                if( !wfRunHooks( 'RenameUserAbort', array( $uid, $oldusername->getText(), $newusername->getText() ) ) ) {
258
 
                        return;
259
 
                }
260
 
 
261
 
                // Do the heavy lifting...
262
 
                $rename = new RenameuserSQL( $oldusername->getText(), $newusername->getText(), $uid );
263
 
                if( !$rename->rename() ) {
264
 
                        return;
265
 
                }
266
 
                
267
 
                // If this user is renaming his/herself, make sure that Title::moveTo()
268
 
                // doesn't make a bunch of null move edits under the old name!
269
 
                if( $wgUser->getId() == $uid ) {
270
 
                        $wgUser->setName( $newusername->getText() );
271
 
                }
272
 
 
273
 
                // Log this rename
274
 
                $log = new LogPage( 'renameuser' );
275
 
                $log->addEntry( 'renameuser', $oldusername, wfMsgExt( 'renameuser-log', array( 'parsemag', 'content' ), 
276
 
                        $wgContLang->formatNum( $contribs ), $reason ), $newusername->getText() );
277
 
 
278
 
                // Move any user pages
279
 
                if( $wgRequest->getCheck( 'movepages' ) && $wgUser->isAllowed( 'move' ) ) {
280
 
                        $dbr = wfGetDB( DB_SLAVE );
281
 
                        $oldkey = $oldusername->getDBkey();
282
 
                        $pages = $dbr->select(
283
 
                                'page',
284
 
                                array( 'page_namespace', 'page_title' ),
285
 
                                array(
286
 
                                        'page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')',
287
 
                                        '(page_title LIKE ' . 
288
 
                                                $dbr->addQuotes( $dbr->escapeLike( $oldusername->getDBkey() ) . '/%' ) . 
289
 
                                                ' OR page_title = ' . $dbr->addQuotes( $oldusername->getDBkey() ) . ')'
290
 
                                ),
291
 
                                __METHOD__
292
 
                        );
293
 
 
294
 
                        $output = '';
295
 
                        $skin =& $wgUser->getSkin();
296
 
                        while ( $row = $dbr->fetchObject( $pages ) ) {
297
 
                                $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
298
 
                                $newPage = Title::makeTitleSafe( $row->page_namespace, 
299
 
                                        preg_replace( '!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
300
 
                                # Do not autodelete or anything, title must not exist
301
 
                                if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
302
 
                                        $link = $skin->makeKnownLinkObj( $newPage );
303
 
                                        $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml( 'renameuser-page-exists', $link ) . '</li>';
304
 
                                } else {
305
 
                                        $success = $oldPage->moveTo( $newPage, false, wfMsgForContent( 'renameuser-move-log', 
306
 
                                                $oldusername->getText(), $newusername->getText() ) );
307
 
                                        if( $success === true ) {
308
 
                                                $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
309
 
                                                $newLink = $skin->makeKnownLinkObj( $newPage );
310
 
                                                $output .= '<li class="mw-renameuser-pm">' . wfMsgHtml( 'renameuser-page-moved', $oldLink, $newLink ) . '</li>';
311
 
                                        } else {
312
 
                                                $oldLink = $skin->makeKnownLinkObj( $oldPage );
313
 
                                                $newLink = $skin->makeLinkObj( $newPage );
314
 
                                                $output .= '<li class="mw-renameuser-pu">' . wfMsgHtml( 'renameuser-page-unmoved', $oldLink, $newLink ) . '</li>';
315
 
                                        }
316
 
                                }
317
 
                        }
318
 
                        if( $output )
319
 
                                $wgOut->addHTML( '<ul>' . $output . '</ul>' );
320
 
                }
321
 
                
322
 
                // Output success message stuff :)
323
 
                $wgOut->addWikiText( "<div class=\"successbox\">" . wfMsg( 'renameusersuccess', $oldusername->getText(), 
324
 
                $newusername->getText() ) . "</div><br style=\"clear:both\" />" );
325
 
        }
326
 
 
327
 
        function showLogExtract( $username, $type, &$out ) {
328
 
                # Show relevant lines from the logs:
329
 
                $out->addHTML( Xml::element( 'h2', null, LogPage::logName( $type ) ) . "\n" );
330
 
                LogEventsList::showLogExtract( $out, $type, $username->getPrefixedText() );
331
 
        }
332
 
}
333
 
 
334
 
class RenameuserSQL {
335
 
        
336
 
        /**
337
 
          * The old username
338
 
          *
339
 
          * @var string
340
 
          * @access private
341
 
          */
342
 
        var $old;
343
 
 
344
 
        /**
345
 
          * The new username
346
 
          *
347
 
          * @var string
348
 
          * @access private
349
 
          */
350
 
        var $new;
351
 
 
352
 
        /**
353
 
          * The user ID
354
 
          *
355
 
          * @var integer
356
 
          * @access private
357
 
          */
358
 
        var $uid;
359
 
 
360
 
        /**
361
 
          * The the tables => fields to be updated
362
 
          *
363
 
          * @var array
364
 
          * @access private
365
 
          */
366
 
        var $tables;
367
 
 
368
 
        /**
369
 
         * Constructor
370
 
         *
371
 
         * @param string $old The old username
372
 
         * @param string $new The new username
373
 
         */
374
 
        function RenameuserSQL($old, $new, $uid) {
375
 
                $this->old = $old;
376
 
                $this->new = $new;
377
 
                $this->uid = $uid;
378
 
                
379
 
                $this->tables = array(); // Immediate updates
380
 
                $this->tables['image'] = array('img_user_text','img_user');
381
 
                $this->tables['oldimage'] = array('oi_user_text','oi_user');
382
 
                # FIXME: $this->tables['filearchive'] = array('fa_user_text','fa_user'); (not indexed yet)
383
 
                $this->tablesJob = array(); // Slow updates
384
 
                // If this user has a large number of edits, use the jobqueue
385
 
                if( User::edits($this->uid) > RENAMEUSER_CONTRIBJOB ) {
386
 
                        $this->tablesJob['revision'] = array('rev_user_text','rev_user','rev_timestamp');
387
 
                        $this->tablesJob['archive'] = array('ar_user_text','ar_user','ar_timestamp');
388
 
                } else {
389
 
                        $this->tables['revision'] = array('rev_user_text','rev_user');
390
 
                        $this->tables['archive'] = array('ar_user_text','ar_user');
391
 
                }
392
 
                // Recent changes is pretty hot, deadlocks occur if done all at once
393
 
                if( wfQueriesMustScale() ) {
394
 
                        $this->tablesJob['recentchanges'] = array('rc_user_text','rc_user','rc_timestamp');
395
 
                } else {
396
 
                        $this->tables['recentchanges'] = array('rc_user_text','rc_user');
397
 
                }
398
 
        }
399
 
 
400
 
        /**
401
 
         * Do the rename operation
402
 
         */
403
 
        function rename() {
404
 
                global $wgMemc, $wgDBname, $wgAuth;
405
 
 
406
 
                wfProfileIn( __METHOD__ );
407
 
 
408
 
                wfRunHooks( 'RenameUserPreRename', array( $this->uid, $this->old, $this->new ) );
409
 
 
410
 
                $dbw = wfGetDB( DB_MASTER );
411
 
                // Rename and touch the user before re-attributing edits,
412
 
                // this avoids users still being logged in and making new edits while
413
 
                // being renamed, which leaves edits at the old name.
414
 
                $dbw->update( 'user',
415
 
                        array( 'user_name' => $this->new, 'user_touched' => $dbw->timestamp() ), 
416
 
                        array( 'user_name' => $this->old ),
417
 
                        __METHOD__
418
 
                );
419
 
                if( !$dbw->affectedRows() ) {
420
 
                        return false;
421
 
                }
422
 
                // Reset token to break login with central auth systems.
423
 
                // Again, avoids user being logged in with old name.
424
 
                $user = User::newFromId( $this->uid );
425
 
                $authUser = $wgAuth->getUserInstance( $user );
426
 
                $authUser->resetAuthToken();
427
 
 
428
 
                // Delete from memcached.
429
 
                global $wgMemc;
430
 
                $wgMemc->delete( wfMemcKey( 'user', 'id', $this->uid ) );
431
 
 
432
 
                // Update ipblock list if this user has a block in there.
433
 
                $dbw->update( 'ipblocks',
434
 
                        array( 'ipb_address' => $this->new ),
435
 
                        array( 'ipb_user' => $this->uid, 'ipb_address' => $this->old ),
436
 
                        __METHOD__ );
437
 
                // Update this users block/rights log. Ideally, the logs would be historical,
438
 
                // but it is really annoying when users have "clean" block logs by virtue of
439
 
                // being renamed, which makes admin tasks more of a pain...
440
 
                $oldTitle = Title::makeTitle( NS_USER, $this->old );
441
 
                $newTitle = Title::makeTitle( NS_USER, $this->new );
442
 
                $dbw->update( 'logging',
443
 
                        array( 'log_title' => $newTitle->getDBKey() ),
444
 
                        array( 'log_type' => array( 'block', 'rights' ),
445
 
                                'log_namespace' => NS_USER,
446
 
                                'log_title' => $oldTitle->getDBKey() ),
447
 
                        __METHOD__ );
448
 
                // Do immediate updates!
449
 
                foreach( $this->tables as $table => $fieldSet ) {
450
 
                        list($nameCol,$userCol) = $fieldSet;
451
 
                        $dbw->update( $table,
452
 
                                array( $nameCol => $this->new ),
453
 
                                array( $nameCol => $this->old, $userCol => $this->uid ),
454
 
                                __METHOD__
455
 
                        );
456
 
                }
457
 
                // Construct jobqueue updates...
458
 
                // FIXME: if a bureaucrat renames a user in error, he/she
459
 
                // must be careful to wait until the rename finishes before
460
 
                // renaming back. This is due to the fact the the job "queue"
461
 
                // is not really FIFO, so we might end up with a bunch of edits
462
 
                // randomly mixed between the two new names. Some sort of rename
463
 
                // lock might be in order...
464
 
                foreach( $this->tablesJob as $table => $params ) {
465
 
                        $userTextC = $params[0]; // some *_user_text column
466
 
                        $userIDC = $params[1]; // some *_user column
467
 
                        $timestampC = $params[2]; // some *_timestamp column
468
 
 
469
 
                        $res = $dbw->select( $table,
470
 
                                array( $userTextC, $timestampC ),
471
 
                                array( $userTextC => $this->old, $userIDC => $this->uid ),
472
 
                                __METHOD__,
473
 
                                array( 'ORDER BY' => "$timestampC ASC" )
474
 
                        );
475
 
 
476
 
                        global $wgUpdateRowsPerJob;
477
 
 
478
 
                        $batchSize = 500; // Lets not flood the job table!
479
 
                        $jobSize = $wgUpdateRowsPerJob; // How many rows per job?
480
 
 
481
 
                        $jobParams = array();
482
 
                        $jobParams['table'] = $table;
483
 
                        $jobParams['column'] = $userTextC;
484
 
                        $jobParams['uidColumn'] = $userIDC;
485
 
                        $jobParams['timestampColumn'] = $timestampC;
486
 
                        $jobParams['oldname'] = $this->old;
487
 
                        $jobParams['newname'] = $this->new;
488
 
                        $jobParams['userID'] = $this->uid;
489
 
                        // Timestamp column data for index optimizations
490
 
                        $jobParams['minTimestamp'] = '0';
491
 
                        $jobParams['maxTimestamp'] = '0';
492
 
                        $jobParams['count'] = 0;
493
 
                        
494
 
                        // Insert into queue!
495
 
                        $jobRows = 0;
496
 
                        $done = false;
497
 
                        while ( !$done ) {
498
 
                                $jobs = array();
499
 
                                for ( $i = 0; $i < $batchSize; $i++ ) {
500
 
                                        $row = $dbw->fetchObject( $res );
501
 
                                        if ( !$row ) {
502
 
                                                # If there are any job rows left, add it to the queue as one job
503
 
                                                if( $jobRows > 0 ) {
504
 
                                                        $jobParams['count'] = $jobRows;
505
 
                                                        $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams );
506
 
                                                        $jobParams['minTimestamp'] = '0';
507
 
                                                        $jobParams['maxTimestamp'] = '0';
508
 
                                                        $jobParams['count'] = 0;
509
 
                                                        $jobRows = 0;
510
 
                                                }
511
 
                                                $done = true;
512
 
                                                break;
513
 
                                        }
514
 
                                        # If we are adding the first item, since the ORDER BY is ASC, set
515
 
                                        # the min timestamp
516
 
                                        if( $jobRows == 0 ) {
517
 
                                                $jobParams['minTimestamp'] = $row->$timestampC;
518
 
                                        }
519
 
                                        # Keep updating the last timestamp, so it should be correct when the last item is added.
520
 
                                        $jobParams['maxTimestamp'] = $row->$timestampC;
521
 
                                        # Update nice counter
522
 
                                        $jobRows++;
523
 
                                        # Once a job has $jobSize rows, add it to the queue
524
 
                                        if( $jobRows >= $jobSize ) {
525
 
                                                $jobParams['count'] = $jobRows;
526
 
                                                $jobs[] = Job::factory( 'renameUser', $oldTitle, $jobParams );
527
 
                                                $jobParams['minTimestamp'] = '0';
528
 
                                                $jobParams['maxTimestamp'] = '0';
529
 
                                                $jobParams['count'] = 0;
530
 
                                                $jobRows = 0;
531
 
                                        }
532
 
                                }
533
 
                                Job::batchInsert( $jobs );
534
 
                        }
535
 
                        $dbw->freeResult( $res );
536
 
                }
537
 
 
538
 
                // Clear caches and inform authentication plugins
539
 
                $user = User::newFromId( $this->uid );
540
 
                $wgAuth->updateExternalDB( $user );
541
 
                wfRunHooks( 'RenameUserComplete', array( $this->uid, $this->old, $this->new ) );
542
 
 
543
 
                wfProfileOut( __METHOD__ );
544
 
                return true;
545
 
        }
546
 
}