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)


 * I just looked into this, and it's odd that you're seeing this problem - in the Replace Text code, there's a check to make sure that it's only doing replacements on pages of type "wikitext" - if the page is of another type, it doesn't run the replacement at all. That check has apparently been in place since version 0.9.6 in 2013... what version of Replace Text are you using? Yaron Koren (talk) 12:23, 31 October 2016 (UTC)

Changing Pagename with command-line
Hi there,

how can I search only in pagenames, like in the gui version in the special site. I played a little bit with the replaceAll.php, but didn`t find a solution. I cant use the Gui version, because of too much Pagenames (ca. 6000 pages, php timeout).

don`t find the Sites I need. And If possible, without forwarding


 * It doesn't look like it's possible, unfortunately - it would require a new parameter for replaceAll.php. Yaron Koren (talk) 12:26, 31 October 2016 (UTC)

I'm not getting anything MW 1.27
I have a template with query in it and when I run the replace text against the template namespace nothing returns. In the example below I want to replace servername.


 * What did you enter for the search and replacement strings? Yaron Koren (talk) 15:07, 1 November 2016 (UTC)

batch replacing using inputfiles corresponding to pages
Im trying to replace multilined text on each Page with multilined text. But my bash knowledge is very limited. I already completed the algorithm in PHP. I tested it successfully on one page. Of course i can sort of create a shell script with PHP but that does not seem to work, i blame my lack of bash knowledge as mentioned. Is it possible to cut out the bash part? Since this is PHP anyways?

PHP code to clarify: $search = $element."

";

$replace = file_get_contents($filespath.$element); $selection = strpos($replace, ""); $selection += 8;

$replace = substr($replace, 0, $selection);

$cmd = '/usr/bin/php '.$scriptpath.'replaceAll.php "'.$search.'" "'.$replace.'" --yes';

I even added absolute path's everywhere

[SOLVED] Replacement won't take place :(
I'm using version 0.10.0 of the extension with mediawiki 1.23.6 and php 5.3.17 and mysql 5.5.47 I've tried to get a newer version of the extension, but I'm not able to install GIT just to get the extension updated and downloading the tarfile got me the version cited on the special:version-page. When I try to replace any kind of text, it gets found ok - the pages are listed allright, but when I click on the "replace"-button, no replacement happens. It doesn't matter whether there are a single hit to replace or nearly a hundred. I've entred the $wgRunJobsAsync = false; in LocalSettings.php and I also cleared the cache.

I'm now looking for a hint where to look for clues of what might be wrong. --Katwol (talk) 15:21, 5 December 2016 (UTC)


 * Try just calling runJobs.php on the command line, if you can - it could be that the jobs just haven't run yet. Yaron Koren (talk) 15:55, 5 December 2016 (UTC)


 * Thanks for the tipp! After adding the correct path for my installationphp /srv/www/htdocs/_fhbwiki/maintenance/runJobs.php suddenly the jobs scrolled through like mad... ;) Now that I know how to get the replacement to work I'm really happy again! :) --Katwol (talk) 08:41, 7 December 2016 (UTC)

List of searchable namespaces incomplete under MediaWiki 1.28
I found one odd problem after upgrading to MW 1.28 (from MW 1.24). The list of namespaces available for selection under "search in namespaces" is now considerably reduced (no more than 18 in total) and does not even include the Main namespace. Cavila 11:42, 31 December 2016 (UTC)
 * I checked with Special:PrefixIndex to see if all namespaces are properly recognised and found no issues there.
 * Problem occurs with the latest version of RT (1.2) as well as 1.0.1 so I don't think there's a breaking change in RT to have caused this.
 * Okay, this is most likely not a RT issue, because the same layout (with many of the namespaces left out) is seen in Special:Search with advanced mode. Cavila 08:46, 1 January 2017 (UTC)
 * Got it. It's the Lockdown extension that introduced a breaking change, which is the requirement in Localsettings.php to define $wgNamespacePermissionLockdown for all namespaces rather than just the ones that you need to 'lock down'. That's it I think. Cavila 20:01, 10 January 2017 (UTC)

[RESOLVED] Missing namespaces
Has anyone experienced a total absence of namespaces in the search form? On one of my wikis, the list of namespaces is completely blank and of course, that makes the search/replace action fail with an error saying that at least one namespace needs to be selected. It looks like it may be a javascript issue on my end. I tried to disable some extensions and to switch to the vector skin, but it feels like flying blind, so I thought maybe someone already went through this issue before. If that can help, I am using the latest version of ReplaceText with Mediawiki 1.28 (but the extension does work fine with another 1.27 instance with another skin and the same version).


 * Are there any JavaScript errors in the browser console? Yaron Koren (talk) 14:33, 10 January 2017 (UTC)


 * The JS error is "Error: Widget not found: searchText Error: Widget not found: searchText". I'm kind of stumped at this point. I tried rolling back to a previous version and it also shows that error. In the meantime, I will try disabling extensions one at a time but that will take a while to go through the list. --Lalquier (talk) 15:00, 10 January 2017 (UTC)


 * (Update) I tracked the issue down the to Extension:Lockdown extension. I can't tell you if it was misconfigured or if the extension itself is a problem but disabling it brought the namespaces back in ReplaceText. --Lalquier (talk) 22:18, 11 January 2017 (UTC)


 * Great! By coincidence, that's the same problem that Cavila had in the section above this one. Yaron Koren (talk) 19:18, 12 January 2017 (UTC)