public class Xob_xfer_regy_log_tbl { public static void Create_table(Db_conn p) { gplx.dbs.engines.sqlite.Sqlite_engine_.Tbl_create_and_delete(p, Tbl_name, Tbl_sql); } public static Db_stmt Insert_stmt(Db_conn p) { return Db_stmt_.new_insert_( p, Tbl_name, Fld_lnki_id, Fld_xfer_status, Fld_xfer_bin_tid, Fld_xfer_bin_msg); } public static void Insert(Db_stmt stmt, byte status, int id, byte wkr_tid, String wkr_msg) { stmt.Clear().Val_int(id).Val_byte(status).Val_byte(wkr_tid).Val_str(wkr_msg).Exec_insert(); } private static final String Tbl_sql = String_.Concat_lines_nl( "CREATE TABLE IF NOT EXISTS xfer_regy_log", "( lnki_id integer NOT NULL", ", xfer_status tinyint NOT NULL" // 0=todo; 1=fail; 2=pass; 3=done , ", xfer_bin_tid tinyint NOT NULL", ", xfer_bin_msg varchar(255) NOT NULL", ");"); public static final String Tbl_name = "xfer_regy_log", Fld_lnki_id = "lnki_id", Fld_xfer_status = "xfer_status", Fld_xfer_bin_tid = "xfer_bin_tid", Fld_xfer_bin_msg = "xfer_bin_msg"; }
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"); }
public class Xob_xfer_temp_cmd_thumb extends Xob_itm_basic_base implements Xob_cmd { public Xob_xfer_temp_cmd_thumb(Xob_bldr bldr, Xowe_wiki wiki) { this.Cmd_ctor(bldr, wiki); } public String Cmd_key() { return Xob_cmd_keys.Key_file_xfer_temp_thumb; } public void Cmd_init(Xob_bldr bldr) {} public void Cmd_bgn(Xob_bldr bldr) { Db_conn conn = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir()).Conn(); Xob_xfer_temp_tbl.Create_table(conn); Db_stmt trg_stmt = Xob_xfer_temp_tbl.Insert_stmt(conn); conn.Txn_bgn(); DataRdr rdr = conn.Exec_sql_as_rdr(Sql_select); Xob_xfer_temp_itm temp_itm = new Xob_xfer_temp_itm(); Xof_img_size img_size = new Xof_img_size(); byte[] cur_ttl = Bry_.Empty; byte cur_repo = Byte_.Max_value_127; while (rdr.MoveNextPeer()) { temp_itm.Clear(); temp_itm.Load(rdr); if (Bry_.Eq(cur_ttl, temp_itm.Orig_file_ttl())) { // same ttl; DATE:2015-03-22 if (temp_itm.Orig_repo() != cur_repo) // if repo is different, ignore 2nd; handles images in both repos; take 1st // only (which should be local) continue; } else { // new ttl; update ttl, repo cur_ttl = temp_itm.Orig_file_ttl(); cur_repo = temp_itm.Orig_repo(); } if (temp_itm.Chk(img_size)) temp_itm.Insert(trg_stmt, img_size); } conn.Txn_end(); } public void Cmd_run() {} public void Cmd_end() {} public void Cmd_term() {} private static final String Sql_select = String_.Concat_lines_nl( "SELECT l.lnki_id", ", l.lnki_tier_id", ", l.lnki_page_id", ", l.lnki_ext", ", l.lnki_type", ", l.lnki_src_tid", ", l.lnki_w", ", l.lnki_h", ", l.lnki_upright", ", l.lnki_time", ", l.lnki_page", ", l.lnki_count", ", o.orig_repo", ", o.orig_page_id", ", o.orig_file_ttl", ", o.orig_file_ext", ", o.orig_file_id", ", o.lnki_ttl", ", o.orig_w", ", o.orig_h", ", o.orig_media_type", ", o.orig_minor_mime", "FROM lnki_regy l", " JOIN orig_regy o ON o.lnki_ttl = l.lnki_ttl", "WHERE o.orig_file_ttl IS NOT NULL", "ORDER BY o.orig_file_ttl, o.orig_repo DESC, l.lnki_w DESC" // NOTE: local=1,common=0; // DATE:2015-03-22 ); }