1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.8.2.1'

This commit is contained in:
gnosygnu
2016-08-07 21:36:50 -04:00
parent b0fdf78a41
commit e4a2af026b
165 changed files with 2534 additions and 1247 deletions

View File

@@ -21,9 +21,9 @@ import gplx.xowa.wikis.data.*; import gplx.xowa.apps.apis.xowa.bldrs.imports.pag
public class Xoapi_import implements Gfo_invk {
public Xoapi_page_rank Page_rank() {return page_rank;} private final Xoapi_page_rank page_rank = new Xoapi_page_rank();
public long Layout_all_max() {return layout_all_max;} private long layout_all_max = 0; // disable by default; may set to 200 MB in future
public long Layout_text_max() {return layout_text_max;} private long layout_text_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
public long Layout_html_max() {return layout_html_max;} private long layout_html_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
public long Layout_file_max() {return layout_file_max;} private long layout_file_max = Io_size_.To_long_by_int_mb(1500); // 1.5 GB
public long Layout_text_max() {return layout_text_max;} private long layout_text_max = Io_size_.To_long_by_int_mb(1500); // 1.0 GB
public long Layout_html_max() {return layout_html_max;} private long layout_html_max = Io_size_.To_long_by_int_mb(1500); // 1.0 GB
public long Layout_file_max() {return layout_file_max;} private long layout_file_max = Io_size_.To_long_by_int_mb(1500); // 1.0 GB
public long Cat_link_db_max() {return cat_link_db_max;} private long cat_link_db_max = Io_size_.To_long_by_int_mb(1500); // 3.6 GB; v1
public long Text_db_max() {return text_db_max;} private long text_db_max = Io_size_.To_long_by_int_mb(1500); // 3.0 GB; v1
public long Html_db_max() {return html_db_max;} private long html_db_max = Io_size_.To_long_by_int_mb(1500); // 3.0 GB; v2; use same as text

View File

@@ -17,8 +17,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.apis.*; import gplx.xowa.apps.apis.xowa.*; import gplx.xowa.apps.apis.xowa.gui.*;
import gplx.gfui.*; import gplx.gfui.kits.core.*; import gplx.xowa.guis.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*;
import gplx.langs.htmls.encoders.*;
public class Xoapi_view implements Gfo_invk {
private Xoae_app app; private Xog_win_itm win;
private final Gfo_url_encoder fsys_encoder = Gfo_url_encoder_.New__fsys_wnt().Make();
public void Init_by_kit(Xoae_app app) {
this.app = app; this.win = app.Gui_mgr().Browser_win();
}
@@ -36,7 +38,7 @@ public class Xoapi_view implements Gfo_invk {
public void Save_as() {
if (this.Active_tab_is_null()) return;
Xog_tab_itm tab = win.Tab_mgr().Active_tab();
String file_name = gplx.langs.htmls.encoders.Gfo_url_encoder_.Fsys_wnt.Encode_str(String_.new_u8(tab.Page().Ttl().Full_url())) + ".html";
String file_name = fsys_encoder.Encode_str(String_.new_u8(tab.Page().Ttl().Full_url())) + ".html";
String file_url = app.Gui_mgr().Kit().New_dlg_file(Gfui_kit_.File_dlg_type_save, "Select file to save to:").Init_file_(file_name).Ask();
if (String_.Len_eq_0(file_url)) return;
Io_mgr.Instance.SaveFilStr(file_url, tab.Html_box().Text());

View File

@@ -26,6 +26,7 @@ public class Xow_url_parser {
private final Gfo_url_encoder encoder;
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
private final Gfo_url_parser url_parser = new Gfo_url_parser(); private final Gfo_url gfo_url = new Gfo_url();
private final Gfo_url_encoder gfs_encoder = Gfo_url_encoder_.New__gfs().Make();
private final Xoa_app app; private final Xow_wiki wiki; private final byte[] domain_bry;
private byte tmp_protocol_tid;
private int tmp_tid;
@@ -146,7 +147,7 @@ public class Xow_url_parser {
private void Bld_xowa() {
tmp_tid = Xoa_url_.Tid_xcmd;
tmp_page = Bry_.Mid(tmp_raw, Gfo_protocol_itm.Len_xcmd); // NOTE: just get String after protocol; anchor (#) or query params (?) must not be parsed
tmp_page = gplx.langs.htmls.encoders.Gfo_url_encoder_.Gfs.Decode(tmp_page); // NOTE: should be decoded; EX: %20 -> " "
tmp_page = gfs_encoder.Decode(tmp_page); // NOTE: should be decoded; EX: %20 -> " "
}
private void Bld_page_by_file_ns() {
tmp_tid = Xoa_url_.Tid_page;

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*;
import gplx.xowa.apps.wms.apis.origs.*;
public class Xowmf_api_mgr {
public Xoapi_orig_base Api_orig() {return api_orig;} public void Api_orig_(Xoapi_orig_base v) {api_orig = v;} private Xoapi_orig_base api_orig = new Xoapi_orig_wmf();
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
import gplx.core.ios.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.downloads.*;
public abstract class Xoapi_orig_base {
public boolean Api_query_size(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, Xow_repo_mgr repo_mgr, byte[] ttl, int width, int height) {
if (!gplx.core.ios.IoEngine_system.Web_access_enabled) return false; // don't check api if download disabled else "download_failed" messages in log (particularly during pkg_make) DATE:2015-02-12
Gfo_usr_dlg usr_dlg = Gfo_usr_dlg_.Instance;
Xof_repo_pair[] repos = repo_mgr.Repos_ary();
int len = repos.length;
for (int i = 0; i < len; i++) {
Xof_repo_pair repo_pair = repos[i];
if (Api_query_size_exec(rv, download_wkr, ttl, width, height, usr_dlg, repo_pair.Wiki_domain())) return true;
}
usr_dlg.Warn_many(Xoapi_orig_wmf.GRP_KEY, "download_failed", "download_failed: ~{0}", String_.new_u8(ttl));
return false;
}
public abstract boolean Api_query_size_exec(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, byte[] ttl, int width, int height, Gfo_usr_dlg usr_dlg, byte[] repo_wiki_key);
}

View File

@@ -0,0 +1,62 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
import org.junit.*;
// https://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=Main Page&rvprop=timestamp|content
public class Xoapi_orig_base_tst {
Xoapi_orig_base_fxt fxt = new Xoapi_orig_base_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Bld_api_url() {
fxt.Bld_api_url_tst("A.png" , 220, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220&iiurlheight=110");
fxt.Bld_api_url_tst("A.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png&iiurlwidth=220");
fxt.Bld_api_url_tst("A.png" , 0, 110, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A.png"); // assert that null width does not write height
fxt.Bld_api_url_tst("A b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A_b.png&iiurlwidth=220");
fxt.Bld_api_url_tst("A&b.png" , 220, 0, "https://en.wikipedia.org/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:A%26b.png&iiurlwidth=220");
}
@Test public void Parse_size() {
String raw = "<api><query><pages><page ns=\"6\" title=\"File:A.png\" missing=\"\" imagerepository=\"shared\"><imageinfo><ii size=\"1234\" width=\"220\" height=\"110\" /></imageinfo></page></pages></query></api>";
fxt.Parse_size_tst(raw, 220, 110);
}
@Test public void Parse_reg() {
String raw = "<api><query><pages><page ns=\"6\" title=\"File:A.png\" missing=\"\" imagerepository=\"shared\"><imageinfo><ii descriptionurl=\"http://commons.wikimedia.org/wiki/File:Berkheyde-Haarlem.png\" /></imageinfo></page></pages></query></api>";
fxt.Parse_reg_tst(raw, "commons.wikimedia.org", "Berkheyde-Haarlem.png");
}
}
class Xoapi_orig_base_fxt {
private Xoae_app app; private Xowe_wiki wiki; private Xoapi_orig_rslts rv = new Xoapi_orig_rslts();
public void Clear() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
}
public void Bld_api_url_tst(String ttl_str, int w, int h, String expd) {
String actl = Xoapi_orig_wmf.Bld_api_url(wiki.Domain_bry(), Bry_.new_u8(ttl_str), w, h);
Tfds.Eq(expd, actl);
}
public void Parse_size_tst(String xml_str, int expd_w, int expd_h) {
byte[] xml_bry = Bry_.new_u8(xml_str);
Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry);
Tfds.Eq(expd_w, rv.Orig_w());
Tfds.Eq(expd_h, rv.Orig_h());
}
public void Parse_reg_tst(String xml_str, String expd_wiki, String expd_page) {
byte[] xml_bry = Bry_.new_u8(xml_str);
Xoapi_orig_wmf.Parse_xml(rv, app.Usr_dlg(), xml_bry);
Tfds.Eq(expd_wiki, String_.new_u8(rv.Orig_wiki()));
Tfds.Eq(expd_page, String_.new_u8(rv.Orig_page()));
}
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
import gplx.xowa.files.downloads.*;
public class Xoapi_orig_mok extends Xoapi_orig_base {
private String wiki_str = "", ttl_str = "", redirect_str = ""; private int orig_w, orig_h; private boolean fail = false;
public Xoapi_orig_mok Ini(String wiki_str, String ttl_str, String redirect_str, int orig_w, int orig_h, boolean pass) {
this.wiki_str = wiki_str; this.ttl_str = ttl_str; this.redirect_str = redirect_str; this.orig_w = orig_w; this.orig_h = orig_h; this.fail = !pass;
return this;
}
public void Clear() {wiki_str = ttl_str = redirect_str = ""; orig_w = orig_h = 0;}
@Override public boolean Api_query_size_exec(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, byte[] ttl, int width, int height, Gfo_usr_dlg usr_dlg, byte[] repo_wiki_key) {
if (!Bry_.Eq(ttl, Bry_.new_u8(ttl_str))) return false;
if (!String_.Eq(wiki_str, String_.new_a7(repo_wiki_key))) return false;
if (fail) return false;
byte[] orig_page = String_.Eq(redirect_str, "") ? ttl : Bry_.new_u8(redirect_str);
rv.Init_all(repo_wiki_key, orig_page, orig_w, orig_h);
return true;
}
public static final Xoapi_orig_mok Instance = new Xoapi_orig_mok(); Xoapi_orig_mok() {}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
public class Xoapi_orig_rslts {
public byte[] Orig_wiki() {return orig_wiki;} private byte[] orig_wiki;
public byte[] Orig_page() {return orig_page;} private byte[] orig_page;
public int Orig_w() {return orig_w;} private int orig_w;
public int Orig_h() {return orig_h;} private int orig_h;
public void Init_all(byte[] wiki, byte[] page, int w, int h) {
this.orig_wiki = wiki; this.orig_page = page; this.orig_w = w; this.orig_h = h;
}
public void Clear() {
orig_wiki = orig_page = null;
orig_w = orig_h = 0;
}
}

View File

@@ -0,0 +1,96 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.origs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.envs.*;
import gplx.langs.htmls.encoders.*;
import gplx.xowa.files.downloads.*;
import gplx.xowa.htmls.hrefs.*;
public class Xoapi_orig_wmf extends Xoapi_orig_base {
@Override public boolean Api_query_size_exec(Xoapi_orig_rslts rv, Xof_download_wkr download_wkr, byte[] ttl, int width, int height, Gfo_usr_dlg usr_dlg, byte[] repo_wiki_key) {
if (Env_.Mode_testing()) return false; // TEST: disable during tests else scrib_lib_title will try to call WMF API; DATE:2015-03-20
String src = Bld_api_url(repo_wiki_key, ttl, width, height);
// xrg.Prog_fmt_hdr_(); // TOMBSTONE: do not uncomment; api will reuse whatever's in place
byte[] xml = download_wkr.Download_xrg().Exec_as_bry(src);
return xml == null ? false : Parse_xml(rv, usr_dlg, xml);
}
public static boolean Parse_xml(Xoapi_orig_rslts rv, Gfo_usr_dlg usr_dlg, byte[] xml) {
synchronized (tmp_rng) {
rv.Clear();
int xml_len = xml.length;
int pos = 0;
pos = Bry_find_.Find_fwd(xml, Bry_xml_ii , pos, xml_len);
if (pos == Bry_find_.Not_found) {usr_dlg.Log_many(GRP_KEY, "api_failed", "api failed: ~{0}", String_.new_u8(xml)); return false;}
pos += Bry_xml_ii.length;
byte[] orig_wiki = null, orig_page = null; int orig_w = 0, orig_h = 0;
if (Parse_xml_val(tmp_rng, usr_dlg, xml, xml_len, pos, Bry_xml_width))
orig_w = Bry_.To_int_or(xml, tmp_rng.Val_0(), tmp_rng.Val_1(), 0);
if (Parse_xml_val(tmp_rng, usr_dlg, xml, xml_len, pos, Bry_xml_height))
orig_h = Bry_.To_int_or(xml, tmp_rng.Val_0(), tmp_rng.Val_1(), 0);
if (Parse_xml_val(tmp_rng, usr_dlg, xml, xml_len, pos, Bry_xml_descriptionurl)) {
byte[] file_url = Bry_.Mid(xml, tmp_rng.Val_0(), tmp_rng.Val_1());
orig_wiki = gplx.xowa.wikis.xwikis.Xow_xwiki_mgr.Get_domain_from_url(url_parser, url, file_url);
byte[] page = Xoa_ttl.Replace_spaces(url.Segs__get_at_nth());
int colon_pos = Bry_find_.Find_fwd(page, Byte_ascii.Colon, 0, page.length);
if (colon_pos != Bry_find_.Not_found)
page = Bry_.Mid(page, colon_pos + 1, page.length);
orig_page = page;
}
rv.Init_all(orig_wiki, orig_page, orig_w, orig_h);
return true;
}
}
private static Int_2_ref tmp_rng = new Int_2_ref();
private static Gfo_url_parser url_parser = new Gfo_url_parser(); private static Gfo_url url = new Gfo_url();
private static boolean Parse_xml_val(Int_2_ref rv, Gfo_usr_dlg usr_dlg, byte[] xml, int xml_len, int pos, byte[] key) {
int bgn = 0, end = 0;
bgn = Bry_find_.Find_fwd(xml, key, pos, xml_len); if (bgn == Bry_find_.Not_found) return false;
bgn += key.length;
end = Bry_find_.Find_fwd(xml, Byte_ascii.Quote , bgn, xml_len); if (end == Bry_find_.Not_found) return false;
rv.Val_all_(bgn, end);
return true;
}
public static String Bld_api_url(byte[] wiki_key, byte[] ttl, int width, int height) {
synchronized (tmp_bfr) {
tmp_bfr.Add(Xoh_href_.Bry__https) // "https://"
.Add(wiki_key) // "commons.wikimedia.org"
.Add(Bry_api) // "/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&titles=File:"
.Add(tmp_encoder.Encode(ttl)) // "A%20B.png"
;
if (width > 0)
tmp_bfr.Add(Bry_width).Add_int_variable(width); // "&iiurlwidth=800"
if (height > 0 && width > 0) // NOTE: height cannot be used alone; width must also exist; "iiurlheight cannot be used without iiurlwidth"
tmp_bfr.Add(Bry_height).Add_int_variable(height); // "&iiurlheight=600"
return tmp_bfr.To_str_and_clear();
}
}
private static Gfo_url_encoder tmp_encoder = Gfo_url_encoder_.New__http_url().Init__diff__one(Byte_ascii.Space, Byte_ascii.Underline).Make();
private static final Bry_bfr tmp_bfr = Bry_bfr_.New();
private static final byte[]
Bry_api = Bry_.new_a7("/w/api.php?action=query&format=xml&prop=imageinfo&iiprop=size|url&redirects&titles=File:") // NOTE: using File b/c it should be canonical
, Bry_width = Bry_.new_a7("&iiurlwidth=")
, Bry_height = Bry_.new_a7("&iiurlheight=")
, Bry_xml_ii = Bry_.new_a7("<ii ")
, Bry_xml_width = Bry_.new_a7("width=\"")
, Bry_xml_height = Bry_.new_a7("height=\"")
, Bry_xml_descriptionurl = Bry_.new_a7("descriptionurl=\"")
;
public static final String GRP_KEY = "xowa.file.wmf.api";
}

View File

@@ -0,0 +1,98 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.revisions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
import gplx.langs.jsons.*;
import gplx.xowa.files.downloads.*;
public abstract class Xowm_revision_base {
}
class Xowm_revision_wmf extends Xowm_revision_base {
private final Bry_bfr bfr = Bry_bfr_.New();
private final Json_parser json_parser = new Json_parser();
public Xowm_revn_data Get_revn_or_null(Xof_download_wkr download_wkr, Xow_wiki wiki, Xoa_ttl page_ttl) {
if (!gplx.core.ios.IoEngine_system.Web_access_enabled) return null;
// create a ctx Object
return Get_revn_by_page(download_wkr, wiki.Domain_bry(), page_ttl.Full_db());
}
private Xowm_revn_data Get_revn_by_page(Xof_download_wkr download_wkr, byte[] wiki_domain, byte[] ttl_full_db) {
byte[] json = Download(bfr, download_wkr, wiki_domain, ttl_full_db);
Xowm_revn_data rv = Parse_json(wiki_domain, json);
// Parse_wtxt(rv, download_wkr, wiki_domain);
return rv;
}
public void Parse_wtxt(Xowe_wiki wiki, byte[] ttl_full_db, byte[] wtxt) {
// Xoae_page page = Xoae_page.New(wiki, wiki.Ttl_parse(ttl_full_db));
// page.Db().Text().Text_bry_(wtxt);
// page.Page_fetcher_(this);
// wiki.Parser_mgr().Parse(page, true);
}
private byte[] Download(Bry_bfr bfr, Xof_download_wkr download_wkr, byte[] wiki_domain, byte[] ttl_full_db) {
// build api; EX: "https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=ids|timestamp|content&titles=Main%20Page
Xowm_api_bldr.Bld_bgn(bfr, wiki_domain);
bfr.Add_str_a7("action=query&prop=revisions&rvprop=ids|timestamp|content&titles=");
bfr.Add(ttl_full_db);
// download bry
return download_wkr.Download_xrg().Exec_as_bry(bfr.To_str_and_clear());
}
private Xowm_revn_data Parse_json(byte[] wiki_domain, byte[] json) {
Json_doc jdoc = json_parser.Parse(json);
// get page_data; note that nde has key of page_id; EX: query:{pages:{1234:{}}}
Json_nde page_nde = (Json_nde)jdoc.Get_grp_many(Path__query, Path__pages); // /query/pages/
page_nde = page_nde.Get_as_nde(0); // {page_id}/
int page_id = page_nde.Get_as_int("pageid");
int page_ns = page_nde.Get_as_int("ns");
byte[] page_ttl = page_nde.Get_as_bry("title");
// get revn_data
Json_nde revn_nde = page_nde.Get_as_nde("revisions");
int revn_id = revn_nde.Get_as_int("revid");
DateAdp revn_time = revn_nde.Get_as_date_by_utc("timestamp");
byte[] revn_text = revn_nde.Get_as_bry("*");
return new Xowm_revn_data(wiki_domain, page_id, page_ns, page_ttl, revn_id, revn_time, revn_text);
}
private final byte[] Path__query = Bry_.new_a7("query"), Path__pages = Bry_.new_a7("pages");
}
/*
{
"batchcomplete": "",
"query": {
"pages": {
"15580374": {
"pageid": 15580374,
"ns": 0,
"title": "Main Page",
"revisions": [
{
"timestamp": "2015-12-26T10:03:53Z",
"contentformat": "text/x-wiki",
"contentmodel": "wikitext",
"*": "[[A]]"
}
]
}
}
}
*/
class Xowm_api_bldr {
public static void Bld_bgn(Bry_bfr bfr, byte[] wiki) {
bfr.Add_str_a7("https://");
bfr.Add(wiki);
bfr.Add_str_a7("/w/api.php?");
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.wms.apis.revisions; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*; import gplx.xowa.apps.wms.*; import gplx.xowa.apps.wms.apis.*;
public class Xowm_revn_data {
public Xowm_revn_data(byte[] wiki_domain
, int page_id, int page_ns, byte[] page_ttl
, int revn_id, DateAdp revn_time, byte[] revn_text) {
this.wiki_domain = wiki_domain;
this.page_id = page_id;
this.page_ns = page_ns;
this.page_ttl = page_ttl;
this.revn_id = revn_id;
this.revn_time = revn_time;
this.revn_text = revn_text;
}
public byte[] Wiki_domain() {return wiki_domain;} private final byte[] wiki_domain;
public int Page_id() {return page_id;} private final int page_id;
public int Page_ns() {return page_ns;} private final int page_ns;
public byte[] Page_ttl() {return page_ttl;} private final byte[] page_ttl;
public int Revn_id() {return revn_id;} private final int revn_id;
public DateAdp Revn_time() {return revn_time;} private final DateAdp revn_time;
public byte[] Revn_text() {return revn_text;} private final byte[] revn_text;
}