@Test public void Bidi() { fxt.Init_ttl("A" + String_.new_u8(Bry_.ints_(226, 128, 142)) + "B").Expd_page_txt("AB").Test(); fxt.Init_ttl("A" + String_.new_u8(Bry_.ints_(226, 128, 97)) + "B") .Expd_page_txt("A" + String_.new_u8(Bry_.ints_(226, 128, 97)) + "B") .Test(); }
Xof_repo_itm Ini_repo_add(Xof_file_mgr file_mgr, byte[] key, String root, String wiki, boolean trg) { Xof_repo_itm repo = file_mgr.Repo_mgr().Set(String_.new_u8(key), root, wiki).Ext_rules_(Xof_rule_grp.Grp_app_default).Dir_depth_(2); if (trg) { byte[][] ary = repo.Mode_names(); ary[0] = Bry_.new_a7("raw"); ary[1] = Bry_.new_a7("fit"); } return repo; }
public static Xopg_tag_itm New_js_file(Io_url src_url) { byte[] src = src_url.To_http_file_bry(); return new Xopg_tag_itm( Tid__js_file, Gfh_tag_.Bry__script, src, null, Tag__type_js, Keyval_.new_("src", String_.new_u8(src))); }
private static boolean Navigate( Gfo_usr_dlg usr_dlg, Xoae_app app, Wdata_wiki_mgr wdata_mgr, Xoae_page page, byte[] site_bry, byte[] page_bry) { page_bry = Xoa_app_.Utl__encoder_mgr() .Http_url() .Decode(page_bry); // NOTE: space is converted to + on postback to url; decode byte[] wiki_domain = Xow_wiki_alias.Parse_wmf_key(site_bry); if (wiki_domain == null) { usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_u8(site_bry)); return false; } Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) { usr_dlg.Warn_many( "", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_u8(wiki_domain)); return false; } Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) { usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false; } Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) { usr_dlg.Warn_many( "", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_u8(wdata_ttl.Raw())); return false; } byte[] qid_bry = doc.Qid(); Xoae_page qid_page = wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (qid_page.Missing()) { usr_dlg.Warn_many( "", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_u8(qid_bry)); return false; } return true; }
public static Xopg_tag_itm New_css_file(Io_url href_url) { byte[] href = href_url.To_http_file_bry(); return new Xopg_tag_itm( Tid__css_file, Gfh_tag_.Bry__link, href, null, Tag__type_css, Tag__rel_stylesheet, Keyval_.new_("href", String_.new_u8(href))); }
String file_svg(int w, int h) {return String_.Format("<svg width=\"{0}\" height=\"{1}\" />", w, h);}
String file_img(int w, int h) {return String_.Format("{0},{1}", w, h);}
public Io_fil reg_(String url, String... v) {return new Io_fil(Io_url_.mem_fil_(url), String_.Concat_lines_nl(v));}
public class Wdata_itemByTitle_page implements Xows_page { private Xoa_url_arg_hash arg_hash = new Xoa_url_arg_hash(); private static final byte[] Arg_site = Bry_.new_a7("site"), Arg_page = Bry_.new_a7("page"); public Bry_fmtr Html_fmtr() { return html_fmtr; } private Wdata_itemByTitle_cfg cfg; public Xows_special_meta Special_meta() { return Xows_special_meta_.Itm__item_by_title; } 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 } private static boolean Navigate( Gfo_usr_dlg usr_dlg, Xoae_app app, Wdata_wiki_mgr wdata_mgr, Xoae_page page, byte[] site_bry, byte[] page_bry) { page_bry = Xoa_app_.Utl__encoder_mgr() .Http_url() .Decode(page_bry); // NOTE: space is converted to + on postback to url; decode byte[] wiki_domain = Xow_wiki_alias.Parse_wmf_key(site_bry); if (wiki_domain == null) { usr_dlg.Warn_many("", "", "site_bry parse failed; site_bry:~{0}", String_.new_u8(site_bry)); return false; } Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain); if (wiki == null) { usr_dlg.Warn_many( "", "", "wiki_domain does not exist; wiki_domain:~{0}", String_.new_u8(wiki_domain)); return false; } Xoa_ttl wdata_ttl = Xoa_ttl.parse_(wiki, page_bry); if (wdata_ttl == null) { usr_dlg.Warn_many("", "", "ttl is invalid; ttl:~{0}", String_.new_u8(page_bry)); return false; } Wdata_doc doc = wdata_mgr.Pages_get(wiki, wdata_ttl); if (doc == null) { usr_dlg.Warn_many( "", "", "ttl cannot be found in wikidata; ttl:~{0}", String_.new_u8(wdata_ttl.Raw())); return false; } byte[] qid_bry = doc.Qid(); Xoae_page qid_page = wdata_mgr.Wdata_wiki().Data_mgr().Redirect(page, qid_bry); if (qid_page.Missing()) { usr_dlg.Warn_many( "", "", "qid cannot be found in wikidata; qid:~{0}", String_.new_u8(qid_bry)); return false; } return true; } private static Bry_fmtr html_fmtr = Bry_fmtr.new_( String_.Concat_lines_nl( "<div id=\"mw-content-text\">", "<form method=\"get\" action=\"//www.wikidata.org/wiki/Special:ItemByTitle\" name=\"itembytitle\" id=\"wb-itembytitle-form1\">", "<fieldset>", "<legend>~{legend}</legend>", "<label for=\"wb-itembytitle-sitename\">~{site_lbl}:</label>", "<input id=\"wb-itembytitle-sitename\" size=\"12\" name=\"site\" value=\"~{site_val}\" accesskey=\"s\" />", "", "<label for=\"pagename\">~{page_lbl}:</label>", "<input id=\"pagename\" size=\"36\" class=\"wb-input-text\" name=\"page\" value=\"~{page_val}\" accesskey=\"p\" />", "", "<input id=\"wb-itembytitle-submit\" class=\"wb-input-button\" type=\"submit\" value=\"~{search_lbl}\" name=\"submit\" />", "</fieldset>", "</form>", "</div>", "<br>To change the default site, see <a href='/site/home/wiki/Help:Options/Wikibase'>Help:Options/Wikibase</a>"), "legend", "site_lbl", "site_val", "page_lbl", "page_val", "search_lbl"); }
String Make_key(int ns_id, byte[] ttl) { return Int_.To_str(ns_id) + "|" + String_.new_u8(ttl); }
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;} }