mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.8.5.1'
This commit is contained in:
@@ -30,7 +30,6 @@ public class Xoh_page implements Xoa_page {
|
||||
public Xopg_html_data Html_data() {return html;} private final Xopg_html_data html = new Xopg_html_data();
|
||||
public Xopg_hdump_data Hdump_mgr() {return hdump;} private final Xopg_hdump_data hdump = new Xopg_hdump_data();
|
||||
|
||||
public void Xtn_gallery_packed_exists_y_() {}
|
||||
public boolean Xtn__timeline_exists() {return xtn__timeline_exists;} private boolean xtn__timeline_exists; public void Xtn__timeline_exists_y_() {xtn__timeline_exists = true;}
|
||||
public boolean Xtn__gallery_exists() {return xtn__gallery_exists;} private boolean xtn__gallery_exists; public void Xtn__gallery_exists_y_() {xtn__gallery_exists = true;}
|
||||
|
||||
@@ -52,7 +51,7 @@ public class Xoh_page implements Xoa_page {
|
||||
this.wiki = wiki; this.page_url = page_url; this.page_ttl = page_ttl; this.page_id = page_id;
|
||||
this.Clear();
|
||||
html.Redlink_list().Disabled_(page_ttl.Ns().Id_is_module()); // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
|
||||
html.Toc_mgr().Init(wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), page_url.Raw());
|
||||
html.Toc_mgr().Init(gplx.xowa.htmls.core.htmls.tidy.Xow_tidy_mgr_interface_.Noop, wiki.Lang().Msg_mgr().Itm_by_id_or_null(gplx.xowa.langs.msgs.Xol_msg_itm_.Id_toc).Val(), page_url.Raw());
|
||||
}
|
||||
public Xoh_page Ctor_by_hdiff(Bry_bfr tmp_bfr, Xoae_page page, byte[] toc_label) {
|
||||
this.wiki = page.Wiki(); this.page_url = page.Url(); this.page_ttl = page.Ttl(); this.page_id = page.Db().Page().Id();
|
||||
@@ -67,7 +66,7 @@ public class Xoh_page implements Xoa_page {
|
||||
this.content_sub = html.Content_sub();
|
||||
this.sidebar_div = Xoh_page_.Save_sidebars(tmp_bfr, page, html);
|
||||
|
||||
html.Toc_mgr().Init(toc_label, page_url.Page_bry());
|
||||
html.Toc_mgr().Init(page.Wikie().Html_mgr().Tidy_mgr(), toc_label, page_url.Page_bry()); // NOTE: do not pass in noop tidy_mgr, else broken TOC html will never get corrected during hdump; DATE:2016-08-14
|
||||
return this;
|
||||
}
|
||||
public void Ctor_by_db(int head_flag, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, int zip_tid, int hzip_tid, byte[] body) {
|
||||
|
||||
@@ -85,7 +85,7 @@ public class Xoh_page_wtr_mgr implements Gfo_invk {
|
||||
, "page_data", "page_langs"
|
||||
, "portal_div_personal", "portal_div_ns", "portal_div_view"
|
||||
, "portal_div_logo", "portal_div_home", "portal_div_xtn"
|
||||
, "portal_div_wikis", "portal_sidebar"
|
||||
, "portal_div_admin", "portal_div_wikis", "portal_sidebar"
|
||||
, "edit_div_rename", "edit_div_preview", "js_edit_toolbar"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -99,8 +99,15 @@ public class Xoh_page_wtr_wkr {
|
||||
, mgr.Css_common_bry(), mgr.Css_wiki_bry(), page.Html_data().Head_mgr().Init(app, wiki, page).Init_dflts()
|
||||
, page.Lang().Dir_ltr_bry(), page.Html_data().Indicators(), page_content_sub, wiki.Html_mgr().Portal_mgr().Div_jump_to(), wiki.Xtn_mgr().Xtn_pgbnr().Write_html(page, ctx, hctx), page_body_class, html_content_editable
|
||||
, page_data, wdata_lang_wtr
|
||||
, portal_mgr.Div_personal_bry(), portal_mgr.Div_ns_bry(wiki.Utl__bfr_mkr(), page_ttl, wiki.Ns_mgr()), portal_mgr.Div_view_bry(wiki.Utl__bfr_mkr(), html_gen_tid, page.Html_data().Xtn_search_text())
|
||||
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar), portal_mgr.Div_wikis_bry(wiki.Utl__bfr_mkr()), portal_mgr.Sidebar_mgr().Html_bry()
|
||||
|
||||
// sidebar divs
|
||||
, portal_mgr.Div_personal_bry()
|
||||
, portal_mgr.Div_ns_bry(wiki.Utl__bfr_mkr(), page_ttl, wiki.Ns_mgr())
|
||||
, portal_mgr.Div_view_bry(wiki.Utl__bfr_mkr(), html_gen_tid, page.Html_data().Xtn_search_text())
|
||||
, portal_mgr.Div_logo_bry(), portal_mgr.Div_home_bry(), new Xopg_xtn_skin_fmtr_arg(page, Xopg_xtn_skin_itm_tid.Tid_sidebar)
|
||||
, portal_mgr.Div_admin_bry(tmp_bfr, wiki, page)
|
||||
, portal_mgr.Div_wikis_bry(wiki.Utl__bfr_mkr())
|
||||
, portal_mgr.Sidebar_mgr().Html_bry()
|
||||
, mgr.Edit_rename_div_bry(page_ttl), page.Html_data().Edit_preview_w_dbg(), js_edit_toolbar_bry
|
||||
);
|
||||
Xoh_page_wtr_wkr_.Bld_head_end(bfr, tmp_bfr, page); // add after </head>
|
||||
@@ -170,7 +177,7 @@ public class Xoh_page_wtr_wkr {
|
||||
if (ns_id == Xow_ns_.Tid__category) wiki.Html_mgr().Ns_ctg().Bld_html(wiki, page, hctx, tidy_bfr);
|
||||
|
||||
// tidy html
|
||||
wiki.Html_mgr().Tidy_mgr().Run_tidy_html(page, tidy_bfr, !hctx.Mode_is_hdump());
|
||||
wiki.Html_mgr().Tidy_mgr().Exec_tidy(tidy_bfr, !hctx.Mode_is_hdump(), page.Url_bry_safe());
|
||||
|
||||
// add back to main bfr
|
||||
bfr.Add_bfr_and_clear(tidy_bfr);
|
||||
|
||||
@@ -62,14 +62,21 @@ public class Xow_hdump_mgr__load {
|
||||
private byte[] Parse(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] src) {
|
||||
if (zip_tid > gplx.core.ios.streams.Io_stream_.Tid_raw)
|
||||
src = zip_mgr.Unzip((byte)zip_tid, src);
|
||||
if (hzip_tid == Xoh_hzip_dict_.Hzip__v1) {
|
||||
src = override_mgr__html.Get_or_same(hpg.Ttl().Page_db(), src);
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
switch (hzip_tid) {
|
||||
case Xoh_hzip_dict_.Hzip__none:
|
||||
src = make_mgr.Parse(src, hpg, hpg.Wiki());
|
||||
break;
|
||||
case Xoh_hzip_dict_.Hzip__v1:
|
||||
src = override_mgr__html.Get_or_same(hpg.Ttl().Page_db(), src);
|
||||
hpg.Section_mgr().Add(0, 2, Bry_.Empty, Bry_.Empty).Content_bgn_(0); // +1 to skip \n
|
||||
src = Decode_as_bry(tmp_bfr.Clear(), hpg, src, Bool_.N);
|
||||
hpg.Section_mgr().Set_content(hpg.Section_mgr().Len() - 1, src, src.length);
|
||||
break;
|
||||
case Xoh_hzip_dict_.Hzip__plain:
|
||||
gplx.xowa.apps.wms.apis.parses.Wm_page_loader page_loader = new gplx.xowa.apps.wms.apis.parses.Wm_page_loader();
|
||||
src = page_loader.Parse(wiki, hpg, src);
|
||||
break;
|
||||
}
|
||||
else
|
||||
src = make_mgr.Parse(src, hpg, hpg.Wiki());
|
||||
return src;
|
||||
}
|
||||
private void Fill_page(Xoae_page wpg, Xoh_page hpg) {
|
||||
@@ -88,13 +95,18 @@ public class Xow_hdump_mgr__load {
|
||||
wpg_head.Itm__toc().Enabled_(hpg.Html_data().Toc_mgr().Exists());
|
||||
wpg_head.Itm__pgbnr().Enabled_(hpg.Html_data().Head_mgr().Itm__pgbnr().Enabled());
|
||||
|
||||
// transfer Xtn_gallery_packed_exists; needed for hdump; PAGE:en.w:Mexico; DATE:2016-08-14
|
||||
if (hpg.Html_data().Xtn_gallery_packed_exists())
|
||||
wpg.Html_data().Xtn_gallery_packed_exists_y_();
|
||||
|
||||
// transfer images from Xoh_page to Xoae_page
|
||||
Xoh_img_mgr src_imgs = hpg.Img_mgr();
|
||||
int len = src_imgs.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
gplx.xowa.files.Xof_fsdb_itm itm = src_imgs.Get_at(i);
|
||||
wpg.Hdump_mgr().Imgs().Add(itm);
|
||||
wpg.File_queue().Add(itm); // add to file_queue for http_server
|
||||
if (!Io_mgr.Instance.ExistsFil(itm.Html_view_url())) // if exists, don't add to file_queue; needed for packed; PAGE:en.w:Mexico; DATE:2016-08-14
|
||||
wpg.File_queue().Add(itm); // add to file_queue for http_server
|
||||
}
|
||||
|
||||
// transfer redlinks
|
||||
|
||||
@@ -23,7 +23,7 @@ import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
public class Xob_hdump_bldr implements Gfo_invk {
|
||||
private boolean enabled, hzip_enabled, hzip_diff, hzip_b256; private byte zip_tid = Byte_.Max_value_127;
|
||||
private Xowe_wiki wiki; private Xow_hdump_mgr hdump_mgr; private Xob_hdump_tbl_retriever html_tbl_retriever;
|
||||
private Xowe_wiki wiki; private Xob_hdump_tbl_retriever html_tbl_retriever;
|
||||
private Xoh_stat_tbl stat_tbl; private Xoh_stat_itm stat_itm;
|
||||
private int prv_row_len = 0;
|
||||
private final Xoh_page tmp_hpg = new Xoh_page(); private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
@@ -33,6 +33,7 @@ public class Xob_hdump_bldr implements Gfo_invk {
|
||||
public Xob_hdump_bldr Hzip_enabled_(boolean v) {this.hzip_enabled = v; return this;}
|
||||
public Xob_hdump_bldr Hzip_diff_(boolean v) {this.hzip_diff = v; return this;}
|
||||
public Xob_hdump_bldr Zip_tid_(byte v) {this.zip_tid = v; return this;}
|
||||
public Xow_hdump_mgr Hdump_mgr() {return hdump_mgr;} private Xow_hdump_mgr hdump_mgr;
|
||||
public boolean Init(Xowe_wiki wiki, Db_conn make_conn, Xob_hdump_tbl_retriever html_tbl_retriever) {
|
||||
if (!enabled) return false;
|
||||
this.op_sys_is_wnt = gplx.core.envs.Op_sys.Cur().Tid_is_wnt();
|
||||
|
||||
@@ -36,6 +36,7 @@ public class Xowd_html_tbl implements Db_tbl {
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = "html";
|
||||
public Dbmeta_fld_list Flds() {return flds;} private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
|
||||
public void Insert_bgn() {conn.Txn_bgn("html__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert(Xoh_page hpg, int zip_tid, int hzip_tid, byte[] body) {Insert(hpg.Page_id(), hpg.Head_mgr().Flag(), zip_tid, hzip_tid, hpg.Display_ttl(), hpg.Content_sub(), hpg.Sidebar_div(), body);}
|
||||
@@ -57,6 +58,15 @@ public class Xowd_html_tbl implements Db_tbl {
|
||||
Fill_stmt(stmt_update, head_flag, body_flag, display_ttl, content_sub, sidebar_div, body);
|
||||
stmt_update.Crt_int(fld_page_id, page_id).Exec_update();
|
||||
}
|
||||
public void Upsert(int page_id, int head_flag, int zip_tid, int hzip_tid, byte[] display_ttl, byte[] content_sub, byte[] sidebar_div, byte[] body) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_page_id).Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_auto();
|
||||
boolean exists = rdr.Move_next();
|
||||
rdr.Rls();
|
||||
if (exists)
|
||||
Update(page_id, head_flag, zip_tid, hzip_tid, display_ttl, content_sub, sidebar_div, body);
|
||||
else
|
||||
Insert(page_id, head_flag, zip_tid, hzip_tid, display_ttl, content_sub, sidebar_div, body);
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, fld_page_id);
|
||||
stmt_delete.Clear().Crt_int(fld_page_id, page_id).Exec_delete();
|
||||
|
||||
@@ -20,5 +20,5 @@ public interface Xoh_tidy_wkr {
|
||||
byte Tid();
|
||||
void Indent_(boolean v);
|
||||
void Init_by_app(Xoae_app app);
|
||||
void Exec_tidy(Xoae_page page, Bry_bfr bfr);
|
||||
void Exec_tidy(Bry_bfr bfr, byte[] page_url);
|
||||
}
|
||||
|
||||
@@ -40,5 +40,5 @@ class Xoh_tidy_wkr_null implements Xoh_tidy_wkr {
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_null;}
|
||||
public void Indent_(boolean v) {}
|
||||
public void Init_by_app(Xoae_app app) {}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {}
|
||||
public void Exec_tidy(Bry_bfr bfr, byte[] page_url) {}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
private Tidy tidy;
|
||||
private ByteArrayOutputStream wtr;
|
||||
public void tidy_init() {
|
||||
long bgn = Env_.TickCount();
|
||||
long bgn = System_.Ticks();
|
||||
wtr = new ByteArrayOutputStream();
|
||||
System.setProperty("line.separator", "\n");
|
||||
tidy = new Tidy(); // obtain a new Tidy instance
|
||||
tidy.setInputEncoding("UTF-8"); // -utf8
|
||||
tidy.setOutputEncoding("UTF-8"); // -utf8
|
||||
tidy.setInputEncoding("utf-8"); // -utf8
|
||||
tidy.setOutputEncoding("utf-8"); // -utf8
|
||||
tidy.setDocType("\"\""); // --doctype \"\"; set to empty else some wikis will show paragraph text with little vertical gap; PAGE:tr.b:
|
||||
tidy.setForceOutput(true); // --force-output y
|
||||
tidy.setQuiet(true); // --quiet y
|
||||
@@ -49,7 +49,7 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
tidy.setTrimEmptyElements(true); // NOTE: tidy always trims (not even an option)
|
||||
tidy.setShowWarnings(false); // NOTE: otherwise warnings printed to output window
|
||||
tidy.setShowErrors(0); // NOTE: otherwise errors printed to output window; EX: Error: <time> is not recognized!
|
||||
app.Usr_dlg().Log_many("", "", "jtidy.init; elapsed=~{0}", Env_.TickCount_elapsed_in_frac(bgn));
|
||||
app.Usr_dlg().Log_many("", "", "jtidy.init; elapsed=~{0}", System_.Ticks__elapsed_in_frac(bgn));
|
||||
}
|
||||
private Xoae_app app;
|
||||
public byte Tid() {return Xoh_tidy_wkr_.Tid_jtidy;}
|
||||
@@ -60,7 +60,7 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
if (tidy == null) tidy_init(); // lazy create to skip tests
|
||||
tidy.setIndentContent(v);
|
||||
}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {
|
||||
public void Exec_tidy(Bry_bfr bfr, byte[] page_url) {
|
||||
if (tidy == null) tidy_init(); // lazy create to skip tests
|
||||
// int bfr_len = bfr.Len();
|
||||
// long bgn = Env_.TickCount();
|
||||
@@ -72,7 +72,7 @@ class Xoh_tidy_wkr_jtidy implements Xoh_tidy_wkr {
|
||||
}
|
||||
catch (Exception exc) {
|
||||
bfr.Add(orig); // jtidy failed; restore original
|
||||
app.Usr_dlg().Warn_many("", "", "jtidy.fail; page=~{0} exc=~{1}", page.Ttl().Full_db_as_str(), Err_.Message_gplx_full(exc));
|
||||
app.Usr_dlg().Warn_many("", "", "jtidy.fail; page=~{0} exc=~{1}", page_url, Err_.Message_gplx_full(exc));
|
||||
}
|
||||
finally {
|
||||
wtr.reset();
|
||||
|
||||
@@ -28,15 +28,15 @@ public class Xoh_tidy_wkr_tidy extends Process_adp implements Xoh_tidy_wkr { pr
|
||||
return super.Tmp_dir_(v);
|
||||
}
|
||||
public void Indent_(boolean v) {Indent_val = v ? "y" : "n";}
|
||||
public void Exec_tidy(Xoae_page page, Bry_bfr bfr) {
|
||||
public void Exec_tidy(Bry_bfr bfr, byte[] page_url) {
|
||||
int bfr_len = bfr.Len();
|
||||
long bgn = Env_.TickCount();
|
||||
long bgn = System_.Ticks();
|
||||
Io_mgr.Instance.SaveFilBfr(tidy_source, bfr); // saves bfr to source; clears bfr
|
||||
this.Run(tidy_source.Raw(), tidy_target.Raw()); // converts source to target
|
||||
Io_mgr.Instance.LoadFilBryByBfr(tidy_target, bfr); // loads bfr by target
|
||||
if (bfr.Len_eq_0()) // something went wrong; load from source
|
||||
Io_mgr.Instance.LoadFilBryByBfr(tidy_source, bfr); // loads bfr by target
|
||||
app.Usr_dlg().Log_many("", "", "tidy exec; elapsed=~{0} len=~{1}", Env_.TickCount_elapsed_in_frac(bgn), bfr_len);
|
||||
app.Usr_dlg().Log_many("", "", "tidy exec; elapsed=~{0} len=~{1}", System_.Ticks__elapsed_in_frac(bgn), bfr_len);
|
||||
}
|
||||
private static String Indent_val = "y";
|
||||
public static String Args_fmt = String_.Concat // see https://meta.wikimedia.org/wiki/Data_dumps; missing numeric-entities:yes; enclose-text: yes
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.langs.htmls.*;
|
||||
public class Xow_tidy_mgr implements Gfo_evt_itm {
|
||||
public class Xow_tidy_mgr implements Gfo_evt_itm, Xow_tidy_mgr_interface {
|
||||
private Xoae_app app; private Xoa_tidy_mgr tidy_mgr;
|
||||
private boolean enabled = true; private Xoh_tidy_wkr wkr = Xoh_tidy_wkr_.Wkr_null; // TEST: set default wkr to null
|
||||
public Xow_tidy_mgr() {this.evt_mgr = new Gfo_evt_mgr(this);}
|
||||
@@ -38,12 +38,12 @@ public class Xow_tidy_mgr implements Gfo_evt_itm {
|
||||
this.enabled = tidy_mgr.Enabled();
|
||||
this.Wkr_(tidy_mgr.Wkr_tid());
|
||||
}
|
||||
public void Run_tidy_html(Xoae_page page, Bry_bfr bfr, boolean indent) {
|
||||
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {
|
||||
if (!enabled) return;
|
||||
if (bfr.Len_eq_0()) return; // document is empty; do not exec b/c tidy will never generate files for 0 len files, and previous file will remain; DATE:2014-06-04
|
||||
Tidy_wrap(bfr);
|
||||
wkr.Indent_(indent);
|
||||
wkr.Exec_tidy(page, bfr);
|
||||
wkr.Exec_tidy(bfr, page_url);
|
||||
Tidy_unwrap(bfr);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public interface Xow_tidy_mgr_interface {
|
||||
void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.htmls.core.htmls.tidy; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xow_tidy_mgr_interface_ {
|
||||
public static final Xow_tidy_mgr_interface Noop = new Xow_tidy_mgr_interface__noop();
|
||||
}
|
||||
class Xow_tidy_mgr_interface__noop implements Xow_tidy_mgr_interface {
|
||||
public void Exec_tidy(Bry_bfr bfr, boolean indent, byte[] page_url) {}
|
||||
}
|
||||
@@ -53,5 +53,5 @@ public class Xoh_hzip_dict_ {
|
||||
, Key__pgbnr = "pgbnr"
|
||||
, Key__media = "media"
|
||||
;
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1;
|
||||
public static final int Hzip__none = 0, Hzip__v1 = 1, Hzip__plain = 2; // SERIALIZED
|
||||
}
|
||||
|
||||
@@ -17,22 +17,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.xndes.tags.*; import gplx.xowa.htmls.core.wkrs.xndes.dicts.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.apps.fsys.*; import gplx.xowa.files.caches.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.xndes.tags.*; import gplx.xowa.htmls.core.wkrs.xndes.dicts.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*; import gplx.xowa.files.caches.*; import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.apps.metas.*;
|
||||
public class Xoh_hdoc_ctx {
|
||||
private byte[] fsys__file;
|
||||
private byte[] fsys__file, abrv__commons, abrv__wiki;
|
||||
public byte[] Fsys__res() {return fsys__res;} private byte[] fsys__res;
|
||||
public byte[] Fsys__root() {return fsys__root;} private byte[] fsys__root;
|
||||
public byte[] Fsys__file__comm() {return fsys__file__comm;} private byte[] fsys__file__comm;
|
||||
public byte[] Fsys__file__wiki() {return fsys__file__wiki;} private byte[] fsys__file__wiki;
|
||||
public Xof_repo_itm Fsys__repo(boolean local) {return local ? repo_local : repo_remote;} private Xof_repo_itm repo_remote, repo_local;
|
||||
public boolean Fsys__is_wnt() {return fsys__is_wnt;} private boolean fsys__is_wnt;
|
||||
public Xoa_app App() {return app;} private Xoa_app app;
|
||||
public byte[] Wiki__domain_bry() {return wiki__domain_bry;} private byte[] wiki__domain_bry;
|
||||
public Xow_domain_itm Wiki__domain_itm() {return wiki__domain_itm;} private Xow_domain_itm wiki__domain_itm;
|
||||
public Xow_ttl_parser Wiki__ttl_parser() {return wiki__ttl_parser;} private Xow_ttl_parser wiki__ttl_parser;
|
||||
public Xow_url_parser Wiki__url_parser() {return wiki__url_parser;} private Xow_url_parser wiki__url_parser;
|
||||
public boolean Xwiki_mgr__missing(byte[] domain){return app.Xwiki_mgr__missing(domain);}
|
||||
public Xou_cache_finder File__mgr() {return file__mgr;} private Xou_cache_finder file__mgr = Xou_cache_finder_.Noop;
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private final Xof_url_bldr file__url_bldr = new Xof_url_bldr();
|
||||
public Xou_cache_finder Cache_mgr() {return cache_mgr;} private Xou_cache_finder cache_mgr = Xou_cache_finder_.Noop;
|
||||
public byte[] Cache__wiki_abrv(boolean repo_is_commons) {return repo_is_commons ? abrv__commons : abrv__wiki;}
|
||||
public Xof_url_bldr File__url_bldr() {return file__url_bldr;} private final Xof_url_bldr file__url_bldr = Xof_url_bldr.new_v2();
|
||||
public Xoa_page Page() {return page;} private Xoa_page page;
|
||||
public byte[] Page__url() {return page__url;} private byte[] page__url;
|
||||
public Xoh_pool_mgr__hzip Pool_mgr__hzip() {return pool_mgr__hzip;} private final Xoh_pool_mgr__hzip pool_mgr__hzip = new Xoh_pool_mgr__hzip();
|
||||
@@ -50,8 +54,10 @@ public class Xoh_hdoc_ctx {
|
||||
this.fsys__file = fsys_mgr.File_dir().To_http_file_bry();
|
||||
this.fsys__file__comm = Bry_.Add(fsys__file, Xow_domain_itm_.Bry__commons, Byte_ascii.Slash_bry);
|
||||
this.fsys__res = gplx.core.envs.Op_sys.Cur().Tid_is_drd() ? Fsys__res__drd : fsys__root;
|
||||
Xou_cache_mgr cache_mgr = app.User().User_db_mgr().Cache_mgr();
|
||||
if (cache_mgr != null && cache_mgr.Enabled()) file__mgr = Xou_cache_finder_.New_db(cache_mgr); // NOTE: this effectively only loads the cache db in app mode (and not in test mode)
|
||||
this.fsys__is_wnt = gplx.core.envs.Op_sys.Cur().Tid_is_wnt();
|
||||
Xou_cache_mgr usr_cache_mgr = app.User().User_db_mgr().Cache_mgr();
|
||||
if (usr_cache_mgr != null && usr_cache_mgr.Enabled()) cache_mgr = Xou_cache_finder_.New_db(usr_cache_mgr); // NOTE: this effectively only loads the cache db in app mode (and not in test mode)
|
||||
this.abrv__commons = Xow_domain_itm_.parse(Xow_domain_itm_.Bry__commons).Abrv_xo();
|
||||
pool_mgr__hzip.Init();
|
||||
}
|
||||
public void Init_by_page(Xow_wiki wiki, Xoa_page page) {
|
||||
@@ -59,6 +65,22 @@ public class Xoh_hdoc_ctx {
|
||||
this.wiki__url_parser = wiki.Utl__url_parser();
|
||||
this.wiki__ttl_parser = wiki;
|
||||
this.wiki__domain_bry = wiki.Domain_bry();
|
||||
this.wiki__domain_itm = wiki.Domain_itm();
|
||||
|
||||
// init repos
|
||||
Xof_repo_pair[] pairs = wiki.File__repo_mgr().Repos_ary();
|
||||
int pairs_len = pairs.length;
|
||||
for (int i = 0; i < pairs_len; ++i) {
|
||||
Xof_repo_pair pair = pairs[i];
|
||||
Xof_repo_itm itm = pair.Trg();
|
||||
byte[] itm_domain = itm.Wiki_domain();
|
||||
if (Bry_.Eq(itm_domain, wiki__domain_bry))
|
||||
repo_local = itm;
|
||||
else if (Bry_.Eq(itm_domain, Xow_domain_itm_.Bry__commons))
|
||||
repo_remote = pair.Trg();
|
||||
}
|
||||
|
||||
this.abrv__wiki = wiki.Domain_itm().Abrv_xo();
|
||||
this.fsys__file__wiki = Bry_.Add(fsys__file, wiki__domain_bry, Byte_ascii.Slash_bry);
|
||||
this.page = page;
|
||||
this.page__url = page.Url_bry_safe();
|
||||
@@ -69,7 +91,7 @@ public class Xoh_hdoc_ctx {
|
||||
this.uid__gly = -1;
|
||||
}
|
||||
|
||||
public void Test__file__mgr_(Xou_cache_finder v) {this.file__mgr = v;}
|
||||
public void Test__cache__mgr_(Xou_cache_finder v) {this.cache_mgr = v;}
|
||||
public static final int Invalid = -1;
|
||||
private static final byte[] Fsys__res__drd = Bry_.new_a7("file:///android_asset/xowa/");
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ public class Xoh_hzip_fxt {
|
||||
public void Init_wiki_installed(String domain) {parser_fxt.Init_xwiki_add_user_(domain);}
|
||||
public Xou_cache_finder_mem Init_file_mgr__mem() {
|
||||
Xou_cache_finder_mem rv = Xou_cache_finder_.New_mem();
|
||||
hzip_mgr.Hctx().Test__file__mgr_(rv);
|
||||
hzip_mgr.Hctx().Test__cache__mgr_(rv);
|
||||
return rv;
|
||||
}
|
||||
public void Init_file_mgr__noop() {
|
||||
hzip_mgr.Hctx().Test__file__mgr_(Xou_cache_finder_.Noop);
|
||||
hzip_mgr.Hctx().Test__cache__mgr_(Xou_cache_finder_.Noop);
|
||||
}
|
||||
public Xowe_wiki Init_wiki_alias(String alias, String domain) {
|
||||
Xowe_wiki rv = Xoa_app_fxt.Make__wiki__edit(parser_fxt.App(), domain);
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.xowa.htmls.core.wkrs; import gplx.*; import gplx.xowa.*; import gpl
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
public abstract class Xoh_itm_parser_fxt {
|
||||
private final Xoae_app app;
|
||||
private final Xowe_wiki wiki;
|
||||
protected final Xoae_app app;
|
||||
protected final Xowe_wiki wiki;
|
||||
private final Bry_err_wkr err_wkr = new Bry_err_wkr();
|
||||
protected byte[] src; protected int src_len;
|
||||
protected final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
|
||||
@@ -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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import gplx.core.threads.poolables.*;
|
||||
import gplx.core.btries.*; import gplx.core.threads.poolables.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
public class Xoh_img_bare_data implements Xoh_data_itm {
|
||||
@@ -30,27 +30,38 @@ public class Xoh_img_bare_data implements Xoh_data_itm {
|
||||
this.src_bgn = src_end = img_tid = dir_bgn = dir_end = -1;
|
||||
}
|
||||
public boolean Init_by_parse(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag img_head, Gfh_tag unused) {
|
||||
// get src attribute
|
||||
this.src_bgn = img_head.Src_bgn(); this.src_end = img_head.Src_end();
|
||||
Gfh_atr img_src_atr = img_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__src); if (img_src_atr.Val_dat_missing()) return false;
|
||||
byte[] root_dir_bry = hctx.Fsys__res(); // NOTE: Fsys_res == Fsys_root on all machines except drd;
|
||||
|
||||
// check if it begins with the xowa root dir; EX: src='file:///C:/xowa/...'
|
||||
byte[] root_dir_bry = hctx.Fsys__res(); // NOTE: Fsys_res == Fsys_root on all machines except drd; note that hdump builds are not done on drd
|
||||
int root_dir_bgn = img_src_atr.Val_bgn();
|
||||
int root_dir_end = root_dir_bgn + root_dir_bry.length;
|
||||
if (Bry_.Match(src, root_dir_bgn, root_dir_end, root_dir_bry)) {
|
||||
int hiero_dir_end = root_dir_end + Url__hiero.length;
|
||||
if (Bry_.Match(src, root_dir_end, hiero_dir_end, Url__hiero)) {
|
||||
img_tid = Img_tid__hiero;
|
||||
dir_bgn = root_dir_bgn;
|
||||
dir_end = hiero_dir_end;
|
||||
return true;
|
||||
}
|
||||
if (Bry_.Match(src, root_dir_bgn, root_dir_end, root_dir_bry)) { // begins with XOWA root dir
|
||||
byte trie_tid = trie.Match_byte_or(trv, src, root_dir_end, src_end, Byte_.Max_value_127);
|
||||
if (trie_tid == Byte_.Max_value_127) return false;
|
||||
img_tid = trie_tid;
|
||||
dir_bgn = root_dir_bgn;
|
||||
dir_end = trv.Pos();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void Init_by_decode__hiero(int src_bgn, int src_end, int dir_bgn, int dir_end) {
|
||||
this.img_tid = Img_tid__hiero; this.src_bgn = src_bgn; this.src_end = src_end; this.dir_bgn = dir_bgn; this.dir_end = dir_end;
|
||||
public void Init_by_decode(int img_tid, int src_bgn, int src_end, int dir_bgn, int dir_end) {
|
||||
this.img_tid = img_tid; this.src_bgn = src_bgn; this.src_end = src_end; this.dir_bgn = dir_bgn; this.dir_end = dir_end;
|
||||
}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_bare_data rv = new Xoh_img_bare_data(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
|
||||
public static final byte[] Url__hiero = Bry_.new_a7("bin/any/xowa/xtns/Wikihiero/img/hiero_");
|
||||
public static final int Img_tid__hiero = 0;
|
||||
|
||||
public static final byte Img_tid__hiero = 0, Img_tid__imap_btn = 1;
|
||||
public static final byte[]
|
||||
Url__hiero = Bry_.new_a7("bin/any/xowa/xtns/Wikihiero/img/hiero_")
|
||||
, Url__imap = Bry_.new_a7("bin/any/xowa/xtns/ImageMap/imgs/")
|
||||
;
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs()
|
||||
.Add_bry_byte(Url__hiero, Img_tid__hiero)
|
||||
.Add_bry_byte(Url__imap , Img_tid__imap_btn)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -24,32 +24,24 @@ public class Xoh_img_bare_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
public byte[] Hook() {return hook;} private byte[] hook;
|
||||
public Gfo_poolable_itm Encode1(Xoh_hzip_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, boolean wkr_is_root, byte[] src, Object data_obj) {
|
||||
Xoh_img_bare_data data = (Xoh_img_bare_data)data_obj;
|
||||
int img_tid = flag_bldr.Set_as_int(Flag__img_tid , data.Img_tid());
|
||||
flag_bldr.Set_as_int(Flag__img_tid , data.Img_tid());
|
||||
bfr.Add(hook);
|
||||
Gfo_hzip_int_.Encode(1, bfr, flag_bldr.Encode());
|
||||
switch (img_tid) {
|
||||
case Xoh_img_bare_data.Img_tid__hiero:
|
||||
bfr.Add_hzip_mid(src, data.Src_bgn(), data.Dir_bgn());
|
||||
bfr.Add_hzip_mid(src, data.Dir_end(), data.Src_end());
|
||||
break;
|
||||
}
|
||||
bfr.Add_hzip_mid(src, data.Src_bgn(), data.Dir_bgn());
|
||||
bfr.Add_hzip_mid(src, data.Dir_end(), data.Src_end());
|
||||
return this;
|
||||
}
|
||||
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
|
||||
Xoh_img_bare_data data = (Xoh_img_bare_data)data_itm; data.Clear();
|
||||
int flag = rdr.Read_hzip_int(1); flag_bldr.Decode(flag);
|
||||
int dir_tid = flag_bldr.Get_as_int(Flag__img_tid);
|
||||
switch (dir_tid) {
|
||||
case Xoh_img_bare_data.Img_tid__hiero:
|
||||
int tag_0_bgn = rdr.Pos(), tag_0_end = rdr.Find_fwd_lr();
|
||||
int tag_1_bgn = rdr.Pos(), tag_1_end = rdr.Find_fwd_lr();
|
||||
data.Init_by_decode__hiero(tag_0_bgn, tag_1_end, tag_0_end, tag_1_bgn);
|
||||
break;
|
||||
}
|
||||
int img_tid = flag_bldr.Get_as_int(Flag__img_tid);
|
||||
int tag_0_bgn = rdr.Pos(), tag_0_end = rdr.Find_fwd_lr();
|
||||
int tag_1_bgn = rdr.Pos(), tag_1_end = rdr.Find_fwd_lr();
|
||||
data.Init_by_decode(img_tid, tag_0_bgn, tag_1_end, tag_0_end, tag_1_bgn);
|
||||
}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_bare_hzip rv = new Xoh_img_bare_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(2);
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(2);
|
||||
private static final int // SERIALIZED
|
||||
Flag__img_tid = 0
|
||||
;
|
||||
|
||||
@@ -34,4 +34,16 @@ public class Xoh_img_bare_hzip__tst {
|
||||
, "<img style='margin: 1px; height: 11px;' src='file:///android_asset/xowa/bin/any/xowa/xtns/Wikihiero/img/hiero_X1.png' title='X1 [t]' alt='t'>"
|
||||
);
|
||||
}
|
||||
@Test public void Imap_btn() {
|
||||
fxt.Test__bicode
|
||||
( "~(\"<img alt=\"About this image\" src=\"~desc-20.png\" style=\"border: none;\">~"
|
||||
, "<img alt=\"About this image\" src=\"file:///android_asset/xowa/bin/any/xowa/xtns/ImageMap/imgs/desc-20.png\" style=\"border: none;\">"
|
||||
);
|
||||
}
|
||||
@Test public void Imap_map() {
|
||||
fxt.Test__bicode
|
||||
( "~%}*BhtA.png~#$m#T\"A.png~"
|
||||
, "<img src=\"file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/330px.png\" width=\"330\" height=\"220\" class=\"thumbimage\" alt=\"\" usemap=\"#imagemap_1_1\">"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,14 @@ public class Xoh_img_bare_wtr implements Bfr_arg, Xoh_wtr_itm {
|
||||
return true;
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
byte[] url_bry = Bry_.Empty;
|
||||
switch (data_itm.Img_tid()) {
|
||||
case Xoh_img_bare_data.Img_tid__hiero:
|
||||
bfr.Add_mid(src, data_itm.Src_bgn(), data_itm.Dir_bgn());
|
||||
bfr.Add(hctx.Fsys__res()).Add(Xoh_img_bare_data.Url__hiero); // NOTE: must use Fsys_res will be android_asset on drd; en.w:Hieroglyphics DATE:2016-01-31
|
||||
bfr.Add_mid(src, data_itm.Dir_end(), data_itm.Src_end());
|
||||
break;
|
||||
case Xoh_img_bare_data.Img_tid__hiero: url_bry = Xoh_img_bare_data.Url__hiero; break;
|
||||
case Xoh_img_bare_data.Img_tid__imap_btn: url_bry = Xoh_img_bare_data.Url__imap; break;
|
||||
}
|
||||
bfr.Add_mid(src, data_itm.Src_bgn(), data_itm.Dir_bgn());
|
||||
bfr.Add(hctx.Fsys__res()).Add(url_bry); // NOTE: must use Fsys_res will be android_asset on drd; en.w:Hieroglyphics DATE:2016-01-31
|
||||
bfr.Add_mid(src, data_itm.Dir_end(), data_itm.Src_end());
|
||||
}
|
||||
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xoh_img_data implements Xoh_data_itm {
|
||||
public int Anch_title_bgn() {return anch_title_bgn;} private int anch_title_bgn;
|
||||
public int Anch_title_end() {return anch_title_end;} private int anch_title_end;
|
||||
public boolean Anch_title_exists() {return anch_title_end != -1;}
|
||||
public Bry_obj_ref Anch_page() {return anch_page;} private Bry_obj_ref anch_page = Bry_obj_ref.New_empty();
|
||||
public Bry_obj_ref Anch_xo_ttl() {return anch_xo_ttl;} private Bry_obj_ref anch_xo_ttl = Bry_obj_ref.New_empty();
|
||||
public Xoh_img_src_data Img_src() {return img_src;} private final Xoh_img_src_data img_src = new Xoh_img_src_data();
|
||||
public Xoh_img_cls_data Img_cls() {return img_cls;} private final Xoh_img_cls_data img_cls = new Xoh_img_cls_data();
|
||||
public Xoh_img_xoimg_data Img_xoimg() {return img_xoimg;} private final Xoh_img_xoimg_data img_xoimg = new Xoh_img_xoimg_data();
|
||||
@@ -39,11 +39,11 @@ public class Xoh_img_data implements Xoh_data_itm {
|
||||
public boolean Img_alt__diff__anch_title() {return img_alt__diff_anch_title;} private boolean img_alt__diff_anch_title;
|
||||
public int Img_w() {return img_w;} private int img_w;
|
||||
public int Img_h() {return img_h;} private int img_h;
|
||||
public boolean Img_w__diff__file_w() {return img_w != img_src.File_w();}
|
||||
public boolean Img_w__diff__file_w() {return !img_src.File_is_orig() && img_w != img_src.File_w();}
|
||||
public boolean Img_is_vid() {return img_is_vid;} private boolean img_is_vid;
|
||||
public boolean Img_wo_anch() {return img_wo_anch;} private boolean img_wo_anch;
|
||||
public boolean Img_wo_anch() {return img_wo_anch;} private boolean img_wo_anch;
|
||||
public int Img_imap_idx() {return img_imap_idx;} private int img_imap_idx;
|
||||
public boolean Img_is_gallery() {return img_is_gallery;} private boolean img_is_gallery; public void Img_is_gallery_(boolean v) {this.img_is_gallery = v;}
|
||||
public boolean Img_is_gallery() {return img_is_gallery;} private boolean img_is_gallery; public void Img_is_gallery_(boolean v) {this.img_is_gallery = v;}
|
||||
public Pgbnr_itm Img_pgbnr() {return img_pgbnr;} private final Pgbnr_itm img_pgbnr = new Pgbnr_itm();
|
||||
public void Clear() {
|
||||
this.img_alt__diff_anch_title = anch_rel_is_nofollow = img_is_vid = img_wo_anch = img_is_gallery = false;
|
||||
@@ -58,7 +58,7 @@ public class Xoh_img_data implements Xoh_data_itm {
|
||||
this.img_wo_anch = anch_head.Name_id() == Gfh_tag_.Id__img;
|
||||
if (img_wo_anch) {
|
||||
Gfh_atr xowa_title = anch_head.Atrs__get_by_or_empty(Xoh_img_xoimg_data.Bry__data_xowa_title); // data-xowa-title='A.png'
|
||||
anch_page.Val_(xowa_title.Val());
|
||||
anch_xo_ttl.Val_(xowa_title.Val());
|
||||
}
|
||||
else {
|
||||
if (anch_head.Name_id() == Gfh_tag_.Id__div) { // video / audio
|
||||
@@ -73,7 +73,7 @@ public class Xoh_img_data implements Xoh_data_itm {
|
||||
Gfh_atr anch_title = anch_head.Atrs__get_by_or_empty(Gfh_atr_.Bry__title); // title='abc'
|
||||
anch_title_bgn = anch_title.Val_bgn(); anch_title_end = anch_title.Val_end();
|
||||
Gfh_atr xowa_title = anch_head.Atrs__get_by_or_empty(Bry__atr__xowa_title); // xowa_title='A.png'
|
||||
if (xowa_title.Val_dat_exists()) anch_page.Val_(xowa_title.Val());
|
||||
if (xowa_title.Val_dat_exists()) anch_xo_ttl.Val_(xowa_title.Val());
|
||||
img_tag = tag_rdr.Tag__move_fwd_head();
|
||||
}
|
||||
img_tag.Chk_name_or_fail(Gfh_tag_.Id__img); // <img
|
||||
@@ -88,10 +88,10 @@ public class Xoh_img_data implements Xoh_data_itm {
|
||||
img_cls.Init_by_parse(err_wkr, src, img_tag); // class='thumbborder'
|
||||
img_alt__diff_anch_title = !Bry_.Match(src, img_alt_bgn, img_alt_end, src, anch_title_bgn, anch_title_end);
|
||||
if (!img_src.Parse(err_wkr, hctx, hctx.Wiki__domain_bry(), img_tag)) return false; // src='...'
|
||||
if (anch_page.Val_is_empty()) {
|
||||
anch_page.Val_(img_src.File_ttl_bry());
|
||||
if (anch_page.Val_is_empty())
|
||||
anch_page.Val_(anch_href.Ttl_page_db());
|
||||
if (anch_xo_ttl.Val_is_empty()) {
|
||||
anch_xo_ttl.Val_(img_src.File_ttl_bry());
|
||||
if (anch_xo_ttl.Val_is_empty())
|
||||
anch_xo_ttl.Val_(anch_href.Ttl_page_db());
|
||||
}
|
||||
this.img_imap_idx = Get_imap_idx(tag_rdr.Err_wkr(), img_tag);
|
||||
if (img_wo_anch) {
|
||||
|
||||
@@ -34,10 +34,10 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
Xoh_img_data data = (Xoh_img_data)data_obj;
|
||||
Xoh_anch_href_data anch_href = data.Anch_href();
|
||||
boolean img_wo_anch = data.Img_wo_anch();
|
||||
Bry_obj_ref anch_page = data.Anch_page();
|
||||
Bry_obj_ref anch_page = data.Anch_xo_ttl();
|
||||
byte anch_href_tid = anch_href.Tid();
|
||||
boolean anch__ns_is_custom = anch_href.Ttl_ns_custom() != null;
|
||||
boolean anch__ns_id_needs_saving = Xoh_anch_href_data.Ns_exists(anch_href.Tid()) && anch_href.Ttl_ns_id() != Xow_ns_.Tid__file;
|
||||
boolean anch__ns_needs_saving = Xoh_anch_href_data.Ns_exists(anch_href.Tid()) && anch_href.Ttl_ns_id() != Xow_ns_.Tid__file;
|
||||
boolean anch_title_exists = data.Anch_title_exists();
|
||||
Xoh_img_xoimg_data img_xoimg = data.Img_xoimg();
|
||||
Xoh_img_cls_data img_cls = data.Img_cls();
|
||||
@@ -45,8 +45,9 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
boolean img__alt_diff_from_anch_title = data.Img_alt__diff__anch_title();
|
||||
boolean file__src_exists = !img_xoimg.Val_dat_exists();
|
||||
boolean anch_href_diff_file = !img_wo_anch && !Bry_.Match(anch_page.Val(), anch_page.Val_bgn(), anch_page.Val_end(), anch_href.Ttl_page_db());
|
||||
boolean img__is_imap = flag_bldr.Set_as_bool(Flag__img__is_imap , data.Img_imap_idx() != -1);
|
||||
boolean img__is_pgbnr = flag_bldr.Set_as_bool(Flag__img__is_pgbnr , data.Img_pgbnr().Exists());
|
||||
boolean img__is_imap = flag_bldr.Set_as_bool(Flag__img__is_imap , data.Img_imap_idx() != -1);
|
||||
boolean img__is_pgbnr = flag_bldr.Set_as_bool(Flag__img__is_pgbnr , data.Img_pgbnr().Exists());
|
||||
boolean img__src_is_diff = flag_bldr.Set_as_bool(Flag__file__src_diff_href , file__src_exists && img_src.Src_end() != -1 && !Bry_.Eq(anch_href.Ttl_page_db(), img_src.File_ttl_bry())); // && img_src.Src_end() != -1; handle missing src in corrupt html; EX: <img w=1 h=2>
|
||||
flag_bldr.Set(Flag__img__wo_anch , img_wo_anch);
|
||||
flag_bldr.Set(Flag__img__is_vid , data.Img_is_vid());
|
||||
flag_bldr.Set(Flag__file__w_diff_from_html , file__src_exists && data.Img_w__diff__file_w());
|
||||
@@ -58,7 +59,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
flag_bldr.Set(Flag__img__cls_other_exists , img_cls.Other_exists());
|
||||
flag_bldr.Set(Flag__anch__ns_is_custom , anch__ns_is_custom);
|
||||
flag_bldr.Set(Flag__anch__cls_tid , data.Anch_cls().Tid());
|
||||
flag_bldr.Set(Flag__anch__ns_id_needs_saving , anch__ns_id_needs_saving);
|
||||
flag_bldr.Set(Flag__anch__ns_needs_saving , anch__ns_needs_saving);
|
||||
flag_bldr.Set(Flag__img__alt_diff_from_anch_title , img__alt_diff_from_anch_title);
|
||||
flag_bldr.Set(Flag__anch__href_diff_file , anch_href_diff_file);
|
||||
flag_bldr.Set(Flag__anch__title_missing , !anch_title_exists);
|
||||
@@ -84,7 +85,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
if (anch_href_diff_file) {
|
||||
data.Anch_page().Bfr_arg__add(bfr);
|
||||
data.Anch_xo_ttl().Bfr_arg__add(bfr);
|
||||
bfr.Add_byte(Xoh_hzip_dict_.Escape);
|
||||
}
|
||||
switch (anch_href_tid) {
|
||||
@@ -93,7 +94,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
break;
|
||||
case Xoh_anch_href_data.Tid__wiki:
|
||||
case Xoh_anch_href_data.Tid__site:
|
||||
if (anch__ns_id_needs_saving)
|
||||
if (anch__ns_needs_saving)
|
||||
Xoh_lnki_dict_.Ns_encode(bfr, anch_href.Ttl_ns_id());
|
||||
break;
|
||||
}
|
||||
@@ -102,7 +103,7 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
Gfo_hzip_int_.Encode(2, bfr, Gfo_hzip_int_.Neg_1_adj + data.Img_w());
|
||||
Gfo_hzip_int_.Encode(2, bfr, Gfo_hzip_int_.Neg_1_adj + data.Img_h());
|
||||
if (data.Img_w__diff__file_w()) Gfo_hzip_int_.Encode(2, bfr, Gfo_hzip_int_.Neg_1_adj + img_src.File_w());
|
||||
if (img_src.File_time_exists()) Gfo_hzip_int_.Encode(1, bfr, Gfo_hzip_int_.Neg_1_adj + img_src.File_time());
|
||||
if (img_src.File_time_exists()) bfr.Add_hzip_double(img_src.File_time());
|
||||
if (img_src.File_page_exists()) Gfo_hzip_int_.Encode(1, bfr, Gfo_hzip_int_.Neg_1_adj + img_src.File_page());
|
||||
}
|
||||
else
|
||||
@@ -118,62 +119,79 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
bfr.Add_hzip_bry(pgbnr.Srcset());
|
||||
bfr.Add_hzip_bry(pgbnr.Style_if_not_dflt());
|
||||
}
|
||||
if (img__src_is_diff) {
|
||||
bfr.Add_hzip_bry(img_src.File_ttl_bry());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public void Decode1(Bry_bfr bfr, Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Xoh_page hpg, Bry_rdr rdr, byte[] src, int src_bgn, int src_end, Xoh_data_itm data_itm) {
|
||||
// decode flags
|
||||
// read flags; order doesn't matter, but reading <a> -> <img> -> src=
|
||||
Xoh_img_data data = (Xoh_img_data)data_itm; data.Clear();
|
||||
int flag = rdr.Read_hzip_int(2); flag_bldr.Decode(flag);
|
||||
boolean img__is_pgbnr = flag_bldr.Get_as_bool(Flag__img__is_pgbnr);
|
||||
int anch__href_tid = flag_bldr.Get_as_int(Flag__anch__href_tid);
|
||||
boolean anch__title_missing = flag_bldr.Get_as_bool(Flag__anch__title_missing);
|
||||
boolean anch__href_diff_file = flag_bldr.Get_as_bool(Flag__anch__href_diff_file);
|
||||
boolean anch__ns_needs_saving = flag_bldr.Get_as_bool(Flag__anch__ns_needs_saving);
|
||||
boolean anch__ns_is_custom = flag_bldr.Get_as_bool(Flag__anch__ns_is_custom);
|
||||
int anch__cls_tid = flag_bldr.Get_as_int(Flag__anch__cls_tid);
|
||||
int img__cls = flag_bldr.Get_as_int(Flag__img__cls_tid);
|
||||
boolean img__cls_other_exists = flag_bldr.Get_as_bool(Flag__img__cls_other_exists);
|
||||
boolean img__alt_diff_from_anch_title = flag_bldr.Get_as_bool(Flag__img__alt_diff_from_anch_title);
|
||||
boolean img__wo_anch = flag_bldr.Get_as_bool(Flag__img__wo_anch);
|
||||
boolean img__is_vid = flag_bldr.Get_as_bool(Flag__img__is_vid);
|
||||
boolean img__is_imap = flag_bldr.Get_as_bool(Flag__img__is_imap);
|
||||
boolean img_wo_anch = flag_bldr.Get_as_bool(Flag__img__wo_anch);
|
||||
boolean img__is_pgbnr = flag_bldr.Get_as_bool(Flag__img__is_pgbnr);
|
||||
boolean img__src_is_diff = flag_bldr.Get_as_bool(Flag__file__src_diff_href);
|
||||
boolean file__is_orig = flag_bldr.Get_as_bool(Flag__file__is_orig);
|
||||
boolean file__repo_is_local = flag_bldr.Get_as_bool(Flag__file__repo_is_local);
|
||||
boolean file__src_exists = flag_bldr.Get_as_bool(Flag__file__src_exists);
|
||||
boolean img__cls_other_exists = flag_bldr.Get_as_bool(Flag__img__cls_other_exists);
|
||||
boolean anch__ns_is_custom = flag_bldr.Get_as_bool(Flag__anch__ns_is_custom);
|
||||
boolean anch__ns_id_needs_saving = flag_bldr.Get_as_bool(Flag__anch__ns_id_needs_saving);
|
||||
int anch__cls_tid = flag_bldr.Get_as_int(Flag__anch__cls_tid);
|
||||
boolean img__alt_diff_from_anch_title = flag_bldr.Get_as_bool(Flag__img__alt_diff_from_anch_title);
|
||||
boolean anch_href_diff_file = flag_bldr.Get_as_bool(Flag__anch__href_diff_file);
|
||||
boolean anch__title_missing = flag_bldr.Get_as_bool(Flag__anch__title_missing);
|
||||
boolean img_is_vid = flag_bldr.Get_as_bool(Flag__img__is_vid);
|
||||
int img_cls = flag_bldr.Get_as_int(Flag__img__cls_tid);
|
||||
int anch__href_tid = flag_bldr.Get_as_int(Flag__anch__href_tid);
|
||||
boolean file__time_exists = flag_bldr.Get_as_bool(Flag__file__time_exists);
|
||||
boolean file__page_exists = flag_bldr.Get_as_bool(Flag__file__page_exists);
|
||||
boolean file__w_diff_from_html = flag_bldr.Get_as_bool(Flag__file__w_diff_from_html);
|
||||
|
||||
// get page, file, etc.
|
||||
byte[] page_db = rdr.Read_bry_to();
|
||||
// get href_page; note: encoded; EX: "A%C3%A9b.png" not "Aéb.png"
|
||||
byte[] href_page = rdr.Read_bry_to();
|
||||
|
||||
// get site_bry; note: href_page will include site_bry and separate with pipe; EX:"en.wiktionary.org|A~"
|
||||
byte[] site_bry = null;
|
||||
switch (anch__href_tid) {
|
||||
case Xoh_anch_href_data.Tid__anch:
|
||||
case Xoh_anch_href_data.Tid__inet:
|
||||
case Xoh_anch_href_data.Tid__wiki:
|
||||
break;
|
||||
case Xoh_anch_href_data.Tid__site:
|
||||
int pipe_pos = Bry_find_.Find_fwd(page_db, Byte_ascii.Pipe);
|
||||
site_bry = Bry_.Mid(page_db, 0, pipe_pos);
|
||||
page_db = Bry_.Mid(page_db, pipe_pos + 1); // encode needed for foreign characters; PAGE:en.w:Pho; DATE:2016-01-04
|
||||
break;
|
||||
if (anch__href_tid == Xoh_anch_href_data.Tid__site) {
|
||||
int pipe_pos = Bry_find_.Find_fwd(href_page, Byte_ascii.Pipe);
|
||||
site_bry = Bry_.Mid(href_page, 0, pipe_pos);
|
||||
href_page = Bry_.Mid(href_page, pipe_pos + 1);
|
||||
}
|
||||
byte[] file_db = page_db;
|
||||
if (anch_href_diff_file) file_db = rdr.Read_bry_to();
|
||||
int anch_href_ns = -1;
|
||||
if (anch__ns_id_needs_saving)
|
||||
anch_href_ns = Xoh_lnki_dict_.Ns_decode(rdr);
|
||||
byte[] ns_custom_bry = null;
|
||||
if (anch__ns_is_custom) ns_custom_bry = Xoa_ttl.Replace_spaces(rdr.Read_bry_to()); // NOTE: use unders not spaces; will be used directly below to generate href; else href="User talk:A"; PAGE:de.b:Wikibooks:Benutzersperrung/_InselFahrer DATE:2016-06-25
|
||||
int img_w = -1, img_h = -1, file_time = -1, file_page = -1;
|
||||
|
||||
// get xo_ttl; note: unencoded; EX: "Aéb.png"; defaults to href_page, else uses next bry
|
||||
byte[] xo_ttl = anch__href_diff_file ? rdr.Read_bry_to() : href_page;
|
||||
|
||||
// get href_ns; usually -1 which means "File"; else, read next int
|
||||
int href_ns_id = anch__ns_needs_saving ? Xoh_lnki_dict_.Ns_decode(rdr) : -1;
|
||||
|
||||
// get href_custom; usually null, but can be "Image";
|
||||
byte[] href_ns_custom = anch__ns_is_custom
|
||||
? Xoa_ttl.Replace_spaces(rdr.Read_bry_to()) // NOTE: use unders not spaces; will be used directly below to generate href; else href="User talk:A"; PAGE:de.b:Wikibooks:Benutzersperrung/_InselFahrer DATE:2016-06-25
|
||||
: null;
|
||||
|
||||
// get img.src attributes like width, height, page, time
|
||||
int file_w = -1, img_w = -1, img_h = -1, file_page = -1;
|
||||
double file_time = -1;
|
||||
if (file__src_exists) {
|
||||
img_w = rdr.Read_hzip_int(2) - Gfo_hzip_int_.Neg_1_adj;
|
||||
img_h = rdr.Read_hzip_int(2) - Gfo_hzip_int_.Neg_1_adj;
|
||||
file_w = file__w_diff_from_html ? rdr.Read_hzip_int(2) - Gfo_hzip_int_.Neg_1_adj : img_w;
|
||||
if (file__time_exists) file_time = rdr.Read_double_to();
|
||||
if (file__page_exists) file_page = rdr.Read_hzip_int(1) - Gfo_hzip_int_.Neg_1_adj;
|
||||
}
|
||||
else
|
||||
xoimg.Decode(bfr, hctx, hpg, rdr, src, data.Img_xoimg());
|
||||
|
||||
// get anch_title; usually missing, else read next bry
|
||||
int anch_title_bgn = -1, anch_title_end = -1;
|
||||
if (!anch__title_missing) {
|
||||
anch_title_bgn = rdr.Pos();
|
||||
anch_title_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
|
||||
// get alt; usually anch_title, else read next bry
|
||||
int img_alt_bgn = -1, img_alt_end = -1;
|
||||
if (!anch__title_missing) {
|
||||
img_alt_bgn = anch_title_bgn;
|
||||
@@ -183,16 +201,18 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
img_alt_bgn = rdr.Pos();
|
||||
img_alt_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
|
||||
// get img_cls; usually missing, else read next bry
|
||||
int img_cls_other_bgn = -1; int img_cls_other_end = -1;
|
||||
if (img__cls_other_exists) {
|
||||
img_cls_other_bgn = rdr.Pos();
|
||||
img_cls_other_end = rdr.Find_fwd_lr();
|
||||
}
|
||||
|
||||
// handle imap idx
|
||||
// get imap_idx
|
||||
int img_imap_idx = img__is_imap ? rdr.Read_hzip_int(1) : -1;
|
||||
|
||||
// handle pgbnr
|
||||
// get pgbnr
|
||||
if (img__is_pgbnr) {
|
||||
double data_pos_x = rdr.Read_double_to();
|
||||
double data_pos_y = rdr.Read_double_to();
|
||||
@@ -202,83 +222,96 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
||||
data.Img_pgbnr().Init_by_decode(data_pos_x, data_pos_y, srcset, style);
|
||||
}
|
||||
|
||||
// transform values
|
||||
boolean anch_rel_is_nofollow = false;
|
||||
if (anch__href_tid == Xoh_anch_href_data.Tid__inet) {// external links should get rel=nofollow
|
||||
Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db);
|
||||
if (Bry_.Len_gt_0(page_db)) // NOTE: page_db == "" for Media links; EX:[[File:A.png|link=file:///C:/A.ogg]] -> <a href='' class='image'>
|
||||
// get img.src.page; usually same as anch.href.page, else read next bry
|
||||
byte[] src_page = img__src_is_diff ? rdr.Read_bry_to() : href_page;
|
||||
|
||||
// rdr done; build full anch_href
|
||||
boolean anch_rel_is_nofollow = false; // anch_rel_is_nofollow usually false, but true when image points to another wiki
|
||||
if (anch__href_tid == Xoh_anch_href_data.Tid__inet) {// handle external links
|
||||
tmp_bfr.Add(href_page); // href_page is actually entire url
|
||||
if (Bry_.Len_gt_0(href_page)) // NOTE: href_page == "" for Media links; EX:[[File:A.png|link=file:///C:/A.ogg]] -> <a href='' class='image'>
|
||||
anch_rel_is_nofollow = true;
|
||||
}
|
||||
else {
|
||||
// if site exists, add "/site/site_domain"
|
||||
if (anch__href_tid == Xoh_anch_href_data.Tid__site)
|
||||
tmp_bfr.Add(Xoh_href_.Bry__site).Add(site_bry);
|
||||
if (anch__ns_id_needs_saving) {
|
||||
byte[] page_ttl_bry = page_db;
|
||||
|
||||
// bld ttl_full; extra logic to handle ns
|
||||
if (anch__ns_needs_saving) {// link exists
|
||||
byte[] ttl_full = href_page;
|
||||
if ( anch__href_tid == Xoh_anch_href_data.Tid__wiki // if wiki, parse ttl
|
||||
|| anch_href_ns != Xow_ns_.Tid__main) { // or if site and !main_ns; handles /site/en.wiktionary.org/wiki/Special:Search but not /site/creativecommons.org/wiki/by/2.5; DATE:2015-12-28
|
||||
if (page_db.length == 0) { // handle invalid titles in link arg; EX:[[File:A.png|link=wikt:]]; PAGE:en.w:List_of_Saint_Petersburg_Metro_stations; DATE:2016-01-04
|
||||
Xow_ns anch_href_ns_itm = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(anch_href_ns);
|
||||
page_ttl_bry = anch_href_ns_itm.Name_db_w_colon(); // ASSUME:anch_href_ns is db_name not ui_name; EX: "Category_talk" vs "Category talk"
|
||||
|| href_ns_id != Xow_ns_.Tid__main) { // or if site and !main_ns; handles /site/en.wiktionary.org/wiki/Special:Search but not /site/creativecommons.org/wiki/by/2.5; DATE:2015-12-28
|
||||
if (href_page.length == 0) { // handle invalid titles in link arg; EX:[[File:A.png|link=wikt:]]; PAGE:en.w:List_of_Saint_Petersburg_Metro_stations; DATE:2016-01-04
|
||||
Xow_ns href_ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(href_ns_id);
|
||||
ttl_full = href_ns.Name_db_w_colon(); // ASSUME:use db_name not ui_name; EX: "Category_talk" vs "Category talk"
|
||||
}
|
||||
else {
|
||||
if (anch__ns_is_custom)
|
||||
page_ttl_bry = Bry_.Add(ns_custom_bry, Byte_ascii.Colon_bry, page_db); // handle ns aliases; EX:WP; PAGE:en.w:Wikipedia:WikiProject_Molecular_and_Cell_Biology; DATE:2016-01-11
|
||||
if (anch__ns_is_custom) // handle ns aliases; EX: "Image:Page"; EX:WP; PAGE:en.w:Wikipedia:WikiProject_Molecular_and_Cell_Biology; DATE:2016-01-11
|
||||
ttl_full = Bry_.Add(href_ns_custom, Byte_ascii.Colon_bry, href_page);
|
||||
else {
|
||||
if (anch__href_tid == Xoh_anch_href_data.Tid__site) { // if site, do not title-case page; EX:[[File:A.png|link=wikt:Category:en:A]]; PAGE:en.w:Portal:Trucks/Wikimedia; DATE:2016-01-11
|
||||
Xow_ns anch_href_ns_itm = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(anch_href_ns);
|
||||
page_ttl_bry = Bry_.Add(anch_href_ns_itm.Name_db_w_colon(), page_db);
|
||||
Xow_ns href_ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(href_ns_id);
|
||||
ttl_full = Bry_.Add(href_ns.Name_db_w_colon(), href_page); // NOTE: just add href_page; do not call ttl.Parse which will title-case;
|
||||
}
|
||||
else {
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(anch_href_ns, page_db);
|
||||
page_ttl_bry = anch_href_ttl.Full_db_w_anch();
|
||||
Xoa_ttl anch_href_ttl = hctx.Wiki__ttl_parser().Ttl_parse(href_ns_id, href_page);
|
||||
ttl_full = anch_href_ttl.Full_db_w_anch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(page_ttl_bry);
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(ttl_full);
|
||||
}
|
||||
else {
|
||||
byte[] ns_bry = anch__ns_is_custom ? ns_custom_bry : hctx.Wiki__ttl_parser().Ns_mgr().Ns_file().Name_db();
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(ns_bry).Add_byte_colon();
|
||||
tmp_bfr.Add(page_db);
|
||||
// Gfo_url_encoder_.Href.Encode(tmp_bfr, page_db); // encode needed for ?; PAGE:en.w:Voiceless_alveolar_affricate; DATE:2016-01-04
|
||||
else {// no link
|
||||
byte[] ns_bry = anch__ns_is_custom ? href_ns_custom : hctx.Wiki__ttl_parser().Ns_mgr().Ns_file().Name_db();
|
||||
tmp_bfr.Add(Xoh_href_.Bry__wiki).Add(ns_bry).Add_byte_colon().Add(href_page);
|
||||
}
|
||||
}
|
||||
this.anch_href_bry = tmp_bfr.To_bry_and_clear();
|
||||
// NOTE: src must go underneath ttl
|
||||
|
||||
// set url_bldr
|
||||
Xof_url_bldr url_bldr = hctx.File__url_bldr();
|
||||
url_bldr.Init_by_root(file__repo_is_local ? hctx.Fsys__file__wiki() : hctx.Fsys__file__comm(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
url_bldr.Init_by_itm(file__is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, file_db, Xof_file_wkr_.Md5(file_db), Xof_ext_.new_by_ttl_(file_db), img_w, file_time, file_page);
|
||||
|
||||
data.Init_by_decode(anch_rel_is_nofollow, anch_title_bgn, anch_title_end, img_wo_anch, img_is_vid, img_w, img_h, img_alt_bgn, img_alt_end, img_imap_idx);
|
||||
url_bldr.Init_by_root(file__repo_is_local ? hctx.Fsys__file__wiki() : hctx.Fsys__file__comm(), hctx.Fsys__is_wnt(), Byte_ascii.Slash, false, false, Md5_depth);
|
||||
// NOTE: set md5 / ext now b/c src_page will be changed for gui mode
|
||||
byte[] md5 = Xof_file_wkr_.Md5(src_page);
|
||||
Xof_ext ext = Xof_ext_.new_by_ttl_(src_page);
|
||||
if (!hpg.Wiki().File__fsdb_mode().Tid__bld()) // if gui, do not url-encode; else "View HTML" will not work, since fsys uses non-url-decoded form; note needs to be url-encoded else hdiff will return different values
|
||||
src_page = Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href.Decode(src_page));
|
||||
url_bldr.Init_for_trg_html(file__is_orig ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, hctx.Fsys__repo(file__repo_is_local), src_page, md5, ext, file_w, file_time, file_page);
|
||||
|
||||
// set data vars for wtr
|
||||
data.Init_by_decode(anch_rel_is_nofollow, anch_title_bgn, anch_title_end, img__wo_anch, img__is_vid, img_w, img_h, img_alt_bgn, img_alt_end, img_imap_idx);
|
||||
data.Anch_xo_ttl().Val_(xo_ttl); // set data-xowa-title
|
||||
data.Anch_href().Init_by_decode(anch_href_bry);
|
||||
data.Anch_cls().Init_by_decode(anch__cls_tid);
|
||||
data.Img_cls().Init_by_decode(src, img_cls, img_cls_other_bgn, img_cls_other_end);
|
||||
data.Img_src().Init_by_decode(file_db, url_bldr.Xto_bry());
|
||||
data.Img_cls().Init_by_decode(src, img__cls, img_cls_other_bgn, img_cls_other_end);
|
||||
data.Img_src().Init_by_decode(url_bldr.Xto_bry(), file__is_orig, src_page, file_w, file_time, file_page);
|
||||
}
|
||||
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
|
||||
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Xoh_img_hzip rv = new Xoh_img_hzip(); rv.pool_mgr = mgr; rv.pool_idx = idx; rv.hook = (byte[])args[0]; return rv;}
|
||||
public static int Md5_depth = 2;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_(1, 1, 1, 1, 1, 1, 1 , 1 , 1, 1, 1 , 1 , 2, 1, 1 , 1, 1, 2, 2);
|
||||
public static int Md5_depth = 4;
|
||||
private final Int_flag_bldr flag_bldr = new Int_flag_bldr().Pow_ary_bld_( 1, 1, 1, 1, 1, 1, 1, 1 , 1 , 1, 1, 1 , 1 , 2, 1, 1 , 1, 1, 2, 2);
|
||||
private static final int // SERIALIZED
|
||||
Flag__img__is_pgbnr = 0
|
||||
, Flag__img__is_imap = 1
|
||||
, Flag__img__wo_anch = 2
|
||||
, Flag__img__is_vid = 3
|
||||
, Flag__file__w_diff_from_html = 4
|
||||
, Flag__file__time_exists = 5
|
||||
, Flag__file__page_exists = 6
|
||||
, Flag__file__is_orig = 7
|
||||
, Flag__file__repo_is_local = 8
|
||||
, Flag__file__src_exists = 9
|
||||
, Flag__img__cls_other_exists = 10
|
||||
, Flag__anch__ns_is_custom = 11
|
||||
, Flag__anch__cls_tid = 12 // none, image
|
||||
, Flag__anch__ns_id_needs_saving = 13
|
||||
, Flag__img__alt_diff_from_anch_title = 14
|
||||
, Flag__anch__href_diff_file = 15
|
||||
, Flag__anch__title_missing = 16
|
||||
, Flag__img__cls_tid = 17 // none, thumbimage, thumbborder
|
||||
, Flag__anch__href_tid = 18 // wiki, site, anch, inet
|
||||
Flag__file__src_diff_href = 0 // compares anch_href vs img_src; EX: <a href='...File:A.png'><img src='...A.png'>
|
||||
, Flag__img__is_pgbnr = 1 // is pagebanner
|
||||
, Flag__img__is_imap = 2 // is imap
|
||||
, Flag__img__wo_anch = 3 // handles hiero, magnify, enlarge where only <img> is parsed; parsing <a> is too irregular
|
||||
, Flag__img__is_vid = 4 // is video thumb
|
||||
, Flag__file__w_diff_from_html = 5 // handles gallery; EX: <img src='A.png/220px.png' width=330px>
|
||||
, Flag__file__time_exists = 6 // img_src has time; EX: 220px-2.png
|
||||
, Flag__file__page_exists = 7 // img_src has page; EX: 220px-2.png
|
||||
, Flag__file__is_orig = 8 // n=orig; y=thumb
|
||||
, Flag__file__repo_is_local = 9 // n=commons.wikimedia.org; y=en.wikipedia.org
|
||||
, Flag__file__src_exists = 10 // <img> has "src="
|
||||
, Flag__img__cls_other_exists = 11 // handle manual class in <img>; EX: <img class='cls1'>
|
||||
, Flag__anch__ns_is_custom = 12 // handle ns-alias's; EX: "Image:A.png"
|
||||
, Flag__anch__cls_tid = 13 // ENUM: none, image
|
||||
, Flag__anch__ns_needs_saving = 14 // handle links which redirect to different ns; EX:[[File:A.png|B]]
|
||||
, Flag__img__alt_diff_from_anch_title = 15 // HTML entities will generate different title vs alt attributes; EX:[[File:A.png|a&]]
|
||||
, Flag__anch__href_diff_file = 16 // compares anch_href vs anch_xowa_title; EX:<a href='...File:A.png#b' xowa_title='A.png'>; differs when (a) anchor (A#B); (b) url-encoding (A'b; Aéb)
|
||||
, Flag__anch__title_missing = 17 // title missing for frameless images
|
||||
, Flag__img__cls_tid = 18 // ENUM: none, thumbimage, thumbborder
|
||||
, Flag__anch__href_tid = 19 // ENUM: wiki, site, anch, inet
|
||||
;
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public class Xoh_img_hzip__dump__basic__tst {
|
||||
}
|
||||
@Test public void Imap() {
|
||||
fxt.Test__bicode
|
||||
( "~%}#Pa$A.png~#:#S#+\""
|
||||
, "<img data-xowa-title='A.png' data-xoimg='1|220|180|-1|-1|-1' src='' width='0' height='0' class='thumbimage' alt='' usemap='#imagemap_1_1'>"
|
||||
( "~%}#P`uA.png~#:#S#+\""
|
||||
, "<img data-xowa-title='A.png' data-xoimg='1|220|180|-1|-1|-1' src='' width='0' height='0' alt='' usemap='#imagemap_1_1'>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@ public class Xoh_img_hzip__dump__link__tst {
|
||||
, "<a href='http://a.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link__wm__n__encoded() { // PURPOSE: do not double-encode A%C3%A9b.org; [[File:A.png|link=http://Aéb.org|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%!Dhttp://A%C3%A9b.org~A.png~)#Sabc~"
|
||||
, "<a href='http://A%C3%A9b.org' rel='nofollow' class='image' title='abc' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link__wm__y() { // [[File:A.png|link=http://en.wikitionary.org/wiki/Special:Search/A|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%\"men.wiktionary.org|Search/A~A.png~\")#Sabc~"
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
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.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_img_hzip__dump__orig__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt().Init_mode_diff_y_();
|
||||
@Before public void Clear() {fxt.Clear();}
|
||||
@Test public void Basic() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%|\"\\QA.png~$m#Tabc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A.png/330px.png' width='330' height='220' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Orig() { // PURPOSE: orig with width was causing "!!" in alt; EX:[[File:A.png|abc]]; DATE:2016-08-09
|
||||
fxt.Test__bicode
|
||||
( "~%|#gqA.png~!b!Babc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img src='file:///mem/xowa/file/commons.wikimedia.org/orig/7/0/A.png' width='64' height='32' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Gallery() {
|
||||
fxt.Test__bicode
|
||||
( "~%|3]3A.png~!b!B\"Mabc~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png' width='64' height='32' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Encode() { // [[File:A+C.png|abc]]
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_();
|
||||
fxt.Test__bicode
|
||||
( "~%|\"\\qA%2BC.png~A+C.png~$m#Tabc~"
|
||||
, "<a href='/wiki/File:A%2BC.png' class='image' title='abc' xowa_title='A+C.png'><img src='file:///mem/xowa/file/en.wikipedia.org/thumb/2/7/A%2BC.png/330px.png' width='330' height='220' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link() { // [[File:A.png|link=File:a.ogg|abc]]; [[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/9/7/4/e/En-us-Alabama.ogg|Listen]]
|
||||
fxt.Test__bicode
|
||||
( "~%}'h(qA.ogg~\"M!babc~A.png~"
|
||||
, "<a href='/wiki/File:A.ogg' class='image' title='abc' xowa_title='A.ogg'><img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png' width='128' height='64' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link__empty() { // [[File:A.png|link=|abc]]; PAGE:en.w:Lackawanna_Cut-Off; DATE:2016-08-19
|
||||
fxt.Test__bicode
|
||||
( "~%}([^KA.png~#\"M!babc~A.png~"
|
||||
, "<img src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png' width='128' height='64' alt='abc'>"
|
||||
);
|
||||
}
|
||||
@Test public void Encode_2() { // [[File:A*C.png|abc]]; PAGE:en.w:Fibonacci_number; DATE:2016-08-10
|
||||
// Tfds.Write(gplx.xowa.files.Xof_file_wkr_.Md5(Bry_.new_a7("A*C.png")));
|
||||
fxt.Test__bicode
|
||||
( "~%|\"\\QA*C.png~$m#Tabc~"
|
||||
, "<a href='/wiki/File:A*C.png' class='image' title='abc' xowa_title='A*C.png'><img src='file:///mem/xowa/file/en.wikipedia.org/thumb/d/d/A*C.png/330px.png' width='330' height='220' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Video() { // handle thumbnail
|
||||
fxt.Test__bicode
|
||||
( "~%|=nTA.ogv~$m#T#T4.5~abc~"
|
||||
, "<a href='/wiki/File:A.ogv' class='image' title='abc' xowa_title='A.ogv'><img src='file:///mem/xowa/file/en.wikipedia.org/thumb/d/0/A.ogv/220px-4.5.jpg' width='330' height='220' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.imgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.hzips.*;
|
||||
public class Xoh_img_hzip__view__tst {
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
private final Xoh_hzip_fxt fxt = new Xoh_hzip_fxt();
|
||||
@Before public void Clear() {fxt.Clear();}
|
||||
@Test public void Basic__border__class__caption() { // [[File:A.png|border|class=other|220px|abc]]
|
||||
fxt.Test__bicode
|
||||
( "~%iAA.png#T\";abc~other~"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' data-xowa-title='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other' alt='abc'></a>"
|
||||
, "<a href='/wiki/File:A.png' class='image' title='abc' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' class='thumbborder other' alt='abc'></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Link() { // [[File:A.png|link=B]]
|
||||
fxt.Test__bicode
|
||||
( "~%SgB~A.png~##T\";B~A.png~"
|
||||
, "<a href='/wiki/B' class='image' title='B' xowa_title='A.png'><img id='xoimg_0' data-xowa-title='A.png' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' alt='A.png'></a>"
|
||||
( "~%}'h+RB~A.png##T\";B~A.png~A.png~"
|
||||
, "<a href='/wiki/B' class='image' title='B' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png' width='220' height='110' alt='A.png'></a>"
|
||||
);
|
||||
}
|
||||
// link_site: [[File:A.png|link=//en.wiktionary.org/B]] -> [[File:Wiktionary-logo-en.svg|25x25px|link=//en.wiktionary.org/wiki/Special:Search/Earth|Search Wiktionary]] -> <a href="/site/en.wiktionary.org/wiki/Special:Search/Earth" rel="nofollow" title="Search Wiktionary" xowa_title="Wiktionary-logo-en.svg"><img id="xoimg_88" alt="Search Wiktionary" src="file:///J:/xowa/file/commons.wikimedia.org/thumb/f/8/c/4/Wiktionary-logo-en.svg/23px.png" width="23" height="25"></a>
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xoh_img_make__dump__tst {
|
||||
@Test public void Utf8() {
|
||||
String
|
||||
orig = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='Aé_b.png'><img data-xowa-title='Aé_b.png' data-xoimg='0|220|110|0.5|-1|-1' src='file:///mem/xowa/file/en.wikipedia.org/thumb/7/0/A%C3%A9_b.png/220px.png' width='220' height='110' alt='abc'></a>"
|
||||
, expd = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='A%C3%A9_b.png'><img id='xoimg_0' data-xowa-title='A%C3%A9_b.png' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
, expd = "<a href='/wiki/File:A%C3%A9_b.png' class='image' title='abc' xowa_title='Aé_b.png'><img id='xoimg_0' data-xowa-title='Aé_b.png' data-xoimg='0|220|110|0.5|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||
;
|
||||
fxt.Test__make(orig, fxt.Page_chkr().Body_(expd)
|
||||
.Imgs__add("en.w", "A.png", Xop_lnki_type.Id_null, 0.5, 220, 110, -1, -1)
|
||||
|
||||
@@ -72,7 +72,7 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
|
||||
}
|
||||
private void Init_xoimg(Xoh_page hpg, Xoh_hdoc_ctx hctx, byte[] lnki_ttl, Xoh_img_xoimg_data img_xowa_image) {
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hpg.Wiki().Domain_itm().Abrv_xo(), lnki_ttl, Xop_lnki_type.To_flag(img_xowa_image.Lnki_type()), img_xowa_image.Lnki_upright(), img_xowa_image.Lnki_w(), img_xowa_image.Lnki_h(), img_xowa_image.Lnki_time(), img_xowa_image.Lnki_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
hctx.File__mgr().Find(hpg.Wiki(), hpg.Url_bry_safe(), fsdb_itm);
|
||||
hctx.Cache_mgr().Find(hpg.Wiki(), hpg.Url_bry_safe(), fsdb_itm);
|
||||
this.img_xowa_image.Set_by_arg(img_xowa_image.Clone()); // NOTE: must clone b/c img_xowa_image is member of Xoh_img_data which is poolable (and cleared); PAGE:en.w:Almagest; DATE:2016-01-05
|
||||
this.Init_html(fsdb_itm.Html_w(), fsdb_itm.Html_h(), fsdb_itm.Html_view_url().To_http_file_bry());
|
||||
this.div_w = fsdb_itm.Lnki_w();
|
||||
@@ -83,8 +83,11 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
|
||||
this.img_is_vid = data.Img_is_vid();
|
||||
this.img_wo_anch = data.Img_wo_anch();
|
||||
this.fsdb_itm = hpg.Img_mgr().Make_img(data.Img_is_gallery());
|
||||
byte[] file_ttl_bry = data.Img_src().File_ttl_bry();
|
||||
byte[] lnki_ttl = Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href_quotes.Decode(file_ttl_bry)); // NOTE: must decode for fsdb.lnki_ttl as well as xowa_title; EX: A%C3%A9b -> A<>b
|
||||
|
||||
byte[] file_ttl_bry = data.Anch_xo_ttl().Val();
|
||||
byte[] lnki_ttl = Xoa_ttl.Replace_spaces(Gfo_url_encoder_.Href_quotes.Decode(data.Img_src().File_ttl_bry())); // NOTE: must decode for fsdb.lnki_ttl as well as xowa_title; EX: A%C3%A9b -> A<>b
|
||||
|
||||
boolean write_xowa_file_title = true;
|
||||
if (data.Img_pgbnr().Exists()) {
|
||||
img_pgbnr_atrs.Set(data.Img_pgbnr());
|
||||
hpg.Html_data().Head_mgr().Itm__pgbnr().Enabled_y_();
|
||||
@@ -94,10 +97,21 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
|
||||
Xoh_img_xoimg_data img_xowa_image = data.Img_xoimg();
|
||||
this.Init_xoimg(hpg, hctx, lnki_ttl, img_xowa_image);
|
||||
}
|
||||
else if (data.Img_w() != -1) {
|
||||
img_w.Set_by_int(data.Img_w());
|
||||
img_h.Set_by_int(data.Img_h());
|
||||
this.img_src.Set_by_arg(data.Img_src());
|
||||
else if (data.Img_w() != -1) { // orig exists or some hard-coded image (hiero)
|
||||
Xoh_img_src_data img_src_data = data.Img_src();
|
||||
|
||||
this.Init_html(data.Img_w(), data.Img_h(), img_src_data.Src_bry());
|
||||
int file_w = data.Img_src().File_w();
|
||||
// NOTE: init lnki with "64|file_w|-1|-1|-1|-1"; DATE:2016-08-10
|
||||
fsdb_itm.Init_at_lnki(Xof_exec_tid.Tid_wiki_page, hctx.Cache__wiki_abrv(img_src_data.Repo_is_commons()), lnki_ttl, Xop_lnki_type.Tid_orig_known, Xop_lnki_tkn.Upright_null, file_w, Xof_img_size.Null, data.Img_src().File_time(), data.Img_src().File_page(), Xof_patch_upright_tid_.Tid_all);
|
||||
fsdb_itm.Init_at_gallery_bgn(data.Img_w(), data.Img_h(), file_w);
|
||||
fsdb_itm.Html_view_url_(Io_url_.New__http_or_fail(img_src_data.Src_bry()));
|
||||
fsdb_itm.File_is_orig_(data.Img_src().File_is_orig());
|
||||
|
||||
// ASSUME: if file_w != img_w, then page has packed gallery; PAGE:en.w:Mexico; DATE:2016-08-14
|
||||
if (file_w != data.Img_w())
|
||||
hpg.Html_data().Xtn_gallery_packed_exists_y_();
|
||||
write_xowa_file_title = false;
|
||||
}
|
||||
if (data.Anch_rel_nofollow_exists()) anch_rel.Set_by_bry(gplx.xowa.htmls.core.wkrs.lnkes.Xoh_lnke_dict_.Html__rel__nofollow);
|
||||
if (!hctx.Mode_is_diff()) {
|
||||
@@ -110,7 +124,9 @@ public class Xoh_img_wtr implements Bfr_arg, Xoh_wtr_itm {
|
||||
if ( data.Img_wo_anch() // anchor-less image
|
||||
|| Bry_.Len_gt_0(file_ttl_bry)) // regular anch with image
|
||||
anch_xowa_title.Set_by_bry(file_ttl_bry);
|
||||
img_xowa_title.Set_by_bry(file_ttl_bry);
|
||||
|
||||
if (write_xowa_file_title)
|
||||
img_xowa_title.Set_by_bry(file_ttl_bry);
|
||||
img_alt.Set_by_mid_or_empty(src, data.Img_alt_bgn(), data.Img_alt_end());
|
||||
img_cls.Set_by_arg(data.Img_cls());
|
||||
if (data.Img_imap_idx() != -1) img_imap_usemap.Set(data.Img_imap_idx());
|
||||
|
||||
@@ -17,10 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.*;
|
||||
import gplx.core.brys.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
|
||||
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
|
||||
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
|
||||
public byte[] Src_bry() {return src_bry;} private byte[] src_bry;
|
||||
public int Src_bgn() {return src_bgn;} private int src_bgn;
|
||||
@@ -34,13 +35,14 @@ public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
|
||||
public byte[] File_ttl_bry() {return file_ttl_bry;} private byte[] file_ttl_bry;
|
||||
public boolean File_is_orig() {return file_is_orig;} private boolean file_is_orig;
|
||||
public int File_w() {return file_w;} private int file_w;
|
||||
public int File_time() {return file_time;} private int file_time;
|
||||
public double File_time() {return file_time;} private double file_time;
|
||||
public int File_page() {return file_page;} private int file_page;
|
||||
public boolean File_time_exists() {return file_time != -1;}
|
||||
public boolean File_page_exists() {return file_page != -1;}
|
||||
public void Clear() {
|
||||
src_bry = null;
|
||||
src_bgn = src_end = repo_bgn = repo_end = file_ttl_bgn = file_ttl_end = file_w = file_time = file_page = -1;
|
||||
src_bgn = src_end = repo_bgn = repo_end = file_ttl_bgn = file_ttl_end = file_w = file_page = -1;
|
||||
file_time = -1;
|
||||
repo_is_commons = file_is_orig = false;
|
||||
file_ttl_bry = null;
|
||||
}
|
||||
@@ -54,36 +56,51 @@ public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
|
||||
this.src_bry = err_wkr.Src();
|
||||
this.src_bgn = src_bgn; this.src_end = src_end;
|
||||
if (src_end == src_bgn) return true; // empty src; just return true;
|
||||
file_w = file_time = file_page = -1;
|
||||
|
||||
// get repo_bgn; note that some <img> may be hiero / enlarge / magnify and should exit
|
||||
rdr.Init_by_wkr(err_wkr, "img.src.xowa", src_bgn, src_end).Fail_throws_err_(Bool_.N);
|
||||
repo_bgn = rdr.Find_fwd_rr(Bry__file); // skip past /file/; EX: "file:///J:/xowa/file/commons.wikimedia.org/"
|
||||
if (repo_bgn == -1) return false;
|
||||
|
||||
rdr.Fail_throws_err_(Bool_.Y);
|
||||
|
||||
// get repo
|
||||
repo_end = rdr.Find_fwd_lr();
|
||||
repo_is_commons = Bry_.Match(rdr.Src(), repo_bgn, repo_end, Xow_domain_itm_.Bry__commons);
|
||||
if (!repo_is_commons) {
|
||||
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) return false; // rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
// if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
if (!Bry_.Match(rdr.Src(), repo_bgn, repo_end, domain_bry)) rdr.Err_wkr().Fail("repo must be commons or self", "repo", Bry_.Mid(rdr.Src(), repo_bgn, repo_end));
|
||||
}
|
||||
|
||||
// get orig / thumb; md5; file_ttl
|
||||
file_is_orig = rdr.Chk(trie) == Tid__orig; // check if 'orig/' or 'thumb/'
|
||||
file_ttl_bgn = Skip_md5(); // skip md5; EX: "0/1/2/3/"
|
||||
if (file_is_orig)
|
||||
file_ttl_end = rdr.Src_end();
|
||||
else {
|
||||
else
|
||||
file_ttl_end = rdr.Find_fwd_lr();
|
||||
file_w = rdr.Read_int_to(Byte_ascii.Ltr_p); // EX: "220px"
|
||||
rdr.Chk(Byte_ascii.Ltr_x);
|
||||
if (rdr.Is(Byte_ascii.At))
|
||||
file_time = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px@5.png"
|
||||
else if (rdr.Is(Byte_ascii.Dash))
|
||||
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
|
||||
}
|
||||
file_ttl_bry = Bry_.Mid(src_bry, file_ttl_bgn, file_ttl_end);
|
||||
|
||||
// get file_w; file_page; file_time
|
||||
if (!file_is_orig) {
|
||||
file_w = rdr.Read_int_to(Byte_ascii.Ltr_p); // EX: "220px"
|
||||
rdr.Chk(Byte_ascii.Ltr_x);
|
||||
if (rdr.Is(Byte_ascii.Dash)) {
|
||||
Xof_ext ext = Xof_ext_.new_by_ttl_(file_ttl_bry);
|
||||
if (ext.Id_supports_page())
|
||||
file_page = rdr.Read_int_to(Byte_ascii.Dot); // EX: "220px-5.png"
|
||||
else {
|
||||
int time_bgn = rdr.Pos();
|
||||
int time_end = rdr.Find_fwd_lr(ext.Ext_view()) - 1; // -1 to position b/c ext doesn't have ".";
|
||||
file_time = Bry_.To_double_or(src_bry, time_bgn, time_end, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void Init_by_decode(byte[] file_ttl_bry, byte[] src) {
|
||||
this.file_ttl_bry = file_ttl_bry;
|
||||
public void Init_by_decode(byte[] src, boolean file_is_orig, byte[] file_ttl_bry, int file_w, double file_time, int file_page) {
|
||||
this.src_bry = src; this.src_bgn = 0; this.src_end = src.length;
|
||||
this.file_is_orig = file_is_orig;
|
||||
this.file_ttl_bry = file_ttl_bry; this.file_w = file_w; this.file_time = file_time; this.file_page = file_page;
|
||||
}
|
||||
public void Bfr_arg__clear() {this.Clear();}
|
||||
public boolean Bfr_arg__missing() {return src_bry == null;}
|
||||
@@ -103,7 +120,7 @@ public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
|
||||
}
|
||||
return rdr.Move_to(pos);
|
||||
}
|
||||
private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/");
|
||||
private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/");
|
||||
private static final byte Tid__orig = 1, Tid__thumb = 2;
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb);
|
||||
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,17 @@ package gplx.xowa.htmls.core.wkrs.imgs.atrs; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.brys.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoh_img_src_data_tst {
|
||||
private final Xoh_img_src_data_fxt fxt = new Xoh_img_src_data_fxt();
|
||||
private final Xoh_img_src_data_fxt fxt = new Xoh_img_src_data_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Basic() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, -1);
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px@5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, 5, -1);
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.png", 220, -1, 5);
|
||||
}
|
||||
@Test public void Video() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.ogv/220px-5.jpg" , "commons.wikimedia.org" , Bool_.N, "A.ogv", 220, 5, -1);
|
||||
}
|
||||
@Test public void Pdf() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.pdf/220px-5.png" , "commons.wikimedia.org" , Bool_.N, "A.pdf", 220, -1, 5);
|
||||
}
|
||||
@Test public void Md5_depth_4() {
|
||||
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/1/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
|
||||
@@ -36,7 +41,11 @@ public class Xoh_img_src_data_tst {
|
||||
// fxt.Test__parse__fail("file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png", "repo must be commons or self: repo='en.wiktionary.org' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/en.wiktionary.org/orig/7/0/A.png'");
|
||||
// }
|
||||
}
|
||||
class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_src_data parser = new Xoh_img_src_data();
|
||||
class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_src_data parser = new Xoh_img_src_data();
|
||||
public void Clear() {
|
||||
Xoa_app_fxt.repo2_(app, wiki);
|
||||
hctx.Init_by_page(wiki, new Xoh_page());
|
||||
}
|
||||
@Override public Xoh_itm_parser Parser_get() {return parser;}
|
||||
public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) {
|
||||
Exec_parse(src_str);
|
||||
@@ -44,7 +53,7 @@ class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_img_s
|
||||
Tfds.Eq_str(expd_file, String_.new_u8(src, parser.File_ttl_bgn(), parser.File_ttl_end()));
|
||||
Tfds.Eq_bool(expd_file_is_orig, parser.File_is_orig());
|
||||
Tfds.Eq_int(expd_w, parser.File_w());
|
||||
Tfds.Eq_int(expd_time, parser.File_time());
|
||||
Tfds.Eq_double(expd_time, parser.File_time());
|
||||
Tfds.Eq_int(expd_page, parser.File_page());
|
||||
}
|
||||
@Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) {
|
||||
|
||||
@@ -18,7 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.anchs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Xoh_anch_href_data_tst {
|
||||
private final Xoh_anch_href_data_fxt fxt = new Xoh_anch_href_data_fxt();
|
||||
private final Xoh_anch_href_data_fxt fxt = new Xoh_anch_href_data_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Site() {
|
||||
fxt.Test__parse("/site/A/wiki/B", "A", "B");
|
||||
}
|
||||
@@ -44,7 +45,11 @@ public class Xoh_anch_href_data_tst {
|
||||
fxt.Test__parse__fail("/site/A/B/C", "failed check: chk='wiki/' page='Main_Page' sect='href' text=/site/A/B/C");
|
||||
}
|
||||
}
|
||||
class Xoh_anch_href_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_anch_href_data parser = new Xoh_anch_href_data();
|
||||
class Xoh_anch_href_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_anch_href_data parser = new Xoh_anch_href_data();
|
||||
public void Clear() {
|
||||
Xoa_app_fxt.repo2_(app, wiki);
|
||||
hctx.Init_by_page(wiki, new Xoh_page());
|
||||
}
|
||||
@Override public Xoh_itm_parser Parser_get() {return parser;}
|
||||
public void Test__parse(String src_str, String expd_site, String expd_page) {
|
||||
Exec_parse(src_str);
|
||||
|
||||
@@ -29,19 +29,29 @@ public class Xoh_file_fmtr__hdump extends Xoh_file_fmtr__basic { private final
|
||||
byte[] data_xowa_title = Gfh_atr_.Make(tmp_bfr, Xoh_img_xoimg_data.Bry__data_xowa_title, a_xowa_title);
|
||||
byte[] data_xowa_image = Bld_xowa_image_data(tmp_bfr, xfer_itm.Lnki_type(), xfer_itm.Lnki_w(), xfer_itm.Lnki_h(), xfer_itm.Lnki_upright(), xfer_itm.Lnki_time(), xfer_itm.Lnki_page());
|
||||
|
||||
// only write src="..." width="..." height="..." if orig is present
|
||||
if (!xfer_itm.Orig_exists()) {
|
||||
img_w = img_h = 0;
|
||||
img_src = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
data_xowa_title = Bry_.Empty;
|
||||
data_xowa_image = Bry_.Empty;
|
||||
}
|
||||
|
||||
// bld bfr
|
||||
if (Bry_.Len_eq_0(a_href))
|
||||
Add_anch_n(bfr, data_xowa_title, data_xowa_image, img_cls, img_cls_other, img_alt, Bry_.Empty);
|
||||
Add_anch_n(bfr, data_xowa_title, data_xowa_image, img_src, img_w, img_h, img_cls, img_cls_other, img_alt, Bry_.Empty);
|
||||
else {
|
||||
if (a_href_is_file) a_href = Bry_.Empty;
|
||||
fmt__anch_y.Bld_many(bfr
|
||||
, a_href, Xoh_lnki_consts.A_cls_to_bry(a_cls), Xoh_lnki_consts.A_rel_to_bry(a_rel), a_title, a_xowa_title
|
||||
, data_xowa_title, data_xowa_image, Xoh_img_cls_.To_html(img_cls, img_cls_other), Gfh_utl.Escape_html_as_bry(img_alt)
|
||||
, data_xowa_title, data_xowa_image, img_src, img_w, img_h, Xoh_img_cls_.To_html(img_cls, img_cls_other), Gfh_utl.Escape_html_as_bry(img_alt)
|
||||
);
|
||||
}
|
||||
}
|
||||
public static void Add_anch_n(Bry_bfr bfr, byte[] data_xowa_title, byte[] data_xowa_image, byte img_cls, byte[] img_cls_other, byte[] img_alt, byte[] img_xtra_atrs) {
|
||||
fmt__anch_n.Bld_many(bfr, data_xowa_title, data_xowa_image, Xoh_img_cls_.To_html(img_cls, img_cls_other), Gfh_utl.Escape_html_as_bry(img_alt), img_xtra_atrs);
|
||||
public static void Add_anch_n(Bry_bfr bfr, byte[] data_xowa_title, byte[] data_xowa_image, byte[] img_src, int img_w, int img_h, byte img_cls, byte[] img_cls_other, byte[] img_alt, byte[] img_xtra_atrs) {
|
||||
fmt__anch_n.Bld_many(bfr, data_xowa_title, data_xowa_image, img_src, img_w, img_h, Xoh_img_cls_.To_html(img_cls, img_cls_other), Gfh_utl.Escape_html_as_bry(img_alt), img_xtra_atrs);
|
||||
}
|
||||
public static byte[] Bld_xowa_image_data(Bry_bfr bfr, byte tid, int w, int h, double upright, double time, int page) {
|
||||
bfr.Add_byte_space().Add(Xoh_img_xoimg_data.Bry__data_xowa_image).Add_byte_eq().Add_byte_quote();
|
||||
@@ -55,11 +65,11 @@ public class Xoh_file_fmtr__hdump extends Xoh_file_fmtr__basic { private final
|
||||
}
|
||||
private static final Bry_fmt
|
||||
fmt__anch_n = Bry_fmt.Auto
|
||||
( "<img~{data_xowa_title}~{data_xowa_image} src=\"\" width=\"0\" height=\"0\"~{img_cls} alt=\"~{img_alt}\"~{img_xtra_atrs}/>"
|
||||
( "<img~{data_xowa_title}~{data_xowa_image} src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"~{img_cls} alt=\"~{img_alt}\"~{img_xtra_atrs}/>"
|
||||
)
|
||||
, fmt__anch_y = Bry_fmt.Auto
|
||||
( "<a href=\"~{a_href}\"~{a_class}~{a_rel}~{a_title} xowa_title=\"~{a_xowa_title}\">"
|
||||
+ "<img~{data_xowa_title}~{data_xowa_image} src=\"\" width=\"0\" height=\"0\"~{img_cls} alt=\"~{img_alt}\"/>"
|
||||
+ "<img~{data_xowa_title}~{data_xowa_image} src=\"~{img_src}\" width=\"~{img_w}\" height=\"~{img_h}\"~{img_cls} alt=\"~{img_alt}\"/>"
|
||||
+ "</a>"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.xfers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.wikis.tdbs.metas.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoh_file_mgr {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xof_url_bldr url_bldr = Xof_url_bldr.new_v2();
|
||||
public Xoh_file_mgr(Xowe_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);
|
||||
}
|
||||
@@ -49,14 +50,15 @@ public class Xoh_file_mgr {
|
||||
return xfer;
|
||||
}
|
||||
private boolean Find_file(Xop_ctx ctx, Xowe_wiki source_wiki, Xof_xfer_itm xfer) {
|
||||
if (source_wiki.File__fsdb_mode().Tid__v2__mp()) {
|
||||
Xof_orig_itm itm = source_wiki.File__orig_mgr().Find_by_ttl_or_null(xfer.Lnki_ttl());
|
||||
if (itm == null)
|
||||
if (source_wiki.File__fsdb_mode().Tid__bld()) {
|
||||
Xof_orig_itm orig = source_wiki.File__orig_mgr().Find_by_ttl_or_null(xfer.Lnki_ttl());
|
||||
if (orig == null)
|
||||
return false;
|
||||
else {
|
||||
byte repo_id = itm.Repo();
|
||||
byte[] repo_name = source_wiki.File_mgr().Repo_mgr().Repos_get_at(repo_id).Wiki_domain();
|
||||
xfer.Init_at_orig(itm.Repo(), repo_name, itm.Ttl(), itm.Ext(), itm.W(), itm.H(), itm.Redirect());
|
||||
byte repo_id = orig.Repo();
|
||||
Xof_repo_itm repo = source_wiki.File_mgr().Repo_mgr().Repos_get_at(repo_id).Trg();
|
||||
xfer.Init_at_orig(orig.Repo(), repo.Wiki_domain(), orig.Ttl(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
|
||||
xfer.Init_at_html(Xof_exec_tid.Tid_wiki_page, wiki.Parser_mgr().Img_size(), repo, url_bldr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,9 +44,14 @@ public class Xoh_file_wtr__basic {
|
||||
public void Write_file(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, Xof_file_itm xfer_itm, byte[] img_alt) {
|
||||
// init
|
||||
int uid = xfer_itm.Html_uid();
|
||||
byte[] lnki_ttl = lnki.Ttl().Page_txt();
|
||||
Xof_ext orig_ext = xfer_itm.Orig_ext();
|
||||
byte[] lnki_href = wiki.Html__href_wtr().Build_to_bry(wiki, lnki.Ttl());
|
||||
|
||||
// lnki_ttl; note if orig exists and orig_ttl is different, use it; PAGE:en.w:Switzerland; EX:[[File:Wappen_Schwyz_matt.svg]] which has redirect of Wappen_des_Kantons_Schwyz.svg; DATE:2016-08-11
|
||||
Xoa_ttl lnki_ttl = lnki.Ttl();
|
||||
if (xfer_itm.Orig_exists() && !Bry_.Eq(xfer_itm.Orig_ttl(), xfer_itm.Lnki_ttl()))
|
||||
lnki_ttl = wiki.Ttl_parse(Xow_ns_.Tid__file, xfer_itm.Orig_ttl());
|
||||
byte[] lnki_ttl_bry = lnki_ttl.Page_txt();
|
||||
byte[] lnki_href = wiki.Html__href_wtr().Build_to_bry(wiki, lnki_ttl);
|
||||
|
||||
// get div_width
|
||||
int div_width = xfer_itm.Html_w();
|
||||
@@ -80,38 +85,28 @@ public class Xoh_file_wtr__basic {
|
||||
|
||||
// main html build
|
||||
if (lnki.Ns_id() == Xow_ns_.Tid__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]]...]]
|
||||
html_fmtr.Add_media(bfr, hctx.Mode_is_hdump(), img_orig_src, lnki_ttl, Bld_caption(ctx, Xoh_wtr_ctx.Basic, src, lnki)); // NOTE: use orig_src not view_src; DATE:2014-01-19
|
||||
html_fmtr.Add_media(bfr, hctx.Mode_is_hdump(), img_orig_src, lnki_ttl_bry, Bld_caption(ctx, Xoh_wtr_ctx.Basic, src, lnki)); // NOTE: use orig_src not view_src; DATE:2014-01-19
|
||||
else {
|
||||
// identify if video; note that this is complicated b/c .ogg is used for both audio and video files
|
||||
// orig_is_video
|
||||
boolean orig_is_video = Xof_ext_.Id_is_video_strict(orig_ext.Id());
|
||||
if (orig_ext.Id_is_ogg()) {
|
||||
if ( wiki.File_mgr().Version_1_y() // version is v1 (v2 always marks ogg as aud if from fsdb); DATE:2014-02-01
|
||||
&& ( xfer_itm.File_exists() // NOTE: xfer_itm.Html_pass() checks for video .ogg files (ext = .ogg and thumb is available); EX: WWI;
|
||||
|| xfer_itm.Dbmeta_is_new() // NOTE: State_new() will always assume that ogg is video; needed for 1st load and dynamic updates
|
||||
)
|
||||
)
|
||||
if (orig_ext.Id_is_ogg()) { // note that this is complicated b/c .ogg usually means audio, but can sometimes mean video
|
||||
if (wiki.File_mgr().Version_1_y()) { // v1
|
||||
if ( xfer_itm.File_exists() // NOTE: xfer_itm.Html_pass() checks for video .ogg files (ext = .ogg and thumb is available); EX: WWI;
|
||||
|| xfer_itm.Dbmeta_is_new() // NOTE: State_new() will always assume that ogg is video; needed for 1st load and dynamic updates
|
||||
)
|
||||
orig_is_video = true;
|
||||
else if ( wiki.File_mgr().Version_2_y() // version is v2
|
||||
&& ( lnki.Lnki_type() != Xop_lnki_type.Id_null // any one of w, h, time, upright, type is present
|
||||
|| lnki.W() > 0
|
||||
|| lnki.H() > 0
|
||||
|| lnki.Time() != Xof_lnki_time.Null
|
||||
|| lnki.Upright() != Xop_lnki_tkn.Upright_null
|
||||
)) {
|
||||
orig_is_video = true; // ASSUME: .ogg is video b/c of supplied values; DATE:2016-08-05
|
||||
}
|
||||
else // v2; note that v2 always marks .ogg video as ext=.oga, so .ogg is always audio;
|
||||
orig_is_video = false;
|
||||
}
|
||||
if (orig_is_video) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid);
|
||||
int vid_lnki_w = lnki.W(); if (vid_lnki_w == -1) vid_lnki_w = 0; if (vid_lnki_w == 0 && xfer_itm.Html_w() != 0) vid_lnki_w = xfer_itm.Html_w();
|
||||
int vid_lnki_h = lnki.H(); if (vid_lnki_h == -1) vid_lnki_h = 0; if (vid_lnki_h == 0 && xfer_itm.Html_h() != 0) vid_lnki_h = xfer_itm.Html_h();
|
||||
xfer_itm.Init_at_gallery_bgn(vid_lnki_w, vid_lnki_h, vid_lnki_w); // HACK: force html_w to be lnki_w; needed b/c play_btn uses html_w; DATE:2016-08-05
|
||||
this.Write_file_video(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl, img_view_src, xfer_itm);
|
||||
if (orig_is_video) {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_vid); // mark as vid for js_mgr
|
||||
this.Write_file_video(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl_bry, img_view_src, xfer_itm);
|
||||
}
|
||||
else if (orig_ext.Id_is_audio()) // audio
|
||||
this.Write_file_audio(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl);
|
||||
this.Write_file_audio(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl_bry);
|
||||
else // image
|
||||
this.Write_file_image(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl, img_view_src, xfer_itm, lnki_is_thumbable, lnki_halign, orig_ext);
|
||||
this.Write_file_image(bfr, ctx, hctx, src, lnki, img_orig_src, uid, div_width, lnki_halign_bry, lnki_href, img_alt, lnki_ttl_bry, img_view_src, xfer_itm, lnki_is_thumbable, lnki_halign, orig_ext);
|
||||
}
|
||||
}
|
||||
private void Write_file_audio(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Xop_lnki_tkn lnki, byte[] img_orig_src, int uid, int div_width, byte[] lnki_halign_bry, byte[] lnki_href, byte[] alt, byte[] lnki_ttl) {
|
||||
@@ -267,7 +262,6 @@ public class Xoh_file_wtr__basic {
|
||||
}
|
||||
private int Get_play_btn_width(int w) {return w > 0 ? w : html_mgr.Img_thumb_width();} // if no width set width to default img width
|
||||
|
||||
// private static final int Play_btn_max_width = 1024;
|
||||
private static final byte[]
|
||||
Div_center_bgn = Bry_.new_a7("<div class=\"center\">")
|
||||
, Div_float_none = Bry_.new_a7("<div class=\"floatnone\">")
|
||||
|
||||
@@ -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.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||
import org.junit.*;
|
||||
import org.junit.*; import gplx.xowa.files.*;
|
||||
public class Xoh_file_wtr__image__tst {
|
||||
private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset();}
|
||||
@@ -318,6 +318,52 @@ public class Xoh_file_wtr__image__tst {
|
||||
+ "</a>"));
|
||||
fxt.Init_xwiki_clear();
|
||||
}
|
||||
@Test public void Redirect() {// PURPOSE: redirect should use trg_lnki, not src_lnki; DATE:2016-08-10
|
||||
Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki());
|
||||
file_fxt.Exec_orig_add(Bool_.Y, "A.png", Xof_ext_.Id_png, 320, 300, "B.png");
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_();
|
||||
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.png|320px|bcd|alt=efg]]"
|
||||
, "<a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_0\" alt=\"efg\" src=\"file:///mem/wiki/repo/trg/orig/5/7/B.png\" width=\"320\" height=\"300\" /></a>"
|
||||
);
|
||||
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__bld__y_();
|
||||
}
|
||||
@Test public void Imap() {
|
||||
Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki());
|
||||
file_fxt.Exec_orig_add(Bool_.Y, "A.png", Xof_ext_.Id_png, 320, 300, "");
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_();
|
||||
fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump);
|
||||
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( String_.Concat_lines_nl_skip_last
|
||||
( "<imagemap>"
|
||||
, "File:A.png|thumb|320px|a1"
|
||||
, "circle 0 0 5 [[B|b1]]"
|
||||
, "rect 0 0 4 8 [[C|c1]]"
|
||||
, "desc none"
|
||||
, "</imagemap>"
|
||||
)
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div class=\"thumbinner\" style=\"width:320px;\">"
|
||||
, " <div id=\"imap_div_0\" class=\"noresize\">"
|
||||
, " <map name=\"imageMap_1_1\">"
|
||||
, " <area href=\"/wiki/B\" shape=\"circle\" coords=\"0,0,5\" alt=\"b1\" title=\"b1\"/>"
|
||||
, " <area href=\"/wiki/C\" shape=\"rect\" coords=\"0,0,4,8\" alt=\"c1\" title=\"c1\"/>"
|
||||
, " </map>"
|
||||
, " <img src=\"file:///mem/wiki/repo/trg/orig/7/0/A.png\" width=\"320\" height=\"300\" alt=\"\" usemap=\"#imagemap_1_1\"/>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, "<div class=\"magnify\"><a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\"></a></div>a1"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__bld__y_();
|
||||
}
|
||||
private void Tst_img_title(String raw, String expd_ttl) {
|
||||
String actl = fxt.Exec_parse_page_wiki_as_str(raw);
|
||||
String actl_ttl = null;
|
||||
|
||||
@@ -45,6 +45,24 @@ public class Xoh_file_wtr__video__tst {
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video__full__ogv__time() {
|
||||
Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki());
|
||||
file_fxt.Exec_orig_add(Bool_.Y, "A.ogv", Xof_ext_.Id_ogv, 220, 300, "");
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__mp__y_();
|
||||
fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump);
|
||||
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.ogv|thumbtime=4]]", String_.Concat_lines_nl_skip_last
|
||||
( " <div class=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
+ "<a href=\"/wiki/File:A.ogv\" class=\"image\" title=\"A.ogv\" xowa_title=\"A.ogv\">"
|
||||
+ "<img src=\"file:///mem/wiki/repo/trg/thumb/d/0/A.ogv/220px-4.jpg\" width=\"220\" height=\"300\" alt=\"\"/>" // NOTE: src should probably be empty;
|
||||
+ "</a>"
|
||||
, " </div>"
|
||||
, "<div><a href=\"\" xowa_title=\"A.ogv\" class=\"xowa_media_play\" style=\"width:218px;max-width:220px;\" alt=\"Play sound\"></a></div>"
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video__full_ogg() {// PURPOSE: ogg w/ width should default to video; otherwise dynamic-update won't be able to convert audio-button to thumb; DATE:2016-08-05
|
||||
// NOTE: simulates app w/ fsdb
|
||||
Xof_file_fxt file_fxt = Xof_file_fxt.new_all(fxt.Wiki());
|
||||
@@ -59,38 +77,6 @@ public class Xoh_file_wtr__video__tst {
|
||||
, " </div>"
|
||||
));
|
||||
}
|
||||
@Test public void Video__thumb_ogg() { // PURPOSE: w/ width should default to video; DATE:2016-08-05
|
||||
// NOTE: simulates hdump w/ no fsdb
|
||||
fxt.Wiki().File_mgr().Version_2_y_();
|
||||
fxt.Wiki().File__fsdb_mode().Tid__v2__bld__y_();
|
||||
fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Hdump);
|
||||
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.ogg|thumb|320px|a|alt=b]]", String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div class=\"thumbinner\" style=\"width:320px;\">" // NOTE:220px is default w for "non-found" thumb; DATE:2014-09-24
|
||||
, " <div class=\"xowa_media_div\">"
|
||||
, " <div>"
|
||||
+ "<a href=\"/wiki/File:A.ogg\" class=\"image\" title=\"A.ogg\" xowa_title=\"A.ogg\">"
|
||||
+ "<img data-xowa-title=\"A.ogg\" data-xoimg=\"4|320|-1|-1|-1|-1\" src=\"\" width=\"0\" height=\"0\" alt=\"b\"/>"
|
||||
+ "</a>"
|
||||
, " </div>"
|
||||
, "<div><a href=\"\" xowa_title=\"A.ogg\" class=\"xowa_media_play\" style=\"width:318px;max-width:320px;\" alt=\"Play sound\"></a></div>"
|
||||
, " </div>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, "<div class=\"magnify\"><a href=\"/wiki/File:A.ogg\" class=\"internal\" title=\"Enlarge\"></a></div>a"
|
||||
, " </div>"
|
||||
, " <hr/>"
|
||||
, " <div class=\"thumbcaption\">b"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
|
||||
fxt.Wiki().File_mgr().Version_1_y_();
|
||||
fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic);
|
||||
}
|
||||
@Test public void Video__thumb() {
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.ogv|thumb|320px|bcd|alt=efg]]", String_.Concat_lines_nl_skip_last
|
||||
|
||||
@@ -68,8 +68,11 @@ public class Xoh_tag_parser implements Gfh_doc_wkr {
|
||||
case Gfh_tag_.Id__img:
|
||||
if (cur.Atrs__has(gplx.xowa.htmls.core.wkrs.imgs.atrs.Xoh_img_xoimg_data.Bry__data_xowa_image))
|
||||
rv = Parse_by_data(hdoc_wkr, hctx, tag_rdr, src, cur, null, Xoh_hzip_dict_.Tid__img);
|
||||
else
|
||||
else {
|
||||
rv = Parse_by_data(hdoc_wkr, hctx, tag_rdr, src, cur, null, Xoh_hzip_dict_.Tid__img_bare);
|
||||
if (rv == -1) // NOTE: handle link-less images which don't have an <a>; EX: <img src="file:///C:/xowa/file/commons.wikimedia.org/thumb/7/0/A.png/128px.png" width="128" height="64" alt="abc">; DATE:2016-08-21
|
||||
rv = Parse_by_data(hdoc_wkr, hctx, tag_rdr, src, cur, null, Xoh_hzip_dict_.Tid__img);
|
||||
}
|
||||
break;
|
||||
case Gfh_tag_.Id__div:
|
||||
if (cur.Atrs__cls_has(Xoh_thm_data.Atr__class__thumb)) {
|
||||
@@ -96,7 +99,7 @@ public class Xoh_tag_parser implements Gfh_doc_wkr {
|
||||
}
|
||||
return cur_end;
|
||||
}
|
||||
private int Parse_by_data(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag cur, Gfh_tag nxt, int tid) {
|
||||
public int Parse_by_data(Xoh_hdoc_wkr hdoc_wkr, Xoh_hdoc_ctx hctx, Gfh_tag_rdr tag_rdr, byte[] src, Gfh_tag cur, Gfh_tag nxt, int tid) {
|
||||
Xoh_data_itm data = hctx.Pool_mgr__data().Get_by_tid(tid);
|
||||
data.Clear();
|
||||
if (!data.Init_by_parse(hdoc_wkr, hctx, tag_rdr, src, cur, nxt)) {data.Pool__rls(); return -1;}
|
||||
|
||||
@@ -39,7 +39,6 @@ public class Xoh_toc_wtr implements gplx.core.brys.Bfr_arg, Xoh_wtr_itm {
|
||||
public static final byte[]
|
||||
Atr__class__toc = Bry_.new_a7("xo-toc")
|
||||
, Atr__data__toc__mode = Bry_.new_a7("data-toc-mode")
|
||||
// , Bry__placeholder = Bry_.new_a7("<!--XOWA:TOC-->\n") // NOTE: need to put \n b/c html_wtr always adds \n before each <h2> and TOC usually goes before <h2>; DATE:2016-07-16
|
||||
;
|
||||
public static void Write_tag(Bry_bfr bfr, boolean pgbnr_enabled) {
|
||||
bfr.Add(Gfh_tag_.Div_lhs_bgn);
|
||||
@@ -58,7 +57,10 @@ public class Xoh_toc_wtr implements gplx.core.brys.Bfr_arg, Xoh_wtr_itm {
|
||||
// build body
|
||||
byte[] bry = rv.To_bry_and_clear(); // NOTE: create bry to free bfr
|
||||
rv.Add_mid(bry, 0, toc_bgn);
|
||||
pg.Html_data().Toc_mgr().To_html(rv, hctx, pg.Html_data().Xtn_pgbnr() != null);
|
||||
if (hctx.Mode_is_hdump()) // NOTE: only write TOC tag in hdump; DATE:2016-08-20
|
||||
Xoh_toc_wtr.Write_tag(rv, false);
|
||||
else
|
||||
pg.Html_data().Toc_mgr().To_html(rv, hctx, pg.Html_data().Xtn_pgbnr() != null);
|
||||
rv.Add_mid(bry, toc_bgn, bry.length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.langs.htmls.styles.*;
|
||||
class Xohz_atr_itm__style implements Xohz_atr_itm { // EX: style='width:20em;'
|
||||
private int flag_idx;
|
||||
private Ordered_hash zatr_hash = Ordered_hash_.New_bry();
|
||||
private final Ordered_hash zatr_hash;
|
||||
private final Gfh_style_wkr__ary style_wkr = new Gfh_style_wkr__ary();
|
||||
public Xohz_atr_itm__style(int uid, byte[] key, Ordered_hash zatr_hash) {this.uid = uid; this.key = key; this.zatr_hash = zatr_hash;}
|
||||
public int Uid() {return uid;} private final int uid;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public int Uid() {return uid;} private final int uid;
|
||||
public byte[] Key() {return key;} private final byte[] key;
|
||||
public void Ini_flag(int flag_idx, List_adp flag_bldr_list) {
|
||||
this.flag_idx = flag_idx;
|
||||
flag_bldr_list.Add(1);
|
||||
@@ -32,7 +33,7 @@ class Xohz_atr_itm__style implements Xohz_atr_itm { // EX: style='width:20em;'
|
||||
flag_bldr.Set_as_bool(flag_idx, hatr.Val_dat_exists());
|
||||
}
|
||||
public void Enc_data (Xoh_hdoc_ctx hctx, byte[] src, Gfh_atr hatr, Xoh_hzip_bfr bfr) {
|
||||
Gfh_style_itm[] itms = Gfh_style_wkr__ary.Instance.Parse(src, hatr.Val_bgn(), hatr.Val_end());
|
||||
Gfh_style_itm[] itms = style_wkr.Parse(src, hatr.Val_bgn(), hatr.Val_end());
|
||||
int len = itms.length;
|
||||
bfr.Add_hzip_int(1, len);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
|
||||
@@ -1,33 +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.htmls.encoders; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Xow_encoder_mgr {
|
||||
public Gfo_url_encoder Id() {return id;} private final Gfo_url_encoder id = Gfo_url_encoder_.New__html_id().Make();
|
||||
public Gfo_url_encoder Href() {return href;} private final Gfo_url_encoder href = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make();
|
||||
public Gfo_url_encoder Href_wo_anch() {return href_wo_anch;} private final Gfo_url_encoder href_wo_anch = Gfo_url_encoder_.New__html_href_mw(Bool_.N).Make();
|
||||
// , Href_quotes = Gfo_url_encoder_.New__html_href_quotes().Make()
|
||||
// , Href_quotes_v2 = Gfo_url_encoder_.New__html_href_quotes_v2().Make()
|
||||
// , Href_qarg = Gfo_url_encoder_.New__html_href_qarg().Make()
|
||||
// , Xourl = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Init__same__many(Byte_ascii.Underline).Make()
|
||||
// , Http_url = Gfo_url_encoder_.New__http_url().Make()
|
||||
// , Http_url_ttl = Gfo_url_encoder_.New__http_url_ttl().Make()
|
||||
// , Fsys_lnx = Gfo_url_encoder_.New__fsys_lnx().Make()
|
||||
// , Fsys_wnt = Gfo_url_encoder_.New__fsys_wnt().Make()
|
||||
// , Gfs = Gfo_url_encoder_.New__gfs().Make()
|
||||
}
|
||||
@@ -19,17 +19,15 @@ package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xo
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.xwikis.*;
|
||||
public class Xoh_href_wtr {
|
||||
private final Bry_bfr encoder_bfr = Bry_bfr_.Reset(255), tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public class Xoh_href_wtr { // TS:do not move to app-level
|
||||
private final Gfo_url_encoder encoder = Gfo_url_encoder_.New__html_href_mw(Bool_.Y).Make();
|
||||
private final Bry_bfr encoder_bfr = Bry_bfr_.Reset(255), tmp_bfr = Bry_bfr_.Reset(255);
|
||||
public byte[] Build_to_bry(Xow_wiki wiki, Xoa_ttl ttl) {
|
||||
synchronized (tmp_bfr) {
|
||||
Build_to_bfr(tmp_bfr, wiki.App(), Xoh_wtr_ctx.Basic, wiki.Domain_bry(), ttl);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
Build_to_bfr(tmp_bfr, wiki.App(), Xoh_wtr_ctx.Basic, wiki.Domain_bry(), ttl);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, byte[] domain_bry, Xoa_ttl ttl) {Build_to_bfr(bfr, app, Xoh_wtr_ctx.Basic, domain_bry, ttl);}
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, Xoh_wtr_ctx hctx, byte[] domain_bry, Xoa_ttl ttl) {
|
||||
public void Build_to_bfr(Bry_bfr bfr, Xoa_app app, Xoh_wtr_ctx hctx, byte[] domain_bry, Xoa_ttl ttl) { // given ttl, write href; EX: A -> '/wiki/A'
|
||||
int hctx_mode = hctx.Mode();
|
||||
byte[] page = ttl.Full_txt_raw();
|
||||
Xow_xwiki_itm xwiki = ttl.Wik_itm();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xow_popup_html_mkr {
|
||||
}
|
||||
public byte[] Bld(Xowe_wiki cur_wiki, Xoae_page page, Xow_popup_itm popup_itm, Bry_bfr wrdx_bfr) {
|
||||
if (output_js_clean) cur_wiki.Html_mgr().Js_cleaner().Clean_bfr(wiki, page.Ttl(), wrdx_bfr, 0);
|
||||
if (output_tidy) cur_wiki.Html_mgr().Tidy_mgr().Run_tidy_html(page, wrdx_bfr, Bool_.Y);
|
||||
if (output_tidy) cur_wiki.Html_mgr().Tidy_mgr().Exec_tidy(wrdx_bfr, Bool_.Y, page.Url_bry_safe());
|
||||
byte[] hdom_bry = wrdx_bfr.To_bry_and_clear();
|
||||
String page_url = wrdx_bfr.Add(page.Wiki().Domain_bry()).Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki).Add(gplx.langs.htmls.encoders.Gfo_url_encoder_.Href
|
||||
.Encode(page.Ttl().Full_db())) // NOTE: was page.Url().Raw(), but that doesn't work for Special:Search; PAGE:en.w:Earth and "Quotations"; DATE:2014-06-29
|
||||
|
||||
@@ -106,6 +106,10 @@ public class Xow_portal_mgr implements Gfo_invk {
|
||||
} public static final byte[] Cls_selected_y = Bry_.new_a7("selected"), Cls_new = Bry_.new_a7("new"), Cls_display_none = Bry_.new_a7("xowa_display_none");
|
||||
public byte[] Div_logo_bry() {return div_logo_bry;} private byte[] div_logo_bry = Bry_.Empty;
|
||||
public byte[] Div_home_bry() {return api_skin != null && api_skin.Sidebar_home_enabled() ? div_home_bry : Bry_.Empty;} private byte[] div_home_bry = Bry_.Empty;
|
||||
public byte[] Div_admin_bry(Bry_bfr tmp_bfr, Xow_wiki wiki, Xoa_page page) {
|
||||
div_admin_fmtr.Bld_bfr_many(tmp_bfr, page.Ttl().Full_url());
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
public byte[] Div_wikis_bry(Bry_bfr_mkr bfr_mkr) {
|
||||
if (toggle_itm == null) // TEST:lazy-new b/c Init_by_wiki
|
||||
toggle_itm = wiki.Appe().Api_root().Html().Page().Toggle_mgr().Get_or_new("offline-wikis").Init(Bry_.new_a7("Wikis"));
|
||||
@@ -114,11 +118,14 @@ public class Xow_portal_mgr implements Gfo_invk {
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
public byte[] Missing_ns_cls() {return missing_ns_cls;} public Xow_portal_mgr Missing_ns_cls_(byte[] v) {missing_ns_cls = v; return this;} private byte[] missing_ns_cls; // NOTE: must be null due to Init check above
|
||||
private final Bry_fmtr div_personal_fmtr = Bry_fmtr.new_("~{portal_personal_subj_href};~{portal_personal_subj_text};~{portal_personal_talk_cls};~{portal_personal_talk_href};~{portal_personal_talk_cls};", "portal_personal_subj_href", "portal_personal_subj_text", "portal_personal_subj_cls", "portal_personal_talk_href", "portal_personal_talk_cls");
|
||||
private final Bry_fmtr div_ns_fmtr = Bry_fmtr.new_("~{portal_ns_subj_href};~{portal_ns_subj_cls};~{portal_ns_talk_href};~{portal_ns_talk_cls};~{portal_div_vnts}", "portal_ns_subj_href", "portal_ns_subj_cls", "portal_ns_talk_href", "portal_ns_talk_cls", "portal_div_vnts");
|
||||
private final Bry_fmtr div_view_fmtr = Bry_fmtr.new_("", "portal_view_read_cls", "portal_view_edit_cls", "portal_view_html_cls", "search_text");
|
||||
private final Bry_fmtr div_logo_fmtr = Bry_fmtr.new_("", "portal_nav_main_href", "portal_logo_url");
|
||||
private final Bry_fmtr div_wikis_fmtr = Bry_fmtr.new_("", "toggle_btn", "toggle_hdr");
|
||||
private final Bry_fmtr
|
||||
div_personal_fmtr = Bry_fmtr.new_("~{portal_personal_subj_href};~{portal_personal_subj_text};~{portal_personal_talk_cls};~{portal_personal_talk_href};~{portal_personal_talk_cls};", "portal_personal_subj_href", "portal_personal_subj_text", "portal_personal_subj_cls", "portal_personal_talk_href", "portal_personal_talk_cls")
|
||||
, div_ns_fmtr = Bry_fmtr.new_("~{portal_ns_subj_href};~{portal_ns_subj_cls};~{portal_ns_talk_href};~{portal_ns_talk_cls};~{portal_div_vnts}", "portal_ns_subj_href", "portal_ns_subj_cls", "portal_ns_talk_href", "portal_ns_talk_cls", "portal_div_vnts")
|
||||
, div_view_fmtr = Bry_fmtr.new_("", "portal_view_read_cls", "portal_view_edit_cls", "portal_view_html_cls", "search_text")
|
||||
, div_logo_fmtr = Bry_fmtr.new_("", "portal_nav_main_href", "portal_logo_url")
|
||||
, div_admin_fmtr = Bry_fmtr.new_("", "page_url")
|
||||
, div_wikis_fmtr = Bry_fmtr.new_("", "toggle_btn", "toggle_hdr")
|
||||
;
|
||||
private byte[] Reverse_li(byte[] bry) {
|
||||
return lang_is_rtl ? Xoh_rtl_utl.Reverse_li(bry) : bry;
|
||||
}
|
||||
@@ -128,6 +135,7 @@ public class Xow_portal_mgr implements Gfo_invk {
|
||||
else if (ctx.Match(k, Invk_div_view_)) div_view_fmtr.Fmt_(Reverse_li(m.ReadBry("v")));
|
||||
else if (ctx.Match(k, Invk_div_logo_)) div_logo_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_home_)) div_home_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_admin_)) div_admin_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_div_wikis_)) div_wikis_fmtr.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_missing_ns_cls)) return String_.new_u8(missing_ns_cls);
|
||||
else if (ctx.Match(k, Invk_missing_ns_cls_)) missing_ns_cls = m.ReadBry("v");
|
||||
@@ -135,7 +143,9 @@ public class Xow_portal_mgr implements Gfo_invk {
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_div_personal_ = "div_personal_", Invk_div_view_ = "div_view_", Invk_div_ns_ = "div_ns_", Invk_div_home_ = "div_home_", Invk_div_wikis_ = "div_wikis_"
|
||||
private static final String Invk_div_personal_ = "div_personal_", Invk_div_view_ = "div_view_", Invk_div_ns_ = "div_ns_", Invk_div_home_ = "div_home_"
|
||||
, Invk_div_admin_ = "div_admin_"
|
||||
, Invk_div_wikis_ = "div_wikis_"
|
||||
, Invk_missing_ns_cls = "missing_ns_cls", Invk_missing_ns_cls_ = "missing_ns_cls_", Invk_missing_ns_cls_list = "missing_ns_cls_list"
|
||||
;
|
||||
public static final String Invk_div_logo_ = "div_logo_";
|
||||
|
||||
Reference in New Issue
Block a user