46 if ( !$this->title->userCan(
'replacetext', $current_user ) ) {
47 $this->error =
'replacetext: permission no longer valid';
52 if ( isset( $this->params[
'session'] ) ) {
55 ScopedCallback::consume( $callback );
59 if ( is_null( $this->title ) ) {
60 $this->error =
"replaceText: Invalid title";
64 if ( array_key_exists(
'move_page', $this->params ) ) {
68 $cur_page_name = $this->title->getText();
69 if ( $this->params[
'use_regex'] ) {
70 $new_page_name = preg_replace(
71 "/" . $this->params[
'target_str'] .
"/Uu", $this->params[
'replacement_str'], $cur_page_name
75 str_replace( $this->params[
'target_str'], $this->params[
'replacement_str'], $cur_page_name );
78 $new_title = Title::newFromText( $new_page_name, $this->title->getNamespace() );
79 $reason = $this->params[
'edit_summary'];
80 $create_redirect = $this->params[
'create_redirect'];
81 $this->title->moveTo( $new_title,
true, $reason, $create_redirect );
82 if ( $this->params[
'watch_page'] ) {
88 $this->error =
'replaceText: Wiki page "' .
89 $this->title->getPrefixedDBkey() .
'" does not hold regular wikitext.';
92 $wikiPage =
new WikiPage( $this->title );
96 'replaceText: Wiki page not found for "' . $this->title->getPrefixedDBkey() .
'."';
99 $wikiPageContent = $wikiPage->getContent();
100 if ( is_null( $wikiPageContent ) ) {
102 'replaceText: No contents found for wiki page at "' . $this->title->getPrefixedDBkey() .
'."';
105 $article_text = $wikiPageContent->getNativeData();
107 $target_str = $this->params[
'target_str'];
108 $replacement_str = $this->params[
'replacement_str'];
111 if ( $this->params[
'use_regex'] ) {
113 preg_replace(
'/' . $target_str .
'/Uu', $replacement_str, $article_text, -1, $num_matches );
115 $new_text = str_replace( $target_str, $replacement_str, $article_text, $num_matches );
120 if ( $num_matches > 0 ) {
127 $edit_summary = $this->params[
'edit_summary'];
129 if (
$wgUser->isAllowed(
'bot' ) ) {
132 if ( isset( $this->params[
'doAnnounce'] ) &&
133 !$this->params[
'doAnnounce'] ) {
135 # fixme log this action
138 $wikiPage->doEditContent( $new_content, $edit_summary, $flags );