FlightGear wiki:Instant-Refs: Difference between revisions

Jump to navigation Jump to search
[Long edit summary] 1) Fix bug in date formatting 2) Remove underscores from just wiki text 3) If label contains dots, replace with URL (e.g., http://example.com/path ... file.html → http://example.com/path/to/file.html)
(→‎Issues/limitations: Update + stumbled on a new problem)
([Long edit summary] 1) Fix bug in date formatting 2) Remove underscores from just wiki text 3) If label contains dots, replace with URL (e.g., http://example.com/path ... file.html → http://example.com/path/to/file.html))
Line 54: Line 54:
== Issues/limitations ==
== Issues/limitations ==
* Taking quotes from the forum '''will not work when the user is logged in'''.
* Taking quotes from the forum '''will not work when the user is logged in'''.
* Underscores are removed from code; change code so that only wiki links have underscores removed. {{progressbar|20}}
* The JavaScript <code>alert();</code> boxes used are typically restricted to a max size of about 10 KB; other options should be looked at. {{Not done}}
* The JavaScript <code>alert();</code> boxes used are typically restricted to a max size of about 10 KB; other options should be looked at. {{Not done}}


== Feature requests & ideas ==
== Feature requests & ideas ==
* Convert videos to wiki markup.
* Internet Explorer stuff can be removed.  It seems that Internet Explorer plugins are implemented completely differently. {{Not done}}
* Internet Explorer stuff can be removed.  It seems that Internet Explorer plugins are implemented completely differently. {{Not done}}
* GET-encoded SID arguments should be stripped from forum URLs. {{Not done}}
* GET-encoded SID arguments should be stripped from forum URLs. {{Not done}}
Line 75: Line 75:
// @description Automatically converts mailing list and forum quotes into Mediawiki markup.
// @description Automatically converts mailing list and forum quotes into Mediawiki markup.
// @namespace  http://wiki.flightgear.org/
// @namespace  http://wiki.flightgear.org/
// @version    0.15
// @version    0.16
// @icon      http://wiki.flightgear.org/images/6/62/FlightGear_logo.png
// @icon      http://wiki.flightgear.org/images/6/62/FlightGear_logo.png
// @require    http://code.jquery.com/jquery-1.11.1.min.js
// @require    http://code.jquery.com/jquery-1.11.1.min.js
Line 216: Line 216:
}
}
   
   
// converts html <a>...</a>'s to wiki links, internal if possible
// Converts HTML <a href="...">...</a> tags to wiki links, internal if possible.
function a2wikilink() {
function a2wikilink(){
    return function(html) {
return function(html)  
        // first tries internal links, firstmost links to images (File:xxx), because
// Links to wiki images, because
        // they need special treatment, or they get displayed
// they need special treatment, or else they get displayed.
        html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(File:.*?)".*?>(.*?)<\/a>/g, "[[:$1|$2]]");
html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(File:.*?)".*?>(.*?)<\/a>/g, "[[Media:$1|$2]]");
        // automatic links to the wiki (we don't use the displayed text)
 
        html = underscoreToSpace(html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>http:\/\/wiki\.flightgear\.org\/.*?<\/a>/g, "[[$1]]"));
// Wiki links without custom text.
        // links to the wiki with custom text (we preserve it)
html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>http:\/\/wiki\.flightgear\.org\/.*?<\/a>/g, "[[$1]]");
        html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>(.*?)<\/a>/g, "[[$1|$2]]");
 
// Links to the wiki with custom text
        // then the others
html = html.replace(/<a.*?href="http:\/\/wiki\.flightgear\.org\/(.*?)".*?>(.*?)<\/a>/g, "[[$1|$2]]");
        html = html.replace(/<a.*?href="(.*?)".*?>(.*?)<\/a>/g, "[$1 $2]");
 
        return html;
// Remove underscores from all wiki links
    };
var list = html.match(/\[\[.*?\]\]/g);
if(list !== null){
for(var i = 0; i < list.length; i++){
html = html.replace(list[i], underscore2Space(list[i]));
}
}
 
// Convert non-wiki links
html = html.replace(/<a.*?href="(.*?)".*?>(.*?)<\/a>/g, "[$1 $2]");
 
// Remove triple dots from external links.
// Replace with raw URL (MediaWiki converts it to a link).
list = html.match(/\[.*?(\.\.\.).*?\]/g);
if(list !== null){
for(var i = 0; i < list.length; i++){
html = html.replace(list[i], list[i].match(/\[(.*?) .*?\]/)[1]);
}
}
 
return html;
};
}
}
   
   
Line 395: Line 415:
     //TODO: add template string to profile
     //TODO: add template string to profile
     var template = "{{FGCquote" + "\n" +
     var template = "{{FGCquote" + "\n" +
         " |" + info.content + "\n" +
         "|" + info.content + "\n" +
         " |{{cite web |url=" + info.url + "\n" +
         "|{{cite web" + "\n" +
         "     |title=" + nowiki(info.title) + "\n" +
" |url   = " + info.url + "\n" +
         "     |author=" + nowiki(info.author) + "\n" +
         " |title = " + nowiki(info.title) + "\n" +
         "     |date=" + datef(info.date) + "\n" +
         " |author = " + nowiki(info.author) + "\n" +
         "   }}" + "\n" +
         " |date   = " + datef(info.date) + "\n" +
         " }}" + "\n" +
         "}}";
         "}}";
     return template;
     return template;
Line 427: Line 448:
if(date == "11" || date == "12" || date == "13"){
if(date == "11" || date == "12" || date == "13"){
return "th";
return "th";
}else if(date.substr(1) == "1"){
}else if(date.substr(1) == "1" || date == "1"){
return "st";
return "st";
}else if(date.substr(1) == "2"){
}else if(date.substr(1) == "2" || date == "2"){
return "nd";
return "nd";
}else if(date.substr(1) == "3"){
}else if(date.substr(1) == "3" || date == "3"){
return "rd";
return "rd";
}else{
}else{
Line 444: Line 465:
}
}


function underscoreToSpace(str){
function underscore2Space(str){
return str.replace(/_/g, " ");
return str.replace(/_/g, " ");
}
}

Navigation menu