This is aninformation page. It is neither anencyclopedia article nor one ofWikipedia's policies or guidelines; rather, its purpose is to explain certain aspects of Wikipedia's norms, customs, technicalities, or practices. It may reflect differing levels ofconsensus andvetting. |
This page serves as a central repository forscripts onWikipedia. Please feel free to improve any of these scripts but make sure to test your changes first. Like the rest of Wikipedia, all material here is underCC BY-SA 4.0. Seelicensing for further details.
Remember toKeep it simple, stupid! Do one thing and do it well; this is a place for simple scripts and not whole programs.
All material on Wikipedia is by default under theCC BY-SA license (and in most cases, also theGNU Free Documentation License (GFDL)). The CC BY-SA license is designed for artistic and literary works, but not for software. However, version 4.0 of CC BY-SA allows its "ShareAlike" provision to be fulfilled by releasing modified code under the GPL, version 3. However, if you want your work to be of the greatest use to the public, please consider dual-licensing it so that reusers can take advantage of future versions of the GPL. Like the GFDL, the GPL is released by theFree Software Foundation. You can use both by explicitly stating in a comment at the start of your script that your script is dual-licensed under the GPL.
A brief ON trigger forircII that works with#mwlink below. If I was really elite this would all be in ircII script language, but that would be really too awful to contemplate: besides which, the filter can be useful for other purposes.
set exec_protection off on public - on #^public 0 * if (match(*[[* [$2-])) { exec mwlink $shellfix($Z$1<$0> $2-) } { echo $Z$1<$0> $2- }Note: setting exec_protection off could make you vulnerable to exploits by others unless you know what you're doing with your ON triggers.
Also, the$Z$1<$0> $2- is my preferred format for channel messages; yours may differ.
This is efficient in the sense that it only invokes the filter for lines containing a wiki link; it is inefficient because it invokes it for every line. I couldn't get persistent process communication working for ircII--if someone else can, that would be great.
ThisircII-derived client can use almost the same script asircII, above:
set exec_protection off on public - on #^public 0 * if (match(*[[* [$2-])) { exec -direct mwlink $Z$1<$0> $2- } { echo $Z$1<$0> $2- }Note that the-direct option to/exec is used instead of the$shellfix() function, which EPIC4 does not provide.
Use of the linkify plugin plus a wikilink config file allows you to see all those [[links]] that everyone is typing as real links.
my$CfgFile="$ENV{HOME}/.gaim/linkify.cfg";
my$CfgFile="C:/Documents and Settings/YOURUSERNAME/Application Data/.gaim/linkify.cfg";
# Wikipedia links\[\[([^\[\]]*)\]\]http://en.wikipedia.org/wiki/$1
(Contributed byUser:Omegatron)
Use the following script, which will make any [[links]] appear as [[links]] <http://en.wikipedia.org/wiki/links>. Store it in .irssi/scripts, then you do /load script-name, although it might not take effect in an existing instance of a channel:
Met's script |
|---|
#!/usr/bin/perlusestrict;usewarnings;useIrssi;Irssi::settings_add_str('wikify','wiki_lang','en');Irssi::settings_add_str('wikify','wiki_active_channels','freenode/#wikipediafreenode/#wikibooks');subwikilang{Irssi::settings_get_str('wiki_lang');}suburlencode{my$string=shift;$string=~y/ /_/;$string=~s/(\W)/sprintf("%%%02X", ord($1))/seg;return$string;}subwikilink{my$s=shift;my$u=urlencode$s;my$l=wikilang;"[[$s]] <http://$l.wikipedia.org/wiki/$u>";}subwikitemplate{my$s=shift;my$u=urlencode$s;my$l=wikilang;"{{$s}} <http://$l.wikipedia.org/wiki/Template:$u>";}subwikify{my$line=shift;$line=~s/\[\[(.*?)\]\]/wikilink $1/eg;$line=~s/{{(.+?)}}/wikitemplate $1/eg;return$line;}subsig_message_public{my($server,$msg,$nick,$address,$target)=@_;my$chatnet=$server->{chatnet};my$ok=0;formy$t(split/\s+/,Irssi::settings_get_str('wiki_active_channels')){$ok=1iflc$teqlc"$chatnet/$target";}returnunless$ok;$msg=wikify$msg;Irssi::signal_continue($server,$msg,$nick,$address,$target);}Irssi::signal_add_first('message public',\&sig_message_public); |
(Contributed byRicky Clarkson, who was channelling 'met' from Freenode IRC, on #irssi)
User:Sam Hocevar has an irssi script to do much the same thing; seehis Wikipedia page;wikilinks.pl.
ERC is an IRC client for emacs implemented in Emacs Lisp.
The following code can be added to your emacs initialization file (I put it in~/.emacs.d/mwlink.el). It uses the#mwlink script below, running in daemon mode (mwlink --daemon); or rather, it depends on it. Your browser will open a URL of the formhttp://localhost:4242/mwlink?page=<page> and get redirected to the appropriate wikimedia page. This means the following code can be relatively simple (rather than having to figure out languages, namespaces and wikis on its own.
Another note: this depends on the emacs-wiki package for theemacs-wiki-escape-url function. I also don't know how well it plays with Custom (though customizing `erc-button-alist' isn't any nicer than doing this or editing it directly).
(add-to-list'erc-button-alist'("\\[\\[\\(.*?\\)\\]\\]"0t(lambda(page)(browse-url(concat"http://localhost:4242/mwlink?page="(emacs-wiki-escape-urlpage))))1))
[10:10]<Someuser>Blah blah blah [[WP:AFD]] blah blah blah. [[WP:POINT]] blah blah blah.[10:10] http://en.wikipedia.org/wiki/WP:AFD http://en.wikipedia.org/wiki/WP:POINT
IceChat |
|---|
FunctionWikiMatch(TextToMatch)DimregEx,CurrentMatch,CurrentMatches,ActualLink,Links,CurrentSearchSetregEx=NewRegExpregEx.Pattern="(\[\[.*?\|)|\[\[.*?\]\]|(\{\{.*?\}\})"regEx.IgnoreCase=TrueregEx.Global=TrueregEx.MultiLine=TrueSetCurrentMatches=regEx.Execute(TextToMatch)ForEachCurrentSearchinCurrentMatchesActualLink=Replace(CurrentSearch,"[[","")ActualLink=Replace(ActualLink,"]]","")ActualLink=Replace(ActualLink,"{{","Template:")ActualLink=Replace(ActualLink,"}}","")ActualLink=Replace(ActualLink,"|","")ActualLink=Replace(ActualLink," ","_")ifActualLink<>""ThenWikiMatch=Wikimatch+" http://en.wikipedia.org/wiki/"+ActualLinkEndIfNextEndFunctionSubONTEXT(Message,Channel,Nickname,Host,ServerNumber)DimMatchesMatches=WikiMatch(Message)IfMatches<>""ThenSendCommand"/echo "+Channel+" "+Matches,ServerNumberEndIfEndSubSubONQUERY(Message,Nickname,Host,ServerNumber)DimMatchesMatches=WikiMatch(Message)IfMatches<>""ThenSendCommand"/echo ="+Nickname+" "+Matches,ServerNumberEndIfEndSub |
To use this script, selectScripting >Edit events..., right-click on theOnChannelMessage event and selectNew handler, then paste the script.
For using thesecure server, change the following line in the used script:
%wikibase="http://en.wikipedia.org/wiki/"
to
%wikibase="https://en.wikipedia.org/wiki/"
KVIrc pre 4.0 script |
|---|
# Parameters:# $0 = source nick# $1 = source username# $2 = source host# $3 = message%wikibase="http://en.wikipedia.org/wiki/"%msg=$3%done=0%replace=0%iter=1while(%done==0){%linkleft=$str.find(%msg,"[[",%iter)%linkright=$str.find(%msg,"]]",%iter)%linklength=$(%linkright-%linkleft)%linklength=$(%linklength-2)if((%linkleft>=0)&&(%linklength>0)){%wikitarget=$str.mid(%msg,$(%linkleft+2),%linklength)%url=%wikibase%wikitarget%newtarget=$k(12)$fmtlink(%wikitarget,openurl%url)$k# Brackets avoid mix-up when wikiword is too short%msg=$str.replace(%msg,"[[%newtarget]]","[[%wikitarget]]")%replace=1}else{%done=1}%iter++# Avoid infinite loopif(%iter>8){%done=1}}if(%replace){echoprivmsg$0$1$2%msg# halt normal message processinghalt}# Function exits without output for unprocessed messages |
Version 4 introduced small changes in the scripting language KVS and thus old scripts may not work any longer. The Version 4.0+ script has additional the possibility to display URLs for wikilinks which are going to theaccount creation tool on thetoolserver and to link templates correctly.
KVIrc 4.0+ |
|---|
# Parameters:# $0 = source nick# $1 = source username# $2 = source host# $3 = message%accbase="http://toolserver.org/~acc/acc.php?action=zoom&id="%wikibase="http://en.wikipedia.org/wiki/"%acc=0%template=0%msg=$3%done=0%replace=0%iter=1while(%done==0){%linkleft=$str.find(%msg,"[[",%iter)%linkleft_acc=$str.find(%msg,"[[acc:",%iter)%linkleft_template=$str.find(%msg,"{{",%iter)if(%linkleft_acc>=0){%acc=1%linkleft=%linkleft_acc}if(%linkleft_template>=0){%template=1%linkleft=%linkleft_template}if(%template==1){%linkright=$str.find(%msg,"}}",%iter)}else{%linkright=$str.find(%msg,"]]",%iter)}%linklength=$(%linkright-%linkleft)%linklength=$(%linklength-2)if((%linkleft>=0)&&(%linklength>0)){%wikitarget=$str.mid(%msg,$(%linkleft+2),%linklength)if(%acc==1){%acctarget=$str.mid(%wikitarget,$(4),%linklength)%url=%accbase%acctarget}else{if(%template==0){%url=%wikibase%wikitarget}else{%url=%wikibase"Template:"%wikitarget}}%newtarget=$k(12)$fmtlink(%wikitarget,openurl%url)$k# Brackets avoid mix-up when wikiword is too shortif(%template==0){%msg=$str.replace(%msg,"[[%wikitarget]]","[[%newtarget]]")}else{%msg=$str.replace(%msg,"{{%wikitarget}}","{{%newtarget}}")}%replace=1}else{%done=1}%iter++# Avoid infinite loopif(%iter>8){%done=1}}if(%replace){echoprivmsg$0$1$2%msg# halt normal message processinghalt}# Function exits without output for unprocessed messages |
The Wordsmith's Script |
|---|
; Copyright (c) 2016 The Wordsmith.; This script is dual-licensed under the GPL,; version 3 or (at your option) any later version.; Redistribution of source code must retain this copyright notice and appropriate attribution.; See http://www.gnu.org/licenses/gpl.txt for more details.on $*:text:/^\[\[.*?\]\]$/i:#:{ var %pos1 = $calc($pos($1-,[,2) + 1) var %pos2 = $pos($1-,],1) var %match = $mid($1-, %pos1, $calc(%pos2 - %pos1)) %match = $urlencode(%match) /echo $chan Wikilink: http://en.wikipedia.org/wiki/ $+ %match}alias UrlEncode return $regsubex($1-, /([^a-z\d_+.-])/ig, % $+ $base( $asc(\t), 10, 16, 2) ) |
Here's a short script to open up all contributions from anons in browser windows (works well with tabbed browsing).CryptoDerk 23:04, Feb 15, 2005 (UTC)
Place the following inTools->Scripts Editor under theremote tab.
ON $50:TEXT:/(http\S+) \* \d\d?\d?\.\d\d?\d?\.\d\d?\d?\.\d\d?\d? /iS:#en.wikipedia: run $regml(1)alias F9 auser 50 *127.0.0.1alias F11 ruser 50 *127.0.0.1
Now just sit in #en.wikipedia and hit F9 to begin. Hit F11 to stop. You can change F9/F11 to whatever function keys you like.
The above script can be adapted to open specific types of edits in #cvn-wp-en:
ON $50:TEXT:/gibberish|copyvio.*diff.*(http\S+)/iS:#cvn-wp-en: run $regml(1)alias F8 auser 50 *computer@wikipediaalias F12 ruser 50 *computer@wikipedia
This will open edits that the user with the cloak "computer@wikipedia" labels as "gibberish" or "copyvio". Use F8 and F12 to start and stop the script.
Also, for a frontend to the IRC live feeds, check outCryptoDerk's Vandal Fighter.
AnHTML character entity converter written inPerl that uses theord() function to convert a character to its corresponding number in the character set. It operates onstandard input.
#!/usr/bin/perl# Code is in the public domain.usestrict;my@input=split(//,<>);foreachmy$c(@input){if(ord($c)>=255){print'&#'.ord($c).';';}else{print$c;}}
Author:Olof
Notes: I got fed up with looking up Unicode characters, so I wrote an AppleScript for my favorite styled text editor (Style) to write them for me. Now, I can just type Japanese into a text edit window like this:
Select it, choose my script from the scripts menu, and it turns into:
小 泉 純 一 郎 小 泉 純 一 郎
which is what you can paste into the Wikipedia edit window. This is a Mac-only solution, but I thought I'd share it for those of you who can use it.
Compile the script below in ScriptEditor, and save it in the "Style Scripts" folder in the same folder where the Style application lives. I have mine saved as "Append Unicoded HTML". Thereafter it will appear in Style's "Scripts" menu.
Style is available atmerzwaren ($20 shareware). I have this running on Mac OS X 10.2.1 with Style version 1.9.2.
Here's the script:
AppleScript |
|---|
settheHTMLto""tellapplication"Style"setselTexttoselectionofdocument1asUnicode textsetselStarttogetoffsetofselectionofdocument1setselEndtogetoffsetofendofselectionofdocument1setdataLento(selEnd-selStart)endtellsettempNameto"unicode temp"tellapplication"Finder"ifaliastempNameexiststhenmovealiastempNametothetrashendifendtellsetfileReftoopen for accesstempNamewithwritepermissionwriteselTexttofileRefsetmyRawDatatoreadfileReffrom0fordataLenclose accessfileReftellapplication"Finder"movealiastempNametothetrashendtellsetnumCharstodataLendiv2repeatwithnfrom1tonumCharssettheHTMLtotheHTML&"&#"setatogetcharacter(2*n-1)ofmyRawDatasetbtogetcharacter(2*n)ofmyRawDatasetlValto((ASCII numberb)+(256*(ASCII numbera)))settheHTMLto(theHTML&lValasstring)&"; "endrepeattellapplication"Style"setselectionofdocument1to((selectionofdocument1)&" ( "&theHTML&" ) ")endtell |
Authors:
Known to work on:
Notes:
You may not need a script for converting CJK characters if you have a Mac running Mac OS X 10.2 and have Mozilla as your browser. Just do the editing from within Mozilla. Mozilla automatically does the conversion. For example, in adding this edit, I type in the Japanese characters for "edit," which are 編集. Mozilla automatically converted these characters to the proper romanized Unicode format. Just look at the above lines in the editing box to see for yourself. -User: IppikiOokami 5 September 2003
JavaScript |
|---|
<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Unicodeconversionutility</title></head><body><formname="charform"><p>Typehere,andallcharacterswithacodegreaterthan127willbeconvertedto&#1234;codes.</p><p>Input:</p><textareaname="input"cols="80"rows="25"onKeyUp="revtxt()">Sorry,thispageisuselesswithJavaScriptdisabled.</textarea><p>Output:</p><textareaname="output"cols="80"rows="25">Sorry,thispageisuselesswithJavaScriptdisabled.</textarea></form><scripttype="text/javascript"><!--document.charform.input.value="";document.charform.output.value="Don't type here.";functionrevtxt(){vars=document.charform.input.value;o="";for(m=0;s.charAt(m);++m)if((c=s.charCodeAt(m))<128&&c!=38)o+=s.charAt(m);elseif(c==38)o+="&";elseo+="&#"+c+";";document.charform.output.value=o;}--></script></html> |
This script usefully checks all checkboxes on a Wikipedia page, useful for clearing large watchlists or restoring pages with large histories. It works in Firefox, Internet Explorer, Camino andSafari.
In Firefox, create a bookmark, with the following code in the "location" field.
In Internet Explorer, create a favourite, and once it's created, right click it, select "properties" and place the following code in the "URL" box (it will give you an invalid protocol warning, but you can ignore this, and it will work).
InSafari, use the "Show all Bookmarks" option. Choose the "Bookmarks Bar" collection. Select the script below into the copy buffer and simply paste ([Command]-v) it into the window on the right. A new bookmark will automatically be created and will appear in the bookmarks bar. Re-name it something sensible like "Select All".
javascript:for(i=0;i<document.forms.length;i++){for(j=0;j<document.forms[i].elements.length;j++){f=document.forms[i].elements[j];if(f.type=='checkbox')f.checked=true;}}void0
A script written in Perl to mass upload photographs to Commons. Seecommons:User:Nichalp/Upload script.
/ImageFileMigrator Python script to download all files from a MediaWiki and add them to another MediaWiki using a Sysop account.
After visiting a Wikipedia link, that link changes color from blue to purple on my computer screen. To tag pages with categories, I've been opening all the pages atCategory:NA-Class articles, for example, to turn the links purple. Then I use theAll pages with prefix. Those pages for which the link still is blue need a Category:NA-Class category tag. It takes a lot of time to initially open all the pages within a particular category to turn the link from blue to purple. Is there a way to change the colors of the links inCategory:NA-Class articles as the appear on my computer screen without having to visit each of the links? I tried editing my temporary internet file (browser history) and tried using the 'Print all linked documents' option of windows print feature to printing to a file (that I then deleted). I wasn't able to edit my temporary internet file (browser history) and the 'Print all linked documents' option didn't result in making the category links purple. Can you create me a script that causes all the links on a page (e.g.Category:NA-Class articles) to change color to show that I visited the page (without actually opening the linked page)? I am open to other methods as well. Thanks.GregManninLB (talk)15:57, 17 April 2008 (UTC)[reply]
There are a number of pages designed to help with Wikipedia maintenance and editing whichare generated by copying the entire Wikipedia database to a machine and running a scriptor program on it.
Here you can request that someone with a recent copy of the database dump and the appropriate skills update theSpecialpages and other pages requiring scripting.
See also:Wikipedia:Request a query.