2011-02-16 13:22:10 +00:00
|
|
|
<?php
|
2008-08-06 16:09:35 +00:00
|
|
|
|
|
|
|
class ReplaceText extends SpecialPage {
|
2012-10-07 10:56:07 +00:00
|
|
|
private $target, $replacement, $use_regex, $category, $prefix, $edit_pages, $move_pages, $selected_namespaces;
|
2011-02-16 03:11:20 +00:00
|
|
|
|
2008-09-18 16:29:10 +00:00
|
|
|
public function __construct() {
|
2009-04-27 09:02:48 +00:00
|
|
|
parent::__construct( 'ReplaceText', 'replacetext' );
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 05:48:04 +00:00
|
|
|
function execute( $query ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
if ( !$this->getUser()->isAllowed( 'replacetext' ) ) {
|
|
|
|
throw new PermissionsError( 'replacetext' );
|
2008-09-18 16:29:10 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 16:09:35 +00:00
|
|
|
$this->setHeaders();
|
2012-10-07 10:56:07 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
if ( !is_null( $out->getResourceLoader()->getModule( 'mediawiki.special' ) ) ) {
|
|
|
|
$out->addModuleStyles( 'mediawiki.special' );
|
2012-01-03 13:36:56 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
$this->doSpecialReplaceText();
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
function getSelectedNamespaces() {
|
2009-05-19 15:19:15 +00:00
|
|
|
$all_namespaces = SearchEngine::searchableNamespaces();
|
|
|
|
$selected_namespaces = array();
|
2010-03-14 18:10:47 +00:00
|
|
|
foreach ( $all_namespaces as $ns => $name ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
if ( $this->getRequest()->getCheck( 'ns' . $ns ) ) {
|
2009-05-19 15:19:15 +00:00
|
|
|
$selected_namespaces[] = $ns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $selected_namespaces;
|
|
|
|
}
|
|
|
|
|
2011-07-12 22:44:16 +00:00
|
|
|
/**
|
|
|
|
* Helper function to display a hidden field for different versions
|
|
|
|
* of MediaWiki.
|
|
|
|
*/
|
2012-10-07 10:56:07 +00:00
|
|
|
function hiddenField( $name, $value ) {
|
|
|
|
return "\t" . Html::hidden( $name, $value ) . "\n";
|
2011-07-12 22:44:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 08:52:10 +00:00
|
|
|
function doSpecialReplaceText() {
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2012-10-07 10:56:07 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2012-01-01 08:54:58 +00:00
|
|
|
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$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();
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2012-11-06 02:08:00 +00:00
|
|
|
if ( $request->getCheck( 'continue' ) && $this->target === '' ) {
|
|
|
|
$this->showForm( 'replacetext_givetarget' );
|
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
return;
|
2009-01-22 23:40:30 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
if ( $request->getCheck( 'replace' ) ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$replacement_params = array();
|
2012-10-07 10:56:07 +00:00
|
|
|
$replacement_params['user_id'] = $this->getUser()->getId();
|
2009-04-30 18:55:08 +00:00
|
|
|
$replacement_params['target_str'] = $this->target;
|
|
|
|
$replacement_params['replacement_str'] = $this->replacement;
|
2011-02-16 03:11:20 +00:00
|
|
|
$replacement_params['use_regex'] = $this->use_regex;
|
2012-10-07 10:56:07 +00:00
|
|
|
$replacement_params['edit_summary'] = $this->msg(
|
|
|
|
'replacetext_editsummary',
|
|
|
|
$this->target, $this->replacement
|
|
|
|
)->inContentLanguage()->text();
|
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;
|
2012-10-07 10:56:07 +00:00
|
|
|
foreach ( $request->getValues() as $key => $value ) {
|
2009-04-27 09:02:48 +00:00
|
|
|
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();
|
2012-10-07 10:56:07 +00:00
|
|
|
foreach ( $request->getValues() as $key => $value ) {
|
2012-02-17 19:49:36 +00:00
|
|
|
if ( $value == '1' && $key !== 'replace' && $key !== 'use_regex' ) {
|
2009-07-16 19:54:10 +00:00
|
|
|
if ( strpos( $key, 'move-' ) !== false ) {
|
2009-05-19 15:19:15 +00:00
|
|
|
$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 );
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$count = $this->getLanguage()->formatNum( count( $jobs ) );
|
|
|
|
$out->addWikiMsg(
|
|
|
|
'replacetext_success',
|
|
|
|
"<code><nowiki>{$this->target}</nowiki></code>",
|
|
|
|
"<code><nowiki>{$this->replacement}</nowiki></code>",
|
|
|
|
$count
|
|
|
|
);
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
// Link back
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
|
|
|
$linker->link( $this->getTitle(),
|
|
|
|
$this->msg( 'replacetext_return' )->escaped() )
|
|
|
|
);
|
|
|
|
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-05-05 20:09:54 +00:00
|
|
|
return;
|
2012-10-07 10:56:07 +00:00
|
|
|
} elseif ( $request->getCheck( 'target' ) ) { // very long elseif, look for "end elseif"
|
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' );
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-05-21 13:27:58 +00:00
|
|
|
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' );
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-04-27 18:48:27 +00:00
|
|
|
return;
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
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
|
|
|
// if user is replacing text within pages...
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( $this->edit_pages ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$res = $this->doSearchQuery(
|
|
|
|
$this->target,
|
|
|
|
$this->selected_namespaces,
|
|
|
|
$this->category,
|
|
|
|
$this->prefix,
|
|
|
|
$this->use_regex
|
|
|
|
);
|
|
|
|
|
2009-04-27 18:48:27 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
|
2011-02-16 03:11:20 +00:00
|
|
|
$context = $this->extractContext( $row->old_text, $this->target, $this->use_regex );
|
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 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$res = $this->getMatchingTitles(
|
|
|
|
$this->target,
|
|
|
|
$this->selected_namespaces,
|
|
|
|
$this->category,
|
|
|
|
$this->prefix,
|
|
|
|
$this->use_regex
|
|
|
|
);
|
|
|
|
|
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
|
2010-03-14 18:10:47 +00:00
|
|
|
$cur_page_name = str_replace( '_', ' ', $row->page_title );
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2011-02-16 03:11:20 +00:00
|
|
|
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 );
|
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2009-04-30 22:23:59 +00:00
|
|
|
$new_title = Title::makeTitleSafe( $row->page_namespace, $new_page_name );
|
2009-04-27 09:02:48 +00:00
|
|
|
$err = $title->isValidMoveOperation( $new_title );
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2011-11-06 18:16:54 +00:00
|
|
|
if ( $title->userCan( 'move' ) && !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
|
|
|
}
|
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2009-09-08 00:04:25 +00:00
|
|
|
// if no results were found, check to see if a bad
|
|
|
|
// category name was entered
|
2010-03-14 18:10:47 +00:00
|
|
|
if ( count( $titles_for_edit ) == 0 && count( $titles_for_move ) == 0 ) {
|
2009-09-08 00:04:25 +00:00
|
|
|
$bad_cat_name = false;
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2010-03-14 18:10:47 +00:00
|
|
|
if ( ! empty( $this->category ) ) {
|
|
|
|
$category_title = Title::makeTitleSafe( NS_CATEGORY, $this->category );
|
|
|
|
if ( ! $category_title->exists() ) $bad_cat_name = true;
|
2009-09-08 00:04:25 +00:00
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2010-03-14 18:10:47 +00:00
|
|
|
if ( $bad_cat_name ) {
|
2012-01-01 08:54:58 +00:00
|
|
|
$link = $linker->link( $category_title, htmlspecialchars( ucfirst( $this->category ) ) );
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
|
|
|
$this->msg( 'replacetext_nosuchcategory' )->rawParams( $link )->escaped()
|
|
|
|
);
|
2009-09-08 00:04:25 +00:00
|
|
|
} else {
|
2012-11-06 02:08:00 +00:00
|
|
|
if ( $this->edit_pages ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiMsg( 'replacetext_noreplacement', "<code><nowiki>{$this->target}</nowiki></code>" );
|
2012-11-06 02:08:00 +00:00
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
|
2012-11-06 02:08:00 +00:00
|
|
|
if ( $this->move_pages ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiMsg( 'replacetext_nomove', "<code><nowiki>{$this->target}</nowiki></code>" );
|
2012-11-06 02:08:00 +00:00
|
|
|
}
|
2009-09-08 00:04:25 +00:00
|
|
|
}
|
|
|
|
// link back to starting form
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML( '<p>' . $linker->link( $this->getTitle(), $this->msg( 'replacetext_return' )->escaped() ) . '</p>' );
|
2009-04-27 08:52:10 +00:00
|
|
|
} else {
|
2011-02-16 03:11:20 +00:00
|
|
|
// Show a warning message if the replacement
|
|
|
|
// string is either blank or found elsewhere on
|
|
|
|
// the wiki (since undoing the replacement
|
|
|
|
// would be difficult in either case).
|
2010-03-18 03:39:45 +00:00
|
|
|
$warning_msg = null;
|
|
|
|
|
|
|
|
if ( $this->replacement === '' ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$warning_msg = $this->msg('replacetext_blankwarning')->escaped();
|
2010-03-18 03:39:45 +00:00
|
|
|
} elseif ( count( $titles_for_edit ) > 0 ) {
|
2011-02-16 03:11:20 +00:00
|
|
|
$res = $this->doSearchQuery( $this->replacement, $this->selected_namespaces, $this->category, $this->prefix, $this->use_regex );
|
2010-03-18 03:39:45 +00:00
|
|
|
$count = $res->numRows();
|
|
|
|
if ( $count > 0 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$warning_msg = $this->msg( 'replacetext_warning' )->numParams( $count )
|
|
|
|
->params( "<code><nowiki>{$this->replacement}</nowiki></code>" )->text();
|
2010-03-18 03:39:45 +00:00
|
|
|
}
|
|
|
|
} elseif ( count( $titles_for_move ) > 0 ) {
|
2011-02-16 03:11:20 +00:00
|
|
|
$res = $this->getMatchingTitles( $this->replacement, $this->selected_namespaces, $this->category, $this->prefix, $this->use_regex );
|
2010-03-18 03:39:45 +00:00
|
|
|
$count = $res->numRows();
|
|
|
|
if ( $count > 0 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$warning_msg = $this->msg( 'replacetext_warning' )->numParams( $count )
|
|
|
|
->params( $this->replacement )->text();
|
2010-03-18 03:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_null( $warning_msg ) ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiText("<div class=\"errorbox\">$warning_msg</div><br clear=\"both\" />");
|
2010-03-18 03:39:45 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
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
|
2010-03-18 03:39:45 +00:00
|
|
|
$this->showForm();
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2008-08-06 16:09:35 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2010-03-18 03:39:45 +00:00
|
|
|
function showForm( $warning_msg = null ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$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 )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
2010-03-18 03:39:45 +00:00
|
|
|
if ( is_null( $warning_msg ) ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiMsg( 'replacetext_docu' );
|
2010-03-18 03:39:45 +00:00
|
|
|
} else {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->wrapWikiMsg(
|
|
|
|
"<div class=\"errorbox\">\n$1\n</div><br clear=\"both\" />",
|
|
|
|
$warning_msg
|
|
|
|
);
|
2010-03-18 03:39:45 +00:00
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
|
|
|
|
$out->addHTML( '<table><tr><td style="vertical-align: top;">' );
|
|
|
|
$out->addWikiMsg( 'replacetext_originaltext' );
|
|
|
|
$out->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
|
2012-10-07 10:56:07 +00:00
|
|
|
$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()
|
|
|
|
)
|
2011-02-16 03:11:20 +00:00
|
|
|
);
|
2009-05-19 15:19:15 +00:00
|
|
|
|
2011-02-16 03:11:20 +00:00
|
|
|
// The interface is heavily based on the one in Special:Search.
|
2009-08-14 17:28:25 +00:00
|
|
|
$namespaces = SearchEngine::searchableNamespaces();
|
|
|
|
$tables = $this->namespaceTables( $namespaces );
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2010-03-18 03:39:45 +00:00
|
|
|
"<div class=\"mw-search-formheader\"></div>\n" .
|
|
|
|
"<fieldset id=\"mw-searchoptions\">\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() )
|
2010-03-18 03:39:45 +00:00
|
|
|
);
|
2011-02-16 03:11:20 +00:00
|
|
|
// The ability to select/unselect groups of namespaces in the
|
2010-10-04 16:20:30 +00:00
|
|
|
// search interface exists only in some skins, like Vector -
|
|
|
|
// check for the presence of the 'powersearch-togglelabel'
|
2011-02-16 03:11:20 +00:00
|
|
|
// message to see if we can use this functionality here.
|
2012-10-07 10:56:07 +00:00
|
|
|
if ( !$this->msg( 'powersearch-togglelabel' )->isDisabled() ) {
|
|
|
|
$out->addHTML(
|
2010-03-18 03:39:45 +00:00
|
|
|
Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'id' => 'mw-search-togglebox' ),
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::label( $this->msg( 'powersearch-togglelabel' )->text(), 'mw-search-togglelabel' ) .
|
2010-03-18 03:39:45 +00:00
|
|
|
Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type'=>'button',
|
|
|
|
'id' => 'mw-search-toggleall',
|
2012-01-03 13:36:56 +00:00
|
|
|
// 'onclick' value needed for MW 1.16
|
2010-03-18 03:39:45 +00:00
|
|
|
'onclick' => 'mwToggleSearchCheckboxes("all");',
|
2012-10-07 10:56:07 +00:00
|
|
|
'value' => $this->msg( 'powersearch-toggleall' )->text()
|
2010-03-18 03:39:45 +00:00
|
|
|
)
|
|
|
|
) .
|
|
|
|
Xml::element(
|
|
|
|
'input',
|
|
|
|
array(
|
|
|
|
'type'=>'button',
|
|
|
|
'id' => 'mw-search-togglenone',
|
2012-01-03 13:36:56 +00:00
|
|
|
// 'onclick' value needed for MW 1.16
|
2010-03-18 03:39:45 +00:00
|
|
|
'onclick' => 'mwToggleSearchCheckboxes("none");',
|
2012-10-07 10:56:07 +00:00
|
|
|
'value' => $this->msg( 'powersearch-togglenone' )->text()
|
2010-03-18 03:39:45 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} // end if
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2010-03-18 03:39:45 +00:00
|
|
|
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
|
|
|
|
"$tables\n</fieldset>"
|
|
|
|
);
|
2012-10-07 10:56:07 +00:00
|
|
|
// @todo FIXME: raw html messages
|
|
|
|
$category_search_label = $this->msg( 'replacetext_categorysearch' )->text();
|
|
|
|
$prefix_search_label = $this->msg( 'replacetext_prefixsearch' )->text();
|
|
|
|
$out->addHTML(
|
2010-03-18 03:39:45 +00:00
|
|
|
"<fieldset id=\"mw-searchoptions\">\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::tags( 'h4', null, $this->msg( 'replacetext_optionalfilters' )->parse() ) .
|
2010-03-18 03:39:45 +00:00
|
|
|
Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
|
2009-08-14 18:50:41 +00:00
|
|
|
"<p>$category_search_label\n" .
|
2011-12-07 02:52:08 +00:00
|
|
|
Xml::input( 'category', 20, $this->category, array( 'type' => 'text' ) ) . '</p>' .
|
2009-08-14 18:50:41 +00:00
|
|
|
"<p>$prefix_search_label\n" .
|
2011-12-07 02:52:08 +00:00
|
|
|
Xml::input( 'prefix', 20, $this->prefix, array( 'type' => 'text' ) ) . '</p>' .
|
2009-08-14 17:28:25 +00:00
|
|
|
"</fieldset>\n" .
|
2010-03-18 03:39:45 +00:00
|
|
|
"<p>\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::checkLabel( $this->msg( 'replacetext_editpages' )->text(), 'edit_pages', 'edit_pages', true ) . '<br />' .
|
|
|
|
Xml::checkLabel( $this->msg( 'replacetext_movepages' )->text(), 'move_pages', 'move_pages' ) .
|
2010-03-18 03:39:45 +00:00
|
|
|
"</p>\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::submitButton( $this->msg( 'replacetext_continue' )->text() ) .
|
2009-04-27 08:52:10 +00:00
|
|
|
Xml::closeElement( 'form' )
|
|
|
|
);
|
2012-01-03 13:36:56 +00:00
|
|
|
// Add Javascript specific to Special:Search
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addModules( 'mediawiki.special.search' );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
2009-05-19 15:19:15 +00:00
|
|
|
/**
|
|
|
|
* Copied almost exactly from MediaWiki's SpecialSearch class, i.e.
|
|
|
|
* the search page
|
|
|
|
*/
|
2010-03-18 03:39:45 +00:00
|
|
|
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 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$name = $this->msg( 'blanknamespace' )->text();
|
2010-03-18 03:39:45 +00:00
|
|
|
}
|
|
|
|
$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-05-19 15:19:15 +00:00
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
global $wgLang, $wgScriptPath;
|
|
|
|
|
|
|
|
$out = $this->getOutput();
|
2012-01-01 08:54:58 +00:00
|
|
|
$linker = class_exists( 'DummyLinker' ) ? new DummyLinker : new Linker;
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
$formOpts = array( 'id' => 'choose_pages', 'method' => 'post', 'action' => $this->getTitle()->getFullUrl() );
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2011-07-12 22:44:16 +00:00
|
|
|
Xml::openElement( 'form', $formOpts ) . "\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
$this->hiddenField( 'title', $this->getTitle()->getPrefixedText() ) .
|
|
|
|
$this->hiddenField( 'target', $this->target ) .
|
|
|
|
$this->hiddenField( 'replacement', $this->replacement ) .
|
|
|
|
$this->hiddenField( 'use_regex', $this->use_regex )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addScriptFile( "$wgScriptPath/extensions/ReplaceText/ReplaceText.js" );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2009-04-30 18:55:08 +00:00
|
|
|
if ( count( $titles_for_edit ) > 0 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiMsg( 'replacetext_choosepagesforedit', "<code><nowiki>{$this->target}</nowiki></code>", "<code><nowiki>{$this->replacement}</nowiki></code>",
|
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 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
/**
|
|
|
|
* @var $title Title
|
|
|
|
*/
|
2009-04-27 18:48:27 +00:00
|
|
|
list( $title, $context ) = $title_and_context;
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2009-04-27 18:48:27 +00:00
|
|
|
Xml::check( $title->getArticleID(), true ) .
|
2012-01-01 08:54:58 +00:00
|
|
|
$linker->link( $title ) . " - <small>$context</small><br />\n"
|
2009-04-27 18:48:27 +00:00
|
|
|
);
|
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML( '<br />' );
|
2009-04-27 18:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( count( $titles_for_move ) > 0 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->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 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2009-04-27 09:02:48 +00:00
|
|
|
Xml::check( 'move-' . $title->getArticleID(), true ) .
|
2012-01-01 08:54:58 +00:00
|
|
|
$linker->link( $title ) . "<br />\n"
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
}
|
2012-10-07 10:56:07 +00:00
|
|
|
$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 )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML( '<br />' );
|
2008-11-05 20:37:50 +00:00
|
|
|
}
|
2008-09-02 17:34:40 +00:00
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2009-04-27 18:48:27 +00:00
|
|
|
"<br />\n" .
|
2012-10-07 10:56:07 +00:00
|
|
|
Xml::submitButton( $this->msg( 'replacetext_replace' )->text() ) . "\n" .
|
|
|
|
$this->hiddenField( 'replace', 1 )
|
2009-04-27 08:52:10 +00:00
|
|
|
);
|
|
|
|
|
2011-02-16 03:11:20 +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',
|
2012-10-07 10:56:07 +00:00
|
|
|
'value' => $this->msg( 'replacetext_invertselections' )->text(),
|
2009-04-27 08:52:10 +00:00
|
|
|
'onclick' => 'invertSelections(); return false;'
|
|
|
|
);
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML(
|
2009-04-27 08:52:10 +00:00
|
|
|
Xml::element( 'input', $buttonOpts )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addHTML( '</form>' );
|
2008-08-06 16:09:35 +00:00
|
|
|
|
2009-04-27 09:02:48 +00:00
|
|
|
if ( count( $unmoveable_titles ) > 0 ) {
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->addWikiMsg( 'replacetext_cannotmove', $wgLang->formatNum( count( $unmoveable_titles ) ) );
|
2009-04-27 08:52:10 +00:00
|
|
|
$text = "<ul>\n";
|
2009-04-27 09:02:48 +00:00
|
|
|
foreach ( $unmoveable_titles as $title ) {
|
2012-01-01 08:54:58 +00:00
|
|
|
$text .= "<li>{$linker->link( $title )}<br />\n";
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
2008-11-05 20:37:50 +00:00
|
|
|
$text .= "</ul>\n";
|
2012-10-07 10:56:07 +00:00
|
|
|
$out->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
|
2011-02-16 03:11:20 +00:00
|
|
|
*
|
2012-10-07 10:56:07 +00:00
|
|
|
* @todo The bolding needs to be fixed for regular expressions.
|
2009-04-27 08:52:10 +00:00
|
|
|
*/
|
2011-02-16 03:11:20 +00:00
|
|
|
function extractContext( $text, $target, $use_regex = false ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
global $wgLang;
|
2011-02-16 03:11:20 +00:00
|
|
|
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2012-10-07 10:56:07 +00:00
|
|
|
$cw = $this->getUser()->getOption( 'contextchars', 40 );
|
2009-04-27 08:52:10 +00:00
|
|
|
|
|
|
|
// Get all indexes
|
2011-02-16 03:11:20 +00:00
|
|
|
if ( $use_regex ) {
|
|
|
|
preg_match_all( "/$target/", $text, $matches, PREG_OFFSET_CAPTURE );
|
|
|
|
} else {
|
|
|
|
$targetq = preg_quote( $target, '/' );
|
|
|
|
preg_match_all( "/$targetq/", $text, $matches, PREG_OFFSET_CAPTURE );
|
|
|
|
}
|
2012-11-06 02:08:00 +00:00
|
|
|
|
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, ) = $_;
|
2012-10-07 10:56:07 +00:00
|
|
|
$context .= $this->convertWhiteSpaceToHTML(
|
2012-01-03 13:36:56 +00:00
|
|
|
$wgLang->truncate( substr( $text, 0, $index ), - $cw, '...', false )
|
2011-03-24 03:43:27 +00:00
|
|
|
);
|
2012-10-07 10:56:07 +00:00
|
|
|
$snippet = $this->convertWhiteSpaceToHTML( substr( $text, $index, $len ) );
|
2011-02-16 03:11:20 +00:00
|
|
|
if ( $use_regex ) {
|
2012-01-03 13:36:56 +00:00
|
|
|
$targetStr = "/$target/U";
|
2011-02-16 03:11:20 +00:00
|
|
|
} else {
|
2012-10-07 10:56:07 +00:00
|
|
|
$targetq = preg_quote( $this->convertWhiteSpaceToHTML( $target ), '/' );
|
2011-02-16 03:11:20 +00:00
|
|
|
$targetStr = "/$targetq/i";
|
|
|
|
}
|
|
|
|
$context .= preg_replace( $targetStr, '<span class="searchmatch">\0</span>', $snippet );
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
$context .= $this->convertWhiteSpaceToHTML(
|
2011-03-24 03:43:27 +00:00
|
|
|
$wgLang->truncate( substr( $text, $index + $len ), $cw, '...', false )
|
|
|
|
);
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
2012-11-06 02:08:00 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2009-04-27 08:52:10 +00:00
|
|
|
return $context;
|
|
|
|
}
|
|
|
|
|
2012-10-07 10:56:07 +00:00
|
|
|
private function convertWhiteSpaceToHTML( $msg ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$msg = htmlspecialchars( $msg );
|
2010-05-30 17:33:59 +00:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2011-02-16 03:11:20 +00:00
|
|
|
function getMatchingTitles( $str, $namespaces, $category, $prefix, $use_regex = false ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-07-30 17:45:36 +00:00
|
|
|
|
2009-08-14 17:28:25 +00:00
|
|
|
$tables = array( 'page' );
|
|
|
|
$vars = array( 'page_title', 'page_namespace' );
|
2011-03-15 20:30:32 +00:00
|
|
|
|
|
|
|
$str = str_replace( ' ', '_', $str );
|
2011-02-16 03:11:20 +00:00
|
|
|
if ( $use_regex ) {
|
2012-02-17 19:49:36 +00:00
|
|
|
$comparisonCond = $this->regexCond( $dbr, 'page_title', $str );
|
2010-10-04 16:20:30 +00:00
|
|
|
} else {
|
2013-01-02 14:41:30 +00:00
|
|
|
$any = $dbr->anyString();
|
|
|
|
$comparisonCond = 'page_title ' . $dbr->buildLike( $any, $str, $any );
|
2010-10-04 16:20:30 +00:00
|
|
|
}
|
2011-02-16 03:11:20 +00:00
|
|
|
$conds = array(
|
|
|
|
$comparisonCond,
|
2011-02-16 19:04:56 +00:00
|
|
|
'page_namespace' => $namespaces,
|
2011-02-16 03:11:20 +00:00
|
|
|
);
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2010-10-04 16:20:30 +00:00
|
|
|
$this->categoryCondition( $category, $tables, $conds );
|
2010-07-30 17:45:36 +00:00
|
|
|
$this->prefixCondition( $prefix, $conds );
|
|
|
|
$sort = array( 'ORDER BY' => 'page_namespace, page_title' );
|
|
|
|
|
|
|
|
return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
|
2008-10-13 12:34:00 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2011-02-16 03:11:20 +00:00
|
|
|
function doSearchQuery( $search, $namespaces, $category, $prefix, $use_regex = false ) {
|
2009-04-27 08:52:10 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$tables = array( 'page', 'revision', 'text' );
|
|
|
|
$vars = array( 'page_id', 'page_namespace', 'page_title', 'old_text' );
|
2011-02-16 03:11:20 +00:00
|
|
|
if ( $use_regex ) {
|
2012-02-17 19:49:36 +00:00
|
|
|
$comparisonCond = $this->regexCond( $dbr, 'old_text', $search );
|
2010-10-04 16:20:30 +00:00
|
|
|
} else {
|
2012-12-09 15:03:08 +00:00
|
|
|
$any = $dbr->anyString();
|
|
|
|
$comparisonCond = 'old_text ' . $dbr->buildLike( $any, $search, $any );
|
2010-10-04 16:20:30 +00:00
|
|
|
}
|
2011-02-16 03:11:20 +00:00
|
|
|
$conds = array(
|
|
|
|
$comparisonCond,
|
2011-02-16 19:04:56 +00:00
|
|
|
'page_namespace' => $namespaces,
|
2011-02-16 03:11:20 +00:00
|
|
|
'rev_id = page_latest',
|
|
|
|
'rev_text_id = old_id'
|
|
|
|
);
|
2010-07-30 17:45:36 +00:00
|
|
|
|
2010-10-04 16:20:30 +00:00
|
|
|
$this->categoryCondition( $category, $tables, $conds );
|
2010-07-30 17:45:36 +00:00
|
|
|
$this->prefixCondition( $prefix, $conds );
|
|
|
|
$sort = array( 'ORDER BY' => 'page_namespace, page_title' );
|
|
|
|
|
|
|
|
return $dbr->select( $tables, $vars, $conds, __METHOD__ , $sort );
|
|
|
|
}
|
|
|
|
|
2010-10-04 16:20:30 +00:00
|
|
|
protected function categoryCondition( $category, &$tables, &$conds ) {
|
2012-01-01 08:54:58 +00:00
|
|
|
if ( strval( $category ) !== '' ) {
|
2010-07-30 17:45:36 +00:00
|
|
|
$category = Title::newFromText( $category )->getDbKey();
|
2009-08-14 17:28:25 +00:00
|
|
|
$tables[] = 'categorylinks';
|
|
|
|
$conds[] = 'page_id = cl_from';
|
2010-07-30 17:45:36 +00:00
|
|
|
$conds['cl_to'] = $category;
|
2009-08-14 17:28:25 +00:00
|
|
|
}
|
2010-07-30 17:45:36 +00:00
|
|
|
}
|
2009-04-27 08:52:10 +00:00
|
|
|
|
2010-07-30 17:45:36 +00:00
|
|
|
protected function prefixCondition( $prefix, &$conds ) {
|
2012-01-01 08:54:58 +00:00
|
|
|
if ( strval( $prefix ) === '' ) {
|
|
|
|
return;
|
2010-07-30 17:45:36 +00:00
|
|
|
}
|
2012-11-06 02:08:00 +00:00
|
|
|
|
2012-01-01 08:54:58 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2012-02-14 05:13:09 +00:00
|
|
|
$title = Title::newFromText( $prefix );
|
|
|
|
if ( !is_null( $title ) ) {
|
|
|
|
$prefix = $title->getDbKey();
|
|
|
|
}
|
2012-01-01 08:54:58 +00:00
|
|
|
$any = $dbr->anyString();
|
|
|
|
$conds[] = 'page_title ' . $dbr->buildLike( $prefix, $any );
|
2009-04-27 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
2012-02-17 19:49:36 +00:00
|
|
|
private function regexCond( $dbr, $column, $regex ) {
|
|
|
|
if ( $dbr instanceof DatabasePostgres ) {
|
|
|
|
$op = '~';
|
|
|
|
} else {
|
|
|
|
$op = 'REGEXP';
|
|
|
|
}
|
|
|
|
return "$column $op " . $dbr->addQuotes( $regex );
|
|
|
|
}
|
2009-04-27 09:02:48 +00:00
|
|
|
}
|