@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { byte[] user_name = Eval_argx(ctx, src, caller, self); byte[] when_m = Bry_.Empty, when_f = Bry_.Empty, when_u = Bry_.Empty; int self_args_len = self.Args_len(); if (self_args_len == 0) return; // per MW: EX: {{gender:name}} -> "" else { if (self_args_len > 0) { when_m = when_u = Pf_func_.Eval_arg_or_empty( ctx, src, caller, self, self_args_len, 0); // default when_u to when_m if (self_args_len > 1) { when_f = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 1); if (self_args_len > 2) { when_u = Pf_func_.Eval_arg_or_empty(ctx, src, caller, self, self_args_len, 2); } } } } if (self_args_len == 1) { bfr.Add(when_m); return; } // per MW: EX: {{gender:name|a}} -> "a" int gender = Get_gender(ctx.App().User(), user_name); Xol_lang_itm lang = ctx.Page().Lang(); bfr.Add(lang.Gender().Gender_eval(gender, when_m, when_f, when_u)); }
public boolean Expr(Scrib_proc_args args, Scrib_proc_rslt rslt) { byte[] expr_bry = args.Xstr_bry_or_null( 0); // NOTE: some modules will pass in an int; PAGE:en.w:531_BC DATE:2016-04-29 Bry_bfr tmp_bfr = core.Wiki().Utl__bfr_mkr().Get_b128(); Pfunc_expr.Evaluate(tmp_bfr, core.Ctx(), expr_bry); String expr_rslt = tmp_bfr.To_str_and_rls(); return rslt.Init_obj( expr_rslt); // NOTE: always return rslt; don't throw error even if expr is invalid; // EX:mw.ParserFuntion.expr('fail'); PAGE:es.w:Freer_(Texas) DATE:2015-07-28 }
public static byte[] Eval_arg_or( Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, int self_args_len, int i, byte[] or) { if (i >= self_args_len) return or; Arg_nde_tkn nde = self.Args_get_by_idx(i); Bry_bfr bfr = Bry_bfr_.New(); Eval_arg_or(bfr, ctx, src, caller, self, nde, or); return bfr.To_bry_and_clear_and_trim(); }
public static byte[] Eval_val_or( Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, int self_args_len, int i, byte[] or) { if (i >= self_args_len) return or; Bry_bfr bfr = Bry_bfr_.New(); Arg_nde_tkn nde = self.Args_get_by_idx(i); nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, bfr); return bfr.To_bry_and_clear_and_trim(); }
public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) { byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code); byte[] img_title = temp_bfr.Add(code_esc) .Add_byte_space() .Add_byte(Byte_ascii.Brack_bgn) .Add(glyph_esc) .Add_byte(Byte_ascii.Brack_end) .Xto_bry_and_clear(); // "~{code} [~{glyph}]" return Img(img_cls, td_height, glyph_esc, code_esc, img_title); }
public void Bfr_arg__add(Bry_bfr bfr) { if (jdoc == null) return; // TEST: wdoc doesn't have jdoc jdoc.Root_nde().Print_as_json(tmp_bfr, 0); fmtr.Bld_bfr_many( bfr, toc_data.Href(), toc_data.Text(), toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), tmp_bfr.To_bry_and_clear()); }
public void Xtn_write( Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) { if (this.name == null) bfr.Add_str_a7("Error: Page status indicators' name attribute must not be empty."); }
public void Special_gen(Xowe_wiki wiki, Xoae_page page, Xoa_url url, Xoa_ttl ttl) { if (cfg == null) cfg = (Wdata_itemByTitle_cfg) wiki.Appe().Special_mgr().Get_or_null(Wdata_itemByTitle_cfg.Key); // Special:ItemByTitle/enwiki/Earth -> www.wikidata.org/wiki/Q2 Gfo_usr_dlg usr_dlg = wiki.Appe().Usr_dlg(); byte[] site_bry = cfg.Site_default(); byte[] page_bry = Bry_.Empty; byte[] raw_bry = ttl.Full_txt_wo_qarg(); // EX: enwiki/Earth int args_len = url.Args().length; if (args_len > 0) { arg_hash.Load(url); site_bry = arg_hash.Get_val_bry_or(Arg_site, Bry_.Empty); page_bry = arg_hash.Get_val_bry_or(Arg_page, Bry_.Empty); } int site_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr); if (site_bgn != Bry_.NotFound) { // leaf arg is available int page_bgn = Bry_finder.Find_fwd(raw_bry, Xoa_ttl.Subpage_spr, site_bgn + 1); int raw_bry_len = raw_bry.length; if (page_bgn != Bry_.NotFound && page_bgn < raw_bry_len) { // pipe is found and not last char (EX: "enwiki/" is invalid site_bry = Bry_.Mid(raw_bry, site_bgn + 1, page_bgn); page_bry = Bry_.Mid(raw_bry, page_bgn + 1, raw_bry_len); } } Xoae_app app = wiki.Appe(); if (Bry_.Len_gt_0(site_bry) && Bry_.Len_gt_0(page_bry)) if (Navigate(usr_dlg, app, app.Wiki_mgr().Wdata_mgr(), page, site_bry, page_bry)) return; Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_k004(); html_fmtr.Bld_bfr_many( tmp_bfr, "Search for items by site and title", "Site", site_bry, "Page", page_bry, "Search"); page.Data_raw_(tmp_bfr.To_bry_and_rls()); page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML }
public static void Eval_arg_or( Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xot_invk caller, Xot_invk self, Arg_nde_tkn nde, byte[] or) { nde.Key_tkn() .Tmpl_evaluate( ctx, src, caller, bfr); // NOTE: must add key b/c parser functions do not have keys and some usages pass // in xml_tkns; EX: {{#if|<a href='{{{1}}}'|}}; "<a href" should not be // interpreted as key if (nde.KeyTkn_exists()) bfr.Add_byte(Byte_ascii.Eq); nde.Val_tkn().Tmpl_evaluate(ctx, src, caller, bfr); }
public static byte[] Write_wdata_links(List_adp slink_list, Xowe_wiki wiki, Xoa_ttl ttl, Wdata_external_lang_links_data external_links_mgr) { try { switch (wiki.Domain_tid()) { case Xow_domain_type_.Tid_home: // home will never be in wikidata case Xow_domain_type_.Tid_wikidata: // wikidata will never be in wikidata return Qid_null; } Wdata_wiki_mgr wdata_mgr = wiki.Appe().Wiki_mgr().Wdata_mgr(); Wdata_doc doc = wdata_mgr.Pages_get(wiki, ttl); if (doc == null) return Qid_null; // no links boolean external_links_mgr_enabled = external_links_mgr.Enabled(); Ordered_hash links = doc.Slink_list(); Bry_bfr tmp_bfr = wiki.Appe().Utl__bfr_mkr().Get_k004(); Xow_wiki_abrv wiki_abrv = new Xow_wiki_abrv(); int len = links.Count(); for (int i = 0; i < len; i++) { Wdata_sitelink_itm slink = (Wdata_sitelink_itm)links.Get_at(i); byte[] xwiki_key = slink.Site(); Xow_wiki_abrv_.parse_(wiki_abrv, xwiki_key, 0, xwiki_key.length); if (wiki_abrv.Domain_tid() == Xow_wiki_abrv_.Tid_null) { wiki.Appe().Usr_dlg().Warn_many("", "", "unknown wiki in wikidata: ttl=~{0} wiki=~{1}", ttl.Page_db_as_str(), String_.new_u8(xwiki_key)); continue; } if (wiki_abrv.Domain_tid() != wiki.Domain_tid()) continue; // ignore wikis in a different domain; EX: looking at enwiki:Earth, and wikidata has dewikiquote; ignore dewikiquote; DATE:2014-06-21 byte[] lang_key = wiki_abrv.Lang_itm().Key(); if (external_links_mgr_enabled && external_links_mgr.Langs_hide(lang_key, 0, lang_key.length)) continue; tmp_bfr.Add(lang_key); tmp_bfr.Add_byte(Byte_ascii.Colon); tmp_bfr.Add(slink.Name()); Xoa_ttl slink_ttl = Xoa_ttl.parse_(wiki, tmp_bfr.Xto_bry_and_clear()); if (slink_ttl == null) continue; // invalid ttl Xow_xwiki_itm xwiki_itm = slink_ttl.Wik_itm(); if ( xwiki_itm == null // not a known xwiki; EX: [[zzz:abc]] || Bry_.Eq(xwiki_itm.Domain_bry(), wiki.Domain_bry()) // skip if same as self; i.e.: do not include links to enwiki if already in enwiki ) continue; slink.Page_ttl_(slink_ttl); slink_list.Add(slink); } tmp_bfr.Mkr_rls(); if (external_links_mgr_enabled && external_links_mgr.Sort()) slink_list.Sort_by(Xoa_ttl_sorter._); return doc.Qid(); } catch (Exception e) {Err_.Noop(e); return Qid_null;} }
public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) { html_bfr.Add(Tbl_inner_bgn) .Add_bfr_and_clear(text_bfr) .Add(Tbl_inner_end); // $html .= self::TABLE_START . "<tr>\n" . $tableContentHtml . // '</tr></table>'; }
public void Hr(Bry_bfr bfr) { bfr.Add(Html_tag_.Hr_inl).Add_byte_nl(); }
class Hiero_html_wtr { private Hiero_phoneme_mgr phoneme_mgr; private Bry_bfr temp_bfr = Bry_bfr.reset_(255); public Hiero_html_wtr(Hiero_html_mgr mgr, Hiero_phoneme_mgr phoneme_mgr) { this.phoneme_mgr = phoneme_mgr; } public void Init_for_write(Xoh_wtr_ctx hctx) { this.hiero_img_dir = hctx.Mode_is_hdump() ? gplx.xowa.html.hdumps.abrvs.Xohd_abrv_.Key_hiero_dir : Hiero_xtn_mgr.Img_src_dir; } private byte[] hiero_img_dir = null; public void Hr(Bry_bfr bfr) { bfr.Add(Html_tag_.Hr_inl).Add_byte_nl(); } public void Tbl_eol(Bry_bfr bfr) { bfr.Add(Tbl_eol_bry); } public byte[] Td_height(int height) { return temp_bfr.Add(Option_bgn_bry) .Add_int_variable(height) .Add(Option_end_bry) .Xto_bry_and_clear(); } private static final byte[] Option_bgn_bry = Bry_.new_a7("height: "), Option_end_bry = Bry_.new_a7("px;"); public void Td(Bry_bfr bfr, byte[] glyph) { bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry); } private static final byte[] Td_bgn_bry = Bry_.new_a7("\n <td>"), Td_end_bry = Bry_.new_a7("\n </td>"); public void Cartouche_bgn(Bry_bfr bfr) { bfr.Add(Cartouche_bgn_lhs_bry) .Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100) .Add(Cartouche_bgn_rhs_bry); } private static final String Tbl_bgn_str = "<table class=\"mw-hiero-table\">"; private static final byte[] Cartouche_bgn_lhs_bry = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "", " <td>", " " + Tbl_bgn_str, " <tr>", " <td class='mw-hiero-box' style='height: ")), Cartouche_bgn_rhs_bry = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "px;'>", " </td>", " </tr>", " <tr>", " <td>", " " + Tbl_bgn_str, " <tr>")); public void Cartouche_end(Bry_bfr bfr) { bfr.Add(Cartouche_end_lhs_bry) .Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100) .Add(Cartouche_end_rhs_bry); } private static final byte[] Cartouche_end_lhs_bry = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "", " </tr>", " </table>", " </td>", " </tr>", " <tr>", " <td class='mw-hiero-box' style='height: ")), Cartouche_end_rhs_bry = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "px;'>", " </td>", " </tr>", " </table>", " </td>")); public byte[] Cartouche_img( Xoh_wtr_ctx hctx, boolean bgn, byte[] glyph) { // render open / close cartouche; note that MW has two branches, but they are // both the same int height = (int) ((Hiero_html_mgr.Max_height * Hiero_html_mgr.scale) / 100); Hiero_phoneme_itm phoneme_itm = phoneme_mgr.Get_by_key(glyph); if (phoneme_itm == null) throw Err_.new_fmt_("missing phoneme: {0}", String_.new_u8(glyph)); byte[] code = phoneme_itm.Gardiner_code(); byte[] title = bgn ? Html_entity_.Lt_bry : Html_entity_.Gt_bry; return cartouche_img_fmtr.Bld_bry_many(temp_bfr, hiero_img_dir, code, height, title); } private static final Bry_fmtr cartouche_img_fmtr = Bry_fmtr.new_( String_.Concat( "\n <img src='~{path}hiero_~{code}.png'", " height='~{height}' title='~{title}'", " alt='~{title}' />"), "path", "code", "height", "title"); public void Tbl_inner(Bry_bfr html_bfr, Bry_bfr text_bfr) { html_bfr.Add(Tbl_inner_bgn) .Add_bfr_and_clear(text_bfr) .Add(Tbl_inner_end); // $html .= self::TABLE_START . "<tr>\n" . $tableContentHtml . // '</tr></table>'; } private static final byte[] Tbl_inner_bgn = Bry_.new_u8( String_.Concat_lines_nl_skip_last( " <table class=\"mw-hiero-table\">", " <tr>")), Tbl_inner_end = Bry_.new_u8(String_.Concat_lines_nl_skip_last("", " </tr>", " </table>")); public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) { bfr.Add(Outer_tbl_bgn); bfr.Add_bfr_and_clear(html_bfr); bfr.Add(Outer_tbl_end); } private static final byte[] Outer_tbl_bgn = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "<table class='mw-hiero-table mw-hiero-outer' dir='ltr'>", " <tr>", " <td>", "")), Outer_tbl_end = Bry_.new_a7( String_.Concat_lines_nl_skip_last("", " </td>", " </tr>", "</table>", "")); public byte[] Img_phoneme(byte[] img_cls, byte[] td_height, byte[] glyph_esc, byte[] code) { byte[] code_esc = Html_utl.Escape_html_as_bry(temp_bfr, code); byte[] img_title = temp_bfr.Add(code_esc) .Add_byte_space() .Add_byte(Byte_ascii.Brack_bgn) .Add(glyph_esc) .Add_byte(Byte_ascii.Brack_end) .Xto_bry_and_clear(); // "~{code} [~{glyph}]" return Img(img_cls, td_height, glyph_esc, code_esc, img_title); } public byte[] Img_file(byte[] img_cls, byte[] td_height, byte[] glyph_esc) { return Img(img_cls, td_height, glyph_esc, glyph_esc, glyph_esc); } private byte[] Img( byte[] img_cls, byte[] td_height, byte[] glyph, byte[] img_src_name, byte[] img_title) { byte[] img_src = Bld_img_src(hiero_img_dir, img_src_name); return glyph_img_fmtr.Bld_bry_many( temp_bfr, img_cls, Hiero_html_mgr.Image_margin, td_height, img_src, img_title, glyph); } private static final byte[] Tbl_eol_bry = Bry_.new_a7( String_.Concat_lines_nl_skip_last( "", " </tr>", " </table>", " " + Tbl_bgn_str, " <tr>")); private static final Bry_fmtr glyph_img_fmtr = Bry_fmtr.new_( "\n <img ~{img_cls}style='margin: ~{img_margin}px; ~{option}' src='~{img_src}' title='~{img_title}' alt='~{glyph}' />", "img_cls", "img_margin", "option", "img_src", "img_title", "glyph"); public byte[] Void(boolean half) { // render void int width = Hiero_html_mgr.Max_height; if (half) width /= 2; return void_fmtr.Bld_bry_many(temp_bfr, width); } private static final Bry_fmtr void_fmtr = Bry_fmtr.new_( String_.Concat_lines_nl_skip_last( "", " <table class=\"mw-hiero-table\" style=\"width: ~{width}px;\">", " <tr>", " <td> ", " </td>", " </tr>", " </table>"), "width"); private static byte[] Bld_img_src(byte[] hiero_img_dir, byte[] name) { return Bry_.Add(hiero_img_dir, Img_src_prefix, name, Img_src_ext); } private static final byte[] Img_src_prefix = Bry_.new_a7("hiero_"), Img_src_ext = Bry_.new_a7(".png"); }
public void Tbl_eol(Bry_bfr bfr) { bfr.Add(Tbl_eol_bry); }
@Override public void Func_evaluate(Bry_bfr bfr, Xop_ctx ctx, Xot_invk caller, Xot_invk self, byte[] src) { bfr.Add_byte_pipe(); }
public byte[] Td_height(int height) { return temp_bfr.Add(Option_bgn_bry) .Add_int_variable(height) .Add(Option_end_bry) .Xto_bry_and_clear(); }
public void Td(Bry_bfr bfr, byte[] glyph) { bfr.Add(Td_bgn_bry).Add(glyph).Add(Td_end_bry); }
public void Cartouche_end(Bry_bfr bfr) { bfr.Add(Cartouche_end_lhs_bry) .Add_int_variable((Hiero_html_mgr.Cartouche_width * Hiero_html_mgr.scale) / 100) .Add(Cartouche_end_rhs_bry); }
public void Xtn_write( Bry_bfr bfr, Xoae_app app, Xop_ctx ctx, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xoae_page wpg, Xop_xnde_tkn xnde, byte[] src) { Xowe_wiki wiki = ctx.Wiki(); Dpl_html_data html_mode = Dpl_html_data.new_(Dpl_itm_keys.Key_unordered); int itms_len = pages.Count(); if (itms_len == 0) { if (!itm.Suppress_errors()) bfr.Add_str_a7("No pages meet these criteria."); return; } int itms_bgn = 0; if (itm.Offset() != Int_.Min_value) { itms_bgn = itm.Offset(); } if (itm.Count() != Int_.Min_value && itms_bgn + itm.Count() < itms_len) { itms_len = itms_bgn + itm.Count(); } boolean show_ns = itm.Show_ns(); Bry_bfr tmp_bfr = Bry_bfr_.Get(); Xop_amp_mgr amp_mgr = wiki.Appe().Parser_amp_mgr(); try { bfr.Add(html_mode.Grp_bgn()).Add_byte_nl(); for (int i = itms_bgn; i < itms_len; i++) { Xowd_page_itm page = (Xowd_page_itm) pages.Get_at(i); Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page.Ns_id(), page.Ttl_page_db()); byte[] ttl_page_txt = show_ns ? ttl.Full_txt_w_ttl_case() : ttl.Page_txt(); if (ttl_page_txt == null) continue; // NOTE: apparently DynamicPageList allows null pages; DATE:2013-07-22 switch (html_mode.Tid()) { case Dpl_html_data.Tid_list_ul: case Dpl_html_data.Tid_list_ol: bfr.Add(Xoh_consts.Space_2).Add(html_mode.Itm_bgn()).Add(Gfh_bldr_.Bry__a_lhs_w_href); bfr.Add_str_a7("/wiki/") .Add(Gfo_url_encoder_.Href.Encode(ttl.Full_db())) .Add_byte_quote(); // NOTE: Full_db to encode spaces as underscores; // PAGE:en.q:Wikiquote:Speedy_deletions DATE:2016-01-19 Gfh_atr_.Add( bfr, Gfh_atr_.Bry__title, Xoh_html_wtr_escaper.Escape( amp_mgr, tmp_bfr, ttl .Full_txt_w_ttl_case())); // NOTE: Full_txt b/c title always includes ns, // even if show_ns is off; // PAGE:en.b:Wikibooks:WikiProject DATE:2016-01-20 if (itm.No_follow()) bfr.Add(Bry_nofollow); bfr.Add_byte(Byte_ascii.Gt); Xoh_html_wtr_escaper.Escape( amp_mgr, bfr, ttl_page_txt, 0, ttl_page_txt.length, false, false); bfr.Add(Gfh_bldr_.Bry__a_rhs).Add(html_mode.Itm_end()).Add_byte_nl(); // TODO_OLD: // lnki_wtr.Clear().Href_wiki_(ttl).Title_(ttl).Nofollow_().Write_head(bfr).Write_text(bfr).Write_tail(bfr) break; default: break; } } bfr.Add(html_mode.Grp_end()).Add_byte_nl(); } finally { tmp_bfr.Mkr_rls(); } }
public void Tbl_outer(Bry_bfr bfr, Bry_bfr html_bfr) { bfr.Add(Outer_tbl_bgn); bfr.Add_bfr_and_clear(html_bfr); bfr.Add(Outer_tbl_end); }