Extension talk:Replace Text/Archive 2018

Is there a way to search with back slashes (/) ?
For example, how would I search for the string "c:\" ? Kmacdowe (talk) 20:19, 29 January 2015 (UTC)


 * You actually have a forward slash in your section header. Anyway, I think you can do it by just escaping it with another backslash, like "\\". Yaron Koren (talk) 00:01, 30 January 2015 (UTC)

How to Use $1 replacer following by numbers?

 * What if I want to replace (\[\[|link=)2L\]\] to $12L]], with regex?
 * The extension assume $12 is the replacer, but I just want $1 to be the replacer. Boxsnake (talk) 04:01, 20 February 2015 (UTC)
 * Do not mind, I found the solution on my own. Leave this thread in case others with the same problem can benefit from this
 * Replace

(\[\[|link=)2L\]\]
 * With

${1}2L]]

Is there a way to replace with \n (newline)
Is there a way to use the ReplaceText extension to replace with the \n (newline) character? I get the literal '\n' as output every time I try to replace with \n. Yes, I have 'Use regular expressions' checked. Cmjohannes (talk) 03:20, 3 September 2015 (UTC)


 * Can't you just have a newline in the replacement string? That's why the text inputs are textareas instead of single-line inputs. Yaron Koren (talk) 12:53, 3 September 2015 (UTC)


 * That solves it. So what regex expressions will be evaluated in the replacement string? For example, why does $1 get evaluated as a regex "variable," but not evaluated as the literal '$1' string? Cmjohannes (talk) 15:38, 4 September 2015 (UTC)


 * I don't know - everything other than "\n", hopefully. I'm surprised that "\n" doesn't work when you check the "regex" box, but thankfully there's a backup for that one. Yaron Koren (talk) 15:59, 4 September 2015 (UTC)

Is there a way to find \n or .newline.?
I would like to find \]\]\n. The ReplaceText extension can find \]\] or the ReplaceText extension can find \n, but the only way I can find \]\]\n is to search \]\] followed by pressing enter in the 'Replace Text:' box. 'Use regular expressions' is checked, so why is white space being searched for? Also, \n\n cannot be found, when I know it exists. Is there some kind of hidden character at the end of line breaks on wiki pages? Cmjohannes (talk) 05:15, 5 September 2015 (UTC)


 * This seems like basically the same question as before - but yes, it could be that, instead of just "\n", it's "\r\n" or some such. Yaron Koren (talk) 13:12, 8 September 2015 (UTC)

Parameter $wgBotJobUserID
I replaced line 56 in SpecialReplaceText.php with these lines:

global $wgBotJobUserID; if (isset($wgBotJobUserID)) $replacement_params['user_id'] = $wgBotJobUserID; else $replacement_params['user_id'] = $this->getUser->getId;

This way you can define a $wgBotJobUserID (number, not name) in LocalSettings.php to hide all changes of the job.

--VolkoV (talk) 12:46, 8 October 2015 (UTC)


 * The idea makes sense, although - I assume you came up with the name "$wgBotJobUserID"? If it's specific to Replace Text, it should start with "$wgReplaceText" - "$wgReplaceTextUserID" might work. Although better yet, I would think, would be to have users set the username, not the ID, and then the code looks up the ID. Yaron Koren (talk) 14:19, 8 October 2015 (UTC)


 * Thanks! This worked great.  I used Extension:LookupUser to find the user ID of the bot I wanted to use.  Just wanted to specify that the line you replaced was: $replacement_params['user_id'] = $this->getUser->getId; (in case line 56 changes) --Potrod (talk) 03:38, 28 May 2016 (UTC)


 * VolkoV - thanks for the idea, and Potrod - thanks for the reminder. I just checked in some code to handle a new global variable, $wgReplaceTextUser - it takes in a username, not an ID. If you get the latest Replace Text code, it should work. Yaron Koren (talk) 19:40, 31 May 2016 (UTC)

Not here
Hi User:Yaron Koren, any particular reason why RT isn't available on this wiki? Thanks. --Elitre (WMF) (talk) 12:39, 22 February 2016 (UTC)


 * I don't know - I have no say in what gets installed on mediawiki.org. If I did, the site would probably look different. :) Yaron Koren (talk) 14:21, 22 February 2016 (UTC)

Is there any way to move pages from one NS to another?
Problem is: I need to move some bunch of pages from Namespace1:Somepagename to Namespace2:Somepagename

When I set replacement string to Namespace1 it says that no result was found, even if both NS was chosen (with or without regexp tick)

Is there any way to do such job using that extension? (btw, mediawiki 1.26.2, private  if that matters) Ibutakov.smartec (talk) 12:19, 18 March 2016 (UTC)


 * Ah, I hadn't realized (or forgot) that RT couldn't be used to modify the namespace. But that makes sense, because the "full name" of a page is not stored anywhere in the database. It would take a good amount of work to get RT to support this, unfortunately. Assuming you have a lot of pages like this, probably the easiest solution is to create a bot to do the replacement, if you know how to program. Yaron Koren (talk) 14:08, 18 March 2016 (UTC)

Disable Watchlist Notifications
Is it possible to block ReplaceText from sending watchlist notifications. In order for users to continue to see major updates they would have to go into each page when they get the emails after we run this script. In our case they may have to go into hundreds of pages. Jrsovereign (talk) 19:30, 4 April 2016 (UTC)


 * This is a tricky one - it appears to be possible to cancel the emailing for MW 1.23 and higher, thanks to a new hook in the code - but users who aren't watching hundreds or thousands of these pages may well want to be notified of Replace Text changes. If someone is watching that many pages, and gets emailed on watchlist changes, won't they be used to getting lots of emails? And if they see hundreds of new emails in a short amount of time, and they check and see that the first few are Replace Text-related, won't they be able to assume that the rest are as well? Yaron Koren (talk) 21:13, 4 April 2016 (UTC)


 * Yes, but regardless they still have to visit all the pages once again to get any additional notifications. Jrsovereign (talk) 21:49, 4 April 2016 (UTC)


 * Oh... now I get what you said; I didn't understand it before. Are you saying that, unless they view a page, users will stop getting emailed about changes to that page? I had no idea about that. Are you sure that that's the case? Do you know if there's any documentation about this? Yaron Koren (talk) 22:30, 4 April 2016 (UTC)


 * Yes here: Help:Watchlist: "After receiving an email notification for a page, you have to visit the page while logged in if you want to be notified of further changes to the same page." Jrsovereign (talk) 02:38, 5 April 2016 (UTC)

Regex flag questions
When I was reviewing this extension for the Miraheze wiki farm, I came up with a couple of questions: Thanks for you work! --BrentLaabs (talk) 00:28, 7 August 2016 (UTC)
 * On this line, is there are reason why you aren't using the  flag, or is that a bug?
 * On a very similar looking flag, : why isn't the Unicode flag enabled everywhere?  Is there some some reason why this can't be enabled?  I know that nothing we can do is going to make Mysql REGEXP aware of Unicode, but my gut feeling is that this will only produce false positives for Mediawiki to potentially make changes.  And Postgres   is Unicode aware, so it's possible you're rejecting matches there.


 * Sorry - I wrote that code a while ago; I no longer remember any of the regex stuff. (And I never really understood SQL regex stuff all that well.) If there are bugs in the current handling, though, that should be fixed. If you don't mind, could you give an example of strings for which the current PHP and/or DB handling fails? Yaron Koren (talk) 01:21, 7 August 2016 (UTC)

No problem! ~/c/mediawiki (REL1_27)&gt; php -r '$x = "¿é?\n"; $y = preg_replace("/alpha:/Uu", "a", $x); echo $y;' ¿a? ~/c/mediawiki (REL1_27)&gt; php -r '$x = "¿é?\n"; $y = preg_replace("/alpha:/U", "a", $x); echo $y;' a�a�?

mysql> select '¿' REGEXP 'alpha:'; +---+ +---+ +---+ 1 row in set (0.02 sec) This error is unfixable -- I know because I just ran into it at my day job 2 weeks ago. People have been complaining about lack of Unicode support in MySQL since 2004...  Anyway totally not an issue in Postgres.
 * '¿' REGEXP 'alpha:' |
 * 1 |

The solution is just to add the '/u' flag to the end, and at least PHP will get it correct when it's editing the page. Or more correct anyway -- there are mines buried everywhere when dealing with Unicode. Because the database only pulls candidate pages, it's OK for it to be a little bit wrong as long as the actual page edit in Mediawiki does the right thing.

I can submit a code patch to you if you want -- but I don't want to learn gerrit. Is emailing a git patch OK, or is there a Git(hub|lab) repo lurking around here? --BrentLaabs (talk) 02:20, 7 August 2016 (UTC)


 * Ah, the '¿' character - I'm pretty sure I never tested that one! In general, I don't know if I did much, or any, testing on non-Unicode characters. Yes, feel free to email me a patch - or just paste it here, if we're just talking about a few lines. Yaron Koren (talk) 03:11, 7 August 2016 (UTC)
 * I just want to make sure you got my email. I had an email with a patch sent to me get put into my spam folder on Gmail, so I was wondering if the same happened to you. --BrentLaabs (talk) 21:28, 10 August 2016 (UTC)
 * Yes, I got the email - sorry, I haven't gotten around yet to merging in your patch, but I hope to do it soon. Yaron Koren (talk) 02:46, 11 August 2016 (UTC)

Brilliant Extension!!!
Saved me countless hours of work.


 * Thank you! Yaron Koren (talk) 15:42, 9 September 2016 (UTC)

how to add text if it doesn't exist in article?
i'd like to add a category to posts that don't have it or a template. so probably i need a regex to jump to end of article and checking if such text exists. how can i do that?

Working on MW 1.27?
Sometimes, when I replace some text, it returns a error page.Does anybody know if it is working with MW 1.27.1? Thanks!


 * What's the error message? Yaron Koren (talk) 15:41, 9 September 2016 (UTC)

Ahhh, page type error again in MW 1.27.1!
This is an old bug which appeared in earlier version of MW before. When you replace text in Mediawiki:xxx.js or Mediawiki:xxx.css page. This extension will change the page type from js/css to wikitext, and resulting in js/css failure. Can someone fix this error? --Zoglun (talk) 00:19, 27 October 2016 (UTC)


 * Oh, I never thought about the possibility of people using this to replace text in non-wikitext pages. Yaron Koren (talk) 01:15, 27 October 2016 (UTC)