@@ -89,7 +89,7 @@ def __init__(self, config: Union[WtSiteConfig, WtSiteLegacyConfig]):
8989 scheme = "https"
9090
9191 if isinstance (config , WtSite .WtSiteLegacyConfig ):
92- self ._site = config .site
92+ self ._site : mwclient . Site = config .site
9393 else :
9494 cred = config .cred_mngr .get_credential (
9595 CredentialManager .CredentialConfig (
@@ -144,6 +144,11 @@ def __init__(self, config: Union[WtSiteConfig, WtSiteLegacyConfig]):
144144 self ._page_cache = {}
145145 self ._cache_enabled = False
146146
147+ @property
148+ def mw_site (self ) -> mwclient .client .Site :
149+ """Returns the mwclient.Site object of the WtSite instance"""
150+ return self ._site
151+
147152 @classmethod
148153 @deprecated ("Use contructor instead" )
149154 def from_domain (
@@ -1175,15 +1180,15 @@ def __init__(self, wtSite: WtSite = None, title: str = None, do_init: bool = Tru
11751180 def init (self ):
11761181 """Initializes the page by loading the content and meta data from the site"""
11771182 # inits the mwclient object - triggers an API call
1178- self ._page = self .wtSite ._site .pages [self .title ]
1183+ self ._page = self .wtSite .mw_site .pages [self .title ]
11791184 self .exists = self ._page .exists
11801185
11811186 if self .exists :
11821187 self ._original_content = self ._page .text ()
11831188 self ._content = self ._original_content
11841189 # multi content revisions
11851190 # second API call - ToDo: combine / replace with first call
1186- rev = self .wtSite ._site .api (
1191+ rev = self .wtSite .mw_site .api (
11871192 "query" ,
11881193 prop = "revisions" ,
11891194 titles = self .title ,
@@ -1381,7 +1386,7 @@ def get_url(self) -> str:
13811386 -------
13821387 the URL of the page
13831388 """
1384- return "https://" + self .wtSite ._site .host + "/wiki/" + self .title
1389+ return "https://" + self .wtSite .mw_site .host + "/wiki/" + self .title
13851390
13861391 def is_file_page (self ) -> bool :
13871392 """Checks if this page is a file page (containing an image, pdf, etc.)
@@ -1557,9 +1562,9 @@ def _edit(self, comment: str = None, mode="action-multislot"):
15571562 params ["slot_" + slot_key ] = content
15581563 if changed :
15591564 self .changed = True
1560- self .wtSite ._site .api (
1565+ self .wtSite .mw_site .api (
15611566 "editslots" ,
1562- token = self .wtSite ._site .get_token ("csrf" ),
1567+ token = self .wtSite .mw_site .get_token ("csrf" ),
15631568 title = self .title ,
15641569 summary = comment ,
15651570 ** params ,
@@ -1574,9 +1579,9 @@ def _edit(self, comment: str = None, mode="action-multislot"):
15741579 content = self ._slots [slot_key ]
15751580 if self ._content_model [slot_key ] == "json" :
15761581 content = json .dumps (content , ensure_ascii = False )
1577- self .wtSite ._site .api (
1582+ self .wtSite .mw_site .api (
15781583 "editslot" ,
1579- token = self .wtSite ._site .get_token ("csrf" ),
1584+ token = self .wtSite .mw_site .get_token ("csrf" ),
15801585 title = self .title ,
15811586 slot = slot_key ,
15821587 text = content ,
@@ -1655,7 +1660,7 @@ class Config:
16551660
16561661 def copy (self , config : CopyPageConfig ) -> PageCopyResult :
16571662 if config .comment is None :
1658- config .comment = f"[bot edit] Copied from { config .source_site ._site .host } "
1663+ config .comment = f"[bot edit] Copied from { config .source_site .mw_site .host } "
16591664 result = config .source_site .get_page_content ([config .existing_page ])
16601665 for title , slot_contents in result .contents .items ():
16611666 self .title = title
@@ -1685,10 +1690,14 @@ def copy(self, config: CopyPageConfig) -> PageCopyResult:
16851690 )
16861691 self .set_slot_content (slot_key = slot , content = slot_contents [slot ])
16871692 self .edit (comment = config .comment )
1688- s2p = f"Page { verb } : 'https://{ self .wtSite ._site .host } /wiki/{ self .title } '."
1693+ s2p = (
1694+ f"Page { verb } : "
1695+ f"'https://{ self .wtSite .mw_site .host } /wiki/{ self .title } '."
1696+ )
16891697 if verb == "updated" :
16901698 s2p = (
1691- f"Page { verb } : 'https://{ self .wtSite ._site .host } /w/index.php?title"
1699+ f"Page { verb } : "
1700+ f"'https://{ self .wtSite .mw_site .host } /w/index.php?title"
16921701 f"={ self .title } &action=history'."
16931702 )
16941703 print (s2p )
@@ -1800,7 +1809,7 @@ def dump_slot_content(slot_key_, content_type_, content_):
18001809 dump_slot_content (slot_key , content_type , content )
18011810
18021811 if self .is_file_page ():
1803- file = self .wtSite ._site .images [self .title .split (":" )[- 1 ]]
1812+ file = self .wtSite .mw_site .images [self .title .split (":" )[- 1 ]]
18041813 file_name = f"{ page_name } "
18051814 file_path = os .path .join (tar_dir , * file_name .split ("/" )) # handle subpages
18061815 # The following will return KeyError "url" if the file is not found
@@ -1826,7 +1835,7 @@ def get_file_info_and_usage(
18261835 and 'usage'.
18271836 """
18281837 return wt .get_file_info_and_usage (
1829- site = self .wtSite ._site ,
1838+ site = self .wtSite .mw_site ,
18301839 title = wt .SearchParam (query = self .title , debug = debug ),
18311840 )[0 ]
18321841
@@ -1913,25 +1922,25 @@ def export_xml(self, config: Optional[ExportConfig] = None) -> ExportResult:
19131922 if config is None :
19141923 config = WtPage .ExportConfig ()
19151924 url = (
1916- self .wtSite ._site .scheme
1925+ self .wtSite .mw_site .scheme
19171926 + "://"
1918- + self .wtSite ._site .host
1919- + self .wtSite ._site .path
1927+ + self .wtSite .mw_site .host
1928+ + self .wtSite .mw_site .path
19201929 + "index.php?title=Special:Export/"
19211930 + self .title
19221931 )
19231932 data = {
19241933 "title" : "Special:Export" ,
19251934 "catname" : "" ,
19261935 "pages" : self .title ,
1927- "wpEditToken" : self .wtSite ._site .get_token ("csrf" ),
1936+ "wpEditToken" : self .wtSite .mw_site .get_token ("csrf" ),
19281937 "wpDownload" : "1" ,
19291938 }
19301939 if not config .full_history :
19311940 data ["curonly" ] = "1"
19321941 if config .include_templates :
19331942 data ["templates" ] = "1"
1934- response = self .wtSite ._site .connection .post (url , data = data )
1943+ response = self .wtSite .mw_site .connection .post (url , data = data )
19351944 if response .status_code != 200 :
19361945 return WtPage .ExportResult (success = False , xml = "" )
19371946 else :
@@ -2008,17 +2017,17 @@ def import_xml(self, config: ImportConfig) -> ImportResult:
20082017 )
20092018
20102019 api_url = (
2011- self .wtSite ._site .scheme
2020+ self .wtSite .mw_site .scheme
20122021 + "://"
2013- + self .wtSite ._site .host
2014- + self .wtSite ._site .path
2022+ + self .wtSite .mw_site .host
2023+ + self .wtSite .mw_site .path
20152024 + "api.php"
20162025 )
2017- response = self .wtSite ._site .connection .post (
2026+ response = self .wtSite .mw_site .connection .post (
20182027 url = api_url ,
20192028 data = {
20202029 "action" : "import" ,
2021- "token" : self .wtSite ._site .get_token ("csrf" ),
2030+ "token" : self .wtSite .mw_site .get_token ("csrf" ),
20222031 "fullhistory" : "1" if config .full_history else "0" ,
20232032 "templates" : "1" if config .include_templates else "0" ,
20242033 "assignknownusers" : "1" ,
0 commit comments