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

'v3.7.1.1'

This commit is contained in:
gnosygnu
2016-07-03 22:41:56 -04:00
parent 1a4ca00c0b
commit 36584a0cc2
220 changed files with 4762 additions and 2627 deletions

View File

@@ -16,11 +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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.makes.*;
public interface Gallery_box_w_fmtr_arg extends gplx.core.brys.Bfr_arg {
Gallery_box_w_fmtr_arg Init(int uid, int width);
}
class Gallery_box_w_fmtr_arg__basic implements gplx.core.brys.Bfr_arg, Gallery_box_w_fmtr_arg {
class Gallery_box_w_fmtr_arg implements gplx.core.brys.Bfr_arg {
private int width;
public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.width = width; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
@@ -28,36 +24,5 @@ class Gallery_box_w_fmtr_arg__basic implements gplx.core.brys.Bfr_arg, Gallery_b
bfr.Add_int_variable(width);
bfr.Add(Style_end);
}
private static final byte[] Style_bgn = Bry_.new_a7("style=\"width:"), Style_end = Bry_.new_a7("px;\"");
private static final byte[] Style_bgn = Bry_.new_a7("style=\"width:"), Style_end = Bry_.new_a7("px;\"");
}
// class Gallery_box_w_fmtr_arg__hdump : gplx.core.brys.Bfr_arg, Gallery_box_w_fmtr_arg {
// private int uid;
// public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.uid = uid; return this;}
// public void Bfr_arg__add(Bry_bfr bfr) {
// bfr.Add(Xoh_make_trie_.Bry__gallery_box_w);
// bfr.Add_int_variable(uid);
// bfr.Add_byte_apos();
// }
// }
interface Gallery_img_pad_fmtr_arg extends gplx.core.brys.Bfr_arg {
Gallery_img_pad_fmtr_arg Init(int uid, int vpad);
}
class Gallery_img_pad_fmtr_arg__basic implements gplx.core.brys.Bfr_arg, Gallery_img_pad_fmtr_arg {
private int vpad;
public Gallery_img_pad_fmtr_arg Init(int uid, int vpad) {this.vpad = vpad; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add(Style_bgn);
bfr.Add_int_variable(vpad);
bfr.Add(Style_end);
}
private static final byte[] Style_bgn = Bry_.new_a7("style=\"margin:"), Style_end = Bry_.new_a7("px auto;\"");
}
// class Gallery_img_pad_fmtr_arg__hdump : gplx.core.brys.Bfr_arg, Gallery_img_pad_fmtr_arg {
// private int uid;
// public Gallery_img_pad_fmtr_arg Init(int uid, int width) {this.uid = uid; return this;}
// public void Bfr_arg__add(Bry_bfr bfr) {
// bfr.Add(Xoh_make_trie_.Bry__gallery_img_pad);
// bfr.Add_int_variable(uid);
// bfr.Add_byte_apos();
// }
// }

View File

@@ -1,126 +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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.xowa.files.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*;
public class Gallery_html_wtr {
private final Xoh_arg_img_core img_core_fmtr_basic = new Xoh_arg_img_core__basic(), img_core_fmtr_hdump = new Xoh_arg_img_core__hdump();
public void Write_html(Bry_bfr bfr, Xoae_app app, Xowe_wiki wiki, Xop_ctx ctx, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Xoae_page page, Gallery_xnde mgr, byte[] src) {
int itm_div_w = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_w_or_default());
int itm_div_h = Gallery_html_wtr_utl.Calc_itm_div_len(mgr.Itm_h_or_default());
int itm_box_w = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w);
int itms_len = mgr.Itms_len();
int itms_per_row = mgr.Itms_per_row();
if (itms_per_row == Gallery_xnde.Null) itms_per_row = wiki.Cfg_gallery().Imgs_per_row();
int mgr_box_width_row = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * itms_per_row;
int row_multiplier; Bry_fmtr mgr_box_style;
if (itms_per_row == Gallery_xnde.Null) { // no "perrow" defined; default to total # of items;
row_multiplier = itms_len;
mgr_box_style = Gallery_html_wtr_.Mgr_box_style_none;
}
else {
row_multiplier = itms_per_row;
mgr_box_style = Gallery_html_wtr_.Mgr_box_style_max;
}
boolean mode_is_packed = Gallery_mgr_base_.Mode_is_packed(mgr.Mode());
byte[] mgr_box_cls; int mgr_box_width_all;
if (mode_is_packed) {
mgr_box_cls = Gallery_html_wtr_.Cls_packed;
mgr_box_width_all = 0;
}
else {
mgr_box_cls = Bry_.Empty;
mgr_box_width_all = Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w) * row_multiplier; // 8=Gallery Box borders; REF.MW:ImageGallery.php|GB_BORDERS;
}
Bry_bfr itm_bfr = wiki.Utl__bfr_mkr().Get_k004(), tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
int mgr_elem_id = -1; int gallery_w_count = 0;
boolean hctx_is_hdump = hctx.Mode_is_hdump();
Xoh_arg_img_core img_core_fmtr = hctx_is_hdump ? img_core_fmtr_hdump : img_core_fmtr_basic;
Xopg_hdump_data hdump_imgs = page.Hdump_data();
for (int i = 0; i < itms_len; i++) {
Gallery_itm itm = mgr.Itms_get_at(i);
byte[] itm_caption = Gallery_html_wtr_.Bld_caption(wiki, ctx, wtr, hctx, itm);
Xoa_ttl itm_ttl = itm.Ttl();
if ( itm_ttl != null // ttl does not have invalid characters
&& itm_ttl.Ns().Id_is_file() // ttl is in file ns;
) {
Xop_lnki_tkn lnki = ctx.Tkn_mkr().Lnki(itm.Ttl_bgn(), itm.Ttl_end()).Ttl_(itm_ttl).W_(mgr.Itm_w()).H_(mgr.Itm_h());
Xof_file_itm xfer_itm = wtr.Lnki_wtr().File_wtr().Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki);
xfer_itm.Html_gallery_mgr_h_(mgr.Itm_h_or_default());
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery);
if (mode_is_packed) {
if (gallery_w_count < itms_per_row) {
mgr_box_width_all += Gallery_html_wtr_utl.Calc_itm_pad_w(itm_box_w);
++gallery_w_count;
}
if (xfer_itm.Html_w() > 0) {
itm_div_w = Gallery_html_wtr_utl.Calc_itm_div_len(xfer_itm.Html_w());
itm_box_w = Gallery_html_wtr_utl.Calc_itm_box_w(itm_div_w); // NOTE: redefine itm_box_w for rest of loop
}
if (xfer_itm.Html_h() > 0)
itm_div_h = Gallery_html_wtr_utl.Calc_itm_div_len(xfer_itm.Html_h());
}
int itm_elem_id = xfer_itm.Html_uid();
if (mgr_elem_id == -1)
mgr_elem_id = itm_elem_id; // HACK: set mgr_elem_id to first itm_elem_id
int html_w = xfer_itm.Html_w();
int html_h = xfer_itm.Html_h();
byte[] html_src = xfer_itm.Html_view_url().To_http_file_bry();
if (html_src.length == 0) { // itm not found; use gallery defaults
html_w = mgr.Itm_w_or_default();
html_h = mgr.Itm_h_or_default();
}
byte[] lnki_ttl = lnki.Ttl().Page_txt();
Xoa_ttl lnki_link_ttl = itm_ttl; // default href to ttl
if ( itm.Link_bgn() != Bry_find_.Not_found // link is not -1; EX: "A.png" has no link specified
&& (itm.Link_end() - itm.Link_bgn()) > 0 // and link_end - link_bgn > 0; EX: "A.png|link="; DATE:2014-06-15
)
lnki_link_ttl = Xoa_ttl.parse(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()));
byte[] lnki_href = app.Html__href_wtr().Build_to_bry(wiki, lnki_link_ttl);
byte[] lnki_alt = itm.Alt_bgn() == Bry_find_.Not_found ? lnki_ttl : Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end()));
img_core_fmtr.Init(itm_elem_id, html_src, html_w, html_h);
int itm_margin = Gallery_html_wtr_utl.Calc_vpad(mgr.Itm_h(), html_h);
Gallery_html_wtr_.Itm_img_fmtr.Bld_bfr_many(itm_bfr
, itm_box_w, itm_div_w, itm_margin
, itm_elem_id
, lnki_ttl
, lnki_href
, img_core_fmtr
, itm_caption
, lnki_alt
);
if (hctx_is_hdump)
hdump_imgs.Imgs_add_img(new Xohd_img_itm__gallery_itm().Data_init_gallery(itm_div_w, itm_box_w, itm_margin), xfer_itm, Xohd_img_itm__gallery_itm.Tid_gallery);
}
else {
Gallery_html_wtr_.Itm_txt_fmtr.Bld_bfr_many(itm_bfr
, itm_box_w, itm_div_h
, Bry_.Mid(src, itm.Ttl_bgn(), itm.Ttl_end())
, itm_caption
);
}
}
byte[] ul_id_atr = Gallery_html_wtr_.Bld_id_atr(tmp_bfr, hctx_is_hdump, Gallery_html_wtr_.Bld_id(tmp_bfr, Gallery_html_wtr_.Id__ul, mgr_elem_id));
itm_bfr.Mkr_rls();
tmp_bfr.Mkr_rls();
int mgr_box_width_max = mgr_box_width_all < mgr_box_width_row ? mgr_box_width_row : mgr_box_width_all;
Gallery_html_wtr_.Fmtr__ul__nde.Bld_bfr_many(bfr, ul_id_atr, mgr_box_cls, Bfr_arg_.New_bry_fmtr(mgr_box_style, Bfr_arg_.New_int(mgr_box_width_max)), itm_bfr);
}
}

View File

@@ -16,11 +16,13 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Xoh_cfg_gallery implements Gfo_invk {
public int Imgs_per_row() {return imgs_per_row;} public Xoh_cfg_gallery Imgs_per_row_(int v) {imgs_per_row = v; return this;} private int imgs_per_row = 8; // changed from 4 to 8; DATE:2014-02-04
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_imgs_per_row_)) imgs_per_row = m.ReadInt("v");
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk_imgs_per_row_ = "imgs_per_row_";
class Gallery_img_pad_fmtr_arg implements gplx.core.brys.Bfr_arg {
private int vpad;
public Gallery_img_pad_fmtr_arg Init(int uid, int vpad) {this.vpad = vpad; return this;}
public void Bfr_arg__add(Bry_bfr bfr) {
bfr.Add(Style_bgn);
bfr.Add_int_variable(vpad);
bfr.Add(Style_end);
}
private static final byte[] Style_bgn = Bry_.new_a7("style=\"margin:"), Style_end = Bry_.new_a7("px auto;\"");
}

View File

@@ -16,23 +16,23 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.files.*; import gplx.xowa.files.gui.*; import gplx.xowa.guis.views.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
public class Gallery_itm implements Js_img_wkr {
private Gallery_xnde xnde; private Xof_file_itm xfer_itm; private Xowe_wiki wiki; private Xop_ctx ctx; private byte[] src; private byte[] gallery_li_id_bry; private int gallery_itm_idx;
public Xoa_ttl Ttl() {return ttl;} public Gallery_itm Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
public int Ttl_bgn() {return ttl_bgn;} public Gallery_itm Ttl_bgn_(int v) {ttl_bgn = v; return this;} private int ttl_bgn;
public int Ttl_end() {return ttl_end;} public Gallery_itm Ttl_end_(int v) {ttl_end = v; return this;} private int ttl_end;
public Xof_ext Ext() {return ext;} public Gallery_itm Ext_(Xof_ext v) {ext = v; return this;} private Xof_ext ext;
public byte[] Caption_bry() {return caption_bry;} public Gallery_itm Caption_bry_(byte[] v) {caption_bry = v; return this;} private byte[] caption_bry;
public Xop_root_tkn Caption_tkn() {return caption_tkn;} public Gallery_itm Caption_tkn_(Xop_root_tkn v) {caption_tkn = v; return this;} private Xop_root_tkn caption_tkn;
public int Alt_bgn() {return alt_bgn;} public Gallery_itm Alt_bgn_(int v) {alt_bgn = v; return this;} private int alt_bgn;
public int Alt_end() {return alt_end;} public Gallery_itm Alt_end_(int v) {alt_end = v; return this;} private int alt_end;
public int Link_bgn() {return link_bgn;} public Gallery_itm Link_bgn_(int v) {link_bgn = v; return this;} private int link_bgn;
public int Link_end() {return link_end;} public Gallery_itm Link_end_(int v) {link_end = v; return this;} private int link_end;
public int Page_bgn() {return page_bgn;} public Gallery_itm Page_bgn_(int v) {page_bgn = v; return this;} private int page_bgn;
public int Page_end() {return page_end;} public Gallery_itm Page_end_(int v) {page_end = v; return this;} private int page_end;
public Xop_lnki_tkn Lnki_tkn() {return lnki_tkn;} public Gallery_itm Lnki_tkn_(Xop_lnki_tkn v) {lnki_tkn = v; return this;} private Xop_lnki_tkn lnki_tkn;
public Xoa_ttl Ttl() {return ttl;} public Gallery_itm Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
public int Ttl_bgn() {return ttl_bgn;} public Gallery_itm Ttl_bgn_(int v) {ttl_bgn = v; return this;} private int ttl_bgn;
public int Ttl_end() {return ttl_end;} public Gallery_itm Ttl_end_(int v) {ttl_end = v; return this;} private int ttl_end;
public Xof_ext Ext() {return ext;} public Gallery_itm Ext_(Xof_ext v) {ext = v; return this;} private Xof_ext ext;
public byte[] Caption_bry() {return caption_bry;} public Gallery_itm Caption_bry_(byte[] v) {caption_bry = v; return this;} private byte[] caption_bry;
public Xop_root_tkn Caption_tkn() {return caption_tkn;} public Gallery_itm Caption_tkn_(Xop_root_tkn v) {caption_tkn = v; return this;} private Xop_root_tkn caption_tkn;
public int Alt_bgn() {return alt_bgn;} public Gallery_itm Alt_bgn_(int v) {alt_bgn = v; return this;} private int alt_bgn;
public int Alt_end() {return alt_end;} public Gallery_itm Alt_end_(int v) {alt_end = v; return this;} private int alt_end;
public int Link_bgn() {return link_bgn;} public Gallery_itm Link_bgn_(int v) {link_bgn = v; return this;} private int link_bgn;
public int Link_end() {return link_end;} public Gallery_itm Link_end_(int v) {link_end = v; return this;} private int link_end;
public int Page_bgn() {return page_bgn;} public Gallery_itm Page_bgn_(int v) {page_bgn = v; return this;} private int page_bgn;
public int Page_end() {return page_end;} public Gallery_itm Page_end_(int v) {page_end = v; return this;} private int page_end;
public Xop_lnki_tkn Lnki_tkn() {return lnki_tkn;} public Gallery_itm Lnki_tkn_(Xop_lnki_tkn v) {lnki_tkn = v; return this;} private Xop_lnki_tkn lnki_tkn;
public Gallery_itm Reset() {
ttl = null;
ttl_bgn = ttl_end = alt_bgn = alt_end = link_bgn = link_end = page_bgn = page_end = Bry_find_.Not_found;
@@ -41,16 +41,17 @@ public class Gallery_itm implements Js_img_wkr {
ext = null;
return this;
}
public void Html_prepare(Xowe_wiki wiki, Xop_ctx ctx, byte[] src, Gallery_xnde xnde, Xof_file_itm xfer_itm, byte[] gallery_li_id_bry, int gallery_itm_idx) {
this.xnde = xnde; this.xfer_itm = xfer_itm;
this.wiki = wiki; this.ctx = ctx; this.src = src; this.gallery_li_id_bry = gallery_li_id_bry; this.gallery_itm_idx = gallery_itm_idx;
}
public void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl) {
public void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl) {
Gallery_mgr_base gallery_mgr = xnde.Gallery_mgr();
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004(), tmp_bfr = wiki.Utl__bfr_mkr().Get_k004();
try {
xfer_itm.Init_at_gallery_end(html_w, html_h, html_view_url, html_orig_url);
gallery_mgr.Write_html_itm(bfr, tmp_bfr, wiki.Appe(), wiki, ctx.Page(), ctx, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, src, xnde, Bry_.Empty, gallery_itm_idx, xfer_itm, false);
Gallery_mgr_wtr.Write_itm(bfr, tmp_bfr, wiki.Appe(), wiki, ctx.Page(), ctx, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, src, gallery_mgr, xnde, gallery_itm_idx, xfer_itm);
String itm_html = bfr.To_str_and_clear();
js_wkr.Html_elem_replace_html(String_.new_u8(gallery_li_id_bry), itm_html);
if (gallery_itm_idx == xnde.Itms_len() - 1 && Gallery_mgr_base_.Mode_is_packed(xnde.Mode()))
@@ -60,4 +61,21 @@ public class Gallery_itm implements Js_img_wkr {
bfr.Mkr_rls(); tmp_bfr.Mkr_rls();
}
}
// public static void Js_wkr__update_hdoc2(Xoa_page page, Xog_js_wkr js_wkr, int html_uid, int html_w, int html_h, Io_url html_view_url, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl) {
// Xow_wiki wiki = null;
// Gallery_mgr_base gallery_mgr = null;
// Bry_bfr bfr = null, tmp_bfr = null;
// Xof_file_itm xfer_itm = null;
// try {
// xfer_itm.Init_at_gallery_end(html_w, html_h, html_view_url, html_orig_url);
//// Gallery_mgr_wtr.Write_itm(bfr, tmp_bfr, wiki.Appe(), wiki, ctx.Page(), ctx, wiki.Html_mgr().Html_wtr(), Xoh_wtr_ctx.Basic, src, gallery_mgr, xnde, gallery_itm_idx, xfer_itm);
//// String itm_html = bfr.To_str_and_clear();
//// js_wkr.Html_elem_replace_html(String_.new_u8(gallery_li_id_bry), itm_html);
//// if (gallery_itm_idx == xnde.Itms_len() - 1 && Gallery_mgr_base_.Mode_is_packed(xnde.Mode()))
//// page.Xtn_gallery_packed_exists_y_(); // set flag for packed_gallery; don't fire multiple times; PAGE:en.w:National_Sculpture_Museum_(Valladolid); DATE:2014-07-21
// }
// finally {
// bfr.Mkr_rls(); tmp_bfr.Mkr_rls();
// }
// }
}

View File

@@ -16,197 +16,51 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.modules.*; import gplx.xowa.files.*; import gplx.xowa.htmls.core.makes.*; import gplx.xowa.htmls.core.makes.imgs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.files.*;
import gplx.xowa.parsers.lnkis.*;
public abstract class Gallery_mgr_base {
private Gallery_box_w_fmtr_arg__basic box_w_fmtr__basic = new Gallery_box_w_fmtr_arg__basic(); // private Gallery_box_w_fmtr_arg__hdump box_w_fmtr__hdump = new Gallery_box_w_fmtr_arg__hdump();
private Gallery_img_pad_fmtr_arg__basic img_pad_fmtr__basic = new Gallery_img_pad_fmtr_arg__basic(); // private Gallery_img_pad_fmtr_arg__hdump img_pad_fmtr__hdump = new Gallery_img_pad_fmtr_arg__hdump();
public abstract byte Tid();
public abstract byte[] Tid_bry();
@gplx.Virtual public boolean Tid_is_packed() {return false;}
public int Itm_default_w() {return itm_default_w;} protected int itm_default_w;
public int Itm_default_h() {return itm_default_h;} protected int itm_default_h;
public int Itms_per_row() {return itms_per_row;} @gplx.Virtual public void Itms_per_row_(int v) {this.itms_per_row = v;} protected int itms_per_row;
@gplx.Virtual public int Get_thumb_padding() {return 30;} // REF.MW: getThumbPadding; How much padding such the thumb have between image and inner div that that contains the border. This is both for verical and horizontal padding. (However, it is cut in half in the vertical direction).
@gplx.Virtual public int Get_gb_padding() {return 5;} // REF.MW: getGBPadding; GB stands for gallerybox (as in the <li class="gallerybox"> element)
@gplx.Virtual public int Get_gb_borders() {return 8;} // REF.MW: getGBBorders; Get how much extra space the borders around the image takes up. For this mode, it is 2px borders on each side + 2px implied padding on each side from the stylesheet, giving us 2*2+2*2 = 8.
@gplx.Virtual public int Get_all_padding() {return this.Get_thumb_padding() + this.Get_gb_padding() + this.Get_gb_borders();} // REF.MW: getAllPadding; How many pixels of whitespace surround the thumbnail.
@gplx.Virtual public int Get_vpad(int itm_h, int thm_h) { // REF.MW: getVPad; Get vertical padding for a thumbnail; Generally this is the total height minus how high the thumb is.
if (thm_h == -1) thm_h = itm_h; // NOTE: thm_h will be -1 on 1st pass; set to dflt_h, else will end up with 115px for hdump; PAGE:en.w:National_Gallery_of_Art DATE:2016-06-19
return (this.Get_thumb_padding() + itm_h - thm_h) / 2;
}
@gplx.Virtual public int Get_thumb_div_width(int thm_w) { // REF.MW: getThumbDivWidth; Get the width of the inner div that contains the thumbnail in question. This is the div with the class of "thumb".
return itm_default_w + this.Get_thumb_padding();
}
@gplx.Virtual public int Get_gb_width(int thm_w, int thm_h) {// REF.MW: getGBWidth; Width of gallerybox <li>. Generally is the width of the image, plus padding on image plus padding on gallerybox.s
public abstract byte Tid();
public int Itm_default_w() {return itm_default_w;} protected int itm_default_w;
public int Itm_default_h() {return itm_default_h;} protected int itm_default_h;
public int Itms_per_row() {return itms_per_row;} protected int itms_per_row;
@gplx.Virtual public int Get_all_padding() {return this.Get_thumb_padding() + this.Get_gb_padding() + this.Get_gb_borders();} // REF.MW: getAllPadding; How many pixels of whitespace surround the thumbnail.
@gplx.Virtual public int Get_gb_padding() {return 5;} // REF.MW: getGBPadding; GB stands for gallerybox (as in the <li class="gallerybox"> element)
@gplx.Virtual public int Get_gb_borders() {return 8;} // REF.MW: getGBBorders; Get how much extra space the borders around the image takes up. For this mode, it is 2px borders on each side + 2px implied padding on each side from the stylesheet, giving us 2*2+2*2 = 8.
@gplx.Virtual public int Get_gb_width(int thm_w, int thm_h) {// REF.MW: getGBWidth; Width of gallerybox <li>. Generally is the width of the image, plus padding on image plus padding on gallerybox.s
return itm_default_w + this.Get_thumb_padding() + this.Get_gb_padding();
}
@gplx.Virtual public void Get_modules(Xoae_page page) { // REF.MW: getModules; Get a list of modules to include in the page.
page.Html_data().Head_mgr().Itm__gallery_styles().Enabled_y_(); // enable styles or some galleries will show up as list items; PAGE:s.w:Gothic_architecture DATE:2015-11-06
@gplx.Virtual public int Get_vpad(int xnde_h, int html_h) { // REF.MW: getVPad; Get vertical padding for a thumbnail; Generally this is the total height minus how high the thumb is.
if (html_h == -1) html_h = xnde_h; // NOTE: html_h will be -1 on 1st pass; set to dflt_h, else will end up with 115px for hdump; PAGE:en.w:National_Gallery_of_Art DATE:2016-06-19
return (this.Get_thumb_padding() + xnde_h - html_h) / 2;
}
@gplx.Virtual public void Init(int itms_per_row, int itm_default_w, int itm_default_h) {
this.itms_per_row = itms_per_row;
this.itm_default_w = itm_default_w;
this.itm_default_h = itm_default_h;
@gplx.Virtual public int Get_thumb_padding() {return 30;} // REF.MW: getThumbPadding; How much padding such the thumb have between image and inner div that that contains the border. This is both for verical and horizontal padding. (However, it is cut in half in the vertical direction).
@gplx.Virtual public int Get_thumb_div_width(int thm_w) { // REF.MW: getThumbDivWidth; Get the width of the inner div that contains the thumbnail in question. This is the div with the class of "thumb".
return itm_default_w + this.Get_thumb_padding();
}
@gplx.Virtual public void Wrap_gallery_text(Bry_bfr bfr, byte[] gallery_text, int thm_w, int thm_h) {
bfr .Add(Wrap_gallery_text_bgn)
.Add(gallery_text)
.Add(Wrap_gallery_text_end)
;
}
public void Write_html(Bry_bfr bfr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde) {
boolean hctx_is_hdump = hctx.Mode_is_hdump();
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
byte[] box_style = xnde.Atr_style();
int gallery_uid = page.Html_data().Xtn_gallery_next_id();
if (itms_per_row > 0) {
int max_width = itms_per_row * (itm_default_w + this.Get_all_padding());
box_style = Fmt_and_add(tmp_bfr, Gallery_html_wtr_.Fmtr__ul__style, box_style, max_width);
page.Hdump_data().Imgs_add(new Xohd_img_itm__gallery_mgr(gallery_uid, max_width));
}
byte[] box_cls = Fmt_and_add(tmp_bfr, Gallery_html_wtr_.Fmtr__ul__cls, xnde.Atr_cls(), this.Tid_bry());
byte[] gallery_ul_id = tmp_bfr.Add(Gallery_html_wtr_.Id__ul).Add_int_variable(gallery_uid).To_bry_and_clear();
Box_hdr_write(bfr, wiki.Appe().Html_mgr().Whitelist_mgr(), src, gallery_ul_id, box_cls, box_style, xnde.Atrs_other(), hctx_is_hdump, gallery_uid);
byte[] box_caption = xnde.Atr_caption();
if (Bry_.Len_gt_0(box_caption)) Gallery_html_wtr_.Fmtr__li__txt.Bld_bfr_many(bfr, box_caption);
Xoae_app app = wiki.Appe(); Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
int itm_len = xnde.Itms_len();
for (int i = 0; i < itm_len; i++) {
Write_html_itm(bfr, tmp_bfr, app, wiki, page, ctx, html_wtr, hctx, src, xnde, gallery_ul_id, i, null, hctx_is_hdump);
}
bfr.Add(box_html_end_bry);
tmp_bfr.Mkr_rls();
}
public static byte File_found_mode = Bool_.__byte;
public void Write_html_itm(Bry_bfr bfr, Bry_bfr tmp_bfr, Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde, byte[] gallery_ul_id, int i, Xof_file_itm xfer_itm, boolean hctx_is_hdump) {
Gallery_itm itm = (Gallery_itm)xnde.Itms_get_at(i);
Xoa_ttl ttl = itm.Ttl(); if (Bry_.Len_eq_0(ttl.Page_db())) return; // if file ttl is invalid, do not write; EX:File:#A.png; DATE:2016-01-12
byte[] itm_caption = itm.Caption_bry(); if (itm_caption == null) itm_caption = Bry_.Empty;
Xop_lnki_tkn lnki = itm.Lnki_tkn();
int lnki_w_orig = lnki.W(), lnki_h_orig = lnki.H(); // store orig lnki_w / lnki_w
this.Get_thumb_size(lnki, itm.Ext()); // packed=expand by 1.5;
if (xfer_itm == null) { // will be null on 1st pass
xfer_itm = html_wtr.Lnki_wtr().File_wtr().Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki);
xfer_itm.Html_gallery_mgr_h_(xnde.Itm_h_or_default());
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2);
}
int img_uid = xfer_itm.Html_uid();
byte[] li_id = Gallery_html_wtr_.Bld_id(tmp_bfr, Gallery_html_wtr_.Id__li, img_uid);
byte[] li_id_atr = Gallery_html_wtr_.Bld_id_atr(tmp_bfr, hctx_is_hdump, li_id);
byte[] itm_html = Bry_.Empty;
int html_w_expand = xfer_itm.Html_w();
int html_h_expand = xfer_itm.Html_h();
boolean file_found = xfer_itm.File_exists();
if (File_found_mode != Bool_.__byte)
file_found = File_found_mode == Bool_.Y_byte;
int vpad = -1, img_div_w = -1;
if ( !hctx_is_hdump // always write img if hdump; DATE:2015-04-27
&& ( !ttl.Ns().Id_is_file()
|| !file_found
)
) { // itm is not a file, or is not found; write text
itm_html = Gallery_html_wtr_.Fmtr__div1__missing.Bld_bry_many(tmp_bfr, this.Get_thumb_padding() + itm_default_h, ttl.Page_txt());
itm.Html_prepare(wiki, ctx, src, xnde, xfer_itm, li_id, i);
xfer_itm.Html_img_wkr_(itm);
lnki.W_(lnki_w_orig).H_(lnki_h_orig);
html_w_expand = lnki_w_orig; html_h_expand = lnki_h_orig; // reset lnki_w_orig / lnki_h_orig else large captions
}
else {
byte[] alt = itm.Alt_bgn() == Bry_find_.Not_found && Bry_.Len_eq_0(itm_caption) // if ( $alt == '' && $text == '' ) $imageParameters['alt'] = $nt->getText();
? itm.Ttl().Page_txt()
: Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end());
alt = Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, alt); // NOTE: need to handle situations wherein alt has quotes; EX:File:A"b.png; PAGE:en.w:Alexandria,_Romania DATE:2015-12-27
Xoa_ttl href_ttl = itm.Link_bgn() == Bry_find_.Not_found
? ttl
: Xoa_ttl.parse(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()))
;
if (href_ttl == null) href_ttl = ttl; // occurs when link is invalid; EX: A.png|link=<invalid>
this.Adjust_image_parameters(xfer_itm); // trad=noop; packed=reduce by 1.5
int html_w_normal = xfer_itm.Html_w();
int html_h_normal = xfer_itm.Html_h();
xfer_itm.Init_at_gallery_bgn(html_w_normal, html_h_normal, html_w_expand);// NOTE: file_w should be set to expanded width so js can resize if gallery
img_div_w = this.Get_thumb_div_width(html_w_expand);
Gallery_html_wtr_.Fmtr__div1__img.Bld_bfr_many(tmp_bfr, img_div_w);
// Gallery_img_pad_fmtr_arg vpad_fmtr = hctx_is_hdump ? (Gallery_img_pad_fmtr_arg)img_pad_fmtr__hdump : (Gallery_img_pad_fmtr_arg)img_pad_fmtr__basic;
Gallery_img_pad_fmtr_arg vpad_fmtr = img_pad_fmtr__basic;
vpad = this.Get_vpad(itm_default_h, html_h_expand);
Gallery_html_wtr_.itm_div1_fmtr.Bld_bfr_many(tmp_bfr, vpad_fmtr.Init(img_uid, vpad)); // <div style="margin:~{vpad}px auto;">
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_file(tmp_bfr, ctx, hctx, src, lnki, xfer_itm, alt);
tmp_bfr.Add(itm_divs_end_bry);
itm_html = tmp_bfr.To_bry_and_clear();
}
byte[] show_filenames_link = Bry_.Empty;
if (xnde.Show_filename()) {
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_plain_by_bry
( tmp_bfr, src, lnki
, Bry_.Limit(ttl.Page_txt(), 25) // 25 is defined by captionLength in DefaultSettings.php
); // MW:passes know,noclasses which isn't relevant to XO
}
int itm_div_width = this.Get_gb_width(html_w_expand, html_h_expand);
// Gallery_box_w_fmtr_arg box_w_fmtr_arg = hctx_is_hdump ? (Gallery_box_w_fmtr_arg)box_w_fmtr__hdump : (Gallery_box_w_fmtr_arg)box_w_fmtr__basic;
Gallery_box_w_fmtr_arg box_w_fmtr_arg = box_w_fmtr__basic;
Gallery_html_wtr_.Fmtr__li__img.Bld_bfr_many(bfr, li_id_atr, box_w_fmtr_arg.Init(img_uid, itm_div_width));
bfr.Add(itm_html);
wiki.Parser_mgr().Main().Parse_text_to_html(tmp_bfr, page, hctx, true, itm_caption);
itm_caption = tmp_bfr.To_bry_and_clear();
itm_caption = tmp_bfr.Add(show_filenames_link).Add(itm_caption).To_bry_and_clear();
Wrap_gallery_text(bfr, itm_caption, html_w_expand, html_h_expand);
bfr.Add(itm_li_end_bry);
if (hctx_is_hdump)
page.Hdump_data().Imgs_add_img(new Xohd_img_itm__gallery_itm().Data_init_gallery(itm_div_width, img_div_w, vpad), xfer_itm, Xohd_img_itm__gallery_itm.Tid_gallery);
}
private static final byte[]
Wrap_gallery_text_bgn = Bry_.new_a7("\n <div class=\"gallerytext\">") // NOTE: The newline after <div class="gallerytext"> is needed to accommodate htmltidy
, Wrap_gallery_text_end = Bry_.new_a7("\n </div>") // NOTE: prepend "\n"; will cause extra \n when caption exists, but needed when caption doesn't exists; EX: "<div class='caption'> </div>"; \n puts
;
@gplx.Virtual public void Get_thumb_size(Xop_lnki_tkn lnki, Xof_ext ext) { // REF.MW: getThumbParams; Get the transform parameters for a thumbnail.
lnki.W_(itm_default_w);
lnki.H_(itm_default_h);
}
@gplx.Virtual public void Adjust_image_parameters(Xof_file_itm xfer_itm) {} // REF.MW: Adjust the image parameters for a thumbnail. Used by a subclass to insert extra high resolution images.
private static final byte[]
itm_li_end_bry = Bry_.new_a7 ( "\n </div>"
+ "\n </li>")
, box_html_end_bry = Bry_.new_a7 ( "\n</ul>")
, itm_divs_end_bry = Bry_.new_a7 ( "\n </div>\n </div>")
;
private static byte[] Fmt_and_add(Bry_bfr tmp_bfr, Bry_fmtr fmtr, byte[] trailer, Object... fmtr_args) {
fmtr.Bld_bfr_many(tmp_bfr, fmtr_args);
if (Bry_.Len_gt_0(trailer)) {
tmp_bfr.Add_byte_space();
tmp_bfr.Add(trailer);
}
return tmp_bfr.To_bry_and_clear();
@gplx.Virtual public void Get_modules(Xoae_page page) { // REF.MW: getModules; Get a list of modules to include in the page.
page.Html_data().Head_mgr().Itm__gallery_styles().Enabled_y_(); // enable styles or some galleries will show up as list items; PAGE:s.w:Gothic_architecture DATE:2015-11-06
}
private static void Box_hdr_write(Bry_bfr bfr, Xop_xatr_whitelist_mgr whitelist_mgr, byte[] src, byte[] gallery_ul_uid, byte[] cls, byte[] style, List_adp xatr_list, boolean hctx_is_hdump, int uid) {
bfr.Add_byte(Byte_ascii.Lt).Add(Gfh_tag_.Bry__ul);
if (!hctx_is_hdump)
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__id, gallery_ul_uid);
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__class, cls);
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__style, style);
if (xatr_list != null) {
int len = xatr_list.Count();
for (int i = 0; i < len; i++) {
Mwh_atr_itm xatr = (Mwh_atr_itm)xatr_list.Get_at(i);
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid__ul, src, xatr)) continue;
byte[] key = xatr.Key_bry();
byte[] val = xatr.Val_as_bry();
Gfh_wtr.Write_atr_bry(bfr, key, val);
}
}
bfr.Add_byte(Byte_ascii.Gt);
@gplx.Virtual public void Init(int itm_default_w, int itm_default_h, int itms_per_row) {
this.itm_default_w = itm_default_w;
this.itm_default_h = itm_default_h;
this.itms_per_row = itms_per_row;
}
@gplx.Virtual public void Adjust_image_parameters(Xof_file_itm xfer_itm) {} // REF.MW: Adjust the image parameters for a thumbnail. Used by a subclass to insert extra high resolution images.
@gplx.Virtual public void Wrap_gallery_text(Bry_bfr bfr, byte[] gallery_text, int thm_w, int thm_h) {
bfr .Add_str_a7("\n <div class=\"gallerytext\">") // NOTE: The newline after <div class="gallerytext"> is needed to accommodate htmltidy
.Add(gallery_text)
.Add_str_a7("\n </div>"); // NOTE: prepend "\n"; will cause extra \n when caption exists, but needed when caption doesn't exists; EX: "<div class='caption'> </div>"; \n puts
}
}
class Gallery_mgr_traditional extends Gallery_mgr_base {
@Override public byte Tid() {return Gallery_mgr_base_.Traditional_tid;}
@Override public byte[] Tid_bry() {return Gallery_mgr_base_.Traditional_bry;}
@Override public byte Tid() {return Gallery_mgr_base_.Tid__traditional;}
}
class Gallery_mgr_nolines extends Gallery_mgr_base {
@Override public byte Tid() {return Gallery_mgr_base_.Nolines_tid;}
@Override public byte[] Tid_bry() {return Gallery_mgr_base_.Nolines_bry;}
@Override public byte Tid() {return Gallery_mgr_base_.Tid__nolines;}
@Override public int Get_thumb_padding() {return 0;}
@Override public int Get_gb_padding() {return 4;} // This accounts for extra space between <li> elements.
@Override public int Get_vpad(int itm_h, int thm_h) {return 0;}

View File

@@ -16,59 +16,60 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*;
public class Gallery_mgr_base_ {
public static byte Get_or_traditional(byte[] bry) {
Byte_obj_val rv = (Byte_obj_val)Hash.Get_by(bry);
return rv == null ? Traditional_tid : rv.Val();
public static final byte
Tid__traditional = 0
, Tid__nolines = 1
, Tid__packed = 2
, Tid__packed__hover = 3
, Tid__packed__overlay = 4
;
private static final byte[]
Bry__traditional = Bry_.new_a7("traditional")
, Bry__nolines = Bry_.new_a7("nolines")
, Bry__packed = Bry_.new_a7("packed")
, Bry__packed__hover = Bry_.new_a7("packed-hover")
, Bry__packed__overlay = Bry_.new_a7("packed-overlay")
;
private static final Hash_adp_bry bry_hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Bry__traditional , Tid__traditional)
.Add_bry_byte(Bry__nolines , Tid__nolines)
.Add_bry_byte(Bry__packed , Tid__packed)
.Add_bry_byte(Bry__packed__hover , Tid__packed__hover)
.Add_bry_byte(Bry__packed__overlay , Tid__packed__overlay)
;
public static byte To_tid_or_traditional(byte[] bry) {
return bry_hash.Get_as_byte_or(bry, Tid__traditional);
}
public static byte[] Get_bry_by_tid(byte mode) {
switch (mode) {
case Traditional_tid: return Traditional_bry;
case Nolines_tid: return Nolines_bry;
case Packed_tid: return Packed_bry;
case Packed_hover_tid: return Packed_hover_bry;
case Packed_overlay_tid: return Packed_overlay_bry;
default: throw Err_.new_unhandled(mode);
public static byte To_tid_or(byte[] src, int bgn, int end, byte or) {
return bry_hash.Get_as_byte_or(src, bgn, end, or);
}
public static byte[] To_bry(byte tid) {
switch (tid) {
case Tid__traditional: return Bry__traditional;
case Tid__nolines: return Bry__nolines;
case Tid__packed: return Bry__packed;
case Tid__packed__hover: return Bry__packed__hover;
case Tid__packed__overlay: return Bry__packed__overlay;
default: throw Err_.new_unhandled(tid);
}
}
public static Gallery_mgr_base New_by_mode(byte mode) {
public static Gallery_mgr_base New(byte mode) {
switch (mode) {
default:
case Traditional_tid: return new Gallery_mgr_traditional();
case Nolines_tid: return new Gallery_mgr_nolines();
case Packed_tid: return new Gallery_mgr_packed_base();
case Packed_hover_tid: return new Gallery_mgr_packed_hover();
case Packed_overlay_tid: return new Gallery_mgr_packed_overlay();
case Tid__traditional: return new Gallery_mgr_traditional();
case Tid__nolines: return new Gallery_mgr_nolines();
case Tid__packed: return new Gallery_mgr_packed_base();
case Tid__packed__hover: return new Gallery_mgr_packed_hover();
case Tid__packed__overlay: return new Gallery_mgr_packed_overlay();
}
}
public static boolean Mode_is_packed(byte v) {
switch (v) {
case Packed_tid:
case Packed_hover_tid:
case Packed_overlay_tid: return true;
public static boolean Mode_is_packed(byte tid) {
switch (tid) {
case Tid__packed:
case Tid__packed__hover:
case Tid__packed__overlay: return true;
default: return false;
}
}
public static final byte
Traditional_tid = 0
, Nolines_tid = 1
, Packed_tid = 2
, Packed_hover_tid = 3
, Packed_overlay_tid = 4
;
public static final byte[]
Traditional_bry = Bry_.new_a7("traditional")
, Nolines_bry = Bry_.new_a7("nolines")
, Packed_bry = Bry_.new_a7("packed")
, Packed_hover_bry = Bry_.new_a7("packed-hover")
, Packed_overlay_bry = Bry_.new_a7("packed-overlay")
;
public static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Traditional_bry , Traditional_tid)
.Add_bry_byte(Nolines_bry , Nolines_tid)
.Add_bry_byte(Packed_bry , Packed_tid)
.Add_bry_byte(Packed_hover_bry , Packed_hover_tid)
.Add_bry_byte(Packed_overlay_bry , Packed_overlay_tid)
;
}

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
import gplx.xowa.htmls.*; import gplx.xowa.files.fsdb.*;
public class Gallery_mgr_base_basic_tst {
public class Gallery_mgr_base__basic__tst {
private Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt();
@Before public void init() {fxt.Reset();}
@Test public void Basic() {
@@ -155,12 +155,6 @@ public class Gallery_mgr_base_basic_tst {
@Test public void Alt__quotes() { // PURPOSE: file name with quotes will cause broken alt; PAGE:en.w:en.w:Alexandria,_Romania; DATE:2015-12-27
fxt.Test_html_frag("<gallery>File:A\"b.png", "alt=\"A&quot;b.png\""); // NOTE: not 'alt="A"b.png"'
}
// @Test public void Ttl_caption() { // TODO_OLD: category entries get rendered with name only (no ns)
// fxt.Test_html_frag
// ( "<gallery>Category:A</gallery>"
// , "<li class='gallerycaption'>B</li>"
// );
// }
@Test public void Invalid() { // PURPOSE: ignore invalid file names; DATE:2016-01-12
fxt.Test_html_str("<gallery>File:#A.png|a</gallery>"
, String_.Concat_lines_nl_skip_last
@@ -177,11 +171,11 @@ public class Gallery_mgr_base_basic_tst {
class Gallery_mgr_base_fxt {
public void Reset() {
fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());
Gallery_mgr_base.File_found_mode = Bool_.Y_byte;
Gallery_mgr_wtr.File_found_mode = Bool_.Y_byte;
}
public Xop_fxt Fxt() {return fxt;} private final Xop_fxt fxt = new Xop_fxt();
public void Init_files_missing_y_() {
Gallery_mgr_base.File_found_mode = Bool_.N_byte;
Gallery_mgr_wtr.File_found_mode = Bool_.N_byte;
}
public void Test_html_str(String raw, String expd) {fxt.Test_html_full_str(raw, expd);}
public void Test_html_frag(String raw, String... expd_frags) {fxt.Test_html_full_frag(raw, expd_frags);} // TODO_OLD: change to wiki_str; currently uids do not get reset if wiki

View File

@@ -18,9 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*;
import gplx.xowa.htmls.*;
public class Gallery_mgr_base_xnde_atrs_tst {
private Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt();
@Before public void init() {fxt.Reset();}
public class Gallery_mgr_base__xatrs__tst {
@Before public void init() {fxt.Reset();} private final Gallery_mgr_base_fxt fxt = new Gallery_mgr_base_fxt();
@Test public void Atr_misc() {// PURPOSE: add other atrs to end of ul
fxt.Test_html_frag
( "<gallery id=a>File:A.png</gallery>"
@@ -33,34 +32,34 @@ public class Gallery_mgr_base_xnde_atrs_tst {
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" style=\"max-width:326px; _width:326px; color:blue;\">"
);
}
@Test public void Atr_caption() { // PURPOSE: caption atr adds new element
fxt.Test_html_frag
( "<gallery caption=B>File:A.png</gallery>"
, "<li class='gallerycaption'>B</li>"
);
}
@Test public void Atr_caption_ignore() { // PURPOSE: blank caption should not create caption element; PAGE:fr.w:Chronologie_du_si<EFBFBD>ge_de_Paris_(1870) DATE:2014-08-15
fxt.Test_html_frag_n
( "<gallery caption=>File:A.png</gallery>"
, "<li class='gallerycaption'>"
);
}
@Test public void Atr_show_filename() { // PURPOSE: show filename
fxt.Test_html_frag
( "<gallery showfilename=true>A.png</gallery>"
, "<div class=\"gallerytext\"><a href=\"/wiki/File:A.png\">File:A.png</a>"
);
}
@Test public void Atr_whitelist() { // PURPOSE: ignore atrs not in whitelist
fxt.Test_html_frag
( "<gallery onmouseover='alert();'>A.png</gallery>"
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
);
}
// @Test public void Ttl_caption() { // TODO_OLD: PURPOSE: category entries get rendered with name only (no ns)
// fxt.Test_html_frag
// ( "<gallery>Category:A</gallery>"
// , "<li class='gallerycaption'>B</li>"
// );
// }
@Test public void Mgr_caption() { // PURPOSE: caption atr adds new element
fxt.Test_html_frag
( "<gallery caption=B>File:A.png</gallery>"
, "<li class=\"gallerycaption\">B</li>"
);
}
@Test public void Mgr_caption_ignore() { // PURPOSE: blank caption should not create caption element; PAGE:fr.w:Chronologie_du_si<EFBFBD>ge_de_Paris_(1870) DATE:2014-08-15
fxt.Test_html_frag_n
( "<gallery caption=>File:A.png</gallery>"
, "<li class=\"gallerycaption\">"
);
}
@Test public void Show_filename() { // PURPOSE: show filename
fxt.Test_html_frag
( "<gallery showfilename=true>A.png</gallery>"
, "<div class=\"gallerytext\"><a href=\"/wiki/File:A.png\">File:A.png</a>"
);
}
//@Test public void Ttl_caption() { // PURPOSE: category entries get rendered with name only (no ns)
// fxt.Test_html_frag
// ( "<gallery>Category:A</gallery>"
// , "<li class='gallerycaption'>B</li>"
// );
//}
}

View File

@@ -19,14 +19,12 @@ package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.x
import gplx.xowa.files.*; import gplx.xowa.htmls.modules.*;
import gplx.xowa.parsers.lnkis.*;
public class Gallery_mgr_packed_base extends Gallery_mgr_base {
@Override public byte Tid() {return Gallery_mgr_base_.Packed_tid;}
@Override public byte[] Tid_bry() {return Gallery_mgr_base_.Packed_bry;}
@Override public void Init(int itms_per_row, int itm_default_w, int itm_default_h) {
this.itms_per_row = 0; // Does not support per row option.
@Override public byte Tid() {return Gallery_mgr_base_.Tid__packed;}
@Override public void Init(int itm_default_w, int itm_default_h, int itms_per_row) {
this.itm_default_w = itm_default_w;
this.itm_default_h = itm_default_h;
this.itms_per_row = 0; // Does not support per row option.
}
@Override public void Itms_per_row_(int v) {}
@Override public void Get_modules(Xoae_page page) {
super.Get_modules(page);
page.Html_data().Head_mgr().Itm__gallery().Enabled_y_();
@@ -66,7 +64,6 @@ public class Gallery_mgr_packed_base extends Gallery_mgr_base {
}
}
class Gallery_mgr_packed_overlay extends Gallery_mgr_packed_base {
@Override public byte[] Tid_bry() {return Gallery_mgr_base_.Packed_overlay_bry;}
@Override public void Wrap_gallery_text(Bry_bfr bfr, byte[] gallery_text, int thm_w, int thm_h) {
if (gallery_text.length == 0) return; // If we have no text, do not output anything to avoid ugly white overlay.
int img_w = this.Get_gb_width(thm_w, thm_h) - this.Get_thumb_padding() - this.Get_gb_padding();
@@ -76,11 +73,10 @@ class Gallery_mgr_packed_overlay extends Gallery_mgr_packed_base {
.Add(Wrap_gallery_text_2)
;
}
private static final byte[]
private static final byte[]
Wrap_gallery_text_0 = Bry_.new_a7("\n <div class=\"gallerytextwrapper\" style=\"width: ")
, Wrap_gallery_text_1 = Bry_.new_a7("px\"><div class=\"gallerytext\">\n") // NOTE: The newline after <div class="gallerytext"> is needed to accommodate htmltidy
, Wrap_gallery_text_2 = Bry_.new_a7("\n </div></div>") // NOTE: 2nd </div> is not part of MW, but needed to close div
;
}
class Gallery_mgr_packed_hover extends Gallery_mgr_packed_overlay { @Override public byte[] Tid_bry() {return Gallery_mgr_base_.Packed_hover_bry;}
}
class Gallery_mgr_packed_hover extends Gallery_mgr_packed_overlay { }

View File

@@ -0,0 +1,199 @@
/*
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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.lnkis.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.htmls.core.makes.imgs.*;
import gplx.xowa.files.*;
public class Gallery_mgr_wtr {
private static final Gallery_img_pad_fmtr_arg div_3_fmtr_arg = new Gallery_img_pad_fmtr_arg();
private static final Gallery_box_w_fmtr_arg li_fmtr_arg = new Gallery_box_w_fmtr_arg();
public static void Write_mgr(Bry_bfr bfr, Gallery_mgr_base mgr, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src, Gallery_xnde xnde) {
// init
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
boolean hctx_is_hdump = hctx.Mode_is_hdump();
int itm_default_w = mgr.Itm_default_w();
int itms_per_row = mgr.Itms_per_row();
// write <ul> lhs
int ul_uid = page.Html_data().Xtn_gallery_next_id();
byte[] ul_id = tmp_bfr.Add(Gallery_mgr_wtr_.Id__ul).Add_int_variable(ul_uid).To_bry_and_clear();
byte[] ul_style = xnde.Atr_style();
if (itms_per_row > 0) { // "perrow" specified; add "_maxwidth" to div1 style
int max_width = itms_per_row * (itm_default_w + mgr.Get_all_padding());
ul_style = Fmt_and_add(tmp_bfr, Gallery_mgr_wtr_.Fmtr__ul__style, ul_style, max_width);
page.Hdump_data().Imgs_add(new Xohd_img_itm__gallery_mgr(ul_uid, max_width));
}
byte[] ul_cls = Fmt_and_add(tmp_bfr, Gallery_mgr_wtr_.Fmtr__ul__cls, xnde.Atr_cls(), Gallery_mgr_base_.To_bry(mgr.Tid()));
Write_ul_lhs(bfr, tmp_bfr, hctx_is_hdump, wiki.Appe().Html_mgr().Whitelist_mgr(), src, xnde, ul_id, ul_cls, ul_style, xnde.Atrs_other());
// write gallery_caption; EX: <li class='gallerycaption'>caption</li>
byte[] mgr_caption = xnde.Mgr_caption();
if (Bry_.Len_gt_0(mgr_caption)) Gallery_mgr_wtr_.Fmtr__mgr_caption.Bld_bfr_many(bfr, mgr_caption);
// write <li> items
Xoae_app app = wiki.Appe(); Xoh_html_wtr html_wtr = wiki.Html_mgr().Html_wtr();
int itm_len = xnde.Itms_len();
for (int i = 0; i < itm_len; i++)
Write_itm(bfr, tmp_bfr, app, wiki, page, ctx, html_wtr, hctx, src, mgr, xnde, i, null);
bfr.Add_byte_nl().Add(Gfh_tag_.Ul_rhs); // "\n</ul>"
tmp_bfr.Mkr_rls();
}
public static void Write_itm(Bry_bfr bfr, Bry_bfr tmp_bfr, Xoae_app app, Xowe_wiki wiki, Xoae_page page, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx
, byte[] src, Gallery_mgr_base mgr, Gallery_xnde xnde, int i, Xof_file_itm xfer_itm) {
boolean hctx_is_hdump = hctx.Mode_is_hdump();
// get itm ttl / caption
Gallery_itm itm = (Gallery_itm)xnde.Itms_get_at(i);
Xoa_ttl itm_ttl = itm.Ttl(); if (Bry_.Len_eq_0(itm_ttl.Page_db())) return; // if file ttl is invalid, do not write; EX:File:#A.png; DATE:2016-01-12
byte[] itm_caption = itm.Caption_bry(); if (itm_caption == null) itm_caption = Bry_.Empty;
// get lnki, xfer, html_w_expand, html_h_expand
Xop_lnki_tkn lnki = itm.Lnki_tkn();
int lnki_w_orig = lnki.W(), lnki_h_orig = lnki.H(); // capture orig lnki_w / lnki_h for later
mgr.Get_thumb_size(lnki, itm.Ext()); // noop if traditional; expand by 1.5 if packed
if (xfer_itm == null) { // will be null on 1st pass
xfer_itm = html_wtr.Lnki_wtr().File_wtr().Lnki_eval(Xof_exec_tid.Tid_wiki_page, ctx, page, lnki);
xfer_itm.Html_gallery_mgr_h_(xnde.Itm_h_actl());
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2);
}
int html_w_expand = xfer_itm.Html_w();
int html_h_expand = xfer_itm.Html_h();
// get id
int img_uid = xfer_itm.Html_uid();
byte[] li_id = Gallery_mgr_wtr_.Bld_id(tmp_bfr, Gallery_mgr_wtr_.Id__li, img_uid);
byte[] li_id_atr = Gallery_mgr_wtr_.Bld_id_atr(tmp_bfr, hctx_is_hdump, li_id);
// get file_found
boolean file_found = xfer_itm.File_exists();
if (File_found_mode != Bool_.__byte) file_found = File_found_mode == Bool_.Y_byte; // TEST: override File_found
// make itm_html; 1st clause is for "missing" itms; 2nd clause is for "found" itms
byte[] itm_html = Bry_.Empty;
int div_2_w = -1, div_3_margin = -1;
if ( !hctx_is_hdump // not hdump; hdump should always write img regardless of whether or not img is missing; DATE:2015-04-27
&& ( !itm_ttl.Ns().Id_is_file() // not a file
|| !file_found // file is missing
)
) { // write text
itm_html = Gallery_mgr_wtr_.Fmtr__div1__missing.Bld_bry_many(tmp_bfr, mgr.Get_thumb_padding() + mgr.Itm_default_h(), itm_ttl.Page_txt());
itm.Html_prepare(wiki, ctx, src, xnde, xfer_itm, li_id, i);
xfer_itm.Html_img_wkr_(itm);
lnki.W_(lnki_w_orig).H_(lnki_h_orig);
html_w_expand = lnki_w_orig; // reset lnki_w_orig / lnki_h_orig else large captions
html_h_expand = lnki_h_orig;
}
else {
// get alt
byte[] alt = itm.Alt_bgn() == Bry_find_.Not_found && Bry_.Len_eq_0(itm_caption) // if ( $alt == '' && $text == '' ) $imageParameters['alt'] = $nt->getText();
? itm.Ttl().Page_txt()
: Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end());
alt = Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, alt); // NOTE: need to handle situations wherein alt has quotes; EX:File:A"b.png; PAGE:en.w:Alexandria,_Romania DATE:2015-12-27
// get href_ttl
Xoa_ttl href_ttl = itm.Link_bgn() == Bry_find_.Not_found
? itm_ttl
: Xoa_ttl.parse(wiki, Bry_.Mid(src, itm.Link_bgn(), itm.Link_end()));
if (href_ttl == null) href_ttl = itm_ttl; // occurs when link is invalid; EX: A.png|link=<invalid>
// get w, h
mgr.Adjust_image_parameters(xfer_itm); // noop if traditional; reduce by 1.5 if packed
int html_w_normal = xfer_itm.Html_w();
int html_h_normal = xfer_itm.Html_h();
xfer_itm.Init_at_gallery_bgn(html_w_normal, html_h_normal, html_w_expand);// NOTE: file_w should be set to expanded width so js can resize if gallery
// write div_2
div_2_w = mgr.Get_thumb_div_width(html_w_expand);
Gallery_mgr_wtr_.Fmtr__div1__img.Bld_bfr_many(tmp_bfr, div_2_w);
// write div_3
div_3_margin = mgr.Get_vpad(mgr.Itm_default_h(), html_h_expand);
Gallery_mgr_wtr_.Fmtr__div1__vpad.Bld_bfr_many(tmp_bfr, div_3_fmtr_arg.Init(img_uid, div_3_margin)); // <div style="margin:~{vpad}px auto;">
// write <img>
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_file(tmp_bfr, ctx, hctx, src, lnki, xfer_itm, alt);
tmp_bfr.Add(itm_divs_end_bry);
itm_html = tmp_bfr.To_bry_and_clear();
}
// write <li>
int div_1_w = mgr.Get_gb_width(html_w_expand, html_h_expand);
Gallery_mgr_wtr_.Fmtr__li__lhs.Bld_bfr_many(bfr, li_id_atr, li_fmtr_arg.Init(img_uid, div_1_w));
bfr.Add(itm_html);
// get show_filenames_link
byte[] show_filenames_link = Bry_.Empty;
if (xnde.Show_filename()) {
wiki.Html_mgr().Html_wtr().Lnki_wtr().Write_plain_by_bry
( tmp_bfr, src, lnki
, Bry_.Limit(itm_ttl.Page_txt(), 25) // 25 is defined by captionLength in DefaultSettings.php
); // MW:passes know,noclasses which isn't relevant to XO
}
// write caption
wiki.Parser_mgr().Main().Parse_text_to_html(tmp_bfr, page, hctx, true, itm_caption);
itm_caption = tmp_bfr.To_bry_and_clear();
itm_caption = tmp_bfr.Add(show_filenames_link).Add(itm_caption).To_bry_and_clear();
mgr.Wrap_gallery_text(bfr, itm_caption, html_w_expand, html_h_expand);
bfr.Add(itm_li_end_bry);
if (hctx_is_hdump)
page.Hdump_data().Imgs_add_img(new Xohd_img_itm__gallery_itm().Data_init_gallery(div_1_w, div_2_w, div_3_margin), xfer_itm, Xohd_img_itm__gallery_itm.Tid_gallery);
}
public static byte File_found_mode = Bool_.__byte;
private static byte[] Fmt_and_add(Bry_bfr tmp_bfr, Bry_fmtr fmtr, byte[] trailer, Object... fmtr_args) {
fmtr.Bld_bfr_many(tmp_bfr, fmtr_args);
if (Bry_.Len_gt_0(trailer)) {
tmp_bfr.Add_byte_space();
tmp_bfr.Add(trailer);
}
return tmp_bfr.To_bry_and_clear();
}
private static void Write_ul_lhs(Bry_bfr bfr, Bry_bfr tmp_bfr, boolean hctx_is_hdump, Xop_xatr_whitelist_mgr whitelist_mgr, byte[] src, Gallery_xnde xnde, byte[] ul_id, byte[] ul_cls, byte[] ul_style, List_adp xatr_list) {
bfr.Add_byte(Byte_ascii.Lt).Add(Gfh_tag_.Bry__ul);
if (hctx_is_hdump) { // if hdump, write extra data;
tmp_bfr.Add_int_variable(xnde.Itm_w_orig()).Add_byte_pipe();
tmp_bfr.Add_int_variable(xnde.Itm_h_orig()).Add_byte_pipe();
tmp_bfr.Add_int_variable(xnde.Itms_per_row());
Gfh_wtr.Write_atr_bry(bfr, Bry__data_xogly, tmp_bfr.To_bry_and_clear());
}
else // not hdump; write id attribute
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__id, ul_id);
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__class, ul_cls);
Gfh_wtr.Write_atr_bry(bfr, Gfh_atr_.Bry__style, ul_style);
if (xatr_list != null) {
int len = xatr_list.Count();
for (int i = 0; i < len; i++) {
Mwh_atr_itm xatr = (Mwh_atr_itm)xatr_list.Get_at(i);
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid__ul, src, xatr)) continue;
byte[] key = xatr.Key_bry();
byte[] val = xatr.Val_as_bry();
Gfh_wtr.Write_atr_bry(bfr, key, val);
}
}
bfr.Add_byte(Byte_ascii.Gt);
}
private static final byte[]
itm_li_end_bry = Bry_.new_a7 ( "\n </div>"
+ "\n </li>")
, itm_divs_end_bry = Bry_.new_a7 ( "\n </div>\n </div>");
public static final byte[] Bry__data_xogly = Bry_.new_a7 ("data-xogly");
}

View File

@@ -18,63 +18,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.parsers.*; import gplx.xowa.htmls.core.htmls.*;
public class Gallery_html_wtr_ {
public static final byte[] Cls_packed = Bry_.new_a7(" mw-gallery-packed");
public static final Bry_fmtr
Fmtr__ul__nde = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<ul~{id} class=\"gallery~{cls}\" style=\"~{style}\">~{itm_list}"
, "</ul>"
), "id", "cls", "style", "itm_list"
)
, Mgr_box_style_none = Bry_fmtr.new_()
, Mgr_box_style_max = Bry_fmtr.new_("max-width:~{gallery_width}px; _width:~{gallery_width}px;", "gallery_width")
, Itm_img_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width}px;\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" class=\"thumb\" style=\"width:~{itm_div_width}px;\">"
, " <div id=\"xowa_gallery_div3_~{img_id}\" style=\"margin:~{itm_margin}px auto;\">"
, " <a href=\"~{img_href}\" class=\"image\">"
, " <img id=\"xoimg_~{img_id}\" alt=\"~{img_alt}\"~{img_core} />"
, " </a>"
, " </div>"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_width", "itm_margin", "img_id", "img_ttl", "img_href", "img_core", "itm_caption", "img_alt"
)
, Itm_txt_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li id=\"xowa_gallery_li_~{img_id}\" class=\"gallerybox\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div1_~{img_id}\" style=\"width:~{itm_box_width};\">"
, " <div id=\"xowa_gallery_div2_~{img_id}\" style=\"~{itm_div_height}\">"
, " ~{itm_text}"
, " </div>"
, " <div class=\"gallerytext\">~{itm_caption}"
, " </div>"
, " </div>"
, " </li>"
), "itm_box_width", "itm_div_height", "itm_text", "itm_caption"
);
public static final Bry_fmtr
public class Gallery_mgr_wtr_ {
public static final Bry_fmtr
Fmtr__ul__style = Bry_fmtr.new_( "max-width:~{max_width}px; _width:~{max_width}px;", "max_width")
, Fmtr__ul__cls = Bry_fmtr.new_( "gallery mw-gallery-~{mode}", "mode")
, Fmtr__li__txt = Bry_fmtr.new_( "\n <li class='gallerycaption'>~{caption}</li>", "caption")
, Fmtr__li__img = Bry_fmtr.new_( "\n <li~{li_id} class=\"gallerybox\" ~{itm_box_w}>"
, Fmtr__mgr_caption = Bry_fmtr.new_( "\n <li class=\"gallerycaption\">~{caption}</li>", "caption")
, Fmtr__li__lhs = Bry_fmtr.new_( "\n <li~{li_id} class=\"gallerybox\" ~{itm_box_w}>"
+ "\n <div ~{itm_box_w}>", "li_id", "itm_box_w")
, Fmtr__div1__img = Bry_fmtr.new_( "\n <div class=\"thumb\" style=\"width:~{width}px;\">", "width")
, Fmtr__div1__missing = Bry_fmtr.new_( "\n <div class=\"thumb\" style=\"height:~{height}px;\">~{ttl_text}</div>", "height", "ttl_text")
, itm_div1_fmtr = Bry_fmtr.new_( "\n <div ~{vpad}>\n ", "vpad")
, Fmtr__div1__vpad = Bry_fmtr.new_( "\n <div ~{vpad}>\n ", "vpad")
, hdump_box_w_fmtr = Bry_fmtr.new_( "width:~{width}px;", "width")
, hdump_img_pad_fmtr = Bry_fmtr.new_( "margin:~{width}px auto;", "width")
;
public static final byte[]
public static final byte[]
Id__ul = Bry_.new_a7("xowa_gallery_ul_")
, Id__li = Bry_.new_a7("xowa_gallery_li_")
;
private static final byte[] Id__atr = Bry_.new_a7(" id=\"");
private static final byte[] Id__atr = Bry_.new_a7(" id=\"");
public static byte[] Bld_id(Bry_bfr bfr, byte[] prefix, int id) {return bfr.Add(prefix).Add_int_variable(id).To_bry_and_clear();}
public static byte[] Bld_id_atr(Bry_bfr bfr, boolean hdump, byte[] li_id) {return hdump ? Bry_.Empty : bfr.Add(Id__atr).Add(li_id).Add_byte_quote().To_bry_and_clear();}
public static byte[] Bld_caption(Xowe_wiki wiki, Xop_ctx ctx, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Gallery_itm itm) {
@@ -87,4 +48,8 @@ public class Gallery_html_wtr_ {
}
return rv;
}
public static int Calc_vpad(int mgr_itm_height, int html_h) {
int min_thumb_height = html_h > 17 ? html_h : 17; // $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17;
return (int)Math_.Floor((30 + mgr_itm_height - min_thumb_height) / 2); // $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2);
}
}

View File

@@ -21,7 +21,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.files.*;
public class Gallery_itm_parser {
public class Gallery_parser {
private Xowe_wiki wiki; private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_u8();
private Gallery_itm cur_itm;
private byte[] src; private int end_pos;
@@ -30,7 +30,7 @@ public class Gallery_itm_parser {
private int itm_bgn;
private Bry_bfr caption_bfr = Bry_bfr_.Reset(255); private int caption_bgn;
private Xop_ctx ctx;
public Gallery_itm_parser Init_by_wiki(Xowe_wiki wiki) {
public Gallery_parser Init_by_wiki(Xowe_wiki wiki) {
this.wiki = wiki; Xol_lang_itm lang = wiki.Lang();
this.ctx = wiki.Parser_mgr().Ctx();
trie.Clear();

View File

@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
public class Gallery_itm_parser_tst {
@Before public void init() {fxt.Init();} private Gallery_itm_parser_fxt fxt = new Gallery_itm_parser_fxt();
public class Gallery_parser_tst {
@Before public void init() {fxt.Init();} private Gallery_parser_fxt fxt = new Gallery_parser_fxt();
@Test public void All() {fxt.Test_parse("File:A.png|a|alt=b|link=c" , fxt.Expd("File:A.png", "a" , "b" , "c"));}
@Test public void Ttl_only() {fxt.Test_parse("File:A.png" , fxt.Expd("File:A.png", null, null, null));}
@Test public void Ttl_url_encoded() {fxt.Test_parse("File:A%28b%29.png" , fxt.Expd("File:A(b).png"));} // PURPOSE: handle url-encoded sequences; DATE:2014-01-01
@@ -65,13 +65,13 @@ public class Gallery_itm_parser_tst {
fxt.Test_parse("File:A.png|alt=a|b", fxt.Expd("File:A.png", "b", "a"));
}
}
class Gallery_itm_parser_fxt {
class Gallery_parser_fxt {
private Xoae_app app; private Xowe_wiki wiki;
private Gallery_itm_parser parser;
public Gallery_itm_parser_fxt Init() {
private Gallery_parser parser;
public Gallery_parser_fxt Init() {
this.app = Xoa_app_fxt.Make__app__edit();
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
parser = new Gallery_itm_parser();
parser = new Gallery_parser();
parser.Init_by_wiki(wiki);
return this;
}
@@ -87,7 +87,7 @@ class Gallery_itm_parser_fxt {
public void Test_parse(String raw, String[]... expd) {
List_adp actl = List_adp_.New();
byte[] src = Bry_.new_a7(raw);
parser.Parse_all(actl, Gallery_mgr_base_.New_by_mode(Gallery_mgr_base_.Traditional_tid), new Gallery_xnde(), src, 0, src.length);
parser.Parse_all(actl, Gallery_mgr_base_.New(Gallery_mgr_base_.Tid__traditional), new Gallery_xnde(), src, 0, src.length);
Tfds.Eq_ary(String_.Ary_flatten(expd), String_.Ary_flatten(Xto_str_ary(src, actl)));
}
private String[][] Xto_str_ary(byte[] src, List_adp list) {

View File

@@ -16,115 +16,83 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.primitives.*; import gplx.dbs.cfgs.*;
import gplx.fsdb.meta.*;
import gplx.xowa.parsers.logs.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.files.*; import gplx.xowa.files.fsdb.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*;
public class Gallery_xnde implements Xox_xnde, Mwh_atr_itm_owner1 {
import gplx.dbs.cfgs.*; import gplx.xowa.parsers.logs.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.files.fsdb.*;
public class Gallery_xnde implements Xox_xnde, Mwh_atr_itm_owner2 {
private Gallery_xtn_mgr xtn_mgr;
public byte Mode() {return mode;} private byte mode;
public int Itm_w() {return itm_w;} private int itm_w = Null;
public int Itm_h() {return itm_h;} private int itm_h = Null;
public int Itms_per_row() {return itms_per_row;} private int itms_per_row = Null;
public boolean Show_filename() {return show_filename;} private boolean show_filename = false;
public byte[] Atr_caption() {return atr_caption;} private byte[] atr_caption = Bry_.Empty;
public byte[] Atr_style() {return atr_style;} private byte[] atr_style = Bry_.Empty;
public byte[] Atr_cls() {return atr_cls;} private byte[] atr_cls = Bry_.Empty;
public List_adp Atrs_other() {return atrs_other;} private List_adp atrs_other;
public int Itm_w_or_default() {return itm_w == Null ? Default : itm_w;}
public int Itm_h_or_default() {return itm_h == Null ? Default : itm_h;}
public int Itms_len() {return itms.Count();} private List_adp itms = List_adp_.New();
public Gallery_itm Itms_get_at(int i) {return (Gallery_itm)itms.Get_at(i);}
public Gallery_mgr_base Gallery_mgr() {return gallery_mgr;} private Gallery_mgr_base gallery_mgr;
private boolean html_wtr_v1 = false;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, Object xatr_id_obj) {
if (xatr_id_obj != null) {
Byte_obj_val xatr_id = (Byte_obj_val)xatr_id_obj;
switch (xatr_id.Val()) {
case Gallery_xnde_atrs.Mode_tid: mode = Gallery_mgr_base_.Get_or_traditional(xatr.Val_as_bry()); break;
case Gallery_xnde_atrs.Perrow_tid: itms_per_row = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Widths_tid: itm_w = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Heights_tid: itm_h = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Showfilename_tid: show_filename = xatr.Val_as_bool(); break;
case Gallery_xnde_atrs.Caption_tid: if (xatr.Key_exists()) atr_caption = xatr.Val_as_bry(); break; // NOTE: do not create caption for key only; EX:<gallery caption=> PAGE:fr.w:Chronologie_du_si<73>ge_de_Paris_(1870); DATE:2014-08-15
case Gallery_xnde_atrs.Style_tid: atr_style = xatr.Val_as_bry(); break;
case Gallery_xnde_atrs.Class_tid: atr_cls = xatr.Val_as_bry(); break;
}
}
else {
if (atrs_other == null) atrs_other = List_adp_.New();
atrs_other.Add(xatr);
public byte Mode() {return mode;} private byte mode;
public int Itm_w_orig() {return itm_w_orig;} private int itm_w_orig = Null;
public int Itm_h_orig() {return itm_h_orig;} private int itm_h_orig = Null;
public int Itm_w_actl() {return itm_w_actl;} private int itm_w_actl = Null;
public int Itm_h_actl() {return itm_h_actl;} private int itm_h_actl = Null;
public int Itms_per_row() {return itms_per_row;} private int itms_per_row = Null;
public int Itms_len() {return itms.Count();} private final List_adp itms = List_adp_.New();
public Gallery_itm Itms_get_at(int i) {return (Gallery_itm)itms.Get_at(i);}
public byte[] Atr_style() {return atr_style;} private byte[] atr_style = Bry_.Empty;
public byte[] Atr_cls() {return atr_cls;} private byte[] atr_cls = Bry_.Empty;
public List_adp Atrs_other() {return atrs_other;} private List_adp atrs_other;
public boolean Show_filename() {return show_filename;} private boolean show_filename = false;
public byte[] Mgr_caption() {return mgr_caption;} private byte[] mgr_caption = Bry_.Empty;
public Gallery_mgr_base Gallery_mgr() {return gallery_mgr;} private Gallery_mgr_base gallery_mgr;
public void Xatr__set(Xowe_wiki wiki, byte[] src, Mwh_atr_itm xatr, byte xatr_id) {
switch (xatr_id) {
case Gallery_xnde_atrs.Tid__mode: mode = Gallery_mgr_base_.To_tid_or_traditional(xatr.Val_as_bry()); break;
case Gallery_xnde_atrs.Tid__perrow: itms_per_row = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Tid__widths: itm_w_orig = itm_w_actl = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Tid__heights: itm_h_orig = itm_h_actl = xatr.Val_as_int_or(Null); break;
case Gallery_xnde_atrs.Tid__style: atr_style = xatr.Val_as_bry(); break;
case Gallery_xnde_atrs.Tid__class: atr_cls = xatr.Val_as_bry(); break;
case Gallery_xnde_atrs.Tid__showfilename: show_filename = xatr.Val_as_bool(); break;
case Gallery_xnde_atrs.Tid__caption: if (xatr.Key_exists()) mgr_caption = xatr.Val_as_bry(); break; // NOTE: do not create caption for key only; EX:<gallery caption=> PAGE:fr.w:Chronologie_du_si<73>ge_de_Paris_(1870); DATE:2014-08-15
default:
if (atrs_other == null) atrs_other = List_adp_.New();
atrs_other.Add(xatr);
break;
}
}
public void Xtn_parse(Xowe_wiki wiki, Xop_ctx ctx, Xop_root_tkn root, byte[] src, Xop_xnde_tkn xnde) {
Xox_xnde_.Parse_xatrs(wiki, this, Gallery_xnde_atrs.Key_hash, src, xnde);
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn); // cancel pre for <gallery>; DATE:2014-03-11
try {
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_bgn); // cancel pre for <gallery>; DATE:2014-03-11
Xox_xnde_.Xatr__set(wiki, this, Gallery_xnde_atrs.Key_hash, src, xnde);
xtn_mgr = (Gallery_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Gallery_xtn_mgr.XTN_KEY);
Init_atrs(wiki);
// do further post-processing of vars based on wiki's fsdb.cfg
Init_xnde_by_atrs(wiki);
gallery_mgr.Get_modules(ctx.Page());
Gallery_itm_parser parser = xtn_mgr.Parser();
if (parser.Parse_in_progress()) parser = new Gallery_itm_parser().Init_by_wiki(wiki); // handle nested galleries; EX: <gallery><ref><gallery>; PAGE:es.w:Arquitectura_medieval DATE:2015-07-10
// parse
xtn_mgr = (Gallery_xtn_mgr)wiki.Xtn_mgr().Get_or_fail(Gallery_xtn_mgr.XTN_KEY);
Gallery_parser parser = xtn_mgr.Parser();
if (parser.Parse_in_progress()) parser = new Gallery_parser().Init_by_wiki(wiki); // handle nested galleries; EX: <gallery><ref><gallery>; PAGE:es.w:Arquitectura_medieval DATE:2015-07-10
parser.Parse_all(itms, gallery_mgr, this, src, xnde.Tag_open_end(), xnde.Tag_close_bgn());
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Page(), Xop_log_basic_wkr.Tid_gallery, src, xnde);
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end); // cancel pre for <gallery>; DATE:2014-03-11
} catch (Exception exc) {
wiki.Appe().Usr_dlg().Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_u8(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx_full(exc));
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_u8(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx_full(exc));
}
ctx.Para().Process_block__xnde(xnde.Tag(), Xop_xnde_tag.Block_end); // cancel pre for <gallery>; DATE:2014-03-11
boolean log_wkr_enabled = Log_wkr != Xop_log_basic_wkr.Null; if (log_wkr_enabled) Log_wkr.Log_end_xnde(ctx.Page(), Xop_log_basic_wkr.Tid_gallery, src, xnde);
} public static Xop_log_basic_wkr Log_wkr = Xop_log_basic_wkr.Null;
public void Xtn_write(Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_xnde_tkn xnde, byte[] src) {
Xowe_wiki wiki = ctx.Wiki();
try {
if (html_wtr_v1)
xtn_mgr.Html_wtr().Write_html(bfr, app, wiki, ctx, html_wtr, hctx, ctx.Page(), this, src);
else {
gallery_mgr.Write_html(bfr, wiki, ctx.Page(), ctx, hctx, src, this);
}
} catch (Exception exc) {
wiki.Appe().Usr_dlg().Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_u8(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx_full(exc));
}
try {Gallery_mgr_wtr.Write_mgr(bfr, gallery_mgr, ctx.Wiki(), ctx.Page(), ctx, hctx, src, this);}
catch (Exception e) {Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write gallery; src=~{0} err=~{1}", String_.new_u8(src, xnde.Src_bgn(), xnde.Src_end()), Err_.Message_gplx_log(e));}
}
private void Init_atrs(Xowe_wiki wiki) {
private void Init_xnde_by_atrs(Xowe_wiki wiki) {
Db_cfg_hash cfg_grp = wiki.File_mgr().Cfg_get(Xof_fsdb_mgr_cfg.Grp_xowa);
if (cfg_grp.Get_by(Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults).To_yn_or_n()) {
if (itm_w == Gallery_xnde.Null && itm_h == Gallery_xnde.Null) // if no w/h specified, set both to default (just like v1)
itm_w = itm_h = Gallery_xnde.Default;
if (itm_w_actl == Gallery_xnde.Null && itm_h_actl == Gallery_xnde.Null) // if no w/h specified, set both to default (just like v1)
itm_w_actl = itm_h_actl = Gallery_xnde.Default;
}
else {
if (itm_w == Gallery_xnde.Null) itm_w = Gallery_xnde.Default;
if (itm_h == Gallery_xnde.Null) itm_h = Gallery_xnde.Default;
}
gallery_mgr = Gallery_mgr_base_.New_by_mode(mode);
if ( !wiki.File_mgr().Version_1_y() // v2: fsdb
gallery_mgr = Gallery_mgr_base_.New(mode);
if ( !wiki.File_mgr().Version_1_y() // v2: fsdb
&& !cfg_grp.Get_by(Xof_fsdb_mgr_cfg.Key_gallery_packed).To_yn_or_n() // packed not supported
) {
gallery_mgr = Gallery_mgr_base_.New_by_mode(Gallery_mgr_base_.Traditional_tid); // always go to traditional
html_wtr_v1 = true;
gallery_mgr = Gallery_mgr_base_.New(Gallery_mgr_base_.Tid__traditional); // always go to traditional
}
if (itm_w_actl == Gallery_xnde.Null) itm_w_actl = Gallery_xnde.Default;
if (itm_h_actl == Gallery_xnde.Null) itm_h_actl = Gallery_xnde.Default;
gallery_mgr.Init(this.Itm_w_actl(), this.Itm_h_actl(), itms_per_row);
if (Bry_.Eq(wiki.Domain_itm().Domain_bry(), gplx.xowa.wikis.domains.Xow_domain_itm_.Bry__commons)) { // HACK.CFG: for commons, hardcode itms per row as 8; DATE:2016-06-30
itms_per_row = 8;
}
gallery_mgr.Init(itms_per_row, this.Itm_w_or_default(), this.Itm_h_or_default());
}
public static final int Default = 120, Null = -1;
}
class Gallery_xnde_atrs {
public static final byte
Mode_tid = 0
, Perrow_tid = 1
, Widths_tid = 2
, Heights_tid = 3
, Caption_tid = 4
, Showfilename_tid = 5
, Style_tid = 6
, Class_tid = 7
;
public static Hash_adp_bry Key_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("mode" , Mode_tid)
.Add_str_byte("perrow" , Perrow_tid)
.Add_str_byte("widths" , Widths_tid)
.Add_str_byte("heights" , Heights_tid)
.Add_str_byte("caption" , Caption_tid)
.Add_str_byte("showfilename" , Showfilename_tid)
.Add_str_byte("style" , Style_tid)
.Add_str_byte("class" , Class_tid)
;
public static final int Default = 120;
private static final int Null = -1;
}

View File

@@ -16,12 +16,25 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
public class Gallery_html_wtr_utl {
public static int Calc_itm_div_len(int v) {return v + 30;} // 30=Thumb padding; REF.MW:ImageGallery.php|THUMB_PADDING
public static int Calc_itm_box_w(int v) {return v + 5;} // 5=Gallery Box padding; REF.MW:ImageGallery.php|GB_PADDING
public static int Calc_itm_pad_w(int v) {return v + 8;} // 8=Gallery Box borders; REF.MW:ImageGallery.php|GB_BORDERS
public static int Calc_vpad(int mgr_itm_height, int html_h) {
int min_thumb_height = html_h > 17 ? html_h : 17; // $minThumbHeight = $thumb->height > 17 ? $thumb->height : 17;
return (int)Math_.Floor((30 + mgr_itm_height - min_thumb_height) / 2); // $vpad = floor(( self::THUMB_PADDING + $this->mHeights - $minThumbHeight ) /2);
}
class Gallery_xnde_atrs {
public static final byte
Tid__mode = 0
, Tid__perrow = 1
, Tid__widths = 2
, Tid__heights = 3
, Tid__caption = 4
, Tid__showfilename = 5
, Tid__style = 6
, Tid__class = 7
;
public static final Hash_adp_bry Key_hash = Hash_adp_bry.ci_a7()
.Add_str_byte("mode" , Tid__mode)
.Add_str_byte("perrow" , Tid__perrow)
.Add_str_byte("widths" , Tid__widths)
.Add_str_byte("heights" , Tid__heights)
.Add_str_byte("caption" , Tid__caption)
.Add_str_byte("showfilename" , Tid__showfilename)
.Add_str_byte("style" , Tid__style)
.Add_str_byte("class" , Tid__class)
;
}

View File

@@ -16,15 +16,11 @@ 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.xtns.gallery; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.htmls.modules.*;
public class Gallery_xtn_mgr extends Xox_mgr_base {
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("gallery");
@Override public Xox_mgr Xtn_clone_new() {return new Gallery_xtn_mgr();}
public Gallery_itm_parser Parser() {return parser;} private Gallery_itm_parser parser;
public Gallery_html_wtr Html_wtr() {return html_wtr;} private Gallery_html_wtr html_wtr;
@Override public byte[] Xtn_key() {return XTN_KEY;} public static final byte[] XTN_KEY = Bry_.new_a7("gallery");
@Override public Xox_mgr Xtn_clone_new() {return new Gallery_xtn_mgr();}
public Gallery_parser Parser() {return parser;} private final Gallery_parser parser = new Gallery_parser();
@Override public void Xtn_init_by_wiki(Xowe_wiki wiki) {
parser = new Gallery_itm_parser();
parser.Init_by_wiki(wiki);
html_wtr = new Gallery_html_wtr();
}
}

View File

@@ -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.xtns.imaps; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.files.*; import gplx.xowa.files.gui.*;
import gplx.xowa.files.*; import gplx.xowa.guis.cbks.js.*;
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.makes.imgs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
import gplx.xowa.xtns.imaps.itms.*; import gplx.xowa.xtns.imaps.htmls.*;
public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
@@ -51,7 +51,7 @@ public class Imap_map implements Xoh_file_img_wkr, Js_img_wkr {
}
public void Js_wkr__update_hdoc(Xoa_page page, Xog_js_wkr js_wkr, int html_uid
, int html_w, int html_h, Io_url html_view_url
, int orig_w, int orig_h, Io_url html_orig_url, byte[] lnki_ttl) {
, int orig_w, int orig_h, Xof_ext orig_ext, Io_url html_orig_url, byte[] lnki_ttl) {
Bry_bfr tmp_bfr = Bry_bfr_.Get();
try {
Write_imap_div(tmp_bfr, Xoh_wtr_ctx.Basic, html_uid, html_w, html_h, html_view_url.To_http_file_bry(), orig_w, orig_h, lnki_ttl);

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Dot_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_number;}
public byte[] Val_ary() {return Val_Ary;} static final byte[] Val_Ary = new byte[] {Byte_ascii.Dot};
public String Val_str() {return String_.new_u8(Val_Ary);}
public Dot_tkn() {}
}

View File

@@ -0,0 +1,23 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
interface Expr_tkn {
int Tid();
byte[] Val_ary();
String Val_str();
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Expr_tkn_ {
public static final int Tid_operator = 1, Tid_paren_lhs = 5, Tid_paren_rhs = 6, Tid_space = 7, Tid_number = 8;
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
interface Func_tkn extends Expr_tkn {
boolean Func_is_const();
int ArgCount();
int Precedence();
Func_tkn GetAlt();
boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack);
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_abs extends Func_tkn_base {
public Func_tkn_abs(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Abs());
return true;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.langs.msgs.*;
class Func_tkn_acos extends Func_tkn_base {
public Func_tkn_acos(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Acos(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_and extends Func_tkn_base {
public Func_tkn_and(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 3;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(!lhs.Eq(0) && !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.langs.msgs.*;
class Func_tkn_asin extends Func_tkn_base {
public Func_tkn_asin(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Asin(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_atan extends Func_tkn_base {
public Func_tkn_atan(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Atan(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.langs.msgs.*;
abstract class Func_tkn_base implements Func_tkn {
public int Tid() {return Expr_tkn_.Tid_operator;}
public abstract int Precedence();
public abstract int ArgCount();
@gplx.Virtual public boolean Func_is_const() {return false;}
public void Ctor(String v) {val_ary = Bry_.new_u8(v);}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return String_.new_u8(Val_ary());}
@gplx.Virtual public Func_tkn GetAlt() {return this;}
public boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
if (val_stack.Len() < this.ArgCount()) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_missing_operand, Val_ary()); return false;}
return Calc_hook(ctx, shunter, val_stack);
}
public abstract boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack);
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_ceil extends Func_tkn_base {
public Func_tkn_ceil(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Ceil(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_cos extends Func_tkn_base {
public Func_tkn_cos(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Cos(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,35 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.langs.msgs.*;
class Func_tkn_divide extends Func_tkn_base {
public Func_tkn_divide(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
if (rhs.Eq(0)) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(lhs.Divide(rhs));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_e_const extends Func_tkn_base {
public Func_tkn_e_const(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 0;}
@Override public int Precedence() {return 0;}
@Override public boolean Func_is_const() {return true;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
val_stack.Push(Decimal_adp_.Const_e);
return true;
}
public static final Func_tkn_e_const Instance = new Func_tkn_e_const("e");
}

View File

@@ -0,0 +1,41 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_e_op extends Func_tkn_base {
public Func_tkn_e_op(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 9;} // NOTE: needs to be < than - sign
@Override public Func_tkn GetAlt() {return Func_tkn_e_const.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
int rhs_int = rhs.To_int();
if ( rhs_int > 308
|| (lhs.To_double() >= 1.8f && rhs_int == 308)) { // PHP:"maximum of ~1.8e308"; verified with {{#expr:1.8e308}} on sandbox; REF:http://php.net/manual/en/language.types.float.php; PAGE:en.w:Factorial; en.w:Astatine; DATE:2015-04-08; DATE:2015-04-21
shunter.Rslt_set(Double_.Inf_pos_bry);
return false;
}
double rhs_double = rhs.To_double();
if ((double)rhs_int == rhs_double) // exponent is integer; use pow_10 which does less casts to double
val_stack.Push(lhs.Multiply(Decimal_adp_.pow_10_(rhs_int)));
else
val_stack.Push(lhs.Multiply(Decimal_adp_.double_thru_str_(Math_.Pow(10d, rhs_double))));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_eq extends Func_tkn_base {
public Func_tkn_eq(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_exp extends Func_tkn_base {
public Func_tkn_exp(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Exp(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_floor extends Func_tkn_base {
public Func_tkn_floor(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Floor(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,34 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.langs.msgs.*;
class Func_tkn_fmod extends Func_tkn_base {
public Func_tkn_fmod(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = (Decimal_adp)val_stack.Pop();
Decimal_adp lhs = (Decimal_adp)val_stack.Pop();
if (rhs.To_double() == 0) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(lhs.Mod(rhs));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_gt extends Func_tkn_base {
public Func_tkn_gt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_gt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_gte extends Func_tkn_base {
public Func_tkn_gte(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_gte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
import gplx.xowa.langs.msgs.*;
class Func_tkn_ln extends Func_tkn_base {
public Func_tkn_ln(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lte(0)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument_ln); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Log(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_lt extends Func_tkn_base {
public Func_tkn_lt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_lt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_lte extends Func_tkn_base {
public Func_tkn_lte(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_lte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_minus extends Func_tkn_base {
public Func_tkn_minus(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 6;}
@Override public Func_tkn GetAlt() {return Func_tkn_minus_negative.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Subtract(rhs));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_minus_negative extends Func_tkn_base {
public Func_tkn_minus_negative(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 10;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Multiply(Decimal_adp_.Neg1));
return true;
}
public static final Func_tkn_minus_negative Instance = new Func_tkn_minus_negative("-");
}

View File

@@ -0,0 +1,36 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*; import gplx.xowa.langs.msgs.*;
class Func_tkn_mod extends Func_tkn_base {
public Func_tkn_mod(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
// must convert to int else issues with {{#expr:0.00999999mod10}} and {{USCensusPop|1960=763956|1970=756510}}; REF: http://php.net/manual/en/language.operators.arithmetic.php: "Operands of modulus are converted to integers (by stripping the decimal part) before processing"
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.Max_value; EX: de.w:Quijano_(Piélagos)
long rhs = ((Decimal_adp)val_stack.Pop()).To_long();
long lhs = ((Decimal_adp)val_stack.Pop()).To_long();
if (rhs == 0) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(Decimal_adp_.long_(lhs % rhs));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_neq extends Func_tkn_base {
public Func_tkn_neq(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.Zero : Decimal_adp_.One);
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_not extends Func_tkn_base {
public Func_tkn_not(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_or extends Func_tkn_base {
public Func_tkn_or(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 2;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(!lhs.Eq(0) || !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_pi extends Func_tkn_base {
public Func_tkn_pi(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 0;}
@Override public int Precedence() {return 0;}
@Override public boolean Func_is_const() {return true;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
val_stack.Push(Decimal_adp_.Const_pi);
return true;
}
}

View File

@@ -0,0 +1,32 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_plus extends Func_tkn_base {
public Func_tkn_plus(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 6;}
@Override public Func_tkn GetAlt() {return Func_tkn_plus_positive.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Add(rhs));
return true;
}
public static final Func_tkn_plus Instance = new Func_tkn_plus(); Func_tkn_plus() {}
}

View File

@@ -0,0 +1,26 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_plus_positive extends Func_tkn_base {
Func_tkn_plus_positive(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 10;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {return true;}// effectively a noop
public static final Func_tkn_plus_positive Instance = new Func_tkn_plus_positive("+");
}

View File

@@ -0,0 +1,41 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_pow extends Func_tkn_base {
public Func_tkn_pow(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 8;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
int rhs_int = rhs.To_int();
if ((double)rhs_int == rhs.To_double()) // exponent is integer; use decimal pow which does less casts to double
val_stack.Push(lhs.Pow(rhs_int));
else {
double rslt = Math_.Pow(lhs.To_double(), rhs.To_double());
if (Double_.IsNaN(rslt)) {
shunter.Rslt_set(Double_.NaN_bry);
return false;
}
else
val_stack.Push(Decimal_adp_.double_thru_str_(rslt));
}
return true;
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_round extends Func_tkn_base {
public Func_tkn_round(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 5;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
if (rhs.Comp_gt(16)) {
rhs = Decimal_adp_.int_(16);
}
else if (rhs.Comp_lt(-16)) {
rhs = Decimal_adp_.int_(-16);
}
Decimal_adp val = lhs.Round_old(rhs.To_int());
if (val.To_double() == 0) // NOTE: must explicitly check for zero, else "0.0" will be pushed onto stack; EXE: {{#expr: 0 round 1}}; DATE:2013-11-09
val_stack.Push(Decimal_adp_.Zero);
else
val_stack.Push(val);
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_sin extends Func_tkn_base {
public Func_tkn_sin(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Sin(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_sqrt extends Func_tkn_base {
public Func_tkn_sqrt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Sqrt());
return true;
}
}

View File

@@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_stack {
public void Clear() {stack_len = 0;}
public int Len() {return stack_len;}
public Func_tkn GetLast() {return stack_len == 0 ? null : stack[stack_len - 1];}
public Func_tkn Pop() {
int stack_len_new = stack_len - 1;
Func_tkn rv = stack[stack_len_new];
stack_len = stack_len_new;
return rv;
}
public void Push(Func_tkn v) {
int stack_len_new = stack_len + 1;
if (stack_len_new > stack_max) {
stack_max = stack_len_new * 2;
stack = (Func_tkn[])Array_.Resize(stack, stack_max);
}
stack[stack_len] = v;
stack_len = stack_len_new;
}
Func_tkn[] stack = new Func_tkn[0]; int stack_len = 0, stack_max = 0;
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_tan extends Func_tkn_base {
public Func_tkn_tan(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Tan(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_times extends Func_tkn_base {
public Func_tkn_times(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Multiply(rhs));
return true;
}
}

View File

@@ -0,0 +1,29 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Func_tkn_trunc extends Func_tkn_base {
public Func_tkn_trunc(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Trunc(val.To_double())));
return true;
}
}

View File

@@ -0,0 +1,28 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Num_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_number;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return String_.new_u8(val_ary);}
public Num_tkn(int val_int) {
this.val_int = val_int;
this.val_ary = new byte[] {Byte_.By_int(val_int + Byte_ascii.Num_0)};
} int val_int;
}

View File

@@ -0,0 +1,30 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Paren_bgn_tkn implements Expr_tkn, Func_tkn {
public int Tid() {return Expr_tkn_.Tid_paren_lhs;}
public boolean Func_is_const() {return false;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary = Bry_.new_u8(val_str);
public String Val_str() {return val_str;} static final String val_str = "(";
public int ArgCount() {return 0;}
public int Precedence() {return -1;}
public Func_tkn GetAlt() {return this;}
public boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {throw Err_.new_unimplemented();}
public static Paren_bgn_tkn Instance = new Paren_bgn_tkn(); Paren_bgn_tkn() {}
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Paren_end_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_paren_rhs;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary = Bry_.new_u8(val_str);
public String Val_str() {return val_str;} static final String val_str = ")";
public static Paren_end_tkn Instance = new Paren_end_tkn(); Paren_end_tkn() {}
}

View File

@@ -1,547 +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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
import gplx.xowa.parsers.*;
interface Expr_tkn {
int Tid();
byte[] Val_ary();
String Val_str();
}
class Expr_tkn_ {
public static final int Tid_operator = 1, Tid_paren_lhs = 5, Tid_paren_rhs = 6, Tid_space = 7, Tid_number = 8;
}
interface Func_tkn extends Expr_tkn {
boolean Func_is_const();
int ArgCount();
int Precedence();
Func_tkn GetAlt();
boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack);
}
class Ws_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_space;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return val_str;} private String val_str;
public Ws_tkn(byte b) {this.val_ary = new byte[] {b}; this.val_str = Char_.To_str(Char_.By_int(b));}
}
class Paren_bgn_tkn implements Expr_tkn, Func_tkn {
public int Tid() {return Expr_tkn_.Tid_paren_lhs;}
public boolean Func_is_const() {return false;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary = Bry_.new_u8(val_str);
public String Val_str() {return val_str;} static final String val_str = "(";
public int ArgCount() {return 0;}
public int Precedence() {return -1;}
public Func_tkn GetAlt() {return this;}
public boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {throw Err_.new_unimplemented();}
public static Paren_bgn_tkn Instance = new Paren_bgn_tkn(); Paren_bgn_tkn() {}
}
class Paren_end_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_paren_rhs;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary = Bry_.new_u8(val_str);
public String Val_str() {return val_str;} static final String val_str = ")";
public static Paren_end_tkn Instance = new Paren_end_tkn(); Paren_end_tkn() {}
}
class Num_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_number;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return String_.new_u8(val_ary);}
public Num_tkn(int val_int) {
this.val_int = val_int;
this.val_ary = new byte[] {Byte_.By_int(val_int + Byte_ascii.Num_0)};
} int val_int;
}
class Dot_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_number;}
public byte[] Val_ary() {return Val_Ary;} static final byte[] Val_Ary = new byte[] {Byte_ascii.Dot};
public String Val_str() {return String_.new_u8(Val_Ary);}
public Dot_tkn() {}
}
class Val_stack {
public void Clear() {stack_len = 0;}
public int Len() {return stack_len;}
public Decimal_adp Pop() {
int stack_len_new = stack_len - 1;
Decimal_adp rv = stack[stack_len_new];
stack_len = stack_len_new;
return rv;
}
public void Push(Decimal_adp v) {
int stack_len_new = stack_len + 1;
if (stack_len_new > stack_max) {
stack_max = stack_len_new * 2;
stack = (Decimal_adp[])Array_.Resize(stack, stack_max);
}
stack[stack_len] = v;
stack_len = stack_len_new;
}
Decimal_adp[] stack = new Decimal_adp[0]; int stack_len = 0, stack_max = 0;
}
class Func_tkn_stack {
public void Clear() {stack_len = 0;}
public int Len() {return stack_len;}
public Func_tkn GetLast() {return stack_len == 0 ? null : stack[stack_len - 1];}
public Func_tkn Pop() {
int stack_len_new = stack_len - 1;
Func_tkn rv = stack[stack_len_new];
stack_len = stack_len_new;
return rv;
}
public void Push(Func_tkn v) {
int stack_len_new = stack_len + 1;
if (stack_len_new > stack_max) {
stack_max = stack_len_new * 2;
stack = (Func_tkn[])Array_.Resize(stack, stack_max);
}
stack[stack_len] = v;
stack_len = stack_len_new;
}
Func_tkn[] stack = new Func_tkn[0]; int stack_len = 0, stack_max = 0;
}
abstract class Func_tkn_base implements Func_tkn {
public int Tid() {return Expr_tkn_.Tid_operator;}
public abstract int Precedence();
public abstract int ArgCount();
@gplx.Virtual public boolean Func_is_const() {return false;}
public void Ctor(String v) {val_ary = Bry_.new_u8(v);}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return String_.new_u8(Val_ary());}
@gplx.Virtual public Func_tkn GetAlt() {return this;}
public boolean Calc(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
if (val_stack.Len() < this.ArgCount()) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_missing_operand, Val_ary()); return false;}
return Calc_hook(ctx, shunter, val_stack);
}
public abstract boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack);
}
class Func_tkn_plus extends Func_tkn_base {
public Func_tkn_plus(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 6;}
@Override public Func_tkn GetAlt() {return Func_tkn_plus_positive.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Add(rhs));
return true;
}
public static final Func_tkn_plus Instance = new Func_tkn_plus(); Func_tkn_plus() {}
}
class Func_tkn_plus_positive extends Func_tkn_base {
Func_tkn_plus_positive(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 10;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {return true;}// effectively a noop
public static final Func_tkn_plus_positive Instance = new Func_tkn_plus_positive("+");
}
class Func_tkn_minus extends Func_tkn_base {
public Func_tkn_minus(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 6;}
@Override public Func_tkn GetAlt() {return Func_tkn_minus_negative.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Subtract(rhs));
return true;
}
}
class Func_tkn_minus_negative extends Func_tkn_base {
public Func_tkn_minus_negative(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 10;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Multiply(Decimal_adp_.Neg1));
return true;
}
public static final Func_tkn_minus_negative Instance = new Func_tkn_minus_negative("-");
}
class Func_tkn_divide extends Func_tkn_base {
public Func_tkn_divide(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
if (rhs.Eq(0)) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(lhs.Divide(rhs));
return true;
}
}
class Func_tkn_times extends Func_tkn_base {
public Func_tkn_times(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Multiply(rhs));
return true;
}
}
class Func_tkn_pow extends Func_tkn_base {
public Func_tkn_pow(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 8;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
int rhs_int = rhs.To_int();
if ((double)rhs_int == rhs.To_double()) // exponent is integer; use decimal pow which does less casts to double
val_stack.Push(lhs.Pow(rhs_int));
else {
double rslt = Math_.Pow(lhs.To_double(), rhs.To_double());
if (Double_.IsNaN(rslt)) {
shunter.Rslt_set(Double_.NaN_bry);
return false;
}
else
val_stack.Push(Decimal_adp_.double_thru_str_(rslt));
}
return true;
}
}
class Func_tkn_e_op extends Func_tkn_base {
public Func_tkn_e_op(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 9;} // NOTE: needs to be < than - sign
@Override public Func_tkn GetAlt() {return Func_tkn_e_const.Instance;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
int rhs_int = rhs.To_int();
if ( rhs_int > 308
|| (lhs.To_double() >= 1.8f && rhs_int == 308)) { // PHP:"maximum of ~1.8e308"; verified with {{#expr:1.8e308}} on sandbox; REF:http://php.net/manual/en/language.types.float.php; PAGE:en.w:Factorial; en.w:Astatine; DATE:2015-04-08; DATE:2015-04-21
shunter.Rslt_set(Double_.Inf_pos_bry);
return false;
}
double rhs_double = rhs.To_double();
if ((double)rhs_int == rhs_double) // exponent is integer; use pow_10 which does less casts to double
val_stack.Push(lhs.Multiply(Decimal_adp_.pow_10_(rhs_int)));
else
val_stack.Push(lhs.Multiply(Decimal_adp_.double_thru_str_(Math_.Pow(10d, rhs_double))));
return true;
}
}
class Func_tkn_mod extends Func_tkn_base {
public Func_tkn_mod(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
// must convert to int else issues with {{#expr:0.00999999mod10}} and {{USCensusPop|1960=763956|1970=756510}}; REF: http://php.net/manual/en/language.operators.arithmetic.php: "Operands of modulus are converted to integers (by stripping the decimal part) before processing"
// must convert to long else issues with (39052000900/1) mod 100 which should be 0, not 47; JAVA does not fail int conversion, and instead converts to Int_.Max_value; EX: de.w:Quijano_(Pi<50>lagos)
long rhs = ((Decimal_adp)val_stack.Pop()).To_long();
long lhs = ((Decimal_adp)val_stack.Pop()).To_long();
if (rhs == 0) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(Decimal_adp_.long_(lhs % rhs));
return true;
}
}
class Func_tkn_eq extends Func_tkn_base {
public Func_tkn_eq(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_neq extends Func_tkn_base {
public Func_tkn_neq(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Eq(rhs) ? Decimal_adp_.Zero : Decimal_adp_.One);
return true;
}
}
class Func_tkn_gt extends Func_tkn_base {
public Func_tkn_gt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_gt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_lt extends Func_tkn_base {
public Func_tkn_lt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_lt(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_gte extends Func_tkn_base {
public Func_tkn_gte(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_gte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_lte extends Func_tkn_base {
public Func_tkn_lte(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 4;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(lhs.Comp_lte(rhs) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_and extends Func_tkn_base {
public Func_tkn_and(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 3;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(!lhs.Eq(0) && !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_or extends Func_tkn_base {
public Func_tkn_or(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 2;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
val_stack.Push(!lhs.Eq(0) || !rhs.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_not extends Func_tkn_base {
public Func_tkn_not(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Eq(0) ? Decimal_adp_.One : Decimal_adp_.Zero);
return true;
}
}
class Func_tkn_e_const extends Func_tkn_base {
public Func_tkn_e_const(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 0;}
@Override public int Precedence() {return 0;}
@Override public boolean Func_is_const() {return true;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
val_stack.Push(Decimal_adp_.Const_e);
return true;
}
public static final Func_tkn_e_const Instance = new Func_tkn_e_const("e");
}
class Func_tkn_pi extends Func_tkn_base {
public Func_tkn_pi(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 0;}
@Override public int Precedence() {return 0;}
@Override public boolean Func_is_const() {return true;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
val_stack.Push(Decimal_adp_.Const_pi);
return true;
}
}
class Func_tkn_ceil extends Func_tkn_base {
public Func_tkn_ceil(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Ceil(val.To_double())));
return true;
}
}
class Func_tkn_trunc extends Func_tkn_base {
public Func_tkn_trunc(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Trunc(val.To_double())));
return true;
}
}
class Func_tkn_floor extends Func_tkn_base {
public Func_tkn_floor(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Floor(val.To_double())));
return true;
}
}
class Func_tkn_abs extends Func_tkn_base {
public Func_tkn_abs(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Abs());
return true;
}
}
class Func_tkn_exp extends Func_tkn_base {
public Func_tkn_exp(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Exp(val.To_double())));
return true;
}
}
class Func_tkn_ln extends Func_tkn_base {
public Func_tkn_ln(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lte(0)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument_ln); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Log(val.To_double())));
return true;
}
}
class Func_tkn_sin extends Func_tkn_base {
public Func_tkn_sin(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Sin(val.To_double())));
return true;
}
}
class Func_tkn_cos extends Func_tkn_base {
public Func_tkn_cos(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Cos(val.To_double())));
return true;
}
}
class Func_tkn_tan extends Func_tkn_base {
public Func_tkn_tan(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Tan(val.To_double())));
return true;
}
}
class Func_tkn_asin extends Func_tkn_base {
public Func_tkn_asin(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Asin(val.To_double())));
return true;
}
}
class Func_tkn_acos extends Func_tkn_base {
public Func_tkn_acos(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
if (val.Comp_lt(-1) || val.Comp_gt(1)) {shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_invalid_argument, this.Val_ary()); return false;}
val_stack.Push(Decimal_adp_.double_(Math_.Acos(val.To_double())));
return true;
}
}
class Func_tkn_atan extends Func_tkn_base {
public Func_tkn_atan(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(Decimal_adp_.double_(Math_.Atan(val.To_double())));
return true;
}
}
class Func_tkn_round extends Func_tkn_base {
public Func_tkn_round(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 5;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = val_stack.Pop();
Decimal_adp lhs = val_stack.Pop();
if (rhs.Comp_gt(16)) {
rhs = Decimal_adp_.int_(16);
}
else if (rhs.Comp_lt(-16)) {
rhs = Decimal_adp_.int_(-16);
}
Decimal_adp val = lhs.Round_old(rhs.To_int());
if (val.To_double() == 0) // NOTE: must explicitly check for zero, else "0.0" will be pushed onto stack; EXE: {{#expr: 0 round 1}}; DATE:2013-11-09
val_stack.Push(Decimal_adp_.Zero);
else
val_stack.Push(val);
return true;
}
}
class Func_tkn_fmod extends Func_tkn_base {
public Func_tkn_fmod(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 2;}
@Override public int Precedence() {return 7;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp rhs = (Decimal_adp)val_stack.Pop();
Decimal_adp lhs = (Decimal_adp)val_stack.Pop();
if (rhs.To_double() == 0) {
shunter.Err_set(ctx, Xol_msg_itm_.Id_pfunc_expr_division_by_zero);
return false;
}
val_stack.Push(lhs.Mod(rhs));
return true;
}
}
class Func_tkn_sqrt extends Func_tkn_base {
public Func_tkn_sqrt(String v) {this.Ctor(v);}
@Override public int ArgCount() {return 1;}
@Override public int Precedence() {return 9;}
@Override public boolean Calc_hook(Xop_ctx ctx, Pfunc_expr_shunter shunter, Val_stack val_stack) {
Decimal_adp val = val_stack.Pop();
val_stack.Push(val.Sqrt());
return true;
}
}

View File

@@ -0,0 +1,39 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Val_stack {
public void Clear() {stack_len = 0;}
public int Len() {return stack_len;}
public Decimal_adp Pop() {
int stack_len_new = stack_len - 1;
Decimal_adp rv = stack[stack_len_new];
stack_len = stack_len_new;
return rv;
}
public void Push(Decimal_adp v) {
int stack_len_new = stack_len + 1;
if (stack_len_new > stack_max) {
stack_max = stack_len_new * 2;
stack = (Decimal_adp[])Array_.Resize(stack, stack_max);
}
stack[stack_len] = v;
stack_len = stack_len_new;
}
Decimal_adp[] stack = new Decimal_adp[0]; int stack_len = 0, stack_max = 0;
}

View File

@@ -0,0 +1,25 @@
/*
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.xtns.pfuncs.exprs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.pfuncs.*;
import gplx.xowa.parsers.*;
class Ws_tkn implements Expr_tkn {
public int Tid() {return Expr_tkn_.Tid_space;}
public byte[] Val_ary() {return val_ary;} private byte[] val_ary;
public String Val_str() {return val_str;} private String val_str;
public Ws_tkn(byte b) {this.val_ary = new byte[] {b}; this.val_str = Char_.To_str(Char_.By_int(b));}
}

View File

@@ -57,7 +57,7 @@ public class Pfunc_anchorencode extends Pf_func_base { // EX: {{anchorencode:a b
case Xop_tkn_itm_.Tid_apos: break; // noop
case Xop_tkn_itm_.Tid_xnde: Xnde(src, (Xop_xnde_tkn)sub, tmp_bfr); break;
case Xop_tkn_itm_.Tid_html_ncr: tmp_bfr.Add_u8_int(((Xop_amp_tkn_num)sub).Val()); break;
case Xop_tkn_itm_.Tid_html_ref: tmp_bfr.Add_u8_int(((Xop_amp_tkn_txt)sub).Char_int()); break;
case Xop_tkn_itm_.Tid_html_ref: tmp_bfr.Add_u8_int(((Xop_amp_tkn_ent)sub).Char_int()); break;
case Xop_tkn_itm_.Tid_tmpl_invk:
Xot_invk_tkn invk_tkn = (Xot_invk_tkn)sub;
Arg_itm_tkn name_tkn = invk_tkn.Name_tkn().Key_tkn();

View File

@@ -41,7 +41,7 @@ class Wdata_fmtr__langtext_tbl implements gplx.core.brys.Bfr_arg {
if (list_len == 0) return;
fmtr.Bld_bfr_many(bfr, toc_data.Href(), toc_data.Text(), col_hdr_lang_name, col_hdr_lang_code, col_hdr_text, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), fmtr_row);
}
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
private final Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <div class='wikibase-sitelinkgroupview'>"
, " <div class='wikibase-sitelinkgroupview-heading-container'>"
@@ -69,7 +69,7 @@ class Wdata_fmtr__langtext_row_base implements gplx.core.brys.Bfr_arg, Wdata_fmt
row_fmtr.Bld_bfr_many(bfr, itm.Lang(), Gfh_utl.Escape_html_as_bry(lang_itm.Canonical_name()), Gfh_utl.Escape_html_as_bry(itm.Text()));
}
}
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-sitelinkview'>"
, " <span class='wikibase-sitelinkview-siteid-container'>"
@@ -115,8 +115,8 @@ class Wdata_fmtr__alias_row implements gplx.core.brys.Bfr_arg, Wdata_fmtr__langt
}
}
}
private static final byte[] lang_code_style_n = Bry_.new_a7("border:1px solid white;background:none;");
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
private static final byte[] lang_code_style_n = Bry_.new_a7("border:1px solid white;background:none;");
private final Bry_fmtr row_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( ""
, " <li class='wikibase-sitelinkview'>"
, " <span class='wikibase-sitelinkview-siteid-container' style='~{lang_code_style}>"

View File

@@ -60,20 +60,3 @@ class Wdata_fmtr__toc_itm implements gplx.core.brys.Bfr_arg {
, " </li>"
), "idx", "href", "text");
}
class Wdata_toc_data {
private final Wdata_fmtr__toc_div fmtr_toc;
private final Gfo_url_encoder href_encoder;
private final Bry_fmtr text_fmtr = Bry_fmtr.new_("~{orig} <sup><small>(~{len})</small></sup>", "orig", "len");
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(8);
public Wdata_toc_data(Wdata_fmtr__toc_div fmtr_toc, Gfo_url_encoder href_encoder) {this.fmtr_toc = fmtr_toc; this.href_encoder = href_encoder;}
public Wdata_toc_data Make(int itms_len) {
this.text = itms_len_enable ? text_fmtr.Bld_bry_many(tmp_bfr, orig, itms_len) : orig;
this.href = href_encoder.Encode(orig);
fmtr_toc.Add(this);
return this;
}
public Wdata_toc_data Itms_len_enable_n_() {itms_len_enable = false; return this;} private boolean itms_len_enable = true;
public byte[] Orig() {return orig;} public void Orig_(byte[] v) {orig = v;} private byte[] orig;
public byte[] Href() {return href;} private byte[] href;
public byte[] Text() {return text;} private byte[] text;
}

View File

@@ -0,0 +1,37 @@
/*
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.xtns.wdatas.hwtrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.htmls.encoders.*;
class Wdata_toc_data {
private final Wdata_fmtr__toc_div fmtr_toc;
private final Gfo_url_encoder href_encoder;
private final Bry_fmtr text_fmtr = Bry_fmtr.new_("~{orig} <sup><small>(~{len})</small></sup>", "orig", "len");
private final Bry_bfr tmp_bfr = Bry_bfr_.New_w_size(8);
public Wdata_toc_data(Wdata_fmtr__toc_div fmtr_toc, Gfo_url_encoder href_encoder) {this.fmtr_toc = fmtr_toc; this.href_encoder = href_encoder;}
public Wdata_toc_data Make(int itms_len) {
this.text = itms_len_enable ? text_fmtr.Bld_bry_many(tmp_bfr, orig, itms_len) : orig;
this.href = href_encoder.Encode(orig);
fmtr_toc.Add(this);
return this;
}
public Wdata_toc_data Itms_len_enable_n_() {itms_len_enable = false; return this;} private boolean itms_len_enable = true;
public byte[] Orig() {return orig;} public void Orig_(byte[] v) {orig = v;} private byte[] orig;
public byte[] Href() {return href;} private byte[] href;
public byte[] Text() {return text;} private byte[] text;
}