MediaWiki:Common.js
From MediaWiki
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.
function loadsearchstuff() {
// If you're reading this, I'm sorry. Messy code lies ahead.
if (document.implementation && document.implementation.createDocument)
xmlDoc=document.implementation.createDocument("","",null);
else
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("/index.php?title=Template:Searchicons&action=raw");
// Establishing the various fragments of the search box.
var randindex = Math.floor(Math.random()*xmlDoc.getElementsByTagName("item").length);
var searchicon = "<a href='/wiki/" + xmlDoc.getElementsByTagName("name")[randindex].childNodes[0].nodeValue + "'><img src='" + xmlDoc.getElementsByTagName("url")[randindex].childNodes[0].nodeValue + "' style='margin-left: -16px; margin-top:-6px;' /></a>";
var searchbox = document.getElementById('searchBody');
var advancedsearchfields = '<div style="width: 80px; text-align: left; font-size: 84%; padding:0; margin:0;"><input type="checkbox" name="all" />All<br /><input type="checkbox" name="categories" />Categories<br /><input type="checkbox" name="templates" />Templates<br /><input type="checkbox" name="talk" />Talk pages</div>';
// Throwing all the various fragments together.
searchbox.innerHTML = searchicon + '<form id="searchform" name="searchform"><input type="image" src="http://images.wikia.com/transformers/images/e/e3/Go.png" name="go" class="searchButton" id="searchGoButton" value="Go" style="float: right; margin: 0; padding: 0;" onclick="return advancedsearch(false)" /><input id="searchInput" name="search" type="text" title="Search Teletraan I [f]" accesskey="f" value="" style="width: 70%;" /><input type="image" src="http://images.wikia.com/transformers/images/9/95/Search.png" name="fulltext" class="searchButton" id="mw-searchButton" value="Search" style="float: right;" onclick="return advancedsearch(true)" />' + advancedsearchfields + '</form>';
// Finally, removing the redundant "search" title at the top.
searchbox.parentNode.removeChild(searchbox.parentNode.getElementsByTagName("h5")[0]);
}
function advancedsearch(fulltext) {
// This is what drives the advanced search. The URL is rewritten, since the parameters
// do not actually match what the form expects. This should be fixed if there's a better
// way of doing it, and there probably is.
var advancedform = document.realform;
var searchform = document.searchform;
advancedform.action = "/wiki/Special:Search";
advancedform.action += "?search=" + searchform.search.value;
if (fulltext) advancedform.action += "&fulltext=Search";
else advancedform.action += "&go=Go";
if (searchform.all.checked || searchform.categories.checked || searchform.templates.checked || searchform.talk.checked) searchform.action += "&searchx=Search";
// This parameter isn't normally passed in the searchbox, but it seems to
// make the checkboxes retain their values on the advanced search page.
if (searchform.all.checked)
for (var i=0; i<15; i++) advancedform.action += "&ns" + i + "=1";
else { // No need to look at the rest if "all" is checked
if (searchform.categories.checked) advancedform.action += "&ns14=1";
if (searchform.templates.checked) advancedform.action += "&ns10=1";
if (searchform.talk.checked) advancedform.action += "&ns1=1&ns3=1&ns5=1&ns7=1&ns9=1&ns11=1&ns13=1&ns15=1";
}
advancedform.submit();
return false;
}
addOnloadHook(loadsearchstuff);

