mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ReplaceText
synced 2024-11-15 02:53:52 +00:00
Maintenance for ReplaceText extension.
* Now requires MediaWiki 1.18 or later. * Use strict in JavaScript and update with JSHint/JSLint suggestions. * Deglobalisation. * Replace deprecated methods, remove pre 1.18 BC code. * Update docs. * Break long lines. * Add FIXME where needed. Change-Id: If9fe1e314937438227458cb07cda7f734043801f
This commit is contained in:
parent
2d92f94c89
commit
4eec59a457
2
README
2
README
|
@ -28,7 +28,7 @@ http://www.mediawiki.org/wiki/Extension:Replace_Text
|
|||
|
||||
== Requirements ==
|
||||
|
||||
This version of the Replace Text extension requires MediaWiki 1.16 or higher.
|
||||
This version of the Replace Text extension requires MediaWiki 1.18 or higher.
|
||||
|
||||
== Installation ==
|
||||
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
function invertSelections() {
|
||||
form = document.getElementById('choose_pages');
|
||||
num_elements = form.elements.length;
|
||||
'use strict';
|
||||
|
||||
var form = document.getElementById('choose_pages' ),
|
||||
num_elements = form.elements.length,
|
||||
i,
|
||||
cur_element;
|
||||
|
||||
for (i = 0; i < num_elements; i++) {
|
||||
cur_element = form.elements[i];
|
||||
if (cur_element.type == "checkbox" && cur_element.id != 'create-redirect' && cur_element.id != 'watch-pages') {
|
||||
if (form.elements[i].checked == true)
|
||||
form.elements[i].checked = false;
|
||||
else
|
||||
form.elements[i].checked = true;
|
||||
|
||||
if (cur_element.type === "checkbox" && cur_element.id !== 'create-redirect' && cur_element.id !== 'watch-pages') {
|
||||
form.elements[i].checked = form.elements[i].checked !== true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* replacement, since it is not easily reversible.
|
||||
*/
|
||||
|
||||
if ( !defined( 'MEDIAWIKI' ) ) die();
|
||||
if ( !defined( 'MEDIAWIKI' ) ) { die(); }
|
||||
|
||||
// credits
|
||||
$wgExtensionCredits['specialpage'][] = array(
|
||||
|
@ -46,8 +46,8 @@ $wgAutoloadClasses['ReplaceText'] = $rtgIP . 'SpecialReplaceText.php';
|
|||
$wgAutoloadClasses['ReplaceTextJob'] = $rtgIP . 'ReplaceTextJob.php';
|
||||
|
||||
// This function should really go into a "ReplaceText_body.php" file.
|
||||
function rtAddToAdminLinks( &$admin_links_tree ) {
|
||||
$general_section = $admin_links_tree->getSection( wfMsg( 'adminlinks_general' ) );
|
||||
function rtAddToAdminLinks( ALTree &$admin_links_tree ) {
|
||||
$general_section = $admin_links_tree->getSection( wfMessage( 'adminlinks_general' )->text() );
|
||||
$extensions_row = $general_section->getRow( 'extensions' );
|
||||
|
||||
if ( is_null( $extensions_row ) ) {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
* @author Ankit Garg
|
||||
*/
|
||||
class ReplaceTextJob extends Job {
|
||||
|
||||
function __construct( $title, $params = '', $id = 0 ) {
|
||||
parent::__construct( 'replaceText', $title, $params, $id );
|
||||
}
|
||||
|
@ -45,12 +44,8 @@ class ReplaceTextJob extends Job {
|
|||
if ( class_exists( 'WatchAction' ) ) {
|
||||
// Class was added in MW 1.19
|
||||
WatchAction::doWatch( $new_title, $wgUser );
|
||||
} elseif ( class_exists( 'Action' ) ) {
|
||||
// Class was added in MW 1.18
|
||||
Action::factory( 'watch', new Article( $new_title, 0 ) )->execute();
|
||||
} else {
|
||||
$article = new Article( $new_title, 0 );
|
||||
$article->doWatch();
|
||||
Action::factory( 'watch', new WikiPage( $new_title ) )->execute();
|
||||
}
|
||||
}
|
||||
$wgUser = $actual_user;
|
||||
|
@ -66,6 +61,7 @@ class ReplaceTextJob extends Job {
|
|||
$article_text = $article->fetchContent();
|
||||
$target_str = $this->params['target_str'];
|
||||
$replacement_str = $this->params['replacement_str'];
|
||||
// @todo FIXME eh?
|
||||
$num_matches;
|
||||
|
||||
if ( $this->params['use_regex'] ) {
|
||||
|
|
|
@ -1,34 +1,30 @@
|
|||
<?php
|
||||
|
||||
class ReplaceText extends SpecialPage {
|
||||
private $target, $replacement, $use_regex, $category, $prefix, $edit_pages, $move_pages, $selected_namespaces;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( 'ReplaceText', 'replacetext' );
|
||||
}
|
||||
|
||||
function execute( $query ) {
|
||||
global $wgUser, $wgOut;
|
||||
|
||||
if ( !$wgUser->isAllowed( 'replacetext' ) ) {
|
||||
$wgOut->permissionRequired( 'replacetext' );
|
||||
return;
|
||||
if ( !$this->getUser()->isAllowed( 'replacetext' ) ) {
|
||||
throw new PermissionsError( 'replacetext' );
|
||||
}
|
||||
|
||||
$this->user = $wgUser;
|
||||
$this->setHeaders();
|
||||
if ( method_exists( $wgOut, 'addModuleStyles' ) &&
|
||||
!is_null( $wgOut->getResourceLoader()->getModule( 'mediawiki.special' ) ) ) {
|
||||
$wgOut->addModuleStyles( 'mediawiki.special' );
|
||||
$out = $this->getOutput();
|
||||
if ( !is_null( $out->getResourceLoader()->getModule( 'mediawiki.special' ) ) ) {
|
||||
$out->addModuleStyles( 'mediawiki.special' );
|
||||
}
|
||||
$this->doSpecialReplaceText();
|
||||
}
|
||||
|
||||
static function getSelectedNamespaces() {
|
||||
global $wgRequest;
|
||||
function getSelectedNamespaces() {
|
||||
$all_namespaces = SearchEngine::searchableNamespaces();
|
||||
$selected_namespaces = array();
|
||||
foreach ( $all_namespaces as $ns => $name ) {
|
||||
if ( $wgRequest->getCheck( 'ns' . $ns ) ) {
|
||||
if ( $this->getRequest()->getCheck( 'ns' . $ns ) ) {
|
||||
$selected_namespaces[] = $ns;
|
||||
}
|
||||
}
|
||||
|
@ -39,44 +35,45 @@ class ReplaceText extends SpecialPage {
|
|||
* Helper function to display a hidden field for different versions
|
||||
* of MediaWiki.
|
||||
*/
|
||||
static function hiddenField( $name, $value ) {
|
||||
if ( class_exists( 'Html' ) ) {
|
||||
return "\t" . Html::hidden( $name, $value ) . "\n";
|
||||
} else {
|
||||
return "\t" . Xml::hidden( $name, $value ) . "\n";
|
||||
}
|
||||
function hiddenField( $name, $value ) {
|
||||
return "\t" . Html::hidden( $name, $value ) . "\n";
|
||||
}
|
||||
|
||||
function doSpecialReplaceText() {
|
||||
global $wgOut, $wgRequest, $wgLang;
|
||||
$out = $this->getOutput();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
|
||||
|
||||
$this->target = $wgRequest->getText( 'target' );
|
||||
$this->replacement = $wgRequest->getText( 'replacement' );
|
||||
$this->use_regex = $wgRequest->getBool( 'use_regex' );
|
||||
$this->category = $wgRequest->getText( 'category' );
|
||||
$this->prefix = $wgRequest->getText( 'prefix' );
|
||||
$this->edit_pages = $wgRequest->getBool( 'edit_pages' );
|
||||
$this->move_pages = $wgRequest->getBool( 'move_pages' );
|
||||
$this->selected_namespaces = self::getSelectedNamespaces();
|
||||
$this->target = $request->getText( 'target' );
|
||||
$this->replacement = $request->getText( 'replacement' );
|
||||
$this->use_regex = $request->getBool( 'use_regex' );
|
||||
$this->category = $request->getText( 'category' );
|
||||
$this->prefix = $request->getText( 'prefix' );
|
||||
$this->edit_pages = $request->getBool( 'edit_pages' );
|
||||
$this->move_pages = $request->getBool( 'move_pages' );
|
||||
$this->selected_namespaces = $this->getSelectedNamespaces();
|
||||
|
||||
if ( $wgRequest->getCheck( 'continue' ) ) {
|
||||
if ( $request->getCheck( 'continue' ) ) {
|
||||
if ( $this->target === '' ) {
|
||||
$this->showForm( 'replacetext_givetarget' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $wgRequest->getCheck( 'replace' ) ) {
|
||||
if ( $request->getCheck( 'replace' ) ) {
|
||||
$replacement_params = array();
|
||||
$replacement_params['user_id'] = $this->user->getId();
|
||||
$replacement_params['user_id'] = $this->getUser()->getId();
|
||||
$replacement_params['target_str'] = $this->target;
|
||||
$replacement_params['replacement_str'] = $this->replacement;
|
||||
$replacement_params['use_regex'] = $this->use_regex;
|
||||
$replacement_params['edit_summary'] = wfMsgForContent( 'replacetext_editsummary', $this->target, $this->replacement );
|
||||
$replacement_params['edit_summary'] = $this->msg(
|
||||
'replacetext_editsummary',
|
||||
$this->target, $this->replacement
|
||||
)->inContentLanguage()->text();
|
||||
$replacement_params['create_redirect'] = false;
|
||||
$replacement_params['watch_page'] = false;
|
||||
foreach ( $wgRequest->getValues() as $key => $value ) {
|
||||
foreach ( $request->getValues() as $key => $value ) {
|
||||
if ( $key == 'create-redirect' && $value == '1' ) {
|
||||
$replacement_params['create_redirect'] = true;
|
||||
} elseif ( $key == 'watch-pages' && $value == '1' ) {
|
||||
|
@ -84,7 +81,7 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
}
|
||||
$jobs = array();
|
||||
foreach ( $wgRequest->getValues() as $key => $value ) {
|
||||
foreach ( $request->getValues() as $key => $value ) {
|
||||
if ( $value == '1' && $key !== 'replace' && $key !== 'use_regex' ) {
|
||||
if ( strpos( $key, 'move-' ) !== false ) {
|
||||
$title = Title::newFromID( substr( $key, 5 ) );
|
||||
|
@ -98,13 +95,22 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
Job::batchInsert( $jobs );
|
||||
|
||||
$count = $wgLang->formatNum( count( $jobs ) );
|
||||
$wgOut->addWikiMsg( 'replacetext_success', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>", $count );
|
||||
$count = $this->getLanguage()->formatNum( count( $jobs ) );
|
||||
$out->addWikiMsg(
|
||||
'replacetext_success',
|
||||
"<code><nowiki>{$this->target}</nowiki></code>",
|
||||
"<code><nowiki>{$this->replacement}</nowiki></code>",
|
||||
$count
|
||||
);
|
||||
|
||||
// Link back
|
||||
$wgOut->addHTML( $linker->link( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) );
|
||||
$out->addHTML(
|
||||
$linker->link( $this->getTitle(),
|
||||
$this->msg( 'replacetext_return' )->escaped() )
|
||||
);
|
||||
|
||||
return;
|
||||
} elseif ( $wgRequest->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
|
||||
} elseif ( $request->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
|
||||
// first, check that at least one namespace has been
|
||||
// picked, and that either editing or moving pages
|
||||
// has been selected
|
||||
|
@ -117,14 +123,20 @@ class ReplaceText extends SpecialPage {
|
|||
return;
|
||||
}
|
||||
|
||||
$jobs = array();
|
||||
$titles_for_edit = array();
|
||||
$titles_for_move = array();
|
||||
$unmoveable_titles = array();
|
||||
|
||||
// if user is replacing text within pages...
|
||||
if ( $this->edit_pages ) {
|
||||
$res = $this->doSearchQuery( $this->target, $this->selected_namespaces, $this->category, $this->prefix , $this->use_regex );
|
||||
$res = $this->doSearchQuery(
|
||||
$this->target,
|
||||
$this->selected_namespaces,
|
||||
$this->category,
|
||||
$this->prefix,
|
||||
$this->use_regex
|
||||
);
|
||||
|
||||
foreach ( $res as $row ) {
|
||||
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
||||
$context = $this->extractContext( $row->old_text, $this->target, $this->use_regex );
|
||||
|
@ -132,18 +144,28 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
}
|
||||
if ( $this->move_pages ) {
|
||||
$res = $this->getMatchingTitles( $this->target, $this->selected_namespaces, $this->category, $this->prefix, $this->use_regex );
|
||||
$res = $this->getMatchingTitles(
|
||||
$this->target,
|
||||
$this->selected_namespaces,
|
||||
$this->category,
|
||||
$this->prefix,
|
||||
$this->use_regex
|
||||
);
|
||||
|
||||
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 );
|
||||
|
||||
if ( $this->use_regex ) {
|
||||
$new_page_name = preg_replace( "/".$this->target."/U", $this->replacement, $cur_page_name );
|
||||
} else {
|
||||
$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->userCan( 'move' ) && !is_array( $err ) ) {
|
||||
$titles_for_move[] = $title;
|
||||
} else {
|
||||
|
@ -151,26 +173,31 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no results were found, check to see if a bad
|
||||
// category name was entered
|
||||
if ( count( $titles_for_edit ) == 0 && count( $titles_for_move ) == 0 ) {
|
||||
$bad_cat_name = false;
|
||||
|
||||
if ( ! empty( $this->category ) ) {
|
||||
$category_title = Title::makeTitleSafe( NS_CATEGORY, $this->category );
|
||||
if ( ! $category_title->exists() ) $bad_cat_name = true;
|
||||
}
|
||||
|
||||
if ( $bad_cat_name ) {
|
||||
$link = $linker->link( $category_title, htmlspecialchars( ucfirst( $this->category ) ) );
|
||||
$wgOut->addHTML( wfMsgHtml( 'replacetext_nosuchcategory', $link ) );
|
||||
$out->addHTML(
|
||||
$this->msg( 'replacetext_nosuchcategory' )->rawParams( $link )->escaped()
|
||||
);
|
||||
} else {
|
||||
if ( $this->edit_pages )
|
||||
$wgOut->addWikiMsg( 'replacetext_noreplacement', "<tt><nowiki>{$this->target}</nowiki></tt>" );
|
||||
$out->addWikiMsg( 'replacetext_noreplacement', "<code><nowiki>{$this->target}</nowiki></code>" );
|
||||
|
||||
if ( $this->move_pages )
|
||||
$wgOut->addWikiMsg( 'replacetext_nomove', "<tt><nowiki>{$this->target}</nowiki></tt>" );
|
||||
$out->addWikiMsg( 'replacetext_nomove', "<code><nowiki>{$this->target}</nowiki></code>" );
|
||||
}
|
||||
// link back to starting form
|
||||
//FIXME: raw html message
|
||||
$wgOut->addHTML( '<p>' . $linker->link( $this->getTitle(), wfMsgHtml( 'replacetext_return' ) ) . '</p>' );
|
||||
$out->addHTML( '<p>' . $linker->link( $this->getTitle(), $this->msg( 'replacetext_return' )->escaped() ) . '</p>' );
|
||||
} else {
|
||||
// Show a warning message if the replacement
|
||||
// string is either blank or found elsewhere on
|
||||
|
@ -179,29 +206,25 @@ class ReplaceText extends SpecialPage {
|
|||
$warning_msg = null;
|
||||
|
||||
if ( $this->replacement === '' ) {
|
||||
$warning_msg = wfMsg('replacetext_blankwarning');
|
||||
$warning_msg = $this->msg('replacetext_blankwarning')->escaped();
|
||||
} elseif ( count( $titles_for_edit ) > 0 ) {
|
||||
$res = $this->doSearchQuery( $this->replacement, $this->selected_namespaces, $this->category, $this->prefix, $this->use_regex );
|
||||
$count = $res->numRows();
|
||||
if ( $count > 0 ) {
|
||||
$warning_msg = wfMsgExt( 'replacetext_warning', 'parsemag',
|
||||
$wgLang->formatNum( $count ),
|
||||
"<tt><nowiki>{$this->replacement}</nowiki></tt>"
|
||||
);
|
||||
$warning_msg = $this->msg( 'replacetext_warning' )->numParams( $count )
|
||||
->params( "<code><nowiki>{$this->replacement}</nowiki></code>" )->text();
|
||||
}
|
||||
} elseif ( count( $titles_for_move ) > 0 ) {
|
||||
$res = $this->getMatchingTitles( $this->replacement, $this->selected_namespaces, $this->category, $this->prefix, $this->use_regex );
|
||||
$count = $res->numRows();
|
||||
if ( $count > 0 ) {
|
||||
$warning_msg = wfMsgExt( 'replacetext_warning', 'parsemag',
|
||||
$wgLang->formatNum( $count ),
|
||||
$this->replacement
|
||||
);
|
||||
$warning_msg = $this->msg( 'replacetext_warning' )->numParams( $count )
|
||||
->params( $this->replacement )->text();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_null( $warning_msg ) ) {
|
||||
$wgOut->addWikiText("<div class=\"errorbox\">$warning_msg</div><br clear=\"both\" />");
|
||||
$out->addWikiText("<div class=\"errorbox\">$warning_msg</div><br clear=\"both\" />");
|
||||
}
|
||||
|
||||
$this->pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles );
|
||||
|
@ -214,54 +237,71 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
|
||||
function showForm( $warning_msg = null ) {
|
||||
global $wgOut;
|
||||
$wgOut->addHTML(
|
||||
Xml::openElement( 'form', array( 'id' => 'powersearch', 'action' => $this->getTitle()->getFullUrl(), 'method' => 'post' ) ) . "\n" .
|
||||
self::hiddenField( 'title', $this->getTitle()->getPrefixedText() ) .
|
||||
self::hiddenField( 'continue', 1 )
|
||||
$out = $this->getOutput();
|
||||
|
||||
$out->addHTML(
|
||||
Xml::openElement(
|
||||
'form',
|
||||
array(
|
||||
'id' => 'powersearch',
|
||||
'action' => $this->getTitle()->getFullUrl(),
|
||||
'method' => 'post'
|
||||
)
|
||||
) . "\n" .
|
||||
$this->hiddenField( 'title', $this->getTitle()->getPrefixedText() ) .
|
||||
$this->hiddenField( 'continue', 1 )
|
||||
);
|
||||
if ( is_null( $warning_msg ) ) {
|
||||
$wgOut->addWikiMsg( 'replacetext_docu' );
|
||||
$out->addWikiMsg( 'replacetext_docu' );
|
||||
} else {
|
||||
$wgOut->wrapWikiMsg( "<div class=\"errorbox\">\n$1\n</div><br clear=\"both\" />", $warning_msg );
|
||||
$out->wrapWikiMsg(
|
||||
"<div class=\"errorbox\">\n$1\n</div><br clear=\"both\" />",
|
||||
$warning_msg
|
||||
);
|
||||
}
|
||||
$wgOut->addHTML( '<table><tr><td style="vertical-align: top;">' );
|
||||
$wgOut->addWikiMsg( 'replacetext_originaltext' );
|
||||
$wgOut->addHTML( '</td><td>' );
|
||||
|
||||
$out->addHTML( '<table><tr><td style="vertical-align: top;">' );
|
||||
$out->addWikiMsg( 'replacetext_originaltext' );
|
||||
$out->addHTML( '</td><td>' );
|
||||
// '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;' ) ) );
|
||||
$wgOut->addHTML( '</td></tr><tr><td style="vertical-align: top;">' );
|
||||
$wgOut->addWikiMsg( 'replacetext_replacementtext' );
|
||||
$wgOut->addHTML( '</td><td>' );
|
||||
$wgOut->addHTML( Xml::textarea( 'replacement', $this->replacement, 50, 2, array( 'style' => 'width: auto;' ) ) );
|
||||
$wgOut->addHTML( '</td></tr></table>' );
|
||||
$wgOut->addHTML( Xml::tags( 'p', null,
|
||||
Xml::checkLabel( wfMsg( 'replacetext_useregex' ), 'use_regex', 'use_regex' ) ) . "\n" .
|
||||
Xml::element( 'p', array( 'style' => 'font-style: italic' ),
|
||||
wfMsg( 'replacetext_regexdocu' ) )
|
||||
$out->addHTML( Xml::textarea( 'target', $this->target, 50, 2, array( 'style' => 'width: auto;' ) ) );
|
||||
$out->addHTML( '</td></tr><tr><td style="vertical-align: top;">' );
|
||||
$out->addWikiMsg( 'replacetext_replacementtext' );
|
||||
$out->addHTML( '</td><td>' );
|
||||
$out->addHTML( Xml::textarea( 'replacement', $this->replacement, 50, 2, array( 'style' => 'width: auto;' ) ) );
|
||||
$out->addHTML( '</td></tr></table>' );
|
||||
$out->addHTML( Xml::tags( 'p', null,
|
||||
Xml::checkLabel(
|
||||
$this->msg( 'replacetext_useregex' )->text(),
|
||||
'use_regex', 'use_regex'
|
||||
)
|
||||
) . "\n" .
|
||||
Xml::element( 'p',
|
||||
array( 'style' => 'font-style: italic' ),
|
||||
$this->msg( 'replacetext_regexdocu' )->text()
|
||||
)
|
||||
);
|
||||
|
||||
// The interface is heavily based on the one in Special:Search.
|
||||
$search_label = wfMsg( 'powersearch-ns' );
|
||||
$namespaces = SearchEngine::searchableNamespaces();
|
||||
$tables = $this->namespaceTables( $namespaces );
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
"<div class=\"mw-search-formheader\"></div>\n" .
|
||||
"<fieldset id=\"mw-searchoptions\">\n" .
|
||||
Xml::tags( 'h4', null, wfMsgExt( 'powersearch-ns', array( 'parseinline' ) ) )
|
||||
Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() )
|
||||
);
|
||||
// The ability to select/unselect groups of namespaces in the
|
||||
// search interface exists only in some skins, like Vector -
|
||||
// check for the presence of the 'powersearch-togglelabel'
|
||||
// message to see if we can use this functionality here.
|
||||
if ( !wfEmptyMsg( 'powersearch-togglelabel', wfMsg( 'powersearch-togglelabel' ) ) ) {
|
||||
$wgOut->addHTML(
|
||||
if ( !$this->msg( 'powersearch-togglelabel' )->isDisabled() ) {
|
||||
$out->addHTML(
|
||||
Xml::tags(
|
||||
'div',
|
||||
array( 'id' => 'mw-search-togglebox' ),
|
||||
Xml::label( wfMsg( 'powersearch-togglelabel' ), 'mw-search-togglelabel' ) .
|
||||
Xml::label( $this->msg( 'powersearch-togglelabel' )->text(), 'mw-search-togglelabel' ) .
|
||||
Xml::element(
|
||||
'input',
|
||||
array(
|
||||
|
@ -269,7 +309,7 @@ class ReplaceText extends SpecialPage {
|
|||
'id' => 'mw-search-toggleall',
|
||||
// 'onclick' value needed for MW 1.16
|
||||
'onclick' => 'mwToggleSearchCheckboxes("all");',
|
||||
'value' => wfMsg( 'powersearch-toggleall' )
|
||||
'value' => $this->msg( 'powersearch-toggleall' )->text()
|
||||
)
|
||||
) .
|
||||
Xml::element(
|
||||
|
@ -279,23 +319,22 @@ class ReplaceText extends SpecialPage {
|
|||
'id' => 'mw-search-togglenone',
|
||||
// 'onclick' value needed for MW 1.16
|
||||
'onclick' => 'mwToggleSearchCheckboxes("none");',
|
||||
'value' => wfMsg( 'powersearch-togglenone' )
|
||||
'value' => $this->msg( 'powersearch-togglenone' )->text()
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
} // end if
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
|
||||
"$tables\n</fieldset>"
|
||||
);
|
||||
//FIXME: raw html messages
|
||||
$optional_filters_label = wfMsg( 'replacetext_optionalfilters' );
|
||||
$category_search_label = wfMsg( 'replacetext_categorysearch' );
|
||||
$prefix_search_label = wfMsg( 'replacetext_prefixsearch' );
|
||||
$wgOut->addHTML(
|
||||
// @todo FIXME: raw html messages
|
||||
$category_search_label = $this->msg( 'replacetext_categorysearch' )->text();
|
||||
$prefix_search_label = $this->msg( 'replacetext_prefixsearch' )->text();
|
||||
$out->addHTML(
|
||||
"<fieldset id=\"mw-searchoptions\">\n" .
|
||||
Xml::tags( 'h4', null, wfMsgExt( 'replacetext_optionalfilters', array( 'parseinline' ) ) ) .
|
||||
Xml::tags( 'h4', null, $this->msg( 'replacetext_optionalfilters' )->parse() ) .
|
||||
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
|
||||
"<p>$category_search_label\n" .
|
||||
Xml::input( 'category', 20, $this->category, array( 'type' => 'text' ) ) . '</p>' .
|
||||
|
@ -303,18 +342,14 @@ class ReplaceText extends SpecialPage {
|
|||
Xml::input( 'prefix', 20, $this->prefix, array( 'type' => 'text' ) ) . '</p>' .
|
||||
"</fieldset>\n" .
|
||||
"<p>\n" .
|
||||
Xml::checkLabel( wfMsg( 'replacetext_editpages' ), 'edit_pages', 'edit_pages', true ) . '<br />' .
|
||||
Xml::checkLabel( wfMsg( 'replacetext_movepages' ), 'move_pages', 'move_pages' ) .
|
||||
Xml::checkLabel( $this->msg( 'replacetext_editpages' )->text(), 'edit_pages', 'edit_pages', true ) . '<br />' .
|
||||
Xml::checkLabel( $this->msg( 'replacetext_movepages' )->text(), 'move_pages', 'move_pages' ) .
|
||||
"</p>\n" .
|
||||
Xml::submitButton( wfMsg( 'replacetext_continue' ) ) .
|
||||
Xml::submitButton( $this->msg( 'replacetext_continue' )->text() ) .
|
||||
Xml::closeElement( 'form' )
|
||||
);
|
||||
// Add Javascript specific to Special:Search
|
||||
if ( method_exists( $wgOut, 'addModules' ) ) {
|
||||
$wgOut->addModules( 'mediawiki.special.search' );
|
||||
} else {
|
||||
$wgOut->addScriptFile( 'search.js' );
|
||||
}
|
||||
$out->addModules( 'mediawiki.special.search' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -334,7 +369,7 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
$name = str_replace( '_', ' ', $name );
|
||||
if ( '' == $name ) {
|
||||
$name = wfMsg( 'blanknamespace' );
|
||||
$name = $this->msg( 'blanknamespace' )->text();
|
||||
}
|
||||
$rows[$subj] .= Xml::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
|
||||
Xml::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $namespaces ) ) .
|
||||
|
@ -359,55 +394,60 @@ class ReplaceText extends SpecialPage {
|
|||
}
|
||||
|
||||
function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
|
||||
global $wgOut, $wgLang, $wgScriptPath;
|
||||
global $wgLang, $wgScriptPath;
|
||||
|
||||
$out = $this->getOutput();
|
||||
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
|
||||
|
||||
$formOpts = array( 'id' => 'choose_pages', 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
Xml::openElement( 'form', $formOpts ) . "\n" .
|
||||
self::hiddenField( 'title', $this->getTitle()->getPrefixedText() ) .
|
||||
self::hiddenField( 'target', $this->target ) .
|
||||
self::hiddenField( 'replacement', $this->replacement ) .
|
||||
self::hiddenField( 'use_regex', $this->use_regex )
|
||||
$this->hiddenField( 'title', $this->getTitle()->getPrefixedText() ) .
|
||||
$this->hiddenField( 'target', $this->target ) .
|
||||
$this->hiddenField( 'replacement', $this->replacement ) .
|
||||
$this->hiddenField( 'use_regex', $this->use_regex )
|
||||
);
|
||||
|
||||
$wgOut->addScriptFile( "$wgScriptPath/extensions/ReplaceText/ReplaceText.js" );
|
||||
$out->addScriptFile( "$wgScriptPath/extensions/ReplaceText/ReplaceText.js" );
|
||||
|
||||
if ( count( $titles_for_edit ) > 0 ) {
|
||||
$wgOut->addWikiMsg( 'replacetext_choosepagesforedit', "<tt><nowiki>{$this->target}</nowiki></tt>", "<tt><nowiki>{$this->replacement}</nowiki></tt>",
|
||||
$out->addWikiMsg( 'replacetext_choosepagesforedit', "<code><nowiki>{$this->target}</nowiki></code>", "<code><nowiki>{$this->replacement}</nowiki></code>",
|
||||
$wgLang->formatNum( count( $titles_for_edit ) ) );
|
||||
|
||||
foreach ( $titles_for_edit as $title_and_context ) {
|
||||
/**
|
||||
* @var $title Title
|
||||
*/
|
||||
list( $title, $context ) = $title_and_context;
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
Xml::check( $title->getArticleID(), true ) .
|
||||
$linker->link( $title ) . " - <small>$context</small><br />\n"
|
||||
);
|
||||
}
|
||||
$wgOut->addHTML( '<br />' );
|
||||
$out->addHTML( '<br />' );
|
||||
}
|
||||
|
||||
if ( count( $titles_for_move ) > 0 ) {
|
||||
$wgOut->addWikiMsg( 'replacetext_choosepagesformove', $this->target, $this->replacement, $wgLang->formatNum( count( $titles_for_move ) ) );
|
||||
$out->addWikiMsg( 'replacetext_choosepagesformove', $this->target, $this->replacement, $wgLang->formatNum( count( $titles_for_move ) ) );
|
||||
foreach ( $titles_for_move as $title ) {
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
Xml::check( 'move-' . $title->getArticleID(), true ) .
|
||||
$linker->link( $title ) . "<br />\n"
|
||||
);
|
||||
}
|
||||
$wgOut->addHTML( '<br />' );
|
||||
$wgOut->addWikiMsg( 'replacetext_formovedpages' );
|
||||
$wgOut->addHTML(
|
||||
Xml::checkLabel( wfMsg( 'replacetext_savemovedpages' ), 'create-redirect', 'create-redirect', true ) . "<br />\n" .
|
||||
Xml::checkLabel( wfMsg( 'replacetext_watchmovedpages' ), 'watch-pages', 'watch-pages', false )
|
||||
$out->addHTML( '<br />' );
|
||||
$out->addWikiMsg( 'replacetext_formovedpages' );
|
||||
$out->addHTML(
|
||||
Xml::checkLabel( $this->msg( 'replacetext_savemovedpages' )->text(), 'create-redirect', 'create-redirect', true ) . "<br />\n" .
|
||||
Xml::checkLabel( $this->msg( 'replacetext_watchmovedpages' )->text(), 'watch-pages', 'watch-pages', false )
|
||||
);
|
||||
$wgOut->addHTML( '<br />' );
|
||||
$out->addHTML( '<br />' );
|
||||
}
|
||||
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
"<br />\n" .
|
||||
Xml::submitButton( wfMsg( 'replacetext_replace' ) ) . "\n" .
|
||||
self::hiddenField( 'replace', 1 )
|
||||
Xml::submitButton( $this->msg( 'replacetext_replace' )->text() ) . "\n" .
|
||||
$this->hiddenField( 'replace', 1 )
|
||||
);
|
||||
|
||||
// Only show "invert selections" link if there are more than
|
||||
|
@ -415,37 +455,37 @@ class ReplaceText extends SpecialPage {
|
|||
if ( count( $titles_for_edit ) + count( $titles_for_move ) > 5 ) {
|
||||
$buttonOpts = array(
|
||||
'type' => 'button',
|
||||
'value' => wfMsg( 'replacetext_invertselections' ),
|
||||
'value' => $this->msg( 'replacetext_invertselections' )->text(),
|
||||
'onclick' => 'invertSelections(); return false;'
|
||||
);
|
||||
|
||||
$wgOut->addHTML(
|
||||
$out->addHTML(
|
||||
Xml::element( 'input', $buttonOpts )
|
||||
);
|
||||
}
|
||||
|
||||
$wgOut->addHTML( '</form>' );
|
||||
$out->addHTML( '</form>' );
|
||||
|
||||
if ( count( $unmoveable_titles ) > 0 ) {
|
||||
$wgOut->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) );
|
||||
$out->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) );
|
||||
$text = "<ul>\n";
|
||||
foreach ( $unmoveable_titles as $title ) {
|
||||
$text .= "<li>{$linker->link( $title )}<br />\n";
|
||||
}
|
||||
$text .= "</ul>\n";
|
||||
$wgOut->addHTML( $text );
|
||||
$out->addHTML( $text );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract context and highlights search text
|
||||
*
|
||||
* TODO: The bolding needs to be fixed for regular expressions.
|
||||
* @todo The bolding needs to be fixed for regular expressions.
|
||||
*/
|
||||
function extractContext( $text, $target, $use_regex = false ) {
|
||||
global $wgLang;
|
||||
|
||||
$cw = $this->user->getOption( 'contextchars', 40 );
|
||||
$cw = $this->getUser()->getOption( 'contextchars', 40 );
|
||||
|
||||
// Get all indexes
|
||||
if ( $use_regex ) {
|
||||
|
@ -480,26 +520,26 @@ class ReplaceText extends SpecialPage {
|
|||
$context = '';
|
||||
foreach ( $cuts as $_ ) {
|
||||
list( $index, $len, ) = $_;
|
||||
$context .= self::convertWhiteSpaceToHTML(
|
||||
$context .= $this->convertWhiteSpaceToHTML(
|
||||
$wgLang->truncate( substr( $text, 0, $index ), - $cw, '...', false )
|
||||
);
|
||||
$snippet = self::convertWhiteSpaceToHTML( substr( $text, $index, $len ) );
|
||||
$snippet = $this->convertWhiteSpaceToHTML( substr( $text, $index, $len ) );
|
||||
if ( $use_regex ) {
|
||||
$targetStr = "/$target/U";
|
||||
} else {
|
||||
$targetq = preg_quote( self::convertWhiteSpaceToHTML( $target ), '/' );
|
||||
$targetq = preg_quote( $this->convertWhiteSpaceToHTML( $target ), '/' );
|
||||
$targetStr = "/$targetq/i";
|
||||
}
|
||||
$context .= preg_replace( $targetStr, '<span class="searchmatch">\0</span>', $snippet );
|
||||
|
||||
$context .= self::convertWhiteSpaceToHTML(
|
||||
$context .= $this->convertWhiteSpaceToHTML(
|
||||
$wgLang->truncate( substr( $text, $index + $len ), $cw, '...', false )
|
||||
);
|
||||
}
|
||||
return $context;
|
||||
}
|
||||
|
||||
public static function convertWhiteSpaceToHTML( $msg ) {
|
||||
private function convertWhiteSpaceToHTML( $msg ) {
|
||||
$msg = htmlspecialchars( $msg );
|
||||
$msg = preg_replace( '/^ /m', '  ', $msg );
|
||||
$msg = preg_replace( '/ $/m', '  ', $msg );
|
||||
|
|
Loading…
Reference in a new issue