User talk:Sreejithk2000/JustReplace.js

Install edit

copy

importScript('User:Sreejithk2000/JustReplace.js');

into ./common.js.

To set an prefilled reason (e.g. duplicate), you can add this command into your ./common.js.

window.GlobalReplaceDefaultReason = "duplicate";

Usage edit

Click on "Global replace" in the dropdown menu:

 


Just a (template insert) bug edit

In the replace field is just the original file name, with the file namespace. If you insert the replacement file with this, you get a double file namespace in the name field for Template:Universal replace (if you use the CommonsDelinker option, I got this several times).[1] (Sreejithk2000?)User: Perhelion (Commons: = crap?) 23:08, 5 August 2014 (UTC)Reply

I never had a problem with this an I'm using it a lot. May it be the additional space in front of the filename causing this? Or a Browser issue? --Denniss (talk) 06:09, 6 August 2014 (UTC)Reply
Yes, it was the space. I've fixed that. -- Rillke(q?) 09:43, 6 August 2014 (UTC)Reply
  This section is resolved and can be archived. If you disagree, replace this template with your comment. Rillke(q?) 09:43, 6 August 2014 (UTC)

Just an exception (bug) edit

Please don't replace file names on his own file page:[2]User: Perhelion (Commons: = crap?) 13:22, 30 August 2014 (UTC)Reply

Is doing so generally wrong? Why? I'd like to see this more fleshed out. -- Rillke(q?) 16:10, 30 May 2015 (UTC)Reply
Because that makes nearly no sense. I can't imagine any case which this replacement could be useful. OT PS: I've putten minor edits off, so I've never seen your reply edits :-( (as in the Wiki guidelines, an posts should never be such).User: Perhelion (Commons: = crap?) 17:08, 24 January 2016 (UTC)Reply
Rillke, I do not know, whether you or Sreejithk2000 is the one to blame, but I must second Perhelion here. It makes no sense, that a file points to itself on its description page. The reason, why there is a link to the replaced file, is in almost all cases, because it is inserted in the “other versions” field of the heavy used templates Information and Artwork, and this field gets a nonsense content after replacing with this script, cf. this example: Special:Diff/188433464/191718812. — Speravir_Talk – 16:03, 31 March 2016 (UTC)Reply
Thinking of it further over night I believe it is more complex and complicated: JustReplace should never alter the content of this “other versions” field. But the underlying lib was originally made for GlobalReplace (Am I right?), and for deleting it would be necessary to remove a link to a file. See this file. There are more than one other version, the other files link back to it. This should never be changed, but it would with JustReplace like it is now. But I once requested a deletion of this file, and if this had been done, then the link had to be removed from the other versions, of course. — Speravir_Talk – 15:55, 1 April 2016 (UTC)Reply
Thank you for assent and assistance. I must do revert nearly on every usage with this tool, so I do not recognize this as really problem anymore (like manual signing) User: Perhelion 09:06, 9 May 2016 (UTC)Reply
PS ToDo: This need to be fixed in MediaWiki:Gadget-libGlobalReplace.js. -- User: Perhelion 00:44, 4 March 2017 (UTC)Reply
  Done -- User: Perhelion 01:49, 8 December 2017 (UTC)Reply

Feature request: checkbox edit

A checkbox for user-space exemption would be nice.User: Perhelion (Commons: = crap?) 12:13, 5 November 2014 (UTC)Reply

In which cases you want to exempt the user namespace? -- Rillke(q?) 16:09, 30 May 2015 (UTC)Reply
Large user page galleries often cause replacements to fail/time-out, especially on somewhat slow connections. Also seen on SteinsplitterBot and other Bot collection/log pages.--Denniss (talk) 16:59, 30 May 2015 (UTC)Reply
So it's not necessary to replace on these pages? Another venue would be a bot using oAuth to do the replacement under whichever user account the replacement was ordered. Wikimedia Labs has very fast access to the production cluster so the risk that something would time out there is low. -- Rillke(q?) 17:48, 30 May 2015 (UTC)Reply
  Done -- User: Perhelion 01:50, 8 December 2017 (UTC)Reply

Feature request: user defined default reason edit

I would like to be able to configure default reasons for replace a file which should appear in the input box for manual override if necessary. Is this possible? (Rillke?)User: Perhelion (Commons: = crap?) 17:02, 24 January 2016 (UTC)Reply

PS: Use of "wgPageName" is deprecated. Use mw.config instead.User: Perhelion (Commons: = crap?) 18:30, 24 January 2016 (UTC)Reply

I have added default reason support. You have to set window.GlobalReplaceDefaultReason = "" in your Custom JavaScript. --Sreejith K (talk) 19:33, 27 January 2016 (UTC)Reply
Ok, thanks, what a name.   PS: on the other side I have made by myself an hack earlier.User: Perhelion 19:41, 27 January 2016 (UTC)Reply
Sreejith K, could you, please, add an example on top here, how to insert this in one’s common.js and prefill it? In fact, I want to add a general string “using script "JustReplace"” (BTW: would be useful anyhow) and then complete this with individual replacing reasons. — Speravir_Talk – 16:14, 31 March 2016 (UTC) @Sreejithk2000, because I made a small mistake above. --Speravir (Talk) 15:54, 1 April 2016 (UTC)Reply
I've added it. There is already a link to the script (in every replace comment), which is not affected by user reason customization (so it would make no sense to add it twice IMHO) User: Perhelion 22:16, 2 April 2016 (UTC)Reply
Oh, so simple. I misinterpreted the “window” part (for “var” I wouldn’t have asked). To your “There is already a link to the script”: Aha, in the version histories of some Wikipedias I can find a “(GR)”, and some also use marks/tags, but not here on Commons, where I did look, cf. Special:Diff/188433464/191718812 (I already linked this above in another thread). No hint to a script, and hence came my question. — Speravir_Talk – 00:26, 3 April 2016 (UTC)Reply
Oh too, this is also new for me. ^^ User: Perhelion 04:45, 3 April 2016 (UTC)Reply
  Done -- User: Perhelion 01:51, 8 December 2017 (UTC)Reply

FeatureRequest: fault check target exists edit

I thought really there is such thing until yet (until you do a typo). The next point is, you can't undo this (automatically, because JustReplace don't work on not existing files on the other side).

Wer mit künstlicher Intelligenz arbeitet, muß auch mit natürlicher Dummheit rechnen.
- Klaus Kornwachs (*1947)

User: Perhelion 22:16, 4 April 2016 (UTC)Reply

I give this back upstream.[3]
  Done @Sreejithk2000 and Rillke: I've made this exists check in an addon here,[4] it also checks for duplicate or vector version available and prefill the input. User: Perhelion 13:18, 23 May 2016 (UTC)Reply

Error .replaceAll edit-request+ edit

{{Edit request}} Hello @Sreejithk2000 and Rillke: , the Script fails to run now. Can someone fix this line:

-var currentFileName = mw.config.get("wgPageName").replaceAll(' ', '_');
+var currentFileName = mw.config.get("wgPageName").replace(/_/g, ' ');

As I never heard about the non-standard replaceAll !? User: Perhelion 19:29, 30 May 2016 (UTC)Reply

Looks like the replaceAll function is loaded from MediaWiki:LAPI.js --Sreejith K (talk) 20:02, 31 May 2016 (UTC)Reply
Hello Sreejith, oh yes. Now it is clear to me, why this works absolutely randomly, because you have not a load time check for the module. Please just replace this absolutely strange prototype function (it splits the string to an array and joins them again together, why?!?). Anyway I've absolutely no idea for what this function could be useful (against native JS function)!? User: Perhelion 08:02, 1 June 2016 (UTC)Reply
PS: Maybe @Lupo: can answer this. Regards User: Perhelion 08:05, 1 June 2016 (UTC)Reply
  Done --Sreejith K (talk) 21:02, 6 June 2016 (UTC)Reply
Thank you, but another question: Is this replace anyway not senseless (thats why I switched the replace values)? The "wgPageName" has never whitespaces. User: Perhelion 11:03, 8 June 2016 (UTC)Reply
wgPageName is not supposed to have whitespace. But if for any reason it has a whitespace on some random page, I did not want the API to fail and throw a JavaScript error. --Sreejith K (talk) 14:12, 8 June 2016 (UTC)Reply
  This section is resolved and can be archived. If you disagree, replace this template with your comment. Sreejith K (talk) 21:02, 6 June 2016 (UTC)

New version edit

I've rewritten the script (a modernized fork, which is now also usable as a module like lib), which has more useful features from the main source lib: User:Perhelion/justReplace.js. Which includes file-exist-check, user-rights-check, name-space-check and value-backup-save for possible retry, and replacing of all redirects. Maybe it could also use few additional features from the addon (but maybe this an too individual addon)!? User: Perhelion 20:59, 12 January 2017 (UTC)Reply

Return to the user page of "Sreejithk2000/JustReplace.js".