Help:VisualFileChange.js/samples

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Some examples have code attached. You can copy this code and paste it into your common.js. Make sure you don't copy evil code and you remove code from old samples before. After saving, you have to reload the page where you want to test the example, click the link to launch VisualFileChange, fill in the target, continue, then open the profile dialog and load the example from your common.js (Commons).

Custom replace

User name changed

Simply replace [[User:Before|Before]] with [[User:After|After]].

If you used a non-default format, you may replace /Before/g with After. To achieve this, enter your old user name in the first field of Pattern to match, click the green label (R. → /R\./g), then enter your new user name in Text to insert instead, select /R/ (regular expression) and all your files and execute. Warning: If your old username was a common word, make ensure it is not accidentally replaced where it shouldn't. In this case, you must set up more strict rules (regular expressions).

Template:CoordTemplate:Object location

If you used decimal numbers, it's very easy. The pattern is a Regular Expression: /\{\{Coord\|([^\|]+)\|([^\|]+)\}\}/ (don't forget to tick the /R/) and the text to insert is {{Object location dec|$1|$2}}.

Moving content

You misplaced a template on a file description page? (E.g. a permission template that should be in the permission section) You want to add {{Book}} or {{Information}} to a batch of files?

No problem.

{{Permissiontemplate|this can vary|different param2}}
== {{int:filedesc}} ==
{{Information
|Description ={{en|1=Test whether scripts are vulnerable.}}
|Source ={{own}}
|Author =[[User:Rillke|Rillke]]
|Date =2011-11-18
|Permission ={{PD-Ineligible}}
}}
[[Category:Test images]]
...
== {{int:filedesc}} ==
{{Information
|Description ={{en|1=Test whether scripts are vulnerable.}}
|Source ={{own}}
|Author =[[User:Rillke|Rillke]]
|Date =2011-11-18
|Permission ={{Permissiontemplate|this can vary|different param2}}
{{PD-Ineligible}}
}}
[[Category:Test images]]
...

Using the following code

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"sample:moving content":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"Moving permission template to the permission section","mdReplacePermission":false,"mdDeleteHeading":"","mdTalkNote":"","mdRRegEx1":true,"mdRVar1":false,"mdMatchText1":"/((?:\\n|.)+)(\\{\\{Permissiontemplate[^\\{\\}]*\\}\\}\\n?)((?:\\n|.)+)([Pp]ermission\\s*=)/","mdReplaceText1":"$1$3$4$2","mdRRegEx2":true,"mdRVar2":true,"mdMatchText2":"/(\\{\\{Permissiontemplate[^\\{\\}]*\\}\\}\\n?)((?:\\n|.)+)([Pp]ermission\\s*=)/","mdReplaceText2":"$2$3$1","mdRRegEx3":false,"mdRVar3":true,"mdMatchText3":"","mdReplaceText3":"","selPreserve":"placeholder","alsoPreserve":""},"action":"c_replace","objectMembers":{"mdTarget":"Category:Test images","mdLedir":"older","mdCmdir":"asc","mdCmsort":"sortkey"},"continueAt":{"vals":["file|4553534149205356472e535647|383225","file|5252522e4a504547|10606118"],"setVals":["mdLestart"]},"time":"2012-04-09T12:03:27.102Z"}}; 
//////////////////////////////////vFCProfilEnd//

Inserting variables

When inserting variables at the end or top of a file using a regular expression, you should switch the preserve mode[clarification needed] to "Allow usage of substring and $1".

Variables:

  • %FULLPAGENAME% (e.g. File:Example.jpg)
  • %FULLPAGENAMEE% (url encoded title)
  • %PAGENAME% (e.g. Example.jpg)

Metadata (there are much more available, values must be numeric or of type string):

  • %Make% (optical device (camera)-manufacturer)
  • %Model% (model manufacturer)
  • %DateTime% (set by the optical device)
  • %DateTimeOriginal%
  • %FocalLength%

camera category or template

This will e.g. add [[Category:Taken with Canon EOS 400D DIGITAL]]

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"sample:Adding a camera category":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"Adding a camera category.","mdReplacePermission":false,"mdDeleteHeading":"","mdTalkNote":"","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/(.)$/","mdReplaceText1":"$1\n[[Category:Taken with %Model%]]","mdRRegEx2":false,"mdRVar2":false,"mdMatchText2":"\n[[Category:Taken with %Model%]]","mdReplaceText2":"","mdRRegEx3":false,"mdRVar3":true,"mdMatchText3":"","mdReplaceText3":"","selPreserve":"placeholder","alsoPreserve":""},"action":"c_replace","objectMembers":{"mdTarget":"Category:Test images","mdLedir":"older","mdCmdir":"asc","mdCmsort":"sortkey"},"continueAt":{"vals":["file|4553534149205356472e535647|383225","file|5252522e4a504547|10606118"],"setVals":["mdLestart"]},"time":"2012-04-09T12:36:40.205Z"}}; 
//////////////////////////////////vFCProfilEnd//

parts of the filename

This will add a category based on the filename. It was used on File:Uruguay Export Treemap.png and some other uploads of User:MIT Harvard Observatory.

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"MIT Harvard Observatory":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"Categorizing images: Economy of country","mdReplacePermission":false,"mdDeleteHeading":"Files uploaded by [[User:MIT Harvard Observatory|MIT Harvard Observatory]] ([[User talk:MIT Harvard Observatory|talk]] · [[Special:Contributions/MIT Harvard Observatory|contribs]])","mdTalkNote":"If you have a question concerning this process, answer below, or in case of a deletion request, on the deletion-discussion page. Do not ask on my discussion page. With best regards","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/(.)$/","mdReplaceText1":"$1\n----ksfjekrekrejr%PAGENAME%----ksfjekrekrejr","mdRRegEx2":true,"mdRVar2":true,"mdMatchText2":"/\\-\\-\\-\\-ksfjekrekrejr(.+) Export Treemap\\.png\\-\\-\\-\\-ksfjekrekrejr$/","mdReplaceText2":"[[Category:Economy of $1]]
[[Category:VisualFileChange]]
","mdRRegEx3":false,"mdRVar3":true,"mdMatchText3":"","mdReplaceText3":"","selPreserve":"secure","alsoPreserve":""},"action":"c_replace","objectMembers":{"mdTarget":"MIT Harvard Observatory","mdLedir":"older","mdCmdir":"asc","mdCmsort":"sortkey"},"continueAt":{"vals":["2012-04-05T21:27:08Z","2012-04-05T20:26:27Z"],"setVals":["mdLestart"]},"time":"2012-04-09T11:12:53.778Z"}}; 
//////////////////////////////////vFCProfilEnd//

GPS from Exif

This is only a sample. If your camera saves Exif-Data in a different format, you have to adjust the code. Please note that DschwenBot usually extracts the location so the use should be limited to rare cases.

//vFCProfil/////////////////////////////////////
/////// VISUAL FILE CHANGE CONFIGURATION ///////
///// DO NOT MODIFY BY HAND - FINGERS AWAY! ////
////////////////////////////////////////////////
window.vFC_Profiles = {"reading GPS":{"editInputs":{"mdDeleteReason":"","mdEditSummary":"Adding Location from Exif.","mdReplacePermission":false,"mdDeleteHeading":"","mdTalkNote":"","mdRRegEx1":true,"mdRVar1":true,"mdMatchText1":"/(\\|other_versions =\\s*\\}\\})/","mdReplaceText1":"$1\n{{Location dec|%GPSLatitude%|%GPSLongitude%}}","mdRRegEx2":false,"mdRVar2":true,"mdMatchText2":"{{Location dec||}}","mdReplaceText2":"","mdRRegEx3":false,"mdRVar3":true,"mdMatchText3":"","mdReplaceText3":"","selPreserve":"placeholder","alsoPreserve":""},"action":"c_replace","objectMembers":{"queryParams":{"target":"","lestart":"","ledir":""},"startInput":{"mode":"User","modeCat":false,"modeUser":true,"modePage":false,"target":"","loadThumbs":true,"loadWikitext":true,"startDate":"","startFile":""}},"proceedAt":{"vals":["2012-10-09T21:26:14Z","2012-07-19T19:20:12Z"],"setVals":["lestart"]},"time":"2012-10-30T19:07:15.361Z"}};
//////////////////////////////////vFCProfilEnd//
Using the provided code in your common.js; after loading the profile reading GPS.