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 ) ) {
58 $actual_user = $wgUser;
60 $cur_page_name = $this->title->getText();
61 if ( $this->params[
'use_regex'] ) {
62 $new_page_name = preg_replace(
63 "/" . $this->params[
'target_str'] .
"/Uu", $this->params[
'replacement_str'], $cur_page_name
67 str_replace( $this->params[
'target_str'], $this->params[
'replacement_str'], $cur_page_name );
70 $new_title = Title::newFromText( $new_page_name, $this->title->getNamespace() );
71 $reason = $this->params[
'edit_summary'];
72 $create_redirect = $this->params[
'create_redirect'];
73 $this->title->moveTo( $new_title,
true, $reason, $create_redirect );
74 if ( $this->params[
'watch_page'] ) {
77 $wgUser = $actual_user;
80 $this->error =
'replaceText: Wiki page "' .
81 $this->title->getPrefixedDBkey() .
'" does not hold regular wikitext.';
84 $wikiPage =
new WikiPage( $this->title );
88 'replaceText: Wiki page not found for "' . $this->title->getPrefixedDBkey() .
'."';
91 $wikiPageContent = $wikiPage->getContent();
92 if ( is_null( $wikiPageContent ) ) {
94 'replaceText: No contents found for wiki page at "' . $this->title->getPrefixedDBkey() .
'."';
97 $article_text = $wikiPageContent->getNativeData();
99 $target_str = $this->params[
'target_str'];
100 $replacement_str = $this->params[
'replacement_str'];
103 if ( $this->params[
'use_regex'] ) {
105 preg_replace(
'/' . $target_str .
'/Uu', $replacement_str, $article_text, -1, $num_matches );
107 $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches );
112 if ( $num_matches > 0 ) {
117 $actual_user = $wgUser;
119 $edit_summary = $this->params[
'edit_summary'];
121 if ( $wgUser->isAllowed(
'bot' ) ) {
124 if ( isset( $this->params[
'doAnnounce'] ) &&
125 !$this->params[
'doAnnounce'] ) {
127 # fixme log this action
130 $wikiPage->doEditContent( $new_content, $edit_summary, $flags );
131 $wgUser = $actual_user;