Skip to content

Commit

Permalink
[mod] wikipedia engine: use wikiless instance
Browse files Browse the repository at this point in the history
Use wikiless instance wikiless.tiekoetter.com instead of wikipedia.org
Use the hostname replace toggle to enable / disable Wikiless.
  • Loading branch information
tiekoetter committed Jul 29, 2024
1 parent 14bb83b commit 361a380
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions searx/engines/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"""

import re
import urllib.parse
import babel

Expand Down Expand Up @@ -186,9 +187,17 @@ def response(resp):

_network.raise_for_httperror(resp)

from searx.preferences import hostname_replace_choice # pylint: disable=import-outside-toplevel

api_result = resp.json()
title = utils.html_to_text(api_result.get('titles', {}).get('display') or api_result.get('title'))
wikipedia_link = api_result['content_urls']['desktop']['page']
if hostname_replace_choice == "on":
wikipedia_link = (
re.sub(r'(.*\.)wikipedia\.org', 'https://wikiless.tiekoetter.com', wikipedia_link)
+ "?lang="
+ api_result['content_urls']['desktop']['page'][8:10]
)

if "list" in display_type or api_result.get('type') != 'standard':
# show item in the result list if 'list' is in the display options or it
Expand Down
9 changes: 9 additions & 0 deletions searx/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,17 @@ def parse_encoded_data(self, input_data: str):
dict_data[x] = y[0]
self.parse_dict(dict_data)

hostname_replace_choice = "off"

def parse_dict(self, input_data: Dict[str, str]):
"""parse preferences from request (``flask.request.form``)"""

global hostname_replace_choice # pylint: disable=global-variable-undefined
if 'hostname_replace' in ','.join(self.plugins.enabled):
hostname_replace_choice = "on"
else:
hostname_replace_choice = "off"

for user_setting_name, user_setting in input_data.items():
if user_setting_name in self.key_value_settings:
if self.key_value_settings[user_setting_name].locked:
Expand Down

0 comments on commit 361a380

Please sign in to comment.