
    i                         U d Z ddlmZ ddlmZmZ ddlmZ dddddd	d
ZdgZdZ	dZ
dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZeed<   	 dZ	 d Zd Zy)a  The MediaWiki engine is a *generic* engine to **query** Wikimedia wikis by
the `MediaWiki Action API`_.  For a `query action`_ all Wikimedia wikis have
endpoints that follow this pattern::

    https://{base_url}/w/api.php?action=query&list=search&format=json

.. note::

   In its actual state, this engine is implemented to parse JSON result
   (`format=json`_) from a search query (`list=search`_).  If you need other
   ``action`` and ``list`` types ask SearXNG developers to extend the
   implementation according to your needs.

.. _MediaWiki Action API: https://www.mediawiki.org/wiki/API:Main_page
.. _query action: https://www.mediawiki.org/w/api.php?action=help&modules=query
.. _`list=search`: https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bsearch
.. _`format=json`: https://www.mediawiki.org/w/api.php?action=help&modules=json

Configuration
=============

Request:

- :py:obj:`base_url`
- :py:obj:`search_type`
- :py:obj:`srenablerewrites`
- :py:obj:`srsort`
- :py:obj:`srprop`

Implementations
===============

    )datetime)	urlencodequote)html_to_textNz=https://www.mediawiki.org/w/api.php?action=help&modules=queryTFJSON)websitewikidata_idofficial_api_documentationuse_official_apirequire_api_keyresultsgeneral   	nearmatchsearch_typesrenablerewrites	relevancesrsortz.sectiontitle|snippet|timestamp|categorysnippetsrpropz!https://{language}.wikipedia.org/base_urlz	w/api.phpapi_pathz%Y-%m-%dT%H:%M:%SZc           
      H   |d   dk(  rd|d<   n|d   j                  d      d   |d<   t        j                  d       dt         dj	                  |d         }|d	   d
z
  t
        z  }ddd| |t
        t        t        t        d	}t        rd|d<   |t        |      z   |d<   |S )Nlanguageallen-r   /?r   pageno   querysearchjson)	actionlistformatsrsearchsroffsetsrlimitsrwhatr   r   1r   url)splitr   rstripr   r'   number_of_resultsr   r   r   r   r   )r"   paramsapi_urloffsetargss        (/root/searxng/searx/engines/mediawiki.pyrequestr6   g   s     jU"!z#J/55c:1=z%&az3::F:DV:WGX"&77F $
D #& io-F5MM    c           	         g }| j                         }|j                  di       j                  d      sg S |d   d   D ]B  }|j                  dd      j                  d      r&|d   }|j                  d      }t        |j                  dd            }t        |j                  dd            }|j                  d	      }t        j                  | j                  d
         dz   t        |j                  dd      j                               z   }	|r7|	dt        |j                  dd      j                               z   z  }	|d|z   z  }|	|||d}
|rt        j                  |t              |
d<   |j                  |
       E |S )Nr"   r#   snippet z	#REDIRECTtitlesectiontitlecategorysnippet	timestampr   r   zwiki/ _#z / )r-   r;   contentmetadatapublishedDate)r$   get
startswithr   r   r'   search_paramsr   replaceencoder   strptimetimestamp_formatappend)respr   search_resultsresultr;   r<   rB   rC   r>   r-   items              r5   responserQ      s|   GYY[N gr*..x8	 )(3 ::i$//<wzz.1vzz)R89

+<b ABJJ{+	 OOT%7%7
%CODwNQVW\WdWdehjmWnWuWuWwQxx 	 3|33C=DDFGGGCU\))EUwHU$,$5$5iAQ$RD!t16 Nr7   )__doc__r   urllib.parser   r   searx.utilsr   about
categoriespagingr0   r   str__annotations__r   boolr   r   r   r   rK   r6   rQ    r7   r5   <module>r\      s    D  ) $ "a	 [
	 S   $    ? >
 4# 3 # 
 (  5>$r7   