Jump to content
Wikipedia The Free Encyclopedia

Wikipedia:AutoEd/wikilinks.js

From Wikipedia, the free encyclopedia
 // Credits: A modification of [[Wikipedia:WikiProject User scripts/Scripts/Formatter]]
 functionautoEdWikilinks(str){//MAIN FUNCTION describes list of fixes

 //Get the list of all wikilinks with underscores
 varm=str.match(/\[\[[^\[\]]*_[^\[\]]*\]\]/g);
 if(m){
 //For each wikilink in the list
 for(vari=0;i<m.length;i++){
 varx=m[i].toString()// Contains the entire wikilink
 // Exclude URLs and leading underscores
 if(!x.match(/^\[\[[\t ]*(?:http|ftp|https):/i)&&!x.match(/^\[\[_[^\[\]]*\]\]/)){
 varx_arr=x.match(/^(\[\[[^\[\]\|]*)(\|?[^\[\]]*?\]\])$/);
 vara=x_arr[1];// Everything before the pipe (or everything minus ]])
 varb=x_arr[2];// Everything after the pipe (or ]])

 // Replace underscores with spaces
 a=a.replace(/_/g,' ');
 // Do the replacement
 str=str.replace(x,a+b);
 }
 }
 }

 //Fix links which have no target
 str=str.replace(/\[\[[\t ]*\|/gi,'[[');

 //Leading and trailing space before the pipe inside wikilinks
 str=str.replace(/(\[\[)[\t ]+([^\[\]\|]*?)(\|)/g,'1ドル2ドル3ドル');
 str=str.replace(/(\[\[)([^\[\]\|]*?)[\t ]+(\|)/g,'1ドル2ドル3ドル');
 //Leading space after the pipe (or in an unpiped) wikilink
 str=str.replace(/^(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g,'1ドル2ドル3ドル');
 str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)[\t ]+([^\[\]\|\t ][^\[\]\|]*?)(\]\])/g,' 1ドル2ドル3ドル');
 //Trailing space after the pipe (or in an unpiped) wikilink
 str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|\t ][^\[\]\|]*?)[\t ]+(\]\])([^A-Za-z])/gi,'1ドル2ドル3ドル 4ドル');
 str=str.replace(/(\[\[[^\[\]\|]*?\||\[\[)([^\[\]\|]*?)[\t ]+(\]\])$/gi,'1ドル2ドル3ドル');

 //Get the list of all piped wikilinks
 varm=str.match(/\[\[[^\[]*?\|[^\[]*?\]\]/g);
 if(m){
 //For each piped wikilink in the list
 for(vari=0;i<m.length;i++){
 varn_arr=m[i].toString().match(/\[\[[ ]*([^\[]*?)\|[ ]*([^\[]*?)\]\]/);
 varn=n_arr[0];// Contains the entire piped link
 vara=n_arr[1];// Contains everything before pipe
 varb=n_arr[2];// Contains everything after pipe
 varc=b.replace(/[\.,:; ]*$/);// Same as b, but without trailing punctuation
 //Is the display name a leading substring of the wikilink?
 if(b.indexOf(a)==0||b.indexOf(autoEd_first2lower(a))==0){
 //Create a simplified replacement string
 vark=n.replace(/\[\[([^\]\|]*?)\|(1円)([\w]*?)\]\]/i,"[[2ドル]]3ドル");
 //And do the replacement
 str=str.replace(n,k);
 }
 if(c.indexOf(a)==0||c.indexOf(autoEd_first2lower(a))==0){
 // Create a simplified replacement string
 vark=n.replace(/\[\[([^\]\|]*?)\|(1円)([\w\.,:;]*?)\]\]/i,"[[2ドル]]3ドル");
 // And do the replacement
 str=str.replace(n,k);
 }
 }
 }

 //Push trailing characters into display string of piped wikilinks
 //str = str.replace(/\[\[([^\[\]\|]+)\|([^\[\]\|]+)\]\]([a-z]+)/g, "[[1ドル|2ドル3ドル]]");

 //Removes links to current article
 varp1=mw.config.get('wgPageName');// PAGENAME including underscores
 varp2=mw.config.get('wgPageName').replace(/_/g,' ');// PAGENAME without underscores
 varp3=autoEd_first2lower(p1);// First character lowercase PAGENAME including underscores
 varp4=autoEd_first2lower(p2);// First character lowercase PAGENAME without underscores
 // Standard wikilinks
 str=str.replace(newRegExp('\\[\\[('+p1+'|'+p2+'|'+p3+'|'+p4+')\\]\\]','g'),'1ドル');
 // Piped wikilinks
 str=str.replace(newRegExp('\\[\\[(?:'+p1+'|'+p2+'|'+p3+'|'+p4+')\\|([^\\]\\|]*)\\]\\]','g'),'1ドル');

 //Shorten interwiki links
 str=str.replace(/\[\[WIKTIONARY:/gi,'[[wikt:');
 str=str.replace(/\[\[WIKINEWS:/gi,'[[n:');
 str=str.replace(/\[\[WIKIBOOKS:/gi,'[[b:');
 str=str.replace(/\[\[WIKIQUOTE:/gi,'[[q:');
 str=str.replace(/\[\[WIKISOURCE:/gi,'[[s:');
 str=str.replace(/\[\[WIKISPECIES:/gi,'[[species:');
 str=str.replace(/\[\[WIKIVERSITY:/gi,'[[v:');
 str=str.replace(/\[\[(?:WIKIMEDIA|FOUNDATION):/gi,'[[wmf:');
 str=str.replace(/\[\[METAWIKIPEDIA:/gi,'[[m:');

 //Replace [[Foo #bar]] -> [[Foo#bar]]
 str=str.replace(/\[\[([^\]]*?)( |_)+#([^\]]*?)\]\]/g,'[[1ドル#3ドル]]');

 //Replace [[Foo|Foo]] -> [[Foo| ]]
 str=str.replace(/\|\]\]/g,'| ]]');

 returnstr;
 }

 // Converts the first character in a string to lower case
 // Notes: Used by autoEdWikilinks
 functionautoEd_first2lower(str){
 if(str!=""){
 varletter=str.substr(0,1);
 returnletter.toLowerCase()+str.substr(1,str.length);
 }else{
 return"";
 }
 }

AltStyle によって変換されたページ (->オリジナル) /