Пример #1
0
 private static void To_html_atr(Bry_bfr bfr, String key, String val) {
   bfr.Add_byte_space();
   bfr.Add_str_a7(key);
   bfr.Add_byte(Byte_ascii.Eq);
   bfr.Add_byte(Byte_ascii.Quote);
   bfr.Add_str_a7(val);
   bfr.Add_byte(Byte_ascii.Quote);
 }
Пример #2
0
 public void To_html(Bry_bfr bfr) {
   bfr.Add_byte(Byte_ascii.Angle_bgn);
   bfr.Add(node);
   To_html_atr(bfr, "data-source", "xowa");
   int len = atrs.length;
   for (int i = 0; i < len; ++i) {
     Keyval atr = atrs[i];
     To_html_atr(bfr, atr.Key(), atr.Val_to_str_or_empty());
   }
   bfr.Add_byte(Byte_ascii.Angle_end);
   if (!Bry_.Eq(node, Gfh_tag_.Bry__link)) {
     if (body != null) {
       bfr.Add_byte_nl();
       bfr.Add(body);
       bfr.Add_byte_nl();
     }
     bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash);
     bfr.Add(node);
     bfr.Add_byte(Byte_ascii.Angle_end);
   }
   bfr.Add_byte_nl();
 }
Пример #3
0
 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);
 }
Пример #4
0
	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;}
	}
Пример #5
0
 public byte[] Replace(Bry_bfr tmp_bfr, byte[] src, int bgn, int end) {
   int pos = bgn;
   boolean dirty = false;
   while (pos < end) {
     byte b = src[pos];
     Object o = this.Match_bgn_w_byte(b, src, pos, end);
     if (o == null) {
       if (dirty) tmp_bfr.Add_byte(b);
       pos++;
     } else {
       if (!dirty) {
         tmp_bfr.Add_mid(src, bgn, pos);
         dirty = true;
       }
       tmp_bfr.Add((byte[]) o);
       pos = match_pos;
     }
   }
   return dirty ? tmp_bfr.Xto_bry_and_clear() : src;
 }
 public byte[] Convert_to_local_urls(byte[] rel_url_prefix, byte[] src, List_adp list) {
   try {
     int src_len = src.length;
     int prv_pos = 0;
     Bry_bfr bfr = Bry_bfr_.New_w_size(src_len);
     Hash_adp img_hash = Hash_adp_bry.cs();
     while (true) {
       int url_pos = Bry_find_.Find_fwd(src, Bry_url, prv_pos);
       if (url_pos == Bry_find_.Not_found) {
         bfr.Add_mid(src, prv_pos, src_len);
         break;
       } // no more "url("; exit;
       int bgn_pos = url_pos + Bry_url_len; // set bgn_pos after "url("
       byte bgn_byte = src[bgn_pos];
       byte end_byte = Byte_ascii.Null;
       boolean quoted = true;
       switch (bgn_byte) { // find end_byte
         case Byte_ascii.Quote:
         case Byte_ascii.Apos: // quoted; end_byte is ' or "
           end_byte = bgn_byte;
           ++bgn_pos;
           break;
         default: // not quoted; end byte is ")"
           end_byte = Byte_ascii.Paren_end;
           quoted = false;
           break;
       }
       int end_pos = Bry_find_.Find_fwd(src, end_byte, bgn_pos, src_len);
       if (end_pos
           == Bry_find_.Not_found) { // unclosed "url("; exit since nothing else will be found
         usr_dlg.Warn_many(
             GRP_KEY,
             "parse.invalid_url.end_missing",
             "could not find end_sequence for 'url(': bgn='~{0}' end='~{1}'",
             prv_pos,
             String_.new_u8__by_len(src, prv_pos, prv_pos + 25));
         bfr.Add_mid(src, prv_pos, src_len);
         break;
       }
       if (end_pos - bgn_pos == 0) { // empty; "url()"; ignore
         usr_dlg.Warn_many(
             GRP_KEY,
             "parse.invalid_url.empty",
             "'url(' is empty: bgn='~{0}' end='~{1}'",
             prv_pos,
             String_.new_u8__by_len(src, prv_pos, prv_pos + 25));
         bfr.Add_mid(src, prv_pos, bgn_pos);
         prv_pos = bgn_pos;
         continue;
       }
       byte[] img_raw = Bry_.Mid(src, bgn_pos, end_pos);
       int img_raw_len = img_raw.length;
       if (Bry_.Has_at_bgn(img_raw, Bry_data_image, 0, img_raw_len)) { // base64
         bfr.Add_mid(src, prv_pos, end_pos); // nothing to download; just add entire String
         prv_pos = end_pos;
         continue;
       }
       int import_url_end =
           Import_url_chk(
               rel_url_prefix,
               src,
               src_len,
               prv_pos,
               url_pos,
               img_raw,
               bfr); // check for embedded stylesheets via @import tag
       if (import_url_end != Bry_find_.Not_found) {
         prv_pos = import_url_end;
         continue;
       }
       byte[] img_cleaned = Xob_url_fixer.Fix(wiki_domain, img_raw, img_raw_len);
       if (img_cleaned == null) { // could not clean img
         usr_dlg.Warn_many(
             GRP_KEY,
             "parse.invalid_url.clean_failed",
             "could not extract valid http src: bgn='~{0}' end='~{1}'",
             prv_pos,
             String_.new_u8(img_raw));
         bfr.Add_mid(src, prv_pos, bgn_pos);
         prv_pos = bgn_pos;
         continue;
       }
       if (!img_hash.Has(img_cleaned)) { // only add unique items for download;
         img_hash.Add_as_key_and_val(img_cleaned);
         list.Add(String_.new_u8(img_cleaned));
       }
       img_cleaned =
           Replace_invalid_chars(
               Bry_.Copy(
                   img_cleaned)); // NOTE: must call ByteAry.Copy else img_cleaned will change
                                  // *inside* hash
       bfr.Add_mid(src, prv_pos, bgn_pos);
       if (!quoted) bfr.Add_byte(Byte_ascii.Quote);
       bfr.Add(img_cleaned);
       if (!quoted) bfr.Add_byte(Byte_ascii.Quote);
       prv_pos = end_pos;
     }
     return bfr.To_bry_and_clear();
   } catch (Exception e) {
     usr_dlg.Warn_many(
         "",
         "",
         "failed to convert local_urls: ~{0} ~{1}",
         String_.new_u8(rel_url_prefix),
         Err_.Message_gplx_full(e));
     return src;
   }
 }
Пример #7
0
 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();
   }
 }
Пример #8
0
 public void XferAry(Bry_bfr trg, int idx) {
   trg.Add_byte(byt);
 }