From 7a0247417de5266261b4dc619c486d0688863bf4 Mon Sep 17 00:00:00 2001 From: gnosygnu Date: Wed, 27 May 2020 07:29:39 -0400 Subject: [PATCH] Embeddable: Do not call hxtn code during embeddable [#733] --- .../parsers/mediawikis/Xop_mediawiki_wkr.java | 2 +- .../src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java | 6 +- .../xowa/htmls/core/htmls/Xoh_wtr_ctx.java | 84 +++++++++++-------- .../gplx/xowa/htmls/hrefs/Xoh_href_wtr.java | 80 ++++++++++-------- .../template_styles/Template_styles_nde.java | 2 +- 5 files changed, 96 insertions(+), 78 deletions(-) diff --git a/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr.java b/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr.java index 3ce322728..2a4c8cf8f 100644 --- a/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr.java +++ b/400_xowa/src/gplx/xowa/addons/parsers/mediawikis/Xop_mediawiki_wkr.java @@ -61,7 +61,7 @@ public class Xop_mediawiki_wkr { boolean is_wikitext = Xow_page_tid.Identify(wpg.Wiki().Domain_tid(), ttl.Ns().Id(), ttl.Page_db()) == Xow_page_tid.Tid_wikitext; byte[] orig_bry = Bry_.Empty; if (is_wikitext) { - wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode_.Tid__read).Write_hdump(tmp_bfr, pctx, Xoh_wtr_ctx.Hdump, wpg); + wiki.Html_mgr().Page_wtr_mgr().Wkr(Xopg_view_mode_.Tid__read).Write_hdump(tmp_bfr, pctx, Xoh_wtr_ctx.Embeddable, wpg); // write categories int ctgs_len = wpg.Wtxt().Ctgs__len(); diff --git a/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java index 5a0c86e22..09c87fd19 100644 --- a/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java +++ b/400_xowa/src/gplx/xowa/htmls/Xoh_page_wtr_wkr.java @@ -28,12 +28,10 @@ import gplx.xowa.Xoa_ttl; import gplx.xowa.Xoae_app; import gplx.xowa.Xoae_page; import gplx.xowa.Xowe_wiki; -import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.Xoctg_pagebox_itm; import gplx.xowa.apps.gfs.Gfs_php_converter; import gplx.xowa.htmls.core.Xow_hdump_mode; import gplx.xowa.htmls.core.htmls.Xoh_html_wtr_escaper; import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx; -import gplx.xowa.htmls.hxtns.blobs.Hxtn_blob_tbl; import gplx.xowa.htmls.hxtns.pages.Hxtn_page_mgr; import gplx.xowa.htmls.portal.Xoh_page_body_cls; import gplx.xowa.htmls.portal.Xow_portal_mgr; @@ -172,7 +170,9 @@ public class Xoh_page_wtr_wkr { int page_id = wpg.Db().Page().Id(); Hxtn_page_mgr html_data_mgr = wpg.Wikie().Hxtn_mgr(); - wpg.Html_data().Indicators().HxtnSave(wpg.Wikie(), html_data_mgr, wpg, page_id); + if (!hctx.Mode_is_embeddable()) { + wpg.Html_data().Indicators().HxtnSave(wpg.Wikie(), html_data_mgr, wpg, page_id); + } this.Write_body(bfr, ctx, hctx, wpg); } diff --git a/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_wtr_ctx.java b/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_wtr_ctx.java index fb80340ca..e2a80a10b 100644 --- a/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_wtr_ctx.java +++ b/400_xowa/src/gplx/xowa/htmls/core/htmls/Xoh_wtr_ctx.java @@ -1,21 +1,23 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012-2017 gnosygnu@gmail.com - -XOWA is licensed under the terms of the General Public License (GPL) Version 3, -or alternatively under the terms of the Apache License Version 2.0. - -You may use XOWA according to either of these licenses as is most appropriate -for your project on a case-by-case basis. - -The terms of each license can be found in the source code repository: - -GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt -Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt -*/ -package gplx.xowa.htmls.core.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; -import gplx.xowa.htmls.core.hzips.*; -import gplx.xowa.htmls.hrefs.*; +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.core.htmls; + +import gplx.xowa.htmls.core.hzips.Xoh_hzip_dict_; +import gplx.xowa.htmls.hrefs.Xoh_href_; + public class Xoh_wtr_ctx { Xoh_wtr_ctx(int mode, int hzip_tid, byte[] anch__href__bgn, byte[] anch__href__end) { this.mode = mode; @@ -23,30 +25,40 @@ public class Xoh_wtr_ctx { this.anch__href__bgn = anch__href__bgn; this.anch__href__end = anch__href__end; } - public int Mode() {return mode;} private final int mode; - public int Hzip_tid() {return hzip_tid;} private final int hzip_tid; - public byte[] Anch__href__bgn() {return anch__href__bgn;} private final byte[] anch__href__bgn; - public byte[] Anch__href__end() {return anch__href__end;} private final byte[] anch__href__end; - public boolean Mode_is_hdump() {return mode == Mode_hdump;} - public boolean Mode_is_file_dump() {return mode == Mode_hdump;} - public boolean Mode_is_alt() {return mode == Mode_alt;} - public boolean Mode_is_display_title() {return mode == Mode_display_title;} - public boolean Mode_is_popup() {return mode == Mode_popup;} + public int Mode() {return mode;} private final int mode; + public byte[] Anch__href__bgn() {return anch__href__bgn;} private final byte[] anch__href__bgn; + public byte[] Anch__href__end() {return anch__href__end;} private final byte[] anch__href__end; + public int Hzip_tid() {return hzip_tid;} private final int hzip_tid; + public boolean Mode_is_hdump() {return mode == TID_HDUMP || mode == TID_EMBEDDABLE;} + public boolean Mode_is_file_dump() {return mode == TID_HDUMP || mode == TID_EMBEDDABLE;} + public boolean Mode_is_embeddable() {return mode == TID_EMBEDDABLE;} + public boolean Mode_is_alt() {return mode == TID_ALT;} + public boolean Mode_is_display_title() {return mode == TID_DISPLAY_TITLE;} + public boolean Mode_is_popup() {return mode == TID_POPUP;} - public static final int Mode_basic = 0, Mode_alt = 1, Mode_display_title = 2, Mode_popup = 3, Mode_hdump = 4, Mode_file_dump = 5; + private static final int + TID_BASIC = 0 + , TID_ALT = 1 + , TID_DISPLAY_TITLE = 2 + , TID_POPUP = 3 + , TID_HDUMP = 4 + , TID_FILE_DUMP = 5 + , TID_EMBEDDABLE = 6 + ; - public static final Xoh_wtr_ctx - Basic = new Xoh_wtr_ctx(Mode_basic , Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) - , Hdump = new Xoh_wtr_ctx(Mode_hdump , Xoh_hzip_dict_.Hdb__hzip , Xoh_href_.Bry__wiki, null) - , Alt = new Xoh_wtr_ctx(Mode_alt , Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) - , Display_title = new Xoh_wtr_ctx(Mode_display_title , Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) - , Popup = new Xoh_wtr_ctx(Mode_popup , Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) + public static final Xoh_wtr_ctx + Basic = new Xoh_wtr_ctx(TID_BASIC, Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) + , Hdump = new Xoh_wtr_ctx(TID_HDUMP, Xoh_hzip_dict_.Hdb__hzip, Xoh_href_.Bry__wiki, null) + , Alt = new Xoh_wtr_ctx(TID_ALT, Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) + , Display_title = new Xoh_wtr_ctx(TID_DISPLAY_TITLE, Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) + , Popup = new Xoh_wtr_ctx(TID_POPUP, Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) + , Embeddable = new Xoh_wtr_ctx(TID_EMBEDDABLE, Xoh_hzip_dict_.Hdb__htxt, Xoh_href_.Bry__wiki, null) ; public static Xoh_wtr_ctx File_dump(byte[] anch__href__bgn, byte[] anch__href__end) { - return new Xoh_wtr_ctx(Mode_file_dump, Xoh_hzip_dict_.Hdb__htxt, anch__href__bgn, anch__href__end); + return new Xoh_wtr_ctx(TID_FILE_DUMP, Xoh_hzip_dict_.Hdb__htxt, anch__href__bgn, anch__href__end); } public static Xoh_wtr_ctx Hdump_by_hzip_tid(int hzip_tid) { - return new Xoh_wtr_ctx(Mode_hdump, hzip_tid, Xoh_href_.Bry__wiki, null); + return new Xoh_wtr_ctx(TID_HDUMP, hzip_tid, Xoh_href_.Bry__wiki, null); } } diff --git a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr.java b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr.java index 95acb0901..3e2ddafec 100644 --- a/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr.java +++ b/400_xowa/src/gplx/xowa/htmls/hrefs/Xoh_href_wtr.java @@ -1,22 +1,34 @@ -/* -XOWA: the XOWA Offline Wiki Application -Copyright (C) 2012-2017 gnosygnu@gmail.com - -XOWA is licensed under the terms of the General Public License (GPL) Version 3, -or alternatively under the terms of the Apache License Version 2.0. - -You may use XOWA according to either of these licenses as is most appropriate -for your project on a case-by-case basis. - -The terms of each license can be found in the source code repository: - -GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt -Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt -*/ -package gplx.xowa.htmls.hrefs; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; -import gplx.core.brys.fmtrs.*; -import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.core.htmls.*; -import gplx.xowa.wikis.xwikis.*; +/* +XOWA: the XOWA Offline Wiki Application +Copyright (C) 2012-2020 gnosygnu@gmail.com + +XOWA is licensed under the terms of the General Public License (GPL) Version 3, +or alternatively under the terms of the Apache License Version 2.0. + +You may use XOWA according to either of these licenses as is most appropriate +for your project on a case-by-case basis. + +The terms of each license can be found in the source code repository: + +GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt +Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt +*/ +package gplx.xowa.htmls.hrefs; + +import gplx.Bool_; +import gplx.Bry_bfr; +import gplx.Bry_bfr_; +import gplx.Bry_find_; +import gplx.Byte_ascii; +import gplx.core.brys.fmtrs.Bry_fmtr; +import gplx.langs.htmls.encoders.Gfo_url_encoder; +import gplx.langs.htmls.encoders.Gfo_url_encoder_; +import gplx.xowa.Xoa_app; +import gplx.xowa.Xoa_ttl; +import gplx.xowa.Xow_wiki; +import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx; +import gplx.xowa.wikis.xwikis.Xow_xwiki_itm; + 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); @@ -46,7 +58,6 @@ public class Xoh_href_wtr { // TS:do not move to app-level } 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) { // 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(); if (xwiki == null) // not an xwiki; EX: [[wikt:Word]] @@ -57,29 +68,24 @@ public class Xoh_href_wtr { // TS:do not move to app-level } if (xwiki == null) { // not an xwiki if (ttl.Anch_bgn() != 1) { // not an anchor-only; EX: "#A" - switch (hctx_mode) { - case Xoh_wtr_ctx.Mode_popup: { // popup parser always writes as "/site/" - bfr.Add(Xoh_href_.Bry__site); // add "/site/"; EX: /site/ - bfr.Add(domain_bry); // add xwiki; EX: en_dict - bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/ - break; - } - case Xoh_wtr_ctx.Mode_file_dump: { - bfr.Add(hctx.Anch__href__bgn()); // add "/wiki/"; EX: /wiki/Page; can be "/home/wiki/Page" for Html__dump_to_fsys - break; - } - default: { - bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/Page - break; - } + if (hctx.Mode_is_popup()) { // popup parser always writes as "/site/" + bfr.Add(Xoh_href_.Bry__site); // add "/site/"; EX: /site/ + bfr.Add(domain_bry); // add xwiki; EX: en_dict + bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/ + } + else if (hctx.Mode_is_file_dump()) { + bfr.Add(hctx.Anch__href__bgn()); // add "/wiki/"; EX: /wiki/Page; can be "/home/wiki/Page" for Html__dump_to_fsys + } + else { + bfr.Add(Xoh_href_.Bry__wiki); // add "/wiki/"; EX: /wiki/Page } } else {} // anchor: noop } else { // xwiki if ( app.Xwiki_mgr__missing(xwiki.Domain_bry()) // xwiki is not offline; use http: - || hctx_mode == Xoh_wtr_ctx.Mode_hdump // hdump should never dump as "/site/" - || hctx_mode == Xoh_wtr_ctx.Mode_file_dump // filedump should never dump as "/site/" + || hctx.Mode_is_hdump() // hdump should never dump as "/site/" + || hctx.Mode_is_file_dump() // filedump should never dump as "/site/" ) { Bry_fmtr url_fmtr = xwiki.Url_fmtr(); if (url_fmtr == null) { diff --git a/400_xowa/src/gplx/xowa/xtns/template_styles/Template_styles_nde.java b/400_xowa/src/gplx/xowa/xtns/template_styles/Template_styles_nde.java index 7bb902036..6f023a570 100644 --- a/400_xowa/src/gplx/xowa/xtns/template_styles/Template_styles_nde.java +++ b/400_xowa/src/gplx/xowa/xtns/template_styles/Template_styles_nde.java @@ -114,7 +114,7 @@ public class Template_styles_nde implements Xox_xnde, Mwh_atr_itm_owner2 { css_dynamic.Add(tmp_bfr.To_bry_and_clear()); } finally {tmp_bfr.Mkr_rls();} - if (hctx.Mode_is_hdump()) { + if (hctx.Mode_is_hdump() && !hctx.Mode_is_embeddable()) { int page_id = wpg.Db().Page().Id(); Hxtn_page_mgr html_data_mgr = wpg.Wikie().Hxtn_mgr(); html_data_mgr.Page_tbl__insert(page_id, Hxtn_page_mgr.Id__template_styles, css_page_id);