isAllowed( 'replacetext' ) ) {
$wgOut->permissionRequired( 'replacetext' );
return;
}
$this->user = $wgUser;
$this->setHeaders();
$this->doSpecialReplaceText();
}
function displayConfirmForm( $message ) {
global $wgOut;
$formOpts = array( 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
$wgOut->addHTML(
Xml::openElement( 'form', $formOpts ) .
Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
Xml::hidden( 'target', $this->target ) .
Xml::hidden( 'replacement', $this->replacement ) .
Xml::hidden( 'edit_pages', $this->edit_pages ) .
Xml::hidden( 'move_pages', $this->move_pages ) .
Xml::hidden( 'confirm', 1 )
);
$wgOut->wrapWikiMsg( '$1', $message );
$wgOut->addHTML(
Xml::submitButton( wfMsg( 'replacetext_continue' ) )
);
$wgOut->addWikiMsg( 'replacetext_cancel' );
$wgOut->addHTML( Xml::closeElement( 'form' ) );
}
function doSpecialReplaceText() {
global $wgUser, $wgOut, $wgRequest, $wgLang;
$this->target = $wgRequest->getText( 'target' );
$this->replacement = $wgRequest->getText( 'replacement' );
$this->edit_pages = $wgRequest->getCheck( 'edit_pages' );
$this->move_pages = $wgRequest->getCheck( 'move_pages' );
if ( $wgRequest->getCheck( 'continue' ) ) {
if ( $this->target === '' ) {
$this->showForm( 'replacetext_givetarget' );
return;
}
}
if ( $wgRequest->getCheck( 'replace' ) ) {
$replacement_params = array();
$replacement_params['user_id'] = $wgUser->getId();
$replacement_params['target_str'] = $this->target;
$replacement_params['replacement_str'] = $this->replacement;
$replacement_params['edit_summary'] = wfMsgForContent( 'replacetext_editsummary', $this->target, $this->replacement );
$replacement_params['create_redirect'] = false;
$replacement_params['watch_page'] = false;
foreach ( $wgRequest->getValues() as $key => $value ) {
if ( $key == 'create-redirect' && $value == '1' ) {
$replacement_params['create_redirect'] = true;
} elseif ( $key == 'watch-pages' && $value == '1' ) {
$replacement_params['watch_page'] = true;
}
}
$jobs = array();
foreach ( $wgRequest->getValues() as $key => $value ) {
if ( $value == '1' ) {
if ( strpos( $key, 'move-' ) !== false ) {
$title = Title::newFromId( substr( $key, 5 ) );
$replacement_params['move_page'] = true;
} else {
$title = Title::newFromId( $key );
}
if ( $title !== null )
$jobs[] = new ReplaceTextJob( $title, $replacement_params );
}
}
Job::batchInsert( $jobs );
$count = $wgLang->formatNum( count( $jobs ) );
$wgOut->addWikiMsg( 'replacetext_success', $this->target, $this->replacement, $count );
// Link back
$sk = $this->user->getSkin();
$wgOut->addHTML( $sk->makeKnownLinkObj( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) );
return;
} elseif ( $wgRequest->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
// first, check that either editing or moving pages
// has been selected
if ( ! $this->edit_pages && ! $this->move_pages ) {
$this->showForm( 'replacetext_editormove' );
return;
}
$jobs = array();
$titles_for_edit = array();
$titles_for_move = array();
$unmoveable_titles = array();
// display a page to make the user confirm the
// replacement, if the replacement string is
// either blank or found elsewhere on the wiki
// (since undoing the replacement would be
// difficult in either case)
if ( !$wgRequest->getCheck( 'confirm' ) ) {
$message = false;
if ( $this->replacement === '' ) {
$message = 'replacetext_blankwarning';
} elseif ( $this->edit_pages ) {
$res = $this->doSearchQuery( $this->replacement );
$count = $res->numRows();
if ( $count > 0 ) {
$message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement );
}
} elseif ( $this->move_pages ) {
$res = $this->getMatchingTitles( $this->replacement );
$count = $res->numRows();
if ( $count > 0 ) {
$message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement );
}
}
if ( $message ) {
$this->displayConfirmForm( $message );
return;
}
}
// if user is replacing text within pages...
if ( $this->edit_pages ) {
$res = $this->doSearchQuery( $this->target );
foreach ( $res as $row ) {
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
$context = $this->extractContext( $row->old_text, $this->target );
$titles_for_edit[] = array( $title, $context );
}
}
if ( $this->move_pages ) {
$res = $this->getMatchingTitles( $this->target );
foreach ( $res as $row ) {
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
// see if this move can happen
$cur_page_name = str_replace('_', ' ', $row->page_title);
$new_page_name = str_replace( $this->target, $this->replacement, $cur_page_name );
$new_title = Title::makeTitleSafe( $row->page_namespace, $new_page_name );
$err = $title->isValidMoveOperation( $new_title );
if ( $title->userCanMove( true ) && !is_array( $err ) ) {
$titles_for_move[] = $title;
} else {
$unmoveable_titles[] = $title;
}
}
}
if ( count($titles_for_edit) == 0 && count($titles_for_move) == 0 ) {
if ( $this->edit_pages )
$wgOut->addWikiMsg( 'replacetext_noreplacement', "
' . $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'replacetext_return' ) ) . '
' ); } else { $this->pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ); } return; } // if we're still here, show the starting form $this->showForm( 'replacetext_docu' ); } function showForm( $message ) { global $wgOut; $wgOut->addHTML( Xml::openElement( 'form', array( 'action' => $this->getTitle()->getFullUrl(), 'method' => 'post' ) ) . Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . Xml::hidden( 'continue', 1 ) ); $wgOut->addWikiMsg( $message ); $wgOut->addWikiMsg( 'replacetext_note' ); $wgOut->addHTML( '' ); $wgOut->addWikiMsg( 'replacetext_originaltext' ); $wgOut->addHTML( ' | ' ); $wgOut->addHTML( Xml::textarea( 'target', $this->target, 50, 2 ) ); $wgOut->addHTML( Xml::closeElement( 'textarea' ) ); $wgOut->addHTML( ' |
' ); $wgOut->addWikiMsg( 'replacetext_replacementtext' ); $wgOut->addHTML( ' | ' ); $wgOut->addHTML( Xml::textarea( 'replacement', $this->replacement, 50, 2 ) ); $wgOut->addHTML( Xml::closeElement( 'textarea' ) ); $wgOut->addHTML( ' |