Extension talk:Replace Text

Jump to navigation Jump to search

About this board

Using ReplaceText with Translate extension needs marking pages again

Tuxxic (talkcontribs)


I am using Replace text for a few lines I have to replace in some of my namespaces.

But everytime I use it on the Translate namespaces, it works and replaces them, but I always have to mark pages for translation, which is very annoying for a wiki with hundreds of pages.

Is there any means to avoid this by any means ?

Best regards,

Kghbln (talkcontribs)

I can feel your pain. I think this is a question for the Translate extension which picks up on edits whether they are done by bots or humans.

Tuxxic (talkcontribs)

Thanks, I didn't know if I chose the right board. I contact them :)

Reply to "Using ReplaceText with Translate extension needs marking pages again"
Farvardyn (talkcontribs)

1) How is this changing bulk replace text? Only one page at a web request? so do I need to refresh wiki that it continues the job to change? Or once I click submit, it does the job with no worries about web request?

2) Pages will be done replacing in which order? By date of creation order?

3) If using command line how to tell the command to add an End Of Line at the end of new text? For example

$ replaceText.php "foo" "bar\n"

is something valid?

Jonathan3 (talkcontribs)

1 - When using the web interface it uses the job queue. I imagine the command line script does too. I always run runJobs.php afterwards.

Reply to "Needs a few clarification"
Spiros71 (talkcontribs)

I am trying to delete some templates with their content. I have gone as far as using something like:


Which only captures text in the template if there is one line break after the template name and another before the end of template. How can I edit this so that it captures any text and any number of lines until it reaches the first "}}" bit (non-greedy)?

Jonathan3 (talkcontribs)

Just get rid of \n in both places - try

Spiros71 (talkcontribs)

"No pages were found containing the string "\{\{WoodhouseENELnames(.*?)\}\}" or "{{WoodhouseENELnames(.*?)}}" I guess multiline is not supported by simply using ".*?"

So far the only workaround I found is using multiple expressions like:

Jonathan3 (talkcontribs)

It seems that you need to escape } but must not escape { in ReplaceText. Try it again :-)

Spiros71 (talkcontribs)

That did not work either:

No pages were found containing the string

Jonathan3 (talkcontribs)

I was sure I'd tried it, but clearly not. Sorry.

Reply to "Multiline replace"

can't replace HTML-like strings

7 (talkcontribs)

I'm trying to replace HTML-like tags spread across hundreds of pages in my wiki. I'm using regular expressions, e.g.


but keep getting Wikimedia\Rdbms\DBQueryError error suppoedly indicating a software bug. Is there a way around this?

My version is MW 1.30.1, PHP 5.5.9, MySQL 5.7.25 (with ReplaceText for MW 1.30 of course)

Ciencia Al Poder (talkcontribs)

Can you temporarily set $wgShowSQLErrors = true; in LocalSettings.php and repeat the action, and see what's the error message? (talkcontribs)

It was already set, nothing shows except what I already mentioned (error occured when querying DB, which might indicate a bug in software "Wikimedia\Rdbms\DBQueryError") ~~~~

FreedomFighterSparrow (talkcontribs)

Trying to reproduce this issue, the error that shows is this:

Function: ReplaceTextSearch::doSearchQuery
Error: 1139 Got error 'repetition-operator operand invalid' from regex

It looks like this is a limitation in MySQL's implementation - you cannot use the non-greedy wildcard, '*?'. It looks like MySQL 8 might have a better implementation of Regex, but I cannot test at the moment. (talkcontribs)

So...is there a way around this limitation? ~~~~

FreedomFighterSparrow (talkcontribs)

That's actually a regex question, more than a mediawiki question... If you don't have any other tags in between those, you can simply do this: <repeat>([^<]*)</repeat>

This obviously won't work if there's any '<' in the text between the "repeat" tags. In that case, my regex knowledge is exhausted, and I would suggest you ask that question on StackOverflow or the like. (talkcontribs)

ok, thanks!

Reply to "can't replace HTML-like strings"
Jonathan3 (talkcontribs)

I tried this with a regular expression replacement. It correctly showed the pages to be changed, but then just froze (I needed to hit control-C). Running runJobs.php didn't have any effect. No pages were changed.

It may have been a problem with my regex. I ended up using the web interface and just using normal text replacement. So unfortunately I can't assist much further (though happy to try things out that won't break my wiki). It may be worth looking into how replaceAll.php operates in this sort of case though. Thanks. Jonathan3 (talk) 17:24, 23 February 2020 (UTC)

Jonathan3 (talkcontribs)

Here's what I typed. Maybe the mistake will be obvious!

php replaceAll.php "{{aaa(.*)=(.*)bbb=(.*)ccc=(.*)ddd=(.*)" "{{eee$1fff=$2ggg=$3hhh=$4iii=$5" --regex --debug --summary "jjj" --user "kkk"

I also tried it without "--debug".

Ciencia Al Poder (talkcontribs)

Using regexp notation in command line parameters is tricky, because some characters like { and $ have a special meaning for the shell.

By {{ you probably want to mean template syntax. However, in regexp, the { character is used to define how many times the previous character/group/expression must be present, and you need to escape it. You probably need to replace it by \\{\\{, and the two \ are to tell the shell to interpret it as a literal \ and not a escape character for the shell itself. This should be needed only in the search string and not in the replacement string.

The $1, $2 etc in the replacement are also problematic because $ is used by the shell to indicate it's a variable name. Since it's not defined, it will replace it with blanks! You should put a single \ before all of them: \$1, \$2, etc

Jonathan3 (talkcontribs)

Thank you for the detailed response.

I hadn't escaped the { or } because the extension page states: The special characters that one can use in the search string are "( ) . * + ? [ ] |"

The other stuff is new to me - it's lucky the script made no changes were made or it would have caused me more bother!

Jonathan3 (talkcontribs)

P.S. Despite this being my fault, it would have been nice if the script had given a error message (even an unhelpful one) rather than frozen :-)

Reply to "replaceAll.php"

ReplaceText just re-loads original replaceText page when I click continue

Tenbergen (talkcontribs)

On one of several wikis I run RT 1.4.1 is misbehaving: if I enter some text I want to replace, it just re-loads the initial replace text page. When I enable debugging there are no entries in the log that seem related. PHP logs are not showing anything either. MW is 1.32.1 and 7.2.11 like the others where it works so probably unrelated. Does anyone else have a problem like this?

Tenbergen (talkcontribs)

This ended up being because my domain/hosting was set up to redirect pages to www.<mydomain>; when I changed it to not redirect, it worked fine. (talkcontribs)

@Tenbergen Would you mind going into more detail about your solution? Do you happen to use Plesk Server for Domain Management? I started running into this problem recently myself after some issues with my Hosting Domain occurred. I'm using MediaWiki v1.41.

Tenbergen (talkcontribs)

Yes, that wasn't very clear, sorry, and now I barely remember the details, but here it is. I use shared hosting, and the provider uses a web page to let me manage how my domain names lead to my wiki. By default, their setup turns e.g. https://mywiki.ca into https://www.mywiki.ca, ie it adds the www. I have is set up to do the opposite, turn any httpss://www.mywiki.ca into https://mywiki.ca. It appears that something got messed up behind the scenes when I made an unrelated change - the domain web page tool is not totally reliable, I have run into problems when I am impatient and open things in multiple tabs. So, something got messed up behind the scenes, and changed the ridirect setting. The rest of the wiki worked just fine that way, but replacetext didn't. Once I changed it back to how it was set up originally, and how localsettings expects it to be set up, it worked again.

Depending on how you have things set up, I could imagine a .htaccess file having a similar effect, but as I said, that'd me imagining :-) Hope that helps! Tenbergen (talk) 20:24, 15 December 2019 (UTC)

Naupe (talkcontribs)
Tenbergen (talkcontribs)

@Naupe, you are right it sounds similar. I am kind of glad I was able to resolve the problem without editing the code of the extension, largely because I download updates for all extensions every few months, and editing one of them would mean always having to also edit it again. I am glad you found a solution!

Reply to "ReplaceText just re-loads original replaceText page when I click continue"

"Extension:ReplaceText just reloads" issue (+ solution!)

Naupe (talkcontribs)

I administrate a MediaWiki (version 1.31.1) on a Third Party Plesk Server host.

The Replace Text Extension I have installed (version 1.4.1) used to work, and it stopped working after some Domain issues. I had to reset my Plesk Server settings as best from memory as I could, and likely what I think occurred were modified PHP/Apache settings.

The Issue: When I went to the Special:ReplaceText page on my Wiki, filled it out and clicked the Continue button ... the page just reloaded. I was no longer redirected to a page that showed all the pages that would be replaced like I had been before. And in fact, no text replacing was done at all!

The Solution: I got ahold of User:Yaron Koren, one of the authors of this Extension, and he was able to assist me and resolved the issue! Here is the solution for those who may be having the same problem as I had:

  1. Open the SpecialReplaceText.php file in your wiki's extension folder in a Text Editor.
  2. Search for getFullURL() (was on Line 411 for me) and change it to getLocalURL().
  3. On the next line, change 'post' to 'get'.
  4. Search for post (this second instance of post was on Line 576 for me) and change it to get.
  5. On the next line, change getFullUrl() to getLocalUrl().
  6. Save the file.

And viola! My Special:ReplaceText page works like it did before the Domain Issues I had before! No PHP/Apache Settings to update/modify!

I really believe Extension:Replace Text#Known issues ought to include this information. I would add it myself, but I don't really feel like I've done a good job explaining my problem (and I really don't know what triggered it; only a guess on Yaron's part).

Ciencia Al Poder (talkcontribs)

This is probably a problem with your domain setup. You may have a different $wgServer than your actual server, and there's a redirect under the hood, causing POST data being lost.

Typical failures: Your $wgServer is set to http:// but your server is set to automatically redirect all traffic to https://. A similar one is your $wgServer being http://example.com and your webserver is automatically redirecting all traffic to http://www.example.com

You can see this if you open the developer tools (hit F12) and open the network tab. If you make this tab persistent (to not reload on every page load), hitting the submit button will give you a GET or POST request that's replied with a HTTP 301 or HTTP 302 status code, causing the server to reissue the same request again on the new location

Reply to ""Extension:ReplaceText just reloads" issue (+ solution!)"

'search only' feature/ability as separate user-right

MvGulik (talkcontribs)

(Pulled from 2008(2018) archive. (no reply))

I (still) think that a Replace_Text search-only feature, as separate user-right, could be useful.

Especially due to the fact that the normal MW search feature is more targeted in its functionality at wiki visitors, and not at general editors. (that's at least my POV on MW's normal search feature)

That way the search-only feature could be given to active editors to help them in finding potential additional edit targets. (leaving the real global changes still in the hands of higher level users)

Yaron Koren (talkcontribs)

Sorry for not responding to this for 11 years... a precise wikitext search feature could indeed be useful, but it seems outside of the "purview" of this extension. It seems better to put that functionality into a separate extension - or even to to make it an option in MediaWiki's standard Special:Search, although that seems doubtful.

MvGulik (talkcontribs)

>Sorry for not responding to this for 11 years

Oops. That would be just one year, as 2008 should have been 2018. Sorry about that.

>It seems better to put that functionality into a separate extension.

That would of course work too.

Ciencia Al Poder (talkcontribs)
Yaron Koren (talkcontribs)

Oh, I didn't know that. That's great!

Reply to "'search only' feature/ability as separate user-right"

I got "Wikimedia\Rdbms\DBQueryError" when I use "?" in regex.

Libattery (talkcontribs)

I got "Wikimedia\Rdbms\DBQueryError" when I use "?" in regex.

When I use regex, like "(<math>.*?<\/math>)" I got Error. Without "?" like "(<math>.*<\/math>) I got ok.

How can I use the lazy matching in regex without "?" ?.

I found no way to around because in Latex equation nearly every characters are used.

Please help me.

Reply to "I got "Wikimedia\Rdbms\DBQueryError" when I use "?" in regex."

Replacements file format / Regex question

Amousey (talkcontribs)

Excellent feature, and a great time saver - thank you.

--replacements option More documentation and examples would be helpful on the replacements file.

The replacements file format is described as:

The format of the replacements file is tab separated with three fields.

Any line that does not have a tab is ignored and can be considered a comment.

Fields are:

1. String to search for.
2. String to replace found text with.
3. (optional) The presence of this field indicates that the previous two are considered a regular expression.

Example: This is a comment TARGET REPL regex(p*) Count the Ps; \\1 true

Questions - Can any database including MariaDB use the regex here, including those described as unable to use regex from the interactive dialog option (MS SQL/SQLServer or SQLite)? - If not using a regular expression, do any special characters need to be avoided / escaped eg pipe |, =, {} and " ' quote marks, etc - How to active ReplaceText from the user interface using a pre-configured set of options, including a replacements file, eg for a non-technical user

Future suggestion: - a way to mark up pages not to have text replaced or ignoring pages with the DISAMBIG tag, which would allow it to be used for autocorrect - A bot using a replacements file. Is there example choose & instructions anywhere?

Reply to "Replacements file format / Regex question"