r104603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104602‎ | r104603 | r104604 >
Date:22:23, 29 November 2011
Author:malvineous
Status:deferred
Tags:
Comment:
[MassEditRegex] Update API calls to work with MW 1.18
Modified paths:
  • /trunk/extensions/MassEditRegex/MassEditRegex.class.php (modified) (history)
  • /trunk/extensions/MassEditRegex/MassEditRegex.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MassEditRegex/MassEditRegex.i18n.php
@@ -12,6 +12,7 @@
1313 * @author Adam Nielsen
1414 */
1515 $messages['en'] = array(
 16+ 'action-masseditregex' => 'perform a bulk edit',
1617 'masseditregex' => 'Mass edit using regular expressions',
1718 'masseditregex-desc' => 'Use regular expressions to [[Special:MassEditRegex|edit many pages in one operation]]',
1819 'masseditregextext' => 'Enter one or more regular expressions (one per line) for matching, and one or more expressions to replace each match with.
Index: trunk/extensions/MassEditRegex/MassEditRegex.class.php
@@ -121,7 +121,7 @@
122122 Xml::openElement('form', array(
123123 'id' => 'masseditregex',
124124 'method' => 'post',
125 - 'action' => $titleObj->escapeLocalURL('action=submit')
 125+ 'action' => $titleObj->getLocalURL('action=submit')
126126 )) .
127127 Xml::element('p',
128128 null, wfMsg( 'masseditregex-pagelisttxt' )
@@ -389,7 +389,7 @@
390390 }
391391
392392 function perform( $bPerformEdits = true ) {
393 - global $wgOut, $wgUser, $wgTitle, $wgLang;
 393+ global $wgRequest, $wgOut, $wgUser, $wgTitle, $wgLang;
394394
395395 $iMaxPerCriterion = $bPerformEdits ? MER_MAX_EXECUTE_PAGES : MER_MAX_PREVIEW_DIFFS;
396396 $aErrors = array();
@@ -405,28 +405,20 @@
406406 $diff = new DifferenceEngine();
407407 $diff->showDiffStyle(); // send CSS link to the browser for diff colours
408408
409 - // Save the state until the MW Edit API does it for us
410 - if ( $bPerformEdits ) {
411 - $o_wgOut = clone $wgOut; // need to do a deep copy here
412 - $wgOut->disable(); // not strictly necessary, but might speed things up
413 - $o_wgTitle = $wgTitle;
414 - } else {
415 - // No difference here, but having the same variable name simplifies code
416 - $o_wgOut = $wgOut;
417 - }
 409+ $wgOut->addHTML( '<ul>' );
418410
419 - $o_wgOut->addHTML( '<ul>' );
420 -
421411 if (count($aErrors))
422 - $o_wgOut->addHTML( '<li>' . join( '</li><li> ', $aErrors) . '</li>' );
 412+ $wgOut->addHTML( '<li>' . join( '</li><li> ', $aErrors) . '</li>' );
423413
424414 $htmlDiff = '';
425415
 416+ $editToken = $wgUser->editToken();
 417+
426418 $iArticleCount = 0;
427419 foreach ( $aPages as $p ) {
428420 $iArticleCount++;
429421 if ( !isset( $p['revisions'] ) ) {
430 - $o_wgOut->addHTML( '<li>'
 422+ $wgOut->addHTML( '<li>'
431423 . wfMsg( 'masseditregex-page-not-exists', $p['title'] )
432424 . '</li>' );
433425 continue; // empty page
@@ -442,32 +434,33 @@
443435 else {
444436 $strErrorMsg = '<li>' . wfMsg( 'masseditregex-badregex' ) . ' <b>'
445437 . htmlspecialchars($strMatch) . '</b></li>';
446 - $o_wgOut->addHTML( $strErrorMsg );
 438+ $wgOut->addHTML( $strErrorMsg );
447439 unset($this->aMatch[$i]);
448440 }
449441 }
450442
451443 if ( $bPerformEdits ) {
452444 // Not in preview mode, make the edits
453 - // print_r( $p );
454 - $o_wgOut->addHTML( '<li>' . wfMsg( 'masseditregex-num-changes',
 445+ $wgOut->addHTML( '<li>' . wfMsg( 'masseditregex-num-changes',
455446 $p['title'], $iCount ) . '</li>' );
456447
457 - $req = new FauxRequest( array(
 448+ $req = new DerivativeRequest( $wgRequest, array(
458449 'action' => 'edit',
459450 'bot' => true,
460 - 'token' => $p['edittoken'],
461451 'title' => $p['title'],
462452 'summary' => $this->strSummary,
463453 'text' => $newContent,
464 - 'basetimestamp' => $p['starttimestamp']
 454+ 'basetimestamp' => $p['starttimestamp'],
 455+ 'watchlist' => 'nochange',
 456+ 'nocreate' => 1,
 457+ 'token' => $editToken,
465458 ), true );
466459 $processor = new ApiMain( $req, true );
467460 try {
468461 $processor->execute();
469462 } catch ( UsageException $e ) {
470 - $o_wgOut->addHTML('<li><ul><li>' . wfMsg( 'masseditregex-editfailed')
471 - . $e . '</li></ul></li>'
 463+ $wgOut->addHTML('<li><ul><li>' . wfMsg( 'masseditregex-editfailed')
 464+ . ' ' . $e . '</li></ul></li>'
472465 );
473466 }
474467 } else {
@@ -489,13 +482,9 @@
490483
491484 }
492485
493 - $o_wgOut->addHTML( '</ul>' );
 486+ $wgOut->addHTML( '</ul>' );
494487
495488 if ( $bPerformEdits ) {
496 - // Restore the state after the Edit API has messed with it
497 - $wgTitle = $o_wgTitle;
498 - $wgOut = $o_wgOut;
499 -
500489 $wgOut->addWikiMsg( 'masseditregex-num-articles-changed', $iArticleCount );
501490 $wgOut->addHTML(
502491 $this->sk->makeKnownLinkObj(

Status & tagging log