Benutzer:Turnvater Jahn/MediaWiki Suche
Vorläufig unter http://tvj.xwsnet.de/wikisearch/index.php. Demnächst auf dem Toolserver.
PHP Quellcode für MediaWiki Such-Tool. Speicher den Code in .../wikisearch/index.php
<?
function ifelse($condition, $iftrue, $iffalse) {
if($condition) return $iftrue;
else return $iffalse;
}
echo "
<html>
<head>
";
$action = $_GET['action'];
$wiki = $_GET['wiki'];
$lang = $_GET['lang'];
$query = $_GET['q'];
$search = $_GET['search'];
$setframe = $_GET['setframe'];
$newframe = $_GET['newframe'];
$showns = $_GET['showns'];
$setnamespaces = $_GET['setnamespaces'];
$namespaces = array();
$customnamespaces = ( $_GET["ns100"] == '1' );
$customtalknamespaces = ( $_GET["ns101"] == '1' );
for($i = 0; $i <= 15; $i++) {
if( $_GET["ns$i"] == '1' ) {
$namespaces[$i] = '1';
} else {
$namespaces[$i] = '0';
}
}
$reload = False;
if ($setframe == 'New frame') {
//$reload = True;
$newframe='On';
} else {
if ($setframe == 'iFrame') {
// $reload = True;
$newframe='Off';
}
}
if ($setnamespaces == 'Show namespaces') {
//$reload = True;
$showns='On';
} else {
if ($setnamespaces == 'Hide namespaces') {
//$reload = True;
$showns='Off';
}
}
if($reload) {
$action='';
$search='';
}
if($action == 'search') {
$baseurl = "http://";
switch($wiki) {
case 'commons':
$baseurl = $baseurl."commons.wikimedia";
break;
case 'meta':
$baseurl = $baseurl."meta.wikimedia";
break;
case 'wikispecies':
$baseurl = $baseurl."species.wikimedia";
break;
default:
$baseurl = $baseurl."$lang.$wiki";
}
$searchurl = "$baseurl.org/wiki/Special:Search?search=$query";
if($search == "Search") {
$searchurl = $searchurl . "&fulltext=Search";
}
for($i = 0; $i <= 15; $i++) {
if( $namespaces[$i] == '1' ) {
$searchurl = $searchurl . "&ns$i=1";
}
}
for($i = 100; $i <= 120; $i += 2) {
if( $customnamespaces ) {
$searchurl = $searchurl . "&ns$i=1";
}
if( $customtalknamespaces ) {
$searchurl = $searchurl . "&ns".($i+1)."=1";
}
}
}
echo " </head><body>";
if( $newframe != 'Off' AND !$setframe AND !$setnamespaces AND $action == 'search') {
if(! $reload) {
echo "<meta HTTP-EQUIV=\"Refresh\" content=\"0; URL=$searchurl\">";
}
} else {
echo " <title>Search WikiMedia Wikis</title>";
echo "
</head>
<body>";
echo "<div \"width=100%\" style=\"float:left; \"><form action=\"/wikisearch/index.php\" target=";
if ($newframe == 'Off') {
echo "\"_self\"";
} else {
echo "\"_blanc\"";
}
echo ">";
$s = 'selected';
echo "
Search for:
<input name=\"action\" value=\"search\" type=\"hidden\">
<input name=\"newframe\" value=\"$newframe\" type=\"hidden\">
<input name=\"showns\" value=\"$showns\" type=\"hidden\">
<input name=\"q\" value=\"$query\" type=\"text\" size=\"20\" maxlength=\"255\" target=\"_blank\">
<select name=\"wiki\" size=\"1\">
<option ".ifelse($wiki=='wikipedia',$s,'')." value=\"wikipedia\">wikipedia</option>
<option ".ifelse($wiki=='commons',$s,'')." value=\"commons\">commons</option>
<option ".ifelse($wiki=='wikiversity',$s,'')." value=\"wikiversity\">wikiversity</option>
<option ".ifelse($wiki=='wikibooks',$s,'')." value=\"wikibooks\">wikibooks</option>
<option ".ifelse($wiki=='wiktionary',$s,'')." value=\"wiktionary\">wiktionary</option>
<option ".ifelse($wiki=='wikisource',$s,'')." value=\"wikisource\">wikisource</option>
<option ".ifelse($wiki=='wikiquote',$s,'')." value=\"wikiquote\">wikiquote</option>
<option ".ifelse($wiki=='wikinews',$s,'')." value=\"wikinews\">wikinews</option>
<option ".ifelse($wiki=='wikispecies',$s,'')." value=\"wikispecies\">wikispecies</option>
<option ".ifelse($wiki=='meta',$s,'')." value=\"meta\">meta</option>
</select>
<select name=\"lang\" size=\"1\">
<option ".ifelse($lang=='en',$s,'')." value=\"en\">en</option>
<option ".ifelse($lang=='de',$s,'')." value=\"de\">de</option>
<option ".ifelse($lang=='fr',$s,'')." value=\"fr\">fr</option>
<option ".ifelse($lang=='it',$s,'')." value=\"it\">it</option>
<option ".ifelse($lang=='es',$s,'')." value=\"es\">es</option>
<option ".ifelse($lang=='pt',$s,'')." value=\"es\">pt</option>
<option ".ifelse($lang=='ru',$s,'')." value=\"es\">ru</option>
<option ".ifelse($lang=='pl',$s,'')." value=\"es\">pl</option>
<option ".ifelse($lang=='cs',$s,'')." value=\"es\">cs</option>
<option ".ifelse($lang=='la',$s,'')." value=\"es\">la</option>
</select>";
echo "
<input type=\"submit\" name=\"search\" value=\"Go\"> <input type=\"submit\" name=\"search\" value=\"Search\">";
$s = 'checked';
$type='hidden';
$shw = ($showns != 'Off');
if( $showns != 'Off' ) {
$type='checkbox';
}
echo "
<span style=\"font-size:9pt\">
<input type=\"$type\" name=\"ns0\" "
.ifelse($namespaces[0]=='1',$s,'')." value="
.ifelse($shw,'"1"> Main', "\"$namespaces[0]\">")." <input type=\"$type\" name=\"ns1\" "
.ifelse($namespaces[1]=='1',$s,'')." value="
.ifelse($shw,'"1"> Talk', "\"$namespaces[1]\">")." | <input type=\"$type\" name=\"ns2\" "
.ifelse($namespaces[2]=='1',$s,'')." value="
.ifelse($shw,'"1"> User', "\"$namespaces[2]\">")." <input type=\"$type\" name=\"ns3\" "
.ifelse($namespaces[3]=='1',$s,'')." value="
.ifelse($shw,'"1"> User talk', "\"$namespaces[3]\">")." | <input type=\"$type\" name=\"ns4\" "
.ifelse($namespaces[4]=='1',$s,'')." value="
.ifelse($shw,'"1"> Project', "\"$namespaces[4]\">")." <input type=\"$type\" name=\"ns5\" "
.ifelse($namespaces[5]=='1',$s,'')." value="
.ifelse($shw,'"1"> Project talk', "\"$namespaces[5]\">")." | <input type=\"$type\" name=\"ns6\" "
.ifelse($namespaces[6]=='1',$s,'')." value="
.ifelse($shw,'"1"> File', "\"$namespaces[6]\">")." <input type=\"$type\" name=\"ns7\" "
.ifelse($namespaces[7]=='1',$s,'')." value="
.ifelse($shw,'"1"> File talk', "\"$namespaces[7]\">")." | <input type=\"$type\" name=\"ns8\" "
.ifelse($namespaces[8]=='1',$s,'')." value="
.ifelse($shw,'"1"> MediaWiki', "\"$namespaces[8]\">")." <input type=\"$type\" name=\"ns9\" "
.ifelse($namespaces[9]=='1',$s,'')." value="
.ifelse($shw,'"1"> MediaWiki talk', "\"$namespaces[9]\">")." | <input type=\"$type\" name=\"ns10\" "
.ifelse($namespaces[10]=='1',$s,'')." value="
.ifelse($shw,'"1"> Template', "\"$namespaces[10]\">")." <input type=\"$type\" name=\"ns11\" "
.ifelse($namespaces[11]=='1',$s,'')." value="
.ifelse($shw,'"1"> Template talk', "\"$namespaces[11]\">")." | <input type=\"$type\" name=\"ns12\" "
.ifelse($namespaces[12]=='1',$s,'')." value="
.ifelse($shw,'"1"> Help', "\"$namespaces[12]\">")." <input type=\"$type\" name=\"ns13\" "
.ifelse($namespaces[13]=='1',$s,'')." value="
.ifelse($shw,'"1"> Help talk', "\"$namespaces[13]\">")." | <input type=\"$type\" name=\"ns14\" "
.ifelse($namespaces[14]=='1',$s,'')." value="
.ifelse($shw,'"1"> Category', "\"$namespaces[14]\">")." <input type=\"$type\" name=\"ns15\" "
.ifelse($namespaces[15]=='1',$s,'')." value="
.ifelse($shw,'"1"> Category talk', "\"$namespaces[15]\">")." | <input type=\"$type\" name=\"ns100\" "
.ifelse($customnamespaces,$s,'')." value="
.ifelse($shw,'"1"> Custom ns', "\"".ifelse($customnamespaces,'1','0')."\">")." <input type=\"$type\" name=\"ns101\" "
.ifelse($customtalknamespaces,$s,'')." value="
.ifelse($shw,'"1"> Custom talk ns', "\"".ifelse($customtalknamespaces,'1','0')."\">");
echo "</span> ";
if ($showns == 'Off') {
echo " <input type=\"submit\" name=\"setnamespaces\" value=\"Show namespaces\" target=\"_self\">";
} else {
echo "<input type=\"submit\" name=\"setnamespaces\" value=\"Hide namespaces\" target=\"_self\">";
}
if ($newframe == 'Off') {
if($action=='search') {
echo " <a href=\"$searchurl\" target=\"_blanc\">open in new window</a> ";
}
echo " <input type=\"submit\" name=\"setframe\" value=\"New frame\" target=\"_self\">";
} else {
echo " <input type=\"submit\" name=\"setframe\" value=\"iFrame\" target=\"_self\">";
}
echo "</form></div> ";
if($action == 'search' AND $newframe == 'Off' ) {
echo "
<iframe src=\"$searchurl\" class=\"resultsFrame\" width=\"100%\" height=\"".ifelse($showns != 'Off', '85%', '95%')."\" name=\"results\">
<p>Your browser does not support frames. Please click the \"New frame\"-Button to open all searches in new window/tab. Followe <a href=\"$searchurl\" target=\"_blanc\">this link</a> to get to the selected WikiMedia search page.</p>
</iframe>";
} else {
}
}
echo "
</body>
</html>
";
?>