diff --git a/engines/special/wikipedia.php b/engines/special/wikipedia.php
@@ -1,13 +1,15 @@
<?php
class WikipediaRequest extends EngineRequest {
public function get_request_url() {
- $this->wikipedia_language = $this->opts->language;
+ $this->wikipedia_domain = "wikipedia.org";
$query_encoded = urlencode($this->query);
- if (!in_array($this->wikipedia_language, json_decode(file_get_contents("static/misc/wikipedia_langs.json"), true)))
- $this->wikipedia_language = "en";
+ $languages = json_decode(file_get_contents("static/misc/languages.json"), true);
- return "https://$this->wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
+ if (array_key_exists($this->opts->language, $languages))
+ $this->wikipedia_domain = $languages[$this->opts->language]["wikipedia"] . ".wikipedia.org";
+
+ return "https://$this->wikipedia_domain/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
}
public function parse_results($response) {
@@ -20,7 +22,7 @@
$description = substr($first_page["extract"], 0, 250) . "...";
- $source = "https://$this->wikipedia_language.wikipedia.org/wiki/$this->query";
+ $source = "https://$this->wikipedia_domain/wiki/$this->query";
$response = array(
"special_response" => array(
"response" => htmlspecialchars($description),
diff --git a/settings.php b/settings.php
@@ -1,6 +1,5 @@
<?php
require "misc/search_engine.php";
- $opts = load_opts();
// Reset all cookies when resetting, or before saving new cookies
if (isset($_REQUEST["reset"]) || isset($_REQUEST["save"])) {
@@ -29,6 +28,8 @@
die();
}
+ $opts = load_opts();
+
require "misc/header.php";
?>
@@ -59,7 +60,7 @@
<option value=\"ubuntu\">Ubuntu</option>
<option value=\"tokyo_night\">Tokyo night</option>";
- if (isset($_COOKIE["theme"])) {
+ if (isset($opts->theme)) {
$theme = $opts->theme;
$themes = str_replace($theme . "\"", $theme . "\" selected", $themes);
}
@@ -97,10 +98,22 @@
<div class="settings-textbox-container">
<div>
<span>Language</span>
+ <select name="language">
<?php
- // TODO make this a dropdown
- echo "<input type=\"text\" name=\"language\" placeholder=\"any\" value=\"" . htmlspecialchars($opts->language ?? "") . "\">";
+
+ $languages = json_decode(file_get_contents("static/misc/languages.json"), true);
+ $options = "";
+
+ $options .= "<option value=\"\" " . (!isset($opts->language) ? "selected" : "") . ">Any</option>";
+
+ foreach ($languages as $lang_code => $language) {
+ $name = $language["name"];
+ $selected = $opts->language == $lang_code ? "selected" : "";
+ $options .= "<option value=\"$lang_code\" $selected>$name</option>";
+ }
+ echo $options;
?>
+ </select>
</div>
<div>
<label>Number of results per page</label>
diff --git a/static/misc/languages.json b/static/misc/languages.json
@@ -0,0 +1 @@
+{"af": {"name": "Afrikaans", "wikipedia": "af"}, "ak": {"name": "Akan", "wikipedia": "ak"}, "sq": {"name": "Albanian", "wikipedia": "sq"}, "ws": {"name": "Samoa", "wikipedia": "ws"}, "am": {"name": "Amharic", "wikipedia": "am"}, "ar": {"name": "Arabic", "wikipedia": "ar"}, "hy": {"name": "Armenian", "wikipedia": "hy"}, "az": {"name": "Azerbaijani", "wikipedia": "az"}, "eu": {"name": "Basque", "wikipedia": "eu"}, "be": {"name": "Belarusian", "wikipedia": "be"}, "bem": {"name": "Bemba", "wikipedia": ""}, "bn": {"name": "Bengali", "wikipedia": "bn"}, "bh": {"name": "Bihari", "wikipedia": "bh"}, "xx-bork": {"name": "Bork, bork, bork!", "wikipedia": ""}, "bs": {"name": "Bosnian", "wikipedia": "bs"}, "br": {"name": "Breton", "wikipedia": "br"}, "bg": {"name": "Bulgarian", "wikipedia": "bg"}, "bt": {"name": "Bhutanese", "wikipedia": ""}, "km": {"name": "Cambodian", "wikipedia": ""}, "ca": {"name": "Catalan", "wikipedia": "ca"}, "chr": {"name": "Cherokee", "wikipedia": "chr"}, "ny": {"name": "Chichewa", "wikipedia": "ny"}, "zh-cn": {"name": "Chinese (Simplified)", "wikipedia": "zh"}, "zh-tw": {"name": "Chinese (Traditional)", "wikipedia": "zh-classical"}, "co": {"name": "Corsican", "wikipedia": "co"}, "hr": {"name": "Croatian", "wikipedia": "hr"}, "cs": {"name": "Czech", "wikipedia": "cs"}, "da": {"name": "Danish", "wikipedia": "da"}, "nl": {"name": "Dutch", "wikipedia": "nl"}, "xx-elmer": {"name": "Elmer Fudd", "wikipedia": ""}, "en": {"name": "English", "wikipedia": "en"}, "eo": {"name": "Esperanto", "wikipedia": "eo"}, "et": {"name": "Estonian", "wikipedia": "et"}, "ee": {"name": "Ewe", "wikipedia": "ee"}, "fo": {"name": "Faroese", "wikipedia": "fo"}, "tl": {"name": "Filipino", "wikipedia": "tl"}, "fi": {"name": "Finnish", "wikipedia": "fi"}, "fr": {"name": "French", "wikipedia": "fr"}, "fy": {"name": "Frisian", "wikipedia": "fy"}, "gaa": {"name": "Ga", "wikipedia": ""}, "gl": {"name": "Galician", "wikipedia": "gl"}, "ka": {"name": "Georgian", "wikipedia": "ka"}, "de": {"name": "German", "wikipedia": "de"}, "el": {"name": "Greek", "wikipedia": "el"}, "kl": {"name": "Greenlandic", "wikipedia": "kl"}, "gn": {"name": "Guarani", "wikipedia": "gn"}, "gu": {"name": "Gujarati", "wikipedia": "gu"}, "xx-hacker": {"name": "Hacker", "wikipedia": ""}, "ht": {"name": "Haitian Creole", "wikipedia": "ht"}, "ha": {"name": "Hausa", "wikipedia": "ha"}, "haw": {"name": "Hawaiian", "wikipedia": "haw"}, "iw": {"name": "Hebrew", "wikipedia": "he"}, "hi": {"name": "Hindi", "wikipedia": "hi"}, "hu": {"name": "Hungarian", "wikipedia": "hu"}, "is": {"name": "Icelandic", "wikipedia": "is"}, "ig": {"name": "Igbo", "wikipedia": "ig"}, "id": {"name": "Indonesian", "wikipedia": "id"}, "ia": {"name": "Interlingua", "wikipedia": "ia"}, "ga": {"name": "Irish", "wikipedia": "ga"}, "it": {"name": "Italian", "wikipedia": "it"}, "ja": {"name": "Japanese", "wikipedia": "ja"}, "jw": {"name": "Javanese", "wikipedia": "jv"}, "kn": {"name": "Kannada", "wikipedia": "kn"}, "kk": {"name": "Kazakh", "wikipedia": "kk"}, "rw": {"name": "Kinyarwanda", "wikipedia": "rw"}, "rn": {"name": "Kirundi", "wikipedia": "rn"}, "xx-klingon": {"name": "Klingon", "wikipedia": "tlh"}, "kg": {"name": "Kongo", "wikipedia": "kg"}, "ko": {"name": "Korean", "wikipedia": "ko"}, "kri": {"name": "Krio (Sierra Leone)", "wikipedia": ""}, "ku": {"name": "Kurdish", "wikipedia": "ku"}, "ckb": {"name": "Kurdish (Soran\u00ee)", "wikipedia": "ckb"}, "ky": {"name": "Kyrgyz", "wikipedia": "ky"}, "lo": {"name": "Laothian", "wikipedia": "lo"}, "la": {"name": "Latin", "wikipedia": "la"}, "lv": {"name": "Latvian", "wikipedia": "lv"}, "ln": {"name": "Lingala", "wikipedia": "ln"}, "lt": {"name": "Lithuanian", "wikipedia": "lt"}, "loz": {"name": "Lozi", "wikipedia": ""}, "lg": {"name": "Luganda", "wikipedia": "lg"}, "ach": {"name": "Luo", "wikipedia": ""}, "mk": {"name": "Macedonian", "wikipedia": "mk"}, "mg": {"name": "Malagasy", "wikipedia": "mg"}, "my": {"name": "Malay", "wikipedia": "ms"}, "ml": {"name": "Malayalam", "wikipedia": "ml"}, "mt": {"name": "Maltese", "wikipedia": "mt"}, "mv": {"name": "Maldives", "wikipedia": "dv"}, "mi": {"name": "Maori", "wikipedia": "mi"}, "mr": {"name": "Marathi", "wikipedia": "mr"}, "mfe": {"name": "Mauritian Creole", "wikipedia": ""}, "mo": {"name": "Moldavian", "wikipedia": "ro"}, "mn": {"name": "Mongolian", "wikipedia": "mn"}, "sr-me": {"name": "Montenegrin", "wikipedia": "sr"}, "ne": {"name": "Nepali", "wikipedia": "ne"}, "pcm": {"name": "Nigerian Pidgin", "wikipedia": "pcm"}, "nso": {"name": "Northern Sotho", "wikipedia": "nso"}, "no": {"name": "Norwegian", "wikipedia": "no"}, "nn": {"name": "Norwegian (Nynorsk)", "wikipedia": "nn"}, "oc": {"name": "Occitan", "wikipedia": "oc"}, "or": {"name": "Oriya", "wikipedia": ""}, "om": {"name": "Oromo", "wikipedia": "om"}, "ps": {"name": "Pashto", "wikipedia": "ps"}, "fa": {"name": "Persian", "wikipedia": "fa"}, "xx-pirate": {"name": "Pirate", "wikipedia": ""}, "pl": {"name": "Polish", "wikipedia": "pl"}, "pt": {"name": "Portuguese", "wikipedia": "pt"}, "pt-br": {"name": "Portuguese (Brazil)", "wikipedia": "pt"}, "pt-pt": {"name": "Portuguese (Portugal)", "wikipedia": "pt"}, "pa": {"name": "Punjabi", "wikipedia": "pa"}, "qu": {"name": "Quechua", "wikipedia": "qu"}, "ro": {"name": "Romanian", "wikipedia": "ro"}, "rm": {"name": "Romansh", "wikipedia": "rm"}, "nyn": {"name": "Runyakitara", "wikipedia": ""}, "ru": {"name": "Russian", "wikipedia": "ru"}, "gd": {"name": "Scots Gaelic", "wikipedia": "gd"}, "sr": {"name": "Serbian", "wikipedia": "sr"}, "sh": {"name": "Serbo-Croatian", "wikipedia": "sh"}, "st": {"name": "Sesotho", "wikipedia": "st"}, "tn": {"name": "Setswana", "wikipedia": "tn"}, "crs": {"name": "Seychellois Creole", "wikipedia": ""}, "sn": {"name": "Shona", "wikipedia": "sn"}, "sd": {"name": "Sindhi", "wikipedia": "sd"}, "si": {"name": "Sinhalese", "wikipedia": "si"}, "sk": {"name": "Slovak", "wikipedia": "sk"}, "sl": {"name": "Slovenian", "wikipedia": "sl"}, "so": {"name": "Somali", "wikipedia": "so"}, "es": {"name": "Spanish", "wikipedia": "es"}, "es-419": {"name": "Spanish (Latin American)", "wikipedia": "es"}, "su": {"name": "Sundanese", "wikipedia": "su"}, "sw": {"name": "Swahili", "wikipedia": "sw"}, "sv": {"name": "Swedish", "wikipedia": "sv"}, "tg": {"name": "Tajik", "wikipedia": "tg"}, "ta": {"name": "Tamil", "wikipedia": "ta"}, "tt": {"name": "Tatar", "wikipedia": "tt"}, "te": {"name": "Telugu", "wikipedia": "te"}, "th": {"name": "Thai", "wikipedia": "th"}, "ti": {"name": "Tigrinya", "wikipedia": "ti"}, "to": {"name": "Tonga", "wikipedia": "to"}, "lua": {"name": "Tshiluba", "wikipedia": ""}, "tum": {"name": "Tumbuka", "wikipedia": "tum"}, "tr": {"name": "Turkish", "wikipedia": "tr"}, "tk": {"name": "Turkmen", "wikipedia": "tk"}, "tw": {"name": "Twi", "wikipedia": "tw"}, "ug": {"name": "Uighur", "wikipedia": "ug"}, "uk": {"name": "Ukrainian", "wikipedia": "uk"}, "ur": {"name": "Urdu", "wikipedia": "ur"}, "uz": {"name": "Uzbek", "wikipedia": "uz"}, "vu": {"name": "Vanuatu", "wikipedia": ""}, "vi": {"name": "Vietnamese", "wikipedia": "vi"}, "cy": {"name": "Welsh", "wikipedia": "cy"}, "wo": {"name": "Wolof", "wikipedia": "wo"}, "xh": {"name": "Xhosa", "wikipedia": "xh"}, "yi": {"name": "Yiddish", "wikipedia": "yi"}, "yo": {"name": "Yoruba", "wikipedia": "yo"}, "zu": {"name": "Zulu", "wikipedia": "zu"}}
diff --git a/static/misc/wikipedia_langs.json b/static/misc/wikipedia_langs.json
@@ -1 +0,0 @@
-["ab","ace","ady","af","ak","als","am","an","ang","ar","arc","ary","arz","as","ast","atj","av","avk","awa","ay","az","azb","ba","ban","bar","bat-smg","bcl","be","be-tarask","bg","bh","bi","bjn","bm","bn","bo","bpy","br","bs","bug","bxr","ca","cbk-zam","cdo","ce","ceb","ch","chr","chy","ckb","co","cr","crh","cs","csb","cu","cv","cy","da","de","din","diq","dsb","dty","dv","dz","ee","el","eml","en","eo","es","et","eu","ext","fa","ff","fi","fiu-vro","fj","fo","fr","frp","frr","fur","fy","ga","gag","gan","gcr","gd","gl","glk","gn","gom","gor","got","gu","gv","ha","hak","haw","he","hi","hif","hr","hsb","ht","hu","hy","hyw","ia","id","ie","ig","ik","ilo","inh","io","is","it","iu","ja","jam","jbo","jv","ka","kaa","kab","kbd","kbp","kg","ki","kk","kl","km","kn","ko","koi","krc","ks","ksh","ku","kv","kw","ky","la","lad","lb","lbe","lez","lfn","lg","li","lij","lld","lmo","ln","lo","lt","ltg","lv","mad","mai","map-bms","mdf","mg","mhr","mi","min","mk","ml","mn","mnw","mr","mrj","ms","mt","mwl","my","myv","mzn","na","nah","nap","nds","nds-nl","ne","new","nia","nl","nn","no","nostalgia","nov","nqo","nrm","nso","nv","ny","oc","olo","om","or","os","pa","pag","pam","pap","pcd","pdc","pfl","pi","pih","pl","pms","pnb","pnt","ps","pt","qu","rm","rmy","rn","ro","roa-rup","roa-tara","ru","rue","rw","sa","sah","sat","sc","scn","sco","sd","se","sg","sh","shn","si","simple","sk","skr","sl","sm","smn","sn","so","sq","sr","srn","ss","st","stq","su","sv","sw","szl","szy","ta","tcy","te","tet","tg","th","ti","tk","tl","tn","to","tpi","tr","ts","tt","tum","tw","ty","tyv","udm","ug","uk","ur","uz","ve","vec","vep","vi","vls","vo","wa","war","wo","wuu","xal","xh","xmf","yi","yo","za","zea","zh","zh-classical","zh-min-nan","zh-yue","zu","zh-hans","zh-hant","zh-cn","zh-hk","zh-mo","zh-my","zh-sg","zh-tw"]
| | | |