44 if ( isset( $this->params[
'session'] ) ) {
45 $callback = RequestContext::importScopedSession( $this->params[
'session'] );
47 ScopedCallback::consume( $callback );
51 if ( is_null( $this->title ) ) {
52 $this->error =
"replaceText: Invalid title";
56 if ( array_key_exists(
'move_page', $this->params ) ) {
57 $current_user = User::newFromId( $this->params[
'user_id'] );
60 $this->params[
'target_str'],
61 $this->params[
'replacement_str'],
62 $this->params[
'use_regex']
65 if ( is_null( $new_title ) ) {
66 $this->error =
"replaceText: Invalid new title - " . $this->params[
'replacement_str'];
70 $reason = $this->params[
'edit_summary'];
71 $create_redirect = $this->params[
'create_redirect'];
72 $mvPage =
new MovePage( $this->title, $new_title );
73 $mvStatus = $mvPage->move( $current_user, $reason, $create_redirect );
74 if ( !$mvStatus->isOK() ) {
75 $this->error =
"replaceText: error while moving: " . $this->title->getPrefixedDBkey() .
76 ". Errors: " . $mvStatus->getWikiText();
80 if ( $this->params[
'watch_page'] ) {
85 $this->error =
'replaceText: Wiki page "' .
86 $this->title->getPrefixedDBkey() .
'" does not hold regular wikitext.';
89 $wikiPage =
new WikiPage( $this->title );
93 'replaceText: Wiki page not found for "' . $this->title->getPrefixedDBkey() .
'."';
96 $wikiPageContent = $wikiPage->getContent();
97 if ( is_null( $wikiPageContent ) ) {
99 'replaceText: No contents found for wiki page at "' . $this->title->getPrefixedDBkey() .
'."';
102 $article_text = $wikiPageContent->getNativeData();
104 $target_str = $this->params[
'target_str'];
105 $replacement_str = $this->params[
'replacement_str'];
108 if ( $this->params[
'use_regex'] ) {
110 preg_replace(
'/' . $target_str .
'/Uu', $replacement_str, $article_text, -1, $num_matches );
112 $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches );
117 if ( $num_matches > 0 ) {
122 $actual_user = $wgUser;
123 $wgUser = User::newFromId( $this->params[
'user_id'] );
124 $edit_summary = $this->params[
'edit_summary'];
126 if ( $wgUser->isAllowed(
'bot' ) ) {
129 if ( isset( $this->params[
'doAnnounce'] ) &&
130 !$this->params[
'doAnnounce'] ) {
132 # fixme log this action
135 $wikiPage->doEditContent( $new_content, $edit_summary, $flags );
136 $wgUser = $actual_user;