1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2016-01-28 11:29:27 -05:00
parent 686d56fdab
commit 52c36aa4f8
138 changed files with 1415 additions and 646 deletions

View File

@@ -16,135 +16,16 @@ 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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.xowa.parsers.*;
class Pgbnr_cfg {
public class Pgbnr_cfg {
private static final int[] wpb_standard_sizes = new int[] {640, 1280, 2560};
public byte[] Default_file() {return null;}
public boolean Enabled_in_ns(int ns_id) {return false;}
}
class Pgbnr_icon {
public byte[] Name;
public byte[] Title;
public byte[] Url;
public Pgbnr_icon(byte[] name, byte[] title, byte[] url) {
this.Name = name; this.Title = title; this.Url = url;
public boolean Get__wpb_enable_default_banner() {return false;}
public boolean Get__wpb_enable_heading_override() {return false;}
public byte[] Get__wpb_image() {return null;}
public int[] Get__wpb_standard_sizes() {return wpb_standard_sizes;}
public boolean Chk_pgbnr_allowed(Xoa_ttl ttl, Xowe_wiki wiki) {
return this.Enabled_in_ns(ttl.Ns().Id()) // chk if ns allows banner
&& !Bry_.Eq(ttl.Page_db(), wiki.Props().Main_page()); // never show on main page
}
public static final Pgbnr_icon[] Ary_empty = new Pgbnr_icon[0];
}
class Pgbnr_itm {
public byte[] Name;
public byte[] Tooltip;
public byte[] Title;
public boolean Bottomtoc;
public boolean Toc;
public Xoa_ttl File_ttl;
public Pgbnr_icon[] Icons;
public Pgbnr_itm(byte[] name, byte[] tooltip, byte[] title, boolean bottomtoc, boolean toc, Xoa_ttl file_ttl, Pgbnr_icon[] icons) {
this.Name = name;
this.Tooltip = tooltip; this.Title = title; this.Bottomtoc = bottomtoc; this.Toc = toc; this.File_ttl = file_ttl; this.Icons = icons;
}
// public static void Do(Bry_bfr bfr, Xop_ctx ctx, Pgbnr_cfg cfg, Pgbnr_itm itm) {
// if (itm != null) {
// byte[] name = itm.Name;
//// if ( isset( $params['icons'] ) ){
//// $out->enableOOUI();
//// $params['icons'] = self::expandIconTemplateOptions( $params['icons'] );
//// }
// // $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
// }
// else {}
// }
public static void Get_banner_html(Bry_bfr bfr, byte[] banner_name, Pgbnr_itm itm, Pgbnr_cfg cfg) {
byte[][] urls = Bry_.Ary(Bry_.Empty); // $urls = static::getStandardSizeUrls( $bannername );
if (urls.length == 0) return;
}
// public static function getBannerHtml( $bannername, $options = array() ) {
// // @var int index variable
// $i = 0;
// foreach ( $urls as $url ) {
// $size = $config->get( 'WPBStandardSizes' );
// $size = $size[$i];
// // add url with width and a comma if not adding the last url
// if ( $i < count( $urls ) ) {
// $srcset[] = "$url {$size}w";
// }
// $i++;
// }
// // create full src set from individual urls, separated by comma
// $srcset = implode( ',', $srcset );
// // use largest image url as src attribute
// $bannerurl = $urls[count( $urls ) - 1];
// $bannerfile = Title::newFromText( "File:$bannername" );
// $templateParser = new TemplateParser( __DIR__ . '/../templates' );
// $options['bannerfile'] = $bannerfile->getLocalUrl();
// $options['banner'] = $bannerurl;
// $options['srcset'] = $srcset;
// $file = wfFindFile( $bannerfile );
// $options['maxWidth'] = $file->getWidth();
// $options['isHeadingOverrideEnabled'] = $config->get( 'WPBEnableHeadingOverride' );
// $banner = $templateParser->processTemplate(
// 'banner',
// $options
// );
// }
// public static function addBanner( OutputPage $out, Skin $skin ) {
// $config = WikidataPageBannerFunctions::getWPBConfig();
// $title = $out->getTitle();
// $isDiff = $out->getRequest()->getVal( 'diff' );
// $wpbFunctionsClass = self::$wpbFunctionsClass;
//
// // if banner-options are set and not a diff page, add banner anyway
// if ( $out->getProperty( 'wpb-banner-options' ) !== null && !$isDiff ) {
// $params = $out->getProperty( 'wpb-banner-options' );
// $bannername = $params['name'];
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
// // attempt to get WikidataBanner
// if ( $banner === null ) {
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
// $banner = $wpbFunctionsClass::getBannerHtml( $bannername, $params );
// }
// // only add banner and styling if valid banner generated
// if ( $banner !== null ) {
// if ( isset( $params['toc'] ) ) {
// $out->addModuleStyles( 'ext.WikidataPageBanner.toc.styles' );
// }
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
//
// // FIXME: This is currently only needed to support testing
// $out->setProperty( 'articlebanner-name', $bannername );
// }
// }
// // if the page uses no 'PAGEBANNER' invocation and if article page, insert default banner
// elseif (
// $title->isKnown() &&
// $out->isArticle() &&
// $config->get( 'WPBEnableDefaultBanner' ) &&
// !$isDiff
// ) {
// $ns = $title->getNamespace();
// // banner only on specified namespaces, and not Main Page of wiki
// if ( in_array( $ns, $config->get( 'WPBNamespaces' ) )
// && !$title->isMainPage() ) {
// // first try to obtain bannername from Wikidata
// $bannername = $wpbFunctionsClass::getWikidataBanner( $title );
// if ( $bannername === null ) {
// // if Wikidata banner not found, set bannername to default banner
// $bannername = $config->get( 'WPBImage' );
// }
// // add title to template parameters
// $paramsForBannerTemplate = array( 'title' => $title );
// $banner = $wpbFunctionsClass::
// getBannerHtml( $bannername, $paramsForBannerTemplate );
// // only add banner and styling if valid banner generated
// if ( $banner !== null ) {
// $wpbFunctionsClass::insertBannerIntoOutputPage( $out, $banner );
//
// // set articlebanner property on OutputPage
// // FIXME: This is currently only needed to support testing
// $out->setProperty( 'articlebanner-name', $bannername );
// }
// }
// }
// return true;
// }
}

View File

@@ -16,25 +16,24 @@ 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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.btries.*;
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.*;
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);}
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { // WikidataPageBanner.hooks.php|addCustomBanner
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { // {{PAGEBANNER}} appears on page; WikidataPageBanner.hooks.php|addCustomBanner
Xowe_wiki wiki = ctx.Wiki();
Pgbnr_cfg cfg = new Pgbnr_cfg(); // ctx.Wiki().Xtn_mgr().Xtn_pgbnr();
Xoa_ttl ttl = ctx.Cur_page().Ttl();
if ( !cfg.Enabled_in_ns(ttl.Ns().Id()) // chk if ns allows banner
|| Bry_.Eq(ttl.Page_db(), wiki.Props().Main_page())) // never show on main page
return;
Bry_bfr tmp_bfr = Bry_bfr.new_();
boolean bottomtoc = false, toc = false;
byte[] tooltip = ttl.Page_txt();
byte[] title = ttl.Page_txt();
int args_len = self.Args_len();
Pgbnr_xtn_mgr xtn_mgr = wiki.Xtn_mgr().Xtn_pgbnr();
Pgbnr_cfg cfg = xtn_mgr.Cfg();
Xoa_ttl ttl = ctx.Page().Ttl();
if (!cfg.Chk_pgbnr_allowed(ttl, wiki)) return;
byte[] tooltip = ttl.Page_txt(), title = ttl.Page_txt(), toc = Bry_.Empty, origin_x = Bry_.Empty;
boolean bottomtoc = false;;
double data_pos_x = 0, data_pos_y = 0;
List_adp icons_list = null;
Bry_bfr tmp_bfr = Bry_bfr.new_();
int args_len = self.Args_len();
for (int i = 0; i < args_len; ++i) {
Arg_nde_tkn arg = self.Args_get_by_idx(i);
byte[] key = Pf_func_.Eval_tkn(tmp_bfr, ctx, src, caller, arg.Key_tkn());
@@ -46,34 +45,141 @@ public class Pgbnr_func extends Pf_func_base {
tooltip = val;
if (tid == Arg__bottomtoc && Bry_.Eq(val, Bry__yes))
bottomtoc = true;
if (tid == Arg__toc && Bry_.Eq(val, Bry__yes))
toc = true;
if (tid == -1 && Bry_.Has_at_bgn(key, Bry__icon) && Bry_.Len_gt_0(val)) {
if (tid == Arg__toc && Bry_.Eq(val, Bry__yes)) // REF.MW:addToc
toc = Bry_.Empty; // note that "" will be overwritten later by actual toc html
if ( tid == -1 // handle "icon-*";
&& Bry_.Has_at_bgn(key, Bry__icon) // if (substr($key, 0, 5) === 'icon-')
&& Bry_.Len(Bry__icon) > 5 // if ( !isset( $iconname) )
&& Bry_.Len_gt_0(val) // if ( !isset( $$value ) )
) { // REF.MW:addIcons
tid = Arg__icon;
if (icons_list == null) icons_list = List_adp_.new_();
byte[] icon_name = Xop_sanitizer.Escape_cls(val);
byte[] icon_key = Bry_.Mid(key, 5);
byte[] icon_name = Xop_sanitizer.Escape_cls(icon_key);
byte[] icon_title = icon_name;
Xoa_ttl icon_url_ttl = wiki.Ttl_parse(val);
// TODO: get icon_url
byte[] icon_url_bry = Bry_.Empty;
if (icon_url_ttl == null) icon_url_bry = Bry__url_dflt;
if (icon_url_ttl == null)
icon_url_bry = Bry__url_dflt; // $iconUrl = Title::newFromText( $value ); if ( $iconUrl )
else {
icon_url_bry = Bry_.Empty;// $iconUrl->getLocalUrl();
icon_url_bry = Bry_.Empty; // $iconUrl->getLocalUrl();
icon_title = ttl.Page_txt();
}
icons_list.Add(new Pgbnr_icon(icon_name, icon_title, icon_url_bry));
tid = Arg__icon;
}
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", "page", ctx.Cur_page().Url_bry_safe(), key, val);
// WikidataPageBannerFunctions::addFocus( $paramsForBannerTemplate, $argumentsFromParserFunction );
if (tid == Arg__origin) { // REF.MW:addFocus
double tmp_data_pos_x = Double_.NaN, tmp_data_pos_y = Double_.NaN;
int comma_pos = Bry_find_.Find_fwd(val, Byte_ascii.Comma);
if (comma_pos != Bry_find_.Not_found) {
tmp_data_pos_x = Bry_.To_double_or(val, 0, comma_pos, Double_.NaN);
if (!Double_.IsNaN(tmp_data_pos_x)) {
if (tmp_data_pos_x >= -1 && tmp_data_pos_x <= 1) {
data_pos_x = tmp_data_pos_x;
origin_x = tmp_data_pos_x <= .25d ? Bry__origin_x__left : Bry__origin_x__right;
}
}
if (!Double_.IsNaN(tmp_data_pos_y)) {
if (tmp_data_pos_y >= -1 && tmp_data_pos_y <= 1)
data_pos_y = tmp_data_pos_y;
}
}
}
if (tid == -1) Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown arg type; page=~{0} key=~{1} val=~{2}", "page", ctx.Page().Url_bry_safe(), key, val);
}
byte[] name = Eval_argx(ctx, src, caller, self);
if (Bry_.Len_eq_0(name))
name = cfg.Default_file();
Xoa_ttl file_ttl = wiki.Ttl_parse(name);
Pgbnr_itm itm = new Pgbnr_itm(name, tooltip, title, bottomtoc, toc, file_ttl, icons_list == null ? Pgbnr_icon.Ary_empty : (Pgbnr_icon[])icons_list.To_ary_and_clear(Pgbnr_icon.class));
Tfds.Write(itm);
// Xoa_ttl file_ttl = wiki.Ttl_parse(name); SKIP?: MW creates title to auto-register page and image in imagelinks
Pgbnr_itm itm = new Pgbnr_itm();
ctx.Page().Html_data().Xtn__pgbnr_(itm);
itm.Init_from_wtxt(name, 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));
}
private static final byte[] Bry__yes = Bry_.new_a7("yes"), Bry__icon = Bry_.new_a7("icon-"), Bry__url_dflt = Bry_.new_a7("#");
private static final int Arg__pgname = 0, Arg__tooltip = 1, Arg__bottomtoc = 2, Arg__toc = 3, Arg__icon = 4;
public static void Add_banner(Bry_bfr bfr, Xop_ctx ctx) {
Xowe_wiki wiki = ctx.Wiki();
Pgbnr_cfg cfg = wiki.Xtn_mgr().Xtn_pgbnr().Cfg();
Xoa_ttl ttl = ctx.Page().Ttl();
Pgbnr_itm itm = ctx.Page().Html_data().Xtn__pgbnr();
byte[] banner_name = null, banner_html = null;
if (itm != null) { // {{PAGEBANNER}} exists in wikitext
banner_name = itm.name;
banner_html = Get_banner_html(wiki, cfg, banner_name, itm);
if (banner_html == null) { // no banner; try again using title from wikidata;
banner_name = Get_wikidata_banner(ttl);
banner_html = Get_banner_html(wiki, cfg, banner_name, itm);
}
if (banner_html != null) { // only add banner and styling if valid banner generated
if (itm.toc != null) {
// $out->addModuleStyles( 'ext.WikidataPageBanner.toc.styles' );
}
bfr.Add(banner_html);
}
}
else if ( ttl.Ns().Id_is_main() // if the page uses no 'PAGEBANNER' invocation and if article page, insert default banner
&& cfg.Get__wpb_enable_default_banner()
) {
if (cfg.Chk_pgbnr_allowed(ttl, wiki)) {
banner_name = Get_wikidata_banner(ttl);
if (banner_name == null) {
banner_name = cfg.Get__wpb_image();
}
itm = new Pgbnr_itm();
itm.name = banner_name;
banner_html = Get_banner_html(wiki, cfg, banner_name, itm);
if (banner_html != null) { // NOTE: same as above
bfr.Add(banner_html);
}
}
}
}
public static byte[] Get_banner_html(Xowe_wiki wiki, Pgbnr_cfg cfg, byte[] banner_name, Pgbnr_itm itm) {
byte[][] urls = Get_standard_size_urls(wiki, cfg, banner_name);
if (urls == null) return null;
Bry_bfr tmp_bfr = Bry_bfr.new_();
int urls_len = urls.length;
int[] sizes = cfg.Get__wpb_standard_sizes();
for (int i = 0; i < urls_len; ++i) {
int size = sizes[i];
if (i != 0) tmp_bfr.Add_byte_comma();
tmp_bfr.Add(urls[i]).Add_byte_space().Add_int_variable(size).Add_byte(Byte_ascii.Ltr_w); // $srcset[] = "$url {$size}w";
}
byte[] srcset = tmp_bfr.To_bry_and_clear();
byte[] banner_url = urls.length == 0 ? Bry_.Empty : urls[urls_len - 1]; // gets largest url
// Xoa_ttl banner_file = wiki.Ttl_parse(tmp_bfr.Add(wiki.Ns_mgr().Ns_file().Name_db_w_colon()).Add(banner_name).To_bry_and_clear());
int maxWidth = 1; // $file = wfFindFile( banner_file ); $options['maxWidth'] = $file->getWidth();
byte[] banner_file = null; // $bannerfile->getLocalUrl();
itm.Init_from_html(maxWidth, banner_file, banner_url, srcset, cfg.Get__wpb_enable_heading_override());
Mustache_render_ctx mctx = new Mustache_render_ctx().Init(itm);
wiki.Xtn_mgr().Xtn_pgbnr().Template_root().Render(tmp_bfr, mctx);
return tmp_bfr.To_bry_and_clear();
}
private static byte[][] Get_standard_size_urls(Xow_wiki wiki, Pgbnr_cfg cfg, byte[] file_name) {
Ordered_hash hash = Ordered_hash_.New_bry();
int[] sizes = cfg.Get__wpb_standard_sizes();
int sizes_len = sizes.length;
for (int i = 0; i < sizes_len; ++i) {
byte[] url = Get_image_url(wiki, file_name, sizes[i]);
if (url != null)
hash.Add_if_dupe_use_1st(url, url);
}
return (byte[][])hash.To_ary_and_clear(byte[].class);
}
private static byte[] Get_image_url(Xow_wiki wiki, byte[] file_name, int width) {
// Xoa_ttl file_ttl = wiki.Ttl_parse(file_name);
// Object file = new Object(); // $file = wfFindFile( file_ttl );
// if (file == null) return null;
if (width >= 0 && width <= 3000) {
// $mto = $file->transform( array( 'width' => $imagewidth ) );
byte[] url = new byte[0]; // $url = wfExpandUrl( $mto->getUrl(), PROTO_CURRENT );
return url;
}
else
return new byte[0]; // $file->getFullUrl();
}
private static byte[] Get_wikidata_banner(Xoa_ttl ttl) {
return null;
}
private static final byte[] Bry__yes = Bry_.new_a7("yes"), Bry__icon = Bry_.new_a7("icon-"), Bry__url_dflt = Bry_.new_a7("#"), Bry__origin_x__left = Bry_.new_a7("wpb-left"), Bry__origin_x__right = Bry_.new_a7("wpb-right");
private static final int Arg__pgname = 0, Arg__tooltip = 1, Arg__bottomtoc = 2, Arg__toc = 3, Arg__icon = 4, Arg__origin = 5;
private static final Hash_adp_bry arg_hash = Hash_adp_bry.cs().Add_str_int("pgname", Arg__pgname)
.Add_str_int("tooltip", Arg__tooltip).Add_str_int("bottomtoc", Arg__bottomtoc).Add_str_int("toc", Arg__toc);
.Add_str_int("tooltip", Arg__tooltip).Add_str_int("bottomtoc", Arg__bottomtoc).Add_str_int("toc", Arg__toc).Add_str_int("origin", Arg__origin);
}

View File

@@ -16,10 +16,28 @@ 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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import org.junit.*; import gplx.xowa.wikis.pages.skins.*;
import org.junit.*; import gplx.core.brys.*; import gplx.xowa.wikis.pages.skins.*;
public class Pgbnr_func_tst {
@Before public void init() {fxt.Reset();} private final Xop_fxt fxt = new Xop_fxt();
@Test public void Basic() {
fxt.Test_html_full_str("{{PAGEBANNER}}", "");
// private final Pgbnr_func_fxt fxt = new Pgbnr_func_fxt();
@Test public void Basic() {
// fxt.Test__parse__eq("{{PAGEBANNER:A.png}}", 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 src='' srcset=' 640w' class='wpb-banner-image ' data-pos-x='0' data-pos-y='0' style='max-width:1px'></a>"
// , " </div>"
// , " <div class='wpb-topbanner-toc '><div class='wpb-banner-toc'></div></div>"
// , "</div>"
// ));
}
}
class Pgbnr_func_fxt {
private final Xop_fxt fxt = new Xop_fxt();
public void Test__parse__eq(String raw, String expd) {
fxt.Exec_parse_page_all_as_str("{{PAGEBANNER:A.png}}");
Bfr_arg arg = fxt.Wiki().Xtn_mgr().Xtn_pgbnr().Write_html(fxt.Ctx(), fxt.Page());
Bry_bfr bfr = Bry_bfr.new_();
arg.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.mustaches.*;
public class Pgbnr_icon implements Mustache_doc_itm {
public byte[] name;
public byte[] title;
public byte[] url;
public Pgbnr_icon(byte[] name, byte[] title, byte[] url) {this.name = name; this.title = title; this.url = url;}
public byte[] Get_prop(String key) {
if (String_.Eq(key, "name")) return name;
else if (String_.Eq(key, "title")) return title;
else if (String_.Eq(key, "url")) return url;
else if (String_.Eq(key, "html")) return Mustache_doc_itm_.Null_val;
return Mustache_doc_itm_.Null_val;
}
public Mustache_doc_itm[] Get_subs(String key) {return Mustache_doc_itm_.Ary__empty;}
public static final Pgbnr_icon[] Ary_empty = new Pgbnr_icon[0];
}

View File

@@ -0,0 +1,59 @@
/*
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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.langs.mustaches.*;
public class Pgbnr_itm implements Mustache_doc_itm {
public byte[] name, toc;
private byte[] tooltip, title, originx, bannerfile, banner, srcset;
private double data_pos_x, data_pos_y;
private int maxWidth;
private boolean bottomtoc, isHeadingOverrideEnabled;
private Pgbnr_icon[] icons;
public void Init_from_wtxt(byte[] name, byte[] tooltip, byte[] title, boolean bottomtoc, byte[] toc, double data_pos_x, double data_pos_y, byte[] originx, Pgbnr_icon[] icons) {
this.name = name;
this.tooltip = tooltip; this.title = title; 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;
}
public void Init_from_html(int maxWidth, byte[] bannerfile, byte[] banner, byte[] srcset, boolean isHeadingOverrideEnabled) {
this.maxWidth = maxWidth;
this.bannerfile = bannerfile;
this.banner = banner;
this.srcset = srcset;
this.isHeadingOverrideEnabled = isHeadingOverrideEnabled;
}
public byte[] Get_prop(String key) {
if (String_.Eq(key, "title")) return title;
else if (String_.Eq(key, "tooltip")) return tooltip;
else if (String_.Eq(key, "bannerfile")) return bannerfile;
else if (String_.Eq(key, "banner")) return banner;
else if (String_.Eq(key, "srcset")) return srcset;
else if (String_.Eq(key, "originx")) return originx;
else if (String_.Eq(key, "data-pos-x")) return Bry_.new_a7(Double_.To_str(data_pos_x));
else if (String_.Eq(key, "data-pos-y")) return Bry_.new_a7(Double_.To_str(data_pos_y));
else if (String_.Eq(key, "maxWidth")) return Int_.To_bry(maxWidth);
else if (String_.Eq(key, "toc")) return toc;
return Mustache_doc_itm_.Null_val;
}
public Mustache_doc_itm[] Get_subs(String key) {
if (String_.Eq(key, "icons")) return icons;
else if (String_.Eq(key, "hasIcons")) return Mustache_doc_itm_.Ary__bool(icons.length > 0);
else if (String_.Eq(key, "bottomtoc")) return Mustache_doc_itm_.Ary__bool(bottomtoc);
else if (String_.Eq(key, "isHeadingOverrideEnabled")) return Mustache_doc_itm_.Ary__bool(isHeadingOverrideEnabled);
return Mustache_doc_itm_.Ary__empty;
}
}

View File

@@ -0,0 +1,58 @@
/*
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.pagebanners; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*;
import gplx.core.brys.*; import gplx.langs.mustaches.*; import gplx.xowa.parsers.*;
public class Pgbnr_xtn_mgr extends Xox_mgr_base implements Bfr_arg {
@Override public byte[] Xtn_key() {return Xtn_key_static;} public static final byte[] Xtn_key_static = Bry_.new_a7("pagebanner");
@Override public Xox_mgr Clone_new() {return new Pgbnr_xtn_mgr();}
public Pgbnr_cfg Cfg() {return cfg;} private final Pgbnr_cfg cfg = new Pgbnr_cfg();
public Mustache_tkn_itm Template_root() {
if (template_root == null) {
Mustache_tkn_parser parser = new Mustache_tkn_parser();
template_root = parser.Parse(Template_dflt, 0, Template_dflt.length);
}
return template_root;
} private Mustache_tkn_itm template_root;
@Override public void Xtn_init_by_app(Xoae_app app) {
}
public Bfr_arg Write_html(Xop_ctx pctx, Xoae_page page) {
this.pctx = pctx; this.page = page;
return this;
} private Xop_ctx pctx; private Xoae_page page;
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);
}
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 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>"
, " {{#hasIcons}}"
, " <div class='wpb-iconbox'>"
, " {{#icons}}"
, " <a href='{{url}}'>{{{html}}}</a>"
, " {{/icons}}"
, " </div>"
, " {{/hasIcons}}"
, " </div>"
, " <div class='wpb-topbanner-toc {{#bottomtoc}}wpb-bottomtoc{{/bottomtoc}}'><div class='wpb-banner-toc'>{{{toc}}}</div></div>"
, "</div>"
);
}