MediaWiki:Common.js/search.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/**
* Modifie Special:Search pour pouvoir utiliser différents moteurs de recherche,
* disponibles dans une boîte déroulante.
* Auteurs : Jakob Voss, Guillaume, importé depuis la Wiki allemande
* <pre><nowiki>
*/
function externalSearchEngines() {
if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;
var mainNode = document.getElementById("powersearch");
if (!mainNode) mainNode = document.getElementById("search");
if (!mainNode) return;
var beforeNode = document.getElementById("mw-search-top-table");
if (!beforeNode) return;
beforeNode = beforeNode.nextSibling;
if (!beforeNode) return;
var firstEngine = "mediawiki";
var choices = document.createElement("div");
choices.setAttribute("id","searchengineChoices");
choices.style.textAlign = "center";
var lsearchbox = document.getElementById("searchText");
var initValue = lsearchbox.value;
var space = "";
for (var id in searchEngines) {
var engine = searchEngines[id];
if(engine.ShortName)
{
if (space) choices.appendChild(space);
space = document.createTextNode(" ");
var attr = {
type: "radio",
name: "searchengineselect",
value: id,
onFocus: "changeSearchEngine(this.value)",
id: "searchengineRadio-"+id
};
var html = "<input";
for (var a in attr) html += " " + a + "='" + attr[a] + "'";
html += " />";
var span = document.createElement("span");
span.innerHTML = html;
choices.appendChild( span );
var label
if (engine.Template.indexOf('http') == 0) {
label = document.createElement("a");
label.href = engine.Template.replace("{searchTerms}", initValue).replace("{language}", "fr");
} else {
label = document.createElement("label");
}
label.appendChild( document.createTextNode( engine.ShortName ) );
choices.appendChild( label );
}
}
mainNode.insertBefore(choices, beforeNode);
var input = document.createElement("input");
input.id = "searchengineextraparam";
input.type = "hidden";
mainNode.insertBefore(input, beforeNode);
changeSearchEngine(firstEngine, initValue);
}
function changeSearchEngine(selectedId, searchTerms) {
var currentId = document.getElementById("searchengineChoices").currentChoice;
if (selectedId == currentId) return;
document.getElementById("searchengineChoices").currentChoice = selectedId;
var radio = document.getElementById('searchengineRadio-' + selectedId);
radio.checked = "checked";
var engine = searchEngines[selectedId];
var p = engine.Template.indexOf('?');
var params = engine.Template.substr(p+1);
var form;
if (document.forms["search"]) {
form = document.forms["search"];
} else {
form = document.getElementById("powersearch");
}
form.setAttribute("action", engine.Template.substr(0,p));
var l = ("" + params).split("&");
for (var idx = 0;idx < l.length;idx++) {
var p = l[idx].split("=");
var pValue = p[1];
if (pValue == "{language}") {
} else if (pValue == "{searchTerms}") {
var input;
input = document.getElementById("searchText");
input.name = p[0];
} else {
var input = document.getElementById("searchengineextraparam");
input.name = p[0];
input.value = pValue;
}
}
}
var searchEngines = {
mediawiki: {
ShortName: "Recherche interne",
Template: "/w/index.php?search={searchTerms}"
},
wikiwix: {
ShortName: "Wikiwix",
Template: "http://sc.wikiwix.com/index.php?action={searchTerms}&lang={language}"
},
google: {
ShortName: "Google",
Template: "http://www.google.fr/search?as_sitesearch=sc.wikipedia.org&hl={language}&q={searchTerms}"
},
wlive: {
ShortName: "Windows Live",
Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://sc.wikipedia.org"
},
yahoo: {
ShortName: "Yahoo!",
Template: "http://search.yahoo.com/search?p={searchTerms}&vs=sc.wikipedia.org"
},
exalead: {
ShortName: "Exalead",
Template: "http://www.exalead.com/wikipedia/results?q={searchTerms}&language=sc"
},
globalwpsearch: {
ShortName: "Global WP",
Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
}
};
$(externalSearchEngines);