r82210 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82209‎ | r82210 | r82211 >
Date:03:04, 16 February 2011
Author:yaron
Status:deferred (Comments)
Tags:
Comment:
Added handling for regular expressions
Modified paths:
  • /trunk/extensions/ReplaceText/ReplaceTextJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ReplaceText/ReplaceTextJob.php
@@ -1,10 +1,11 @@
2 -<?php
 2+<?php
33
44 /**
55 * Background job to replace text in a given page
66 * - based on /includes/RefreshLinksJob.php
77 *
88 * @author Yaron Koren
 9+ * @author Ankit Garg
910 */
1011 class ReplaceTextJob extends Job {
1112
@@ -30,7 +31,12 @@
3132 $actual_user = $wgUser;
3233 $wgUser = User::newFromId( $this->params['user_id'] );
3334 $cur_page_name = $this->title->getText();
34 - $new_page_name = str_replace( $this->params['target_str'], $this->params['replacement_str'], $cur_page_name );
 35+ if ( $this->params['use_regex'] ) {
 36+ $new_page_name = preg_replace( "/".$this->params['target_str']."/U", $this->params['replacement_str'], $cur_page_name );
 37+ } else {
 38+ $new_page_name = str_replace( $this->params['target_str'], $this->params['replacement_str'], $cur_page_name );
 39+ }
 40+
3541 $new_title = Title::newFromText( $new_page_name, $this->title->getNamespace() );
3642 $reason = $this->params['edit_summary'];
3743 $create_redirect = $this->params['create_redirect'];
@@ -53,7 +59,13 @@
5460 $target_str = $this->params['target_str'];
5561 $replacement_str = $this->params['replacement_str'];
5662 $num_matches;
57 - $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches );
 63+
 64+ if ( $this->params['use_regex'] ) {
 65+ $new_text = preg_replace( '/'.$target_str.'/U', $replacement_str, $article_text, -1, $num_matches );
 66+ } else {
 67+ $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches );
 68+ }
 69+
5870 // if there's at least one replacement, modify the page,
5971 // using the passed-in edit summary
6072 if ( $num_matches > 0 ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r82249Partly revert r82210: Remove spurios character (BOM?)raymond14:40, 16 February 2011

Comments

#Comment by Nikerabbit (talk | contribs)   07:32, 16 February 2011

Some kind of space character was inserted before <?php

Status & tagging log