Go to the documentation of this file.
33 parent::__construct(
'ReplaceText',
'replacetext' );
49 if ( !$this->
getUser()->isAllowed(
'replacetext' ) ) {
56 $errorMsg =
"Error: text replacements cannot be run if \$wgCompressRevisions is set to true.";
57 $this->
getOutput()->addWikiText(
"<div class=\"errorbox\">$errorMsg</div>" );
61 $errorMsg =
"Error: text replacements cannot be run if \$wgExternalStores is non-empty.";
62 $this->
getOutput()->addWikiText(
"<div class=\"errorbox\">$errorMsg</div>" );
68 if ( !is_null(
$out->getResourceLoader()->getModule(
'mediawiki.special' ) ) ) {
69 $out->addModuleStyles(
'mediawiki.special' );
80 foreach ( $all_namespaces
as $ns =>
$name ) {
81 if ( $this->
getRequest()->getCheck(
'ns' . $ns ) ) {
95 $this->target =
$request->getText(
'target' );
96 $this->replacement =
$request->getText(
'replacement' );
97 $this->use_regex =
$request->getBool(
'use_regex' );
98 $this->category =
$request->getText(
'category' );
99 $this->prefix =
$request->getText(
'prefix' );
100 $this->edit_pages =
$request->getBool(
'edit_pages' );
101 $this->move_pages =
$request->getBool(
'move_pages' );
102 $this->doAnnounce =
$request->getBool(
'doAnnounce' );
105 if (
$request->getCheck(
'continue' ) && $this->target ===
'' ) {
106 $this->
showForm(
'replacetext_givetarget' );
110 if (
$request->getCheck(
'replace' ) ) {
114 if ( !
$user->matchEditToken(
$request->getVal(
'token' ) ) ) {
115 $out->addWikiMsg(
'sessionfailure' );
124 'replacetext_success',
125 "<code><nowiki>{$this->target}</nowiki></code>",
126 "<code><nowiki>{$this->replacement}</nowiki></code>",
134 $this->
msg(
'replacetext_return' )->escaped()
140 if (
$request->getCheck(
'target' ) ) {
143 if ( !
$user->matchEditToken(
$request->getVal(
'token' ) ) ) {
144 $out->addWikiMsg(
'sessionfailure' );
151 if (
count( $this->selected_namespaces ) == 0 ) {
152 $this->
showForm(
'replacetext_nonamespace' );
155 if ( ! $this->edit_pages && ! $this->move_pages ) {
156 $this->
showForm(
'replacetext_editormove' );
161 $titles_for_edit = $titles_for_move = $unmoveable_titles = [];
162 if ( $this->edit_pages ) {
165 if ( $this->move_pages ) {
171 if (
count( $titles_for_edit ) == 0 &&
count( $titles_for_move ) == 0 ) {
172 $bad_cat_name =
false;
174 if ( !empty( $this->category ) ) {
176 if ( !$category_title->exists() ) {
177 $bad_cat_name =
true;
181 if ( $bad_cat_name ) {
183 htmlspecialchars( ucfirst( $this->category ) ) );
185 $this->
msg(
'replacetext_nosuchcategory' )->rawParams(
$link )->escaped()
188 if ( $this->edit_pages ) {
190 'replacetext_noreplacement',
"<code><nowiki>{$this->target}</nowiki></code>"
194 if ( $this->move_pages ) {
195 $out->addWikiMsg(
'replacetext_nomove',
"<code><nowiki>{$this->target}</nowiki></code>" );
203 $this->
msg(
'replacetext_return' )->escaped() )
208 if ( ! is_null( $warning_msg ) ) {
209 $out->addWikiText(
"<div class=\"errorbox\">$warning_msg</div><br clear=\"both\" />" );
212 $this->
pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles );
229 $replacement_params = [];
236 $replacement_params[
'user_id'] =
$user->getId();
240 $replacement_params[
'edit_summary'] = $this->
msg(
241 'replacetext_editsummary',
242 $this->target, $this->replacement
243 )->inContentLanguage()->plain();
244 $replacement_params[
'create_redirect'] =
false;
245 $replacement_params[
'watch_page'] =
false;
250 if ( $key ==
'create-redirect' &&
$value ==
'1' ) {
251 $replacement_params[
'create_redirect'] =
true;
252 } elseif ( $key ==
'watch-pages' &&
$value ==
'1' ) {
253 $replacement_params[
'watch_page'] =
true;
259 if (
$value ==
'1' && $key !==
'replace' && $key !==
'use_regex' ) {
260 if ( strpos( $key,
'move-' ) !==
false ) {
262 $replacement_params[
'move_page'] =
true;
282 $titles_for_edit = [];
286 $this->selected_namespaces,
292 foreach (
$res as $row ) {
301 return $titles_for_edit;
313 $titles_for_move = [];
314 $unmoveable_titles = [];
318 $this->selected_namespaces,
324 foreach (
$res as $row ) {
330 $cur_page_name = str_replace(
'_',
' ', $row->page_title );
332 if ( $this->use_regex ) {
334 preg_replace(
"/" . $this->target .
"/Uu", $this->replacement, $cur_page_name );
337 str_replace( $this->target, $this->replacement, $cur_page_name );
341 $err =
$title->isValidMoveOperation( $new_title );
343 if (
$title->userCan(
'move' ) && !is_array( $err ) ) {
344 $titles_for_move[] =
$title;
346 $unmoveable_titles[] =
$title;
350 return [ $titles_for_move, $unmoveable_titles ];
363 if ( $this->replacement ===
'' ) {
364 return $this->
msg(
'replacetext_blankwarning' )->text();
365 } elseif ( $this->use_regex ) {
370 } elseif (
count( $titles_for_edit ) > 0 ) {
373 $this->selected_namespaces,
378 $count =
$res->numRows();
380 return $this->
msg(
'replacetext_warning' )->numParams( $count )
381 ->params(
"<code><nowiki>{$this->replacement}</nowiki></code>" )->text();
383 } elseif (
count( $titles_for_move ) > 0 ) {
386 $this->selected_namespaces,
388 $this->prefix, $this->use_regex
390 $count =
$res->numRows();
392 return $this->
msg(
'replacetext_warning' )->numParams( $count )
393 ->params( $this->replacement )->text();
410 'id' =>
'powersearch',
419 if ( is_null( $warning_msg ) ) {
420 $out->addWikiMsg(
'replacetext_docu' );
423 "<div class=\"errorbox\">\n$1\n</div><br clear=\"both\" />",
428 $out->addHTML(
'<table><tr><td style="vertical-align: top;">' );
429 $out->addWikiMsg(
'replacetext_originaltext' );
430 $out->addHTML(
'</td><td>' );
435 Xml::textarea(
'target', $this->target, 100, 5, [
'style' =>
'width: auto;' ] )
437 $out->addHTML(
'</td></tr><tr><td style="vertical-align: top;">' );
438 $out->addWikiMsg(
'replacetext_replacementtext' );
439 $out->addHTML(
'</td><td>' );
441 Xml::textarea(
'replacement', $this->replacement, 100, 5, [
'style' =>
'width: auto;' ] )
443 $out->addHTML(
'</td></tr></table>' );
448 if (
$dbr->getType() !=
'sqlite' ) {
451 $this->
msg(
'replacetext_useregex' )->
text(),
452 'use_regex',
'use_regex'
456 [
'style' =>
'font-style: italic' ],
457 $this->
msg(
'replacetext_regexdocu' )->
text()
466 "<div class=\"mw-search-formheader\"></div>\n" .
467 "<fieldset id=\"mw-searchoptions\">\n" .
468 Xml::tags(
'h4',
null, $this->
msg(
'powersearch-ns' )->parse() )
474 if ( $this->
msg(
'powersearch-togglelabel' )->isDisabled() ) {
480 [
'id' =>
'mw-search-togglebox' ]
485 Xml::element(
'div', [
'class' =>
'divider' ],
'',
false ) .
486 "$tables\n</fieldset>"
489 $category_search_label = $this->
msg(
'replacetext_categorysearch' )->escaped();
490 $prefix_search_label = $this->
msg(
'replacetext_prefixsearch' )->escaped();
492 $rcPageName = $rcPage->getPrefixedText();
494 "<fieldset id=\"mw-searchoptions\">\n" .
495 Xml::tags(
'h4',
null, $this->
msg(
'replacetext_optionalfilters' )->parse() ) .
496 Xml::element(
'div', [
'class' =>
'divider' ],
'',
false ) .
497 "<p>$category_search_label\n" .
498 Xml::input(
'category', 20, $this->category, [
'type' =>
'text' ] ) .
'</p>' .
499 "<p>$prefix_search_label\n" .
500 Xml::input(
'prefix', 20, $this->prefix, [
'type' =>
'text' ] ) .
'</p>' .
504 $this->
msg(
'replacetext_editpages' )->
text(),
'edit_pages',
'edit_pages',
true
507 $this->
msg(
'replacetext_movepages' )->
text(),
'move_pages',
'move_pages'
510 $this->
msg(
'replacetext_announce', $rcPageName )->
text(),
'doAnnounce',
'doAnnounce',
true
517 $out->addModules(
'mediawiki.special.search' );
535 if ( !array_key_exists( $subj,
$rows ) ) {
540 $name = $this->
msg(
'blanknamespace' )->text();
552 'float: right; margin: 0 0 0em 1em' :
'float: left; margin: 0 1em 0em 0';
554 for ( $i = 0; $i < $numRows; $i += $rowsPerTable ) {
556 for ( $j = $i; $j < $i + $rowsPerTable && $j < $numRows; $j++ ) {
569 function pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles ) {
575 'id' =>
'choose_pages',
592 foreach ( $this->selected_namespaces
as $ns ) {
596 $out->addModules(
"ext.ReplaceText" );
597 $out->addModuleStyles(
"ext.ReplaceTextStyles" );
599 $out->addModuleStyles(
"mediawiki.special.search.styles" );
601 if (
count( $titles_for_edit ) > 0 ) {
603 'replacetext_choosepagesforedit',
604 "<code><nowiki>{$this->target}</nowiki></code>",
605 "<code><nowiki>{$this->replacement}</nowiki></code>",
609 foreach ( $titles_for_edit
as $title_and_context ) {
617 " - <small>$context</small><br />\n"
620 $out->addHTML(
'<br />' );
623 if (
count( $titles_for_move ) > 0 ) {
625 'replacetext_choosepagesformove',
626 $this->target, $this->replacement,
$wgLang->formatNum(
count( $titles_for_move ) )
628 foreach ( $titles_for_move
as $title ) {
634 $out->addHTML(
'<br />' );
635 $out->addWikiMsg(
'replacetext_formovedpages' );
637 $rcPageName = $rcPage->getPrefixedText();
640 $this->
msg(
'replacetext_savemovedpages' )->
text(),
641 'create-redirect',
'create-redirect',
true ) .
"<br />\n" .
643 $this->
msg(
'replacetext_watchmovedpages' )->
text(),
644 'watch-pages',
'watch-pages',
false ) .
'<br />'
646 $out->addHTML(
'<br />' );
656 if (
count( $titles_for_edit ) +
count( $titles_for_move ) > 5 ) {
659 'value' => $this->
msg(
'replacetext_invertselections' )->text(),
661 'id' =>
'replacetext-invert',
662 'class' =>
'mw-replacetext-invert'
670 $out->addHTML(
'</form>' );
672 if (
count( $unmoveable_titles ) > 0 ) {
673 $out->addWikiMsg(
'replacetext_cannotmove',
$wgLang->formatNum(
count( $unmoveable_titles ) ) );
675 foreach ( $unmoveable_titles
as $title ) {
679 $out->addHTML( $text );
695 $cw = $this->
getUser()->getOption(
'contextchars', 40 );
699 preg_match_all(
"/$target/Uu", $text,
$matches, PREG_OFFSET_CAPTURE );
701 $targetq = preg_quote(
$target,
'/' );
702 preg_match_all(
"/$targetq/", $text,
$matches, PREG_OFFSET_CAPTURE );
712 for ( $i = 0; $i <
count( $poss ); $i++ ) {
718 while ( isset( $poss[$i + 1] ) ) {
719 if ( $poss[$i + 1] < $index + $len + $cw * 2 ) {
720 $len += $poss[$i + 1] - $poss[$i];
727 $cuts[] = [ $index, $len ];
731 foreach ( $cuts
as $_ ) {
732 list( $index, $len, ) = $_;
734 $wgLang->truncate( substr( $text, 0, $index ), - $cw,
'...',
false )
738 $targetStr =
"/$target/Uu";
741 $targetStr =
"/$targetq/i";
743 $context .= preg_replace( $targetStr,
'<span class="searchmatch">\0</span>', $snippet );
746 $wgLang->truncate( substr( $text, $index + $len ), $cw,
'...',
false )
753 $msg = htmlspecialchars( $msg );
754 $msg = preg_replace(
'/^ /m',
'  ', $msg );
755 $msg = preg_replace(
'/ $/m',
'  ', $msg );
756 $msg = preg_replace(
'/ /',
'  ', $msg );
757 # $msg = str_replace( "\n", '<br />', $msg );
765 $vars = [
'page_title',
'page_namespace' ];
767 $str = str_replace(
' ',
'_', $str );
771 $any =
$dbr->anyString();
772 $comparisonCond =
'page_title ' .
$dbr->buildLike( $any, $str, $any );
781 $sort = [
'ORDER BY' =>
'page_namespace, page_title' ];
getPageTitle( $subpage=false)
Get a self-referential title object.
doSpecialReplaceText()
Do the actual display and logic of Special:ReplaceText.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
msg( $key)
Wrapper around wfMessage that sets the current context.
extractContext( $text, $target, $use_regex=false)
Extract context and highlights search text.
processing should stop and the error should be shown to the user * false
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
$wgExternalStores
External stores allow including content from non database sources following URL links.
static tags( $element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
getOutput()
Get the OutputPage being used for this instance.
static prefixCondition( $prefix, &$conds)
pageListForm( $titles_for_edit, $titles_for_move, $unmoveable_titles)
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
static searchableNamespaces()
Make a list of searchable namespaces and their canonical names.
namespace and then decline to actually register it & $namespaces
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Allows to change the fields on the form that will be generated $name
Show an error when a user tries to do something they do not have the necessary permissions for.
getLanguage()
Shortcut to get user's language.
static regexCond( $dbr, $column, $regex)
static openElement( $element, $attribs=null)
This opens an XML element.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
showForm( $warning_msg=null)
static categoryCondition( $category, &$tables, &$conds)
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
static link(Title $title, $text=null)
Shim for compatibility.
namespace and then decline to actually register it file or subcat img or subcat $title
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Background job to replace text in a given page.
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
when a variable name is used in a it is silently declared as a new masking the global
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
$wgCompressRevisions
We can also compress text stored in the 'text' table.
getTitlesForMoveAndUnmoveableTitles()
Returns two lists: the set of titles that would be moved/renamed by the current text replacement,...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
static hidden( $name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Parent class for all special pages.
createJobsForTextReplacements()
Returns the set of MediaWiki jobs that will do all the actual replacements.
getRequest()
Get the WebRequest being used for this instance.
static closeElement( $element)
Shortcut to close an XML element.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
static doSearchQuery( $search, $namespaces, $category, $prefix, $use_regex=false)
static singleton( $wiki=false)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
usually copyright or history_copyright This message must be in HTML not wikitext & $link
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
getMatchingTitles( $str, $namespaces, $category, $prefix, $use_regex=false)
getAnyWarningMessageBeforeReplace( $titles_for_edit, $titles_for_move)
Get the warning message if the replacement string is either blank or found elsewhere on the wiki (sin...
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
getGroupName()
@inheritDoc
static getSubject( $index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA,...
convertWhiteSpaceToHTML( $msg)
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
namespaceTables( $namespaces, $rowsPerTable=3)
Copied almost exactly from MediaWiki's SpecialSearch class, i.e.
getTitlesForEditingWithContext()
Returns the set of Titles whose contents would be modified by this replacement, along with the "searc...
static submitButton( $value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
static checkLabel( $label, $name, $id, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox with a label.
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out