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

'v3.7.2.1'

This commit is contained in:
gnosygnu
2016-07-10 23:35:32 -04:00
parent f5f48bb9b1
commit b333db45f8
366 changed files with 4468 additions and 3460 deletions

View File

@@ -96,19 +96,20 @@ public class Pgbnr_func extends Pf_func_base {
itm.Init_from_wtxt(banner_ttl, banner_file_itm, tooltip, title, bottomtoc, toc, data_pos_x, data_pos_y, origin_x, icons_list == null ? Pgbnr_icon.Ary_empty : (Pgbnr_icon[])icons_list.To_ary_and_clear(Pgbnr_icon.class));
page.Html_data().Xtn_pgbnr_(itm);
page.Html_data().Head_mgr().Itm__pgbnr().Enabled_y_(); // register css / js during parse stage
page.Hdr_mgr().Toc_manual_(); // NOTE: must mark toc_manual else will show 2nd TOC in edit mode; DATE:2016-07-10
}
public static void Add_banner(Bry_bfr bfr, Xop_ctx ctx, Xoh_wtr_ctx hctx, byte[] src) {
public static void Add_banner(Bry_bfr bfr, Xoae_page wpg, Xop_ctx ctx, Xoh_wtr_ctx hctx, Pgbnr_itm itm) {
Xowe_wiki wiki = ctx.Wiki(); Xoae_app app = wiki.Appe();
Pgbnr_cfg cfg = wiki.Xtn_mgr().Xtn_pgbnr().Cfg(); if (!cfg.enabled) return;
Xoae_page page = ctx.Page(); Xoa_ttl ttl = page.Ttl();
Pgbnr_itm itm = page.Html_data().Xtn_pgbnr();
Xoa_ttl ttl = wpg.Ttl();
Xoa_ttl banner_ttl = null; byte[] banner_html = null;
if (itm != null) { // {{PAGEBANNER}} exists in wikitext
itm.Init_hdump(hctx.Mode_is_hdump());
banner_ttl = itm.banner_ttl;
banner_html = Get_banner_html(wiki, ctx, src, cfg, banner_ttl, itm);
banner_html = Get_banner_html(wiki, ctx, hctx, cfg, banner_ttl, itm);
if (banner_html == null) { // no banner; try again using title from wikidata; note that this should only happen if no banner_ttl or banner_ttl is invalid; EX:{{PAGEBANNER:|toc=yes}}
banner_ttl = Get_wikidata_banner(app, wiki, cfg, ttl);
banner_html = Get_banner_html(wiki, ctx, src, cfg, banner_ttl, itm);
banner_html = Get_banner_html(wiki, ctx, hctx, cfg, banner_ttl, itm);
}
}
else if ( ttl.Ns().Id_is_main() // {{PAGEBANNER}} missing, but wiki is marked as enable_default_banner
@@ -121,12 +122,13 @@ public class Pgbnr_func extends Pf_func_base {
Xof_file_itm banner_file_itm = File__make_tkn(ctx, Xop_file_logger_.Tid__pgbnr_main, banner_ttl, Xop_lnki_tkn.Width_null, Xop_lnki_tkn.Height_null);
itm = new Pgbnr_itm();
itm.Init_from_wtxt(banner_ttl, banner_file_itm, Bry_.Empty, Bry_.Empty, false, Bry_.Empty, 0, 0, Bry_.Empty, Pgbnr_icon.Ary_empty);
banner_html = Get_banner_html(wiki, ctx, src, cfg, banner_ttl, itm);
itm.Init_hdump(hctx.Mode_is_hdump());
banner_html = Get_banner_html(wiki, ctx, hctx, cfg, banner_ttl, itm);
}
if (banner_html != null)
bfr.Add(banner_html);
}
public static byte[] Get_banner_html(Xowe_wiki wiki, Xop_ctx ctx, byte[] src, Pgbnr_cfg cfg, Xoa_ttl banner_ttl, Pgbnr_itm itm) {
public static byte[] Get_banner_html(Xowe_wiki wiki, Xop_ctx ctx, Xoh_wtr_ctx hctx, Pgbnr_cfg cfg, Xoa_ttl banner_ttl, Pgbnr_itm itm) {
byte[][] urls = Get_standard_size_urls(wiki, cfg, banner_ttl); if (urls == null) return null;
Bry_bfr tmp_bfr = Bry_bfr_.New();
int urls_len = urls.length;
@@ -141,8 +143,16 @@ public class Pgbnr_func extends Pf_func_base {
int max_width = itm.banner_file_itm.Orig_w(); // $file = wfFindFile( banner_file ); $options['max_width'] = $file->getWidth();
byte[] banner_file = null; // $bannerfile->getLocalUrl();
wiki.Html_mgr().Toc_mgr().Html(ctx.Page(), gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, src, tmp_bfr, false);
byte[] toc_html = tmp_bfr.To_bry_and_clear();
byte[] toc_html = null;
if (hctx.Mode_is_hdump()) {
gplx.xowa.htmls.core.wkrs.tocs.Xoh_toc_wtr.Write_tag(tmp_bfr, true);
toc_html = tmp_bfr.To_bry_and_clear();
banner_file = Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, gplx.xowa.wikis.nss.Xow_ns_.Bry__file, Byte_ascii.Colon_bry, banner_ttl.Full_db());
}
else {
wiki.Html_mgr().Toc_mgr().Html(ctx.Page(), gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, tmp_bfr, true);
toc_html = tmp_bfr.To_bry_and_clear();
}
itm.Init_from_html(max_width, banner_file, banner_url, srcset, cfg.enable_heading_override, toc_html);
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(itm);

View File

@@ -17,19 +17,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
import gplx.xowa.htmls.core.htmls.*;
public class Pgbnr_func_tst {
private final Pgbnr_func_fxt fxt = new Pgbnr_func_fxt();
@Test public void Basic() {
fxt.Test__parse__eq("{{PAGEBANNER:A.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
fxt.Test__parse(Bool_.N, "{{PAGEBANNER:A.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " <h1 class='wpb-name'>Test page</h1>"
, " <a class='image' title='Test page' href=''><img id='xoimg_0' src='file:///mem/wiki/repo/trg/orig/7/0/A.png' srcset='' class='wpb-banner-image ' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <a href='' class='image' title='Test page' xowa_title='A.png'><img id='xoimg_0' class='wpb-banner-image ' alt='' src='file:///mem/wiki/repo/trg/orig/7/0/A.png' srcset='' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <div class='wpb-iconbox'>"
, " <a href='/wiki/Star_article'><span aria-disabled='false' title='Star article' class='oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-star oo-ui-iconElement oo-ui-iconWidget'></span></a>"
, " </div>"
, " </div>"
, " <div class='wpb-topbanner-toc '><div class='wpb-banner-toc'></div></div>"
, " <div class='wpb-topbanner-toc'><div class='wpb-banner-toc'></div></div>"
, "</div>"
));
}
@Test public void Hdump() {
fxt.Test__parse(Bool_.Y, "{{PAGEBANNER:A.png|icon-star=Star_article}}", String_.Concat_lines_nl_apos_skip_last
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " <h1 class='wpb-name'>Test page</h1>"
, " <a href='/wiki/File:A.png' class='image' title='Test page' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg=\"0|-1|-1|-1|-1|-1\" class='wpb-banner-image ' alt='' src='file:///mem/wiki/repo/trg/orig/7/0/A.png' srcset='' data-pos-x='0' data-pos-y='0' style='max-width:0px'></a>"
, " <div class='wpb-iconbox'>"
, " <a href='/wiki/Star_article'><span aria-disabled='false' title='Star article' class='oo-ui-widget oo-ui-widget-enabled oo-ui-iconElement-icon oo-ui-icon-star oo-ui-iconElement oo-ui-iconWidget'></span></a>"
, " </div>"
, " </div>"
, " <div class='wpb-topbanner-toc'><div class='wpb-banner-toc'><div class=\"xo-toc\" data-toc-mode=\"1\"></div></div></div>"
, "</div>"
));
}
@@ -41,9 +56,10 @@ class Pgbnr_func_fxt {
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "en.wikivoyage.org");
fxt = new Xop_fxt(app, wiki);
}
public void Test__parse__eq(String raw, String expd) {
public void Test__parse(boolean hdump, String raw, String expd) {
fxt.Exec_parse_page_all_as_str(raw);
Bfr_arg arg = fxt.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(fxt.Ctx(), fxt.Page(), null, null);
Xoh_wtr_ctx hctx = hdump ? Xoh_wtr_ctx.Hdump : Xoh_wtr_ctx.Basic;
Bfr_arg arg = fxt.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(fxt.Page(), fxt.Ctx(), hctx);
Bry_bfr bfr = Bry_bfr_.New();
arg.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());

View File

@@ -18,23 +18,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.xtns.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.mustaches.*; import gplx.xowa.parsers.lnkis.*;
import gplx.xowa.files.*;
import gplx.langs.htmls.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
public class Pgbnr_itm implements Mustache_doc_itm {
public Xoa_ttl banner_ttl;
public byte[] banner_img_src;
private int html_uid;
public byte[] toc;
public Xof_file_itm banner_file_itm;
private byte[] banner_anch_title, banner_hdr_text, originx, banner_anch_href, srcset;
private double data_pos_x, data_pos_y;
private int maxWidth;
private boolean bottomtoc, isHeadingOverrideEnabled;
private byte[] file_ttl;
private Pgbnr_icon[] icons;
public void Init_from_wtxt(Xoa_ttl banner_ttl, Xof_file_itm banner_file_itm, byte[] banner_anch_title, byte[] banner_hdr_text, boolean bottomtoc, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons) {
private byte[] img_id_atr, img_xottl_atr, img_xoimg_atr;
public void Init_from_wtxt(Xoa_ttl banner_ttl, Xof_file_itm banner_file_itm, byte[] banner_anch_title, byte[] banner_hdr_text, boolean bottomtoc
, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons) {
this.banner_ttl = banner_ttl; this.banner_file_itm = banner_file_itm;
this.banner_anch_title = banner_anch_title; this.banner_hdr_text = banner_hdr_text; this.bottomtoc = bottomtoc; this.toc = toc; this.icons = icons;
this.data_pos_x = data_pos_x; this.data_pos_y = data_pos_y; this.originx = originx;
this.html_uid = banner_file_itm.Html_uid();
this.banner_img_src = banner_file_itm.Html_view_url().To_http_file_bry();
this.file_ttl = banner_file_itm.Orig_ttl();
}
public void Init_from_html(int maxWidth, byte[] banner_anch_href, byte[] banner_img_src, byte[] srcset, boolean isHeadingOverrideEnabled, byte[] toc) {
this.maxWidth = maxWidth;
@@ -44,18 +47,33 @@ public class Pgbnr_itm implements Mustache_doc_itm {
this.isHeadingOverrideEnabled = isHeadingOverrideEnabled;
this.toc = toc;
}
public void Init_hdump(boolean mode_is_hdump) {
Bry_bfr tmp_bfr = Bry_bfr_.New();
if (mode_is_hdump) {
this.img_id_atr = Bry_.Empty;
this.img_xottl_atr = Gfh_atr_.Add_to_bry(tmp_bfr, Xoh_img_xoimg_data.Bry__data_xowa_title, file_ttl);
this.img_xoimg_atr = Gfh_atr_.Add_to_bry(tmp_bfr, Xoh_img_xoimg_data.Bry__data_xowa_image, Xoh_img_xoimg_data.Bry__data_xowa_image__full);
}
else {
this.img_id_atr = tmp_bfr.Add(Bry__anch_atr_id).Add_int_variable(banner_file_itm.Html_uid()).Add_byte_quote().To_bry_and_clear();
this.img_xottl_atr = this.img_xoimg_atr = Bry_.Empty;
}
}
public boolean Mustache__write(String key, Mustache_bfr bfr) {
if (String_.Eq(key, "title")) bfr.Add_bry(banner_hdr_text);
else if (String_.Eq(key, "tooltip")) bfr.Add_bry(banner_anch_title);
else if (String_.Eq(key, "bannerfile")) bfr.Add_bry(banner_anch_href);
else if (String_.Eq(key, "banner")) bfr.Add_bry(banner_img_src);
else if (String_.Eq(key, "html_uid")) bfr.Add_bry(Bry_.new_u8(gplx.xowa.htmls.Xoh_img_mgr.Str__html_uid + Int_.To_str(html_uid)));
else if (String_.Eq(key, "srcset")) bfr.Add_bry(srcset == null ? Bry_.Empty : Bry_.Empty);
else if (String_.Eq(key, "originx")) bfr.Add_bry(originx);
else if (String_.Eq(key, "data-pos-x")) bfr.Add_double(data_pos_x);
else if (String_.Eq(key, "data-pos-y")) bfr.Add_double(data_pos_y);
else if (String_.Eq(key, "maxWidth")) bfr.Add_int(maxWidth);
else if (String_.Eq(key, "toc")) bfr.Add_bry(toc);
else if (String_.Eq(key, "img_id_atr")) bfr.Add_bry(img_id_atr);
else if (String_.Eq(key, "img_xottl")) bfr.Add_bry(img_xottl_atr);
else if (String_.Eq(key, "img_xoimg")) bfr.Add_bry(img_xoimg_atr);
else if (String_.Eq(key, "file_ttl")) bfr.Add_bry(file_ttl);
else return false;
return true;
}
@@ -66,4 +84,5 @@ public class Pgbnr_itm implements Mustache_doc_itm {
else if (String_.Eq(key, "isHeadingOverrideEnabled")) return Mustache_doc_itm_.Ary__bool(isHeadingOverrideEnabled);
return Mustache_doc_itm_.Ary__empty;
}
private static final byte[] Bry__anch_atr_id = Bry_.new_a7(" id=\"xoimg_");
}

View File

@@ -74,20 +74,20 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
Mustache_tkn_parser parser = new Mustache_tkn_parser();
template_root = parser.Parse(template_data, 0, template_data.length);
}
public Bfr_arg Write_html(Xop_ctx pctx, Xoae_page page, Xoh_wtr_ctx hctx, byte[] src) {
this.pctx = pctx; this.page = page; this.hctx = hctx; this.src = src;
public Bfr_arg Write_html(Xoae_page wpg, Xop_ctx pctx, Xoh_wtr_ctx hctx) {
this.wpg = wpg; this.pctx = pctx; this.hctx = hctx;
return this;
} private Xop_ctx pctx; private Xoae_page page; private Xoh_wtr_ctx hctx; private byte[] src;
} private Xoae_page wpg; private Xop_ctx pctx; private Xoh_wtr_ctx hctx;
public void Bfr_arg__add(Bry_bfr bfr) {
Pgbnr_itm itm = page.Html_data().Xtn_pgbnr();
if (itm == null) return;
Pgbnr_func.Add_banner(bfr, pctx, hctx, src);
Pgbnr_itm itm = wpg.Html_data().Xtn_pgbnr(); if (itm == null) return;
Pgbnr_func.Add_banner(bfr, wpg, pctx, hctx, itm);
}
public static final byte[] Bry__cls__wpb_banner_image = Bry_.new_a7("wpb-banner-image");
private static final byte[] Template_dflt = Bry_.New_u8_nl_apos
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
, " <div class='wpb-topbanner'>"
, " {{#isHeadingOverrideEnabled}}<h1 class='wpb-name'>{{title}}</h1>{{/isHeadingOverrideEnabled}}"
, " <a class='image' title='{{tooltip}}' href='{{bannerfile}}'><img id='{{html_uid}}' src='{{banner}}' srcset='{{srcset}}' class='wpb-banner-image {{originx}}' data-pos-x='{{data-pos-x}}' data-pos-y='{{data-pos-y}}' style='max-width:{{maxWidth}}px'></a>"
, " <a href='{{bannerfile}}' class='image' title='{{tooltip}}' xowa_title='{{file_ttl}}'><img{{{img_id_atr}}}{{{img_xottl}}}{{{img_xoimg}}} class='wpb-banner-image {{originx}}' alt='' src='{{banner}}' srcset='{{srcset}}' data-pos-x='{{data-pos-x}}' data-pos-y='{{data-pos-y}}' style='max-width:{{maxWidth}}px'></a>"
, " {{#hasIcons}}"
, " <div class='wpb-iconbox'>"
, " {{#icons}}"
@@ -96,7 +96,7 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
, " </div>"
, " {{/hasIcons}}"
, " </div>"
, " <div class='wpb-topbanner-toc {{#bottomtoc}}wpb-bottomtoc{{/bottomtoc}}'><div class='wpb-banner-toc'>{{{toc}}}</div></div>"
, " <div class='wpb-topbanner-toc{{#bottomtoc}} wpb-bottomtoc{{/bottomtoc}}'><div class='wpb-banner-toc'>{{{toc}}}</div></div>"
, "</div>"
);
}