mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.7.3.1'
This commit is contained in:
@@ -18,7 +18,8 @@ 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.core.btries.*; import gplx.langs.mustaches.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.langs.kwds.*; import gplx.xowa.parsers.utils.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.files.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.encoders.*;
|
||||
public class Pgbnr_func extends Pf_func_base {
|
||||
@Override public int Id() {return Xol_kwd_grp_.Id_pagebanner;}
|
||||
@Override public Pf_func New(int id, byte[] name) {return new Pgbnr_func().Name_(name);}
|
||||
@@ -85,18 +86,24 @@ public class Pgbnr_func extends Pf_func_base {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", page.Url_bry_safe(), key, val);
|
||||
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", page.Ttl().Full_db(), key, val);
|
||||
}
|
||||
|
||||
byte[] banner_name = Eval_argx(ctx, src, caller, self);
|
||||
Xoa_ttl banner_ttl = wiki.Ttl_parse(banner_name); // NOTE: MW also creates title to auto-register page and image in imagelinks
|
||||
if (banner_ttl == null) // if ttl is invalid, get it from wikidata; PAGE:en.v:Diving_the_Cape_Peninsula_and_False_Bay/Whale_Rock; DATE:2016-07-12
|
||||
banner_ttl = Get_wikidata_banner(wiki.Appe(), wiki, wiki.Xtn_mgr().Xtn_pgbnr().Cfg(), page.Ttl());
|
||||
if (banner_ttl == null) { // if ttl is still invalid, exit now else will fail with nullref below; PAGE:en.v:Peterborough (New Hampshire); DATE:2016-07-12
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "banner file is invalid; page=~{0} banner=~{1}", page.Url_bry_safe(), banner_name);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
|
||||
Pgbnr_itm itm = new Pgbnr_itm();
|
||||
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
|
||||
page.Wtxt().Toc().Flag__toc_y_(); // 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, Xoae_page wpg, Xop_ctx ctx, Xoh_wtr_ctx hctx, Pgbnr_itm itm) {
|
||||
Xowe_wiki wiki = ctx.Wiki(); Xoae_app app = wiki.Appe();
|
||||
@@ -147,10 +154,11 @@ public class Pgbnr_func extends Pf_func_base {
|
||||
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());
|
||||
banner_file = Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, gplx.xowa.wikis.nss.Xow_ns_.Bry__file, Byte_ascii.Colon_bry
|
||||
, Gfo_url_encoder_.Href.Encode(banner_ttl.Full_db())); // NOTE: must encode so "'" becomes "%27", not "'"; PAGE:en.v:'s-Hertogenbosch; DATE:2016-07-12
|
||||
}
|
||||
else {
|
||||
wiki.Html_mgr().Toc_mgr().Html(ctx.Page(), gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic, tmp_bfr, true);
|
||||
ctx.Page().Html_data().Toc_mgr().To_html(tmp_bfr, Xoh_wtr_ctx.Basic, 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);
|
||||
|
||||
@@ -25,21 +25,40 @@ public class Pgbnr_func_tst {
|
||||
( "<div class='ext-wpb-pagebanner noprint pre-content'>"
|
||||
, " <div class='wpb-topbanner'>"
|
||||
, " <h1 class='wpb-name'>Test page</h1>"
|
||||
, " <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>"
|
||||
, " <a href='' class='image' title='Test page' xowa_title='A.png'><img id='xoimg_0' src='file:///mem/wiki/repo/trg/orig/7/0/A.png' width='0' height='0' class='wpb-banner-image ' alt='' 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 id=\"toctitle\">"
|
||||
, " <h2>Contents</h2>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, "</div></div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Hdump() {
|
||||
@Test public void Hdump__basic() {
|
||||
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>"
|
||||
, " <a href='/wiki/File:A.png' class='image' title='Test page' xowa_title='A.png'><img data-xowa-title=\"A.png\" data-xoimg=\"1|-1|-1|-1|-1|-1\" src='file:///mem/wiki/repo/trg/orig/7/0/A.png' width='0' height='0' class='wpb-banner-image ' alt='' 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>"
|
||||
));
|
||||
}
|
||||
@Test public void Hdump__quote() { // PAGE:en.v:Europe; DATE:2016-07-12
|
||||
fxt.Test__parse(Bool_.Y, "{{PAGEBANNER:A\"b.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%22b.png' class='image' title='Test page' xowa_title='A%22b.png'><img data-xowa-title=\"A%22b.png\" data-xoimg=\"1|-1|-1|-1|-1|-1\" src='file:///mem/wiki/repo/trg/orig/d/4/A%22b.png' width='0' height='0' class='wpb-banner-image ' alt='' 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>"
|
||||
|
||||
@@ -18,7 +18,7 @@ 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.*;
|
||||
import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.langs.htmls.encoders.*;
|
||||
public class Pgbnr_itm implements Mustache_doc_itm {
|
||||
public Xoa_ttl banner_ttl;
|
||||
public byte[] banner_img_src;
|
||||
@@ -26,21 +26,49 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
||||
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 int max_width;
|
||||
private boolean bottomtoc, isHeadingOverrideEnabled;
|
||||
private byte[] file_ttl;
|
||||
private Pgbnr_icon[] icons;
|
||||
private byte[] img_id_atr, img_xottl_atr, img_xoimg_atr;
|
||||
|
||||
// NOTE: used by hdump
|
||||
public boolean Exists() {return exists;} private boolean exists;
|
||||
public byte[] Srcset() {return srcset;}
|
||||
public byte[] Style_if_not_dflt() {return Bry_.Eq(style, Atr_val__style_dflt) ? Bry_.Empty : style;}
|
||||
public byte[] Style() {return style;} private byte[] style;
|
||||
public double Data_pos_x() {return data_pos_x;}
|
||||
public double Data_pos_y() {return data_pos_y;}
|
||||
|
||||
public void Clear_by_hdump() {
|
||||
this.exists = false;
|
||||
this.srcset = style = null;
|
||||
this.data_pos_x = this.data_pos_y = 0;
|
||||
}
|
||||
public void Init_by_parse(Gfh_tag tag) {
|
||||
this.exists = true;
|
||||
this.srcset = tag.Atrs__get_as_bry(Atr_key__srcset);
|
||||
this.style = tag.Atrs__get_as_bry(Gfh_atr_.Bry__style);
|
||||
this.data_pos_x = tag.Atrs__get_as_double_or(Atr_key__data_pos_x, 0);
|
||||
this.data_pos_y = tag.Atrs__get_as_double_or(Atr_key__data_pos_y, 0);
|
||||
}
|
||||
public void Init_by_decode(double data_pos_x, double data_pos_y, byte[] srcset, byte[] style_if_not_dflt) {
|
||||
this.data_pos_x = data_pos_x;
|
||||
this.data_pos_y = data_pos_y;
|
||||
this.srcset = srcset;
|
||||
this.style = Bry_.Eq(style_if_not_dflt, Bry_.Empty) ? Atr_val__style_dflt : style_if_not_dflt;
|
||||
this.exists = true;
|
||||
}
|
||||
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.banner_img_src = banner_file_itm.Html_view_url().To_http_file_bry();
|
||||
this.file_ttl = banner_file_itm.Orig_ttl();
|
||||
this.file_ttl = Gfo_url_encoder_.Href_quotes.Encode(banner_file_itm.Lnki_ttl()); // NOTE: Encode(Lnki_ttl) not Orig_ttl; else "%27s" instead of "'s" PAGE:en.v:'s-Hertogenbosch; DATE:2016-07-12
|
||||
}
|
||||
public void Init_from_html(int maxWidth, byte[] banner_anch_href, byte[] banner_img_src, byte[] srcset, boolean isHeadingOverrideEnabled, byte[] toc) {
|
||||
this.maxWidth = maxWidth;
|
||||
public void Init_from_html(int max_width, byte[] banner_anch_href, byte[] banner_img_src, byte[] srcset, boolean isHeadingOverrideEnabled, byte[] toc) {
|
||||
this.max_width = max_width;
|
||||
this.banner_anch_href = banner_anch_href;
|
||||
this.banner_img_src = banner_img_src;
|
||||
this.srcset = srcset;
|
||||
@@ -68,7 +96,7 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
||||
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, "maxWidth")) bfr.Add_int(max_width);
|
||||
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);
|
||||
@@ -85,4 +113,10 @@ public class Pgbnr_itm implements Mustache_doc_itm {
|
||||
return Mustache_doc_itm_.Ary__empty;
|
||||
}
|
||||
private static final byte[] Bry__anch_atr_id = Bry_.new_a7(" id=\"xoimg_");
|
||||
public static final byte[]
|
||||
Atr_key__srcset = Bry_.new_a7("srcset")
|
||||
, Atr_key__data_pos_x = Bry_.new_a7("data-pos-x")
|
||||
, Atr_key__data_pos_y = Bry_.new_a7("data-pos-y")
|
||||
, Atr_val__style_dflt = Bry_.new_a7("max-width:-1px")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -82,12 +82,13 @@ public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
|
||||
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 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>"
|
||||
, " <a href='{{bannerfile}}' class='image' title='{{tooltip}}' xowa_title='{{file_ttl}}'><img{{{img_id_atr}}}{{{img_xottl}}}{{{img_xoimg}}} src='{{banner}}' width='0' height='0' class='wpb-banner-image {{originx}}' alt='' 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}}"
|
||||
|
||||
Reference in New Issue
Block a user