2008-08-06 16:09:35 +00:00
|
|
|
<?php
|
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) die();
|
2008-08-06 16:09:35 +00:00
|
|
|
|
|
|
|
class ReplaceText extends SpecialPage {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2008-09-18 16:29:10 +00:00
|
|
|
public function __construct() {
|
2009-04-27 09:02:48 +00:00
|
|
|
parent::__construct( 'ReplaceText', 'replacetext' );
|
|
|
|
wfLoadExtensionMessages( 'ReplaceText' );
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 05:48:04 +00:00
|
|
|
function execute( $query ) {
|
2008-09-18 16:29:10 +00:00
|
|
|
global $wgUser, $wgOut;
|
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( ! $wgUser->isAllowed( 'replacetext' ) ) {
|
|
|
|
$wgOut->permissionRequired( 'replacetext' );
|
2008-09-18 16:29:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-27 08:52:10 +00:00
|
|
|
$this->user = $wgUser;
|
2008-08-06 16:09:35 +00:00
|
|
|
$this->setHeaders();
|
2009-04-27 08:52:10 +00:00
|
|
|
$this->doSpecialReplaceText();
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
function displayConfirmForm( $message ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
global $wgOut;
|
|
|
|
|
|
|
|
$formOpts = array( 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
|
|
|
|
|
|
|
|
$wgOut->addHTML(
|
2009-05-21 13:27:58 +00:00
|
|
|
Xml::openElement( 'form', $formOpts ) . "\n".
|
|
|
|
Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n".
|
|
|
|
Xml::hidden( 'target', $this->target ) . "\n".
|
|
|
|
Xml::hidden( 'replacement', $this->replacement ) . "\n".
|
|
|
|
Xml::hidden( 'edit_pages', $this->edit_pages ) . "\n".
|
|
|
|
Xml::hidden( 'move_pages', $this->move_pages ) . "\n".
|
|
|
|
Xml::hidden( 'confirm', 1 ) . "\n"
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
2009-05-21 13:27:58 +00:00
|
|
|
foreach ($this->selected_namespaces as $ns) {
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::hidden( 'ns' . $ns, 1 ) . "\n"
|
|
|
|
);
|
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->wrapWikiMsg( '$1', $message );
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::submitButton( wfMsg( 'replacetext_continue' ) )
|
|
|
|
);
|
|
|
|
|
|
|
|
$wgOut->addWikiMsg( 'replacetext_cancel' );
|
|
|
|
$wgOut->addHTML( Xml::closeElement( 'form' ) );
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-05-19 15:19:15 +00:00
|
|
|
static function getSelectedNamespaces() {
|
|
|
|
global $wgRequest;
|
|
|
|
$all_namespaces = SearchEngine::searchableNamespaces();
|
|
|
|
$selected_namespaces = array();
|
|
|
|
foreach ($all_namespaces as $ns => $name) {
|
|
|
|
if ($wgRequest->getCheck('ns' . $ns)) {
|
|
|
|
$selected_namespaces[] = $ns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $selected_namespaces;
|
|
|
|
}
|
|
|
|
|
2009-04-27 08:52:10 +00:00
|
|
|
function doSpecialReplaceText() {
|
|
|
|
global $wgUser, $wgOut, $wgRequest, $wgLang;
|
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
$this->target = $wgRequest->getText( 'target' );
|
|
|
|
$this->replacement = $wgRequest->getText( 'replacement' );
|
|
|
|
$this->edit_pages = $wgRequest->getCheck( 'edit_pages' );
|
|
|
|
$this->move_pages = $wgRequest->getCheck( 'move_pages' );
|
2009-05-21 13:27:58 +00:00
|
|
|
$this->selected_namespaces = self::getSelectedNamespaces();
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $wgRequest->getCheck( 'continue' ) ) {
|
|
|
|
if ( $this->target === '' ) {
|
|
|
|
$this->showForm( 'replacetext_givetarget' );
|
|
|
|
return;
|
|
|
|
}
|
2009-01-22 23:40:30 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( $wgRequest->getCheck( 'replace' ) ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$replacement_params = array();
|
|
|
|
$replacement_params['user_id'] = $wgUser->getId();
|
2009-04-30 18:55:08 +00:00
|
|
|
$replacement_params['target_str'] = $this->target;
|
|
|
|
$replacement_params['replacement_str'] = $this->replacement;
|
|
|
|
$replacement_params['edit_summary'] = wfMsgForContent( 'replacetext_editsummary', $this->target, $this->replacement );
|
2009-04-27 08:52:10 +00:00
|
|
|
$replacement_params['create_redirect'] = false;
|
2009-04-27 18:48:27 +00:00
|
|
|
$replacement_params['watch_page'] = false;
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $wgRequest->getValues() as $key => $value ) {
|
|
|
|
if ( $key == 'create-redirect' && $value == '1' ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$replacement_params['create_redirect'] = true;
|
2009-04-27 18:48:27 +00:00
|
|
|
} elseif ( $key == 'watch-pages' && $value == '1' ) {
|
|
|
|
$replacement_params['watch_page'] = true;
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
$jobs = array();
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $wgRequest->getValues() as $key => $value ) {
|
|
|
|
if ( $value == '1' ) {
|
2009-05-19 15:19:15 +00:00
|
|
|
if ($key === 'replace') {
|
|
|
|
// ignore this value
|
|
|
|
} elseif ( strpos( $key, 'move-' ) !== false ) {
|
|
|
|
$title = Title::newFromID( substr( $key, 5 ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
$replacement_params['move_page'] = true;
|
|
|
|
} else {
|
2009-05-19 15:19:15 +00:00
|
|
|
$title = Title::newFromID( $key );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( $title !== null )
|
2009-04-27 08:52:10 +00:00
|
|
|
$jobs[] = new ReplaceTextJob( $title, $replacement_params );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Job::batchInsert( $jobs );
|
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
$count = $wgLang->formatNum( count( $jobs ) );
|
2009-05-19 16:55:59 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_success', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>", $count );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
// Link back
|
2009-04-27 18:48:27 +00:00
|
|
|
$sk = $this->user->getSkin();
|
2009-05-08 20:02:06 +00:00
|
|
|
$wgOut->addHTML( $sk->makeKnownLinkObj( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) );
|
2009-05-05 20:09:54 +00:00
|
|
|
return;
|
2009-04-27 09:02:48 +00:00
|
|
|
} elseif ( $wgRequest->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-05-21 13:27:58 +00:00
|
|
|
// first, check that at least one namespace has been
|
|
|
|
// picked, and that either editing or moving pages
|
2009-04-27 18:48:27 +00:00
|
|
|
// has been selected
|
2009-05-21 13:27:58 +00:00
|
|
|
if ( count( $this->selected_namespaces ) == 0 ) {
|
|
|
|
$this->showForm( 'replacetext_nonamespace' );
|
|
|
|
return;
|
|
|
|
}
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( ! $this->edit_pages && ! $this->move_pages ) {
|
2009-04-27 18:48:27 +00:00
|
|
|
$this->showForm( 'replacetext_editormove' );
|
|
|
|
return;
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
$jobs = array();
|
2009-04-27 18:48:27 +00:00
|
|
|
$titles_for_edit = array();
|
2009-04-27 08:52:10 +00:00
|
|
|
$titles_for_move = array();
|
|
|
|
$unmoveable_titles = array();
|
|
|
|
|
2009-04-27 20:55:00 +00:00
|
|
|
// 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;
|
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->replacement === '' ) {
|
2009-04-27 20:55:00 +00:00
|
|
|
$message = 'replacetext_blankwarning';
|
2009-04-30 18:55:08 +00:00
|
|
|
} elseif ( $this->edit_pages ) {
|
2009-05-21 13:27:58 +00:00
|
|
|
$res = $this->doSearchQuery( $this->replacement, $this->selected_namespaces );
|
2009-04-27 20:55:00 +00:00
|
|
|
$count = $res->numRows();
|
|
|
|
if ( $count > 0 ) {
|
2009-05-19 16:55:59 +00:00
|
|
|
$message = array( 'replacetext_warning', $wgLang->formatNum( $count ), "<tt><nowiki>{$this->replacement}</nowiki></tt>" );
|
2009-04-27 18:48:27 +00:00
|
|
|
}
|
2009-04-30 18:55:08 +00:00
|
|
|
} elseif ( $this->move_pages ) {
|
2009-05-21 13:27:58 +00:00
|
|
|
$res = $this->getMatchingTitles( $this->replacement, $this->selected_namespaces );
|
2009-04-27 20:55:00 +00:00
|
|
|
$count = $res->numRows();
|
|
|
|
if ( $count > 0 ) {
|
2009-04-30 18:55:08 +00:00
|
|
|
$message = array( 'replacetext_warning', $wgLang->formatNum( $count ), $this->replacement );
|
2009-04-27 18:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-27 20:55:00 +00:00
|
|
|
|
|
|
|
if ( $message ) {
|
2009-04-30 18:55:08 +00:00
|
|
|
$this->displayConfirmForm( $message );
|
2009-04-27 20:55:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if user is replacing text within pages...
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->edit_pages ) {
|
2009-05-21 13:27:58 +00:00
|
|
|
$res = $this->doSearchQuery( $this->target, $this->selected_namespaces );
|
2009-04-27 18:48:27 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
2009-04-30 18:55:08 +00:00
|
|
|
$context = $this->extractContext( $row->old_text, $this->target );
|
2009-04-27 18:48:27 +00:00
|
|
|
$titles_for_edit[] = array( $title, $context );
|
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->move_pages ) {
|
2009-05-21 13:27:58 +00:00
|
|
|
$res = $this->getMatchingTitles( $this->target, $this->selected_namespaces );
|
2009-04-27 08:52:10 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-04-27 09:02:48 +00:00
|
|
|
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
2009-04-27 08:52:10 +00:00
|
|
|
// see if this move can happen
|
2009-04-30 22:23:59 +00:00
|
|
|
$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 );
|
2009-04-27 09:02:48 +00:00
|
|
|
$err = $title->isValidMoveOperation( $new_title );
|
2009-05-24 08:52:19 +00:00
|
|
|
if ( $title->userCan( 'move', true ) && !is_array( $err ) ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$titles_for_move[] = $title;
|
|
|
|
} else {
|
|
|
|
$unmoveable_titles[] = $title;
|
|
|
|
}
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-27 18:48:27 +00:00
|
|
|
if ( count($titles_for_edit) == 0 && count($titles_for_move) == 0 ) {
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->edit_pages )
|
2009-05-08 20:02:06 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_noreplacement', "<tt><nowiki>{$this->target}</nowiki></tt>" );
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->move_pages )
|
2009-05-08 20:02:06 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_nomove', "<tt><nowiki>{$this->target}</nowiki></tt>" );
|
2009-04-27 08:52:10 +00:00
|
|
|
// link back to starting form
|
|
|
|
$sk = $this->user->getSkin();
|
|
|
|
$wgOut->addHTML( '<p>' . $sk->makeKnownLinkObj( $this->getTitle(), wfMsg( 'replacetext_return' ) ) . '</p>' );
|
|
|
|
} else {
|
2009-04-30 18:55:08 +00:00
|
|
|
$this->pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
2009-04-30 18:55:08 +00:00
|
|
|
return;
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
2009-04-30 18:55:08 +00:00
|
|
|
|
|
|
|
// if we're still here, show the starting form
|
|
|
|
$this->showForm( 'replacetext_docu' );
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
function showForm( $message ) {
|
|
|
|
global $wgOut;
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::openElement( 'form', array( 'action' => $this->getTitle()->getFullUrl(), 'method' => 'post' ) ) .
|
2009-04-30 18:55:08 +00:00
|
|
|
Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
|
|
|
|
Xml::hidden( 'continue', 1 )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
$wgOut->addWikiMsg( $message );
|
2009-04-30 18:55:08 +00:00
|
|
|
$wgOut->addHTML( '<table><tr><td style="vertical-align: top;">' );
|
2009-04-27 18:48:27 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_originaltext' );
|
|
|
|
$wgOut->addHTML( '</td><td>' );
|
2009-05-27 04:59:00 +00:00
|
|
|
// 'width: auto' style is needed to override MediaWiki's
|
|
|
|
// normal 'width: 100%', which causes the textarea to get
|
|
|
|
// zero width in IE
|
|
|
|
$wgOut->addHTML( Xml::textarea( 'target', $this->target, 50, 2, array( 'style' => 'width: auto;' ) ) );
|
2009-04-30 18:55:08 +00:00
|
|
|
$wgOut->addHTML( '</td></tr><tr><td style="vertical-align: top;">' );
|
2009-04-27 18:48:27 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_replacementtext' );
|
|
|
|
$wgOut->addHTML( '</td><td>' );
|
2009-05-27 04:59:00 +00:00
|
|
|
$wgOut->addHTML( Xml::textarea( 'replacement', $this->replacement, 50, 2, array( 'style' => 'width: auto;' ) ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML( '</td></tr></table>' );
|
2009-05-19 15:19:15 +00:00
|
|
|
|
|
|
|
$search_label = wfMsg('powersearch-ns');
|
|
|
|
$namespaces = SearchEngine::searchableNamespaces();
|
|
|
|
$tables = $this->namespaceTables( $namespaces );
|
|
|
|
$wgOut->addHTML( "<fieldset>\n<p>$search_label</p\n>$tables\n</fieldset>" );
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML(
|
2009-04-27 18:48:27 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'replacetext_editpages' ), 'edit_pages', 'edit_pages', true ) . '<br />' .
|
|
|
|
Xml::checkLabel( wfMsg( 'replacetext_movepages' ), 'move_pages', 'move_pages' ) . '<br /><br />' .
|
2009-04-27 08:52:10 +00:00
|
|
|
Xml::submitButton( wfMsg( 'replacetext_continue' ) ) .
|
|
|
|
Xml::closeElement( 'form' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:19:15 +00:00
|
|
|
/**
|
|
|
|
* Copied almost exactly from MediaWiki's SpecialSearch class, i.e.
|
|
|
|
* the search page
|
|
|
|
*/
|
|
|
|
function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
|
|
|
|
global $wgContLang;
|
|
|
|
// Group namespaces into rows according to subject.
|
|
|
|
// Try not to make too many assumptions about namespace numbering.
|
|
|
|
$rows = array();
|
|
|
|
$tables = "";
|
|
|
|
foreach( $namespaces as $ns => $name ) {
|
|
|
|
$subj = MWNamespace::getSubject( $ns );
|
|
|
|
if( !array_key_exists( $subj, $rows ) ) {
|
|
|
|
$rows[$subj] = "";
|
|
|
|
}
|
|
|
|
$name = str_replace( '_', ' ', $name );
|
|
|
|
if( '' == $name ) {
|
|
|
|
$name = wfMsg( 'blanknamespace' );
|
|
|
|
}
|
|
|
|
$rows[$subj] .= Xml::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
|
|
|
|
Xml::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $namespaces ) ) .
|
|
|
|
Xml::closeElement( 'td' ) . "\n";
|
|
|
|
}
|
|
|
|
$rows = array_values( $rows );
|
|
|
|
$numRows = count( $rows );
|
|
|
|
// Lay out namespaces in multiple floating two-column tables so they'll
|
|
|
|
// be arranged nicely while still accommodating different screen widths
|
|
|
|
// Float to the right on RTL wikis
|
|
|
|
$tableStyle = $wgContLang->isRTL() ?
|
|
|
|
'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
|
|
|
|
// Build the final HTML table...
|
|
|
|
for( $i = 0; $i < $numRows; $i += $rowsPerTable ) {
|
|
|
|
$tables .= Xml::openElement( 'table', array( 'style' => $tableStyle ) );
|
|
|
|
for( $j = $i; $j < $i + $rowsPerTable && $j < $numRows; $j++ ) {
|
|
|
|
$tables .= "<tr>\n" . $rows[$j] . "</tr>";
|
|
|
|
}
|
|
|
|
$tables .= Xml::closeElement( 'table' ) . "\n";
|
|
|
|
}
|
|
|
|
return $tables;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
global $wgOut, $wgLang, $wgScript;
|
|
|
|
|
2009-04-27 18:48:27 +00:00
|
|
|
$skin = $this->user->getSkin();
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
$formOpts = array( 'id' => 'choose_pages', 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::openElement( 'form', $formOpts ) .
|
|
|
|
Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
|
2009-04-30 18:55:08 +00:00
|
|
|
Xml::hidden( 'target', $this->target ) .
|
|
|
|
Xml::hidden( 'replacement', $this->replacement )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
$js = file_get_contents( dirname( __FILE__ ) . '/ReplaceText.js' );
|
|
|
|
$js = '<script type="text/javascript">' . $js . '</script>';
|
|
|
|
$wgOut->addScript( $js );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( count( $titles_for_edit ) > 0 ) {
|
2009-05-08 20:02:06 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_choosepagesforedit', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>",
|
2009-04-27 18:48:27 +00:00
|
|
|
$wgLang->formatNum( count( $titles_for_edit ) ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-04-27 18:48:27 +00:00
|
|
|
foreach ( $titles_for_edit as $title_and_context ) {
|
|
|
|
list( $title, $context ) = $title_and_context;
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::check( $title->getArticleID(), true ) .
|
|
|
|
$skin->makeKnownLinkObj( $title, $title->getPrefixedText() ) . " - <small>$context</small><br />\n"
|
|
|
|
);
|
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML( '<br />' );
|
2009-04-27 18:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( count( $titles_for_move ) > 0 ) {
|
2009-04-30 18:55:08 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_choosepagesformove', $this->target, $this->replacement, $wgLang->formatNum( count( $titles_for_move ) ) );
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $titles_for_move as $title ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML(
|
2009-04-27 09:02:48 +00:00
|
|
|
Xml::check( 'move-' . $title->getArticleID(), true ) .
|
|
|
|
$skin->makeLinkObj( $title, $title->prefix( $title->getText() ) ) . "<br />\n"
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
}
|
2009-04-27 18:48:27 +00:00
|
|
|
$wgOut->addHTML( '<br />' );
|
|
|
|
$wgOut->addWikiMsg( 'replacetext_formovedpages' );
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML(
|
2009-04-27 18:48:27 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'replacetext_savemovedpages' ), 'create-redirect', 'create-redirect', true ) . "<br />\n" .
|
2009-05-05 20:09:54 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'replacetext_watchmovedpages' ), 'watch-pages', 'watch-pages', false )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
2009-04-27 18:48:27 +00:00
|
|
|
$wgOut->addHTML( '<br />' );
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
2008-09-02 17:34:40 +00:00
|
|
|
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addHTML(
|
2009-04-27 18:48:27 +00:00
|
|
|
"<br />\n" .
|
2009-04-27 09:02:48 +00:00
|
|
|
Xml::submitButton( wfMsg( 'replacetext_replace' ) ) .
|
2009-04-27 08:52:10 +00:00
|
|
|
Xml::hidden( 'replace', 1 )
|
|
|
|
);
|
|
|
|
|
2008-10-13 12:34:00 +00:00
|
|
|
// only show "invert selections" link if there are more than five pages
|
2009-04-27 18:48:27 +00:00
|
|
|
if ( count( $titles_for_edit ) + count( $titles_for_move ) > 5 ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$buttonOpts = array(
|
|
|
|
'type' => 'button',
|
|
|
|
'value' => wfMsg( 'replacetext_invertselections' ),
|
|
|
|
'onclick' => 'invertSelections(); return false;'
|
|
|
|
);
|
|
|
|
|
|
|
|
$wgOut->addHTML(
|
|
|
|
Xml::element( 'input', $buttonOpts )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$wgOut->addHTML( '</form>' );
|
2008-08-06 16:09:35 +00:00
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( count( $unmoveable_titles ) > 0 ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$wgOut->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) );
|
|
|
|
$text = "<ul>\n";
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $unmoveable_titles as $title ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$text .= "<li>{$skin->makeKnownLinkObj( $title, $title->getPrefixedText() )}<br />\n";
|
|
|
|
}
|
2008-11-05 20:37:50 +00:00
|
|
|
$text .= "</ul>\n";
|
2009-04-27 09:02:48 +00:00
|
|
|
$wgOut->addHTML( $text );
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract context and highlights search text
|
|
|
|
*/
|
|
|
|
function extractContext( $text, $target ) {
|
|
|
|
global $wgLang;
|
|
|
|
$cw = $this->user->getOption( 'contextchars', 40 );
|
|
|
|
|
|
|
|
// Get all indexes
|
|
|
|
$targetq = preg_quote( $target, '/' );
|
2009-05-19 15:19:15 +00:00
|
|
|
preg_match_all( "/$targetq/", $text, $matches, PREG_OFFSET_CAPTURE );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
$poss = array();
|
|
|
|
foreach ( $matches[0] as $_ ) {
|
|
|
|
$poss[] = $_[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
$cuts = array();
|
2009-04-27 09:02:48 +00:00
|
|
|
for ( $i = 0; $i < count( $poss ); $i++ ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$index = $poss[$i];
|
2009-04-27 09:02:48 +00:00
|
|
|
$len = strlen( $target );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
// Merge to the next if possible
|
2009-04-27 09:02:48 +00:00
|
|
|
while ( isset( $poss[$i + 1] ) ) {
|
|
|
|
if ( $poss[$i + 1] < $index + $len + $cw * 2 ) {
|
|
|
|
$len += $poss[$i + 1] - $poss[$i];
|
2009-04-27 08:52:10 +00:00
|
|
|
$i++;
|
|
|
|
} else {
|
|
|
|
break; // Can't merge, exit the inner loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$cuts[] = array( $index, $len );
|
|
|
|
}
|
|
|
|
|
|
|
|
$context = '';
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $cuts as $_ ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
list( $index, $len, ) = $_;
|
2009-04-27 09:02:48 +00:00
|
|
|
$context .= self::convertWhiteSpaceToHTML( $wgLang->truncate( substr( $text, 0, $index ), - $cw ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
$snippet = self::convertWhiteSpaceToHTML( substr( $text, $index, $len ) );
|
|
|
|
$targetq = preg_quote( self::convertWhiteSpaceToHTML( $target ), '/' );
|
|
|
|
$context .= preg_replace( "/$targetq/i", '<span class="searchmatch">\0</span>', $snippet );
|
2009-04-27 09:02:48 +00:00
|
|
|
$context .= self::convertWhiteSpaceToHTML( $wgLang->truncate( substr( $text, $index + $len ), $cw ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function convertWhiteSpaceToHTML( $msg ) {
|
|
|
|
$msg = htmlspecialchars( $msg );
|
|
|
|
$msg = preg_replace( '/^ /m', ' ', $msg );
|
|
|
|
$msg = preg_replace( '/ $/m', ' ', $msg );
|
|
|
|
$msg = preg_replace( '/ /', ' ', $msg );
|
2009-04-27 09:02:48 +00:00
|
|
|
# $msg = str_replace( "\n", '<br />', $msg );
|
2009-04-27 08:52:10 +00:00
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:19:15 +00:00
|
|
|
function getMatchingTitles( $str, $namespaces ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2009-06-26 02:54:43 +00:00
|
|
|
$sql_str = $dbr->escapeLike( str_replace( ' ', '_', $str ) );
|
2009-05-19 15:19:15 +00:00
|
|
|
$include_ns = $dbr->makeList( $namespaces );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
return $dbr->select(
|
|
|
|
'page',
|
|
|
|
array( 'page_title', 'page_namespace' ),
|
2009-05-19 15:19:15 +00:00
|
|
|
"page_title LIKE '%$sql_str%' AND page_namespace IN ($include_ns)",
|
2009-04-27 08:52:10 +00:00
|
|
|
__METHOD__,
|
2009-04-27 09:02:48 +00:00
|
|
|
array( 'ORDER BY' => 'page_namespace, page_title' )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-05-19 15:19:15 +00:00
|
|
|
function doSearchQuery( $search, $namespaces ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
|
|
|
|
$search = $dbr->escapeLike( $search );
|
2009-05-08 20:02:06 +00:00
|
|
|
$search = str_replace(array("\\", "'"), array("\\\\", "\'"), $search);
|
2009-05-19 15:19:15 +00:00
|
|
|
$include_ns = $dbr->makeList( $namespaces );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
$tables = array( 'page', 'revision', 'text' );
|
|
|
|
$vars = array( 'page_id', 'page_namespace', 'page_title', 'old_text' );
|
|
|
|
$conds = array(
|
|
|
|
"old_text like '%$search%'",
|
2009-05-19 15:19:15 +00:00
|
|
|
"page_namespace in ($include_ns)",
|
2009-04-27 08:52:10 +00:00
|
|
|
'rev_id = page_latest',
|
|
|
|
'rev_text_id = old_id'
|
|
|
|
);
|
2009-05-19 16:55:59 +00:00
|
|
|
$sort = array( 'ORDER BY' => 'page_namespace, page_title' );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-05-19 16:55:59 +00:00
|
|
|
return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
}
|