mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.1.1
This commit is contained in:
@@ -20,20 +20,20 @@ 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 extends gplx.core.brys.Bfr_arg_base implements Gallery_box_w_fmtr_arg {
|
||||
class Gallery_box_w_fmtr_arg__basic implements gplx.core.brys.Bfr_arg, Gallery_box_w_fmtr_arg {
|
||||
private int width;
|
||||
public Gallery_box_w_fmtr_arg Init(int uid, int width) {this.width = width; return this;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
bfr.Add(Style_bgn);
|
||||
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_base, Gallery_box_w_fmtr_arg {
|
||||
// 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 override void Bfr_arg__add(Bry_bfr bfr) {
|
||||
// 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();
|
||||
@@ -42,20 +42,20 @@ class Gallery_box_w_fmtr_arg__basic extends gplx.core.brys.Bfr_arg_base implemen
|
||||
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 extends gplx.core.brys.Bfr_arg_base implements Gallery_img_pad_fmtr_arg {
|
||||
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;}
|
||||
@Override public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
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_base, Gallery_img_pad_fmtr_arg {
|
||||
// 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 override void Bfr_arg__add(Bry_bfr bfr) {
|
||||
// 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();
|
||||
|
||||
@@ -117,60 +117,10 @@ public class Gallery_html_wtr {
|
||||
);
|
||||
}
|
||||
}
|
||||
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_.Mgr_all_fmtr.Bld_bfr_many(bfr, mgr_elem_id, mgr_box_cls, Bfr_arg_.New_bry_fmtr(mgr_box_style, Bfr_arg_.New_int(mgr_box_width_max)), itm_bfr);
|
||||
}
|
||||
}
|
||||
class Gallery_html_wtr_ {
|
||||
public static final byte[] Cls_packed = Bry_.new_a7(" mw-gallery-packed");
|
||||
public static final Bry_fmtr
|
||||
Mgr_all_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"xowa_gallery_ul_~{gallery_id}\" class=\"gallery~{gallery_cls}\" style=\"~{gallery_style}\">~{itm_list}"
|
||||
, "</ul>"
|
||||
), "gallery_id", "gallery_cls", "gallery_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=\"xowa_file_img_~{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 byte[] Bld_caption(Xowe_wiki wiki, Xop_ctx ctx, Xoh_html_wtr wtr, Xoh_wtr_ctx hctx, Gallery_itm itm) {
|
||||
byte[] rv = itm.Caption_bry();
|
||||
if (Bry_.Len_gt_0(rv)) {
|
||||
Bry_bfr caption_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Xop_root_tkn caption_root = itm.Caption_tkn();
|
||||
wtr.Write_tkn(caption_bfr, ctx, hctx, caption_root.Root_src(), caption_root, Xoh_html_wtr.Sub_idx_null, caption_root);
|
||||
rv = caption_bfr.To_bry_and_rls();
|
||||
}
|
||||
return rv;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
90
400_xowa/src/gplx/xowa/xtns/gallery/Gallery_html_wtr_.java
Normal file
90
400_xowa/src/gplx/xowa/xtns/gallery/Gallery_html_wtr_.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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.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
|
||||
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}>"
|
||||
+ "\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")
|
||||
, 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[]
|
||||
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=\"");
|
||||
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) {
|
||||
byte[] rv = itm.Caption_bry();
|
||||
if (Bry_.Len_gt_0(rv)) {
|
||||
Bry_bfr caption_bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Xop_root_tkn caption_root = itm.Caption_tkn();
|
||||
wtr.Write_tkn(caption_bfr, ctx, hctx, caption_root.Root_src(), caption_root, Xoh_html_wtr.Sub_idx_null, caption_root);
|
||||
rv = caption_bfr.To_bry_and_rls();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -54,16 +54,16 @@ public class Gallery_itm_parser_tst {
|
||||
@Test public void Caption_complicated() {
|
||||
fxt.Test_parse("File:A.png|alt=a|b[[c|d]]e ", fxt.Expd("File:A.png", "b[[c|d]]e", "a"));
|
||||
}
|
||||
@Test public void Alt_magic_word_has_arg() { // PURPOSE: img_alt magic_word is of form "alt=$1"; make sure =$1 is stripped for purpose of parser; DATE:2013-09-12
|
||||
fxt.Init_kwd_set(Xol_kwd_grp_.Id_img_alt, "alt=$1");
|
||||
fxt.Test_parse("File:A.png|alt=a|b", fxt.Expd("File:A.png", "b", "a"));
|
||||
}
|
||||
@Test public void Link_null() { // PURPOSE: null link causes page to fail; EX: ru.w:Гянджа; <gallery>Datei:A.png|link= |</gallery>; DATE:2014-04-11
|
||||
fxt.Test_parse("File:A.png|link = |b", fxt.Expd("File:A.png", "b", null, null));
|
||||
}
|
||||
@Test public void Caption_empty() { // PURPOSE: check that empty ws doesn't break caption (based on Link_null); DATE:2014-04-11
|
||||
fxt.Test_parse("File:A.png| | | ", fxt.Expd("File:A.png", null, null, null));
|
||||
}
|
||||
@Test public void Alt__magic_word_has_arg() { // PURPOSE: img_alt magic_word is of form "alt=$1"; make sure =$1 is stripped for purpose of parser; DATE:2013-09-12
|
||||
fxt.Init_kwd_set(Xol_kwd_grp_.Id_img_alt, "alt=$1");
|
||||
fxt.Test_parse("File:A.png|alt=a|b", fxt.Expd("File:A.png", "b", "a"));
|
||||
}
|
||||
}
|
||||
class Gallery_itm_parser_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki;
|
||||
|
||||
@@ -62,14 +62,14 @@ public abstract class Gallery_mgr_base {
|
||||
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, box_style_max_width_fmtr, box_style, max_width);
|
||||
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, box_cls_fmtr, xnde.Atr_cls(), this.Tid_bry());
|
||||
byte[] gallery_ul_id = tmp_bfr.Add(box_id_prefix_bry).Add_int_variable(gallery_uid).To_bry_and_clear();
|
||||
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)) box_caption_fmtr.Bld_bfr_many(bfr, box_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();
|
||||
@@ -78,7 +78,7 @@ public abstract class Gallery_mgr_base {
|
||||
}
|
||||
bfr.Add(box_html_end_bry);
|
||||
tmp_bfr.Mkr_rls();
|
||||
} private static final byte[] box_id_prefix_bry = Bry_.new_a7("xowa_gallery_ul_"), itm_id_prefix_bry = Bry_.new_a7("xowa_gallery_li_");
|
||||
}
|
||||
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);
|
||||
@@ -94,7 +94,8 @@ public abstract class Gallery_mgr_base {
|
||||
xfer_itm.Html_elem_tid_(Xof_html_elem.Tid_gallery_v2);
|
||||
}
|
||||
int img_uid = xfer_itm.Html_uid();
|
||||
byte[] gallery_li_id = tmp_bfr.Add(itm_id_prefix_bry).Add_int_variable(img_uid).To_bry_and_clear();
|
||||
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();
|
||||
@@ -107,8 +108,8 @@ public abstract class Gallery_mgr_base {
|
||||
|| !file_found
|
||||
)
|
||||
) { // itm is not a file, or is not found; write text
|
||||
itm_html = itm_missing_fmtr.Bld_bry_many(tmp_bfr, this.Get_thumb_padding() + itm_default_h, ttl.Page_txt());
|
||||
itm.Html_prepare(wiki, ctx, src, xnde, xfer_itm, gallery_li_id, i);
|
||||
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
|
||||
@@ -116,8 +117,8 @@ public abstract class Gallery_mgr_base {
|
||||
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()
|
||||
: Xoh_html_wtr_escaper.Escape(app.Parser_amp_mgr(), tmp_bfr, Bry_.Mid(src, itm.Alt_bgn(), itm.Alt_end()))
|
||||
;
|
||||
: 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()))
|
||||
@@ -128,11 +129,11 @@ public abstract class Gallery_mgr_base {
|
||||
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);
|
||||
itm_div0_fmtr.Bld_bfr_many(tmp_bfr, img_div_w);
|
||||
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);
|
||||
itm_div1_fmtr.Bld_bfr_many(tmp_bfr, vpad_fmtr.Init(img_uid, vpad)); // <div style="margin:~{vpad}px auto;">
|
||||
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();
|
||||
@@ -148,7 +149,7 @@ public abstract class Gallery_mgr_base {
|
||||
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;
|
||||
itm_li_bgn_fmtr.Bld_bfr_many(bfr, gallery_li_id, box_w_fmtr_arg.Init(img_uid, itm_div_width));
|
||||
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();
|
||||
@@ -167,19 +168,6 @@ public abstract class Gallery_mgr_base {
|
||||
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.
|
||||
public static final Bry_fmtr
|
||||
box_style_max_width_fmtr = Bry_fmtr.new_( "max-width:~{max_width}px;_width:~{max_width}px;", "max_width") // id=xowa_gallery_ul_1
|
||||
, box_cls_fmtr = Bry_fmtr.new_( "gallery mw-gallery-~{mode}", "mode")
|
||||
, box_caption_fmtr = Bry_fmtr.new_( "\n <li class='gallerycaption'>~{caption}</li>", "caption")
|
||||
, itm_li_bgn_fmtr = Bry_fmtr.new_( "\n <li id=\"~{id}\" class=\"gallerybox\" ~{itm_box_w}>" // id=xowa_gallery_li_1
|
||||
+ "\n <div ~{itm_box_w}>", "id", "itm_box_w")
|
||||
, itm_div0_fmtr = Bry_fmtr.new_( "\n <div class=\"thumb\" style=\"width: ~{width}px;\">", "width")
|
||||
, itm_missing_fmtr = 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")
|
||||
, hdump_box_w_fmtr = Bry_fmtr.new_( "width:~{width}px;", "width")
|
||||
, hdump_img_pad_fmtr = Bry_fmtr.new_( "margin:~{width}px auto;", "width")
|
||||
;
|
||||
|
||||
private static final byte[]
|
||||
itm_li_end_bry = Bry_.new_a7 ( "\n </div>"
|
||||
+ "\n </li>")
|
||||
@@ -195,9 +183,10 @@ public abstract class Gallery_mgr_base {
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
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(Html_tag_.Bry__ul);
|
||||
Html_wtr.Write_atr_bry(bfr, Html_atr_.Bry__id, gallery_ul_uid);
|
||||
Html_wtr.Write_atr_bry(bfr, Html_atr_.Bry__class, cls);
|
||||
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);
|
||||
// if (hctx_is_hdump) {
|
||||
// bfr.Add_byte_space();
|
||||
// bfr.Add(Xoh_make_trie_.Bry__gallery_box_max);
|
||||
@@ -205,7 +194,7 @@ public abstract class Gallery_mgr_base {
|
||||
// bfr.Add_byte_apos();
|
||||
// }
|
||||
// else
|
||||
Html_wtr.Write_atr_bry(bfr, Html_atr_.Bry__style, style);
|
||||
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++) {
|
||||
@@ -213,7 +202,7 @@ public abstract class Gallery_mgr_base {
|
||||
if (!whitelist_mgr.Chk(Xop_xnde_tag_.Tid_ul, src, xatr)) continue;
|
||||
byte[] key = xatr.Key_bry();
|
||||
byte[] val = xatr.Val_as_bry();
|
||||
Html_wtr.Write_atr_bry(bfr, key, val);
|
||||
Gfh_wtr.Write_atr_bry(bfr, key, val);
|
||||
}
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Gt);
|
||||
|
||||
@@ -17,11 +17,21 @@ 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.*;
|
||||
class Gallery_mgr_base_ {
|
||||
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 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 Gallery_mgr_base New_by_mode(byte mode) {
|
||||
switch (mode) {
|
||||
default:
|
||||
@@ -54,7 +64,7 @@ class Gallery_mgr_base_ {
|
||||
, Packed_hover_bry = Bry_.new_a7("packed-hover")
|
||||
, Packed_overlay_bry = Bry_.new_a7("packed-overlay")
|
||||
;
|
||||
private static final Hash_adp_bry Hash = Hash_adp_bry.ci_a7()
|
||||
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)
|
||||
|
||||
@@ -29,11 +29,11 @@ public class Gallery_mgr_base_basic_tst {
|
||||
, "</gallery>"
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\">"
|
||||
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width: 235px\">"
|
||||
, " <div style=\"width: 235px\">"
|
||||
, " <div class=\"thumb\" style=\"width: 230px;\">"
|
||||
, " <li id=\"xowa_gallery_li_0\" class=\"gallerybox\" style=\"width:235px;\">"
|
||||
, " <div style=\"width:235px;\">"
|
||||
, " <div class=\"thumb\" style=\"width:230px;\">"
|
||||
, " <div style=\"margin:15px auto;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/200px.png\" width=\"200\" height=\"300\" /></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class=\"gallerytext\"><p><i>a1</i>"
|
||||
@@ -42,11 +42,11 @@ public class Gallery_mgr_base_basic_tst {
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width: 235px\">"
|
||||
, " <div style=\"width: 235px\">"
|
||||
, " <div class=\"thumb\" style=\"width: 230px;\">"
|
||||
, " <li id=\"xowa_gallery_li_1\" class=\"gallerybox\" style=\"width:235px;\">"
|
||||
, " <div style=\"width:235px;\">"
|
||||
, " <div class=\"thumb\" style=\"width:230px;\">"
|
||||
, " <div style=\"margin:15px auto;\">"
|
||||
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xowa_file_img_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
|
||||
, " <a href=\"/wiki/File:B.png\" class=\"image\" xowa_title=\"B.png\"><img id=\"xoimg_1\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/5/7/B.png/200px.png\" width=\"200\" height=\"300\" /></a>"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, " <div class=\"gallerytext\"><p><i>b1</i>"
|
||||
@@ -67,7 +67,7 @@ public class Gallery_mgr_base_basic_tst {
|
||||
fxt.Test_html_frag("<gallery>File:A.png|a{{test_tmpl}}c</gallery>", "<div class=\"gallerytext\"><p>abc\n</p>");
|
||||
}
|
||||
@Test public void Itm_defaults_to_120() {
|
||||
fxt.Test_html_frag("<gallery>File:A.png|a</gallery>", "<img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />");
|
||||
fxt.Test_html_frag("<gallery>File:A.png|a</gallery>", "<img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />");
|
||||
}
|
||||
@Test public void Height_fix() {
|
||||
fxt.Fxt().Wiki().File_mgr().Cfg_set(Xof_fsdb_mgr_cfg.Grp_xowa, Xof_fsdb_mgr_cfg.Key_gallery_fix_defaults, "y");
|
||||
@@ -76,7 +76,7 @@ public class Gallery_mgr_base_basic_tst {
|
||||
}
|
||||
@Test public void Alt() {
|
||||
fxt.Test_html_frag("<gallery>File:A.png|b|alt=c</gallery>"
|
||||
, "<img id=\"xowa_file_img_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
|
||||
, "<img id=\"xoimg_0\" alt=\"c\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"
|
||||
, "<div class=\"gallerytext\"><p>b\n</p>"
|
||||
);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class Gallery_mgr_base_basic_tst {
|
||||
fxt.Test_html_frag("<gallery>File:A.png</gallery>", "<div class=\"gallerytext\">\n");
|
||||
}
|
||||
@Test public void Ttl_has_no_ns() { // PURPOSE: MW allows ttl to not have ns; DATE: 2013-11-18
|
||||
fxt.Test_html_frag("<gallery>A.png|b</gallery>", "<img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"); // make sure image is generated
|
||||
fxt.Test_html_frag("<gallery>A.png|b</gallery>", "<img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/120px.png\" width=\"120\" height=\"120\" />"); // make sure image is generated
|
||||
}
|
||||
@Test public void Ref() { // PURPOSE: <ref> inside <gallery> was not showing up in <references>; DATE:2013-10-09
|
||||
fxt.Test_html_frag("<gallery>File:A.png|<ref name='a'>b</ref></gallery><references/>"
|
||||
@@ -125,7 +125,7 @@ public class Gallery_mgr_base_basic_tst {
|
||||
}
|
||||
@Test public void Missing() {
|
||||
fxt.Init_files_missing_y_();
|
||||
fxt.Test_html_frag("<gallery>File:A.png|b</gallery>", "<div class=\"thumb\" style=\"height: 150px;\">A.png</div>");
|
||||
fxt.Test_html_frag("<gallery>File:A.png|b</gallery>", "<div class=\"thumb\" style=\"height:150px;\">A.png</div>");
|
||||
}
|
||||
@Test public void Multiple() { // PURPOSE.bug: multiple galleries should not use same gallery super; DATE:2014-04-13
|
||||
fxt.Test_html_frag("<gallery>File:A.png|a</gallery><gallery widths=180px>File:B.png|b</gallery>"
|
||||
@@ -148,6 +148,9 @@ public class Gallery_mgr_base_basic_tst {
|
||||
), "C1" // make sure that image after nested gallery appears
|
||||
);
|
||||
}
|
||||
@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"b.png\""); // NOTE: not 'alt="A"b.png"'
|
||||
}
|
||||
// @Test public void Ttl_caption() { // TODO: category entries get rendered with name only (no ns)
|
||||
// fxt.Test_html_frag
|
||||
// ( "<gallery>Category:A</gallery>"
|
||||
@@ -160,7 +163,7 @@ class Gallery_mgr_base_fxt {
|
||||
fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());
|
||||
Gallery_mgr_base.File_found_mode = Bool_.Y_byte;
|
||||
}
|
||||
public Xop_fxt Fxt() {return fxt;} private Xop_fxt fxt = new Xop_fxt();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Gallery_mgr_base_xnde_atrs_tst {
|
||||
@Test public void Atr_style() { // PURPOSE: combine style with itms_per_row
|
||||
fxt.Test_html_frag
|
||||
( "<gallery perrow=2 style='color:blue;'>File:A.png</gallery>"
|
||||
, "<ul id=\"xowa_gallery_ul_0\" class=\"gallery mw-gallery-traditional\" style=\"max-width:326px;_width:326px; color:blue;\">"
|
||||
, "<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
|
||||
|
||||
@@ -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.core.tests.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.wikis.ttls.*;
|
||||
public class Gallery_xnde_tst {
|
||||
private Xop_fxt fxt = new Xop_fxt(); String raw_src;
|
||||
private final Xop_fxt fxt = new Xop_fxt(); String raw_src;
|
||||
@Before public void init() {fxt.Reset(); fxt.Wiki().Xtn_mgr().Init_by_wiki(fxt.Wiki());}
|
||||
@Test public void Lnki_no_caption() {
|
||||
fxt.Test_parse_page_wiki("<gallery>File:A.png</gallery>"
|
||||
|
||||
Reference in New Issue
Block a user