Index: trunk/extensions/ReplaceText/ReplaceTextJob.php |
— | — | @@ -1,10 +1,11 @@ |
2 | | -<?php |
| 2 | +<?php |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Background job to replace text in a given page |
6 | 6 | * - based on /includes/RefreshLinksJob.php |
7 | 7 | * |
8 | 8 | * @author Yaron Koren |
| 9 | + * @author Ankit Garg |
9 | 10 | */ |
10 | 11 | class ReplaceTextJob extends Job { |
11 | 12 | |
— | — | @@ -30,7 +31,12 @@ |
31 | 32 | $actual_user = $wgUser; |
32 | 33 | $wgUser = User::newFromId( $this->params['user_id'] ); |
33 | 34 | $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 | + |
35 | 41 | $new_title = Title::newFromText( $new_page_name, $this->title->getNamespace() ); |
36 | 42 | $reason = $this->params['edit_summary']; |
37 | 43 | $create_redirect = $this->params['create_redirect']; |
— | — | @@ -53,7 +59,13 @@ |
54 | 60 | $target_str = $this->params['target_str']; |
55 | 61 | $replacement_str = $this->params['replacement_str']; |
56 | 62 | $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 | + |
58 | 70 | // if there's at least one replacement, modify the page, |
59 | 71 | // using the passed-in edit summary |
60 | 72 | if ( $num_matches > 0 ) { |