mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
v1.8.3.1
This commit is contained in:
parent
56128795f5
commit
df7fcf8eae
@ -32,7 +32,7 @@ public class Err extends RuntimeException {
|
||||
return rv;
|
||||
} @gplx.Internal protected Err() {}
|
||||
@gplx.Internal protected static Err exc_(Exception thrown, String hdr) {
|
||||
Err rv = hdr_(hdr);
|
||||
Err rv = hdr_(hdr + ":" + Err_.Message_lang(thrown)); // add a better error description; DATE:2014-08-15
|
||||
rv.inner = convert_(thrown);
|
||||
for (int i = 0; i < rv.inner.callStack.Count(); i++) {
|
||||
ErrProcData itm = (ErrProcData)rv.inner.callStack.FetchAt(i);
|
||||
|
@ -221,6 +221,10 @@ public class Bry_ {
|
||||
byte[] ary = Bry_.Mid(src, bgn, end);
|
||||
return String_.new_utf8_(ary);
|
||||
}
|
||||
public static byte[] Mid_safe(byte[] src, int bgn, int end) {
|
||||
try {return Mid(src, bgn, end);}
|
||||
catch (Exception e) {Err_.Noop(e); return Bry_.Add_w_dlm(Byte_ascii.Space, Bry_.XbyInt(bgn), Bry_.XbyInt(end));}
|
||||
}
|
||||
public static byte[] Mid(byte[] src, int bgn) {return Mid(src, bgn, src.length);}
|
||||
public static byte[] Mid_or(byte[] src, int bgn, int end, byte[] or) {
|
||||
int src_len = src.length;
|
||||
|
@ -136,7 +136,7 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
|
||||
private String Eval_script_as_str(String script) {return (String)Eval_script(script);}
|
||||
public Object Eval_script(String script) {
|
||||
eval_rslt.Clear();
|
||||
try {
|
||||
try {
|
||||
eval_rslt.Result_set(browser.evaluate(script));
|
||||
return eval_rslt.Result();
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
<classpathentry kind="src" path="src_162_xfer"/>
|
||||
<classpathentry kind="src" path="src_200_bldr"/>
|
||||
<classpathentry kind="src" path="src_210_bldr_core"/>
|
||||
<classpathentry kind="src" path="src_220_bldr_file"/>
|
||||
<classpathentry kind="src" path="src_240_install"/>
|
||||
<classpathentry kind="src" path="src_300_html"/>
|
||||
<classpathentry kind="src" path="src_310_url"/>
|
||||
|
@ -24,5 +24,6 @@ public class Html_atr_ {
|
||||
Id_bry = Bry_.new_ascii_("id")
|
||||
, Cls_bry = Bry_.new_ascii_("class")
|
||||
, Style_bry = Bry_.new_ascii_("style")
|
||||
, Href_bry = Bry_.new_ascii_("href")
|
||||
;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package gplx.html; import gplx.*;
|
||||
public class Html_tag_ {
|
||||
public static final byte[]
|
||||
Ul_name_bry = Bry_.new_ascii_("ul")
|
||||
, A_name_bry = Bry_.new_ascii_("a")
|
||||
;
|
||||
public static final byte[]
|
||||
Br_inl = Bry_.new_ascii_("<br/>")
|
||||
@ -27,6 +28,7 @@ public class Html_tag_ {
|
||||
, B_lhs = Bry_.new_ascii_("<b>") , B_rhs = Bry_.new_ascii_("</b>")
|
||||
, I_lhs = Bry_.new_ascii_("<i>") , I_rhs = Bry_.new_ascii_("</i>")
|
||||
, P_lhs = Bry_.new_ascii_("<p>") , P_rhs = Bry_.new_ascii_("</p>")
|
||||
, Div_lhs = Bry_.new_ascii_("<div>") , Div_rhs = Bry_.new_ascii_("</div>")
|
||||
, Html_rhs = Bry_.new_ascii_("</html>")
|
||||
, Head_lhs_bgn = Bry_.new_ascii_("<head")
|
||||
, Head_rhs = Bry_.new_ascii_("</head>")
|
||||
@ -36,9 +38,11 @@ public class Html_tag_ {
|
||||
, Script_lhs_w_type = Bry_.new_ascii_("<script type='text/javascript'>")
|
||||
, Script_rhs = Bry_.new_ascii_("</script>")
|
||||
;
|
||||
|
||||
public static final String
|
||||
Comm_bgn_str = "<!--"
|
||||
, Comm_end_str = "-->"
|
||||
Comm_bgn_str = "<!--"
|
||||
, Comm_end_str = "-->"
|
||||
, Anchor_str = "#"
|
||||
;
|
||||
public static final byte[]
|
||||
Comm_bgn = Bry_.new_ascii_(Comm_bgn_str), Comm_end = Bry_.new_ascii_(Comm_end_str)
|
||||
|
@ -23,7 +23,7 @@ public class Xoa_app_ {
|
||||
boot_mgr.Run(args);
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "1.8.2.1";
|
||||
public static final String Version = "1.8.3.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys;
|
||||
public static String User_agent = "";
|
||||
|
@ -16,7 +16,7 @@ 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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.gfui.*; import gplx.xowa.pages.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_find implements GfoInvkAble {
|
||||
private Xog_find_box find_box;
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
@ -62,7 +62,7 @@ class Xog_find_box {
|
||||
}
|
||||
public void Exec() {
|
||||
Xog_tab_itm tab = win.Tab_mgr().Active_tab(); if (tab == Xog_tab_itm_.Null) return;
|
||||
String elem_id = tab.View_mode() == Xog_page_mode.Tid_read
|
||||
String elem_id = tab.View_mode() == Xopg_view_mode.Tid_read
|
||||
? Gfui_html.Elem_id_body
|
||||
: Xog_html_itm.Elem_id__xowa_edit_data_box
|
||||
;
|
||||
|
@ -16,7 +16,7 @@ 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.apis.xowa.gui.browsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.gfui.*; import gplx.xowa.pages.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
public class Xoapi_html_box implements GfoInvkAble, GfoEvMgrOwner {
|
||||
private Xog_win_itm win;
|
||||
public Xoapi_html_box() {
|
||||
@ -29,7 +29,7 @@ public class Xoapi_html_box implements GfoInvkAble, GfoEvMgrOwner {
|
||||
Xog_tab_itm tab = win.Active_tab(); if (tab == Xog_tab_itm_.Null) return;
|
||||
Gfui_html html_box = tab.Html_itm().Html_box();
|
||||
html_box.Focus();
|
||||
if (tab.View_mode() != Xog_page_mode.Tid_read) // if edit / html, place focus in edit box
|
||||
if (tab.View_mode() != Xopg_view_mode.Tid_read) // if edit / html, place focus in edit box
|
||||
html_box.Html_elem_focus(Xog_html_itm.Elem_id__xowa_edit_data_box);
|
||||
}
|
||||
public void Selection_focus() {
|
||||
|
@ -16,21 +16,21 @@ 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.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
|
||||
public class Xoapi_edit implements GfoInvkAble {
|
||||
private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
win = app.Gui_mgr().Browser_win();
|
||||
}
|
||||
private boolean Active_tab_is_null() {return win.Tab_mgr().Active_tab_is_null();}
|
||||
private boolean Active_tab_is_edit() {return !win.Tab_mgr().Active_tab_is_null() && win.Tab_mgr().Active_tab().View_mode() == Xog_page_mode.Tid_edit;}
|
||||
private boolean Active_tab_is_edit() {return !win.Tab_mgr().Active_tab_is_null() && win.Tab_mgr().Active_tab().View_mode() == Xopg_view_mode.Tid_edit;}
|
||||
public void Copy() {if (Active_tab_is_null()) return; win.Kit().Clipboard().Copy(win.Active_html_itm().Html_selected_get_text_or_href());}
|
||||
public void Select_all() {if (Active_tab_is_null()) return; GfoInvkAble_.InvkCmd(win.Win_box().Kit().Clipboard(), gplx.gfui.Gfui_clipboard_.Invk_select_all);}
|
||||
public void Save() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), false);}
|
||||
public void Save_draft() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Save(win.Active_tab(), true);}
|
||||
public void Preview() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Preview(win.Active_tab());}
|
||||
public void Dbg_tmpl() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xog_page_mode.Tid_edit);}
|
||||
public void Dbg_html() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xog_page_mode.Tid_html);}
|
||||
public void Dbg_tmpl() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xopg_view_mode.Tid_edit);}
|
||||
public void Dbg_html() {if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Debug(win, Xopg_view_mode.Tid_html);}
|
||||
public void Focus_edit_box(){if (!Active_tab_is_edit()) return; Xog_tab_itm_edit_mgr.Focus(win, Xog_html_itm.Elem_id__xowa_edit_data_box);}
|
||||
public void Exec() {
|
||||
}
|
||||
|
@ -16,16 +16,16 @@ 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.apis.xowa.gui.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*; import gplx.xowa.apis.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
|
||||
public class Xoapi_view implements GfoInvkAble {
|
||||
private Xoa_app app; private Xog_win_itm win;
|
||||
public void Init_by_kit(Xoa_app app) {
|
||||
this.app = app; this.win = app.Gui_mgr().Browser_win();
|
||||
}
|
||||
private boolean Active_tab_is_null() {return win.Tab_mgr().Active_tab_is_null();}
|
||||
public void Mode_read() {Mode(Xog_page_mode.Tid_read);}
|
||||
public void Mode_edit() {Mode(Xog_page_mode.Tid_edit);}
|
||||
public void Mode_html() {Mode(Xog_page_mode.Tid_html);}
|
||||
public void Mode_read() {Mode(Xopg_view_mode.Tid_read);}
|
||||
public void Mode_edit() {Mode(Xopg_view_mode.Tid_edit);}
|
||||
public void Mode_html() {Mode(Xopg_view_mode.Tid_html);}
|
||||
private void Mode(byte v) {if (Active_tab_is_null()) return; win.Page__mode_(v);}
|
||||
public void Reload() {if (Active_tab_is_null()) return; win.Page__reload();}
|
||||
public void Refresh() {if (Active_tab_is_null()) return; win.Page__refresh();}
|
||||
|
@ -37,7 +37,7 @@ public class Db_mgr_fxt {
|
||||
Xodb_page_tbl tbl_page = wiki.Db_mgr_as_sql().Tbl_page();
|
||||
Db_stmt stmt = Db_stmt_.Null;
|
||||
try {
|
||||
stmt = tbl_page.Insert_stmt(wiki.Db_mgr_as_sql().Fsys_mgr().Page_provider());
|
||||
stmt = tbl_page.Insert_stmt(wiki.Db_mgr_as_sql().Fsys_mgr().Provider_page());
|
||||
int len = ttls.length;
|
||||
DateAdp modified_on = Tfds.Now_time0_add_min(0);
|
||||
for (int i = 0; i < len; i++) {
|
||||
@ -130,8 +130,8 @@ public class Db_mgr_fxt {
|
||||
Db_provider_pool._.Clear();
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_create_as_sql();
|
||||
db_mgr.Data_storage_format_(gplx.ios.Io_stream_.Tid_file);
|
||||
db_mgr.Init_make("");
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Core_provider();
|
||||
db_mgr.Init_by_ns_map("");
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Provider_core();
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_cfg"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_db"));
|
||||
provider.Exec_qry(Db_qry_delete.new_all_("xowa_ns"));
|
||||
@ -150,7 +150,7 @@ public class Db_mgr_fxt {
|
||||
Io_url url2 = Io_url_.mem_fil_("mem/xowa/bin/any/sql/xowa/xowa.sqlite3");
|
||||
Io_mgr._.SaveFilStr(url2, dsv_db);
|
||||
this.Wiki().Db_mgr_create_as_sql();// .("gplx_key=tdb;url=" + url.Raw());
|
||||
this.Wiki().Db_mgr_as_sql().Init_make("");
|
||||
this.Wiki().Db_mgr_as_sql().Init_by_ns_map("");
|
||||
}
|
||||
private static String dsv_db_() {
|
||||
String_bldr sb = String_bldr_.new_();
|
||||
|
@ -15,10 +15,10 @@ 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; import gplx.*;
|
||||
package gplx.xowa.bldrs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.ios.*; import gplx.xowa.bldrs.*;
|
||||
public class Xobc_base_fxt {
|
||||
public Xobc_base_fxt Clear() {
|
||||
public class Xob_base_fxt {
|
||||
public Xob_base_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
@ -29,7 +29,7 @@ public class Xobc_base_fxt {
|
||||
return this;
|
||||
}
|
||||
@gplx.Virtual public void Clear_hook() {}
|
||||
public Xobc_base_fxt Init_(Xob_bldr bldr, Xow_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;}
|
||||
public Xob_base_fxt Init_(Xob_bldr bldr, Xow_wiki wiki) {this.bldr = bldr; this.wiki = wiki; return this;}
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public Xob_bldr Bldr() {return bldr;} private Xob_bldr bldr;
|
||||
public Xow_wiki Wiki() {return wiki;} private Xow_wiki wiki;
|
||||
@ -37,14 +37,14 @@ public class Xobc_base_fxt {
|
||||
public Xodb_page page_(String ttl) {return page_(ttl, "");}
|
||||
public Xodb_page page_(String ttl, String text) {return new Xodb_page().Ttl_(Bry_.new_utf8_(ttl), wiki.Ns_mgr()).Text_(Bry_.new_utf8_(text));}
|
||||
public Io_fil_chkr meta_(String url, String data) {return new Io_fil_chkr(Io_url_.mem_fil_(url), data);}
|
||||
public void Init_fxts(Xob_bldr bldr, Xow_wiki wiki, Xobc_base_fxt... fxt_ary) {
|
||||
public void Init_fxts(Xob_bldr bldr, Xow_wiki wiki, Xob_base_fxt... fxt_ary) {
|
||||
int fxt_ary_len = fxt_ary.length;
|
||||
for (int i = 0; i < fxt_ary_len; i++)
|
||||
fxt_ary[i].Init_(bldr, wiki);
|
||||
}
|
||||
public Xobc_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Xobc_base_fxt Init_fil(Io_url url, String raw) {Io_mgr._.SaveFilStr(url, raw); return this;}
|
||||
public Xobc_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) {
|
||||
public Xob_base_fxt Init_fil(String url, String raw) {return Init_fil(Io_url_.new_fil_(url), raw);}
|
||||
public Xob_base_fxt Init_fil(Io_url url, String raw) {Io_mgr._.SaveFilStr(url, raw); return this;}
|
||||
public Xob_base_fxt Exec_cmd(String cmd_key, GfoMsg... msgs) {
|
||||
Xob_cmd cmd = (Xob_cmd)bldr.Cmd_mgr().Add_cmd(wiki, cmd_key);
|
||||
this.bldr_itm = cmd;
|
||||
int len = msgs.length;
|
||||
@ -56,8 +56,8 @@ public class Xobc_base_fxt {
|
||||
Run_cmd(bldr, cmd);
|
||||
return this;
|
||||
}
|
||||
public Xobc_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public Xobc_base_fxt Test_fil(Io_url url, String expd) {
|
||||
public Xob_base_fxt Test_fil(String url, String expd) {return Test_fil(Io_url_.new_fil_(url), expd);}
|
||||
public Xob_base_fxt Test_fil(Io_url url, String expd) {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr._.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
@ -75,13 +75,6 @@ public class Xob_cmd_mgr implements GfoInvkAble {
|
||||
else if (String_.Eq(cmd_key, Xobc_core_decompress_bz.KEY)) return Add(new Xobc_core_decompress_bz(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_deploy_zip.KEY)) return Add(new Xobc_deploy_zip(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_deploy_copy.KEY)) return Add(new Xobc_deploy_copy(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_parse_dump_templates.KEY)) return Xml_rdr_direct_add(wiki, new Xobc_parse_dump_templates(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_parse_run.KEY)) return Add(new Xobc_parse_run(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_dump_ttl.KEY)) return Xml_rdr_direct_add(wiki, new Xobc_img_dump_ttl(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_merge_ttl_sql.KEY)) return Add(new Xobc_img_merge_ttl_sql(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_prep_xfer.KEY)) return Add(new Xobc_img_prep_xfer(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_img_run_xfer.KEY)) return Add(new Xobc_img_run_xfer(bldr, wiki));
|
||||
else if (String_.Eq(cmd_key, Xobc_math_run.KEY)) return Add(new Xobc_math_run(bldr, wiki));
|
||||
else throw Err_.unhandled(cmd_key);
|
||||
}
|
||||
private Xobd_wkr Xml_rdr_direct_add(Xow_wiki wiki, Xobd_wkr wkr) {
|
||||
|
@ -71,30 +71,6 @@ public class Xob_fxt {
|
||||
Run(wkr);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_img(String expd) {
|
||||
Xobc_parse_run wkr = new Xobc_parse_run(bldr, wiki).Load_len_(Io_mgr.Len_kb);
|
||||
wkr.Tmpl_on_(true).Cmd_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xodb_page page = doc_ary[i];
|
||||
wkr.Parse_page(page);
|
||||
}
|
||||
wkr.Cmd_end();
|
||||
String actl = Io_mgr._.LoadFilStr(Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/tmp/img.dump_link/make/0000000000.csv"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Xob_fxt Run_math(String expd) {
|
||||
Xobc_parse_run wkr = new Xobc_parse_run(bldr, wiki).Load_len_(Io_mgr.Len_kb);
|
||||
wkr.Tmpl_on_(true).Cmd_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
Xodb_page page = doc_ary[i];
|
||||
wkr.Parse_page(page);
|
||||
}
|
||||
wkr.Cmd_end();
|
||||
String actl = Io_mgr._.LoadFilStr(Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/tmp/math.text/make/0000000000.csv"));
|
||||
Tfds.Eq_str_lines(expd, actl);
|
||||
return this;
|
||||
}
|
||||
private void Run_wkr(Xobd_wkr wkr) {
|
||||
wkr.Wkr_bgn(bldr);
|
||||
for (int i = 0; i < doc_ary.length; i++) {
|
||||
|
@ -16,7 +16,7 @@ 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.bldrs.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.oimgs.*; import gplx.fsdb.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.gui.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.parsers.logs.*;
|
||||
@ -47,7 +47,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_log
|
||||
}
|
||||
@Override protected void Cmd_bgn_end() {
|
||||
wiki_ns_file_is_case_match_all = Wiki_ns_for_file_is_case_match_all(wiki); // NOTE: must call after wiki.init
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xog_page_mode.Tid_read).Ctgs_enabled_(false); // disable categories else progress messages written (also for PERF)
|
||||
wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read).Ctgs_enabled_(false); // disable categories else progress messages written (also for PERF)
|
||||
commons_wiki = app.Wiki_mgr().Get_by_key_or_make(Xow_wiki_.Domain_commons_bry);
|
||||
Xop_log_mgr log_mgr = ctx.App().Log_mgr();
|
||||
log_mgr.Log_dir_(wiki.Fsys_mgr().Root_dir()); // put log in wiki dir, instead of user.temp
|
||||
@ -86,7 +86,7 @@ public class Xob_lnki_temp_wkr extends Xob_dump_mgr_base implements Xop_lnki_log
|
||||
parser.Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), page_src);
|
||||
if (gen_html) {
|
||||
page.Root_(root);
|
||||
wiki.Html_mgr().Page_wtr_mgr().Gen(ctx.Cur_page(), gplx.xowa.gui.Xog_page_mode.Tid_read);
|
||||
wiki.Html_mgr().Page_wtr_mgr().Gen(ctx.Cur_page(), Xopg_view_mode.Tid_read);
|
||||
}
|
||||
root.Clear();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.xowa.dbs.*; import gplx.xowa.bldrs.oimgs.*;
|
||||
class Xob_page_regy_tbl {
|
||||
public static void Reset_table(Db_provider p) {Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql);}
|
||||
public static void Create_data(Gfo_usr_dlg usr_dlg, Db_provider p, byte repo_tid, Xow_wiki wiki) {
|
||||
Create_data__insert_page(usr_dlg, p, repo_tid, wiki.Db_mgr_as_sql().Fsys_mgr().Get_url(Xodb_file_tid_.Tid_core));
|
||||
Create_data__insert_page(usr_dlg, p, repo_tid, wiki.Db_mgr_as_sql().Fsys_mgr().Get_url(Xodb_file_tid.Tid_core));
|
||||
Create_data__insert_redirect(usr_dlg, p, repo_tid, wiki.Fsys_mgr().Root_dir().GenSubFil(Xodb_db_file.Name__wiki_redirect));
|
||||
}
|
||||
public static void Delete_local(Db_provider p) {
|
||||
|
@ -27,7 +27,7 @@ public class Xob_cmd_exec_sql implements Xob_cmd {
|
||||
wiki.Init_assert(); // force load; needed to pick up MediaWiki ns for MediaWiki:mainpage
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Xodb_file file = fsys_mgr.Get_by_db_idx(file_idx);
|
||||
Xodb_file file = fsys_mgr.Get_by_idx(file_idx);
|
||||
app.Usr_dlg().Plog_many("", "", "exec_sql: running sql; file_idx=~{0} sql=~{1}", file_idx, sql);
|
||||
file.Provider().Exec_sql(sql);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class Xob_init_sql extends Xob_init_base {
|
||||
if (Xodb_mgr_sql.Find_core_url(wiki) != null) throw wiki.App().Bldr().Usr_dlg().Fail_many("", "", "directory must not contain any sqlite3 files: ~{0}", wiki.Fsys_mgr().Root_dir().Raw());
|
||||
String ns_map = wiki.App().Setup_mgr().Dump_mgr().Db_ns_map();
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_create_as_sql();
|
||||
db_mgr.Init_make(ns_map); // NOTE: must Init after Xob_siteinfo_parser b/c Xob_siteinfo_parser will create new ns itms
|
||||
db_mgr.Init_by_ns_map(ns_map); // NOTE: must Init after Xob_siteinfo_parser b/c Xob_siteinfo_parser will create new ns itms
|
||||
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "db_mgr.data_storage_format", Xoi_dump_mgr.Wtr_tid_to_str(db_mgr.Data_storage_format())); // NOTE: insert data_storage_format at init stage, not at term stage; bldr will reload wiki, and will default to gz since setting is not saved; DATE:2013-10-27
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
|
||||
db_mgr = wiki.Db_mgr_as_sql();
|
||||
db_mgr.Data_storage_format_(data_storage_format);
|
||||
fsys_mgr = db_mgr.Fsys_mgr();
|
||||
page_provider = fsys_mgr.Page_provider();
|
||||
page_provider = fsys_mgr.Provider_page();
|
||||
page_stmt = db_mgr.Tbl_page().Insert_stmt(page_provider);
|
||||
page_provider.Txn_mgr().Txn_bgn_if_none();
|
||||
text_stmts_mgr = new Xob_text_stmts_mgr(db_mgr, fsys_mgr);
|
||||
@ -79,12 +79,12 @@ public class Xob_page_sql extends Xob_itm_basic_base implements Xobd_wkr, GfoInv
|
||||
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
|
||||
db_mgr.Tbl_site_stats().Update(page_count_main, page_count_all, ns_mgr.Ns_file().Count()); // save page stats
|
||||
db_mgr.Tbl_xowa_ns().Insert(ns_mgr); // save ns
|
||||
db_mgr.Tbl_xowa_db().Commit_all(page_provider, db_mgr.Fsys_mgr().Ary()); // save dbs; note that dbs can be saved again later
|
||||
db_mgr.Tbl_xowa_db().Commit_all(page_provider, db_mgr.Fsys_mgr().Files_ary()); // save dbs; note that dbs can be saved again later
|
||||
db_mgr.Tbl_xowa_cfg().Insert_str(Xodb_mgr_sql.Grp_wiki_init, "props.modified_latest", modified_latest.XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
if (idx_mode.Tid_is_end()) Idx_create();
|
||||
}
|
||||
private void Idx_create() {
|
||||
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_text), Idx_page_title, Idx_page_random);
|
||||
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid.Tid_core, Xodb_file_tid.Tid_text), Idx_page_title, Idx_page_random);
|
||||
}
|
||||
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_txn_commit_interval_)) txn_commit_interval = m.ReadInt("v");
|
||||
@ -130,12 +130,12 @@ class Xob_text_stmts_mgr {
|
||||
Xodb_file File_get(int file_idx, int text_len) {
|
||||
if (file_idx == Xow_ns.Bldr_file_idx_heap) {
|
||||
file_idx = fsys_mgr.Tid_text_idx();
|
||||
Xodb_file file = fsys_mgr.Get_or_make(Xodb_file_tid_.Tid_text, file_idx);
|
||||
Xodb_file file = fsys_mgr.Get_or_make(Xodb_file_tid.Tid_text, file_idx);
|
||||
long file_len = file.File_len();
|
||||
long file_max = fsys_mgr.Tid_text_max();
|
||||
if (file_max != Xodb_fsys_mgr.Heap_max_infinite && (file_len + text_len > file_max)) { // file is "full"
|
||||
file.Provider().Txn_mgr().Txn_end_all(); // close txn
|
||||
file = fsys_mgr.Make(Xodb_file_tid_.Tid_text);
|
||||
file = fsys_mgr.Make(Xodb_file_tid.Tid_text);
|
||||
file_idx = file.Id();
|
||||
fsys_mgr.Tid_text_idx_(file_idx);
|
||||
}
|
||||
@ -143,7 +143,7 @@ class Xob_text_stmts_mgr {
|
||||
return file;
|
||||
}
|
||||
else
|
||||
return fsys_mgr.Get_or_make(Xodb_file_tid_.Tid_text, file_idx);
|
||||
return fsys_mgr.Get_or_make(Xodb_file_tid.Tid_text, file_idx);
|
||||
}
|
||||
private void Add(Db_stmt stmt, int stmt_idx) {
|
||||
int new_len = stmt_idx + 1;
|
||||
|
@ -59,7 +59,7 @@ public abstract class Xob_search_base extends Xob_itm_dump_base implements Xobd_
|
||||
if (delete_temp) Io_mgr._.DeleteDirDeep(temp_dir);
|
||||
if (wiki.Db_mgr().Tid() == Xodb_mgr_sql.Tid_sql) {
|
||||
Xodb_fsys_mgr db_fs = wiki.Db_mgr_as_sql().Fsys_mgr();
|
||||
wiki.Db_mgr_as_sql().Tbl_xowa_db().Commit_all(db_fs.Core_provider(), db_fs.Ary()); // always save files now; need to commit created search_db_idx to xowa_db, else will be reused by ctg v2; DATE:2014-02-07
|
||||
wiki.Db_mgr_as_sql().Tbl_xowa_db().Commit_all(db_fs.Provider_core(), db_fs.Files_ary()); // always save files now; need to commit created search_db_idx to xowa_db, else will be reused by ctg v2; DATE:2014-02-07
|
||||
}
|
||||
}
|
||||
public void Wkr_print() {}
|
||||
|
@ -30,12 +30,12 @@ public class Xob_search_sql_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
if (!Env_.Mode_testing()) wiki.Init_assert();
|
||||
Xodb_fsys_mgr db_fs = wiki.Db_mgr_as_sql().Fsys_mgr();
|
||||
usr_dlg.Log_many("", "", "search_title.cmd: getting core db");
|
||||
Xodb_file page_db = db_fs.Get_tid_root(Xodb_file_tid_.Tid_core);
|
||||
Xodb_file page_db = db_fs.Get_tid_root(Xodb_file_tid.Tid_core);
|
||||
usr_dlg.Log_many("", "", "search_title.cmd: getting existing searchdb");
|
||||
Xodb_file search_db = db_fs.Get_tid_root(Xodb_file_tid_.Tid_search);
|
||||
Xodb_file search_db = db_fs.Get_tid_root(Xodb_file_tid.Tid_search);
|
||||
if (search_db == null) {
|
||||
usr_dlg.Log_many("", "", "search_title.cmd: making new searchdb");
|
||||
search_db = db_fs.Make(Xodb_file_tid_.Tid_search);
|
||||
search_db = db_fs.Make(Xodb_file_tid.Tid_search);
|
||||
}
|
||||
DataRdr page_rdr = DataRdr_.Null;
|
||||
Db_provider search_provider = search_db.Provider();
|
||||
@ -76,7 +76,7 @@ public class Xob_search_sql_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
search_provider.Txn_mgr().Txn_end_all_bgn_if_none();
|
||||
search_temp_tbl.Make_data(usr_dlg, search_provider);
|
||||
search_provider.Txn_mgr().Txn_bgn_if_none();
|
||||
wiki.Db_mgr_as_sql().Tbl_xowa_db().Commit_all(db_fs.Core_provider(), db_fs.Ary());
|
||||
wiki.Db_mgr_as_sql().Tbl_xowa_db().Commit_all(db_fs.Provider_core(), db_fs.Files_ary());
|
||||
search_provider.Txn_mgr().Txn_end_all();
|
||||
} private int commit_interval = 100000, progress_interval = 10000;
|
||||
private void Commit(Db_provider search_provider) {
|
||||
|
@ -25,9 +25,9 @@ public class Xob_search_sql_wkr extends Xob_search_base implements Io_make_cmd {
|
||||
public void Sort_bgn() {
|
||||
db_mgr = wiki.Db_mgr_as_sql();
|
||||
boolean created = false;
|
||||
Xodb_file search_db = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_search);
|
||||
Xodb_file search_db = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search);
|
||||
if (search_db == null) {
|
||||
search_db = db_mgr.Fsys_mgr().Make(Xodb_file_tid_.Tid_search);
|
||||
search_db = db_mgr.Fsys_mgr().Make(Xodb_file_tid.Tid_search);
|
||||
created = true;
|
||||
}
|
||||
provider = search_db.Provider();
|
||||
|
@ -146,43 +146,6 @@ public class Xobc_tst {
|
||||
.Run_ctg()
|
||||
;
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_wo_date_(2, "A", "[[File:X.png|thumb|220x110px]] [[Image:Y.png|upright=.80]]")
|
||||
, fxt.doc_wo_date_(3, "B", "[[File:X.png]] [[Image:Y.png|upright=.80]]")
|
||||
)
|
||||
.Run_img(String_.Concat_lines_nl
|
||||
( "X.png|0,-1,-1"
|
||||
, "X.png|8,220,110"
|
||||
, "Y.png|0,-1,-1,upright=0.8"
|
||||
, ""
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Img_chars() {
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_wo_date_(2, "A", "[[File:A + b.png]] [[File:A %3c b.png]] [[File:A 折 b.png]]")
|
||||
)
|
||||
.Run_img(String_.Concat_lines_nl
|
||||
( "A_+_b.png|0,-1,-1" // EX: ASLSJSW Aas+.PNG
|
||||
, "A_<_b.png|0,-1,-1" // EX: ANKAW%C3%9C-Burgunder-wei%C3%9F.jpg
|
||||
, "A_折_b.png|0,-1,-1" // EX: 折鶴 WUXGA.jpg
|
||||
, ""
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Math() {
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_wo_date_(2, "A", "<math>a</math>")
|
||||
, fxt.doc_wo_date_(3, "B", "<math>a</math> <math>b</math>")
|
||||
)
|
||||
.Run_math(String_.Concat_lines_nl
|
||||
( "a"
|
||||
, "b"
|
||||
, ""
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Tmpl_dump() {
|
||||
fxt.doc_ary_
|
||||
( fxt.doc_wo_date_(2, "Template:A", "a")
|
||||
@ -239,20 +202,3 @@ public class Xobc_tst {
|
||||
*/;
|
||||
}
|
||||
}
|
||||
class Xob_img_xfer_gen_fxt extends Xob_fxt { public Xob_img_xfer_gen_fxt Files_len(int v) {expd_files_len = v; return this;} private int expd_files_len;
|
||||
public Xob_img_xfer_gen_fxt Files_(Io_fil... v) {expd_files = v; return this;} Io_fil[] expd_files;
|
||||
public Xob_img_xfer_gen_fxt tst() {
|
||||
Xob_bldr bldr = this.Bldr();
|
||||
Xobc_img_prep_xfer wkr = new Xobc_img_prep_xfer(bldr, this.Wiki());
|
||||
wkr.Cmd_bgn(bldr);
|
||||
wkr.Cmd_run();
|
||||
wkr.Cmd_end();
|
||||
Io_url[] urls = wkr.Dump_url_gen().Prv_urls();
|
||||
Tfds.Eq(expd_files_len, urls.length);
|
||||
return this;
|
||||
}
|
||||
// public void Cmd_end() {
|
||||
// Io_url_gen make_url_gen = new Io_url_gen_md5(temp_dir.GenSubFil("make"));
|
||||
// Xobdc_merger.Basic(bldr.Status_mgr(), dump_url_gen, temp_dir.GenSubDir("sort"), sort_mem_len, Io_line_rdr_key_gen_.last_pipe, new Io_sort_fil_basic(bldr.Status_mgr(), make_url_gen, make_fil_len));
|
||||
// } int sort_mem_len = Int_.Neg1, make_fil_len = 100 * Io_mgr.Len_kb;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
|
||||
import org.junit.*;
|
||||
public class Uca_trie_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xobc_base_fxt fxt = new Xobc_base_fxt();
|
||||
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
|
||||
@Test public void Basic() {
|
||||
Uca_trie_fxt fxt = new Uca_trie_fxt();
|
||||
fxt.Clear();
|
||||
|
@ -29,7 +29,7 @@ public class Xob_category_registry_sql implements Xob_cmd {
|
||||
Xob_tmp_wtr rslt_wtr = Xob_tmp_wtr.new_wo_ns_(Io_url_gen_.dir_(rslt_dir), Io_mgr.Len_mb);
|
||||
|
||||
Xodb_mgr_sql db_mgr = Xodb_mgr_sql.Get_or_load(wiki);
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Core_provider();
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Provider_core();
|
||||
Db_qry_select qry = Db_qry_select.new_()
|
||||
.Cols_(Xodb_page_tbl.Fld_page_title, Xodb_page_tbl.Fld_page_id)
|
||||
.From_(Xodb_page_tbl.Tbl_name)
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
|
||||
import org.junit.*;
|
||||
public class Xob_categorylinks_base_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xobc_base_fxt fxt = new Xobc_base_fxt();
|
||||
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
|
||||
@Test public void Basic() {
|
||||
Io_url src_fil = Io_url_.new_fil_("mem/temp/sql_dump.sql");
|
||||
fxt .Init_fil(src_fil, String_.Concat
|
||||
|
@ -30,15 +30,15 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
|
||||
name_id_rdr = New_registry_rdr(wiki, usr_dlg);
|
||||
cur_cat_file_max = wiki.App().Setup_mgr().Dump_mgr().Db_categorylinks_max();
|
||||
|
||||
db_mgr.Delete_by_tid(Xodb_file_tid_.Tid_category);
|
||||
db_mgr.Delete_by_tid(Xodb_file_tid.Tid_category);
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Xodb_file category_file = fsys_mgr.Get_tid_root(Xodb_file_tid_.Tid_core);
|
||||
Xodb_file category_file = fsys_mgr.Get_tid_root(Xodb_file_tid.Tid_core);
|
||||
if (cur_cat_file_max > 0) {
|
||||
category_file = fsys_mgr.Make(Xodb_file_tid_.Tid_category);
|
||||
fsys_mgr.Init_by_tid_category(category_file);
|
||||
category_file = fsys_mgr.Make(Xodb_file_tid.Tid_category);
|
||||
fsys_mgr.Provider_ctg_(category_file);
|
||||
}
|
||||
|
||||
cat_provider = db_mgr.Fsys_mgr().Category_provider();
|
||||
cat_provider = db_mgr.Fsys_mgr().Provider_ctg();
|
||||
ctg_stmt = db_mgr.Tbl_category().Insert_stmt(cat_provider);
|
||||
File_open(category_file);
|
||||
first_provider = true;
|
||||
@ -70,7 +70,7 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Ctg_grp_end(Ttl_last);
|
||||
File_close();
|
||||
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Core_provider(), fsys_mgr.Ary());
|
||||
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), fsys_mgr.Files_ary());
|
||||
if (db_mgr.Category_version() == Xoa_ctg_mgr.Version_null) // NOTE: ctg_v1 wkr will set this to v1; only set to v2 if null
|
||||
db_mgr.Category_version_update(false);
|
||||
usr_dlg.Log_many("", "", "import.category.v2: insert done; committing; rows=~{0}", row_count);
|
||||
@ -82,13 +82,13 @@ public class Xob_categorylinks_sql_make implements Io_make_cmd {
|
||||
Io_mgr._.DeleteFil(sql_parser.Src_fil());
|
||||
}
|
||||
private void Idx_create(Xodb_fsys_mgr fsys_mgr) {
|
||||
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid_.Tid_core, Xodb_file_tid_.Tid_category), Idx_categorylinks_from, Idx_categorylinks_main);
|
||||
fsys_mgr.Index_create(usr_dlg, Byte_.Ary(Xodb_file_tid.Tid_core, Xodb_file_tid.Tid_category), Idx_categorylinks_from, Idx_categorylinks_main);
|
||||
}
|
||||
int Ctg_grp_end(byte[] new_ctg_ttl) {
|
||||
if (cur_cat_ttl != Bry_.Empty && cur_cat_id != -1)
|
||||
db_mgr.Tbl_category().Insert(ctg_stmt, cur_cat_id, cur_cat_counts[Xoa_ctg_mgr.Tid_page], cur_cat_counts[Xoa_ctg_mgr.Tid_subc], cur_cat_counts[Xoa_ctg_mgr.Tid_file], Xoa_ctg_mgr.Hidden_n, cur_cat_file_idx);
|
||||
if (new_ctg_ttl == Ttl_last) return Cur_cat_id_null; // last ttl; called by this.End(); exit early else will fail in Cur_cat_id_find()
|
||||
if (cur_cat_file_max > 0 && cur_cat_file_size > cur_cat_file_max) {File_close(); File_open(db_mgr.Fsys_mgr().Make(Xodb_file_tid_.Tid_category));}
|
||||
if (cur_cat_file_max > 0 && cur_cat_file_size > cur_cat_file_max) {File_close(); File_open(db_mgr.Fsys_mgr().Make(Xodb_file_tid.Tid_category));}
|
||||
cur_cat_id = Cur_cat_id_find(new_ctg_ttl);
|
||||
for (int i = 0; i < Xoa_ctg_mgr.Tid__max; i++)
|
||||
cur_cat_counts[i] = 0;
|
||||
|
@ -34,7 +34,7 @@ public class Xob_categorylinks_sql_tst {
|
||||
));
|
||||
fxt.Exec_run(new Xob_category_registry_sql(fxt.Bldr(), fxt.Wiki()));
|
||||
fxt.Exec_run(new Xob_categorylinks_sql(fxt.Bldr(), fxt.Wiki()));
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Category_provider();
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Provider_ctg();
|
||||
Db_tst_qry.tbl_(Xodb_category_tbl.Tbl_name, Xodb_category_tbl.Fld_cat_id)
|
||||
.Cols_(Xodb_category_tbl.Fld_cat_id, Xodb_category_tbl.Fld_cat_subcats, Xodb_category_tbl.Fld_cat_files, Xodb_category_tbl.Fld_cat_pages)
|
||||
.Rows_add_vals(1, 0, 0, 2)
|
||||
|
@ -24,7 +24,7 @@ public class Xoctg_hiddencat_parser_sql extends Xoctg_hiddencat_parser_base {
|
||||
super.Cmd_bgn_hook(bldr, parser);
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Db_provider provider = fsys_mgr.Category_provider();
|
||||
Db_provider provider = fsys_mgr.Provider_ctg();
|
||||
provider.Txn_mgr().Txn_bgn_if_none();
|
||||
tbl = db_mgr.Tbl_category();
|
||||
stmt = tbl.Update_stmt(provider);
|
||||
|
@ -40,7 +40,7 @@ public class Xoctg_hiddencat_parser_sql_tst {
|
||||
private void Init_ctgs(int... ctgs) {
|
||||
int len = ctgs.length;
|
||||
Xodb_category_tbl tbl = fxt.Wiki().Db_mgr_as_sql().Tbl_category();
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Category_provider();
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Provider_ctg();
|
||||
Db_stmt stmt = tbl.Insert_stmt(provider);
|
||||
try {
|
||||
for (int i = 0; i < len; i++) {
|
||||
@ -52,7 +52,7 @@ public class Xoctg_hiddencat_parser_sql_tst {
|
||||
private void Tst_ctg_hidden(boolean expd_hidden, int... ctgs) {
|
||||
int len = ctgs.length;
|
||||
Xodb_category_tbl tbl = fxt.Wiki().Db_mgr_as_sql().Tbl_category();
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Category_provider();
|
||||
Db_provider provider = fxt.Wiki().Db_mgr_as_sql().Fsys_mgr().Provider_ctg();
|
||||
for (int i = 0; i < len; i++) {
|
||||
int ctg_id = ctgs[i];
|
||||
Xodb_category_itm ctg_itm = tbl.Select(provider, ctg_id);
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
|
||||
import org.junit.*;
|
||||
public class Xoctg_hiddencat_ttl_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xobc_base_fxt fxt = new Xobc_base_fxt();
|
||||
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt
|
||||
.Init_fil("mem/xowa/wiki/en.wikipedia.org/tmp/ctg.hiddencat_sql/make/0000000000.csv", String_.Concat_lines_nl
|
||||
|
@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.bldrs.imports.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.imports.*;
|
||||
import org.junit.*; import gplx.xowa.ctgs.*;
|
||||
public class Xoctg_link_idx_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xobc_base_fxt fxt = new Xobc_base_fxt();
|
||||
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt
|
||||
.Init_fil("mem/xowa/wiki/en.wikipedia.org/tmp/ctg.link_sql/make/0000000000.csv", String_.Concat_lines_nl
|
||||
|
@ -355,7 +355,7 @@ public class Xol_mw_lang_parser {
|
||||
mw_names.Add_obj("NS_PROJECT_TALK", Int_obj_val.new_(Xow_ns_.Id_project_talk));
|
||||
mw_names.Add_obj("NS_FILE", Int_obj_val.new_(Xow_ns_.Id_file));
|
||||
mw_names.Add_obj("NS_FILE_TALK", Int_obj_val.new_(Xow_ns_.Id_file_talk));
|
||||
mw_names.Add_obj("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Id_mediaWiki));
|
||||
mw_names.Add_obj("NS_MEDIAWIKI", Int_obj_val.new_(Xow_ns_.Id_mediawiki));
|
||||
mw_names.Add_obj("NS_MEDIAWIKI_TALK", Int_obj_val.new_(Xow_ns_.Id_mediaWiki_talk));
|
||||
mw_names.Add_obj("NS_TEMPLATE", Int_obj_val.new_(Xow_ns_.Id_template));
|
||||
mw_names.Add_obj("NS_TEMPLATE_TALK", Int_obj_val.new_(Xow_ns_.Id_template_talk));
|
||||
|
@ -21,7 +21,7 @@ class Xob_dump_src_ttl implements Xob_parse_all_db {
|
||||
private Xodb_mgr_sql db_mgr; private Db_stmt page_stmt; private Xodb_file[] text_files_ary; private int text_files_len; private byte redirect;
|
||||
public Xob_dump_src_ttl Init(Xow_wiki wiki, int limit, byte redirect) {
|
||||
this.db_mgr = wiki.Db_mgr_as_sql(); this.redirect = redirect;
|
||||
page_stmt = db_mgr.Tbl_page().Select_for_parse_all_stmt(db_mgr.Fsys_mgr().Core_provider(), limit, redirect);
|
||||
page_stmt = db_mgr.Tbl_page().Select_for_parse_all_stmt(db_mgr.Fsys_mgr().Provider_core(), limit, redirect);
|
||||
text_files_ary = Init_text_files_ary(db_mgr.Fsys_mgr());
|
||||
text_files_len = text_files_ary.length;
|
||||
return this;
|
||||
@ -36,12 +36,12 @@ class Xob_dump_src_ttl implements Xob_parse_all_db {
|
||||
}
|
||||
public static Xodb_file[] Init_text_files_ary(Xodb_fsys_mgr fsys_mgr) {
|
||||
ListAdp text_files_list = ListAdp_.new_();
|
||||
Xodb_file[] file_ary = fsys_mgr.Ary();
|
||||
Xodb_file[] file_ary = fsys_mgr.Files_ary();
|
||||
int len = file_ary.length;
|
||||
if (len == 1) return new Xodb_file[] {file_ary[0]}; // single file: return core; note that there are no Tid = Text
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_file file = file_ary[i];
|
||||
if (file.Tid() == Xodb_file_tid_.Tid_text)
|
||||
if (file.Tid() == Xodb_file_tid.Tid_text)
|
||||
text_files_list.Add(file);
|
||||
}
|
||||
return (Xodb_file[])text_files_list.XtoAryAndClear(Xodb_file.class);
|
||||
@ -54,7 +54,7 @@ class Xob_dump_src_id {
|
||||
public Xob_dump_src_id Init(Xow_wiki wiki, byte redirect, int size_max) {
|
||||
this.db_mgr = wiki.Db_mgr_as_sql(); this.redirect = redirect;
|
||||
this.size_max = size_max;
|
||||
page_db_url = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_core).Url().Raw();
|
||||
page_db_url = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_core).Url().Raw();
|
||||
return this;
|
||||
}
|
||||
public void Get_pages(ListAdp list, int text_db_idx, int cur_ns, int prv_id) {
|
||||
@ -76,7 +76,7 @@ class Xob_dump_src_id {
|
||||
private DataRdr New_rdr(Xodb_mgr_sql db_mgr, String page_db_url, int text_db_idx, int cur_ns, int prv_id, byte redirect) {
|
||||
if (cur_text_db_idx != text_db_idx) {
|
||||
cur_text_db_idx = text_db_idx;
|
||||
Xodb_file text_db = db_mgr.Fsys_mgr().Get_by_db_idx(text_db_idx);
|
||||
Xodb_file text_db = db_mgr.Fsys_mgr().Get_by_idx(text_db_idx);
|
||||
Db_provider provider = text_db.Provider();
|
||||
String sql = String_.Format(Sql_select, New_rdr__redirect_clause(redirect));
|
||||
text_stmt = provider.Prepare(Db_qry_sql.rdr_(sql));
|
||||
|
@ -27,12 +27,12 @@ public class Xob_text_db_prep extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
public void Cmd_run() {
|
||||
Xodb_fsys_mgr db_fsys_mgr = wiki.Db_mgr_as_sql().Fsys_mgr();
|
||||
String page_db_url = db_fsys_mgr.Get_tid_root(Xodb_file_tid_.Tid_core).Url().Raw();
|
||||
db_files = db_fsys_mgr.Ary();
|
||||
String page_db_url = db_fsys_mgr.Get_tid_root(Xodb_file_tid.Tid_core).Url().Raw();
|
||||
db_files = db_fsys_mgr.Files_ary();
|
||||
int len = db_files.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_file db_file = db_files[i];
|
||||
if (db_file.Tid() == Xodb_file_tid_.Tid_text)
|
||||
if (db_file.Tid() == Xodb_file_tid.Tid_text)
|
||||
Prep_db(page_db_url, db_file);
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class Xob_text_db_prep extends Xob_itm_basic_base implements Xob_cmd {
|
||||
int len = db_files.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_file db_file = db_files[i];
|
||||
if (db_file.Tid() == Xodb_file_tid_.Tid_text)
|
||||
if (db_file.Tid() == Xodb_file_tid.Tid_text)
|
||||
db_file.Rls();
|
||||
}
|
||||
db_files = null;
|
||||
|
@ -35,12 +35,7 @@ public class Xob_wiki_image_sql_fxt {
|
||||
Io_mgr._.SaveFilStr(src_fil, raw_sql);
|
||||
|
||||
rv.Src_fil_(src_fil);
|
||||
Xobc_base_fxt.Run_cmd(fxt.Bldr(), rv);
|
||||
Xob_base_fxt.Run_cmd(fxt.Bldr(), rv);
|
||||
return rv;
|
||||
}
|
||||
// public void Tst(String expd) {
|
||||
// Io_url trg_fil = Io_url_.mem_fil_("mem/temp/sql_dump.sql");//cmd.Make_url_gen().Prv_urls()[0];
|
||||
// String actl = Io_mgr._.LoadFilStr(trg_fil);
|
||||
// Tfds.Eq_str_lines(expd, actl);
|
||||
// }
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class Xob_wiki_redirect_cmd extends Xob_dump_mgr_base {
|
||||
@Override public void Exec_end_hook() {
|
||||
provider.Txn_mgr().Txn_end_all();
|
||||
tbl_redirect.Create_indexes(usr_dlg, provider);
|
||||
tbl_redirect.Update_redirects(provider, db_mgr.Fsys_mgr().Get_url(Xodb_file_tid_.Tid_core), 4);
|
||||
tbl_redirect.Update_redirects(provider, db_mgr.Fsys_mgr().Get_url(Xodb_file_tid.Tid_core), 4);
|
||||
}
|
||||
// private static final Db_idx_itm Idx_page_title = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS page__title ON page (page_namespace, page_title, page_id, page_len, page_is_redirect, page_file_idx);"); // PERF:page_id for general queries; PERF: page_len for search_suggest
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ 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.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
public void Init_from_all(Xow_wiki wiki, Xol_lang lang, Xoctg_view_ctg ctg, Xoctg_fmtr_all mgr, Xoctg_view_grp itms_list, int itms_list_len) {
|
||||
@ -60,7 +60,7 @@ abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
@gplx.Virtual public void Bld_html(Bry_bfr bfr, Xow_wiki wiki, Xoctg_view_itm itm, Xoa_ttl ttl, byte[] ttl_page, Xoh_href_parser href_parser, Bry_fmtr html_itm) {
|
||||
byte[] itm_href = href_parser.Build_to_bry(wiki, ttl);
|
||||
byte[] itm_full_ttl = ttl.Full_txt();// NOTE: ttl.Full_txt() to get full ns; EX: Template:A instead of just "A"
|
||||
byte[] itm_atr_cls = Xoh_lnki_file_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] itm_atr_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
Bry_fmtr fmtr = itm.Id_missing() ? html_itm_missing : html_itm;
|
||||
fmtr.Bld_bfr_many(bfr, itm_href, itm_full_ttl, itm_full_ttl, itm.Id(), itm_atr_cls);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ 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.ctgs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.html.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
public void Init_app(Xoa_app app, Bry_fmtr fmtr_itm) {
|
||||
@ -32,7 +32,7 @@ public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_page page = (Xodb_page)itms.FetchAt(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, Xow_ns_.Id_category, page.Ttl_wo_ns());
|
||||
byte[] lnki_cls = Xoh_lnki_file_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] lnki_href = href_parser.Build_to_bry(wiki, ttl);
|
||||
byte[] lnki_ttl = ttl.Full_txt();
|
||||
byte[] lnki_text = ttl.Page_txt();
|
||||
|
@ -19,8 +19,8 @@ package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xodb_file {
|
||||
public Xodb_file(int id, byte tid) {this.id = id; this.tid = tid;}
|
||||
public int Id() {return id;} private int id;
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public int Id() {return id;} private final int id; // unique id in xowa_db
|
||||
public byte Tid() {return tid;} private final byte tid; // db type id
|
||||
public Io_url Url() {return url;} public Xodb_file Url_(Io_url v) {url = v; return this;} private Io_url url;
|
||||
public String Url_rel() {return url_rel;} public Xodb_file Url_rel_(String v) {url_rel = v; return this;} private String url_rel;
|
||||
public long File_len() {return file_len;} public Xodb_file File_len_add(int v) {file_len += v; return this;} private long file_len;
|
||||
@ -39,7 +39,6 @@ public class Xodb_file {
|
||||
provider.Rls();
|
||||
} finally {provider = null;}
|
||||
}
|
||||
|
||||
public static Xodb_file load_(int id, byte tid, String url) {return new Xodb_file(id, tid).Url_rel_(url).Cmd_mode_(Db_cmd_mode.Ignore);}
|
||||
public static Xodb_file make_(int id, byte tid, String url) {return new Xodb_file(id, tid).Url_rel_(url).Cmd_mode_(Db_cmd_mode.Create);}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
public class Xodb_file_tid_ {
|
||||
public static final byte Tid_core = 1, Tid_text = 2, Tid_category = 3, Tid_search = 4, Tid_wikidata = 5, Tid_temp = 6;
|
||||
public static final String Key_core = "core", Key_text = "text", Key_category = "category", Key_wikidata = "wikidata", Key_temp = "temp", Key_search = "search";
|
||||
public class Xodb_file_tid {
|
||||
public static final byte Tid_core = 1, Tid_text = 2, Tid_category = 3, Tid_search = 4, Tid_wikidata = 5, Tid_temp = 6, Tid_html = 7; // SERIALIZED
|
||||
public static final String Key_core = "core", Key_text = "text", Key_category = "category", Key_wikidata = "wikidata", Key_temp = "temp", Key_search = "search", Key_html = "html";
|
||||
public static String Xto_key(byte v) {
|
||||
switch (v) {
|
||||
case Tid_core: return Key_core;
|
||||
@ -27,6 +27,7 @@ public class Xodb_file_tid_ {
|
||||
case Tid_wikidata: return Key_wikidata;
|
||||
case Tid_temp: return Key_temp;
|
||||
case Tid_search: return Key_search;
|
||||
case Tid_html: return Key_html;
|
||||
default: throw Err_.unhandled(v);
|
||||
}
|
||||
}
|
@ -16,23 +16,17 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.tbls.*;
|
||||
public class Xodb_fsys_mgr {
|
||||
public Xodb_fsys_mgr Ctor(Io_url src_dir, Io_url trg_dir, String trg_name) {
|
||||
this.src_dir = src_dir;
|
||||
this.trg_dir = trg_dir;
|
||||
this.trg_name = trg_name;
|
||||
return this;
|
||||
} private Io_url src_dir; private String trg_name;
|
||||
public Db_provider Core_provider() {return core_provider;} private Db_provider core_provider;
|
||||
public Db_provider Page_provider() {return page_provider;} private Db_provider page_provider;
|
||||
public Db_provider Category_provider() {return category_provider;} private Db_provider category_provider;
|
||||
public Db_provider Wdata_provider() {return wikidata_provider;} private Db_provider wikidata_provider;
|
||||
public Io_url Trg_dir() {return trg_dir;} private Io_url trg_dir;
|
||||
private final Io_url src_dir; private final Io_url trg_dir; private final String wiki_name;
|
||||
public Xodb_fsys_mgr(Io_url src_dir, Io_url trg_dir, String wiki_name) {this.src_dir = src_dir; this.trg_dir = trg_dir; this.wiki_name = wiki_name;}
|
||||
public Xodb_file[] Files_ary() {return files_ary;}
|
||||
public Db_provider Provider_core() {return provider_core;} private Db_provider provider_core;
|
||||
public Db_provider Provider_page() {return provider_page;} private Db_provider provider_page;
|
||||
public Db_provider Provider_ctg() {return provider_ctg;} public void Provider_ctg_(Xodb_file file) {provider_ctg = file.Provider();} private Db_provider provider_ctg;
|
||||
public Db_provider Provider_wdata() {return provider_wdata;}public void Provider_wdata_(Xodb_file file) {provider_wdata = file.Provider();} private Db_provider provider_wdata;
|
||||
public int Tid_text_idx() {return tid_text_idx;} public Xodb_fsys_mgr Tid_text_idx_(int v) {tid_text_idx = v; return this;} private int tid_text_idx = File_id_core;
|
||||
public long Tid_text_max() {return tid_text_max;} long tid_text_max = Heap_max_infinite;
|
||||
static final int File_id_core = 0;
|
||||
public Xodb_file[] Ary() {return files_ary;}
|
||||
public long Tid_text_max() {return tid_text_max;} private long tid_text_max = Heap_max_infinite;
|
||||
public void Init_by_files(Db_provider p, Xodb_file[] v) {
|
||||
files_ary = v; files_ary_len = v.length;
|
||||
boolean category_provider_core_null = true;
|
||||
@ -41,55 +35,44 @@ public class Xodb_fsys_mgr {
|
||||
Io_url url = trg_dir.GenSubFil(file.Url_rel()); // relative name only
|
||||
file.Connect_(Db_connect_.sqlite_(url)).Url_(url);
|
||||
switch (file.Tid()) {
|
||||
case Xodb_file_tid_.Tid_core : file.Provider_(p); Init_by_tid_core(file); break;
|
||||
case Xodb_file_tid_.Tid_category : if (category_provider_core_null) {Init_by_tid_category(file); category_provider_core_null = false;}break;
|
||||
case Xodb_file_tid_.Tid_wikidata : Init_by_tid_wikidata(file); break;
|
||||
case Xodb_file_tid_.Tid_text : Init_by_tid_text(file); break;
|
||||
case Xodb_file_tid.Tid_core : file.Provider_(p); Set_file_core(file); break;
|
||||
case Xodb_file_tid.Tid_category : if (category_provider_core_null) {Provider_ctg_(file); category_provider_core_null = false;} break;
|
||||
case Xodb_file_tid.Tid_wikidata : Provider_wdata_(file); break;
|
||||
case Xodb_file_tid.Tid_text : Set_file_text(file); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Init_make(Xow_ns_mgr ns_mgr, String ns_map_str, long text_max) {
|
||||
Init_by_tid_core(Make(Xodb_file_tid_.Tid_core));
|
||||
Init_by_ns_map(ns_mgr, Xodb_ns_map_mgr.Parse(Bry_.new_ascii_(ns_map_str)));
|
||||
if (text_max > 0)
|
||||
Init_by_tid_text(Init_make_file(Xodb_file_tid_.Tid_text, text_max));
|
||||
}
|
||||
public Xodb_file Init_make_file(byte tid, long max) {
|
||||
if (max == Max_core_db) return files_ary[File_id_core];
|
||||
return Make(tid).File_max_(max);
|
||||
}
|
||||
private void Init_by_tid_core(Xodb_file file) {core_provider = page_provider = category_provider = wikidata_provider = file.Provider();}
|
||||
public void Init_by_tid_category(Xodb_file file) {category_provider = file.Provider();}
|
||||
public void Init_by_tid_wikidata(Xodb_file file) {wikidata_provider = file.Provider();}
|
||||
private void Init_by_ns_map(Xow_ns_mgr ns_mgr, Xodb_ns_map_mgr ns_map) {
|
||||
public void Init_by_ns_map(Xow_ns_mgr ns_mgr, String ns_map_str, long text_max) {
|
||||
Set_file_core(Make(Xodb_file_tid.Tid_core));
|
||||
Xodb_ns_map_mgr ns_map = Xodb_ns_map_mgr.Parse(Bry_.new_ascii_(ns_map_str));
|
||||
Xodb_ns_map_itm[] ns_map_itms = ns_map.Itms();
|
||||
int ns_map_itms_len = ns_map_itms.length;
|
||||
for (int i = 0; i < ns_map_itms_len; i++) {
|
||||
Xodb_ns_map_itm itm = ns_map_itms[i];
|
||||
int[] ns_ids = itm.Ns_ids();
|
||||
int ns_ids_len = ns_ids.length;
|
||||
Xodb_file file = Make(Xodb_file_tid_.Tid_text);
|
||||
Xodb_file file = Make(Xodb_file_tid.Tid_text);
|
||||
for (int j = 0; j < ns_ids_len; j++) {
|
||||
int ns_id = ns_ids[j];
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id); if (ns == null) continue; // some dumps may not have ns; for example, pre-2013 dumps won't have Module (828)
|
||||
ns.Bldr_file_idx_(file.Id());
|
||||
}
|
||||
}
|
||||
if (text_max > 0)
|
||||
Set_file_text(Make(Xodb_file_tid.Tid_text).File_max_(text_max));
|
||||
}
|
||||
private void Init_by_tid_text(Xodb_file file) {
|
||||
tid_text_idx = file.Id();
|
||||
tid_text_max = file.File_max();
|
||||
}
|
||||
public Xodb_file Get_by_db_idx(int db_idx) {return files_ary[db_idx];}
|
||||
public Xodb_file Get_or_make(byte file_tid, int file_idx) {return file_idx < files_ary_len ? files_ary[file_idx] : Make(file_tid);}
|
||||
private void Set_file_core(Xodb_file file) {provider_core = provider_page = provider_ctg = provider_wdata = file.Provider();}
|
||||
private void Set_file_text(Xodb_file file) {tid_text_idx = file.Id(); tid_text_max = file.File_max();}
|
||||
public Io_url Get_url(byte file_tid) {
|
||||
Xodb_file file = Get_tid_root(file_tid);
|
||||
return trg_dir.GenSubFil(file.Url_rel());
|
||||
}
|
||||
public Xodb_file Get_by_idx(int idx) {return files_ary[idx];}
|
||||
public Xodb_file Get_or_make(byte file_tid, int file_idx) {return file_idx < files_ary_len ? files_ary[file_idx] : Make(file_tid);}
|
||||
public Xodb_file Get_tid_root(byte file_tid) {
|
||||
for (int i = 0; i < files_ary_len; i++) {
|
||||
Xodb_file file = files_ary[i];
|
||||
if (file.Tid() == file_tid) return file; // assume 1st file is root
|
||||
if (file.Tid() == file_tid) return file; // assume 1st found file is root
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -100,33 +83,25 @@ public class Xodb_fsys_mgr {
|
||||
Sqlite_engine_.Idx_create(usr_dlg, file.Provider(), Int_.XtoStr(file.Id()), idxs);
|
||||
}
|
||||
}
|
||||
public void Overwrite(int file_idx) {Create_sqlite3(src_dir, trg_dir, trg_name, file_idx);}
|
||||
public Xodb_file Get_or_make(String name) {
|
||||
Io_url url = trg_dir.GenSubFil(name + ".sqlite3");
|
||||
if (!Io_mgr._.ExistsFil(url))
|
||||
Io_mgr._.CopyFil(src_dir.GenSubFil("xowa.sqlite3"), url, true);
|
||||
return Xodb_file.make_(-1, Xodb_file_tid_.Tid_temp, url.NameAndExt()).Connect_(Db_connect_.sqlite_(url));
|
||||
}
|
||||
public Xodb_file Make(byte file_tid) {
|
||||
int file_idx = files_ary_len;
|
||||
Io_url url = Create_sqlite3(src_dir, trg_dir, trg_name, file_idx);
|
||||
Io_url url = Create_sqlite3(src_dir, trg_dir, wiki_name, file_idx);
|
||||
Xodb_file rv = Xodb_file.make_(file_idx, file_tid, url.NameAndExt()).Connect_(Db_connect_.sqlite_(url));
|
||||
gplx.xowa.dbs.tbls.Xodb_xowa_cfg_tbl.Insert_str(rv.Provider(), "db.meta", "type_name", Xodb_file_tid_.Xto_key(file_tid));
|
||||
Xodb_xowa_cfg_tbl.Insert_str(rv.Provider(), "db.meta", "type_name", Xodb_file_tid.Xto_key(file_tid));
|
||||
files_ary = (Xodb_file[])Array_.Resize(files_ary, files_ary_len + 1);
|
||||
files_ary[files_ary_len] = rv;
|
||||
++files_ary_len;
|
||||
files_ary[files_ary_len++] = rv;
|
||||
return rv;
|
||||
} private Xodb_file[] files_ary = new Xodb_file[0]; int files_ary_len = 0;
|
||||
} private Xodb_file[] files_ary = new Xodb_file[0]; private int files_ary_len = 0;
|
||||
public void Rls() {
|
||||
for (int i = 0; i < files_ary_len; i++)
|
||||
files_ary[i].Rls();
|
||||
}
|
||||
private static Io_url Create_sqlite3(Io_url src_dir, Io_url trg_dir, String trg_name, int file_idx) {
|
||||
private static Io_url Create_sqlite3(Io_url src_dir, Io_url trg_dir, String wiki_name, int file_idx) {
|
||||
Io_url src_fil = src_dir.GenSubFil("xowa.sqlite3"); // /bin/any/sql/xowa/xowa.sqlite3
|
||||
Io_url trg_fil = trg_dir.GenSubFil_ary(trg_name, ".", Int_.XtoStr_PadBgn(file_idx, 3), ".sqlite3"); // /wiki/en.wikipedia.org/en.wikipedia.org.000.sqlite3
|
||||
Io_url trg_fil = trg_dir.GenSubFil_ary(wiki_name, ".", Int_.XtoStr_PadBgn(file_idx, 3), ".sqlite3"); // /wiki/en.wikipedia.org/en.wikipedia.org.000.sqlite3
|
||||
Io_mgr._.CopyFil(src_fil, trg_fil, true);
|
||||
return trg_fil;
|
||||
}
|
||||
private static final int File_id_core = 0;
|
||||
public static final int Heap_max_infinite = 0;
|
||||
public static final long Max_core_db = -1;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.bldrs.imports.ctgs.*; import gplx.xowa.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.dbs.tbls.*;
|
||||
public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = db_mgr.Fsys_mgr();} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
|
||||
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xodb_fsys_mgr fsys_mgr;
|
||||
public byte Search_version() {
|
||||
if (search_provider == null) Search_version_init();
|
||||
return search_version;
|
||||
@ -56,15 +56,15 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
public void Load_by_ids(Cancelable cancelable, ListAdp rv, int bgn, int end) {db_mgr.Tbl_page().Select_by_id_list(cancelable, false, rv, bgn, end);}
|
||||
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
|
||||
int cat_page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xodb_mgr_sql.Page_id_null) return false;
|
||||
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), cat_page_id); if (ctg == Xodb_category_itm.Null) return false;
|
||||
Db_provider p = fsys_mgr.Get_by_db_idx(ctg.File_idx()).Provider();
|
||||
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), cat_page_id); if (ctg == Xodb_category_itm.Null) return false;
|
||||
Db_provider p = fsys_mgr.Get_by_idx(ctg.File_idx()).Provider();
|
||||
return db_mgr.Ctg_select_v1(rv, p, ctg);
|
||||
}
|
||||
public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.not_implemented_();}
|
||||
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) {
|
||||
int cat_page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xodb_mgr_sql.Page_id_null) return;
|
||||
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), cat_page_id); if (ctg == Xodb_category_itm.Null) return;
|
||||
Db_provider p = fsys_mgr.Get_by_db_idx(ctg.File_idx()).Provider();
|
||||
Xodb_category_itm ctg = db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), cat_page_id); if (ctg == Xodb_category_itm.Null) return;
|
||||
Db_provider p = fsys_mgr.Get_by_idx(ctg.File_idx()).Provider();
|
||||
ListAdp list = ListAdp_.new_();
|
||||
Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, p, list);
|
||||
Load_ctg_v2a_ui_sift(rv, ctg, list);
|
||||
@ -112,7 +112,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
private Db_provider search_provider = null;
|
||||
private void Search_version_init() {
|
||||
if (search_provider == null) {
|
||||
Xodb_file search_file = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_search);
|
||||
Xodb_file search_file = db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search);
|
||||
if (search_file == null) {
|
||||
search_provider = Db_provider_.Null;
|
||||
search_version = gplx.xowa.specials.search.Xosrh_core.Version_1;
|
||||
@ -128,7 +128,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
if (search_version == gplx.xowa.specials.search.Xosrh_core.Version_1)
|
||||
db_mgr.Tbl_page().Select_by_search(cancelable, rv, search, results_max);
|
||||
else {
|
||||
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid_.Tid_search).Provider());
|
||||
Xodb_search_title_word_tbl.Select_by_word(cancelable, rv, search, results_max, db_mgr.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_search).Provider());
|
||||
db_mgr.Tbl_page().Select_by_id_list(cancelable, true, rv);
|
||||
}
|
||||
}
|
||||
@ -141,10 +141,10 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
public int Load_ctg_count(byte[] ttl) {
|
||||
int page_id = db_mgr.Tbl_page().Select_id(Xow_ns_.Id_category, ttl);
|
||||
if (page_id == Xodb_mgr_sql.Page_id_null) return 0; // title not found; return 0;
|
||||
return db_mgr.Tbl_category().Select(fsys_mgr.Category_provider(), page_id).Count_all();
|
||||
return db_mgr.Tbl_category().Select(fsys_mgr.Provider_ctg(), page_id).Count_all();
|
||||
}
|
||||
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Tbl_wdata_qids().Select_qid(fsys_mgr.Wdata_provider(), wiki_alias, ns_num, ttl);}
|
||||
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Tbl_wdata_pids().Select_pid(fsys_mgr.Wdata_provider(), lang_key, pid_name);}
|
||||
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Tbl_wdata_qids().Select_qid(fsys_mgr.Provider_wdata(), wiki_alias, ns_num, ttl);}
|
||||
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Tbl_wdata_pids().Select_pid(fsys_mgr.Provider_wdata(), lang_key, pid_name);}
|
||||
public byte[] Find_random_ttl(Xow_ns ns) {return db_mgr.Tbl_page().Select_random(ns);}
|
||||
public void Clear() {}
|
||||
public Xodb_page[] Load_ctg_list(byte[][] ctg_ttls) {
|
||||
@ -166,7 +166,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
hash2.Add(page.Id_val(), page);
|
||||
}
|
||||
len = hash2.Count(); // must update len (!hash2.Has() may have skipped titles)
|
||||
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Category_provider(), 0, len);
|
||||
db_mgr.Tbl_category().Select_by_cat_id_in(Cancelable_.Never, hash2, fsys_mgr.Provider_ctg(), 0, len);
|
||||
return (Xodb_page[])hash.XtoAry(Xodb_page.class);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class Xodb_load_mgr_sql_fxt {
|
||||
public void Init_save_ctgs(Xodb_page[] ary) {
|
||||
int len = ary.length;
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
|
||||
Db_provider p = db_mgr.Fsys_mgr().Core_provider();
|
||||
Db_provider p = db_mgr.Fsys_mgr().Provider_core();
|
||||
p.Txn_mgr().Txn_bgn_if_none();
|
||||
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(p);
|
||||
Db_stmt category_stmt = db_mgr.Tbl_category().Insert_stmt(p);
|
||||
|
@ -16,7 +16,7 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
public interface Xodb_mgr extends GfoInvkAble, RlsAble {
|
||||
byte Tid();
|
||||
String Tid_name();
|
||||
@ -26,4 +26,5 @@ public interface Xodb_mgr extends GfoInvkAble, RlsAble {
|
||||
DateAdp Dump_date_query();
|
||||
Xodb_load_mgr Load_mgr();
|
||||
Xodb_save_mgr Save_mgr();
|
||||
Xodb_html_mgr Html_mgr();
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
public Xodb_mgr_sql(Xow_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
load_mgr = new Xodb_load_mgr_sql(this);
|
||||
fsys_mgr = new Xodb_fsys_mgr(wiki.App().Fsys_mgr().Bin_db_dir(), wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
|
||||
load_mgr = new Xodb_load_mgr_sql(this, fsys_mgr);
|
||||
save_mgr = new Xodb_save_mgr_sql(this);
|
||||
tbl_text = new Xodb_text_tbl(this);
|
||||
fsys_mgr.Ctor(wiki.App().Fsys_mgr().Bin_db_dir(), wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
|
||||
}
|
||||
public byte Tid() {return Tid_sql;} public static final byte Tid_sql = 1;
|
||||
public String Tid_name() {return "sqlite3";}
|
||||
@ -33,9 +33,10 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
public byte Category_version() {return category_version;} private byte category_version = Xoa_ctg_mgr.Version_null;
|
||||
public byte Search_version() {return load_mgr.Search_version();}
|
||||
public void Search_version_refresh() {load_mgr.Search_version_refresh();}
|
||||
public Xodb_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xodb_fsys_mgr fsys_mgr = new Xodb_fsys_mgr();
|
||||
public Xodb_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xodb_fsys_mgr fsys_mgr;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_sql load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_sql save_mgr;
|
||||
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
|
||||
public Xodb_xowa_cfg_tbl Tbl_xowa_cfg() {return tbl_cfg;} private Xodb_xowa_cfg_tbl tbl_cfg = new Xodb_xowa_cfg_tbl();
|
||||
public Xodb_xowa_ns_tbl Tbl_xowa_ns() {return tbl_ns;} private Xodb_xowa_ns_tbl tbl_ns = new Xodb_xowa_ns_tbl();
|
||||
public Xodb_xowa_db_tbl Tbl_xowa_db() {return tbl_db;} private Xodb_xowa_db_tbl tbl_db = new Xodb_xowa_db_tbl();
|
||||
@ -52,14 +53,14 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
public DateAdp Dump_date_query() {
|
||||
DateAdp rv = wiki.Props().Modified_latest();
|
||||
if (rv != null) return rv;
|
||||
Io_url url = fsys_mgr.Get_url(Xodb_file_tid_.Tid_core);
|
||||
Io_url url = fsys_mgr.Get_url(Xodb_file_tid.Tid_core);
|
||||
return Io_mgr._.QueryFil(url).ModifiedTime();
|
||||
}
|
||||
public void Init_make(String ns_map) {
|
||||
public void Init_by_ns_map(String ns_map) {
|
||||
Xoi_dump_mgr dump_mgr = wiki.App().Setup_mgr().Dump_mgr();
|
||||
data_storage_format = dump_mgr.Data_storage_format();
|
||||
fsys_mgr.Init_make(wiki.Ns_mgr(), ns_map, dump_mgr.Db_text_max());
|
||||
Core_provider_(fsys_mgr.Core_provider());
|
||||
fsys_mgr.Init_by_ns_map(wiki.Ns_mgr(), ns_map, dump_mgr.Db_text_max());
|
||||
Core_provider_(fsys_mgr.Provider_core());
|
||||
state = State_make;
|
||||
}
|
||||
public void Init_load(Db_connect connect) {
|
||||
@ -129,13 +130,14 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
|
||||
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
|
||||
else if (ctx.Match(k, Invk_tid_name)) return this.Tid_name();
|
||||
else if (ctx.Match(k, Invk_html_mgr)) return html_mgr;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_"
|
||||
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_"
|
||||
, Invk_search_version = "search_version"
|
||||
, Invk_tid_name = "tid_name"
|
||||
, Invk_tid_name = "tid_name", Invk_html_mgr = "html_mgr"
|
||||
;
|
||||
public void Category_version_update(boolean version_is_1) {
|
||||
String grp = Xodb_mgr_sql.Grp_wiki_init;
|
||||
@ -146,7 +148,7 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
tbl_cfg.Insert_str(grp, key, Byte_.XtoStr(category_version));
|
||||
}
|
||||
public void Delete_by_tid(byte tid) {
|
||||
Xodb_file[] ary = fsys_mgr.Ary();
|
||||
Xodb_file[] ary = fsys_mgr.Files_ary();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xodb_file file = ary[i] ;
|
||||
@ -156,8 +158,8 @@ public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
Io_mgr._.DeleteFil_args(sqlite.Url()).MissingFails_off().Exec();
|
||||
file.Cmd_mode_(Db_cmd_mode.Delete);
|
||||
}
|
||||
tbl_db.Commit_all(fsys_mgr.Core_provider(), ary);
|
||||
this.Init_load(fsys_mgr.Core_provider().ConnectInfo());
|
||||
tbl_db.Commit_all(fsys_mgr.Provider_core(), ary);
|
||||
this.Init_load(fsys_mgr.Provider_core().ConnectInfo());
|
||||
}
|
||||
|
||||
public static final String Grp_wiki_init = "wiki.init";
|
||||
|
@ -16,7 +16,7 @@ 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.dbs; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*; import gplx.xowa.ctgs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.ctgs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public Xodb_mgr_txt(Xow_wiki wiki, Xow_data_mgr data_mgr) {
|
||||
this.wiki = wiki;
|
||||
@ -28,6 +28,7 @@ public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public byte Data_storage_format() {return data_storage_format;} public void Data_storage_format_(byte v) {data_storage_format = v;} private byte data_storage_format = gplx.ios.Io_stream_.Tid_file;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
|
||||
public Xodb_html_mgr Html_mgr() {return html_mgr;} private Xodb_html_mgr html_mgr = new Xodb_html_mgr();
|
||||
public DateAdp Dump_date_query() {
|
||||
Io_url url = wiki.Fsys_mgr().Url_ns_fil(Xow_dir_info_.Tid_page, Xow_ns_.Id_main, 0);
|
||||
return Io_mgr._.QueryFil(url).ModifiedTime();
|
||||
|
@ -20,7 +20,7 @@ import gplx.dbs.*; import gplx.ios.*;
|
||||
public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
public Xodb_save_mgr_sql(Xodb_mgr_sql db_mgr) {
|
||||
this.db_mgr = db_mgr; zip_mgr = db_mgr.Wiki().App().Zip_mgr();
|
||||
} Xodb_mgr_sql db_mgr; Io_stream_zip_mgr zip_mgr;
|
||||
} private Xodb_mgr_sql db_mgr; private Io_stream_zip_mgr zip_mgr;
|
||||
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
|
||||
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
|
||||
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next;
|
||||
@ -44,8 +44,8 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
int file_idx = fsys_mgr.Tid_text_idx();
|
||||
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text, text.length);
|
||||
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(fsys_mgr.Page_provider());
|
||||
Db_provider text_provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_idx).Provider();
|
||||
Db_stmt page_stmt = db_mgr.Tbl_page().Insert_stmt(fsys_mgr.Provider_page());
|
||||
Db_provider text_provider = db_mgr.Fsys_mgr().Get_by_idx(file_idx).Provider();
|
||||
Db_stmt text_stmt = db_mgr.Tbl_text().Insert_stmt(text_provider);
|
||||
text = zip_mgr.Zip(db_mgr.Data_storage_format(), text);
|
||||
try {
|
||||
@ -72,7 +72,7 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
if (redirect_changed) kv_ary[kv_idx++] = KeyVal_.new_("page_is_redirect", redirect_changed);
|
||||
if (modified_changed) kv_ary[kv_idx++] = KeyVal_.new_("page_touched", Xto_touched_str(modified));
|
||||
qry = Db_qry_.update_common_("page", Db_crt_.eq_("page_id", page.Revision_data().Id()), kv_ary);
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Core_provider();
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Provider_core();
|
||||
provider.Txn_mgr().Txn_bgn_if_none();
|
||||
provider.Exec_qry(qry);
|
||||
provider.Txn_mgr().Txn_end_all();
|
||||
@ -88,12 +88,12 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
, KeyVal_.new_("page_title", String_.new_utf8_(trg_ttl))
|
||||
);
|
||||
try {
|
||||
db_mgr.Fsys_mgr().Core_provider().Exec_qry(qry);
|
||||
db_mgr.Fsys_mgr().Provider_core().Exec_qry(qry);
|
||||
} catch (Exception exc) {
|
||||
if (String_.Has(Err_.Message_gplx_brief(exc), "columns page_namespace, page_random_int are not unique")) { // HACK: terrible hack, but moving pages across ns will break UNIQUE index
|
||||
db_mgr.Fsys_mgr().Core_provider().Exec_sql("DROP INDEX page__name_random;"); // is UNIQUE by default
|
||||
db_mgr.Fsys_mgr().Core_provider().Exec_sql("CREATE INDEX page__name_random ON page (page_namespace, page_random_int);");
|
||||
db_mgr.Fsys_mgr().Core_provider().Exec_qry(qry);
|
||||
db_mgr.Fsys_mgr().Provider_core().Exec_sql("DROP INDEX page__name_random;"); // is UNIQUE by default
|
||||
db_mgr.Fsys_mgr().Provider_core().Exec_sql("CREATE INDEX page__name_random ON page (page_namespace, page_random_int);");
|
||||
db_mgr.Fsys_mgr().Provider_core().Exec_qry(qry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,43 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.dbs.tbls.*; import gplx.xowa.dbs.hdumps.saves.*;
|
||||
public class Hdump_db_mgr {
|
||||
public Hdump_db_mgr() {
|
||||
save_mgr.Tbl_(text_tbl);
|
||||
}
|
||||
public Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr = new Hdump_save_mgr();
|
||||
public Hdump_text_tbl Text_tbl() {return text_tbl;} private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
|
||||
@gplx.Internal protected void Mode_mem_() {
|
||||
text_tbl = new Hdump_text_tbl_mem();
|
||||
save_mgr.Tbl_(text_tbl);
|
||||
}
|
||||
public Db_provider Db_provider_by_page(int page_id) {
|
||||
return null;
|
||||
}
|
||||
public int Next_insert_id() {return 0;}
|
||||
}
|
||||
class Hdump_db_mgr_setup {
|
||||
public static Xodb_file Setup(Xodb_mgr_sql db_mgr) {
|
||||
Xodb_fsys_mgr fsys_mgr = db_mgr.Fsys_mgr();
|
||||
Update_core(fsys_mgr);
|
||||
Xodb_file html_db_file = Create_db(db_mgr, fsys_mgr);
|
||||
Create_idx(html_db_file);
|
||||
return html_db_file;
|
||||
}
|
||||
public static void Update_core(Xodb_fsys_mgr fsys_mgr) {
|
||||
Db_provider core_provider = fsys_mgr.Provider_core();
|
||||
try {
|
||||
Xodb_xowa_cfg_tbl.Insert_str(core_provider, "db.meta", "html_db.exists", "y");
|
||||
core_provider.Exec_sql("ALTER TABLE page ADD COLUMN html_db_idx integer NOT NULL DEFAULT '-1'");
|
||||
} catch (Exception e) {Gfo_usr_dlg_._.Warn_many("", "", "failed to update core: db=~{0} err=~{1}", core_provider.ConnectInfo().Raw_of_db_connect(), Err_.Message_gplx(e));}
|
||||
}
|
||||
public static Xodb_file Create_db(Xodb_mgr_sql db_mgr, Xodb_fsys_mgr fsys_mgr) {
|
||||
Xodb_file html_db_file = fsys_mgr.Make(Xodb_file_tid.Tid_html);
|
||||
html_db_file.Provider().Exec_sql(Hdump_text_tbl.Tbl_sql);
|
||||
db_mgr.Tbl_xowa_db().Commit_all(fsys_mgr.Provider_core(), db_mgr.Fsys_mgr().Files_ary());
|
||||
return html_db_file;
|
||||
}
|
||||
public static void Create_idx(Xodb_file html_db_file) {
|
||||
Sqlite_engine_.Idx_create(html_db_file.Provider(), Hdump_text_tbl.Idx_core);
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_img_itm {
|
||||
public Hdump_img_itm(int img_id, byte[] img_src, int img_w, int img_h) {
|
||||
this.img_id = img_id;
|
||||
this.img_src = img_src;
|
||||
this.img_w = img_w;
|
||||
this.img_h = img_h;
|
||||
public Hdump_img_itm(int idx, int view_w, int view_h, byte[] lnki_ttl, byte[] view_src) {
|
||||
this.idx = idx;
|
||||
this.view_w = view_w;
|
||||
this.view_h = view_h;
|
||||
this.lnki_ttl = lnki_ttl;
|
||||
this.view_src = view_src;
|
||||
}
|
||||
public int Img_id() {return img_id;} private int img_id;
|
||||
public byte[] Img_src() {return img_src;} private byte[] img_src;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public void Write_html(Bry_bfr bfr) {
|
||||
fmtr.Bld_bfr_many(bfr, img_src, img_w, img_h);
|
||||
} private static final Bry_fmtr fmtr = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public byte[] Lnki_ttl() {return lnki_ttl;} private byte[] lnki_ttl;
|
||||
public int View_w() {return view_w;} private int view_w;
|
||||
public int View_h() {return view_h;} private int view_h;
|
||||
public byte[] View_src() {return view_src;} private byte[] view_src;
|
||||
@Override public String toString() {
|
||||
return String_.Concat_with_str("|", Int_.XtoStr(idx), Int_.XtoStr(view_w), Int_.XtoStr(view_h), String_.new_utf8_(lnki_ttl), String_.new_utf8_(view_src));
|
||||
}
|
||||
public static final Hdump_img_itm[] Ary_empty = new Hdump_img_itm[0];
|
||||
}
|
||||
|
85
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_mgr__save_tst.java
Normal file
85
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_mgr__save_tst.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*; import gplx.dbs.*; import gplx.xowa.files.*;
|
||||
public class Hdump_mgr__save_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_mgr__save_fxt fxt = new Hdump_mgr__save_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Test_save("abc", fxt.Make_itm_body("abc"));
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt.Test_save("a[[File:A.png|test_caption]]b"
|
||||
, fxt.Make_itm_body("a<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>b")
|
||||
, fxt.Make_itm_img(0, 0, 0, "A.png", "orig/7/0/A.png")
|
||||
);
|
||||
}
|
||||
@Test public void Display_title() {
|
||||
fxt.Test_save("{{DISPLAYTITLE:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_display_title("A"));
|
||||
}
|
||||
@Test public void Content_sub() {
|
||||
fxt.Test_save("{{#isin:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_content_sub("<a href=\"/wiki/A\">A</a>"));
|
||||
}
|
||||
@Test public void Sidebar_div() {
|
||||
fxt.Test_save("{{#related:A}}bcd", fxt.Make_itm_body("bcd"), fxt.Make_itm_sidebar_div(String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"portal\" role=\"navigation\" id=\"p-relatedarticles\">"
|
||||
, " <h3></h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li class=\"interwiki-relart\"><a href=\"/wiki/A\">A</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
)));
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__save_fxt extends Hdump_mgr__base_fxt {
|
||||
private int page_id = 0;
|
||||
private ListAdp text_itms = ListAdp_.new_();
|
||||
@Override public void Clear_end() {
|
||||
db_mgr.Mode_mem_();
|
||||
db_mgr.Text_tbl().Provider_(Hdump_text_tbl_mem.Null_provider);
|
||||
}
|
||||
public Hdump_text_row Make_itm_body(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_img(int uid, int img_w, int img_h, String lnki_ttl, String img_src_rel) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img, 0, 0, Hdump_text_row.data_img_(bfr, uid, img_w, img_h, Bry_.new_utf8_(lnki_ttl), Bry_.new_utf8_(img_src_rel)));}
|
||||
public Hdump_text_row Make_itm_display_title(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_display_ttl, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_content_sub(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_content_sub, 0, 0, Bry_.new_utf8_(v));}
|
||||
public Hdump_text_row Make_itm_sidebar_div(String v) {return new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_sidebar_div, 0, 0, Bry_.new_utf8_(v));}
|
||||
public void Test_save(String raw, Hdump_text_row... expd) {
|
||||
this.Exec_write(raw);
|
||||
hdump_mgr.Save_mgr().Update(page);
|
||||
db_mgr.Text_tbl().Select_by_page(text_itms, 0);
|
||||
Hdump_text_row[] actl = (Hdump_text_row[])text_itms.XtoAryAndClear(Hdump_text_row.class);
|
||||
Tfds.Eq_ary_str(Xto_str_ary(expd), Xto_str_ary(actl));
|
||||
}
|
||||
private static String[] Xto_str_ary(Hdump_text_row[] ary) {
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Hdump_text_row itm = ary[i];
|
||||
bfr .Add_int_variable(itm.Page_id())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Tid())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Idx())
|
||||
.Add_byte_pipe().Add_int_variable(itm.Version_id())
|
||||
.Add_byte_pipe().Add(itm.Data())
|
||||
;
|
||||
rv[i] = bfr.XtoStrAndClear();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
124
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_mgr__write_tst.java
Normal file
124
400_xowa/src/gplx/xowa/dbs/hdumps/Hdump_mgr__write_tst.java
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
public class Hdump_mgr__write_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_mgr__write_fxt fxt = new Hdump_mgr__write_fxt();
|
||||
@Test public void Image_full() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "orig/7/0/A.png"));
|
||||
fxt.Test_write
|
||||
( "[[File:A.png|test_caption]]"
|
||||
, "<a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"test_caption\"~<img|0> /></a>");
|
||||
}
|
||||
@Test public void Image_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, "thumb/7/0/A.png/220px.png"));
|
||||
fxt.Test_write
|
||||
( "[[File:A.png|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\"~<img|0> /></a>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Audio_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 220, -1, ""));
|
||||
fxt.Test_write
|
||||
( "[[File:A.oga|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <div id=\"xowa_media_div\">~<mda.play|0>~<mda.info|0>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video_thumb() {
|
||||
fxt.Expd_itms_xfers(fxt.Make_xfer(0, 0, 0, ""));
|
||||
fxt.Test_write
|
||||
( "[[File:A.ogv|thumb|test_caption]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:~<img.w|0>px;\">"
|
||||
, " <div id=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\">"
|
||||
, " <img id=\"xowa_file_img_0\"~<img|0> alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>~<mda.play|0>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">~<mda.mgnf|0>"
|
||||
, " test_caption"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__base_fxt {
|
||||
protected Hdump_db_mgr db_mgr;
|
||||
protected Xodb_html_mgr hdump_mgr = new Xodb_html_mgr();
|
||||
protected Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
protected Xow_wiki wiki; protected Xoa_page page;
|
||||
public Xop_fxt Fxt() {return fxt;} protected Xop_fxt fxt;
|
||||
public void Clear() {
|
||||
if (fxt == null) {
|
||||
fxt = new Xop_fxt();
|
||||
wiki = fxt.Wiki();
|
||||
page = wiki.Ctx().Cur_page();
|
||||
db_mgr = hdump_mgr.Db_mgr();
|
||||
}
|
||||
fxt.Reset();
|
||||
this.Clear_end();
|
||||
}
|
||||
@gplx.Virtual public void Clear_end() {}
|
||||
public void Exec_write(String raw) {
|
||||
Xop_root_tkn root = fxt.Exec_parse_page_all_as_root(Bry_.new_utf8_(raw));
|
||||
page.Root_(root);
|
||||
hdump_mgr.Write(bfr, wiki, page);
|
||||
}
|
||||
}
|
||||
class Hdump_mgr__write_fxt extends Hdump_mgr__base_fxt {
|
||||
private ListAdp expd_itms_xfers = ListAdp_.new_();
|
||||
@Override public void Clear_end() {expd_itms_xfers.Clear();}
|
||||
public Xof_xfer_itm Make_xfer(int uid, int img_w, int img_h, String img_src) {
|
||||
Xof_xfer_itm rv = new Xof_xfer_itm();
|
||||
rv.Init_for_test__hdump(uid, img_w, img_h, Bry_.new_utf8_(img_src));
|
||||
return rv;
|
||||
}
|
||||
public void Expd_itms_xfers(Xof_xfer_itm... itms) {expd_itms_xfers.AddMany((Object[])itms);}
|
||||
public void Test_write(String raw, String expd_html) {
|
||||
this.Exec_write(raw);
|
||||
Tfds.Eq_str_lines(expd_html, String_.new_utf8_(page.Hdump_data().Body()));
|
||||
if (expd_itms_xfers.Count() > 0) Tfds.Eq_ary_str(Xfer_to_str_ary(expd_itms_xfers), Xfer_to_str_ary(page.Hdump_data().Imgs()));
|
||||
}
|
||||
private static String[] Xfer_to_str_ary(ListAdp list) {
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_xfer_itm itm = (Xof_xfer_itm)list.FetchAt(i);
|
||||
rv[i] = String_.Concat_with_str("|", Int_.XtoStr(itm.Html_uid()), Int_.XtoStr(itm.Html_w()), Int_.XtoStr(itm.Html_h()), String_.new_utf8_(itm.Html_view_src_rel()));
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -20,11 +20,11 @@ public class Hdump_page_itm {
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public byte[] Page_url() {return page_url;} private byte[] page_url;
|
||||
public int Version_id() {return version_id;} public void Version_id_(int v) {version_id = v;} private int version_id;
|
||||
public byte[] Page_body() {return page_body;} private byte[] page_body;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub;
|
||||
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs;
|
||||
public Hdump_img_itm[] Img_itms() {return img_itms;} private Hdump_img_itm[] img_itms;
|
||||
public byte[] Page_body() {return page_body;} public void Page_body_(byte[] v) {this.page_body = v;} private byte[] page_body = Bry_.Empty;
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl = Bry_.Empty;
|
||||
public byte[] Content_sub() {return content_sub;} private byte[] content_sub = Bry_.Empty;
|
||||
public byte[][] Sidebar_divs() {return sidebar_divs;} private byte[][] sidebar_divs = Bry_.Ary_empty;
|
||||
public Hdump_img_itm[] Img_itms() {return img_itms;} public void Img_itms_(Hdump_img_itm[] v) {this.img_itms = v;} private Hdump_img_itm[] img_itms = Hdump_img_itm.Ary_empty;
|
||||
public void Init(int page_id, byte[] page_url, int version_id, byte[] display_ttl, byte[] content_sub, byte[] page_body, byte[][] sidebar_divs, Hdump_img_itm[] img_itms) {
|
||||
this.page_id = page_id;
|
||||
this.page_url = page_url;
|
||||
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
|
||||
class Hdump_page_itm_save {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
|
||||
private Hdump_text_tbl text_tbl = new Hdump_text_tbl();
|
||||
private Hdump_db_mgr text_db_mgr = new Hdump_db_mgr();
|
||||
public void Insert(Db_provider provider, Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_body, Version_id, Bry_.Empty, Bry_.Empty);
|
||||
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
|
||||
Insert_if_exists(provider, page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
|
||||
Insert_sidebars(provider, page_id, page, html_data.Xtn_skin_mgr());
|
||||
}
|
||||
private void Insert_if_exists(Db_provider provider, int page_id, int tid, byte[] val) {
|
||||
if (Bry_.Len_gt_0(val))
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, tid, Version_id, Bry_.Empty, val);
|
||||
}
|
||||
private void Insert_sidebars(Db_provider provider, int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
|
||||
int len = xtn_skin_mgr.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
|
||||
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
|
||||
itm.Write(tmp_bfr, page);
|
||||
text_tbl.Insert(provider, text_db_mgr.Next_insert_id(), page_id, Hdump_text_row_tid.Tid_sidebar_div, Version_id, Bry_.Empty, tmp_bfr.XtoAryAndClear());
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final int Version_id = 0;
|
||||
}
|
@ -16,19 +16,22 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
class Hdump_text_row {
|
||||
public int Id() {return id;} private int id;
|
||||
public class Hdump_text_row {
|
||||
public Hdump_text_row(int page_id, int tid, int idx, int version_id, byte[] data) {
|
||||
this.page_id = page_id; this.tid = tid; this.idx = idx; this.version_id = version_id; this.data = data;
|
||||
}
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Tid() {return tid;} private int tid;
|
||||
public int Version() {return version;} private int version;
|
||||
public byte[] Meta() {return meta;} private byte[] meta;
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public int Version_id() {return version_id;} private int version_id;
|
||||
public byte[] Data() {return data;} private byte[] data;
|
||||
public int Sub_id() {return sub_id;} public void Sub_id_(int v) {sub_id = v;} private int sub_id;
|
||||
public Hdump_text_row Init(int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
this.id = id; this.page_id = page_id; this.tid = tid; this.version = version; this.meta = meta; this.data = data;
|
||||
return this;
|
||||
public static byte[] data_img_(Bry_bfr bfr, int uid, int img_w, int img_h, byte[] lnki_ttl, byte[] img_src_rel) {
|
||||
bfr .Add_int_variable(uid)
|
||||
.Add_byte_pipe().Add_int_variable(img_w)
|
||||
.Add_byte_pipe().Add_int_variable(img_h)
|
||||
.Add_byte_pipe().Add(lnki_ttl)
|
||||
.Add_byte_pipe().Add(img_src_rel)
|
||||
;
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
}
|
||||
class Hdump_text_row_tid {
|
||||
public static final int Tid_body = 0, Tid_img = 1, Tid_display_ttl = 2, Tid_content_sub = 3, Tid_sidebar_div = 4;
|
||||
}
|
||||
|
@ -15,16 +15,7 @@ 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.html; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_html_tag {
|
||||
public static final String
|
||||
Nde_xowa_title_str = "xowa_title"
|
||||
, Const_anchor = "#"
|
||||
;
|
||||
|
||||
public static final byte[]
|
||||
Nde_a_bry = Bry_.new_ascii_("a")
|
||||
, Nde_href_bry = Bry_.new_ascii_("href")
|
||||
, Nde_xowa_title_bry = Bry_.new_ascii_(Nde_xowa_title_str)
|
||||
;
|
||||
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Hdump_text_row_tid { // NOTE: SERIALIZED
|
||||
public static final int Tid_body = 0, Tid_img = 1, Tid_gallery = 2, Tid_imap = 3, Tid_display_ttl = 4, Tid_content_sub = 5, Tid_sidebar_div = 6;
|
||||
}
|
@ -17,23 +17,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
class Hdump_text_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert;//, stmt_update, stmt_delete;
|
||||
@gplx.Virtual public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
stmt_insert.Val_int_(id).Val_int_(page_id).Val_int_(tid).Val_int_(version).Val_str_by_bry_(meta).Val_str_by_bry_(data).Exec_insert();
|
||||
public class Hdump_text_tbl {
|
||||
private Db_stmt stmt_select, stmt_insert, stmt_delete;
|
||||
public Db_provider Provider() {return provider;} public void Provider_(Db_provider v) {this.Rls_all(); provider = v;} private Db_provider provider;
|
||||
@gplx.Virtual public void Delete_by_page(int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = Db_stmt_.new_delete_(provider, Tbl_name, Fld_page_id);
|
||||
try {
|
||||
stmt_delete.Clear().Val_int_(page_id).Exec_delete();
|
||||
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
|
||||
}
|
||||
@gplx.Virtual public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
|
||||
@gplx.Virtual public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
|
||||
if (stmt_insert == null) stmt_insert = Db_stmt_.new_insert_(provider, Tbl_name, Flds_all);
|
||||
try {
|
||||
stmt_insert.Clear().Val_int_(page_id).Val_int_(tid).Val_int_(idx).Val_int_(version).Val_str_by_bry_(data).Exec_insert();
|
||||
} catch (Exception exc) {stmt_insert = null; throw Err_.err_(exc, "stmt failed");} // must reset stmt, else next call will fail
|
||||
}
|
||||
@gplx.Virtual public void Select_by_page(ListAdp rv, int page_id) {
|
||||
if (stmt_select == null) stmt_select = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Flds_all);
|
||||
try {
|
||||
DataRdr rdr = stmt_select.Val_int_(page_id).Exec_select();
|
||||
DataRdr rdr = stmt_select.Clear().Val_int_(page_id).Exec_select();
|
||||
while(rdr.MoveNextPeer()) {
|
||||
Hdump_text_row row = new Hdump_text_row().Init
|
||||
( rdr.ReadInt(Fld_text_id)
|
||||
, rdr.ReadInt(Fld_page_id)
|
||||
Hdump_text_row row = new Hdump_text_row
|
||||
( rdr.ReadInt(Fld_page_id)
|
||||
, rdr.ReadInt(Fld_text_tid)
|
||||
, rdr.ReadInt(Fld_text_idx)
|
||||
, rdr.ReadInt(Fld_text_version)
|
||||
, rdr.ReadBryByStr(Fld_text_meta)
|
||||
, rdr.ReadBryByStr(Fld_text_data)
|
||||
);
|
||||
rv.Add(row);
|
||||
@ -41,28 +49,36 @@ class Hdump_text_tbl {
|
||||
rdr.Rls();
|
||||
} finally {stmt_select.Rls();}
|
||||
}
|
||||
public void Rls_all() {
|
||||
if (stmt_select != null) {stmt_select.Rls(); stmt_select = null;}
|
||||
if (stmt_insert != null) {stmt_insert.Rls(); stmt_insert = null;}
|
||||
if (stmt_delete != null) {stmt_delete.Rls(); stmt_delete = null;}
|
||||
provider = null;
|
||||
}
|
||||
public static final String Tbl_name = "html_text"
|
||||
, Fld_text_id = "text_id", Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_version = "text_version"
|
||||
, Fld_text_meta = "text_meta", Fld_text_data = "text_data";
|
||||
private static final String[] Flds_all = new String[] {Fld_text_id, Fld_page_id, Fld_text_tid, Fld_text_version, Fld_text_meta, Fld_text_data};
|
||||
, Fld_page_id = "page_id", Fld_text_tid = "text_tid", Fld_text_idx = "text_idx"
|
||||
, Fld_text_version = "text_version", Fld_text_data = "text_data";
|
||||
private static final String[] Flds_all = new String[] {Fld_page_id, Fld_text_tid, Fld_text_idx, Fld_text_version, Fld_text_data};
|
||||
public static final String Tbl_sql = String_.Concat_lines_nl
|
||||
( "CREATE TABLE IF NOT EXISTS html_text"
|
||||
, "( text_id integer NOT NULL PRIMARY KEY"
|
||||
, ", page_id integer NOT NULL"
|
||||
, "( page_id integer NOT NULL"
|
||||
, ", text_tid integer NOT NULL"
|
||||
, ", text_idx integer NOT NULL"
|
||||
, ", text_version integer NOT NULL"
|
||||
, ", text_meta varchar(4000) NOT NULL"
|
||||
, ", text_data mediumblob NOT NULL"
|
||||
, ");"
|
||||
);
|
||||
public static final Db_idx_itm
|
||||
Idx_core = Db_idx_itm.sql_("CREATE UNIQUE INDEX IF NOT EXISTS html_text__core ON html_text (page_id, text_tid, text_idx);")
|
||||
;
|
||||
}
|
||||
class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashAdp_.new_();
|
||||
@Override public void Insert(Db_provider provider, int id, int page_id, int tid, int version, byte[] meta, byte[] data) {
|
||||
Hdump_text_row row = new Hdump_text_row().Init(id, page_id, tid, version, meta, data);
|
||||
@Override public void Insert(int page_id, int tid, int idx, int version, byte[] data) {
|
||||
Hdump_text_row row = new Hdump_text_row(page_id, tid, idx, version, data);
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
rows.Add(row);
|
||||
}
|
||||
@Override public void Select_by_page(ListAdp rv, Db_provider provider, int page_id) {
|
||||
@Override public void Select_by_page(ListAdp rv, int page_id) {
|
||||
ListAdp rows = Get_or_new(pages, page_id);
|
||||
int len = rows.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@ -70,6 +86,7 @@ class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashA
|
||||
rv.Add(row);
|
||||
}
|
||||
}
|
||||
@Override public void Delete_by_page(int page_id) {pages.Del(page_id);}
|
||||
private static ListAdp Get_or_new(HashAdp pages, int page_id) {
|
||||
ListAdp rv = (ListAdp)pages.Fetch(page_id);
|
||||
if (rv == null) {
|
||||
@ -78,4 +95,5 @@ class Hdump_text_tbl_mem extends Hdump_text_tbl { private HashAdp pages = HashA
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static final Db_provider Null_provider = null;
|
||||
}
|
||||
|
60
400_xowa/src/gplx/xowa/dbs/hdumps/Xodb_html_mgr.java
Normal file
60
400_xowa/src/gplx/xowa/dbs/hdumps/Xodb_html_mgr.java
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.saves.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.gui.*;
|
||||
public class Xodb_html_mgr implements GfoInvkAble {
|
||||
private Xodb_file hdump_db_file;
|
||||
public Xodb_html_mgr() {
|
||||
save_mgr = db_mgr.Save_mgr();
|
||||
}
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled;
|
||||
public Hdump_db_mgr Db_mgr() {return db_mgr;} private Hdump_db_mgr db_mgr = new Hdump_db_mgr();
|
||||
@gplx.Internal protected Hdump_save_mgr Save_mgr() {return save_mgr;} private Hdump_save_mgr save_mgr;
|
||||
public void Write(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page) {
|
||||
page.File_queue().Clear(); // need to reset uid to 0;
|
||||
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
|
||||
wkr.Write_body(bfr, Xoh_wtr_ctx.Hdump, page);
|
||||
page.Hdump_data().Body_(bfr.XtoAryAndClear());
|
||||
}
|
||||
public void Save(Xoa_page page) {
|
||||
if (!enabled) return;
|
||||
if (hdump_db_file == null) hdump_db_file = Hdump_db_file_init(this, page);
|
||||
Xow_wiki wiki = page.Wiki();
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
|
||||
this.Write(tmp_bfr, wiki, page);
|
||||
save_mgr.Update(page);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) enabled = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static Xodb_file Hdump_db_file_init(Xodb_html_mgr html_mgr, Xoa_page page) {
|
||||
Xow_wiki wiki = page.Wiki();
|
||||
Xodb_mgr_sql db_mgr_as_sql = wiki.Db_mgr_as_sql();
|
||||
Xodb_file rv = db_mgr_as_sql.Fsys_mgr().Get_tid_root(Xodb_file_tid.Tid_html);
|
||||
if (rv == null) rv = Hdump_db_mgr_setup.Setup(db_mgr_as_sql);
|
||||
html_mgr.Db_mgr().Text_tbl().Provider_(rv.Provider());
|
||||
return rv;
|
||||
}
|
||||
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
|
||||
}
|
@ -15,15 +15,12 @@ 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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_html_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
// fxt.Test_save("A b c", fxt.itm_text_("A b c"));
|
||||
}
|
||||
}
|
||||
class Hdump_html_mgr_fxt {
|
||||
package gplx.xowa.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Xopg_hdump_data {
|
||||
public ListAdp Imgs() {return imgs;} private ListAdp imgs = ListAdp_.new_();
|
||||
public byte[] Body() {return body;} public void Body_(byte[] v) {body = v;} private byte[] body;
|
||||
public void Clear() {
|
||||
imgs.Clear();
|
||||
body = null;
|
||||
}
|
||||
}
|
30
400_xowa/src/gplx/xowa/dbs/hdumps/Xopg_hdump_img_itm.java
Normal file
30
400_xowa/src/gplx/xowa/dbs/hdumps/Xopg_hdump_img_itm.java
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
public class Xopg_hdump_img_itm {
|
||||
public int Uid() {return uid;} private int uid;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public byte[] Img_src() {return img_src;} private byte[] img_src;
|
||||
public Xopg_hdump_img_itm(int uid, int img_w, int img_h, byte[] img_src) {
|
||||
this.uid = uid; this.img_w = img_w; this.img_h = img_h; this.img_src = img_src;
|
||||
}
|
||||
@Override public String toString() {
|
||||
return String_.Concat_with_str("|", Int_.XtoStr(uid), Int_.XtoStr(img_w), Int_.XtoStr(img_h), String_.new_utf8_(img_src));
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.core.btries.*;
|
||||
class Hdump_html_fmtr__body implements Bry_fmtr_arg {
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
private Hdump_page_itm page;
|
||||
private Gfo_usr_dlg usr_dlg; private byte[] app_dir = Bry_.Empty;
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {this.usr_dlg = usr_dlg; this.app_dir = app_dir;}
|
||||
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[] src = page.Page_body(); int len = src.length;
|
||||
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
|
||||
bry_rdr.Src_(src);
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
|
||||
if (o == null) {
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
}
|
||||
else {
|
||||
if (rng_bgn != -1) {
|
||||
bfr.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
byte tid = ((Byte_obj_val)o).Val();
|
||||
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
|
||||
switch (tid) {
|
||||
case Tid_app_dir: bfr.Add(app_dir); break;
|
||||
case Tid_img: pos = Write_img(bfr, page, src, imgs, imgs_len, pos); break;
|
||||
}
|
||||
++pos; // + 1 to skip trailing }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
|
||||
}
|
||||
private int Write_img(Bry_bfr bfr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int idx_bgn) {
|
||||
int idx_val = bry_rdr.Read_int_to(Byte_ascii.Curly_end);
|
||||
int idx_end = bry_rdr.Pos();
|
||||
if (idx_val == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid(src, idx_bgn, idx_end)); return idx_end;}
|
||||
if (!Int_.Between(idx_val, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), idx_val, imgs_len); return idx_end;}
|
||||
imgs[idx_val].Write_html(bfr);
|
||||
return idx_end;
|
||||
}
|
||||
private static final byte Tid_app_dir = 0, Tid_img = 1;
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
|
||||
.Add_str_byte("~{xo.dir" , Tid_app_dir)
|
||||
.Add_str_byte("~{xo.img." , Tid_img)
|
||||
;
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.html.*; import gplx.xowa.html.lnkis.*;
|
||||
public class Hdump_html_fmtr__body implements Bry_fmtr_arg {
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
private Xow_wiki wiki; private Hdump_page_itm page;
|
||||
private Gfo_usr_dlg usr_dlg; private byte[] file_dir;
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte [] file_dir) {this.usr_dlg = usr_dlg; this.file_dir = file_dir;}
|
||||
public void Init_by_page(Xow_wiki wiki, Hdump_page_itm page) {this.wiki = wiki; this.page = page;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
byte[] src = page.Page_body(); int len = src.length;
|
||||
Hdump_img_itm[] imgs = page.Img_itms(); int imgs_len = page.Img_itms().length;
|
||||
bry_rdr.Src_(src);
|
||||
int pos = 0; int rng_bgn = -1;
|
||||
Xow_html_mgr html_mgr = wiki.Html_mgr();
|
||||
Xoh_file_html_fmtr__base html_fmtr = html_mgr.Html_wtr().Lnki_wtr().File_wtr().File_wtr().Html_fmtr();
|
||||
while (pos < len) {
|
||||
byte b = src[pos];
|
||||
Object o = trie.Match_bgn_w_byte(b, src, pos, len);
|
||||
if (o == null) {
|
||||
if (rng_bgn == -1) rng_bgn = pos;
|
||||
++pos;
|
||||
}
|
||||
else {
|
||||
if (rng_bgn != -1) {
|
||||
bfr.Add_mid(src, rng_bgn, pos);
|
||||
rng_bgn = -1;
|
||||
}
|
||||
byte tid = ((Byte_obj_val)o).Val();
|
||||
pos = trie.Match_pos(); // position after match; EX: "~{xo.img." positions after "."
|
||||
pos = Write_img(bfr, html_mgr, html_fmtr, page, src, imgs, imgs_len, pos, tid); // note no +1; Write_img return pos after }
|
||||
}
|
||||
}
|
||||
if (rng_bgn != -1) bfr.Add_mid(src, rng_bgn, len);
|
||||
}
|
||||
private int Write_img(Bry_bfr bfr, Xow_html_mgr html_mgr, Xoh_file_html_fmtr__base fmtr, Hdump_page_itm page, byte[] src, Hdump_img_itm[] imgs, int imgs_len, int uid_bgn, byte tid) {
|
||||
bry_rdr.Pos_(uid_bgn);
|
||||
int uid = bry_rdr.Read_int_to(Byte_ascii.Gt);
|
||||
int uid_end = bry_rdr.Pos(); // note that uid_end is set to pos after }
|
||||
if (uid == bry_rdr.Or_int()) {usr_dlg.Warn_many("", "", "index is not a valid int; page=~{0} text=~{1}", page.Page_url(), Bry_.Mid_safe(src, uid_bgn, uid_end)); return uid_end;}
|
||||
if (!Int_.Between(uid, 0, imgs_len)) {usr_dlg.Warn_many("", "", "index is out of range; page=~{0} idx=~{1} len=~{2}", page.Page_url(), uid, imgs_len); return uid_end;}
|
||||
Hdump_img_itm img = imgs[uid];
|
||||
int img_view_w = img.View_w();
|
||||
if (tid == Tid_img_w) {
|
||||
bfr.Add_int_variable(img_view_w);
|
||||
return uid_end;
|
||||
}
|
||||
byte[] a_title = img.Lnki_ttl();
|
||||
byte[] a_href = Bry_.Add(A_href_bgn, a_title);
|
||||
switch (tid) {
|
||||
case Tid_mda_info: fmtr.Html_thumb_part_info (bfr, uid, a_href, html_mgr.Img_media_info_btn()); return uid_end;
|
||||
case Tid_mda_mgnf: fmtr.Html_thumb_part_magnify (bfr, uid, a_href, a_title, html_mgr.Img_thumb_magnify()); return uid_end;
|
||||
case Tid_mda_play: fmtr.Html_thumb_part_play (bfr, uid, img_view_w, Xoh_file_wtr__basic.Play_btn_max_width, a_href, a_title, html_mgr.Img_media_play_btn()); return uid_end;
|
||||
}
|
||||
byte[] img_src = Bry_.Add(file_dir, img.View_src());
|
||||
if (tid == Tid_img) {
|
||||
fmtr_img.Bld_bfr_many(bfr, img_src, img_view_w, img.View_h());
|
||||
}
|
||||
return uid_end;
|
||||
}
|
||||
private static final Bry_fmtr fmtr_img = Bry_fmtr.new_(" src='~{src}' width='~{w}' height='~{h}'", "src", "w", "h");
|
||||
private static final byte[] A_href_bgn = Bry_.new_ascii_("/wiki/File:");
|
||||
public static final byte[]
|
||||
Key_img = Bry_.new_ascii_("~<img|")
|
||||
, Key_img_w = Bry_.new_ascii_("~<img.w|")
|
||||
, Key_mda_play = Bry_.new_ascii_("~<mda.play|")
|
||||
, Key_mda_info = Bry_.new_ascii_("~<mda.info|")
|
||||
, Key_mda_mgnf = Bry_.new_ascii_("~<mda.mgnf|")
|
||||
;
|
||||
private static final byte Tid_img = 1, Tid_img_w = 2, Tid_mda_play = 3, Tid_mda_info = 4, Tid_mda_mgnf = 5;
|
||||
private Btrie_slim_mgr trie = Btrie_slim_mgr.cs_()
|
||||
.Add_bry_bval(Key_img , Tid_img)
|
||||
.Add_bry_bval(Key_img_w , Tid_img_w)
|
||||
.Add_bry_bval(Key_mda_play , Tid_mda_play)
|
||||
.Add_bry_bval(Key_mda_info , Tid_mda_info)
|
||||
.Add_bry_bval(Key_mda_mgnf , Tid_mda_mgnf)
|
||||
;
|
||||
}
|
@ -15,7 +15,7 @@ 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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
package gplx.xowa.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_fmtr__sidebars implements Bry_fmtr_arg {
|
||||
private Hdump_page_itm page;
|
||||
public void Init_by_page(Hdump_page_itm page) {this.page = page;}
|
@ -15,13 +15,13 @@ 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.dbs.hdumps.html; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
package gplx.xowa.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
class Hdump_html_mgr {
|
||||
private Hdump_html_fmtr__sidebars sidebars_fmtr = new Hdump_html_fmtr__sidebars();
|
||||
private Hdump_html_fmtr__body body_fmtr = new Hdump_html_fmtr__body();
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] app_dir) {body_fmtr.Init_by_app(usr_dlg, app_dir);}
|
||||
public void Write(Bry_bfr bfr, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
|
||||
body_fmtr.Init_by_page(page);
|
||||
public void Init_by_app(Gfo_usr_dlg usr_dlg, byte[] file_dir) {body_fmtr.Init_by_app(usr_dlg, file_dir);}
|
||||
public void Write(Bry_bfr bfr, Xow_wiki wiki, Bry_fmtr skin_fmtr, Hdump_page_itm page) {
|
||||
body_fmtr.Init_by_page(wiki, page);
|
||||
sidebars_fmtr.Init_by_page(page);
|
||||
skin_fmtr.Bld_bfr_many(bfr, page.Display_ttl(), page.Content_sub(), sidebars_fmtr, body_fmtr);
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
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.dbs.hdumps.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_html_mgr_tst {
|
||||
@Before public void init() {
|
||||
fxt.Clear();
|
||||
fxt.Init_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
} private Hdump_html_mgr_fxt fxt = new Hdump_html_mgr_fxt();
|
||||
@Test public void Img() {
|
||||
fxt .Init_body("~<img|0>")
|
||||
.Test_html(" src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220.png' width='220' height='110'");
|
||||
}
|
||||
@Test public void Img_w() {
|
||||
fxt .Init_body("~<img.w|0>")
|
||||
.Test_html("220");
|
||||
}
|
||||
@Test public void Mda_info() {
|
||||
fxt .Init_body("~<mda.info|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/info.png\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Mda_mgnf() {
|
||||
fxt .Init_body("~<mda.mgnf|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"A.png\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Mda_play() {
|
||||
fxt .Init_body("~<mda.play|0>")
|
||||
.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_0\" href=\"/wiki/File:A.png\" xowa_title=\"A.png\" class=\"xowa_anchor_button\" style=\"width:220px;max-width:1024px;\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/play.png\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Hdump_html_mgr_fxt {
|
||||
private Hdump_html_mgr html_mgr = new Hdump_html_mgr();
|
||||
private Hdump_page_itm page = new Hdump_page_itm();
|
||||
private Bry_bfr bfr = Bry_bfr.reset_(255);
|
||||
private Bry_fmtr skin_fmtr = Bry_fmtr.new_("~{display_ttl}~{content_sub}~{sidebar_divs}~{body_html}", "display_ttl", "content_sub", "sidebar_divs", "body_html");
|
||||
private ListAdp img_list = ListAdp_.new_();
|
||||
private Xow_wiki wiki;
|
||||
public void Clear() {
|
||||
html_mgr.Init_by_app(Gfo_usr_dlg_.Null, Bry_.new_ascii_("file:///mem/xowa/file/"));
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
}
|
||||
public Hdump_html_mgr_fxt Init_body(String body) {page.Page_body_(Bry_.new_utf8_(body)); return this;}
|
||||
public Hdump_html_mgr_fxt Init_img(int id, int w, int h, String ttl, String src) {img_list.Add(new Hdump_img_itm(id, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
|
||||
public Hdump_html_mgr_fxt Test_html(String expd) {
|
||||
if (img_list.Count() > 0) page.Img_itms_((Hdump_img_itm[])img_list.XtoAryAndClear(Hdump_img_itm.class));
|
||||
html_mgr.Write(bfr, wiki, skin_fmtr, page);
|
||||
Tfds.Eq_str_lines(expd, bfr.XtoStrAndClear());
|
||||
return this;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ 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.dbs.hdumps; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*;
|
||||
package gplx.xowa.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.ios.*;
|
||||
import gplx.core.btries.*; import gplx.xowa.pages.*;
|
||||
class Hdump_load_mgr {
|
||||
@ -26,7 +26,8 @@ class Hdump_load_mgr {
|
||||
private ListAdp sidebar_divs = ListAdp_.new_(), img_itms = ListAdp_.new_();
|
||||
private Hdump_text_tbl text_tbl = new Hdump_text_tbl(); private ListAdp tmp_text_itms = ListAdp_.new_();
|
||||
private Bry_rdr bry_rdr = new Bry_rdr();
|
||||
public Hdump_load_mgr(Hdump_db_mgr db_mgr) {this.db_mgr = db_mgr;}
|
||||
private byte zip_tid;
|
||||
public Hdump_load_mgr(Hdump_db_mgr db_mgr, byte zip_tid) {this.db_mgr = db_mgr; this.zip_tid = zip_tid;}
|
||||
public void Clear() {
|
||||
page_version = -1;
|
||||
page_text = display_ttl = content_sub = null;
|
||||
@ -35,7 +36,8 @@ class Hdump_load_mgr {
|
||||
}
|
||||
public void Load(Hdump_page_itm page, int page_id, byte[] page_url) {
|
||||
Db_provider provider = db_mgr.Db_provider_by_page(page_id);
|
||||
text_tbl.Select_by_page(tmp_text_itms, provider, page_id);
|
||||
text_tbl.Provider_(provider);
|
||||
text_tbl.Select_by_page(tmp_text_itms, page_id);
|
||||
Load_itm(page, page_id, page_url, tmp_text_itms);
|
||||
}
|
||||
public void Load_itm(Hdump_page_itm page, int page_id, byte[] page_url, ListAdp itms) {
|
||||
@ -46,9 +48,9 @@ class Hdump_load_mgr {
|
||||
switch (itm.Tid()) {
|
||||
case Hdump_text_row_tid.Tid_body: Load_itm_body(itm); break;
|
||||
case Hdump_text_row_tid.Tid_img: Load_itm_img(itm); break;
|
||||
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data())); break;
|
||||
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
|
||||
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data()); break;
|
||||
case Hdump_text_row_tid.Tid_sidebar_div: sidebar_divs.Add(zip_mgr.Unzip(zip_tid, itm.Data())); break;
|
||||
case Hdump_text_row_tid.Tid_display_ttl: display_ttl = zip_mgr.Unzip(zip_tid, itm.Data()); break;
|
||||
case Hdump_text_row_tid.Tid_content_sub: content_sub = zip_mgr.Unzip(zip_tid, itm.Data()); break;
|
||||
}
|
||||
}
|
||||
page.Init(page_id, page_url, page_version, display_ttl, content_sub, page_text
|
||||
@ -57,16 +59,17 @@ class Hdump_load_mgr {
|
||||
);
|
||||
}
|
||||
public void Load_itm_body(Hdump_text_row itm) {
|
||||
page_version = Bry_.Xto_int(itm.Meta());
|
||||
page_text = zip_mgr.Unzip(Io_stream_.Tid_gzip, itm.Data());
|
||||
page_version = itm.Version_id();
|
||||
page_text = zip_mgr.Unzip(zip_tid, itm.Data());
|
||||
}
|
||||
public void Load_itm_img(Hdump_text_row itm) {
|
||||
bry_rdr.Src_(itm.Meta());
|
||||
int img_id = itm.Sub_id();
|
||||
byte[] img_src = bry_rdr.Read_bry_to_pipe();
|
||||
int img_w = bry_rdr.Read_int_to_pipe();
|
||||
int img_h = bry_rdr.Read_int_to_pipe();
|
||||
Hdump_img_itm img_itm = new Hdump_img_itm(img_id, img_src, img_w, img_h);
|
||||
bry_rdr.Src_(itm.Data());
|
||||
int uid = bry_rdr.Read_int_to_pipe();
|
||||
int w = bry_rdr.Read_int_to_pipe();
|
||||
int h = bry_rdr.Read_int_to_pipe();
|
||||
byte[] ttl = bry_rdr.Read_bry_to_pipe();
|
||||
byte[] src = bry_rdr.Read_bry_to_pipe();
|
||||
Hdump_img_itm img_itm = new Hdump_img_itm(uid, w, h, ttl, src);
|
||||
img_itms.Add(img_itm);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
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.dbs.hdumps.loads; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import org.junit.*;
|
||||
public class Hdump_load_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Hdump_load_mgr_fxt fxt = new Hdump_load_mgr_fxt();
|
||||
@Test public void Body() {
|
||||
fxt.Init_row_body("<body/>");
|
||||
fxt.Expd_body("<body/>");
|
||||
fxt.Test_load(0);
|
||||
}
|
||||
@Test public void Img() {
|
||||
fxt.Init_row_img(0, "0|220|110|A.png|commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
fxt.Init_row_img(1, "1|200|100|B.png|commons.wikimedia.org/thumb/7/0/B.png/200.png");
|
||||
fxt.Expd_img(0, 220, 110, "A.png", "commons.wikimedia.org/thumb/7/0/A.png/220.png");
|
||||
fxt.Expd_img(1, 200, 100, "B.png", "commons.wikimedia.org/thumb/7/0/B.png/200.png");
|
||||
fxt.Test_load(0);
|
||||
}
|
||||
}
|
||||
class Hdump_load_mgr_fxt {
|
||||
private Hdump_load_mgr load_mgr;
|
||||
private Hdump_page_itm page = new Hdump_page_itm();
|
||||
private ListAdp init_rows = ListAdp_.new_();
|
||||
private String expd_body;
|
||||
private ListAdp expd_imgs = ListAdp_.new_();
|
||||
private int page_id = 0;
|
||||
public void Clear() {
|
||||
load_mgr = new Hdump_load_mgr(null, gplx.ios.Io_stream_.Tid_file);
|
||||
init_rows.Clear();
|
||||
expd_body = null;
|
||||
expd_imgs.Clear();
|
||||
}
|
||||
public Hdump_load_mgr_fxt Init_row_body(String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_body, 0, 0, Bry_.new_utf8_(data))); return this;}
|
||||
public Hdump_load_mgr_fxt Init_row_img (int uid, String data) {init_rows.Add(new Hdump_text_row(page_id, Hdump_text_row_tid.Tid_img , uid, 0, Bry_.new_utf8_(data))); return this;}
|
||||
public Hdump_load_mgr_fxt Expd_body(String v) {this.expd_body = v; return this;}
|
||||
public Hdump_load_mgr_fxt Expd_img(int idx, int w, int h, String ttl, String src) {expd_imgs.Add(new Hdump_img_itm(idx, w, h, Bry_.new_utf8_(ttl), Bry_.new_utf8_(src))); return this;}
|
||||
public Hdump_load_mgr_fxt Test_load(int page_id) {
|
||||
load_mgr.Load_itm(page, page_id, Bry_.Empty, init_rows);
|
||||
if (expd_body != null) Tfds.Eq(expd_body, String_.new_utf8_(page.Page_body()));
|
||||
if (expd_imgs.Count() != 0) Tfds.Eq_ary_str((Hdump_img_itm[])expd_imgs.XtoAryAndClear(Hdump_img_itm.class), page.Img_itms());
|
||||
return this;
|
||||
}
|
||||
}
|
62
400_xowa/src/gplx/xowa/dbs/hdumps/saves/Hdump_save_mgr.java
Normal file
62
400_xowa/src/gplx/xowa/dbs/hdumps/saves/Hdump_save_mgr.java
Normal 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.dbs.hdumps.saves; import gplx.*; import gplx.xowa.*; import gplx.xowa.dbs.*; import gplx.xowa.dbs.hdumps.*;
|
||||
import gplx.dbs.*; import gplx.xowa.files.*; import gplx.xowa.pages.*; import gplx.xowa.pages.skins.*;
|
||||
public class Hdump_save_mgr {
|
||||
private Bry_bfr tmp_bfr = Bry_bfr.reset_(10 * Io_mgr.Len_mb);
|
||||
private Hdump_text_tbl text_tbl;
|
||||
public void Tbl_(Hdump_text_tbl v) {text_tbl = v;}
|
||||
public void Update(Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
text_tbl.Delete_by_page(page_id);
|
||||
this.Insert(page);
|
||||
}
|
||||
public void Insert(Xoa_page page) {
|
||||
int page_id = page.Revision_data().Id();
|
||||
Xopg_html_data html_data = page.Html_data();
|
||||
Xopg_hdump_data hdump_data = page.Hdump_data();
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_body, 0, 0, hdump_data.Body());
|
||||
Insert_files(page_id, hdump_data.Imgs());
|
||||
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_display_ttl, html_data.Display_ttl());
|
||||
Insert_if_exists(page_id, Hdump_text_row_tid.Tid_content_sub, html_data.Content_sub());
|
||||
Insert_sidebars(page_id, page, html_data.Xtn_skin_mgr());
|
||||
}
|
||||
private void Insert_files(int page_id, ListAdp imgs) {
|
||||
int len = imgs.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xof_xfer_itm img = (Xof_xfer_itm)imgs.FetchAt(i);
|
||||
int uid = img.Html_uid();
|
||||
byte[] data = Hdump_text_row.data_img_(tmp_bfr, uid, img.Html_w(), img.Html_h(), img.Lnki_ttl(), img.Html_view_src_rel());
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_img, uid, 0, data);
|
||||
}
|
||||
}
|
||||
private void Insert_if_exists(int page_id, int tid, byte[] val) {
|
||||
if (Bry_.Len_gt_0(val))
|
||||
text_tbl.Insert(page_id, tid, 0, 0, val);
|
||||
}
|
||||
private void Insert_sidebars(int page_id, Xoa_page page, Xopg_xtn_skin_mgr xtn_skin_mgr) {
|
||||
int len = xtn_skin_mgr.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xopg_xtn_skin_itm itm = xtn_skin_mgr.Get_at(i);
|
||||
if (itm.Tid() == Xopg_xtn_skin_itm_tid.Tid_sidebar) {
|
||||
itm.Write(tmp_bfr, page);
|
||||
text_tbl.Insert(page_id, Hdump_text_row_tid.Tid_sidebar_div, i, 0, tmp_bfr.XtoAryAndClear());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ public class Xodb_text_tbl {
|
||||
public void Update(int file_id, int page_id, byte[] text) {
|
||||
Db_stmt stmt = Db_stmt_.Null;
|
||||
try {
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_id).Provider();
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Get_by_idx(file_id).Provider();
|
||||
stmt = Db_stmt_.new_update_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_old_text);
|
||||
stmt.Val_bry_(text).Val_int_(page_id).Exec_update();
|
||||
} finally {stmt.Rls();}
|
||||
@ -35,7 +35,7 @@ public class Xodb_text_tbl {
|
||||
public byte[] Select(int file_id, int page_id) {
|
||||
Db_stmt stmt = Db_stmt_.Null;
|
||||
try {
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Get_by_db_idx(file_id).Provider();
|
||||
Db_provider provider = db_mgr.Fsys_mgr().Get_by_idx(file_id).Provider();
|
||||
stmt = Db_stmt_.new_select_(provider, Tbl_name, String_.Ary(Fld_page_id), Fld_old_text);
|
||||
byte[] rv = (byte[])stmt.Val_int_(page_id).Exec_select_val();
|
||||
rv = zip_mgr.Unzip(db_mgr.Data_storage_format(), rv);
|
||||
|
@ -29,7 +29,7 @@ public interface Xof_file_itm {
|
||||
int Orig_w();
|
||||
int Orig_h();
|
||||
// byte Orig_repo();
|
||||
boolean File_is_orig();
|
||||
boolean Img_is_thumbable();
|
||||
int File_w();
|
||||
int Html_uid();
|
||||
int Html_w();
|
||||
|
@ -48,15 +48,17 @@ public class Xof_lnki_file_mgr {
|
||||
xfer_itm.Lnki_ext_(fsdb_itm.Lnki_ext()); // WORKAROUND: hacky, but fsdb_itm knows when ogg is ogv whereas xfer_itm does not; so, always override xfer_itm.ext with fsdb's; DATE:2014-02-02
|
||||
xfer_itm.Url_bldr_(url_bldr); // default Url_bldr for xfer_itm uses @ for thumbtime; switch to -; DATE:2014-02-02
|
||||
Init_fsdb_by_xfer(fsdb_itm, xfer_itm); // copy xfer itm props to fsdb_itm;
|
||||
xfer_itm.Atrs_by_orig(fsdb_itm.Orig_w(), fsdb_itm.Orig_h(), xfer_itm.Orig_file_len()); // copy orig props from orig_itm to xfer_itm
|
||||
fsdb_itm.Html__init(wiki.File_mgr().Repo_mgr(), url_bldr, tmp_img_size, exec_tid);
|
||||
xfer_itm.Set__orig(fsdb_itm.Orig_w(), fsdb_itm.Orig_h(), xfer_itm.Orig_file_len()); // copy orig props from orig_itm to xfer_itm
|
||||
Xof_repo_itm repo = wiki.File_mgr().Repo_mgr().Repos_get_by_wiki(fsdb_itm.Orig_wiki()).Trg();
|
||||
fsdb_itm.Html__init(repo, url_bldr, tmp_img_size, exec_tid);
|
||||
xfer_itm.Trg_repo_(repo);
|
||||
xfer_itm.Html_orig_src_(Bry_.new_utf8_(fsdb_itm.Html_orig_url().To_http_file_str())); // always set orig_url; note that w,h are not necessary for orig url; orig url needed for [[Media:]] links; DATE:2014-01-19
|
||||
gplx.ios.IoItmFil fil = Io_mgr._.QueryFil(fsdb_itm.Html_url());
|
||||
if (fil.Exists()) {
|
||||
if (fil.Size() == 0) // NOTE: fix; XOWA used to write 0 byte files if file was missing, delete them and do not return true; DATE:2014-06-21
|
||||
Io_mgr._.DeleteFil(fsdb_itm.Html_url());
|
||||
else {
|
||||
xfer_itm.Atrs_calc_by_fsdb(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_url(), fsdb_itm.Html_orig_url());
|
||||
xfer_itm.Calc_by_fsdb(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_url(), fsdb_itm.Html_orig_url());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -25,41 +25,47 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type;
|
||||
public int Lnki_w() {return lnki_w;} private int lnki_w;
|
||||
public int Lnki_h() {return lnki_h;} private int lnki_h;
|
||||
public double Lnki_upright() {return lnki_upright;} double lnki_upright;
|
||||
public double Lnki_upright() {return lnki_upright;} private double lnki_upright;
|
||||
public double Lnki_thumbtime() {return lnki_thumbtime;} private double lnki_thumbtime = Xof_doc_thumb.Null;
|
||||
public int Lnki_page() {return lnki_page;} private int lnki_page = Xof_doc_page.Null;
|
||||
public boolean Lnki_thumbable() {return lnki_thumbable;} private boolean lnki_thumbable; // SEE:NOTE_1:Lnki_thumbable
|
||||
public boolean File_is_orig() {return !lnki_thumbable;}
|
||||
public int Orig_w() {return orig_w;} private int orig_w;
|
||||
public int Orig_h() {return orig_h;} private int orig_h;
|
||||
public int Orig_file_len() {return orig_file_len;} private int orig_file_len;
|
||||
public int Trg_repo_idx() {return trg_repo_idx;} public Xof_xfer_itm Trg_repo_idx_(int trg_repo_idx) {this.trg_repo_idx = trg_repo_idx; return this;} private int trg_repo_idx = Xof_meta_itm.Repo_unknown;
|
||||
public int Html_uid() {return html_uid;} private int html_uid = -1;
|
||||
public byte Html_elem_tid() {return html_elem_tid;} public Xof_xfer_itm Html_elem_tid_(byte v) {html_elem_tid = v; return this;} private byte html_elem_tid = Xof_html_elem.Tid_none;
|
||||
public Xof_xfer_itm Html_elem_atrs_(int uid, byte tid) {html_uid = uid; html_elem_tid = tid; return this;}
|
||||
public int Html_w() {return html_w;} private int html_w;
|
||||
public int Html_h() {return html_h;} private int html_h;
|
||||
public int File_w() {return file_w == -1 ? html_w : file_w;} public void File_w_(int v) {file_w = v;} private int file_w = -1; // NOTE: for itm_meta, file_w == html_w
|
||||
public byte[] Html_view_src() {return html_view_src;} private byte[] html_view_src = Bry_.Empty;
|
||||
public byte[] Html_orig_src() {return html_orig_src;} public void Html_orig_src_(byte[] v) {this.html_orig_src = v;} private byte[] html_orig_src = Bry_.Empty;
|
||||
public boolean Html_pass() {return html_pass;} private boolean html_pass;
|
||||
public void Atrs_by_html_for_tests(int html_w, int html_h, byte[] html_view_src, byte[] html_orig_src) {this.html_w = html_w; this.html_h = html_h; this.html_view_src = html_view_src; this.html_orig_src = html_orig_src;}
|
||||
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} public Xof_xfer_itm Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v; return this;} private Js_img_wkr html_img_wkr;
|
||||
public int File_w() {return file_w == -1 ? html_w : file_w;} public void File_w_(int v) {file_w = v;} private int file_w = -1; // NOTE: for itm_meta, file_w == html_w
|
||||
public boolean Img_is_thumbable() {return img_is_thumbable;} private boolean img_is_thumbable; // SEE:NOTE_1:Lnki_thumbable
|
||||
public boolean Img_is_orig() {return !img_is_thumbable;}
|
||||
public int Gallery_mgr_h() {return gallery_mgr_h;} public Xof_xfer_itm Gallery_mgr_h_(int v) {gallery_mgr_h = v; return this;} private int gallery_mgr_h = Int_.Neg1;
|
||||
public boolean File_found() {return file_found;} public Xof_xfer_itm File_found_(boolean v) {file_found = v; return this;} private boolean file_found;
|
||||
public Xof_meta_itm Meta_itm() {return meta_itm;} private Xof_meta_itm meta_itm;
|
||||
public Xof_repo_itm Trg_repo() {return trg_repo;}
|
||||
public Xof_xfer_itm Trg_repo_(Xof_repo_itm v) {
|
||||
trg_repo = v;
|
||||
trg_repo_root = trg_repo == null ? Bry_.Empty : trg_repo.Root_http();
|
||||
return this;
|
||||
} private Xof_repo_itm trg_repo;
|
||||
public int Trg_repo_idx() {return trg_repo_idx;} public Xof_xfer_itm Trg_repo_idx_(int trg_repo_idx) {this.trg_repo_idx = trg_repo_idx; return this;} private int trg_repo_idx = Xof_meta_itm.Repo_unknown;
|
||||
public byte[] Trg_repo_root() {return trg_repo_root;} private byte[] trg_repo_root = Bry_.Empty; // HACK: needed for hdump
|
||||
public byte[] Html_view_src_rel() {return html_view_src_rel;} public void Html_view_src_rel_(byte[] v) {html_view_src_rel = v;} private byte[] html_view_src_rel;
|
||||
private byte[] Trg_html(byte mode_id, int width) {return url_bldr.Set_trg_html_(mode_id, trg_repo, lnki_ttl, lnki_md5, lnki_ext, width, lnki_thumbtime, lnki_page).Xto_bry();}
|
||||
public Io_url Trg_file(byte mode_id, int width) {return url_bldr.Set_trg_file_(mode_id, trg_repo, lnki_ttl, lnki_md5, lnki_ext, width, lnki_thumbtime, lnki_page).Xto_url();}
|
||||
public Js_img_wkr Html_img_wkr() {return html_img_wkr;} public Xof_xfer_itm Html_img_wkr_(Js_img_wkr v) {html_img_wkr = v; return this;} private Js_img_wkr html_img_wkr;
|
||||
public Xof_url_bldr Url_bldr(){ return url_bldr;}
|
||||
public Xof_xfer_itm Url_bldr_(Xof_url_bldr v) {url_bldr = v; return this;} private Xof_url_bldr url_bldr = Xof_url_bldr.Temp;
|
||||
public Xof_meta_itm Meta_itm() {return meta_itm;} private Xof_meta_itm meta_itm;
|
||||
public Xof_repo_itm Trg_repo() {return trg_repo;} public Xof_xfer_itm Trg_repo_(Xof_repo_itm v) {trg_repo = v; return this;} private Xof_repo_itm trg_repo;
|
||||
public Xof_xfer_itm Clear() {
|
||||
lnki_type = Byte_.MaxValue_127;
|
||||
lnki_w = lnki_h = file_w = orig_w = orig_h = html_w = html_h = gallery_mgr_h = Int_.Neg1;
|
||||
lnki_upright = Int_.Neg1; lnki_thumbtime = Xof_doc_thumb.Null; lnki_page = Xof_doc_page.Null;
|
||||
lnki_thumbable = false;
|
||||
img_is_thumbable = false;
|
||||
orig_file_len = 0; // NOTE: cannot be -1, or else will always download orig; see ext rule chk and (orig_file_len < 0)
|
||||
lnki_redirect = null; lnki_ttl = null; lnki_md5 = null; lnki_ext = null;
|
||||
html_orig_src = html_view_src = Bry_.Empty;
|
||||
html_orig_src = html_view_src = html_view_src_rel = Bry_.Empty;
|
||||
trg_repo_idx = Int_.Neg1; meta_itm = null;
|
||||
html_uid = Int_.Neg1; html_elem_tid = Xof_html_elem.Tid_none;
|
||||
return this;
|
||||
@ -67,63 +73,64 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public Xof_xfer_itm Clone() {
|
||||
Xof_xfer_itm rv = new Xof_xfer_itm();
|
||||
rv.lnki_type = lnki_type; rv.lnki_w = lnki_w; rv.lnki_h = lnki_h; rv.lnki_upright = lnki_upright; rv.lnki_thumbtime = lnki_thumbtime; rv.lnki_page = lnki_page;
|
||||
rv.lnki_thumbable = lnki_thumbable;
|
||||
rv.img_is_thumbable = img_is_thumbable;
|
||||
rv.orig_w = orig_w; rv.orig_h = orig_h; rv.orig_file_len = orig_file_len;
|
||||
rv.lnki_redirect = lnki_redirect; rv.lnki_ttl = lnki_ttl; rv.lnki_md5 = lnki_md5; rv.lnki_ext = lnki_ext;
|
||||
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_src = html_view_src; rv.html_orig_src = html_orig_src;
|
||||
rv.html_w = html_w; rv.html_h = html_h; rv.html_view_src = html_view_src; rv.html_orig_src = html_orig_src; rv.html_view_src_rel = html_view_src_rel;
|
||||
rv.file_w = file_w;
|
||||
rv.trg_repo_idx = trg_repo_idx;
|
||||
rv.trg_repo_root = trg_repo_root;
|
||||
rv.meta_itm = meta_itm; // NOTE: shared reference
|
||||
rv.html_uid = html_uid; rv.html_elem_tid = html_elem_tid;
|
||||
rv.gallery_mgr_h = gallery_mgr_h;
|
||||
return rv;
|
||||
}
|
||||
|
||||
public void Init_xfer_for_gallery(int html_w, int html_h, int file_w) {
|
||||
public Xof_xfer_itm Init_by_lnki(byte[] ttl, byte[] redirect, byte lnki_type, int w, int h, double upright, double thumbtime, int lnki_page) {
|
||||
this.Set__ttl(ttl, redirect);
|
||||
this.lnki_type = lnki_type; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = upright; this.lnki_thumbtime = thumbtime; this.lnki_page = lnki_page;
|
||||
img_is_thumbable = Xof_xfer_itm_.Lnki_thumbable_calc(lnki_type, lnki_w, lnki_h);
|
||||
if (lnki_thumbtime != Xof_doc_thumb.Null && !lnki_ext.Id_is_media()) // thumbtime is set, but ext is not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0:02]] DATE:2014-07-22
|
||||
lnki_thumbtime = Xof_doc_thumb.Null; // disable thumbtime
|
||||
return this;
|
||||
}
|
||||
public void Init_for_gallery(int html_w, int html_h, int file_w) {
|
||||
this.html_w = html_w; this.html_h = html_h;
|
||||
this.file_w = file_w;
|
||||
}
|
||||
public void Init_xfer_html_size(int html_w, int html_h) {
|
||||
this.html_w = html_w; this.html_h = html_h;
|
||||
}
|
||||
public void Init_xfer_by_gallery_update(int html_w, int html_h, String view_src, String orig_src) {
|
||||
public void Init_for_gallery_update(int html_w, int html_h, String view_src, String orig_src) {
|
||||
this.html_w = html_w; this.html_h = html_h;
|
||||
this.html_view_src = Bry_.new_utf8_(view_src);
|
||||
this.html_orig_src = Bry_.new_utf8_(orig_src);
|
||||
this.html_pass = true;
|
||||
this.file_found = true;
|
||||
}
|
||||
public Xof_xfer_itm Init_by_lnki(byte[] ttl, byte[] redirect, byte lnki_type, int w, int h, double upright, double thumbtime, int lnki_page) {
|
||||
this.Atrs_by_ttl(ttl, redirect);
|
||||
this.lnki_type = lnki_type; this.lnki_w = w; this.lnki_h = h; this.lnki_upright = upright; this.lnki_thumbtime = thumbtime; this.lnki_page = lnki_page;
|
||||
lnki_thumbable = Xof_xfer_itm_.Lnki_thumbable_calc(lnki_type, lnki_w, lnki_h);
|
||||
if (lnki_thumbtime != Xof_doc_thumb.Null && !lnki_ext.Id_is_media()) // thumbtime is set, but ext is not media; PAGE:en.w:Moon; EX:[[File:A.png|thumbtime=0:02]] DATE:2014-07-22
|
||||
lnki_thumbtime = Xof_doc_thumb.Null; // disable thumbtime
|
||||
return this;
|
||||
}
|
||||
public void Atrs_by_meta(Xof_meta_itm meta_itm, Xof_repo_itm trg_repo, int thumb_w_img) {
|
||||
this.meta_itm = meta_itm; this.trg_repo = trg_repo; this.thumb_w_img = thumb_w_img;
|
||||
this.orig_w = meta_itm.Orig_w(); this.orig_h = meta_itm.Orig_h(); // orig_w / orig_h needed for imap; DATE:2014-08-08
|
||||
} private int thumb_w_img;
|
||||
public void Atrs_by_meta_only(Xof_meta_itm meta_itm) {this.meta_itm = meta_itm; Atrs_by_ttl(meta_itm.Ttl(), meta_itm.Ptr_ttl());}
|
||||
public Xof_xfer_itm Atrs_by_ttl(byte[] ttl, byte[] redirect) {
|
||||
public void Init_for_test__hdump(int uid, int img_w, int img_h, byte[] html_view_src_rel) {this.html_uid = uid; this.html_w = img_w; this.html_h = img_h; this.html_view_src_rel = html_view_src_rel;}
|
||||
public void Init_for_test__img(int html_w, int html_h, byte[] html_view_src, byte[] html_orig_src) {this.html_w = html_w; this.html_h = html_h; this.html_view_src = html_view_src; this.html_orig_src = html_orig_src;}
|
||||
public Xof_xfer_itm Set__ttl(byte[] ttl, byte[] redirect) {
|
||||
this.lnki_redirect = redirect;
|
||||
this.lnki_ttl = lnki_redirect == Xop_redirect_mgr.Redirect_null_bry ? Bry_.Copy(ttl) : lnki_redirect;
|
||||
this.lnki_ttl = Xof_xfer_itm_.Md5_decoder.Decode_lax(Xof_xfer_itm_.Ttl_standardize(lnki_ttl)); // NOTE: this line is repeated in static method below
|
||||
this.lnki_md5 = Xof_xfer_itm_.Md5_calc(lnki_ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
|
||||
this.lnki_md5 = Xof_xfer_itm_.Md5_calc(lnki_ttl); // NOTE: md5 is calculated off of url_decoded ttl; EX: A%2Cb is converted to A,b and then md5'd. note that A%2Cb still remains the title
|
||||
this.lnki_ext = Xof_ext_.new_by_ttl_(lnki_ttl);
|
||||
return this;
|
||||
}
|
||||
public Xof_xfer_itm Atrs_by_orig(int w, int h, int orig_file_len) {this.orig_w = w; this.orig_h = h; this.orig_file_len = orig_file_len; return this;}
|
||||
public void Atrs_calc_by_fsdb(int html_w, int html_h, Io_url view_url, Io_url orig_url) {
|
||||
public void Set__html_size(int html_w, int html_h) {this.html_w = html_w; this.html_h = html_h; }
|
||||
public Xof_xfer_itm Set__html_uid_tid(int uid, byte tid) {html_uid = uid; html_elem_tid = tid; return this;}
|
||||
public Xof_xfer_itm Set__orig(int w, int h, int orig_file_len) {this.orig_w = w; this.orig_h = h; this.orig_file_len = orig_file_len; return this;}
|
||||
public void Set__meta(Xof_meta_itm meta_itm, Xof_repo_itm trg_repo, int thumb_w_img) {
|
||||
this.meta_itm = meta_itm; Trg_repo_(trg_repo); this.thumb_w_img = thumb_w_img;
|
||||
this.orig_w = meta_itm.Orig_w(); this.orig_h = meta_itm.Orig_h(); // orig_w / orig_h needed for imap; DATE:2014-08-08
|
||||
} private int thumb_w_img;
|
||||
public void Set__meta_only(Xof_meta_itm meta_itm) {this.meta_itm = meta_itm; Set__ttl(meta_itm.Ttl(), meta_itm.Ptr_ttl());}
|
||||
public void Calc_by_fsdb(int html_w, int html_h, Io_url view_url, Io_url orig_url) {
|
||||
html_pass = true;
|
||||
this.html_w = html_w;
|
||||
this.html_h = html_h;
|
||||
this.html_orig_src = Bry_.new_utf8_(orig_url.To_http_file_str());
|
||||
this.html_view_src = Bry_.new_utf8_(view_url.To_http_file_str());
|
||||
}
|
||||
public boolean Atrs_calc_for_html() {return Atrs_calc_for_html(false);}
|
||||
public boolean Atrs_calc_for_html(boolean caller_is_file_page) {
|
||||
public boolean Calc_by_meta() {return Calc_by_meta(false);}
|
||||
public boolean Calc_by_meta(boolean caller_is_file_page) {
|
||||
html_pass = false;
|
||||
html_orig_src = html_view_src = Bry_.Empty;
|
||||
html_w = lnki_w; html_h = lnki_h;
|
||||
@ -135,13 +142,13 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
boolean limit_size = !lnki_ext.Id_is_svg() || (lnki_ext.Id_is_svg() && caller_is_file_page);
|
||||
if (lnki_ext.Id_is_media() && html_w < 1) // if media and no width, set to default; NOTE: must be set or else dynamic download will resize play button to small size; DATE:20121227
|
||||
html_w = Xof_img_size.Thumb_width_ogv;
|
||||
if (lnki_thumbable) { // file is thumb
|
||||
if (img_is_thumbable) { // file is thumb
|
||||
if (lnki_ext.Id_is_video()) { // video is a special case; src is thumb_w but html_w / html_h is based on calc
|
||||
html_orig_src = Trg_html(Xof_repo_itm.Mode_orig, Xof_img_size.Size_null_deprecated);
|
||||
if (meta_itm.Thumbs_indicates_oga() && lnki_ext.Id_is_ogv()) {lnki_ext = Xof_ext_.new_by_ext_(Xof_ext_.Bry_oga); return true;} // if audio, do not thumb; NOTE: must happen after html_orig_src, b/c html must still be generated to auto-download files; NOTE: must change ext to oga b/c ogg may trigger video code elsewhere
|
||||
Xof_meta_thumb thumb = meta_itm.Thumbs_get_vid(Xof_doc_thumb.X_int(lnki_thumbtime));
|
||||
if (thumb != null) {
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, thumb.Width(), thumb.Height(), html_w, html_h, lnki_thumbable, lnki_upright);
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, thumb.Width(), thumb.Height(), html_w, html_h, img_is_thumbable, lnki_upright);
|
||||
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
|
||||
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, thumb.Width()); // NOTE: must pass thumb.Width() not html_w b/c only one thumb generated for a video file
|
||||
html_pass = true;
|
||||
@ -154,7 +161,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
Xof_meta_thumb[] thumbs = meta_itm.Thumbs(); int thumbs_len = thumbs.length; Xof_meta_thumb thumb = null;
|
||||
if (lnki_h > 0 && orig_w < 1 && thumbs_len > 0) { // if height is specified and no orig, then iterate over thumbs to find similar height; NOTE: this is a fallback case; orig_w/h is optimal; EX: c:Jacques-Louis David and <gallery>
|
||||
Xof_meta_thumb largest = meta_itm.Thumbs_get_largest(thumbs_len); // get largest thumb
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, largest.Width(), largest.Height(), html_w, html_h, lnki_thumbable, lnki_upright, false); // use largest to calc correct width/height; note that this is needed for gallery which passes in 120,120; EX:c:Yellowstone Park
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, largest.Width(), largest.Height(), html_w, html_h, img_is_thumbable, lnki_upright, false); // use largest to calc correct width/height; note that this is needed for gallery which passes in 120,120; EX:c:Yellowstone Park
|
||||
int comp_height = calc_size.Val_1();
|
||||
for (int i = 0; i < thumbs_len; i++) {
|
||||
Xof_meta_thumb tmp_thumb = thumbs[i];
|
||||
@ -163,10 +170,10 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (thumb != null) return Atrs_calc_for_html_found(lnki_type, thumb.Width(), thumb.Height()); // thumb found
|
||||
if (thumb != null) return Calc_by_meta_found(lnki_type, thumb.Width(), thumb.Height()); // thumb found
|
||||
}
|
||||
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, meta_itm.Orig_w(), meta_itm.Orig_h(), html_w, html_h, lnki_thumbable, lnki_upright, limit_size); // calc html_h and html_w; can differ from lnki_w, lnki_h; note that -1 width is handled by thumb_w_img
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, meta_itm.Orig_w(), meta_itm.Orig_h(), html_w, html_h, img_is_thumbable, lnki_upright, limit_size); // calc html_h and html_w; can differ from lnki_w, lnki_h; note that -1 width is handled by thumb_w_img
|
||||
html_w = calc_size.Val_0();
|
||||
if (html_h != -1) html_h = calc_size.Val_1(); // NOTE: if -1 (no height specified) do not set height; EX:Tokage_2011-07-15.jpg; DATE:2013-06-03
|
||||
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, this.File_w());
|
||||
@ -183,7 +190,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
}
|
||||
if (lnki_ext.Id_is_djvu()) { // NOTE: exact djvu w thumbs are not on server; always seems to be 1 off; EX: 90 requested, but 90 doesn't exist; 89 does
|
||||
thumb = meta_itm.Thumbs_get_img(html_w, 1);
|
||||
if (thumb != null) return Atrs_calc_for_html_found(lnki_type, thumb.Width(), thumb.Height()); // thumb found
|
||||
if (thumb != null) return Calc_by_meta_found(lnki_type, thumb.Width(), thumb.Height()); // thumb found
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -219,8 +226,8 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
html_h = lnki_h < 0 ? 0 : lnki_h;
|
||||
return false;
|
||||
} private Int_2_ref calc_size = new Int_2_ref();
|
||||
private boolean Atrs_calc_for_html_found(byte lnki_type, int model_w, int model_h) {
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, model_w, model_h, html_w, html_h, lnki_thumbable, lnki_upright, false); // recalc html_w, html_h; note that false passed b/c truncation is not needed
|
||||
private boolean Calc_by_meta_found(byte lnki_type, int model_w, int model_h) {
|
||||
Xof_xfer_itm_.Calc_xfer_size(calc_size, lnki_type, thumb_w_img, model_w, model_h, html_w, html_h, img_is_thumbable, lnki_upright, false); // recalc html_w, html_h; note that false passed b/c truncation is not needed
|
||||
html_w = calc_size.Val_0(); html_h = calc_size.Val_1();
|
||||
html_view_src = Trg_html(Xof_repo_itm.Mode_thumb, model_w); // note that thumb.Width is used (the actual file width), not html_w
|
||||
html_pass = true;
|
||||
@ -228,6 +235,15 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
}
|
||||
}
|
||||
/*
|
||||
NOTE_1:Lnki_thumbable
|
||||
. false only if following form
|
||||
[[A.png]] -> must get orig
|
||||
. true in almost all other cases, especially if (a) type is thumb; (b) size exists; (c) upright;
|
||||
. basically, indicates that image will be stored on wmf server as "/thumb/" url
|
||||
[[A.png|thumb]] -> default to 220 and check for 220px
|
||||
[[A.png|40px]] -> check for 40px
|
||||
[[A.png|x40px]] -> calc n width and check for npx
|
||||
|
||||
NOTE_2:return true if media
|
||||
. this seems hackish, but if Atrs_calc_for_html returns false, then file is generally added to the queue
|
||||
. the problem is that media/audio is usually not found
|
||||
|
@ -108,13 +108,4 @@ EX_1: view is 120,40 (3:1)
|
||||
EX_2: view is 120,80 (1.5:1)
|
||||
- (a) 120,60 or (b) 160,80
|
||||
- (a) 120,60
|
||||
|
||||
NOTE_3:Lnki_thumbable
|
||||
. false only if following form
|
||||
[[A.png]] -> must get orig
|
||||
. true in almost all other cases, especially if (a) type is thumb; (b) size exists; (c) upright;
|
||||
. basically, indicates that image will be stored on wmf server as "/thumb/" url
|
||||
[[A.png|thumb]] -> default to 220 and check for 220px
|
||||
[[A.png|40px]] -> check for 40px
|
||||
[[A.png|x40px]] -> calc n width and check for npx
|
||||
*/
|
@ -78,19 +78,19 @@ public class Xow_file_mgr implements GfoInvkAble {
|
||||
public boolean Find_meta(Xof_xfer_itm xfer_itm) {
|
||||
xfer_itm.Trg_repo_idx_(Xof_meta_itm.Repo_unknown);
|
||||
byte[] xfer_itm_ttl = xfer_itm.Lnki_ttl();
|
||||
xfer_itm.Atrs_by_ttl(xfer_itm_ttl, Bry_.Empty);
|
||||
xfer_itm.Set__ttl(xfer_itm_ttl, Bry_.Empty);
|
||||
Xof_meta_itm meta_itm = meta_mgr.Get_itm_or_new(xfer_itm_ttl, xfer_itm.Lnki_md5());
|
||||
xfer_itm.Atrs_by_meta_only(meta_itm);
|
||||
xfer_itm.Set__meta_only(meta_itm);
|
||||
if (meta_itm.State_new()) { // meta_itm is brand new
|
||||
xfer_itm.Atrs_by_meta(meta_itm, repo_mgr.Repos_get_at(0).Trg(), wiki.Html_mgr().Img_thumb_width()); // default to 1st repo to prevent null_ref in xfer_mgr; questionable, but all wikis must have at least 1 repo
|
||||
xfer_itm.Atrs_calc_for_html();
|
||||
xfer_itm.Set__meta(meta_itm, repo_mgr.Repos_get_at(0).Trg(), wiki.Html_mgr().Img_thumb_width()); // default to 1st repo to prevent null_ref in xfer_mgr; questionable, but all wikis must have at least 1 repo
|
||||
xfer_itm.Calc_by_meta();
|
||||
return false;
|
||||
}
|
||||
else { // meta_itm exists
|
||||
Xof_repo_itm cur_repo = null;
|
||||
cur_repo = meta_itm.Repo_itm(wiki);
|
||||
xfer_itm.Atrs_by_meta(meta_itm, cur_repo, wiki.Html_mgr().Img_thumb_width());
|
||||
return xfer_itm.Atrs_calc_for_html();
|
||||
xfer_itm.Set__meta(meta_itm, cur_repo, wiki.Html_mgr().Img_thumb_width());
|
||||
return xfer_itm.Calc_by_meta();
|
||||
}
|
||||
}
|
||||
public boolean Exists(byte[] ttl_bry) {
|
||||
|
@ -85,9 +85,9 @@ public class Xof_fsdb_itm {
|
||||
lnki_type_as_mode = file_is_orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb;
|
||||
}
|
||||
}
|
||||
public void Html__init(Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, Xof_img_size img_size, byte exec_tid) {
|
||||
public void Html__init(Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, Xof_img_size img_size, byte exec_tid) {this.Html__init(repo_mgr.Repos_get_by_wiki(orig_wiki).Trg(), url_bldr, img_size, exec_tid);}
|
||||
public void Html__init(Xof_repo_itm repo, Xof_url_bldr url_bldr, Xof_img_size img_size, byte exec_tid) {
|
||||
Html_size_calc(img_size, exec_tid);
|
||||
Xof_repo_itm repo = repo_mgr.Repos_get_by_wiki(orig_wiki).Trg();
|
||||
byte[] name_bry = Bry_.Len_eq_0(orig_redirect) ? lnki_ttl : orig_redirect;
|
||||
if (!lnki_ext.Id_is_media() && lnki_thumbtime != Xof_doc_thumb.Null) // file is not media, but has thumbtime; this check can't be moved to Lnki_thumbtime_() b/c it needs ext
|
||||
lnki_thumbtime = Xof_doc_thumb.Null; // set thumbtime to null; needed else url will reference thumbtime; PAGE:en.w:Moon; EX:[[File:Lunar libration with phase Oct 2007 450px.gif|thumbtime=0:02]]; DATE:2014-07-20
|
||||
|
@ -46,7 +46,7 @@ public class Xof_fsdb_mgr_ {
|
||||
case Xof_wiki_orig_wkr_.Tid_missing_qry:
|
||||
case Xof_wiki_orig_wkr_.Tid_missing_bin: return; // already missing; do not try to find again
|
||||
}
|
||||
if (itm.Lnki_ext().Id_is_audio() && exec_tid != Xof_exec_tid.Tid_viewer_app) { // NOTE: was audio_strict, but v2 always redefines .ogg as .ogv; DATE:2014-02-02
|
||||
if (Is_not_viewable(exec_tid, itm.Lnki_ext())) { // NOTE: was audio_strict, but v2 always redefines .ogg as .ogv; DATE:2014-02-02
|
||||
itm.Rslt_qry_(Xof_qry_wkr_.Tid_noop);
|
||||
return;
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class Xof_fsdb_mgr_ {
|
||||
return;
|
||||
}
|
||||
byte orig_wiki = repo_pair.Repo_id(); // NOTE: should be itm.Orig_repo, but throws null refs
|
||||
if (itm.Lnki_ext().Id_is_audio() && exec_tid != Xof_exec_tid.Tid_viewer_app) { // NOTE: was audio_strict, but v2 always redefines .ogg as .ogv; DATE:2014-02-02
|
||||
if (Is_not_viewable(exec_tid, itm.Lnki_ext())) {
|
||||
itm.Rslt_qry_(Xof_qry_wkr_.Tid_mock);
|
||||
itm.Rslt_bin_(Xof_bin_wkr_.Tid_noop);
|
||||
fsdb_mgr.Reg_insert(itm, orig_wiki, Xof_wiki_orig_wkr_.Tid_noop);
|
||||
@ -74,14 +74,20 @@ public class Xof_fsdb_mgr_ {
|
||||
usr_dlg.Warn_many("", "", "file not found: page=~{0} file=~{1} width=~{2}", page.Url().Xto_full_str_safe(), String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w());
|
||||
itm.Rslt_bin_(Xof_bin_wkr_.Tid_not_found);
|
||||
fsdb_mgr.Reg_insert(itm, orig_wiki, Xof_wiki_orig_wkr_.Tid_missing_bin);
|
||||
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid());
|
||||
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid()); // TODO: update caption with "" if image is missing
|
||||
}
|
||||
}
|
||||
else {
|
||||
fsdb_mgr.Reg_insert(itm, Xof_repo_itm.Repo_unknown, Xof_wiki_orig_wkr_.Tid_missing_qry);
|
||||
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid());
|
||||
// gplx.xowa.files.gui.Js_img_mgr.Update_img_missing(usr_dlg, itm.Html_uid()); // TODO: update caption with "" if image is missing
|
||||
}
|
||||
}
|
||||
private static boolean Is_not_viewable(byte exec_tid, Xof_ext ext) {
|
||||
return exec_tid != Xof_exec_tid.Tid_viewer_app // only apply logic if !Tid_viewer_app; note that if Tid_viewer_app, then user clicked on file, so return true;
|
||||
&& ( ext.Id_is_audio() // NOTE: was audio_strict, but v2 always redefines .ogg as .ogv; DATE:2014-02-02
|
||||
|| ext.Id() == Xof_ext_.Id_unknown // ignore unknown exts, else will download needlessly when viewing page; EX: .wav before .wav was registered; PAGE:pl.s:Śpiąca_królewna_(Oppman); DATE:2014-08-17
|
||||
);
|
||||
}
|
||||
private Xof_img_size img_size = new Xof_img_size();
|
||||
private void Itm_process(Xof_fsdb_mgr fsdb_mgr, Io_url file_dir, Gfo_usr_dlg usr_dlg, Xof_fsdb_itm itm, ListAdp fsdb_list, Xow_repo_mgr repo_mgr, Xof_url_bldr url_bldr, byte exec_tid) {
|
||||
switch (itm.Rslt_reg()) {
|
||||
|
@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import org.junit.*;
|
||||
import gplx.fsdb.*;
|
||||
public class Xof_offline_unknown_tst {
|
||||
@Before public void init() {if (fxt.Db_skip()) return; fxt.Reset();} private Xof_file_fxt fxt = new Xof_file_fxt();
|
||||
@After public void term() {if (fxt.Db_skip()) return; fxt.Rls();}
|
||||
@Test public void Orig_page() { // .bin is on page [[File:A.bin]]; do not qry or get bin; (since file is not "viewable" immediately); DATE:2014-08-17
|
||||
if (fxt.Db_skip()) return;
|
||||
fxt.Init_qry_xowa(Xof_fsdb_arg_init_qry.new_().Init_commons_file("A.bin"));
|
||||
fxt.Init_bin_fsdb(Xof_fsdb_arg_init_bin.new_().Init_commons_file("A.bin"));
|
||||
fxt.Exec_get(Xof_fsdb_arg_exec_get.new_().Init_orig("A.bin").Rslt_reg_missing_reg().Rslt_qry_noop_());
|
||||
fxt.Test_fsys_exists_n("mem/root/common/orig/f/b/A.bin");
|
||||
fxt.Test_regy_pass("A.bin");
|
||||
}
|
||||
@Test public void Orig_app() { // .bin is clicked; get file
|
||||
if (fxt.Db_skip()) return;
|
||||
fxt.Init_qry_xowa(Xof_fsdb_arg_init_qry.new_().Init_commons_file("A.bin"));
|
||||
fxt.Init_bin_fsdb(Xof_fsdb_arg_init_bin.new_().Init_commons_file("A.bin"));
|
||||
fxt.Exec_get(Xof_fsdb_arg_exec_get.new_().Init_orig("A.bin").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_reg_missing_reg().Rslt_qry_mock_().Rslt_bin_fsdb_());
|
||||
fxt.Test_fsys_exists_y("mem/root/common/orig/f/b/A.bin");
|
||||
fxt.Test_regy_pass("A.bin");
|
||||
}
|
||||
}
|
@ -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.files.fsdb.tsts; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
|
||||
import org.junit.*;
|
||||
import gplx.fsdb.*; import gplx.xowa.files.bins.*;
|
||||
public class Xof_offline_wav_tst {
|
||||
@Before public void init() {if (fxt.Db_skip()) return; fxt.Reset();} private Xof_file_fxt fxt = new Xof_file_fxt();
|
||||
@After public void term() {if (fxt.Db_skip()) return; fxt.Rls();}
|
||||
@Test public void Orig_page() { // .wav is on page [[File:A.wav]]; do not qry or get bin; (since file is not "viewable" immediately); DATE:2014-08-17
|
||||
if (fxt.Db_skip()) return;
|
||||
fxt.Init_qry_xowa(Xof_fsdb_arg_init_qry.new_().Init_commons_file("A.wav"));
|
||||
fxt.Init_bin_fsdb(Xof_fsdb_arg_init_bin.new_().Init_commons_file("A.wav"));
|
||||
fxt.Exec_get(Xof_fsdb_arg_exec_get.new_().Init_orig("A.wav").Rslt_reg_missing_reg().Rslt_qry_noop_());
|
||||
fxt.Test_fsys_exists_n("mem/root/common/orig/c/3/A.wav");
|
||||
fxt.Test_regy_pass("A.wav");
|
||||
}
|
||||
@Test public void Orig_app() { // .wav is clicked; get file
|
||||
if (fxt.Db_skip()) return;
|
||||
fxt.Init_qry_xowa(Xof_fsdb_arg_init_qry.new_().Init_commons_file("A.wav"));
|
||||
fxt.Init_bin_fsdb(Xof_fsdb_arg_init_bin.new_().Init_commons_file("A.wav"));
|
||||
fxt.Exec_get(Xof_fsdb_arg_exec_get.new_().Init_orig("A.wav").Exec_tid_(Xof_exec_tid.Tid_viewer_app).Rslt_reg_missing_reg().Rslt_qry_mock_().Rslt_bin_fsdb_());
|
||||
fxt.Test_fsys_exists_y("mem/root/common/orig/c/3/A.wav");
|
||||
fxt.Test_regy_pass("A.wav");
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ public class Xog_url_wkr {
|
||||
Io_url href_url = Io_url_.http_any_(String_.new_utf8_(href_bry), Op_sys.Cur().Tid_is_wnt());
|
||||
gplx.gfui.Gfui_html html_box = win.Active_html_box();
|
||||
String xowa_ttl = page.Wiki().Gui_mgr().Cfg_browser().Content_editable()
|
||||
? html_box.Html_active_atr_get_str(gplx.xowa.html.Xoh_html_tag.Nde_xowa_title_str, null)
|
||||
? html_box.Html_active_atr_get_str(gplx.xowa.html.Xoh_consts.Atr_xowa_title_str, null)
|
||||
: Xoh_dom_.Title_by_href(app.Encoder_mgr().Comma(), app.Utl_bry_bfr_mkr().Get_b512().Mkr_rls(), href_bry, Bry_.new_utf8_(html_box.Html_doc_html()));
|
||||
if (!Io_mgr._.ExistsFil(href_url)) {
|
||||
Xof_xfer_itm xfer_itm = new Xof_xfer_itm();
|
||||
|
@ -16,7 +16,7 @@ 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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.core.btries.*; import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*; import gplx.xowa.html.modules.*;
|
||||
import gplx.core.btries.*; import gplx.gfui.*; import gplx.html.*; import gplx.xowa.gui.menus.*; import gplx.xowa.gui.menus.dom.*; import gplx.xowa.html.modules.*; import gplx.xowa.pages.*;
|
||||
public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
|
||||
private Xoa_app app;
|
||||
public Xog_html_itm(Xog_tab_itm owner_tab) {
|
||||
@ -56,7 +56,7 @@ public class Xog_html_itm implements GfoInvkAble, GfoEvObj {
|
||||
byte view_mode = owner_tab.View_mode();
|
||||
byte[] html_src = page.Wiki().Html_mgr().Page_wtr_mgr().Gen(page, view_mode);
|
||||
Html_src_(page, html_src);
|
||||
if (view_mode == Xog_page_mode.Tid_read){ // used only for Xosrh test; DATE:2014-01-29
|
||||
if (view_mode == Xopg_view_mode.Tid_read){ // used only for Xosrh test; DATE:2014-01-29
|
||||
html_box.Html_doc_body_focus(); // NOTE: only focus if read so up / down will scroll box; edit / html should focus edit-box; DATE:2014-06-05
|
||||
page.Root().Data_htm_(html_src);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.threads.*; import gplx.gfui.*; import gplx.xowa.gui.history.*; import gplx.xowa.gui.bnds.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.cfgs2.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.cfgs2.*; import gplx.xowa.pages.*;
|
||||
public class Xog_tab_itm implements GfoInvkAble {
|
||||
private Xog_win_itm win; private Xocfg_tab_mgr cfg_tab_mgr;
|
||||
public Xog_tab_itm(Xog_tab_mgr tab_mgr, Gfui_tab_itm_data tab_data) {
|
||||
@ -91,9 +91,8 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
tab_box.Tab_name_(tab_name);
|
||||
}
|
||||
public Xog_history_mgr History_mgr() {return history_mgr;} private Xog_history_mgr history_mgr = new Xog_history_mgr();
|
||||
public byte View_mode() {return view_mode;} public Xog_tab_itm View_mode_(byte v) {view_mode = v; return this;} private byte view_mode = Xog_page_mode.Tid_read;
|
||||
public void Pin_toggle() {
|
||||
}
|
||||
public byte View_mode() {return view_mode;} public Xog_tab_itm View_mode_(byte v) {view_mode = v; return this;} private byte view_mode = Xopg_view_mode.Tid_read;
|
||||
public void Pin_toggle() {}
|
||||
public void Show_url_bgn(Xoa_url url) {
|
||||
this.tab_is_loading = true;
|
||||
Xoa_app app = win.App(); Gfo_usr_dlg usr_dlg = app.Usr_dlg();
|
||||
@ -125,7 +124,7 @@ public class Xog_tab_itm implements GfoInvkAble {
|
||||
if (page.Missing()) {
|
||||
if (wiki.Db_mgr().Save_mgr().Create_enabled()) {
|
||||
page = Xoa_page.create_(wiki, ttl);
|
||||
view_mode = Xog_page_mode.Tid_edit;
|
||||
view_mode = Xopg_view_mode.Tid_edit;
|
||||
history_mgr.Add(page); // NOTE: must put new_page on stack so that pressing back will pop new_page, not previous page
|
||||
Xog_tab_itm_read_mgr.Show_page(this, page, false);
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ 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.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.xowa.html.*;
|
||||
import gplx.gfui.*; import gplx.xowa.html.*; import gplx.xowa.pages.*;
|
||||
public class Xog_tab_itm_edit_mgr {
|
||||
public static void Save(Xog_tab_itm tab, boolean quick_save) {
|
||||
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles ctrl+s being pressed on read/html modes
|
||||
if (tab.View_mode() != Xopg_view_mode.Tid_edit) return; // exit if not edit; handles ctrl+s being pressed in read/html modes
|
||||
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
|
||||
byte[] new_text = Get_new_text(tab);
|
||||
if (page.Edit_mode() == Xoa_page_.Edit_mode_create) {
|
||||
@ -37,12 +37,13 @@ public class Xog_tab_itm_edit_mgr {
|
||||
Xoa_page stack_page = tab.History_mgr().Cur_page(wiki); // NOTE: must be to CurPage() else changes will be lost when going Bwd,Fwd
|
||||
stack_page.Data_raw_(page.Data_raw()); // NOTE: overwrite with "saved" changes
|
||||
stack_page.Wiki().ParsePage_root(page, true); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
|
||||
win_itm.Page__mode_(Xog_page_mode.Tid_read);
|
||||
win_itm.Page__mode_(Xopg_view_mode.Tid_read);
|
||||
win_itm.Page__async__bgn(tab);
|
||||
}
|
||||
wiki.Db_mgr().Html_mgr().Save(page);
|
||||
}
|
||||
public static void Preview(Xog_tab_itm tab) {
|
||||
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles preview somehow being called?
|
||||
if (tab.View_mode() != Xopg_view_mode.Tid_edit) return; // exit if not edit; handles preview somehow being called?
|
||||
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
|
||||
Xog_html_itm html_itm = tab.Html_itm();
|
||||
|
||||
@ -54,19 +55,19 @@ public class Xog_tab_itm_edit_mgr {
|
||||
tab.Page_(new_page);
|
||||
|
||||
Bry_bfr tmp_bfr = wiki.Utl_bry_bfr_mkr().Get_m001();
|
||||
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xog_page_mode.Tid_read);
|
||||
Xoh_page_wtr_wkr wkr = wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode.Tid_read);
|
||||
wkr.Page_(new_page);
|
||||
wkr.XferAry(tmp_bfr, 0);
|
||||
byte[] new_html = tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
new_page.Html_data().Edit_preview_(new_html);
|
||||
|
||||
Invalidate(wiki);
|
||||
win_itm.Page__mode_(Xog_page_mode.Tid_edit);
|
||||
win_itm.Page__mode_(Xopg_view_mode.Tid_edit);
|
||||
html_itm.Scroll_page_by_id_gui(Xog_html_itm.Elem_id__first_heading);// NOTE: was originally directly; changed to call on thread; DATE:2014-05-03
|
||||
win_itm.Page__async__bgn(tab); // NOTE: needed to show images during preview; DATE:2014-06-21
|
||||
}
|
||||
public static void Rename(Xog_tab_itm tab) {
|
||||
if (tab.View_mode() != Xog_page_mode.Tid_edit) return; // exit if not edit; handles ctrl+r being pressed
|
||||
if (tab.View_mode() != Xopg_view_mode.Tid_edit) return; // exit if not edit; handles ctrl+r being pressed
|
||||
Xoa_page page = tab.Page(); Xow_wiki wiki = page.Wiki(); Xog_win_itm win_itm = tab.Tab_mgr().Win();
|
||||
if (Bry_.Eq(page.Ttl().Page_db(), wiki.Props().Main_page())) {
|
||||
win_itm.Usr_dlg().Warn_many("", "", "The Main Page cannot be renamed");
|
||||
@ -83,7 +84,7 @@ public class Xog_tab_itm_edit_mgr {
|
||||
}
|
||||
wiki.Db_mgr().Save_mgr().Data_rename(page, new_ns_id, new_text);
|
||||
page.Ttl_(Xoa_ttl.parse_(wiki, Bry_.Add(page.Ttl().Ns().Name_db_w_colon(), new_text)));
|
||||
win_itm.Page__mode_(Xog_page_mode.Tid_read);
|
||||
win_itm.Page__mode_(Xopg_view_mode.Tid_read);
|
||||
win_itm.Usr_dlg().Prog_one("", "", "renamed page to {0}", String_.new_utf8_(page.Ttl().Full_txt_raw()));
|
||||
}
|
||||
public static void Focus(Xog_win_itm win, String elem_focus_id) {
|
||||
|
@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.gfui.*; import gplx.threads.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.gui.history.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*; import gplx.xowa.gui.history.*; import gplx.xowa.pages.*;
|
||||
public class Xog_tab_itm_read_mgr {
|
||||
public static void Async(Xog_tab_itm tab) {tab.Async();}
|
||||
public static void Show_page(Xog_tab_itm tab, Xoa_page new_page, boolean reset_to_read) {Show_page(tab, new_page, reset_to_read, false, false, Xog_history_stack.Nav_fwd);}
|
||||
public static void Show_page(Xog_tab_itm tab, Xoa_page new_page, boolean reset_to_read, boolean new_page_is_same, boolean show_is_err, byte history_nav_type) {
|
||||
if (reset_to_read) tab.View_mode_(Xog_page_mode.Tid_read);
|
||||
if (new_page.Url().Action_is_edit()) tab.View_mode_(Xog_page_mode.Tid_edit);
|
||||
if (reset_to_read) tab.View_mode_(Xopg_view_mode.Tid_read);
|
||||
if (new_page.Url().Action_is_edit()) tab.View_mode_(Xopg_view_mode.Tid_edit);
|
||||
Xoa_page cur_page = tab.Page(); Xog_html_itm html_itm = tab.Html_itm(); Gfui_html html_box = html_itm.Html_box();
|
||||
Xoa_app app = cur_page.App(); Xog_win_itm win = tab.Tab_mgr().Win();
|
||||
if (cur_page != null && !new_page_is_same) { // if new_page_is_same, don't update DocPos; will "lose" current position
|
||||
@ -51,7 +51,7 @@ public class Xog_tab_itm_read_mgr {
|
||||
tab.Tab_mgr().Tab_mgr().Focus();
|
||||
html_box.Focus();
|
||||
win.Usr_dlg().Prog_none("", "", ""); // blank out status bar
|
||||
if (tab.View_mode() == Xog_page_mode.Tid_read)
|
||||
if (tab.View_mode() == Xopg_view_mode.Tid_read)
|
||||
html_itm.Scroll_page_by_bmk_gui();
|
||||
else
|
||||
GfoInvkAble_.InvkCmd_val(tab.Html_itm().Cmd_async(), Xog_html_itm.Invk_html_elem_focus, Xog_html_itm.Elem_id__xowa_edit_data_box); // NOTE: must be async, else won't work; DATE:2014-06-05
|
||||
@ -76,7 +76,7 @@ public class Xog_tab_itm_read_mgr {
|
||||
win.Usr_dlg().Warn_many("", "", err_msg);
|
||||
win.App().Log_wtr().Queue_enabled_(false);
|
||||
Xoa_page fail_page = wiki.Data_mgr().Get_page(ttl, false);
|
||||
tab.View_mode_(Xog_page_mode.Tid_edit);
|
||||
tab.View_mode_(Xopg_view_mode.Tid_edit);
|
||||
Update_selected_tab(win.App(), win, url, ttl);
|
||||
Show_page(tab, fail_page, false, false, true, Xog_history_stack.Nav_fwd);
|
||||
win.Win_box().Text_(err_msg);
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.gui.views; import gplx.*; import gplx.xowa.*; import gplx.xowa.gui.*;
|
||||
import gplx.threads.*; import gplx.gfui.*; import gplx.xowa.gui.*; import gplx.xowa.gui.history.*; import gplx.xowa.xtns.math.*; import gplx.xowa.files.*;
|
||||
import gplx.xowa.gui.urls.*; import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.gui.urls.*; import gplx.xowa.gui.views.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.parsers.lnkis.redlinks.*;
|
||||
public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
private GfoInvkAble sync_cmd;
|
||||
@ -62,17 +62,17 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
else if (ctx.Match(k, Gfui_html.Evt_win_resized)) Refresh_win_size();
|
||||
else if (ctx.Match(k, Invk_page_refresh)) Page__refresh();
|
||||
else if (ctx.Match(k, Invk_page_async_exec)) Xog_tab_itm_read_mgr.Async((Xog_tab_itm)m.ReadObj("v"));
|
||||
else if (ctx.Match(k, Invk_page_view_read)) Page__mode_(Xog_page_mode.Tid_read);
|
||||
else if (ctx.Match(k, Invk_page_view_edit)) Page__mode_(Xog_page_mode.Tid_edit);
|
||||
else if (ctx.Match(k, Invk_page_view_html)) Page__mode_(Xog_page_mode.Tid_html);
|
||||
else if (ctx.Match(k, Invk_page_view_read)) Page__mode_(Xopg_view_mode.Tid_read);
|
||||
else if (ctx.Match(k, Invk_page_view_edit)) Page__mode_(Xopg_view_mode.Tid_edit);
|
||||
else if (ctx.Match(k, Invk_page_view_html)) Page__mode_(Xopg_view_mode.Tid_html);
|
||||
else if (ctx.Match(k, Invk_page_edit_save)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.N);
|
||||
else if (ctx.Match(k, Invk_page_edit_save_draft)) Xog_tab_itm_edit_mgr.Save(tab_mgr.Active_tab(), Bool_.Y);
|
||||
else if (ctx.Match(k, Invk_page_edit_preview)) Xog_tab_itm_edit_mgr.Preview(tab_mgr.Active_tab());
|
||||
else if (ctx.Match(k, Invk_page_edit_rename)) Xog_tab_itm_edit_mgr.Rename(tab_mgr.Active_tab());
|
||||
else if (ctx.Match(k, Invk_page_edit_focus_box)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__xowa_edit_data_box);
|
||||
else if (ctx.Match(k, Invk_page_edit_focus_first)) Xog_tab_itm_edit_mgr.Focus(this, Xog_html_itm.Elem_id__first_heading);
|
||||
else if (ctx.Match(k, Invk_page_dbg_html)) Xog_tab_itm_edit_mgr.Debug(this, Xog_page_mode.Tid_html);
|
||||
else if (ctx.Match(k, Invk_page_dbg_wiki)) Xog_tab_itm_edit_mgr.Debug(this, Xog_page_mode.Tid_edit);
|
||||
else if (ctx.Match(k, Invk_page_dbg_html)) Xog_tab_itm_edit_mgr.Debug(this, Xopg_view_mode.Tid_html);
|
||||
else if (ctx.Match(k, Invk_page_dbg_wiki)) Xog_tab_itm_edit_mgr.Debug(this, Xopg_view_mode.Tid_edit);
|
||||
else if (ctx.Match(k, Invk_page_goto)) Page__navigate_by_url_bar(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_page_goto_recent)) Page__navigate_by_url_bar(app.User().History_mgr().Get_at_last(app));
|
||||
else if (ctx.Match(k, Invk_history_bwd)) {Page__navigate_by_history(Bool_.N);}
|
||||
@ -119,7 +119,7 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
}
|
||||
private void Win__link_clicked(String anchor_raw) {
|
||||
String url = url_box.Text();
|
||||
int pos = String_.FindFwd(url, gplx.xowa.html.Xoh_html_tag.Const_anchor);
|
||||
int pos = String_.FindFwd(url, gplx.html.Html_tag_.Anchor_str);
|
||||
if (pos != Bry_.NotFound) url = String_.Mid(url, 0, pos);
|
||||
String anchor_str = Parse_evt_location_changing(anchor_raw);
|
||||
byte[] anchor_bry = Bry_.new_utf8_(anchor_str);
|
||||
@ -142,14 +142,14 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
app.Gfs_mgr().Run_str(snippet);
|
||||
}
|
||||
private static String Parse_evt_location_changing(String v) { // EX: about:blank#anchor -> anchor
|
||||
int pos = String_.FindFwd(v, gplx.xowa.html.Xoh_html_tag.Const_anchor);
|
||||
int pos = String_.FindFwd(v, gplx.html.Html_tag_.Anchor_str);
|
||||
return pos == Bry_.NotFound
|
||||
? null
|
||||
: String_.Mid(v, pos + 1);
|
||||
}
|
||||
public void Page__mode_(byte new_mode_tid) {
|
||||
Xog_tab_itm tab = tab_mgr.Active_tab(); Xoa_page page = tab.Page();
|
||||
if ( new_mode_tid == Xog_page_mode.Tid_read // used to be && cur_view_tid == Edit; removed clause else redlinks wouldn't show when going form html to read (or clicking read multiple times) DATE: 2013-11-26;
|
||||
if ( new_mode_tid == Xopg_view_mode.Tid_read // used to be && cur_view_tid == Edit; removed clause else redlinks wouldn't show when going form html to read (or clicking read multiple times) DATE: 2013-11-26;
|
||||
&& !page.Missing() // if new page, don't try to reload
|
||||
) {
|
||||
// NOTE: if moving from "Edit" to "Read", reload page (else Preview changes will still show); NOTE: do not call Exec_page_reload / Exec_page_refresh, which will fire redlinks code
|
||||
|
@ -17,6 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_consts {
|
||||
public static final String
|
||||
Atr_xowa_title_str = "xowa_title"
|
||||
;
|
||||
public static final byte[]
|
||||
__end = Bry_.new_ascii_(">")
|
||||
, __end_quote = Bry_.new_ascii_("\">")
|
||||
@ -46,6 +49,8 @@ public class Xoh_consts {
|
||||
, Title_atr = Bry_.new_ascii_("\" title=\"")
|
||||
, Id_atr = Bry_.new_ascii_(" id=\"")
|
||||
, Style_atr = Bry_.new_ascii_(" style=\"")
|
||||
, Atr_xowa_title_bry = Bry_.new_ascii_(Atr_xowa_title_str)
|
||||
;
|
||||
|
||||
public static final int Nbsp_int = 160;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.btries.*; import gplx.html.*; import gplx.xowa.wikis.*; import gplx.xowa.net.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*;
|
||||
import gplx.xowa.parsers.apos.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.lnkes.*; import gplx.xowa.parsers.hdrs.*; import gplx.xowa.parsers.lists.*; import gplx.xowa.html.lnkis.*;
|
||||
import gplx.xowa.xtns.*; import gplx.xowa.xtns.dynamicPageList.*; import gplx.xowa.xtns.math.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.xtns.cite.*;
|
||||
public class Xoh_html_wtr {
|
||||
private Xow_wiki wiki; private Xoa_app app; private Xoa_page page; private Xop_xatr_whitelist_mgr whitelist_mgr;
|
||||
@ -37,27 +37,27 @@ public class Xoh_html_wtr {
|
||||
public Xoh_lnki_wtr Lnki_wtr() {return lnki_wtr;} private Xoh_lnki_wtr lnki_wtr;
|
||||
public Xoh_lnke_wtr Lnke_wtr() {return lnke_wtr;} private Xoh_lnke_wtr lnke_wtr;
|
||||
public Ref_html_wtr Ref_wtr() {return ref_wtr;} private Ref_html_wtr ref_wtr;
|
||||
public void Init_by_page(Xop_ctx ctx, Xoa_page page) {this.page = page; lnki_wtr.Init_by_page(ctx, page);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_root_tkn root) {Write_all(bfr, ctx, Xoh_html_wtr_ctx.Basic, src, root);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_root_tkn root) {
|
||||
public void Init_by_page(Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xoa_page page) {this.page = page; lnki_wtr.Init_by_page(ctx, hctx, src, page);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_root_tkn root) {Write_all(bfr, ctx, Xoh_wtr_ctx.Basic, src, root);}
|
||||
public void Write_all(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_root_tkn root) {
|
||||
try {
|
||||
indent_level = 0; this.page = ctx.Cur_page();
|
||||
page.Xwiki_langs().Clear(); // HACK: always clear langs; necessary for reload
|
||||
lnki_wtr.Init_by_page(ctx, ctx.Cur_page());
|
||||
lnki_wtr.Init_by_page(ctx, hctx, src, ctx.Cur_page());
|
||||
Write_tkn(bfr, ctx, hctx, src, null, -1, root);
|
||||
}
|
||||
finally {
|
||||
page.Category_list_(page.Html_data().Ctgs_to_ary());
|
||||
}
|
||||
}
|
||||
public void Write_tkn_ary(Bry_bfr bfr, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_tkn_itm[] ary) {
|
||||
public void Write_tkn_ary(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_itm[] ary) {
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Xop_tkn_itm itm = ary[i];
|
||||
Write_tkn(bfr, ctx, hctx, src, itm, i, itm);
|
||||
}
|
||||
}
|
||||
public void Write_tkn(Bry_bfr bfr, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_tkn_itm tkn) {
|
||||
public void Write_tkn(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_tkn_itm tkn) {
|
||||
if (tkn.Ignore()) return;
|
||||
switch (tkn.Tkn_tid()) {
|
||||
case Xop_tkn_itm_.Tid_arg_itm:
|
||||
@ -94,16 +94,16 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Html_ncr(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_num tkn) {
|
||||
@gplx.Virtual public void Html_ncr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_num tkn) {
|
||||
if (tkn.Val() < Byte_ascii.Max_7_bit) // NOTE: must "literalize"; <nowiki> converts wiki chars to ncrs, which must be "literalized: EX: <nowiki>[[A]]</nowiki> -> \\A]] which must be converted back to [[A]]
|
||||
bfr.Add(tkn.Str_as_bry());
|
||||
else
|
||||
bfr.Add_byte(Byte_ascii.Amp).Add_byte(Byte_ascii.Hash).Add_int_variable(tkn.Val()).Add_byte(Byte_ascii.Semic); // NOTE: do not literalize, else browser may not display multi-char bytes properly; EX:   gets added as   not as {192,160}; DATE:2013-12-09
|
||||
}
|
||||
@gplx.Virtual public void Html_ref(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_txt tkn) {tkn.Print_to_html(bfr);}
|
||||
@gplx.Virtual public void Html_ref(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_amp_tkn_txt tkn) {tkn.Print_to_html(bfr);}
|
||||
private static final byte[] Bry_hdr_bgn = Bry_.new_ascii_("<span class='mw-headline' id='"), Bry_hdr_end = Bry_.new_ascii_("</span>");
|
||||
@gplx.Virtual public void Hr(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hr_tkn tkn) {bfr.Add(Tag_hr);}
|
||||
@gplx.Virtual public void Hdr(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hdr_tkn hdr) {
|
||||
@gplx.Virtual public void Hr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hr_tkn tkn) {bfr.Add(Tag_hr);}
|
||||
@gplx.Virtual public void Hdr(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_hdr_tkn hdr) {
|
||||
// page.Hdrs_id_bld(hdr, src);
|
||||
if (hdr.Hdr_html_first() && cfg.Toc_show() && !page.Hdr_mgr().Toc_manual()) { // __TOC__ not specified; place at top; NOTE: if __TOC__ was specified, then it would be placed wherever __TOC__ appears
|
||||
wiki.Html_mgr().Toc_mgr().Html(ctx.Cur_page(), src, bfr);
|
||||
@ -132,7 +132,7 @@ public class Xoh_html_wtr {
|
||||
bfr.Add(Tag_hdr_end).Add_int(hdr_len, 1, 1).Add_byte(Tag__end).Add_byte_nl();// NOTE: do not need to check hdr_len b/c it is impossible for end to occur without bgn
|
||||
}
|
||||
}
|
||||
public void Apos(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_apos_tkn apos) {
|
||||
public void Apos(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_apos_tkn apos) {
|
||||
if (hctx.Mode_is_alt()) return; // ignore apos if alt; EX: [[File:A.png|''A'']] should have alt of A; DATE:2013-10-25
|
||||
int literal_apos = apos.Apos_lit();
|
||||
if (literal_apos > 0)
|
||||
@ -155,7 +155,7 @@ public class Xoh_html_wtr {
|
||||
}
|
||||
}
|
||||
public static byte[] Ttl_to_title(byte[] ttl) {return ttl;} // FUTURE: swap html chars?
|
||||
public void List(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_list_tkn list) {
|
||||
public void List(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_list_tkn list) {
|
||||
if (hctx.Mode_is_alt()) { // alt; add literally; EX: "*" for "\n*"; note that \n is added in NewLine()
|
||||
if (list.List_bgn() == Bool_.Y_byte) { // bgn tag
|
||||
bfr.Add_byte(list.List_itmTyp()); // add literal byte
|
||||
@ -174,7 +174,7 @@ public class Xoh_html_wtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void List_grp_bgn(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
@gplx.Virtual public void List_grp_bgn(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol: tag = Tag_list_grp_ol_bgn; break;
|
||||
@ -188,7 +188,7 @@ public class Xoh_html_wtr {
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
@gplx.Virtual public void List_itm_bgn(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
@gplx.Virtual public void List_itm_bgn(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
case Xop_list_tkn_.List_itmTyp_ol:
|
||||
@ -202,7 +202,7 @@ public class Xoh_html_wtr {
|
||||
bfr.Add(tag);
|
||||
++indent_level;
|
||||
}
|
||||
@gplx.Virtual public void List_grp_end(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
@gplx.Virtual public void List_grp_end(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
@ -217,7 +217,7 @@ public class Xoh_html_wtr {
|
||||
bfr.Add(tag);
|
||||
}
|
||||
|
||||
@gplx.Virtual public void List_itm_end(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
@gplx.Virtual public void List_itm_end(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, byte type) {
|
||||
--indent_level;
|
||||
byte[] tag = null;
|
||||
switch (type) {
|
||||
@ -231,7 +231,7 @@ public class Xoh_html_wtr {
|
||||
if (indent_level > 0) bfr.Add_byte_repeat(Byte_ascii.Space, indent_level * 2);
|
||||
bfr.Add(tag);
|
||||
}
|
||||
@gplx.Virtual public void NewLine(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_nl_tkn tkn) {
|
||||
@gplx.Virtual public void NewLine(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_nl_tkn tkn) {
|
||||
if (hctx.Mode_is_alt())
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
@ -240,10 +240,10 @@ public class Xoh_html_wtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Space(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_space_tkn space) {
|
||||
public void Space(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tkn_grp grp, int sub_idx, Xop_space_tkn space) {
|
||||
bfr.Add_byte_repeat(Byte_ascii.Space, space.Src_end_grp(grp, sub_idx) - space.Src_bgn_grp(grp, sub_idx)); // NOTE: lnki.caption will convert \n to \s; see Xop_nl_lxr; PAGE:en.w:Schwarzschild radius
|
||||
}
|
||||
@gplx.Virtual public void Para(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_para_tkn para) {
|
||||
@gplx.Virtual public void Para(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_para_tkn para) {
|
||||
if (para.Nl_bgn() && bfr.Len() > 0) {
|
||||
if (hctx.Mode_is_alt())
|
||||
bfr.Add_byte_space();
|
||||
@ -269,7 +269,7 @@ public class Xoh_html_wtr {
|
||||
if (!bfr.Match_end_byt_nl_or_bos()) bfr.Add_byte_nl();
|
||||
if (src_bgn != 0) bfr.Add_byte_nl();
|
||||
}
|
||||
@gplx.Virtual public void Pre(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_pre_tkn pre) {
|
||||
@gplx.Virtual public void Pre(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_pre_tkn pre) {
|
||||
switch (pre.Pre_tid()) {
|
||||
case Xop_pre_tkn.Pre_tid_bgn:
|
||||
bfr.Add(Tag_pre_bgn);
|
||||
@ -279,13 +279,13 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Bry(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_bry_tkn bry) {
|
||||
@gplx.Virtual public void Bry(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_bry_tkn bry) {
|
||||
bfr.Add(bry.Val());
|
||||
}
|
||||
@gplx.Virtual public void Vnt(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_vnt_tkn vnt) {
|
||||
@gplx.Virtual public void Vnt(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_vnt_tkn vnt) {
|
||||
Xop_vnt_html_wtr.Write(this, ctx, hctx, bfr, src, vnt); // NOTE: using wiki, b/c getting nullPointer with ctx during mass parse
|
||||
}
|
||||
@gplx.Virtual public void Under(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_under_tkn under) {
|
||||
@gplx.Virtual public void Under(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_under_tkn under) {
|
||||
if (hctx.Mode_is_alt()) return;
|
||||
switch (under.Under_tid()) {
|
||||
case Xol_kwd_grp_.Id_toc:
|
||||
@ -295,7 +295,7 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@gplx.Virtual public void Xnde(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
@gplx.Virtual public void Xnde(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
if (hctx.Mode_is_alt()) {
|
||||
if (xnde.Tag_close_bgn() > 0) // NOTE: some tags are not closed; WP.EX: France; <p>
|
||||
Xoh_html_wtr_escaper.Escape(app, bfr, src, xnde.Tag_open_end(), xnde.Tag_close_bgn(), true, false);
|
||||
@ -433,7 +433,7 @@ public class Xoh_html_wtr {
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void Write_xnde(Bry_bfr bfr, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Xop_xnde_tkn xnde, Xop_xnde_tag tag, int tag_id, byte[] src) {
|
||||
private void Write_xnde(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, Xop_xnde_tag tag, int tag_id, byte[] src) {
|
||||
byte[] name = tag.Name_bry();
|
||||
boolean at_bgn = true;
|
||||
Bry_bfr ws_bfr = wiki.Utl_bry_bfr_mkr().Get_b512(); // create separate ws_bfr to handle "a<b> c </b>d" -> "a <b>c</b> d"
|
||||
@ -476,7 +476,7 @@ public class Xoh_html_wtr {
|
||||
if (ws_bfr.Len() > 0) bfr.Add_bfr_and_clear(ws_bfr); // dump any leftover ws to bfr; handles "<b>c </b>" -> "<b>c</b> "
|
||||
ws_bfr.Mkr_rls();
|
||||
}
|
||||
public void Xnde_atrs(int tag_id, Xoh_html_wtr_ctx hctx, byte[] src, int bgn, int end, Xop_xatr_itm[] ary, Bry_bfr bfr) {
|
||||
public void Xnde_atrs(int tag_id, Xoh_wtr_ctx hctx, byte[] src, int bgn, int end, Xop_xatr_itm[] ary, Bry_bfr bfr) {
|
||||
if (ary == null) return; // NOTE: some nodes will have null xatrs b/c of whitelist; EX: <pre style="overflow:auto">a</pre>; style is not on whitelist so not xatr generated, but xatr_bgn will != -1
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
@ -487,7 +487,7 @@ public class Xoh_html_wtr {
|
||||
}
|
||||
}
|
||||
|
||||
public static void Xnde_atr_write(Bry_bfr bfr, Xoa_app app, Xoh_html_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr) {
|
||||
public static void Xnde_atr_write(Bry_bfr bfr, Xoa_app app, Xoh_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr) {
|
||||
byte[] atr_key = atr.Key_bry();
|
||||
if ( hctx.Mode_is_display_title()
|
||||
&& Xoh_display_ttl_wtr._.Is_style_restricted(bfr, hctx, src, atr, atr_key))
|
||||
@ -519,12 +519,12 @@ public class Xoh_html_wtr {
|
||||
private static void Xnde_atr_write_id(Bry_bfr bfr, Xoa_app app, byte[] bry, int bgn, int end) {
|
||||
app.Encoder_mgr().Id().Encode(bfr, bry, bgn, end);
|
||||
}
|
||||
private void Xnde_subs(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
private void Xnde_subs(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde) {
|
||||
int subs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < subs_len; i++)
|
||||
Write_tkn(bfr, ctx, hctx, src, xnde, i, xnde.Subs_get(i));
|
||||
}
|
||||
private void Xnde_subs_escape(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde, boolean amp_enable, boolean nowiki) {
|
||||
private void Xnde_subs_escape(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_xnde_tkn xnde, boolean amp_enable, boolean nowiki) {
|
||||
int xndesubs_len = xnde.Subs_len();
|
||||
for (int i = 0; i < xndesubs_len; i++) {
|
||||
Xop_tkn_itm sub = xnde.Subs_get(i);
|
||||
@ -558,7 +558,7 @@ public class Xoh_html_wtr {
|
||||
}
|
||||
}
|
||||
public Bool_obj_ref Queue_add_ref() {return queue_add_ref;} Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
|
||||
public void Tblw(Xop_ctx ctx, Xoh_html_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tblw_tkn tkn, byte[] bgn, byte[] end, boolean tblw_bgn) {
|
||||
public void Tblw(Xop_ctx ctx, Xoh_wtr_ctx hctx, Bry_bfr bfr, byte[] src, Xop_tblw_tkn tkn, byte[] bgn, byte[] end, boolean tblw_bgn) {
|
||||
if (hctx.Mode_is_alt()) // add \s for each \n
|
||||
bfr.Add_byte_space();
|
||||
else {
|
||||
@ -621,7 +621,7 @@ class Xoh_display_ttl_wtr {
|
||||
;
|
||||
private Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_ascii_()
|
||||
.Add_str_byte__many(Byte_.int_(0), "display", "user-select", "visibility"); // if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
|
||||
public boolean Is_style_restricted(Bry_bfr bfr, Xoh_html_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr, byte[] atr_key) {
|
||||
public boolean Is_style_restricted(Bry_bfr bfr, Xoh_wtr_ctx hctx, byte[] src, Xop_xatr_itm atr, byte[] atr_key) {
|
||||
if (atr_key != null
|
||||
&& Bry_.Eq(atr_key, Atr_key_style)
|
||||
) {
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
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.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*;
|
||||
public interface Xoh_lnki_file_wkr {
|
||||
void Write_img_full(Bry_bfr bfr, Xof_xfer_itm xfer_itm, int elem_id, byte[] link_ref, byte[] html_view_src, int html_w, int html_h, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_cls, byte[] anchor_rel, byte[] anchor_title, byte[] itm_cls);
|
||||
}
|
||||
class Xoh_lnki_file_wkr_basic implements Xoh_lnki_file_wkr {
|
||||
private Bry_fmtr img_full_fmtr;
|
||||
public void Init(Bry_fmtr img_full_fmtr) {
|
||||
this.img_full_fmtr = img_full_fmtr;
|
||||
}
|
||||
public void Write_img_full(Bry_bfr bfr, Xof_xfer_itm xfer_itm, int elem_id, byte[] lnki_href, byte[] html_view_src, int html_w, int html_h, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_cls, byte[] anchor_rel, byte[] anchor_title, byte[] itm_cls) {
|
||||
img_full_fmtr.Bld_bfr_many(bfr, elem_id, lnki_href, html_view_src, html_w, html_h, lnki_alt_text, lnki_ttl, anchor_cls, anchor_rel, anchor_title, itm_cls);
|
||||
}
|
||||
}
|
@ -1,302 +0,0 @@
|
||||
/*
|
||||
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.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_lnki_file_wtr {
|
||||
private Xoh_lnki_file_wkr_basic lnki_file_wkr_basic = new Xoh_lnki_file_wkr_basic();
|
||||
public Xoh_lnki_file_wtr(Xow_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
|
||||
this.html_mgr = html_mgr;
|
||||
this.wiki = wiki; this.html_wtr = html_wtr; bfr_mkr = wiki.Utl_bry_bfr_mkr();
|
||||
lnki_file_wkr_basic.Init(html_mgr.Lnki_full_image());
|
||||
} private Xow_html_mgr html_mgr; private boolean lnki_title_enabled;
|
||||
private Xow_wiki wiki; private Xoh_html_wtr html_wtr;
|
||||
private Xoh_lnki_txt_fmtr media_alt_fmtr = new Xoh_lnki_txt_fmtr(), caption_fmtr = new Xoh_lnki_txt_fmtr(); private Bry_bfr_mkr bfr_mkr;
|
||||
private Xoa_url tmp_url = Xoa_url.blank_();
|
||||
public void Write_or_queue(Bry_bfr bfr, Xoa_page page, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {
|
||||
Xof_xfer_itm xfer_itm = this.Lnki_eval(ctx, page, lnki, queue_add_ref);
|
||||
this.Write_media(bfr, hctx, src, lnki, xfer_itm, Alt_text(src, lnki));
|
||||
}
|
||||
public void Write_or_queue(Bry_bfr bfr, Xoa_page page, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {
|
||||
Xof_xfer_itm xfer_itm = this.Lnki_eval(ctx, page, lnki, queue_add_ref);
|
||||
this.Write_media(bfr, hctx, src, lnki, xfer_itm, alt_text);
|
||||
} private Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
|
||||
public void Page_bgn(Xoa_page page) {
|
||||
cfg_alt_defaults_to_caption = page.Wiki().App().User().Wiki().Html_mgr().Imgs_mgr().Alt_defaults_to_caption().Val();
|
||||
} private boolean cfg_alt_defaults_to_caption = true;
|
||||
private Xop_ctx ctx;
|
||||
public Xof_xfer_itm Lnki_eval(Xop_ctx ctx, Xoa_page page, Xop_lnki_tkn lnki, Bool_obj_ref queue_add_ref) {return Lnki_eval(ctx, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Lnki_w(), lnki.Lnki_h(), lnki.Upright(), lnki.Thumbtime(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Id_media, queue_add_ref);}
|
||||
public Xof_xfer_itm Lnki_eval(Xop_ctx ctx, Xof_xfer_queue queue, byte[] lnki_ttl, byte lnki_type, int lnki_w, int lnki_h, double lnki_upright, double lnki_thumbtime, int lnki_page, boolean lnki_is_media_ns, Bool_obj_ref queue_add_ref) {
|
||||
this.ctx = ctx;
|
||||
queue_add_ref.Val_n_();
|
||||
tmp_xfer_itm.Clear().Init_by_lnki(lnki_ttl, Bry_.Empty, lnki_type, lnki_w, lnki_h, lnki_upright, lnki_thumbtime, lnki_page);
|
||||
boolean found = Find_file(ctx, tmp_xfer_itm);
|
||||
boolean file_queue_add = File_queue_add(wiki, tmp_xfer_itm, lnki_is_media_ns, found);
|
||||
Xof_xfer_itm rv = tmp_xfer_itm;
|
||||
if (file_queue_add) {
|
||||
queue_add_ref.Val_y_();
|
||||
return Queue_add_manual(queue, tmp_xfer_itm);
|
||||
}
|
||||
rv.File_found_(found);
|
||||
return rv;
|
||||
} private Xof_xfer_itm tmp_xfer_itm = new Xof_xfer_itm();
|
||||
private boolean Find_file(Xop_ctx ctx, Xof_xfer_itm xfer_itm) {
|
||||
if (wiki.File_mgr().Version() == Xow_file_mgr.Version_2)
|
||||
return ctx.Cur_page().Lnki_file_mgr().Find(wiki, ctx.Cur_page(), Xof_exec_tid.Tid_wiki_page, xfer_itm);
|
||||
else
|
||||
return wiki.File_mgr().Find_meta(xfer_itm);
|
||||
}
|
||||
public static Xof_xfer_itm Queue_add_manual(Xof_xfer_queue queue, Xof_xfer_itm xfer_itm) {
|
||||
int elem_id = queue.Elem_id().Val_add();
|
||||
Xof_xfer_itm rv = xfer_itm.Clone().Html_elem_atrs_(elem_id, Xof_html_elem.Tid_img);
|
||||
queue.Add(rv);
|
||||
return rv;
|
||||
}
|
||||
private static boolean File_queue_add(Xow_wiki wiki, Xof_xfer_itm xfer_itm, boolean lnki_is_media_ns, boolean found) {
|
||||
if (!wiki.File_mgr().Cfg_download().Enabled()) return false;
|
||||
// if (xfer_itm.Meta_itm() == null) return false; // occurs when repos are missing; // DELETE: caused Redownload_missing to fail; no reason why missing shouldn't return a default repo; DATE:2013-01-26
|
||||
if (lnki_is_media_ns) return false;
|
||||
switch (wiki.File_mgr().Cfg_download().Redownload()) {
|
||||
case Xof_cfg_download.Redownload_none:
|
||||
if (found) return false;
|
||||
if (!found
|
||||
&& xfer_itm.Meta_itm() != null // null check; fsdb_call does not set meta
|
||||
&& xfer_itm.Meta_itm().Orig_exists() == Xof_meta_itm.Exists_n)
|
||||
return false; // not found, and orig_exists is n; do not download again (NOTE: even if current lnki is thumb, don't bother looking for thumb if orig is missing)
|
||||
break;
|
||||
case Xof_cfg_download.Redownload_missing:
|
||||
if (found) return false;
|
||||
break;
|
||||
case Xof_cfg_download.Redownload_all:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private Xop_link_parser tmp_link_parser = new Xop_link_parser();
|
||||
private Xohp_title_wkr anchor_title_wkr = new Xohp_title_wkr();
|
||||
public void Write_media(Bry_bfr bfr, Xoh_html_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, byte[] lnki_alt_text) {
|
||||
try {
|
||||
lnki_title_enabled = html_wtr.Cfg().Lnki_title();
|
||||
int elem_id = xfer_itm.Html_uid();
|
||||
int div_width = xfer_itm.Html_w();
|
||||
if (div_width < 1 && wiki.File_mgr().Version_2_y()) // NOTE: html_w is -1 for v2 and missing files; use lnki_w if available; primarily affects audio files with specified width; [[File:A.oga|30px]]; DATE:2014-05-03
|
||||
div_width = xfer_itm.Lnki_w();
|
||||
if (div_width < 1) div_width = wiki.Html_mgr().Img_thumb_width();
|
||||
int lnki_halign = lnki.Align_h();
|
||||
if (lnki_halign == Xop_lnki_align_h.Null) lnki_halign = wiki.Lang().Img_thumb_halign_default(); // if halign is not supplied, then default to align for language
|
||||
byte[] lnki_halign_bry = Xop_lnki_align_h.Html_names[lnki_halign];
|
||||
byte[] lnki_href = wiki.App().Href_parser().Build_to_bry(wiki, lnki.Ttl());
|
||||
byte[] html_orig_src = xfer_itm.Html_orig_src();
|
||||
byte[] html_view_src = xfer_itm.Html_view_src();
|
||||
byte[] content = Bry_.Empty;
|
||||
byte[] lnki_ttl = lnki.Ttl().Page_txt();
|
||||
Xof_ext lnki_ext = xfer_itm.Lnki_ext();
|
||||
if ( html_mgr.Img_suppress_missing_src() // option to suppress src when file is missing
|
||||
&& !xfer_itm.Html_pass() // file is missing; wipe values and wait for "correct" info before regenerating; mostly to handle unknown redirects
|
||||
&& !lnki_ext.Id_is_media() // file is media; never suppress; src needs to be available for "click" on play; note that most media will be missing (not downloaded)
|
||||
&& lnki.Ns_id() != Xow_ns_.Id_media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30
|
||||
) {
|
||||
html_orig_src = html_view_src = Bry_.Empty; // null out src
|
||||
}
|
||||
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_media) { // REF.MW:Linker.php|makeMediaLinkObj; NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; see Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
|
||||
html_mgr.Lnki_full_media().Bld_bfr_many(bfr, html_orig_src // NOTE: should always use orig_src; was using view_src; DATE:2014-01-19
|
||||
, lnki.Ttl().Page_txt(), Caption(src, lnki, Xoh_html_wtr_ctx.Basic, html_orig_src));
|
||||
return;
|
||||
}
|
||||
if (lnki_ext.Id_is_media()) {
|
||||
if ( Xof_ext_.Id_is_video_strict(lnki_ext.Id()) // id is .ogv or .webm
|
||||
|| ( lnki_ext.Id_is_ogg() // id is ogg
|
||||
&& wiki.File_mgr().Version_1_y() // version is v1 (v2 always marks ogg as aud); DATE:2014-02-01
|
||||
&& ( xfer_itm.Html_pass() // NOTE: xfer_itm.Html_pass() checks for video .ogg files (ext = .ogg and thumb is available); EX: WWI;
|
||||
|| xfer_itm.Meta_itm().State_new() // NOTE: State_new() will always assume that ogg is video; needed for 1st load and dynamic updates
|
||||
)
|
||||
)
|
||||
) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
if (Xop_lnki_type.Id_defaults_to_thumb(lnki.Lnki_type())) {
|
||||
content = Video(src, hctx, lnki, xfer_itm, elem_id, true, lnki_href, html_view_src, html_orig_src, lnki_alt_text);
|
||||
}
|
||||
else {
|
||||
content = Video(src, hctx, lnki, xfer_itm, elem_id, false, lnki_href, html_view_src, html_orig_src, lnki_alt_text);
|
||||
html_mgr.Plain().Bld_bfr_many(bfr, content);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (lnki_ext.Id_is_audio()) {
|
||||
content = Audio(src, hctx, lnki, elem_id, lnki_href, html_orig_src, lnki_alt_text);
|
||||
if (lnki.Media_icon())
|
||||
html_mgr.Lnki_thumb_core().Bld_bfr_many(bfr, div_width, lnki_halign_bry, content, elem_id);
|
||||
else
|
||||
html_mgr.Plain().Bld_bfr_many(bfr, content);
|
||||
return;
|
||||
}
|
||||
html_mgr.Lnki_thumb_core().Bld_bfr_many(bfr, div_width, lnki_halign_bry, content, elem_id);
|
||||
}
|
||||
else { // image
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Bry_div_bgn_center);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] anchor_title = lnki_title_enabled
|
||||
? Make_anchor_title(tmp_bfr, src, lnki, lnki_ttl, anchor_title_wkr) // NOTE: Make_anchor_title should only be called if there is no caption, else refs may not show; DATE:2014-03-05
|
||||
: Bry_.Empty;
|
||||
Xoh_lnki_file_wkr lnki_file_wkr = lnki.Lnki_file_wkr(); if (lnki_file_wkr == null) lnki_file_wkr = lnki_file_wkr_basic;
|
||||
if (Xop_lnki_type.Id_is_thumbable(lnki.Lnki_type())) { // is "thumb"
|
||||
if (bfr.Len() > 0) bfr.Add_byte_nl();
|
||||
content = Image_thumb(lnki_file_wkr, src, hctx, lnki, xfer_itm, elem_id, lnki_href, html_view_src, html_orig_src, lnki_alt_text, lnki_ttl, anchor_title);
|
||||
html_mgr.Lnki_thumb_core().Bld_bfr_many(bfr, div_width, lnki_halign_bry, content, elem_id);
|
||||
}
|
||||
else {
|
||||
if ( cfg_alt_defaults_to_caption
|
||||
&& Bry_.Len_eq_0(lnki_alt_text) // NOTE: if no alt, always use caption; DATE:2013-07-22
|
||||
&& !lnki.Alt_exists()) { // unless blank alt exists; EX: [[File:A.png|a|alt=]] should have alt of "", not "a"
|
||||
Caption(src, lnki, Xoh_html_wtr_ctx.Alt, html_orig_src).XferAry(tmp_bfr, 0);
|
||||
lnki_alt_text = tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
switch (lnki.Align_h()) {
|
||||
case Xop_lnki_align_h.Left: bfr.Add(Bry_div_float_left).Add_byte_nl(); break;
|
||||
case Xop_lnki_align_h.Right: bfr.Add(Bry_div_float_right).Add_byte_nl(); break;
|
||||
case Xop_lnki_align_h.None: bfr.Add(Bry_div_float_none).Add_byte_nl(); break;
|
||||
}
|
||||
Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn();
|
||||
if (lnki_link_tkn == Arg_nde_tkn.Null)
|
||||
lnki_file_wkr.Write_img_full(bfr, xfer_itm, elem_id, lnki_href, html_view_src, xfer_itm.Html_w(), xfer_itm.Html_h(), lnki_alt_text, lnki_ttl, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, Img_cls(lnki));
|
||||
else {
|
||||
Arg_itm_tkn link_tkn = lnki_link_tkn.Val_tkn();
|
||||
byte[] link_ref = link_tkn.Dat_to_bry(src);
|
||||
byte[] link_ref_new = tmp_link_parser.Parse(tmp_bfr, tmp_url, wiki, link_ref, lnki_href);
|
||||
link_ref = link_ref_new == null ? lnki_href: link_ref_new; // if parse fails, then assign to lnki_href; EX:link={{{1}}}
|
||||
link_ref = ctx.App().Encoder_mgr().Href_quotes().Encode(link_ref); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
|
||||
lnki_ttl = Bry_.Coalesce(lnki_ttl, tmp_link_parser.Html_xowa_ttl());
|
||||
lnki_file_wkr.Write_img_full(bfr, xfer_itm, elem_id, link_ref, html_view_src, xfer_itm.Html_w(), xfer_itm.Html_h(), lnki_alt_text, lnki_ttl, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anchor_title, Img_cls(lnki));
|
||||
}
|
||||
switch (lnki.Align_h()) {
|
||||
case Xop_lnki_align_h.Left:
|
||||
case Xop_lnki_align_h.Right:
|
||||
case Xop_lnki_align_h.None: bfr.Add(Bry_div_end); break;
|
||||
}
|
||||
}
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Bry_div_end);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
wiki.App().Usr_dlg().Warn_many("", "", "lnki_wtr:fatal error while writing lnki: ttl=~{0} err=~{1}", String_.new_utf8_(lnki.Ttl().Raw()), Err_.Message_gplx_brief(e));
|
||||
}
|
||||
}
|
||||
private static byte[] Make_anchor_title(Bry_bfr bfr, byte[] src, Xop_lnki_tkn lnki, byte[] lnki_ttl, Xohp_title_wkr anchor_title_wkr) {
|
||||
switch (lnki.Lnki_type()) {
|
||||
case Xop_lnki_type.Id_thumb: // If the image is a thumb, do not add a title / alt, even if a caption is available
|
||||
case Xop_lnki_type.Id_frame:
|
||||
return Bry_.Empty;
|
||||
case Xop_lnki_type.Id_frameless: // If the image is frameless, add the caption as a title / alt. If no caption is available, do not add a title / alt
|
||||
break;
|
||||
}
|
||||
Xop_tkn_itm anchor_title_tkn = lnki.Caption_tkn();
|
||||
if (anchor_title_tkn == Xop_tkn_null.Null_tkn) return Bry_.Empty; // no caption; return empty; (do not use lnki); DATE:2013-12-31
|
||||
bfr.Add(Anchor_title);
|
||||
anchor_title_wkr.Set(src, anchor_title_tkn).XferAry(bfr, 0);
|
||||
bfr.Add_byte(Byte_ascii.Quote);
|
||||
return bfr.XtoAryAndClear();
|
||||
}
|
||||
private byte[] Video(byte[] src, Xoh_html_wtr_ctx hctx, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int elem_id, boolean lnki_thumb, byte[] lnki_href, byte[] html_view_src, byte[] html_orig_src, byte[] lnki_alt_text) {
|
||||
int thumb_w = xfer_itm.Html_w();
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
int play_btn_width = thumb_w; if (play_btn_width < 1) play_btn_width = wiki.Html_mgr().Img_thumb_width();
|
||||
if (lnki_thumb)
|
||||
html_mgr.Lnki_thumb_file_video().Bld_bfr_many(tmp_bfr, Play_btn(elem_id, play_btn_width, play_btn_width, html_orig_src, lnki.Ttl().Page_txt()), Img_thumb(lnki, xfer_itm, elem_id, lnki_href, html_view_src, lnki_alt_text), Caption_div(src, lnki, html_orig_src, lnki_href), Alt_html(src, lnki));
|
||||
else
|
||||
html_mgr.Lnki_thumb_file_video().Bld_bfr_many(tmp_bfr, Play_btn(elem_id, play_btn_width, play_btn_width, html_orig_src, lnki.Ttl().Page_txt()), Img_thumb(lnki, xfer_itm, elem_id, lnki_href, html_view_src, lnki_alt_text), Bry_.Empty, Bry_.Empty);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Image_thumb(Xoh_lnki_file_wkr lnki_file_wkr, byte[] src, Xoh_html_wtr_ctx hctx, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int elem_id, byte[] lnki_href, byte[] html_view_src, byte[] html_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) {
|
||||
byte[] lnki_alt_html = Alt_html(src, lnki);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] lnki_class = xfer_itm.Html_pass()
|
||||
? Xow_html_mgr.Bry_img_class_thumbimage
|
||||
: Xow_html_mgr.Bry_img_class_none;
|
||||
lnki_file_wkr.Write_img_full(tmp_bfr, xfer_itm, elem_id, lnki_href, html_view_src, xfer_itm.Html_w(), xfer_itm.Html_h(), lnki_alt_text, lnki_ttl, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_class);
|
||||
byte[] thumb = tmp_bfr.XtoAryAndClear();
|
||||
if (!wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val()) lnki_alt_html = Bry_.Empty;
|
||||
html_mgr.Lnki_thumb_file_image().Bld_bfr_many(tmp_bfr, thumb, Caption_div(src, lnki, html_orig_src, lnki_href), lnki_alt_html);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
} private static final byte[] Anchor_title = Bry_.new_utf8_(" title=\"");
|
||||
private byte[] Audio(byte[] src, Xoh_html_wtr_ctx hctx, Xop_lnki_tkn lnki, int elem_id, byte[] lnki_href, byte[] html_orig_src, byte[] lnki_alt_text) {
|
||||
byte[] info_btn = Bry_.Empty;
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
if (lnki.Media_icon()) {
|
||||
html_mgr.Lnki_thumb_part_info_btn().Bld_bfr_many(tmp_bfr, wiki.Html_mgr().Img_media_info_btn(), lnki_href);
|
||||
info_btn = tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
int play_btn_width = lnki.Lnki_w(); if (play_btn_width < 1) play_btn_width = wiki.Html_mgr().Img_thumb_width(); // if no width set width to default img width
|
||||
html_mgr.Lnki_thumb_file_audio().Bld_bfr_many(tmp_bfr, Play_btn(elem_id, play_btn_width, Play_btn_max_width, html_orig_src, lnki.Ttl().Page_txt()), info_btn, Caption_div(src, lnki, html_orig_src, lnki_href), Alt_html(src, lnki));
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Img_thumb(Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int elem_id, byte[] lnki_href, byte[] html_view_src, byte[] alt) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
html_mgr.Lnki_thumb_part_image().Bld_bfr_many(tmp_bfr, elem_id, Bry_class_internal, lnki_href, lnki.Ttl().Page_txt(), html_view_src, xfer_itm.Html_w(), xfer_itm.Html_h(), alt);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Img_cls(Xop_lnki_tkn lnki) {
|
||||
if (lnki.Border() == Bool_.Y_byte) {
|
||||
return Img_cls_thumbborder;
|
||||
}
|
||||
else
|
||||
return Bry_.Empty;
|
||||
} private static final byte[] Img_cls_thumbborder = Bry_.new_ascii_(" class=\"thumbborder\"");
|
||||
public static final byte[] Bry_class_internal = Bry_.new_ascii_("image");
|
||||
private byte[] Alt_text(byte[] src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(html_wtr, ctx, Xoh_html_wtr_ctx.Alt, src, lnki.Alt_tkn().Val_tkn(), html_mgr.Plain());
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.XferAry(tmp_bfr, 0);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Alt_html(byte[] src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(html_wtr, ctx, Xoh_html_wtr_ctx.Basic, src, lnki.Alt_tkn().Val_tkn(), html_mgr.Lnki_thumb_part_alt());
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.XferAry(tmp_bfr, 0);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Caption_div(byte[] src, Xop_lnki_tkn lnki, byte[] html_orig_src, byte[] lnki_href) {
|
||||
Bry_fmtr_arg caption = Caption(src, lnki, Xoh_html_wtr_ctx.Basic, html_orig_src);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] magnify_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
html_mgr.Lnki_thumb_part_magnfiy_btn().Bld_bfr_many(tmp_bfr, wiki.Html_mgr().Img_thumb_magnify(), lnki_href, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_file_enlarge));
|
||||
magnify_btn = tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
html_mgr.Lnki_thumb_part_caption().Bld_bfr_many(tmp_bfr, magnify_btn, caption);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private Bry_fmtr_arg Caption(byte[] src, Xop_lnki_tkn lnki, Xoh_html_wtr_ctx hctx, byte[] html_orig_src) {
|
||||
return lnki.Caption_exists()
|
||||
? caption_fmtr.Set(html_wtr, ctx, hctx, src, lnki.Caption_val_tkn(), html_mgr.Plain())
|
||||
: Bry_fmtr_arg_.Null;
|
||||
}
|
||||
private byte[] Play_btn(int elem_id, int width, int max_width, byte[] html_orig_src, byte[] lnki_href) {
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
html_mgr.Lnki_thumb_part_play_btn().Bld_bfr_many(tmp_bfr, elem_id, wiki.Html_mgr().Img_media_play_btn(), width - 2, max_width, html_orig_src, lnki_href); // NOTE: -2 is fudge factor else play btn will jut out over video thumb; see Earth and ISS video
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private static final int Play_btn_max_width = 1024;
|
||||
private static final byte[] Bry_div_bgn_center = Bry_.new_ascii_("<div class=\"center\">"), Bry_div_end = Bry_.new_ascii_("</div>")
|
||||
, Bry_div_float_none = Bry_.new_ascii_("<div class=\"floatnone\">"), Bry_div_float_left = Bry_.new_ascii_("<div class=\"floatleft\">"), Bry_div_float_right = Bry_.new_ascii_("<div class=\"floatright\">");
|
||||
public static byte[] Lnki_cls_visited(gplx.xowa.users.history.Xou_history_mgr history_mgr, byte[] wiki_key, byte[] page_ttl) {
|
||||
return history_mgr.Has(wiki_key, page_ttl) ? Lnki_cls_visited_bry : Bry_.Empty;
|
||||
} private static final byte[] Lnki_cls_visited_bry = Bry_.new_ascii_(" class=\"xowa-visited\"");
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
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.html; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_lnki_txt_fmtr implements Bry_fmtr_arg { // formats alt or caption
|
||||
private Bry_fmtr fmtr; private Xoh_html_wtr wtr; private Xop_ctx ctx; private Xoh_html_wtr_ctx hctx; private byte[] src; private Xop_tkn_itm tkn;
|
||||
public Xoh_lnki_txt_fmtr Set(Xoh_html_wtr wtr, Xop_ctx ctx, Xoh_html_wtr_ctx hctx, byte[] src, Xop_tkn_itm tkn, Bry_fmtr fmtr) {
|
||||
this.wtr = wtr; this.ctx = ctx; this.hctx = hctx; this.src = src; this.tkn = tkn; this.fmtr = fmtr;
|
||||
return this;
|
||||
}
|
||||
public void XferAry(Bry_bfr trg, int idx) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr.new_();
|
||||
wtr.Write_tkn(tmp_bfr, ctx, hctx, src, null, Xoh_html_wtr.Sub_idx_null, tkn);
|
||||
byte[] bry = tmp_bfr.XtoAryAndClear();
|
||||
if (bry.length == 0) return;
|
||||
fmtr.Bld_bfr_many(trg, bry);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ 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.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.gui.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.pages.*;
|
||||
public class Xoh_page_wtr_mgr implements GfoInvkAble {
|
||||
private Xoh_page_wtr_wkr edit_wtr, html_wtr, read_wtr; private Xoa_app app;
|
||||
public Xoh_page_wtr_mgr(Xoa_app app, boolean html_capable) {
|
||||
@ -41,9 +41,9 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
|
||||
, "</html>"
|
||||
));
|
||||
this.html_capable = html_capable;
|
||||
read_wtr = new Xoh_page_wtr_wkr(Xog_page_mode.Tid_read);
|
||||
edit_wtr = new Xoh_page_wtr_wkr(Xog_page_mode.Tid_edit);
|
||||
html_wtr = new Xoh_page_wtr_wkr(Xog_page_mode.Tid_html);
|
||||
read_wtr = new Xoh_page_wtr_wkr(Xopg_view_mode.Tid_read);
|
||||
edit_wtr = new Xoh_page_wtr_wkr(Xopg_view_mode.Tid_edit);
|
||||
html_wtr = new Xoh_page_wtr_wkr(Xopg_view_mode.Tid_html);
|
||||
}
|
||||
public boolean Html_capable() {return html_capable;} public Xoh_page_wtr_mgr Html_capable_(boolean v) {html_capable = v; return this;} private boolean html_capable;
|
||||
public Bry_fmtr Page_read_fmtr() {return page_read_fmtr;}
|
||||
@ -105,9 +105,9 @@ public class Xoh_page_wtr_mgr implements GfoInvkAble {
|
||||
}
|
||||
public Xoh_page_wtr_wkr Wkr(byte output_tid) {
|
||||
switch (output_tid) {
|
||||
case Xog_page_mode.Tid_edit: return edit_wtr;
|
||||
case Xog_page_mode.Tid_html: return html_wtr;
|
||||
case Xog_page_mode.Tid_read: return read_wtr;
|
||||
case Xopg_view_mode.Tid_edit: return edit_wtr;
|
||||
case Xopg_view_mode.Tid_html: return html_wtr;
|
||||
case Xopg_view_mode.Tid_read: return read_wtr;
|
||||
default: throw Err_.unhandled(output_tid);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.html.*; import gplx.xowa.html.portal.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.html.*; import gplx.xowa.html.portal.*; import gplx.xowa.pages.*;
|
||||
public class Xoh_page_wtr_mgr_tst {
|
||||
@Before public void init() {}
|
||||
@Test public void Logo_has_correct_main_page() { // PURPOSE: Logo href should be "/site/en.wikipedia.org/wiki/", not "/wiki/Main_Page"
|
||||
@ -27,7 +27,7 @@ public class Xoh_page_wtr_mgr_tst {
|
||||
GfoInvkAble_.InvkCmd_val(portal_mgr, Xow_portal_mgr.Invk_div_logo_, Bry_.new_ascii_("~{portal_nav_main_href}"));
|
||||
portal_mgr.Init_assert();
|
||||
Xoh_page_wtr_mgr page_wtr_mgr = new Xoh_page_wtr_mgr(app, true);
|
||||
page_wtr_mgr.Gen(wiki.Ctx().Cur_page(), Xog_page_mode.Tid_read);
|
||||
page_wtr_mgr.Gen(wiki.Ctx().Cur_page(), Xopg_view_mode.Tid_read);
|
||||
Tfds.Eq(String_.new_ascii_(portal_mgr.Div_logo_bry()), "/site/en.wikipedia.org/wiki/");
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ 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.html; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.html.*; import gplx.xowa.html.portal.*; import gplx.xowa.pages.skins.*;
|
||||
import gplx.html.*; import gplx.xowa.html.portal.*; import gplx.xowa.pages.skins.*; import gplx.xowa.pages.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.gui.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
private Xop_ctx ctx; private Xoa_page page; private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
|
||||
@ -34,14 +34,14 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
wtr_page_lang.Page_(page);
|
||||
byte view_mode = page_mode;
|
||||
switch (page_mode) {
|
||||
case Xog_page_mode.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break;
|
||||
case Xog_page_mode.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xog_page_mode.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML
|
||||
case Xog_page_mode.Tid_read: fmtr = mgr.Page_read_fmtr();
|
||||
case Xopg_view_mode.Tid_edit: fmtr = mgr.Page_edit_fmtr(); break;
|
||||
case Xopg_view_mode.Tid_html: fmtr = mgr.Page_read_fmtr(); view_mode = Xopg_view_mode.Tid_read; break; // set view_mode to read, so that "read" is highlighted in HTML
|
||||
case Xopg_view_mode.Tid_read: fmtr = mgr.Page_read_fmtr();
|
||||
ctx.Cur_page().Lnki_redlinks_mgr().Page_bgn(); // not sure if this is the best place to put it, but redlinks (a) must only fire once; (b) must fire before html generation; (c) cannot fire during edit (preview will handle separately)
|
||||
break;
|
||||
}
|
||||
Write_page(html_bfr, app, wiki, mgr, page, view_mode, fmtr, this);
|
||||
if (page_mode == Xog_page_mode.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
if (page_mode == Xopg_view_mode.Tid_html) // if html, write page again, but wrap it in html skin this time
|
||||
Write_page(html_bfr, app, wiki, mgr, page, page_mode, mgr.Page_html_fmtr(), Html_utl.Escape_html_as_str(html_bfr.XtoStrAndClear()));
|
||||
wtr_page_lang.Page_(null);
|
||||
}
|
||||
@ -61,7 +61,7 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
byte[] html_content_editable = wiki.Gui_mgr().Cfg_browser().Content_editable() ? Content_editable_bry : Bry_.Empty;
|
||||
byte[] page_content_sub = Xoh_page_wtr_wkr_.Bld_page_content_sub(app, wiki, page, tmp_bfr);
|
||||
byte[] js_wikidata_bry = Wdata_wiki_mgr.Wiki_page_is_json(wiki.Domain_tid(), page.Ttl().Ns().Id()) ? app.User().Lang().Fragment_mgr().Html_js_wikidata() : Bry_.Empty;
|
||||
byte[] js_edit_toolbar_bry = view_tid == Xog_page_mode.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
|
||||
byte[] js_edit_toolbar_bry = view_tid == Xopg_view_mode.Tid_edit ? wiki.Fragment_mgr().Html_js_edit_toolbar() : Bry_.Empty;
|
||||
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
|
||||
fmtr.Bld_bfr_many(html_bfr, page.Revision_data().Id()
|
||||
, Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page.Ttl(), null) // NOTE: page_name does not show display_title (<i>). always pass in null
|
||||
@ -81,74 +81,74 @@ public class Xoh_page_wtr_wkr implements Bry_fmtr_arg {
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(html_bfr, page);
|
||||
Xoh_page_wtr_wkr_.Bld_html_end(html_bfr, page);
|
||||
}
|
||||
public void XferAry(Bry_bfr html_bfr, int idx) {
|
||||
public void XferAry(Bry_bfr bfr, int idx) {Write_body(bfr, Xoh_wtr_ctx.Basic, page);}
|
||||
public void Write_body(Bry_bfr bfr, Xoh_wtr_ctx hctx, Xoa_page page) {
|
||||
Xow_wiki wiki = page.Wiki(); Xoa_app app = wiki.App();
|
||||
byte[] data_raw = page.Data_raw();
|
||||
int ns_id = page.Ttl().Ns().Id();
|
||||
byte[] data_raw = page.Data_raw();
|
||||
byte page_tid = Xow_page_tid.Identify(wiki.Domain_tid(), ns_id, page.Ttl().Page_db());
|
||||
if (page_mode == Xog_page_mode.Tid_edit) {
|
||||
Write_mode_edit(html_bfr, data_raw, ns_id, page_tid);
|
||||
return;
|
||||
}
|
||||
int bfr_page_bgn = html_bfr.Len();
|
||||
boolean page_tid_uses_pre = false;
|
||||
switch (page_tid) {
|
||||
case Xow_page_tid.Tid_json:
|
||||
app.Wiki_mgr().Wdata_mgr().Write_json_as_html(html_bfr, data_raw);
|
||||
break;
|
||||
case Xow_page_tid.Tid_js:
|
||||
case Xow_page_tid.Tid_css:
|
||||
case Xow_page_tid.Tid_lua:
|
||||
Xoh_html_wtr_escaper.Escape(page.Wiki().App(), tmp_bfr, data_raw, 0, data_raw.length, false, false);
|
||||
app.Html_mgr().Page_mgr().Content_code_fmtr().Bld_bfr_many(html_bfr, tmp_bfr);
|
||||
tmp_bfr.Clear();
|
||||
page_tid_uses_pre = true;
|
||||
break;
|
||||
case Xow_page_tid.Tid_wikitext:
|
||||
if (ns_id == Xow_ns_.Id_mediaWiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
html_bfr.Add(gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
|
||||
return;
|
||||
}
|
||||
if (ns_id == Xow_ns_.Id_file) // if File ns, add boilerplate header
|
||||
app.File_main_wkr().Bld_html(wiki, ctx, html_bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
gplx.xowa.html.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
|
||||
boolean tidy_enabled = tidy_mgr.Enabled();
|
||||
Bry_bfr hdom_bfr = tidy_enabled ? app.Utl_bry_bfr_mkr().Get_m001() : html_bfr; // if tidy, then write to tidy_bfr; note that html_bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
wiki.Html_mgr().Html_wtr().Write_all(hdom_bfr, page.Wiki().Ctx(), page.Root().Data_mid(), page.Root());
|
||||
if (tidy_enabled) {
|
||||
tidy_mgr.Run_tidy_html(page, hdom_bfr);
|
||||
html_bfr.Add_bfr_and_clear(hdom_bfr);
|
||||
hdom_bfr.Mkr_rls();
|
||||
}
|
||||
if (ns_id == Xow_ns_.Id_category) // if Category, render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
wiki.Html_mgr().Ns_ctg().Bld_html(page, html_bfr);
|
||||
int ctgs_len = page.Category_list().length; // add Categories
|
||||
if (ctgs_enabled && ctgs_len > 0) {
|
||||
app.Usr_dlg().Prog_many("", "", "loading categories: count=~{0}", ctgs_len);
|
||||
if (app.Ctg_mgr().Pagecats_grouping_enabled())
|
||||
app.Ctg_mgr().Pagectgs_wtr().Write(html_bfr, wiki, page);
|
||||
else
|
||||
wiki.Html_mgr().Ctg_mgr().Bld(html_bfr, page, ctgs_len);
|
||||
}
|
||||
break;
|
||||
int bfr_page_bgn = bfr.Len();
|
||||
if (page_mode == Xopg_view_mode.Tid_edit)
|
||||
Write_body_edit(bfr, data_raw, ns_id, page_tid);
|
||||
else {
|
||||
switch (page_tid) {
|
||||
case Xow_page_tid.Tid_js:
|
||||
case Xow_page_tid.Tid_css:
|
||||
case Xow_page_tid.Tid_lua: Write_body_pre (bfr, app, wiki, data_raw, tmp_bfr); page_tid_uses_pre = true; break;
|
||||
case Xow_page_tid.Tid_wikitext: Write_body_wikitext (bfr, app, wiki, data_raw, hctx, page, ns_id); break;
|
||||
case Xow_page_tid.Tid_json: app.Wiki_mgr().Wdata_mgr().Write_json_as_html(bfr, data_raw); break;
|
||||
}
|
||||
}
|
||||
if ( wiki.Domain_tid() != Xow_wiki_domain_.Tid_home // allow home wiki to use javascript
|
||||
&& !page_tid_uses_pre) { // if .js, .css or .lua, skip test; may have js fragments, but entire text is escaped and put in pre; don't show spurious warning; DATE:2013-11-21
|
||||
app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page.Ttl(), html_bfr, bfr_page_bgn);
|
||||
app.Html_mgr().Js_cleaner().Clean_bfr(wiki, page.Ttl(), bfr, bfr_page_bgn);
|
||||
}
|
||||
}
|
||||
private void Write_mode_edit(Bry_bfr html_bfr, byte[] data_raw, int ns_id, byte page_tid) {
|
||||
if ( ns_id == Xow_ns_.Id_mediaWiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
private void Write_body_wikitext(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, byte[] data_raw, Xoh_wtr_ctx hctx, Xoa_page page, int ns_id) {
|
||||
if (ns_id == Xow_ns_.Id_mediawiki) { // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
bfr.Add(gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw));
|
||||
return;
|
||||
}
|
||||
if (ns_id == Xow_ns_.Id_file) // if [[File]], add boilerplate header
|
||||
app.File_main_wkr().Bld_html(wiki, ctx, bfr, page.Ttl(), wiki.Cfg_file_page(), page.File_queue());
|
||||
gplx.xowa.html.tidy.Xoh_tidy_mgr tidy_mgr = app.Html_mgr().Tidy_mgr();
|
||||
boolean tidy_enabled = tidy_mgr.Enabled();
|
||||
Bry_bfr hdom_bfr = tidy_enabled ? app.Utl_bry_bfr_mkr().Get_m001() : bfr; // if tidy, then write to tidy_bfr; note that bfr already has <html> and <head> written to it, so this can't be passed to tidy; DATE:2014-06-11
|
||||
wiki.Html_mgr().Html_wtr().Write_all(hdom_bfr, page.Wiki().Ctx(), hctx, page.Root().Data_mid(), page.Root());
|
||||
if (tidy_enabled) {
|
||||
tidy_mgr.Run_tidy_html(page, hdom_bfr);
|
||||
bfr.Add_bfr_and_clear(hdom_bfr);
|
||||
hdom_bfr.Mkr_rls();
|
||||
}
|
||||
if (ns_id == Xow_ns_.Id_category) // if Category, render rest of html (Subcategories; Pages; Files); note that a category may have other html which requires wikitext processing
|
||||
wiki.Html_mgr().Ns_ctg().Bld_html(page, bfr);
|
||||
int ctgs_len = page.Category_list().length; // add Categories
|
||||
if (ctgs_enabled && ctgs_len > 0) {
|
||||
app.Usr_dlg().Prog_many("", "", "loading categories: count=~{0}", ctgs_len);
|
||||
if (app.Ctg_mgr().Pagecats_grouping_enabled())
|
||||
app.Ctg_mgr().Pagectgs_wtr().Write(bfr, wiki, page);
|
||||
else
|
||||
wiki.Html_mgr().Ctg_mgr().Bld(bfr, page, ctgs_len);
|
||||
}
|
||||
}
|
||||
private void Write_body_pre(Bry_bfr bfr, Xoa_app app, Xow_wiki wiki, byte[] data_raw, Bry_bfr tmp_bfr) {
|
||||
Xoh_html_wtr_escaper.Escape(app, tmp_bfr, data_raw, 0, data_raw.length, false, false);
|
||||
app.Html_mgr().Page_mgr().Content_code_fmtr().Bld_bfr_many(bfr, tmp_bfr);
|
||||
tmp_bfr.Clear();
|
||||
}
|
||||
private void Write_body_edit(Bry_bfr bfr, byte[] data_raw, int ns_id, byte page_tid) {
|
||||
if ( ns_id == Xow_ns_.Id_mediawiki // if MediaWiki and wikitext, must be a message; convert args back to php; DATE:2014-06-13
|
||||
&& page_tid == Xow_page_tid.Tid_wikitext
|
||||
)
|
||||
data_raw = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_php(tmp_bfr, Bool_.N, data_raw);
|
||||
int data_raw_len = data_raw.length;
|
||||
if (mgr.Html_capable())
|
||||
Xoh_html_wtr_escaper.Escape(page.Wiki().App(), html_bfr, data_raw, 0, data_raw_len, false, false); // NOTE: must escape; assume that browser will automatically escape (<) (which Mozilla does)
|
||||
Xoh_html_wtr_escaper.Escape(page.Wiki().App(), bfr, data_raw, 0, data_raw_len, false, false); // NOTE: must escape; assume that browser will automatically escape (<) (which Mozilla does)
|
||||
else
|
||||
html_bfr.Add(data_raw);
|
||||
bfr.Add(data_raw);
|
||||
if (data_raw_len > 0) // do not add nl if empty String
|
||||
html_bfr.Add_byte_nl(); // per MW:EditPage.php: "Ensure there's a newline at the end, otherwise adding lines is awkward."
|
||||
bfr.Add_byte_nl(); // per MW:EditPage.php: "Ensure there's a newline at the end, otherwise adding lines is awkward."
|
||||
}
|
||||
private static final byte[] Content_editable_bry = Bry_.new_ascii_(" contenteditable=\"true\"");
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.html; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.gui.*;
|
||||
import gplx.xowa.gui.*; import gplx.xowa.pages.*;
|
||||
public class Xoh_page_wtr_wkr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_page_wtr_wkr_fxt fxt = new Xoh_page_wtr_wkr_fxt();
|
||||
@Test public void Page_name() {
|
||||
@ -58,7 +58,7 @@ class Xoh_page_wtr_wkr_fxt {
|
||||
Xoa_page page = wiki.Ctx().Cur_page();
|
||||
page.Data_raw_(Bry_.new_utf8_(raw));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xog_page_mode.Tid_edit).Page_(page).Mgr_(mgr);
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_view_mode.Tid_edit).Page_(page).Mgr_(mgr);
|
||||
wkr.XferAry(tmp_bfr, 0);
|
||||
Tfds.Eq(expd, tmp_bfr.XtoStrAndClear());
|
||||
}
|
||||
@ -68,7 +68,7 @@ class Xoh_page_wtr_wkr_fxt {
|
||||
page.Ttl_(Xoa_ttl.parse_(wiki, Bry_.new_ascii_(page_name)));
|
||||
page.Data_raw_(Bry_.new_utf8_(page_text));
|
||||
Xoh_page_wtr_mgr mgr = wiki.Html_mgr().Page_wtr_mgr();
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xog_page_mode.Tid_read).Page_(page).Mgr_(mgr);
|
||||
Xoh_page_wtr_wkr wkr = mgr.Wkr(Xopg_view_mode.Tid_read).Page_(page).Mgr_(mgr);
|
||||
wkr.XferAry(tmp_bfr, 0);
|
||||
Tfds.Eq(expd, tmp_bfr.XtoStrAndClear());
|
||||
}
|
||||
|
@ -16,16 +16,18 @@ 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.html; import gplx.*; import gplx.xowa.*;
|
||||
public class Xoh_html_wtr_ctx {
|
||||
Xoh_html_wtr_ctx(byte mode) {this.mode = mode;} private byte mode;
|
||||
public class Xoh_wtr_ctx {
|
||||
Xoh_wtr_ctx(byte mode) {this.mode = mode;} private byte mode;
|
||||
public boolean Mode_is_alt() {return mode == Mode_alt;}
|
||||
public boolean Mode_is_display_title() {return mode == Mode_display_title;}
|
||||
public boolean Mode_is_popup() {return mode == Mode_popup;}
|
||||
public static final byte Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3;
|
||||
public static final Xoh_html_wtr_ctx
|
||||
Basic = new Xoh_html_wtr_ctx(Mode_basic)
|
||||
, Alt = new Xoh_html_wtr_ctx(Mode_alt)
|
||||
, Display_title = new Xoh_html_wtr_ctx(Mode_display_title)
|
||||
, Popup = new Xoh_html_wtr_ctx(Mode_popup)
|
||||
public boolean Mode_is_hdump() {return mode == Mode_hdump;}
|
||||
public static final byte Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4;
|
||||
public static final Xoh_wtr_ctx
|
||||
Basic = new Xoh_wtr_ctx(Mode_basic)
|
||||
, Alt = new Xoh_wtr_ctx(Mode_alt)
|
||||
, Display_title = new Xoh_wtr_ctx(Mode_display_title)
|
||||
, Popup = new Xoh_wtr_ctx(Mode_popup)
|
||||
, Hdump = new Xoh_wtr_ctx(Mode_hdump)
|
||||
;
|
||||
}
|
@ -56,117 +56,20 @@ public class Xow_html_mgr implements GfoInvkAble {
|
||||
public Xohp_ctg_grp_mgr Ctg_mgr() {return ctg_mgr;} private Xohp_ctg_grp_mgr ctg_mgr = new Xohp_ctg_grp_mgr();
|
||||
public Xoctg_html_mgr Ns_ctg() {return ns_ctg;} private Xoctg_html_mgr ns_ctg = new Xoctg_html_mgr();
|
||||
public Xoh_imgs_mgr Imgs_mgr() {return imgs_mgr;} private Xoh_imgs_mgr imgs_mgr;
|
||||
public Bry_fmtr Lnki_full_image() {return lnki_full_image;} Bry_fmtr lnki_full_image = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"~{href}\"~{anchor_class}~{anchor_rel}~{anchor_title} xowa_title=\"~{lnki_title}\"><img id=\"xowa_file_img_~{elem_id}\" alt=\"~{alt}\" src=\"~{src}\" width=\"~{width}\" height=\"~{height}\"~{img_class} /></a>"
|
||||
), "elem_id", "href", "src", "width", "height", "alt", "lnki_title", "anchor_class", "anchor_rel", "anchor_title", "img_class"
|
||||
);
|
||||
public Bry_fmtr Lnki_full_media() {return lnki_full_media;} Bry_fmtr lnki_full_media = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"~{lnki_src}\" xowa_title=\"~{lnki_title}\">~{lnki_caption}"
|
||||
, "</a>"
|
||||
), "lnki_src", "lnki_title", "lnki_caption"
|
||||
);
|
||||
|
||||
public Bry_fmtr Lnki_thumb_core() {return lnki_thumb_core;} Bry_fmtr lnki_thumb_core = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last // REF.MW: Linker.php|makeImageLink2
|
||||
( "<div class=\"thumb t~{lnki_halign}\">"
|
||||
, " <div id=\"xowa_file_div_~{elem_id}\" class=\"thumbinner\" style=\"width:~{div_width}px;\">"
|
||||
, "~{lnki_content}"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
), "div_width", "lnki_halign", "lnki_content", "elem_id"
|
||||
);
|
||||
public Bry_fmtr Lnki_thumb_file_image() {return lnki_thumb_file_image;} Bry_fmtr lnki_thumb_file_image = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( " ~{thumb_image}~{lnki_caption}~{lnki_alt}"
|
||||
), "thumb_image", "lnki_caption", "lnki_alt");
|
||||
public Bry_fmtr Lnki_thumb_file_video() {return lnki_thumb_file_video;} Bry_fmtr lnki_thumb_file_video = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( " <div id=\"xowa_media_div\">~{video_thumb}~{play_btn}"
|
||||
, " </div>~{lnki_caption}~{lnki_alt}"
|
||||
), "play_btn", "video_thumb", "lnki_caption", "lnki_alt");
|
||||
public Bry_fmtr Lnki_thumb_file_audio() {return lnki_thumb_file_audio;} Bry_fmtr lnki_thumb_file_audio = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( " <div id=\"xowa_media_div\">~{play_btn}~{info_btn}"
|
||||
, " </div>~{lnki_caption}~{lnki_alt}"
|
||||
), "play_btn", "info_btn", "lnki_caption", "lnki_alt");
|
||||
public Bry_fmtr Lnki_thumb_part_image() {return lnki_thumb_part_image;} Bry_fmtr lnki_thumb_part_image = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"~{lnki_href}\" class=\"~{lnki_class}\" title=\"~{lnki_title}\">"
|
||||
, " <img id=\"xowa_file_img_~{elem_id}\" src=\"~{lnki_src}\" width=\"~{lnki_width}\" height=\"~{lnki_height}\" alt=\"~{lnki_alt}\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "elem_id", "lnki_class", "lnki_href", "lnki_title", "lnki_src", "lnki_width", "lnki_height", "lnki_alt");
|
||||
public Bry_fmtr Lnki_thumb_part_caption() {return lnki_thumb_part_caption;} Bry_fmtr lnki_thumb_part_caption = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"thumbcaption\">~{magnify_btn}"
|
||||
, " ~{lnki_caption}"
|
||||
, " </div>"
|
||||
), "magnify_btn", "lnki_caption");
|
||||
public Bry_fmtr Lnki_thumb_part_alt() {return lnki_thumb_part_alt;} Bry_fmtr lnki_thumb_part_alt = Bry_fmtr.new_
|
||||
(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <hr/>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, "~{alt_html}"
|
||||
, " </div>"
|
||||
)
|
||||
, "alt_html");
|
||||
public Bry_fmtr Lnki_thumb_part_magnfiy_btn() {return lnki_thumb_part_magnify_btn;} Bry_fmtr lnki_thumb_part_magnify_btn = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"~{lnki_src}\" class=\"internal\" title=\"~{lnki_enlarge_msg}\">"
|
||||
, " <img src=\"~{magnify_icon}\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "magnify_icon", "lnki_src", "lnki_enlarge_msg");
|
||||
public Bry_fmtr Lnki_thumb_part_play_btn() {return lnki_thumb_part_play_btn;} Bry_fmtr lnki_thumb_part_play_btn = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_~{play_id}\" href=\"~{lnki_url}\" xowa_title=\"~{lnki_title}\" class=\"xowa_anchor_button\" style=\"width:~{play_width}px;max-width:~{play_max_width}px;\">"
|
||||
, " <img src=\"~{play_icon}\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "play_id", "play_icon", "play_width", "play_max_width", "lnki_url", "lnki_title");
|
||||
public Bry_fmtr Lnki_thumb_part_info_btn() {return lnki_thumb_part_info_btn;} Bry_fmtr lnki_thumb_part_info_btn = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"~{lnki_href}\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"~{info_icon}\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "info_icon", "lnki_href");
|
||||
public Bry_fmtr Plain() {return plain;} Bry_fmtr plain = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "~{val}"
|
||||
), "val");
|
||||
public void Copy_cfg(Xow_html_mgr html_mgr) {imgs_mgr.Copy_cfg(html_mgr.Imgs_mgr());}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_lnki_full_image_)) lnki_full_image.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_full_media_)) lnki_full_media.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_core_)) lnki_thumb_core.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_file_image_)) lnki_thumb_file_image.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_file_audio_)) lnki_thumb_file_audio.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_file_video_)) lnki_thumb_file_video.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_image_)) lnki_thumb_part_image.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_caption_)) lnki_thumb_part_caption.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_alt_)) lnki_thumb_part_alt.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_magnify_btn_)) lnki_thumb_part_magnify_btn.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_play_btn_)) lnki_thumb_part_play_btn.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_lnki_thumb_part_info_btn_)) lnki_thumb_part_info_btn.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_article)) return page_wtr_mgr;
|
||||
if (ctx.Match(k, Invk_article)) return page_wtr_mgr;
|
||||
else if (ctx.Match(k, Invk_portal)) return portal_mgr;
|
||||
else if (ctx.Match(k, Invk_imgs)) return imgs_mgr;
|
||||
else if (ctx.Match(k, Invk_ns_ctg)) return ns_ctg;
|
||||
else if (ctx.Match(k, Invk_modules)) return module_mgr;
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_lnki_full_image_ = "lnki_full_image_", Invk_lnki_full_media_ = "lnki_full_media_", Invk_lnki_thumb_core_ = "lnki_thumb_core_"
|
||||
, Invk_lnki_thumb_file_image_ = "lnki_thumb_file_image_", Invk_lnki_thumb_file_audio_ = "lnki_thumb_file_audio_", Invk_lnki_thumb_file_video_ = "lnki_thumb_file_video_"
|
||||
, Invk_lnki_thumb_part_image_ = "lnki_thumb_part_image_", Invk_lnki_thumb_part_caption_ = "lnki_thumb_part_caption_", Invk_lnki_thumb_part_alt_ = "lnki_thumb_part_alt_"
|
||||
, Invk_lnki_thumb_part_magnify_btn_ = "lnki_thumb_part_magnify_btn_", Invk_lnki_thumb_part_play_btn_ = "lnki_thumb_part_play_btn_", Invk_lnki_thumb_part_info_btn_ = "lnki_thumb_part_info_btn_"
|
||||
, Invk_article = "article"
|
||||
Invk_article = "article"
|
||||
, Invk_portal = "portal", Invk_imgs = "imgs", Invk_ns_ctg = "ns_ctg"
|
||||
, Invk_modules = "modules"
|
||||
;
|
||||
public static final String Str_img_class_thumbimage = "thumbimage";
|
||||
public static final byte[] Bry_anchor_class_image = Bry_.new_ascii_(" class=\"image\""), Bry_anchor_class_blank = Bry_.Empty, Bry_anchor_rel_nofollow = Bry_.new_ascii_(" rel=\"nofollow\""), Bry_anchor_rel_blank = Bry_.Empty, Bry_img_class_thumbimage = Bry_.new_ascii_(" class=\"thumbimage\""), Bry_img_class_none = Bry_.Empty;
|
||||
public static final byte[] Bry_anchor_class_image = Bry_.new_ascii_(" class=\"image\""), Bry_anchor_class_blank = Bry_.Empty, Bry_anchor_rel_nofollow = Bry_.new_ascii_(" rel=\"nofollow\""), Bry_anchor_rel_blank = Bry_.Empty, Bry_img_cls_thumbimage = Bry_.new_ascii_(" class=\"thumbimage\""), Bry_img_cls_none = Bry_.Empty;
|
||||
}
|
||||
|
175
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java
Normal file
175
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_html_fmtr__base.java
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.dbs.hdumps.htmls.*;
|
||||
class Xoh_file_html_fmtr__hdump extends Xoh_file_html_fmtr__base {
|
||||
@gplx.Internal @Override protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__hdump();}
|
||||
@Override public void Html_thumb_core(Bry_bfr tmp_bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
|
||||
Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_img_w, uid);
|
||||
byte[] div2_width_repl = tmp_bfr.XtoAryAndClear();
|
||||
fmtr_thumb_core.Bld_bfr_many(tmp_bfr, uid, div1_halign, div2_width_repl, div2_content);
|
||||
}
|
||||
@Override public void Html_thumb_part_magnify(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_mgnf, uid);}
|
||||
@Override public void Html_thumb_part_info(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_info, uid);}
|
||||
@Override public void Html_thumb_part_play(Bry_bfr tmp_bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {Write_fmt(tmp_bfr, Hdump_html_fmtr__body.Key_mda_play, uid);}
|
||||
public static void Write_fmt(Bry_bfr bfr, byte[] key, int uid) {
|
||||
bfr.Add(key);
|
||||
bfr.Add_int_variable(uid);
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
}
|
||||
public static final Xoh_file_html_fmtr__hdump Hdump = new Xoh_file_html_fmtr__hdump(); Xoh_file_html_fmtr__hdump() {}
|
||||
}
|
||||
public class Xoh_file_html_fmtr__base implements Xoh_file_img_wkr {
|
||||
private final Xoh_arg_img_core arg_img_core; //Xoh_arg_img_core arg_img_mgnf;
|
||||
public Xoh_file_html_fmtr__base() {
|
||||
arg_img_core = New_arg_img_core();
|
||||
}
|
||||
@gplx.Internal @gplx.Virtual protected Xoh_arg_img_core New_arg_img_core() {return new Xoh_arg_img_core__basic();}
|
||||
public void Html_full_media(Bry_bfr tmp_bfr, byte[] a_href, byte[] a_title, Bry_fmtr_arg html) {fmtr_full_media.Bld_bfr_many(tmp_bfr, a_href, a_title, html);}
|
||||
private Bry_fmtr fmtr_full_media = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"~{a_href}\" xowa_title=\"~{a_xowa_title}\">~{html}"
|
||||
, "</a>"
|
||||
), "a_href", "a_xowa_title", "html"
|
||||
);
|
||||
public void Html_full_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class) {
|
||||
fmtr_full_img.Bld_bfr_many(tmp_bfr, uid, a_href, a_class, a_rel, a_title, a_xowa_title, arg_img_core.Init(uid, img_src, img_w, img_h), img_alt, img_class);
|
||||
}
|
||||
private Bry_fmtr fmtr_full_img = Bry_fmtr.new_
|
||||
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title} xowa_title=\"~{a_xowa_title}\">"
|
||||
+ "<img id=\"xowa_file_img_~{uid}\" alt=\"~{img_alt}\"~{img_core}~{img_class} /></a>"
|
||||
, "uid", "a_href", "a_class", "a_rel", "a_title", "a_xowa_title", "img_core", "img_alt", "img_class"
|
||||
);
|
||||
|
||||
@gplx.Virtual public void Html_thumb_core(Bry_bfr tmp_bfr, int uid, byte[] div1_halign, int div2_width, byte[] div2_content) {
|
||||
fmtr_thumb_core.Bld_bfr_many(tmp_bfr, uid, div1_halign, div2_width, div2_content);
|
||||
}
|
||||
protected Bry_fmtr fmtr_thumb_core = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last // REF.MW: Linker.php|makeImageLink2
|
||||
( "<div class=\"thumb t~{div1_halign}\">"
|
||||
, " <div id=\"xowa_file_div_~{uid}\" class=\"thumbinner\" style=\"width:~{div2_width}px;\">"
|
||||
, "~{div2_content}"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
), "uid", "div1_halign", "div2_width", "div2_content"
|
||||
);
|
||||
public byte[] Html_thumb_part_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, Xop_lnki_tkn lnki, int uid, byte[] a_href, byte[] img_src, byte[] img_alt) {
|
||||
Html_thumb_part_img(tmp_bfr, page, xfer_itm, uid, a_href, lnki.Ttl().Page_txt(), xfer_itm.Html_w(), xfer_itm.Html_h(), img_src, img_alt);
|
||||
return tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
public void Html_thumb_part_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_title, int img_w, int img_h, byte[] img_src, byte[] img_alt) {
|
||||
fmtr_thumb_part_img.Bld_bfr_many(tmp_bfr, uid, a_href, a_title, arg_img_core.Init(uid, img_src, img_w, img_h), img_alt);
|
||||
}
|
||||
private Bry_fmtr fmtr_thumb_part_img = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"~{a_href}\" class=\"image\" title=\"~{a_title}\">"
|
||||
, " <img id=\"xowa_file_img_~{uid}\"~{img_core} alt=\"~{img_alt}\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "uid", "a_href", "a_title", "img_core", "img_alt");
|
||||
|
||||
public void Html_thumb_part_caption(Bry_bfr tmp_bfr, byte[] magnify_btn, Bry_fmtr_arg caption) {fmtr_thumb_part_caption.Bld_bfr_many(tmp_bfr, magnify_btn, caption);}
|
||||
private Bry_fmtr fmtr_thumb_part_caption = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"thumbcaption\">~{magnify_btn}"
|
||||
, " ~{caption}"
|
||||
, " </div>"
|
||||
), "magnify_btn", "caption");
|
||||
|
||||
public void Html_thumb_file_image(Bry_bfr tmp_bfr, byte[] thumb_image, byte[] caption, byte[] alt) {fmtr_thumb_file_image.Bld_bfr_many(tmp_bfr, thumb_image, caption, alt);}
|
||||
private Bry_fmtr fmtr_thumb_file_image = Bry_fmtr.new_(" ~{thumb_image}~{caption}~{alt}", "thumb_image", "caption", "alt");
|
||||
|
||||
public void Html_thumb_file_audio(Bry_bfr tmp_bfr, byte[] caption, byte[] alt, byte[] play_btn, byte[] audio_info) {fmtr_thumb_file_audio.Bld_bfr_many(tmp_bfr, caption, alt, play_btn, audio_info);}
|
||||
private Bry_fmtr fmtr_thumb_file_audio = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( " <div id=\"xowa_media_div\">~{play_btn}~{audio_info}"
|
||||
, " </div>~{caption}~{alt}"
|
||||
), "caption", "alt", "play_btn", "audio_info");
|
||||
|
||||
public void Html_thumb_file_video(Bry_bfr tmp_bfr, byte[] play_btn, byte[] video_thumb, byte[] caption, byte[] alt) {fmtr_thumb_file_video.Bld_bfr_many(tmp_bfr, caption, alt, play_btn, video_thumb);}
|
||||
private Bry_fmtr fmtr_thumb_file_video = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( " <div id=\"xowa_media_div\">~{video_thumb}~{play_btn}"
|
||||
, " </div>~{caption}~{alt}"
|
||||
), "caption", "alt", "play_btn", "video_thumb");
|
||||
|
||||
public void Html_thumb_part_alt(Bry_bfr tmp_bfr, byte[] alt_html) {fmtr_thumb_part_alt.Bld_bfr_many(tmp_bfr, alt_html);}
|
||||
public Bry_fmtr Html_thumb_part_alt_fmtr() {return fmtr_thumb_part_alt;} private Bry_fmtr fmtr_thumb_part_alt = Bry_fmtr.new_
|
||||
(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <hr/>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, "~{html}"
|
||||
, " </div>"
|
||||
), "html");
|
||||
|
||||
@gplx.Virtual public void Html_thumb_part_magnify(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] a_title, byte[] img_src) {
|
||||
fmtr_thumb_part_magnify.Bld_bfr_many(tmp_bfr, a_href, a_title, img_src);
|
||||
}
|
||||
private Bry_fmtr fmtr_thumb_part_magnify = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"~{a_href}\" class=\"internal\" title=\"~{a_title}\">"
|
||||
, " <img src=\"~{img_src}\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "a_href", "a_title", "img_src");
|
||||
|
||||
@gplx.Virtual public void Html_thumb_part_info(Bry_bfr tmp_bfr, int uid, byte[] a_href, byte[] img_src) {fmtr_thumb_part_info.Bld_bfr_many(tmp_bfr, a_href, img_src);}
|
||||
private Bry_fmtr fmtr_thumb_part_info = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a href=\"~{a_href}\" class=\"image\" title=\"About this file\">"
|
||||
, " <img src=\"~{img_src}\" width=\"22\" height=\"22\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "a_href", "img_src");
|
||||
|
||||
@gplx.Virtual public void Html_thumb_part_play(Bry_bfr tmp_bfr, int uid, int a_width, int a_max_width, byte[] a_href, byte[] a_xowa_title, byte[] img_src) {
|
||||
fmtr_thumb_part_play.Bld_bfr_many(tmp_bfr, uid, a_width, a_max_width, a_href, a_xowa_title, img_src);
|
||||
}
|
||||
private Bry_fmtr fmtr_thumb_part_play = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div>"
|
||||
, " <a id=\"xowa_file_play_~{uid}\" href=\"~{a_href}\" xowa_title=\"~{a_xowa_title}\" class=\"xowa_anchor_button\" style=\"width:~{a_width}px;max-width:~{a_max_width}px;\">"
|
||||
, " <img src=\"~{img_src}\" width=\"22\" height=\"22\" alt=\"Play sound\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
), "uid", "a_width", "a_max_width", "a_href", "a_xowa_title", "img_src");
|
||||
|
||||
public static final Xoh_file_html_fmtr__base Base = new Xoh_file_html_fmtr__base();
|
||||
}
|
||||
interface Xoh_arg_img_core extends Bry_fmtr_arg {
|
||||
Xoh_arg_img_core Init(int uid, byte[] src, int w, int h);
|
||||
}
|
||||
class Xoh_arg_img_core__hdump implements Xoh_arg_img_core {
|
||||
private int uid;
|
||||
public Xoh_arg_img_core Init(int uid, byte[] img_src, int img_w, int img_h) {
|
||||
this.uid = uid;
|
||||
return this;
|
||||
}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
Xoh_file_html_fmtr__hdump.Write_fmt(bfr, Hdump_html_fmtr__body.Key_img, uid);
|
||||
}
|
||||
}
|
||||
class Xoh_arg_img_core__basic implements Xoh_arg_img_core {
|
||||
private byte[] src; private int w, h;
|
||||
public Xoh_arg_img_core Init(int uid, byte[] src, int w, int h) {this.src = src; this.w = w; this.h = h; return this;}
|
||||
public void XferAry(Bry_bfr bfr, int idx) {
|
||||
fmtr_img_atrs.Bld_bfr_many(bfr, src, w, h);
|
||||
}
|
||||
private Bry_fmtr fmtr_img_atrs = Bry_fmtr.new_(" src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"", "img_src", "img_w", "img_h");
|
||||
}
|
22
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_img_wkr.java
Normal file
22
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_img_wkr.java
Normal 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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.files.*;
|
||||
public interface Xoh_file_img_wkr {
|
||||
void Html_full_img(Bry_bfr tmp_bfr, Xoa_page page, Xof_xfer_itm xfer_itm, int uid, byte[] a_href, byte[] a_class, byte[] a_rel, byte[] a_title, byte[] a_xowa_title, int img_w, int img_h, byte[] img_src, byte[] img_alt, byte[] img_class);
|
||||
}
|
78
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_mgr.java
Normal file
78
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_mgr.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Xoh_file_mgr {
|
||||
private final Xow_wiki wiki; private final Bool_obj_ref queue_add_ref = Bool_obj_ref.n_();
|
||||
public Xoh_file_mgr(Xow_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
|
||||
this.wiki = wiki;
|
||||
this.file_wtr = new Xoh_file_wtr__basic(wiki, html_mgr, html_wtr);
|
||||
}
|
||||
public Xoh_file_wtr__basic File_wtr() {return file_wtr;} private final Xoh_file_wtr__basic file_wtr;
|
||||
public void Init_by_page(Xoh_wtr_ctx hctx, Xoa_page page) {file_wtr.Init_by_page(hctx, page);}
|
||||
public void Write_or_queue(Bry_bfr bfr, Xoa_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki) {
|
||||
Xof_xfer_itm xfer_itm = this.Lnki_eval(ctx, page, lnki, queue_add_ref);
|
||||
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, xfer_itm, file_wtr.Arg_alt_text(ctx, src, lnki));
|
||||
}
|
||||
public void Write_or_queue(Bry_bfr bfr, Xoa_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] alt_text) {
|
||||
Xof_xfer_itm xfer_itm = this.Lnki_eval(ctx, page, lnki, queue_add_ref);
|
||||
file_wtr.Write_file(bfr, ctx, hctx, src, lnki, xfer_itm, alt_text);
|
||||
}
|
||||
public Xof_xfer_itm Lnki_eval(Xop_ctx ctx, Xoa_page page, Xop_lnki_tkn lnki, Bool_obj_ref queue_add_ref) {return Lnki_eval(ctx, page.File_queue(), lnki.Ttl().Page_url(), lnki.Lnki_type(), lnki.Lnki_w(), lnki.Lnki_h(), lnki.Upright(), lnki.Thumbtime(), lnki.Page(), lnki.Ns_id() == Xow_ns_.Id_media, queue_add_ref);}
|
||||
public Xof_xfer_itm Lnki_eval(Xop_ctx ctx, Xof_xfer_queue queue, byte[] lnki_ttl, byte lnki_type, int lnki_w, int lnki_h, double lnki_upright, double lnki_thumbtime, int lnki_page, boolean lnki_is_media_ns, Bool_obj_ref queue_add_ref) {
|
||||
queue_add_ref.Val_n_();
|
||||
int uid = queue.Elem_id().Val_add();
|
||||
tmp_xfer_itm.Clear().Init_by_lnki(lnki_ttl, Bry_.Empty, lnki_type, lnki_w, lnki_h, lnki_upright, lnki_thumbtime, lnki_page).Set__html_uid_tid(uid, Xof_html_elem.Tid_img);
|
||||
boolean found = Find_file(ctx, tmp_xfer_itm);
|
||||
boolean file_queue_add = File_queue_add(wiki, tmp_xfer_itm, lnki_is_media_ns, found);
|
||||
Xof_xfer_itm rv = tmp_xfer_itm;
|
||||
if (file_queue_add) {
|
||||
queue_add_ref.Val_y_();
|
||||
rv = tmp_xfer_itm.Clone();
|
||||
queue.Add(rv);
|
||||
return rv;
|
||||
}
|
||||
rv.File_found_(found);
|
||||
return rv;
|
||||
} private Xof_xfer_itm tmp_xfer_itm = new Xof_xfer_itm();
|
||||
private boolean Find_file(Xop_ctx ctx, Xof_xfer_itm xfer_itm) {
|
||||
if (wiki.File_mgr().Version() == Xow_file_mgr.Version_2)
|
||||
return ctx.Cur_page().Lnki_file_mgr().Find(wiki, ctx.Cur_page(), Xof_exec_tid.Tid_wiki_page, xfer_itm);
|
||||
else
|
||||
return wiki.File_mgr().Find_meta(xfer_itm);
|
||||
}
|
||||
private static boolean File_queue_add(Xow_wiki wiki, Xof_xfer_itm xfer_itm, boolean lnki_is_media_ns, boolean found) {
|
||||
if (!wiki.File_mgr().Cfg_download().Enabled()) return false;
|
||||
if (lnki_is_media_ns) return false;
|
||||
switch (wiki.File_mgr().Cfg_download().Redownload()) {
|
||||
case Xof_cfg_download.Redownload_none:
|
||||
if (found) return false;
|
||||
if (!found
|
||||
&& xfer_itm.Meta_itm() != null // null check; fsdb_call does not set meta
|
||||
&& xfer_itm.Meta_itm().Orig_exists() == Xof_meta_itm.Exists_n)
|
||||
return false; // not found, and orig_exists is n; do not download again (NOTE: even if current lnki is thumb, don't bother looking for thumb if orig is missing)
|
||||
break;
|
||||
case Xof_cfg_download.Redownload_missing:
|
||||
if (found) return false;
|
||||
break;
|
||||
case Xof_cfg_download.Redownload_all:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
235
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java
Normal file
235
400_xowa/src/gplx/xowa/html/lnkis/Xoh_file_wtr__basic.java
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
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.html.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.html.*;
|
||||
import gplx.html.*; import gplx.xowa.files.*;
|
||||
public class Xoh_file_wtr__basic {
|
||||
private final Xow_wiki wiki; private final Xow_html_mgr html_mgr; private final Xoh_html_wtr html_wtr; private final Bry_bfr_mkr bfr_mkr; private final Bry_bfr scratch_bfr = Bry_bfr.reset_(Io_mgr.Len_kb);
|
||||
private final Xoh_lnki_text_fmtr media_alt_fmtr, caption_fmtr;
|
||||
private final Xop_link_parser tmp_link_parser = new Xop_link_parser(); private Xoa_url tmp_url = Xoa_url.blank_(); private final Xoh_lnki_title_fmtr anchor_title_wkr = new Xoh_lnki_title_fmtr();
|
||||
private Xoh_file_html_fmtr__base html_fmtr = Xoh_file_html_fmtr__base.Base;
|
||||
private Xoa_page page; private boolean cfg_alt_defaults_to_caption;
|
||||
public Xoh_file_wtr__basic(Xow_wiki wiki, Xow_html_mgr html_mgr, Xoh_html_wtr html_wtr) {
|
||||
this.wiki = wiki; this.html_mgr = html_mgr; this.html_wtr = html_wtr; this.bfr_mkr = wiki.Utl_bry_bfr_mkr();
|
||||
this.media_alt_fmtr = new Xoh_lnki_text_fmtr(bfr_mkr, html_wtr);
|
||||
this.caption_fmtr = new Xoh_lnki_text_fmtr(bfr_mkr, html_wtr);
|
||||
}
|
||||
public Xoh_file_html_fmtr__base Html_fmtr() {return html_fmtr;}
|
||||
public void Init_by_page(Xoh_wtr_ctx hctx, Xoa_page page) {
|
||||
this.page = page;
|
||||
this.cfg_alt_defaults_to_caption = wiki.App().User().Wiki().Html_mgr().Imgs_mgr().Alt_defaults_to_caption().Val();
|
||||
html_fmtr = hctx.Mode_is_hdump() ? Xoh_file_html_fmtr__hdump.Hdump : Xoh_file_html_fmtr__hdump.Base;
|
||||
}
|
||||
public void Write_file(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, byte[] img_alt) {
|
||||
int uid = xfer_itm.Html_uid();
|
||||
int div_width = xfer_itm.Html_w();
|
||||
if (div_width < 1 && wiki.File_mgr().Version_2_y()) // NOTE: html_w is -1 for v2 and missing files; use lnki_w if available; primarily affects audio files with specified width; [[File:A.oga|30px]]; DATE:2014-05-03
|
||||
div_width = xfer_itm.Lnki_w();
|
||||
if (div_width < 1)
|
||||
div_width = wiki.Html_mgr().Img_thumb_width();
|
||||
int lnki_halign = lnki.Align_h();
|
||||
if (lnki_halign == Xop_lnki_align_h.Null)
|
||||
lnki_halign = wiki.Lang().Img_thumb_halign_default(); // if halign is not supplied, then default to align for language
|
||||
byte[] lnki_halign_bry = Xop_lnki_align_h.Html_names[lnki_halign];
|
||||
byte[] lnki_href = wiki.App().Href_parser().Build_to_bry(wiki, lnki.Ttl());
|
||||
byte[] img_view_src = xfer_itm.Html_view_src();
|
||||
byte[] img_orig_src = xfer_itm.Html_orig_src();
|
||||
byte[] lnki_ttl = lnki.Ttl().Page_txt();
|
||||
Xof_ext lnki_ext = xfer_itm.Lnki_ext();
|
||||
if ( html_mgr.Img_suppress_missing_src() // option to suppress src when file is missing
|
||||
&& !xfer_itm.Html_pass() // file is missing; wipe values and wait for "correct" info before regenerating; mostly to handle unknown redirects
|
||||
&& !lnki_ext.Id_is_media() // file is media; never suppress; src needs to be available for "click" on play; note that most media will be missing (not downloaded)
|
||||
&& lnki.Ns_id() != Xow_ns_.Id_media // ns is media; never suppress; "src" will use only orig_src; DATE:2014-01-30
|
||||
) {
|
||||
img_orig_src = img_view_src = Bry_.Empty; // null out src
|
||||
}
|
||||
if (lnki.Ns_id() == Xow_ns_.Id_media) { // NOTE: regardless of ext (ogg vs jpeg) and literal status (Media vs :Media), [[Media]] links are always rendered the same way; REF.MW:Linker.php|makeMediaLinkObj; PAGE:en.w:Beethoven; EX: [[:Media:De-Ludwig_van_Beethoven.ogg|listen]]); [[File:Beethoven 3.jpg|The [[Media:BeethovenWithLyreGuitar( W. J. Mahler - 1804).jpg|complete painting]]...]]
|
||||
this.Write_file_ns_media(bfr, ctx, src, lnki, img_orig_src);
|
||||
return;
|
||||
}
|
||||
if ( Xof_ext_.Id_is_video_strict(lnki_ext.Id()) // id is .ogv or .webm
|
||||
|| ( lnki_ext.Id_is_ogg() // id is ogg
|
||||
&& wiki.File_mgr().Version_1_y() // version is v1 (v2 always marks ogg as aud); DATE:2014-02-01
|
||||
&& ( xfer_itm.Html_pass() // NOTE: xfer_itm.Html_pass() checks for video .ogg files (ext = .ogg and thumb is available); EX: WWI;
|
||||
|| xfer_itm.Meta_itm().State_new() // NOTE: State_new() will always assume that ogg is video; needed for 1st load and dynamic updates
|
||||
)
|
||||
)
|
||||
) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
this.Write_file_video(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_view_src, img_orig_src, img_alt, xfer_itm);
|
||||
}
|
||||
else if (lnki_ext.Id_is_audio()) // audio
|
||||
this.Write_file_audio(bfr, ctx, src, lnki, uid, div_width, lnki_halign_bry, lnki_href, img_orig_src, img_alt);
|
||||
else // image
|
||||
this.Write_file_image(bfr, ctx, hctx, src, lnki, xfer_itm, uid, div_width, lnki_halign, lnki_halign_bry, lnki_ttl, lnki_ext, lnki_href, img_view_src, img_orig_src, img_alt);
|
||||
if (hctx.Mode_is_hdump()) {
|
||||
byte[] rel_src = Bry_.Len_eq_0(img_view_src) ? Bry_.Empty : Bry_.Mid(img_view_src, xfer_itm.Trg_repo_root().length);
|
||||
xfer_itm.Html_view_src_rel_(rel_src);
|
||||
page.Hdump_data().Imgs().Add(xfer_itm.Clone());
|
||||
}
|
||||
}
|
||||
private void Write_file_ns_media(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, byte[] img_orig_src) {
|
||||
html_fmtr.Html_full_media(bfr, img_orig_src, lnki.Ttl().Page_txt(), Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki)); // NOTE: use orig_src not view_src; DATE:2014-01-19
|
||||
}
|
||||
private void Write_file_audio(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
byte[] content = Arg_content_audio(lnki, ctx, src, uid, lnki_href, img_orig_src, alt);
|
||||
if (lnki.Media_icon())
|
||||
html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content);
|
||||
else
|
||||
bfr.Add(content);
|
||||
}
|
||||
private void Write_file_video(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt, Xof_xfer_itm xfer_itm) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
boolean video_is_thumb = Xop_lnki_type.Id_defaults_to_thumb(lnki.Lnki_type());
|
||||
byte[] content = Arg_content_video(ctx, src, lnki, xfer_itm, uid, video_is_thumb, lnki_href, img_view_src, img_orig_src, alt);
|
||||
if (video_is_thumb)
|
||||
html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content);
|
||||
else
|
||||
bfr.Add(content);
|
||||
}
|
||||
private void Write_file_image(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int uid, int div_width, int lnki_halign, byte[] lnki_halign_bry
|
||||
, byte[] lnki_ttl, Xof_ext lnki_ext, byte[] lnki_href, byte[] img_view_src, byte[] img_orig_src, byte[] alt) {
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Div_center_bgn);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
byte[] anchor_title = html_wtr.Cfg().Lnki_title()
|
||||
? Arg_anchor_title(tmp_bfr, src, lnki, lnki_ttl, anchor_title_wkr) // NOTE: Arg_anchor_title should only be called if there is no caption, else refs may not show; DATE:2014-03-05
|
||||
: Bry_.Empty;
|
||||
Xoh_file_img_wkr lnki_file_wkr = lnki.Lnki_file_wkr(); if (lnki_file_wkr == null) lnki_file_wkr = html_fmtr;
|
||||
if (Xop_lnki_type.Id_is_thumbable(lnki.Lnki_type())) { // is "thumb"
|
||||
if (bfr.Len() > 0) bfr.Add_byte_nl();
|
||||
byte[] content = Arg_content_thumb(lnki_file_wkr, ctx, hctx, src, lnki, xfer_itm, uid, lnki_href, img_view_src, img_orig_src, alt, lnki_ttl, anchor_title);
|
||||
html_fmtr.Html_thumb_core(bfr, uid, lnki_halign_bry, div_width, content);
|
||||
}
|
||||
else {
|
||||
if ( cfg_alt_defaults_to_caption
|
||||
&& Bry_.Len_eq_0(alt) // NOTE: if no alt, always use caption; DATE:2013-07-22
|
||||
&& !lnki.Alt_exists() // unless blank alt exists; EX: [[File:A.png|a|alt=]] should have alt of "", not "a"
|
||||
) {
|
||||
Arg_caption(ctx, src, Xoh_wtr_ctx.Alt, lnki).XferAry(tmp_bfr, 0);
|
||||
alt = tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
boolean div_align_exists = false;
|
||||
switch (lnki.Align_h()) {
|
||||
case Xop_lnki_align_h.Left: bfr.Add(Div_float_left) .Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h.Right: bfr.Add(Div_float_right).Add_byte_nl(); div_align_exists = true; break;
|
||||
case Xop_lnki_align_h.None: bfr.Add(Div_float_none) .Add_byte_nl(); div_align_exists = true; break;
|
||||
}
|
||||
Arg_nde_tkn lnki_link_tkn = lnki.Link_tkn();
|
||||
if (lnki_link_tkn == Arg_nde_tkn.Null) // full
|
||||
lnki_file_wkr.Html_full_img(bfr, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
|
||||
else { // thumb
|
||||
Arg_itm_tkn link_tkn = lnki_link_tkn.Val_tkn();
|
||||
byte[] link_ref = link_tkn.Dat_to_bry(src);
|
||||
byte[] link_ref_new = tmp_link_parser.Parse(tmp_bfr, tmp_url, wiki, link_ref, lnki_href);
|
||||
link_ref = link_ref_new == null ? lnki_href: link_ref_new; // if parse fails, then assign to lnki_href; EX:link={{{1}}}
|
||||
link_ref = ctx.App().Encoder_mgr().Href_quotes().Encode(link_ref); // must encode quotes; PAGE:en.w:List_of_cultural_heritage_sites_in_Punjab,_Pakistan; DATE:2014-07-16
|
||||
lnki_ttl = Bry_.Coalesce(lnki_ttl, tmp_link_parser.Html_xowa_ttl());
|
||||
lnki_file_wkr.Html_full_img(bfr, page, xfer_itm, uid, link_ref, tmp_link_parser.Html_anchor_cls(), tmp_link_parser.Html_anchor_rel(), anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), img_view_src, alt, Arg_img_cls(lnki));
|
||||
}
|
||||
if (div_align_exists) bfr.Add(Html_tag_.Div_rhs); // close div from above
|
||||
}
|
||||
if (lnki_halign == Xop_lnki_align_h.Center) bfr.Add(Html_tag_.Div_rhs);
|
||||
tmp_bfr.Mkr_rls();
|
||||
}
|
||||
private byte[] Arg_content_thumb(Xoh_file_img_wkr lnki_file_wkr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int uid, byte[] lnki_href, byte[] view_src, byte[] img_orig_src, byte[] lnki_alt_text, byte[] lnki_ttl, byte[] anchor_title) {
|
||||
byte[] lnki_alt_html = wiki.Html_mgr().Imgs_mgr().Alt_in_caption().Val() ? Arg_alt_html(ctx, src, lnki) : Bry_.Empty;
|
||||
byte[] lnki_cls = xfer_itm.Html_pass() ? Xow_html_mgr.Bry_img_cls_thumbimage : Xow_html_mgr.Bry_img_cls_none;
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
lnki_file_wkr.Html_full_img(tmp_bfr, page, xfer_itm, uid, lnki_href, Xow_html_mgr.Bry_anchor_class_image, Xow_html_mgr.Bry_anchor_rel_blank, anchor_title, lnki_ttl, xfer_itm.Html_w(), xfer_itm.Html_h(), view_src, lnki_alt_text, lnki_cls);
|
||||
byte[] thumb = tmp_bfr.XtoAryAndClear();
|
||||
html_fmtr.Html_thumb_file_image(tmp_bfr, thumb, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), lnki_alt_html);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Arg_content_audio(Xop_lnki_tkn lnki, Xop_ctx ctx, byte[] src, int uid, byte[] lnki_href, byte[] img_orig_src, byte[] alt) {
|
||||
byte[] info_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
html_fmtr.Html_thumb_part_info(scratch_bfr, uid, lnki_href, html_mgr.Img_media_info_btn());
|
||||
info_btn = scratch_bfr.XtoAryAndClear();
|
||||
}
|
||||
int play_btn_width = lnki.Lnki_w(); if (play_btn_width < 1) play_btn_width = html_mgr.Img_thumb_width(); // if no width set width to default img width
|
||||
html_fmtr.Html_thumb_file_audio(scratch_bfr, Arg_caption_div(ctx, src, lnki, uid, img_orig_src, lnki_href), Arg_alt_html(ctx, src, lnki), Arg_play_btn(uid, play_btn_width, Play_btn_max_width, img_orig_src, lnki.Ttl().Page_txt()), info_btn);
|
||||
return scratch_bfr.XtoAryAndClear();
|
||||
}
|
||||
private byte[] Arg_content_video(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, Xof_xfer_itm xfer_itm, int uid, boolean lnki_thumb, byte[] a_href, byte[] view_src, byte[] orig_src, byte[] img_alt) {
|
||||
int thumb_w = xfer_itm.Html_w();
|
||||
int play_btn_width = thumb_w; if (play_btn_width < 1) play_btn_width = wiki.Html_mgr().Img_thumb_width();
|
||||
byte[] caption_html = Bry_.Empty, alt_html = Bry_.Empty;
|
||||
if (lnki_thumb) {
|
||||
caption_html = Arg_caption_div(ctx, src, lnki, uid, orig_src, a_href);
|
||||
alt_html = Arg_alt_html(ctx, src, lnki);
|
||||
}
|
||||
html_fmtr.Html_thumb_file_video(scratch_bfr, Arg_play_btn(uid, play_btn_width, play_btn_width, orig_src, lnki.Ttl().Page_txt()), html_fmtr.Html_thumb_part_img(scratch_bfr, page, xfer_itm, lnki, uid, a_href, view_src, img_alt), caption_html, alt_html);
|
||||
return scratch_bfr.XtoAryAndClear();
|
||||
}
|
||||
private byte[] Arg_caption_div(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki, int uid, byte[] img_orig_src, byte[] lnki_href) {
|
||||
Bry_fmtr_arg caption = Arg_caption(ctx, src, Xoh_wtr_ctx.Basic, lnki);
|
||||
byte[] magnify_btn = Bry_.Empty;
|
||||
if (lnki.Media_icon()) {
|
||||
if (msg_file_enlarge == null) msg_file_enlarge = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_file_enlarge);
|
||||
html_fmtr.Html_thumb_part_magnify(scratch_bfr, uid, lnki_href, msg_file_enlarge, html_mgr.Img_thumb_magnify());
|
||||
magnify_btn = scratch_bfr.XtoAryAndClear();
|
||||
}
|
||||
html_fmtr.Html_thumb_part_caption(scratch_bfr, magnify_btn, caption);
|
||||
return scratch_bfr.XtoAryAndClear();
|
||||
} private byte[] msg_file_enlarge;
|
||||
private Bry_fmtr_arg Arg_caption(Xop_ctx ctx, byte[] src, Xoh_wtr_ctx hctx_for_caption, Xop_lnki_tkn lnki) {
|
||||
return lnki.Caption_exists() ? caption_fmtr.Set(ctx, hctx_for_caption, src, lnki.Caption_val_tkn(), Xoh_lnki_text_fmtr.Null_fmtr) : Bry_fmtr_arg_.Null;
|
||||
}
|
||||
public byte[] Arg_alt_text(Xop_ctx ctx, byte[] src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(ctx, Xoh_wtr_ctx.Alt, src, lnki.Alt_tkn().Val_tkn(), Xoh_lnki_text_fmtr.Null_fmtr);
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.XferAry(tmp_bfr, 0);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Arg_alt_html(Xop_ctx ctx, byte[] alt_src, Xop_lnki_tkn lnki) {
|
||||
if (!lnki.Alt_exists()) return Bry_.Empty;
|
||||
media_alt_fmtr.Set(ctx, Xoh_wtr_ctx.Basic, alt_src, lnki.Alt_tkn().Val_tkn(), html_fmtr.Html_thumb_part_alt_fmtr());
|
||||
Bry_bfr tmp_bfr = bfr_mkr.Get_k004();
|
||||
media_alt_fmtr.XferAry(tmp_bfr, 0);
|
||||
return tmp_bfr.Mkr_rls().XtoAryAndClear();
|
||||
}
|
||||
private byte[] Arg_play_btn(int uid, int width, int max_width, byte[] a_href, byte[] a_xowa_title) {
|
||||
html_fmtr.Html_thumb_part_play(scratch_bfr, uid, width - 2, max_width, a_href, a_xowa_title, html_mgr.Img_media_play_btn()); // NOTE: -2 is fudge factor else play btn will jut out over video thumb; see Earth and ISS video
|
||||
return scratch_bfr.XtoAryAndClear();
|
||||
}
|
||||
private static byte[] Arg_anchor_title(Bry_bfr tmp_bfr, byte[] src, Xop_lnki_tkn lnki, byte[] lnki_ttl, Xoh_lnki_title_fmtr anchor_title_wkr) {
|
||||
switch (lnki.Lnki_type()) {
|
||||
case Xop_lnki_type.Id_thumb: // If the image is a thumb, do not add a title / alt, even if a caption is available
|
||||
case Xop_lnki_type.Id_frame:
|
||||
return Bry_.Empty;
|
||||
case Xop_lnki_type.Id_frameless: // If the image is frameless, add the caption as a title / alt. If no caption is available, do not add a title / alt
|
||||
break;
|
||||
}
|
||||
Xop_tkn_itm anchor_title_tkn = lnki.Caption_tkn();
|
||||
if (anchor_title_tkn == Xop_tkn_null.Null_tkn) return Bry_.Empty; // no caption; return empty; (do not use lnki); DATE:2013-12-31
|
||||
tmp_bfr.Add(Atr_title);
|
||||
anchor_title_wkr.Set(src, anchor_title_tkn).XferAry(tmp_bfr, 0);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Quote);
|
||||
return tmp_bfr.XtoAryAndClear();
|
||||
}
|
||||
private static byte[] Arg_img_cls(Xop_lnki_tkn lnki) {return lnki.Border() == Bool_.Y_byte ? Atr_cls_thumbborder : Bry_.Empty;}
|
||||
public static final int Play_btn_max_width = 1024;
|
||||
private static final byte[]
|
||||
Div_center_bgn = Bry_.new_ascii_("<div class=\"center\">")
|
||||
, Div_float_none = Bry_.new_ascii_("<div class=\"floatnone\">")
|
||||
, Div_float_left = Bry_.new_ascii_("<div class=\"floatleft\">")
|
||||
, Div_float_right = Bry_.new_ascii_("<div class=\"floatright\">")
|
||||
, Atr_cls_thumbborder = Bry_.new_ascii_(" class=\"thumbborder\"")
|
||||
, Atr_title = Bry_.new_ascii_(" title=\"")
|
||||
;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user