mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.4.3.1
This commit is contained in:
@@ -60,6 +60,7 @@ public class Db_cfg_tbl implements RlsAble {
|
||||
if (stmt_update == null) stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_grp, fld_key);
|
||||
stmt_update.Clear().Val_str(fld_val, val).Crt_str(fld_grp, grp).Crt_str(fld_key, key).Exec_update();
|
||||
}
|
||||
public void Upsert_int (String grp, String key, int val) {Upsert_str(grp, key, Int_.Xto_str(val));}
|
||||
public void Upsert_str (String grp, String key, String val) {
|
||||
String cur_val = this.Select_str_or(grp, key, null);
|
||||
if (cur_val == null) this.Insert_str(grp, key, val);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Fsdb_db_file {
|
||||
this.url = url; this.conn = conn;
|
||||
this.tbl__core_cfg = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
}
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Db_cfg_tbl Tbl__cfg() {return tbl__core_cfg;} private final Db_cfg_tbl tbl__core_cfg;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Db_cfg_tbl Tbl__cfg() {return tbl__core_cfg;} private final Db_cfg_tbl tbl__core_cfg;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.fsdb; import gplx.*;
|
||||
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.data.*;
|
||||
public class Fsdb_db_mgr_ {
|
||||
public static Fsdb_db_mgr new_detect(String domain_str, Io_url wiki_dir, Io_url file_dir) {
|
||||
public static Fsdb_db_mgr new_detect(Xow_wiki wiki, Io_url wiki_dir, Io_url file_dir) {
|
||||
Gfo_usr_dlg usr_dlg = Xoa_app_.Usr_dlg();
|
||||
String domain_str = wiki.Domain_str();
|
||||
Fsdb_db_mgr rv = null;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_few, usr_dlg, wiki_dir, domain_str); if (rv != null) return rv;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_lot, usr_dlg, wiki_dir, domain_str); if (rv != null) return rv;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_all, usr_dlg, wiki_dir, domain_str); if (rv != null) return rv;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_few, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_lot, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
|
||||
rv = load_or_null(Xowd_db_layout.Itm_all, usr_dlg, wiki_dir, wiki, domain_str); if (rv != null) return rv;
|
||||
Io_url url = file_dir.GenSubFil(Fsdb_db_mgr__v1.Mnt_name); // EX: /xowa/file/en.wikipedia.org/wiki.mnt.sqlite3
|
||||
if (Db_conn_bldr.I.Exists(url)) {
|
||||
usr_dlg.Log_many("", "", "fsdb.db_core.v1: url=~{0}", url.Raw());
|
||||
@@ -32,13 +33,15 @@ public class Fsdb_db_mgr_ {
|
||||
usr_dlg.Log_many("", "", "fsdb.db_core.none: wiki_dir=~{0} file_dir=~{1}", wiki_dir.Raw(), file_dir.Raw());
|
||||
return null;
|
||||
}
|
||||
private static Fsdb_db_mgr load_or_null(Xowd_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, String domain_str) {
|
||||
private static Fsdb_db_mgr load_or_null(Xowd_db_layout layout, Gfo_usr_dlg usr_dlg, Io_url wiki_dir, Xow_wiki wiki, String domain_str) {
|
||||
Io_url main_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Main_core_name(layout, domain_str));
|
||||
if (!Db_conn_bldr.I.Exists(main_core_url)) return null;
|
||||
usr_dlg.Log_many("", "", "fsdb.db_core.v2: type=~{0} url=~{1}", layout.Name(), main_core_url.Raw());
|
||||
Db_conn main_core_conn = Db_conn_bldr.I.Get(main_core_url);
|
||||
Io_url user_core_url = wiki_dir.GenSubFil(Fsdb_db_mgr__v2_bldr.Make_user_name(domain_str));
|
||||
Db_conn user_core_conn = Db_conn_bldr.I.Get(user_core_url);
|
||||
if (!Db_conn_bldr.I.Exists(user_core_url)) // if user file does not exist, create it; needed b/c offline packages don't include file; DATE:2015-04-19
|
||||
Fsdb_db_mgr__v2_bldr.I.Make_core_file_user(wiki, wiki_dir, user_core_url.NameAndExt(), main_core_url.NameAndExt());
|
||||
Db_conn user_core_conn = Db_conn_bldr.I.Get(user_core_url);
|
||||
return new Fsdb_db_mgr__v2(Fsdb_db_mgr__v2.Cfg__layout_file__get(main_core_conn), wiki_dir, new Fsdb_db_file(main_core_url, main_core_conn), new Fsdb_db_file(user_core_url, user_core_conn));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ public class Fsdb_db_mgr__v2 implements Fsdb_db_mgr {
|
||||
if (layout.Tid_is_all_or_few()) return file_main_core;
|
||||
Io_url url = wiki_dir.GenSubFil(file_name);
|
||||
Db_conn conn = Db_conn_bldr.I.Get(url);
|
||||
if (conn == null) { // bin file deleted or not downloaded; use Noop Db_conn and continue; do not fail; DATE:2015-04-16
|
||||
Gfo_usr_dlg_.I.Warn_many("", "", "fsdb.bin:file does not exist; url=~{0}", url);
|
||||
conn = Db_conn_.Empty;
|
||||
}
|
||||
return new Fsdb_db_file(url, conn);
|
||||
}
|
||||
public Fsdb_db_file File__bin_file__new(int mnt_id, String file_name) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Fsdb_db_mgr__v2_bldr {
|
||||
conn.Txn_end();
|
||||
return rv;
|
||||
}
|
||||
private Fsdb_db_file Make_core_file_user(Xowe_wiki wiki, Io_url wiki_dir, String user_file_name, String main_core_name) { // always create file; do not create mnt_tbl;
|
||||
public Fsdb_db_file Make_core_file_user(Xow_wiki wiki, Io_url wiki_dir, String user_file_name, String main_core_name) { // always create file; do not create mnt_tbl;
|
||||
Io_url url = wiki_dir.GenSubFil(user_file_name);
|
||||
Db_conn conn = Db_conn_bldr.I.New(url);
|
||||
conn.Txn_bgn();
|
||||
@@ -91,11 +91,11 @@ public class Fsdb_db_mgr__v2_bldr {
|
||||
default: throw Err_.not_implemented_();
|
||||
}
|
||||
}
|
||||
public static void Make_cfg_data(Xowe_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
|
||||
public static void Make_cfg_data(Xow_wiki wiki, String file_core_name, Fsdb_db_file file, byte file_tid, int part_id) {
|
||||
Db_cfg_tbl cfg_tbl = file.Tbl__cfg();
|
||||
Xowd_db_file core_db = wiki.Data_mgr__core_mgr().Db__core();
|
||||
core_db.Info_session().Save(cfg_tbl);
|
||||
Xob_info_file info_file = new Xob_info_file(-1, Xowd_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.random_(), 2, file_core_name, file.Url().NameAndExt());
|
||||
Xob_info_file info_file = new Xob_info_file(-1, Xowd_db_file_.To_key(file_tid), Xob_info_file.Ns_ids_empty, part_id, Guid_adp_.new_(), 2, file_core_name, file.Url().NameAndExt());
|
||||
info_file.Save(cfg_tbl);
|
||||
}
|
||||
private static String Main_core_name_all(String wiki_domain) {return wiki_domain + ".xowa";} // EX: en.wikipedia.org.xowa
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Fsd_fil_tbl implements RlsAble {
|
||||
.Val_int(fld_bin_db_id, bin_db_id)
|
||||
.Val_bry_as_str(fld_name, name)
|
||||
.Val_long(fld_size, size)
|
||||
.Val_str(fld_modified, String_.Empty)
|
||||
.Val_str(fld_hash, String_.Empty)
|
||||
.Crt_int(fld_id, id)
|
||||
.Exec_update();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xoa_app_ {
|
||||
boot_mgr.Run(args);
|
||||
}
|
||||
public static final String Name = "xowa";
|
||||
public static final String Version = "2.4.2.1";
|
||||
public static final String Version = "2.4.3.1";
|
||||
public static String Build_date = "2012-12-30 00:00:00";
|
||||
public static String Op_sys;
|
||||
public static String User_agent = "";
|
||||
|
||||
@@ -156,9 +156,9 @@ public class Xoae_app implements Xoa_app, GfoInvkAble {
|
||||
if (setup_mgr.Cmd_mgr().Working()) {
|
||||
if (!gui_mgr.Kit().Ask_yes_no("", "", "An import is in progress. Are you sure you want to exit?")) return false;
|
||||
}
|
||||
if (!gui_mgr.Browser_win().Tab_mgr().Tabs__pub_close_all()) return false;
|
||||
gui_mgr.Browser_win().Usr_dlg().Canceled_y_();
|
||||
user.App_term(); usr_dlg.Log_many("", "", "term:app_term");
|
||||
gui_mgr.Browser_win().Tab_mgr().Tabs_close_all();
|
||||
log_wtr.Term(); usr_dlg.Log_many("", "", "term:log_wtr");
|
||||
log_mgr.Rls(); usr_dlg.Log_many("", "", "term:log_mgr");
|
||||
if (Scrib_core.Core() != null) {Scrib_core.Core().Term(); usr_dlg.Log_many("", "", "term:scrib");}
|
||||
|
||||
@@ -16,19 +16,39 @@ 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.apis.xowa.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.apis.*; import gplx.xowa.apis.xowa.*;
|
||||
public class Xoapi_search implements GfoInvkAble {
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.crts.*;
|
||||
public class Xoapi_search implements GfoInvkAble, GfoEvMgrOwner {
|
||||
private final Xow_domain_crt_kv_mgr multi_wiki_rules_mgr = new Xow_domain_crt_kv_mgr(); private String multi_wiki_rules_str = "*.*|<self>";
|
||||
public Xoapi_search() {
|
||||
this.evMgr = GfoEvMgr.new_(this);
|
||||
}
|
||||
public GfoEvMgr EvMgr() {return evMgr;} private GfoEvMgr evMgr;
|
||||
public int Results_per_page() {return results_per_page;} private int results_per_page = 20;
|
||||
public boolean Async_db() {return async_db;} private boolean async_db = true;
|
||||
public void Multi_wiki_rule_str_(String v) {
|
||||
if (!multi_wiki_rules_mgr.Parse(Bry_.new_utf8_(v))) return;
|
||||
this.multi_wiki_rules_str = v;
|
||||
GfoEvMgr_.PubVal(this, Evt_multi_wiki_rules_changed, v);
|
||||
}
|
||||
public Xow_domain_crt_itm Multi_wiki_crt(Xow_domain cur_domain) {
|
||||
return multi_wiki_rules_mgr.Find(cur_domain, cur_domain);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_results_per_page)) return results_per_page;
|
||||
else if (ctx.Match(k, Invk_results_per_page_)) results_per_page = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_async_db)) return Yn.Xto_str(async_db);
|
||||
else if (ctx.Match(k, Invk_async_db_)) async_db = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_multi_wiki_rules)) return multi_wiki_rules_str;
|
||||
else if (ctx.Match(k, Invk_multi_wiki_rules_)) multi_wiki_rules_str = m.ReadStr("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String
|
||||
Invk_results_per_page = "results_per_page" , Invk_results_per_page_ = "results_per_page_"
|
||||
, Invk_async_db = "async_db" , Invk_async_db_ = "async_db_"
|
||||
, Invk_multi_wiki_rules = "multi_wiki_rules" , Invk_multi_wiki_rules_ = "multi_wiki_rules_"
|
||||
;
|
||||
public static final String
|
||||
Evt_multi_wiki_rules_changed = "multi_wiki_rules_changed"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
// trg_mnt_itm
|
||||
this.trg_bin_db_max = app.Api_root().Bldr().Wiki().Import().File_db_max();
|
||||
Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki.Domain_str(), wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
Fsdb_db_mgr trg_db_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
if (trg_db_mgr == null) trg_db_mgr = Fsdb_db_mgr__v2_bldr.I.Make(wiki);
|
||||
Fsm_mnt_mgr trg_mnt_mgr = new Fsm_mnt_mgr(); trg_mnt_mgr.Ctor_by_load(trg_db_mgr);
|
||||
trg_mnt_mgr.Mnts__get_insert_idx_(Fsm_mnt_mgr.Mnt_idx_main); // NOTE: do not delete; mnt_mgr default to Mnt_idx_user; DATE:2014-04-25
|
||||
@@ -119,7 +119,7 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
public void Cmd_end() {
|
||||
usr_dlg.Note_many("", "", "fsdb_make.done: count=~{0} rate=~{1}", exec_count, DecimalAdp_.divide_safe_(exec_count, Env_.TickCount_elapsed_in_sec(time_bgn)).Xto_str("#,###.000"));
|
||||
src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end();
|
||||
if (src_fsdb_wkr != null) src_fsdb_wkr.Mnt_mgr().Mnts__get_main().Txn_end(); // NOTE: src_fsdb_wkr will be null if no src db defined
|
||||
trg_atr_fil.Conn().Txn_end(); trg_atr_fil.Conn().Rls_conn();
|
||||
if (!trg_mnt_itm.Db_mgr().File__solo_file()) {
|
||||
trg_bin_fil.Conn().Txn_end(); trg_bin_fil.Conn().Rls_conn();
|
||||
@@ -303,10 +303,10 @@ public class Xob_fsdb_make_cmd extends Xob_itm_basic_base implements Xob_cmd {
|
||||
}
|
||||
else if (String_.Eq(version, "v2")) {
|
||||
url = wiki.Fsys_mgr().Root_dir().GenSubDir("prv"); // v2: EX: /xowa/wiki/en.wikipedia.org/prv/
|
||||
rv = Fsdb_db_mgr_.new_detect(domain_str, url, url); // note that v2 is prioritized over v1
|
||||
rv = Fsdb_db_mgr_.new_detect(wiki, url, url); // note that v2 is prioritized over v1
|
||||
}
|
||||
else throw Err_.new_("fsdb.make:unknown fsdb_type; version={0}", version);
|
||||
if (!Io_mgr._.ExistsFil(rv.File__mnt_file().Url())) throw Err_.new_("fsdb.make:source fsdb not found; version={0} url={1}", version, url.Raw());
|
||||
if (rv == null) throw Err_.new_("fsdb.make:source fsdb not found; version={0} url={1}", version, url.Raw());
|
||||
return rv;
|
||||
}
|
||||
private static final byte Select_rv_stop = 0, Select_rv_process = 1, Select_rv_next_page = 2;
|
||||
|
||||
@@ -27,6 +27,7 @@ public class Xob_term_cmd extends Xob_term_base {
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.main_page", wiki.Props().Main_page());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_misc", wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Insert_bry(Xow_cfg_consts.Grp_wiki_init, "props.siteinfo_mainpage", wiki.Props().Siteinfo_mainpage());
|
||||
// gplx.fsdb.Fsdb_db_mgr__v2_bldr.I.Make(wiki);// bld wiki
|
||||
wiki.Data_mgr__core_mgr().Rls();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ public class Xob_info_session {
|
||||
, Cfg_key__time = "time" // EX: 20150102 030405
|
||||
, Cfg_key__guid = "guid" // EX: 00000000-0000-0000-0000-000000000000
|
||||
;
|
||||
public static Xob_info_session new_(String user, String wiki_domain, String dump_name) {return new Xob_info_session(user, Xoa_app_.Version, wiki_domain, dump_name, DateAdp_.Now(), Guid_adp_.Empty);}
|
||||
public static Xob_info_session new_(String user, String wiki_domain, String dump_name) {return new Xob_info_session(user, Xoa_app_.Version, wiki_domain, dump_name, DateAdp_.Now(), Guid_adp_.new_());}
|
||||
public static final Xob_info_session Test = new_("anonymous", "en.wikipedia.org", "enwiki-latest-pages-articles");
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class Xol_mw_lang_parser {
|
||||
try {
|
||||
Xol_lang lang = lang_mgr.Get_by_key_or_new(Bry_.new_utf8_(fil.NameOnly()));
|
||||
Xob_i18n_parser.Load_msgs(true, lang, fil);
|
||||
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText(String_.Format("failed to parse json file; url={0} err={1}", fil.Raw(), Err_.Message_gplx_brief(exc)));}
|
||||
} catch (Exception exc) {Err_.Noop(exc); Tfds.WriteText(String_.Format("failed to parse json file; url={0} err={1}\n", fil.Raw(), Err_.Message_gplx_brief(exc)));}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
if (cur_page_id > max_page_id) max_page_id = cur_page_id;
|
||||
}
|
||||
page_id = max_page_id + 1;
|
||||
db_mgr.Core_data_mgr().Tbl__cfg().Insert_int("db", "page.id_next", page_id + 1);
|
||||
db_mgr.Core_data_mgr().Tbl__cfg().Upsert_int("db", "page.id_next", page_id + 1);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
page_core_tbl.Insert_bgn();
|
||||
page_text_tbl.Insert_bgn();
|
||||
try {
|
||||
page_mgr.Create(page_core_tbl, page_text_tbl, page_id, ns_id, text_raw, redirect, DateAdp_.Now(), text_zip, text_raw.length, ns_count, page_text_db.Id(), -1);
|
||||
page_mgr.Create(page_core_tbl, page_text_tbl, page_id, ns_id, ttl.Page_db(), redirect, DateAdp_.Now(), text_zip, text_raw.length, ns_count, page_text_db.Id(), -1);
|
||||
db_file.Tbl__ns().Update_ns_count(ns_id, ns_count);
|
||||
db_file.Tbl__cfg().Update_int("db", "page.id_next", page_id + 1);
|
||||
} finally {
|
||||
|
||||
@@ -29,7 +29,7 @@ public interface Xof_file_itm {
|
||||
byte Orig_repo_id();
|
||||
byte[] Orig_repo_name();
|
||||
byte[] Orig_ttl();
|
||||
int Orig_ext();
|
||||
Xof_ext Orig_ext();
|
||||
int Orig_w();
|
||||
int Orig_h();
|
||||
byte[] Orig_redirect();
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
|
||||
}
|
||||
public static void Show_img(byte exec_tid, Xof_fsdb_itm fsdb, Gfo_usr_dlg usr_dlg, Xof_bin_mgr bin_mgr, Fsm_mnt_mgr mnt_mgr, Xof_cache_mgr cache_mgr, Xow_repo_mgr repo_mgr, Xog_js_wkr js_wkr, Xof_img_size img_size, Xof_url_bldr url_bldr, Xoa_page hpg) {
|
||||
try {
|
||||
if (fsdb.Orig_ext() < 0) {
|
||||
if (fsdb.Orig_ext() == null) {
|
||||
usr_dlg.Warn_many("", "", "file.missing.ext: file=~{0} width=~{1} page=~{2}", fsdb.Lnki_ttl(), fsdb.Lnki_w(), hpg.Ttl().Full_db());
|
||||
return;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Xof_file_wkr implements Gfo_thread_wkr {
|
||||
byte repo_id = orig.Repo();
|
||||
Xof_repo_pair repo_pair = repo_mgr.Repos_get_by_id(repo_id);
|
||||
Xof_repo_itm repo_itm = repo_pair.Trg();
|
||||
fsdb.Ctor_by_orig(repo_id, repo_pair.Wiki_domain(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
|
||||
fsdb.Ctor_by_orig(repo_id, repo_pair.Wiki_domain(), orig.Page(), Xof_ext_.new_by_id_(orig.Ext()), orig.W(), orig.H(), orig.Redirect());
|
||||
fsdb.Ctor_for_html(exec_tid, img_size, repo_itm, url_bldr);
|
||||
}
|
||||
private static void Save_bin(Xof_fsdb_itm itm, Fsm_mnt_mgr mnt_mgr) {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Xof_img_size {
|
||||
}
|
||||
public void Html_size_calc(byte exec_tid, int lnki_w, int lnki_h, byte lnki_type, int upright_patch, double lnki_upright, int lnki_ext, int orig_w, int orig_h, int thm_dflt_w) {
|
||||
this.Clear(); // always clear before calc; caller should be responsible, but just to be safe.
|
||||
if (lnki_type == Xop_lnki_type.Id_frame // frame: always return orig size; Linker.php!makeThumbLink2; // Use image dimensions, don't scale
|
||||
if (Enm_.HasInt(lnki_type, Xop_lnki_type.Id_frame) // frame: always return orig size; Linker.php!makeThumbLink2; // Use image dimensions, don't scale
|
||||
&& lnki_h == Null) { // unless lnki_h specified; DATE:2013-12-22
|
||||
html_w = file_w = orig_w;
|
||||
html_h = file_h = orig_h;
|
||||
|
||||
@@ -74,6 +74,9 @@ public class Xof_img_size_tst {
|
||||
@Test public void Frame() { // PURPOSE: frame incorrectly defaulted to file_is_orig; [[File:MESSENGER.jpg|200x200px|framed]]; DATE:2013-12-22
|
||||
fxt.Lnki_type_(Xop_lnki_type.Id_frame).Lnki_ext_(Xof_ext_.Id_png).Lnki_(200, 200).Orig_(2038, 1529).Test_html(200, 150, Bool_.N);
|
||||
}
|
||||
@Test public void Frame_and_thumb(){ // PURPOSE: frame and thumb should be treated as frame; Enm.Has(val, Id_frame) vs val == Id_frame; PAGE:en.w:History_of_Western_Civilization; DATE:2015-04-16
|
||||
fxt.Lnki_type_(Enm_.Add_byte(Xop_lnki_type.Id_frame, Xop_lnki_type.Id_thumb)).Lnki_(200, -1).Test_html(400, 200, Bool_.Y); // mut return same as Lnki_lt_orig_frame above
|
||||
}
|
||||
}
|
||||
class Xof_img_size_fxt {
|
||||
private Xof_img_size img_size = new Xof_img_size();
|
||||
|
||||
@@ -65,6 +65,7 @@ public class Xof_url_bldr {
|
||||
public Io_url Xto_url() {Bld(); Io_url rv = Io_url_.new_fil_(bfr.Xto_str()); Clear(); return rv;}
|
||||
public Io_url To_url_trg(Xof_repo_itm repo_itm, Xof_fsdb_itm itm, boolean orig) {
|
||||
byte mode = orig ? Xof_repo_itm.Mode_orig : Xof_repo_itm.Mode_thumb;
|
||||
// return this.Init_for_trg_file(mode, repo_itm, itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), itm.Html_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
|
||||
return this.Init_for_trg_file(mode, repo_itm, itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), itm.Html_w(), itm.Lnki_time(), itm.Lnki_page()).Xto_url();
|
||||
}
|
||||
private void Bld() {
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_itm.Repo_null;
|
||||
public byte[] Orig_repo_name() {return orig_repo_name;} private byte[] orig_repo_name;
|
||||
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
|
||||
public int Orig_ext() {return orig_ext;} private int orig_ext;
|
||||
public Xof_ext Orig_ext() {return orig_ext;} private Xof_ext orig_ext;
|
||||
public int Orig_w() {return orig_w;} private int orig_w;
|
||||
public int Orig_h() {return orig_h;} private int orig_h;
|
||||
public byte[] Orig_redirect() {return orig_redirect;} private byte[] orig_redirect;
|
||||
@@ -66,7 +66,8 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public Xof_xfer_itm Url_bldr_(Xof_url_bldr v) {url_bldr = v; return this;} private Xof_url_bldr url_bldr = Xof_url_bldr.Temp;
|
||||
public Xof_xfer_itm Clear() {
|
||||
lnki_type = orig_repo_id = Byte_.Max_value_127;
|
||||
lnki_w = lnki_h = file_w = orig_ext = orig_w = orig_h = html_w = html_h = gallery_mgr_h = Int_.Neg1;
|
||||
lnki_w = lnki_h = file_w = orig_w = orig_h = html_w = html_h = gallery_mgr_h = Int_.Neg1;
|
||||
orig_ext = null;
|
||||
lnki_upright = Int_.Neg1; lnki_time = Xof_lnki_time.Null; lnki_page = Xof_lnki_page.Null;
|
||||
file_found = file_exists = img_is_thumbable = false;
|
||||
orig_file_len = 0; // NOTE: cannot be -1, or else will always download orig; see ext rule chk and (orig_file_len < 0)
|
||||
@@ -104,14 +105,16 @@ public class Xof_xfer_itm implements Xof_file_itm {
|
||||
public void Init_by_orig_old(int w, int h, int orig_file_len) {
|
||||
this.orig_w = w; this.orig_h = h; this.orig_file_len = orig_file_len;
|
||||
}
|
||||
public void Init_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, int orig_ext, int orig_w, int orig_h, byte[] orig_redirect, int orig_file_len) {
|
||||
public void Init_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, Xof_ext orig_ext, int orig_w, int orig_h, byte[] orig_redirect, int orig_file_len) {
|
||||
this.orig_repo_id = orig_repo_id; this.orig_repo_name = orig_repo_name;
|
||||
this.orig_ttl = orig_ttl; this.orig_ext = orig_ext;
|
||||
this.orig_w = orig_w; this.orig_h = orig_h; this.orig_redirect = orig_redirect;
|
||||
if (orig_ext != lnki_ext.Id())
|
||||
this.Lnki_ext_(Xof_ext_.new_by_id_(orig_ext)); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
|
||||
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
|
||||
if (orig_ext.Id() != lnki_ext.Id())
|
||||
this.Lnki_ext_(orig_ext); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
|
||||
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
|
||||
this.Lnki_ttl_(orig_redirect); // update fsdb with atrs of B.png
|
||||
else if (!Bry_.Eq(lnki_ttl, orig_ttl)) // ttls differ; EX: "A_.png" vs "A.png"
|
||||
this.Lnki_ttl_(orig_ttl);
|
||||
this.orig_file_len = orig_file_len;
|
||||
}
|
||||
private void Lnki_ttl_(byte[] v) {
|
||||
|
||||
@@ -115,7 +115,7 @@ public class Xow_file_mgr implements GfoInvkAble {
|
||||
}
|
||||
public void Init_file_mgr_by_load(Xow_wiki wiki) {
|
||||
if (db_core != null) return; // already init'd
|
||||
this.db_core = Fsdb_db_mgr_.new_detect(wiki.Domain_str(), wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
this.db_core = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
if (db_core == null ) return; // no fsdb_core found; exit
|
||||
this.version = Version_2;
|
||||
this.fsdb_mode = Xof_fsdb_mode.new_view();
|
||||
|
||||
@@ -62,43 +62,43 @@ public class Xof_bin_mgr {
|
||||
if (!Env_.Mode_testing()) cache_mgr.Reg(itm, rdr.Len());
|
||||
return trg;
|
||||
}
|
||||
public Io_stream_rdr Find_as_rdr(byte exec_tid, Xof_fsdb_itm itm) {
|
||||
public Io_stream_rdr Find_as_rdr(byte exec_tid, Xof_fsdb_itm fsdb) {
|
||||
Io_stream_rdr rv = Io_stream_rdr_.Null;
|
||||
Xof_repo_itm repo = repo_mgr.Repos_get_by_wiki(itm.Orig_repo_name()).Trg();
|
||||
boolean file_is_orig = itm.File_is_orig();
|
||||
Xof_repo_itm repo = repo_mgr.Repos_get_by_wiki(fsdb.Orig_repo_name()).Trg();
|
||||
boolean file_is_orig = fsdb.File_is_orig();
|
||||
if (file_is_orig || exec_tid == Xof_exec_tid.Tid_viewer_app) { // orig or viewer_app; note that viewer_app always return orig
|
||||
Io_url trg = url_bldr.To_url_trg(repo, itm, Bool_.Y);
|
||||
itm.Html_view_url_(trg);
|
||||
Io_url trg = url_bldr.To_url_trg(repo, fsdb, Bool_.Y);
|
||||
fsdb.Html_view_url_(trg);
|
||||
for (int i = 0; i < wkrs_len; i++) {
|
||||
Xof_bin_wkr wkr = wkrs[i];
|
||||
rv = wkr.Get_as_rdr(itm, Bool_.N, itm.Html_w());
|
||||
rv = wkr.Get_as_rdr(fsdb, Bool_.N, fsdb.Html_w());
|
||||
if (rv == Io_stream_rdr_.Null) continue; // orig not found; continue;
|
||||
itm.File_exists_y_();
|
||||
fsdb.File_exists_y_();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
else { // thumb
|
||||
Io_url trg = url_bldr.To_url_trg(repo, itm, Bool_.N);
|
||||
itm.Html_view_url_(trg);
|
||||
Io_url trg = url_bldr.To_url_trg(repo, fsdb, Bool_.N);
|
||||
fsdb.Html_view_url_(trg);
|
||||
for (int i = 0; i < wkrs_len; i++) {
|
||||
Xof_bin_wkr wkr = wkrs[i];
|
||||
rv = wkr.Get_as_rdr(itm, Bool_.Y, itm.Html_w()); // get thumb's bin
|
||||
rv = wkr.Get_as_rdr(fsdb, Bool_.Y, fsdb.Html_w()); // get thumb's bin
|
||||
if (rv != Io_stream_rdr_.Null) { // thumb's bin exists;
|
||||
itm.File_exists_y_();
|
||||
fsdb.File_exists_y_();
|
||||
return rv;
|
||||
}
|
||||
usr_dlg.Log_direct(String_.Format("thumb not found; ttl={0} w={1} ", String_.new_utf8_(itm.Lnki_ttl()), itm.Lnki_w()));
|
||||
rv = wkr.Get_as_rdr(itm, Bool_.N, itm.Orig_w()); // thumb missing; get orig;
|
||||
usr_dlg.Log_direct(String_.Format("thumb not found; ttl={0} w={1} ", String_.new_utf8_(fsdb.Lnki_ttl()), fsdb.Lnki_w()));
|
||||
rv = wkr.Get_as_rdr(fsdb, Bool_.N, fsdb.Orig_w()); // thumb missing; get orig;
|
||||
if (rv == Io_stream_rdr_.Null) {
|
||||
usr_dlg.Log_direct(String_.Format("orig not found;"));
|
||||
continue; // nothing found; continue;
|
||||
}
|
||||
if (!wkr.Resize_allowed()) continue;
|
||||
Io_url orig = url_bldr.To_url_trg(repo, itm, Bool_.Y); // get orig url
|
||||
Io_url orig = url_bldr.To_url_trg(repo, fsdb, Bool_.Y); // get orig url
|
||||
Io_stream_wtr_.Save_rdr(orig, rv);
|
||||
boolean resized = Resize(exec_tid, itm, file_is_orig, orig, trg);
|
||||
boolean resized = Resize(exec_tid, fsdb, file_is_orig, orig, trg);
|
||||
if (!resized) continue;
|
||||
itm.File_exists_y_();
|
||||
fsdb.File_exists_y_();
|
||||
rv = Io_stream_rdr_.file_(trg); // return stream of resized url; (result of imageMagick / inkscape)
|
||||
rv.Open();
|
||||
return rv;
|
||||
|
||||
@@ -16,47 +16,42 @@ 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.files.bins; import gplx.*; import gplx.xowa.*; import gplx.xowa.files.*;
|
||||
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.ios.*; import gplx.cache.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.dbs.*; import gplx.ios.*; import gplx.cache.*; import gplx.xowa.files.fsdb.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.data.*; import gplx.fsdb.meta.*;
|
||||
public class Xof_bin_wkr__fsdb_sql implements Xof_bin_wkr {
|
||||
private final Int_obj_ref tmp_itm_id = Int_obj_ref.neg1_(), tmp_bin_id = Int_obj_ref.neg1_(), tmp_mnt_id = Int_obj_ref.neg1_();
|
||||
private final Xof_bin_wkr_ids tmp_ids = new Xof_bin_wkr_ids();
|
||||
Xof_bin_wkr__fsdb_sql(Fsm_mnt_mgr mnt_mgr) {this.mnt_mgr = mnt_mgr;}
|
||||
public byte Tid() {return Xof_bin_wkr_.Tid_fsdb_xowa;}
|
||||
public String Key() {return Xof_bin_wkr_.Key_fsdb_wiki;}
|
||||
public Fsm_mnt_mgr Mnt_mgr() {return mnt_mgr;} private final Fsm_mnt_mgr mnt_mgr;
|
||||
public boolean Resize_allowed() {return bin_wkr_resize;} public void Resize_allowed_(boolean v) {bin_wkr_resize = v;} private boolean bin_wkr_resize = false;
|
||||
public Io_stream_rdr Get_as_rdr(Xof_fsdb_itm itm, boolean is_thumb, int w) {
|
||||
Find_ids(itm, is_thumb, w, tmp_itm_id, tmp_bin_id, tmp_mnt_id);
|
||||
int bin_db_id = tmp_bin_id.Val(); if (bin_db_id == Fsd_bin_tbl.Bin_db_id_null) return gplx.ios.Io_stream_rdr_.Null;
|
||||
Fsm_bin_fil bin_db = mnt_mgr.Bins__at(tmp_mnt_id.Val(), bin_db_id);
|
||||
return bin_db.Select_as_rdr(tmp_itm_id.Val());
|
||||
Find_ids(itm, is_thumb, w);
|
||||
int bin_db_id = tmp_ids.Bin_db_id(); if (bin_db_id == Fsd_bin_tbl.Bin_db_id_null) return gplx.ios.Io_stream_rdr_.Null;
|
||||
Fsm_bin_fil bin_db = mnt_mgr.Bins__at(tmp_ids.Mnt_id(), bin_db_id);
|
||||
return bin_db.Select_as_rdr(tmp_ids.Itm_id());
|
||||
}
|
||||
public boolean Get_to_fsys(Xof_fsdb_itm itm, boolean is_thumb, int w, Io_url bin_url) {return Get_to_fsys(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_md5(), itm.Lnki_ext(), is_thumb, w, itm.Lnki_time(), itm.Lnki_page(), bin_url);}
|
||||
private boolean Get_to_fsys(byte[] orig_repo, byte[] orig_ttl, byte[] orig_md5, Xof_ext orig_ext, boolean lnki_is_thumb, int file_w, double lnki_time, int lnki_page, Io_url file_url) {
|
||||
Find_ids(orig_repo, orig_ttl, orig_ext.Id(), lnki_time, lnki_page, lnki_is_thumb, file_w, tmp_itm_id, tmp_bin_id, tmp_mnt_id);
|
||||
int bin_db_id = tmp_bin_id.Val(); if (bin_db_id == Fsd_bin_tbl.Bin_db_id_null) return false;
|
||||
Fsm_bin_fil bin_db = mnt_mgr.Bins__at(tmp_mnt_id.Val(), bin_db_id);
|
||||
return bin_db.Select_to_url(tmp_itm_id.Val(), file_url);
|
||||
Find_ids(orig_repo, orig_ttl, orig_ext.Id(), lnki_time, lnki_page, lnki_is_thumb, file_w);
|
||||
int bin_db_id = tmp_ids.Bin_db_id(); if (bin_db_id == Fsd_bin_tbl.Bin_db_id_null) return false;
|
||||
Fsm_bin_fil bin_db = mnt_mgr.Bins__at(tmp_ids.Mnt_id(), bin_db_id);
|
||||
return bin_db.Select_to_url(tmp_ids.Itm_id(), file_url);
|
||||
}
|
||||
private void Find_ids(Xof_fsdb_itm itm, boolean is_thumb, int w, Int_obj_ref tmp_itm_id, Int_obj_ref tmp_bin_id, Int_obj_ref tmp_mnt_id) {Find_ids(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Lnki_time(), itm.Lnki_page(), is_thumb, w, tmp_itm_id, tmp_bin_id, tmp_mnt_id);}
|
||||
private void Find_ids(byte[] orig_repo, byte[] orig_ttl, int orig_ext, double lnki_time, int lnki_page, boolean is_thumb, int w, Int_obj_ref tmp_itm_id, Int_obj_ref tmp_bin_id, Int_obj_ref tmp_mnt_id) {
|
||||
synchronized (tmp_bin_id) {
|
||||
private void Find_ids(Xof_fsdb_itm itm, boolean is_thumb, int w) {Find_ids(itm.Orig_repo_name(), itm.Lnki_ttl(), itm.Lnki_ext().Id(), itm.Lnki_time(), itm.Lnki_page(), is_thumb, w);}
|
||||
private void Find_ids(byte[] orig_repo, byte[] orig_ttl, int orig_ext, double lnki_time, int lnki_page, boolean is_thumb, int w) {
|
||||
synchronized (tmp_ids) {
|
||||
byte[] dir = orig_repo, fil = orig_ttl;
|
||||
double time = Xof_lnki_time.Convert_to_fsdb_thumbtime(orig_ext, lnki_time, lnki_page);
|
||||
if (is_thumb) {
|
||||
Fsd_thm_itm thm_itm = Fsd_thm_itm.new_();
|
||||
thm_itm.Init_by_req(w, lnki_time, lnki_page);
|
||||
boolean found = Select_thm_bin(thm_itm, dir, fil);
|
||||
tmp_itm_id.Val_(thm_itm.Thm_id());
|
||||
tmp_bin_id.Val_(found ? thm_itm.Db_bin_id() : Fsd_bin_tbl.Bin_db_id_null);
|
||||
tmp_mnt_id.Val_(thm_itm.Mnt_id());
|
||||
tmp_ids.Init_by_thm(found, thm_itm);
|
||||
}
|
||||
else {
|
||||
Fsd_fil_itm fil_itm = Select_fil_bin(dir, fil, is_thumb, w, time);
|
||||
if (fil_itm == Fsd_fil_itm.Null) return;
|
||||
tmp_itm_id.Val_(fil_itm.Fil_id());
|
||||
tmp_bin_id.Val_(fil_itm.Bin_db_id());
|
||||
tmp_mnt_id.Val_(fil_itm.Mnt_id());
|
||||
tmp_ids.Init_by_fil(fil_itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,4 +77,33 @@ public class Xof_bin_wkr__fsdb_sql implements Xof_bin_wkr {
|
||||
public void Txn_bgn() {mnt_mgr.Mnts__get_insert().Txn_bgn();}
|
||||
public void Txn_end() {mnt_mgr.Mnts__get_insert().Txn_end();}
|
||||
public static Xof_bin_wkr__fsdb_sql new_(Fsm_mnt_mgr mnt_mgr) {return new Xof_bin_wkr__fsdb_sql(mnt_mgr);}
|
||||
}
|
||||
}
|
||||
class Xof_bin_wkr_ids {
|
||||
public Xof_bin_wkr_ids() {this.Clear();}
|
||||
public int Mnt_id() {return mnt_id;} private int mnt_id;
|
||||
public int Bin_db_id() {return bin_db_id;} private int bin_db_id;
|
||||
public int Itm_id() {return itm_id;} private int itm_id;
|
||||
public void Init_by_thm(boolean found, Fsd_thm_itm thm) {
|
||||
if (found) {
|
||||
this.mnt_id = thm.Mnt_id();
|
||||
this.bin_db_id = thm.Db_bin_id();
|
||||
this.itm_id = thm.Thm_id();
|
||||
}
|
||||
else
|
||||
this.Clear();
|
||||
}
|
||||
public void Init_by_fil(Fsd_fil_itm fil) {
|
||||
if (fil == Fsd_fil_itm.Null)
|
||||
this.Clear();
|
||||
else {
|
||||
this.mnt_id = fil.Mnt_id();
|
||||
this.bin_db_id = fil.Bin_db_id();
|
||||
this.itm_id = fil.Fil_id();
|
||||
}
|
||||
}
|
||||
private void Clear() {
|
||||
this.mnt_id = -1;
|
||||
this.bin_db_id = Fsd_bin_tbl.Bin_db_id_null;
|
||||
this.itm_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Xof_cache_mgr2 {
|
||||
Xof_cache_itm itm = Get_or_null(fsdb.Lnki_ttl(), fsdb.Lnki_type(), fsdb.Lnki_upright(), fsdb.Lnki_w(), fsdb.Lnki_h(), fsdb.Lnki_time(), fsdb.Lnki_page());
|
||||
if (itm == Xof_cache_itm.Null) {
|
||||
itm = new Xof_cache_itm(key_bfr, Db_cmd_mode.Tid_create, site, fsdb.Lnki_ttl(), fsdb.Lnki_type(), fsdb.Lnki_upright(), fsdb.Lnki_w(), fsdb.Lnki_h(), fsdb.Lnki_time(), fsdb.Lnki_page()
|
||||
, fsdb.Orig_repo_id(), fsdb.Orig_ttl(), fsdb.Orig_ext(), fsdb.Orig_w(), fsdb.Orig_h()
|
||||
, fsdb.Orig_repo_id(), fsdb.Orig_ttl(), fsdb.Orig_ext().Id(), fsdb.Orig_w(), fsdb.Orig_h()
|
||||
, fsdb.Lnki_time(), fsdb.Lnki_page(), fsdb.Temp_file_size(), 1, DateAdp_.Now().Timestamp_unix(), fsdb.Temp_file_w())
|
||||
;
|
||||
hash.Add(itm.Lnki_key(), itm);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Xof_fsdb_itm {
|
||||
public byte Orig_repo_id() {return orig_repo_id;} private byte orig_repo_id = Xof_repo_itm.Repo_null;
|
||||
public byte[] Orig_repo_name() {return orig_repo_name;} private byte[] orig_repo_name;
|
||||
public byte[] Orig_ttl() {return orig_ttl;} private byte[] orig_ttl;
|
||||
public int Orig_ext() {return orig_ext;} private int orig_ext;
|
||||
public Xof_ext Orig_ext() {return orig_ext;} private Xof_ext orig_ext;
|
||||
public int Orig_w() {return orig_w;} private int orig_w = Xop_lnki_tkn.Width_null;
|
||||
public int Orig_h() {return orig_h;} private int orig_h = Xop_lnki_tkn.Height_null;
|
||||
public byte[] Orig_redirect() {return orig_redirect;} private byte[] orig_redirect = Bry_.Empty;
|
||||
@@ -59,14 +59,16 @@ public class Xof_fsdb_itm {
|
||||
// this.file_is_orig = !(Xop_lnki_type.Id_defaults_to_thumb(lnki_type) || lnki_w != Xop_lnki_tkn.Width_null || lnki_h != Xop_lnki_tkn.Height_null); // DELETE: overriden below.
|
||||
this.Lnki_ttl_(lnki_ttl);
|
||||
} private int lnki_upright_patch;
|
||||
public void Ctor_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, int orig_ext, int orig_w, int orig_h, byte[] orig_redirect) {
|
||||
public void Ctor_by_orig(byte orig_repo_id, byte[] orig_repo_name, byte[] orig_ttl, Xof_ext orig_ext, int orig_w, int orig_h, byte[] orig_redirect) {
|
||||
this.orig_repo_id = orig_repo_id; this.orig_repo_name = orig_repo_name;
|
||||
this.orig_ttl = orig_ttl; this.orig_ext = orig_ext;
|
||||
this.orig_w = orig_w; this.orig_h = orig_h; this.orig_redirect = orig_redirect;
|
||||
if (orig_ext != lnki_ext.Id())
|
||||
this.Lnki_ext_(Xof_ext_.new_by_id_(orig_ext)); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
|
||||
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
|
||||
if (orig_ext != null && orig_ext.Id() != lnki_ext.Id())
|
||||
this.Lnki_ext_(orig_ext); // overwrite ext with whatever's in file_orig; needed for ogg -> oga / ogv
|
||||
if (Bry_.Len_gt_0(orig_redirect)) // redirect exists; EX: A.png redirected to B.png
|
||||
this.Lnki_ttl_(orig_redirect); // update fsdb with atrs of B.png
|
||||
else if (!Bry_.Eq(lnki_ttl, orig_ttl)) // ttls differ; EX: "A_.png" vs "A.png"
|
||||
this.Lnki_ttl_(orig_ttl);
|
||||
}
|
||||
public void Ctor_for_html(byte exec_tid, Xof_img_size img_size, Xof_repo_itm repo, Xof_url_bldr url_bldr) {
|
||||
Calc_html_size(exec_tid, img_size);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xof_fsdb_mgr__sql implements Xof_fsdb_mgr, GfoInvkAble {
|
||||
Xoa_app app = wiki.App();
|
||||
this.cache_mgr = app.File_mgr__cache_mgr(); this.url_bldr = Xof_url_bldr.new_v2_();
|
||||
this.repo_mgr = wiki.File_mgr__repo_mgr(); Xof_img_mgr img_mgr = app.File_mgr__img_mgr();
|
||||
Fsdb_db_mgr core = Fsdb_db_mgr_.new_detect(wiki.Domain_str(), wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
Fsdb_db_mgr core = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
if (core == null) return;
|
||||
fsdb_enabled = true;
|
||||
mnt_mgr.Ctor_by_load(core);
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xob_orig_tbl_bldr extends Xob_itm_basic_base implements Xob_cmd {
|
||||
Xof_fsdb_mode fsdb_mode = wiki.File_mgr__fsdb_mode();
|
||||
fsdb_mode.Tid_make_y_();
|
||||
wiki.Init_assert();
|
||||
Fsdb_db_mgr db_core_mgr = Fsdb_db_mgr_.new_detect(wiki.Domain_str(), wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
Fsdb_db_mgr db_core_mgr = Fsdb_db_mgr_.new_detect(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Fsys_mgr().File_dir());
|
||||
conn = db_core_mgr.File__orig_tbl_ary()[gplx.fsdb.meta.Fsm_mnt_mgr.Mnt_idx_main].Conn();
|
||||
Io_url make_db_url = Xob_db_file.new__file_make(wiki.Fsys_mgr().Root_dir()).Url();
|
||||
Sqlite_engine_.Db_attach(conn, "make_db", make_db_url.Raw());
|
||||
|
||||
@@ -37,9 +37,8 @@ public class Xof_orig_mgr {
|
||||
public Xof_orig_itm Find_by_ttl_or_null(byte[] ttl) {
|
||||
for (int i = 0; i < wkrs_len; i++) {
|
||||
Xof_orig_wkr wkr = wkrs[i];
|
||||
Xof_orig_itm orig = wkr.Find_as_itm(ttl);
|
||||
if (orig == Xof_orig_itm.Null) continue;
|
||||
if (orig.Insert_new()) this.Insert(orig.Repo(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
|
||||
Xof_orig_itm orig = wkr.Find_as_itm(ttl); if (orig == Xof_orig_itm.Null) continue;
|
||||
if (orig.Insert_new()) this.Insert(orig.Repo(), ttl, orig.Ext(), orig.W(), orig.H(), orig.Redirect()); // NOTE: orig_page must be same as find_arg not orig.Page() else will not be found for next call; DATE:2015-04-14
|
||||
return orig;
|
||||
}
|
||||
return Xof_orig_itm.Null;
|
||||
@@ -54,9 +53,8 @@ public class Xof_orig_mgr {
|
||||
try {
|
||||
Xof_fsdb_itm fsdb = (Xof_fsdb_itm)itms.FetchAt(i);
|
||||
fsdb.Orig_exists_n_(); // default to status = missing
|
||||
Xof_orig_itm orig = (Xof_orig_itm)rv.Fetch(fsdb.Lnki_ttl());
|
||||
if (orig == Xof_orig_itm.Null) continue;
|
||||
if (orig.Insert_new()) this.Insert(orig.Repo(), orig.Page(), orig.Ext(), orig.W(), orig.H(), orig.Redirect());
|
||||
Xof_orig_itm orig = (Xof_orig_itm)rv.Fetch(fsdb.Lnki_ttl()); if (orig == Xof_orig_itm.Null) continue;
|
||||
if (orig.Insert_new()) this.Insert(orig.Repo(), fsdb.Lnki_ttl(), orig.Ext(), orig.W(), orig.H(), orig.Redirect()); // NOTE: orig_page must be same as find_arg not orig.Page() else will not be found for next call; DATE:2015-04-14
|
||||
Xof_file_wkr.Eval_orig(exec_tid, orig, fsdb, url_bldr, repo_mgr, img_size);
|
||||
if (!Io_mgr._.ExistsFil(fsdb.Html_view_url()))
|
||||
fsdb.File_exists_n_();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Xog_mnu_grp extends Xog_mnu_base {
|
||||
}
|
||||
public void Build() {
|
||||
Xoa_gui_mgr gui_mgr = app.Gui_mgr(); Gfui_kit kit = gui_mgr.Kit(); Xog_win_itm win = gui_mgr.Browser_win();
|
||||
if (!kit.Kit_init_done()) return; // NOTE: .gfs will fire Build before Kit.Init; check that kit is inited
|
||||
if (!kit.Kit_mode__ready()) return; // NOTE: .gfs will fire Build before Kit.Init; check that kit is inited
|
||||
if (under_mnu == null) {
|
||||
if (mnu_is_popup) {
|
||||
if (String_.Eq(key, Xog_popup_mnu_mgr.Root_key_tabs_btns))
|
||||
|
||||
@@ -122,7 +122,7 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
}
|
||||
public void Tabs_close_cur() {
|
||||
if (this.Active_tab_is_null()) return;
|
||||
if (!active_tab.Page().Tab_data().Close_mgr().When_close(active_tab)) return;
|
||||
Tabs__pub_close(active_tab);
|
||||
tab_mgr.Tabs_close_by_idx(active_tab.Tab_idx());
|
||||
Xog_tab_itm cur_tab = this.Active_tab(); // get new current tab for line below
|
||||
if (cur_tab != null) cur_tab.Html_box().Focus(); // NOTE: needed to focus tab box else tab button will be focused; DATE:2014-07-13
|
||||
@@ -133,11 +133,24 @@ public class Xog_tab_mgr implements GfoEvObj {
|
||||
public void Tabs_close_rng(int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xog_tab_itm tab = Tabs_get_at(bgn);
|
||||
if (tab.Page().Tab_data().Close_mgr().When_close(tab))
|
||||
tab_mgr.Tabs_close_by_idx(bgn);
|
||||
if (!Tabs__pub_close(tab)) return;
|
||||
}
|
||||
for (int i = bgn; i < end; i++)
|
||||
tab_mgr.Tabs_close_by_idx(bgn); // NOTE: close at bgn, not at i, b/c each close will remove a tab from collection
|
||||
}
|
||||
public boolean Tabs__pub_close_all() {return Tabs__pub_close_rng(0, this.Tabs_len());}
|
||||
public boolean Tabs__pub_close_rng(int bgn, int end) {
|
||||
boolean rv = true;
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xog_tab_itm tab = Tabs_get_at(i);
|
||||
boolean close_allowed = Tabs__pub_close(tab);
|
||||
if (!close_allowed) rv = false;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public boolean Tabs__pub_close(Xog_tab_itm tab) {
|
||||
return tab.Page().Tab_data().Close_mgr().When_close(tab);
|
||||
}
|
||||
public void Tabs_close_all() {Tabs_close_rng(0, Tabs_len());}
|
||||
public void Tabs_close_undo() {
|
||||
if (closed_undo_list.Count() == 0) return;
|
||||
String url = (String)ListAdp_.Pop(closed_undo_list);
|
||||
|
||||
@@ -44,8 +44,8 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
public Xoae_app App() {return app;} private Xoae_app app;
|
||||
public Xog_tab_mgr Tab_mgr() {return tab_mgr;} private Xog_tab_mgr tab_mgr;
|
||||
public Xog_tab_itm Active_tab() {return tab_mgr.Active_tab();}
|
||||
public Xoae_page Active_page() {return tab_mgr.Active_tab().Page();} public void Active_page_(Xoae_page v) {tab_mgr.Active_tab().Page_(v);}
|
||||
public Xowe_wiki Active_wiki() {return tab_mgr.Active_tab().Wiki();}
|
||||
public Xoae_page Active_page() {return tab_mgr.Active_tab().Page();} public void Active_page_(Xoae_page v) {tab_mgr.Active_tab().Page_(v);}
|
||||
public Xowe_wiki Active_wiki() {return tab_mgr.Active_tab().Wiki();}
|
||||
public Xog_html_itm Active_html_itm() {return tab_mgr.Active_tab().Html_itm();}
|
||||
public Gfui_html Active_html_box() {return tab_mgr.Active_tab().Html_itm().Html_box();}
|
||||
public Xog_resizer Resizer() {return resizer;} private Xog_resizer resizer = new Xog_resizer();
|
||||
@@ -180,6 +180,8 @@ public class Xog_win_itm implements GfoInvkAble, GfoEvObj {
|
||||
Xoae_page cur_page = tab.Page(); Xowe_wiki cur_wiki = tab.Wiki();
|
||||
Xoae_page new_page = tab.History_mgr().Go_by_dir(cur_wiki, fwd);
|
||||
if (new_page.Missing()) return;
|
||||
if (new_page.Wikie().Special_mgr().Page_search().Match_ttl(new_page.Ttl())) // if Special:Search, reload page; needed for async loading; DATE:2015-04-19
|
||||
new_page = new_page.Wikie().GetPageByTtl(new_page.Url(), new_page.Ttl()); // NOTE: must reparse page if (a) Edit -> Read; or (b) "Options" save
|
||||
byte history_nav_type = fwd ? Xog_history_stack.Nav_fwd : Xog_history_stack.Nav_bwd;
|
||||
boolean new_page_is_same = Bry_.Eq(cur_page.Ttl().Full_txt(), new_page.Ttl().Full_txt());
|
||||
Xog_tab_itm_read_mgr.Show_page(tab, new_page, true, new_page_is_same, false, history_nav_type);
|
||||
|
||||
@@ -211,12 +211,11 @@ public class Xoh_file_wtr__basic {
|
||||
return scratch_bfr.Xto_bry_and_clear();
|
||||
}
|
||||
private static byte[] Arg_anchor_title(Bry_bfr tmp_bfr, byte[] src, Xop_lnki_tkn lnki, byte[] lnki_ttl, Xoh_lnki_title_fmtr anchor_title_wkr) {
|
||||
switch (lnki.Lnki_type()) {
|
||||
case Xop_lnki_type.Id_thumb: // If the image is a thumb, do not add a title / alt, even if a caption is available
|
||||
case Xop_lnki_type.Id_frame:
|
||||
return Bry_.Empty;
|
||||
case Xop_lnki_type.Id_frameless: // If the image is frameless, add the caption as a title / alt. If no caption is available, do not add a title / alt
|
||||
break;
|
||||
if ( Enm_.HasInt(lnki.Lnki_type(), Xop_lnki_type.Id_thumb)
|
||||
|| Enm_.HasInt(lnki.Lnki_type(), Xop_lnki_type.Id_frame) // If the image is a thumb, do not add a title / alt, even if a caption is available
|
||||
)
|
||||
return Bry_.Empty;
|
||||
else if ( Enm_.HasInt(lnki.Lnki_type(), Xop_lnki_type.Id_frameless)) { // If the image is frameless, add the caption as a title / alt. If no caption is available, do not add a title / alt
|
||||
}
|
||||
Xop_tkn_itm anchor_title_tkn = lnki.Caption_tkn();
|
||||
if (anchor_title_tkn == Xop_tkn_null.Null_tkn) return Bry_.Empty; // no caption; return empty; (do not use lnki); DATE:2013-12-31
|
||||
|
||||
@@ -98,6 +98,26 @@ public class Xoh_file_wtr_basic_tst {
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Img_frame_and_thumb() { // PURPOSE: lnki with "frame and thumb" was not showing box due to bit-adding; PAGE:en.w:History_of_Western_Civilization DATE:2015-04-16
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.png|frame|thumb|220x110px|b]]" // NOTE: frame AND thumb
|
||||
, String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"220\" height=\"110\" /></a>"
|
||||
, " <div class=\"thumbcaption\">"
|
||||
, " <div class=\"magnify\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"internal\" title=\"Enlarge\">"
|
||||
, " <img src=\"file:///mem/xowa/user/test_user/app/img/file/magnify-clip.png\" width=\"15\" height=\"11\" alt=\"\" />"
|
||||
, " </a>"
|
||||
, " </div>"
|
||||
, " b"
|
||||
, " </div>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
));
|
||||
}
|
||||
@Test public void Cls_border() {
|
||||
fxt.Test_parse_page_wiki_str
|
||||
( "[[File:A.png|border]]"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -229,8 +229,7 @@ class HttpRequest implements Runnable{
|
||||
else
|
||||
req += app.Http_server().Home();
|
||||
}
|
||||
if(req.endsWith("wiki/")) req+="Main_Page";
|
||||
if(req.endsWith("wiki")) req+="/Main_Page";
|
||||
req = Http_server_wkr_.Assert_main_page(app, req);
|
||||
}
|
||||
|
||||
if(req.contains("%xowa-cmd%") || req.contains("/xowa-cmd:")){
|
||||
|
||||
39
400_xowa/src/gplx/xowa/servers/http/Http_server_wkr_.java
Normal file
39
400_xowa/src/gplx/xowa/servers/http/Http_server_wkr_.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.servers.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
|
||||
class Http_server_wkr_ {
|
||||
public static String Assert_main_page(Xoae_app app, String req) {
|
||||
int mode = -1;
|
||||
String[] req_array = String_.Split(req, "/");
|
||||
if (String_.HasAtEnd(req, "wiki/")) mode = 0;
|
||||
else if (String_.HasAtEnd(req, "wiki")) mode = 1;
|
||||
else if (req_array.length == 3) mode = 2;
|
||||
if (mode == -1) return req; // not a link to a Main Page; EX:localhost:8080/en.wikipedia.org/wiki/Earth
|
||||
if (req_array.length < 3) return req; // shouldn't happen; EX: "localhost:8080wiki"
|
||||
byte[] wiki_domain = Bry_.new_utf8_(req_array[1]);
|
||||
Xow_domain domain_itm = Xow_domain_.parse(wiki_domain);
|
||||
if (domain_itm.Domain_tid() == Xow_domain_.Tid_int_other && domain_itm.Lang_itm().Id() == Xol_lang_itm_.Id__intl) return req;
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(wiki_domain);
|
||||
wiki.Init_assert();
|
||||
String main_page = String_.new_utf8_(wiki.Props().Main_page());
|
||||
if (mode == 1) main_page = "/" + main_page;
|
||||
else if (mode == 2) main_page = "wiki/" + main_page;
|
||||
return req + main_page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
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.servers.http; import gplx.*; import gplx.xowa.*; import gplx.xowa.servers.*;
|
||||
import org.junit.*;
|
||||
public class Http_server_wkr__tst {
|
||||
@Before public void init() {fxt.Clear();} private Http_server_wkr__fxt fxt = new Http_server_wkr__fxt();
|
||||
@Test public void Assert_main_page() {
|
||||
fxt.Init_wiki_main_page("fr.wikiversity.org", "Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/" , "/fr.wikiversity.org/wiki/Accueil");
|
||||
fxt.Test_assert_main_page("/fr.wikiversity.org/wiki/A" , "/fr.wikiversity.org/wiki/A");
|
||||
}
|
||||
}
|
||||
class Http_server_wkr__fxt {
|
||||
private Xoae_app app;
|
||||
public void Clear() {
|
||||
this.app = Xoa_app_fxt.app_();
|
||||
}
|
||||
public void Init_wiki_main_page(String domain, String main_page) {
|
||||
Xowe_wiki wiki = app.Wiki_mgr().Get_by_key_or_make(Bry_.new_utf8_(domain));
|
||||
wiki.Props().Main_page_(Bry_.new_utf8_(main_page));
|
||||
}
|
||||
public void Test_assert_main_page(String url, String expd) {
|
||||
Tfds.Eq(expd, Http_server_wkr_.Assert_main_page(app, url));
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class Wmf_dump_list_parser_tst {
|
||||
, fxt.itm("zh-classicalwiki", "20131128", Wmf_dump_itm.Status_tid_complete, "Dump complete", "2013-11-28 06:08:56")
|
||||
);
|
||||
}
|
||||
// @Test public void Update() { // MAINT:QUARTERLY:2015-03-01
|
||||
// @Test public void Update() { // MAINT:QUARTERLY:2015-03-01; must run C:\xowa\ and update dump status
|
||||
// Hash_adp_bry excluded_domains = Hash_adp_bry.cs_().Add_many_str
|
||||
// ( "advisory.wikipedia.org", "beta.wikiversity.org", "donate.wikipedia.org", "login.wikipedia.org"
|
||||
// , "nostalgia.wikipedia.org", "outreach.wikipedia.org", "quality.wikipedia.org", "sources.wikipedia.org"
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xows_mgr {
|
||||
Evt_lang_changed(wiki.Lang());
|
||||
}
|
||||
public Xows_page_allpages Page_allpages() {return page_allpages;} private final Xows_page_allpages page_allpages;
|
||||
public Xows_page__search Page_search() {return page_search;} private final Xows_page__search page_search;
|
||||
public Xows_page__search Page_search() {return page_search;} private final Xows_page__search page_search;
|
||||
public Xows_page_random Page_random() {return page_random;} private final Xows_page_random page_random;
|
||||
public Xop_randomRootPage_page Page_randomRootPage() {return page_randomRootPage;} private final Xop_randomRootPage_page page_randomRootPage = new Xop_randomRootPage_page();
|
||||
public Xou_history_html Page_history() {return page_history;} private final Xou_history_html page_history = new Xou_history_html();
|
||||
|
||||
@@ -34,6 +34,7 @@ class Xows_db_wkr {
|
||||
, wiki.Data_mgr__core_mgr().Db__search().Tbl__search_word()
|
||||
);
|
||||
}
|
||||
Xoa_app_.Usr_dlg().Prog_many("", "", "search started (please wait)");
|
||||
// load pages for each word
|
||||
Xows_db_matcher matcher = cache.Matcher();
|
||||
Xows_db_word[] word_ary = cache.Words();
|
||||
|
||||
@@ -78,7 +78,7 @@ class Xows_html_wkr {
|
||||
private static final Bry_fmtr fmtr_tbl = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<table class='wikitable sortable'>"
|
||||
, " <tr>"
|
||||
, " <th colspan='2' style='text-align:left'><a href='/site/home/wiki/Help:Special/Search'>Help</a>"
|
||||
, " <th colspan='2' style='text-align:left'><a href='/site/home/wiki/Help:Special/Search'>Help</a>" // SERVER:"<a href='"; DATE:2015-04-16
|
||||
, " </th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
@@ -95,8 +95,8 @@ class Xows_html_wkr {
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
), "wiki", "cancel", "hdr_len", "hdr_ttl", "insert_key", "rows");
|
||||
private static final Bry_fmtr fmtr_link = Bry_fmtr.new_("<a href='~{a_href}' title='~{a_title}'>~{a_text}</a>", "a_href", "a_title", "a_text");
|
||||
private static final Bry_fmtr fmtr_link_id = Bry_fmtr.new_("<a id='~{a_id}' href='~{a_href}' title='~{a_title}'>~{a_text}</a>", "a_id", "a_href", "a_title", "a_text");
|
||||
private static final Bry_fmtr fmtr_link = Bry_fmtr.new_("<a href='~{a_href}' title='~{a_title}'>~{a_text}</a>", "a_href", "a_title", "a_text"); // SERVER:"<a href='"; DATE:2015-04-16
|
||||
private static final Bry_fmtr fmtr_link_id = Bry_fmtr.new_("<a href='~{a_href}' title='~{a_title}' id='~{a_id}'>~{a_text}</a>", "a_id", "a_href", "a_title", "a_text"); // SERVER:"<a href='"; DATE:2015-04-16
|
||||
private static final Bry_fmtr_vals fmtr_paging_bwd = Bry_fmtr_vals.new_(fmtr_link);
|
||||
private static final Bry_fmtr_vals fmtr_paging_fwd = Bry_fmtr_vals.new_(fmtr_link);
|
||||
private static final Bry_fmtr_vals fmtr_paging_cxl = Bry_fmtr_vals.new_(fmtr_link_id);
|
||||
@@ -126,7 +126,7 @@ class Xows_html_row implements Bry_fmtr_arg {
|
||||
, " <tr id='~{page_key}'>"
|
||||
, " <td>~{page_len}"
|
||||
, " </td>"
|
||||
, " <td><a href='~{a_href}' title='~{a_title}'>~{a_text}</a>"
|
||||
, " <td><a href='~{a_href}' title='~{a_title}'>~{a_text}</a>" // SERVER:"<a href='"; DATE:2015-04-16
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
), "page_key", "page_len", "a_href", "a_title", "a_text");
|
||||
|
||||
@@ -17,13 +17,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.specials.search; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.wikis.*; import gplx.xowa.apis.xowa.specials.*;
|
||||
public class Xows_page__search implements Xows_page {
|
||||
import gplx.xowa.wikis.domains.crts.*;
|
||||
public class Xows_page__search implements Xows_page, GfoInvkAble, GfoEvObj {
|
||||
private final Xow_domain wiki_domain; private final Xoapi_search search_api;
|
||||
private final Xows_core search_mgr; private final Xows_arg_mgr args_mgr = new Xows_arg_mgr();
|
||||
private Xow_domain_crt_itm multi_wiki_crt;
|
||||
public Xows_page__search(Xowe_wiki wiki) {
|
||||
this.wiki_domain = wiki.Domain_itm();
|
||||
this.search_mgr = new Xows_core(wiki.Appe().Wiki_mgr());
|
||||
}
|
||||
this.ev_mgr = GfoEvMgr.new_(this);
|
||||
this.search_api = wiki.Appe().Api_root().Special().Search();
|
||||
}
|
||||
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Xoapi_search.Evt_multi_wiki_rules_changed)) this.multi_wiki_crt = search_api.Multi_wiki_crt(wiki_domain);
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public boolean Match_ttl(Xoa_ttl ttl) {
|
||||
return ttl.Ns().Id_special() && Bry_.Eq(ttl.Root_txt(), Bry_search);
|
||||
}
|
||||
public void Special_gen(Xowe_wiki wiki, Xoae_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
if (wiki.Domain_tid() == Xow_domain_.Tid_int_home) return; // do not allow search in home wiki; will throw null ref error b/c no search_ttl dirs
|
||||
if (multi_wiki_crt == null) {
|
||||
this.multi_wiki_crt = search_api.Multi_wiki_crt(wiki.Domain_itm());
|
||||
GfoEvMgr_.SubSame_many(search_api, this, Xoapi_search.Evt_multi_wiki_rules_changed);
|
||||
}
|
||||
// get args
|
||||
Xog_search_suggest_mgr search_suggest_mgr = wiki.Appe().Gui_mgr().Search_suggest_mgr();
|
||||
args_mgr.Clear();
|
||||
@@ -56,7 +75,6 @@ public class Xows_page__search implements Xows_page {
|
||||
}
|
||||
page.Html_data().Html_restricted_n_();
|
||||
page.Html_data().Xtn_search_text_(search_bry);
|
||||
Xoapi_search search_api = wiki.Appe().Api_root().Special().Search();
|
||||
Xows_ui_qry qry = new Xows_ui_qry(search_bry, args_mgr.Paging_idx(), search_api.Results_per_page(), args_mgr.Sort_tid(), args_mgr.Ns_mgr(), search_api.Async_db(), Bry_.Ary(wiki.Domain_bry()));
|
||||
search_mgr.Search(wiki, page, qry);
|
||||
}
|
||||
@@ -71,5 +89,5 @@ public class Xows_page__search implements Xows_page {
|
||||
}
|
||||
public static final byte Match_tid_all = 0, Match_tid_bgn = 1;
|
||||
public static final byte Version_null = 0, Version_1 = 1, Version_2 = 2;
|
||||
private static final byte[] Bry_special_name = Bry_.new_ascii_("Special:Search");
|
||||
private static final byte[] Bry_special_name = Bry_.new_ascii_("Special:Search"), Bry_search = Bry_.new_ascii_("Search");
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class Xows_ui_cmd implements GfoInvkAble, Cancelable, Xog_tab_close_lnr {
|
||||
if (canceled) return; // NOTE: must check else throws SWT exception
|
||||
}
|
||||
js_wkr.Html_atr_set("xowa_cancel_" + wiki.Domain_str(), "style", "display:none;");
|
||||
qry.Page_max_(cache.Count() / qry.Page_len());
|
||||
Xoa_app_.Usr_dlg().Prog_many("", "", "");
|
||||
}
|
||||
public boolean Search() {
|
||||
@@ -55,7 +56,7 @@ class Xows_ui_cmd implements GfoInvkAble, Cancelable, Xog_tab_close_lnr {
|
||||
boolean rv = false;
|
||||
if (qry.Itms_end() > cache.Count() && !cache.Done()) {
|
||||
if (async)
|
||||
ThreadAdp_.invk_(this, Invk_search_db).Start();
|
||||
ThreadAdp_.invk_("xowa.special.search", this, Invk_search_db).Start();
|
||||
else
|
||||
Search_db();
|
||||
rv = true;
|
||||
|
||||
@@ -16,7 +16,7 @@ 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.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.wikis.domains.crts.*;
|
||||
public class Xoa_wiki_mgr implements GfoInvkAble {
|
||||
private Xoae_app app;
|
||||
private ListAdp list = ListAdp_.new_(); private Hash_adp_bry hash = Hash_adp_bry.ci_ascii_(); // ASCII:url_domain; EX:en.wikipedia.org
|
||||
@@ -42,6 +42,15 @@ public class Xoa_wiki_mgr implements GfoInvkAble {
|
||||
if (rv == null) rv = New_wiki(key);
|
||||
return rv;
|
||||
}
|
||||
public Xowe_wiki[] Get_by_crt(Xow_domain cur, Xow_domain_crt_itm crt) {
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
int len = this.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_wiki wiki = this.Get_at(i);
|
||||
if (crt.Matches(cur, wiki.Domain_itm())) rv.Add(wiki);
|
||||
}
|
||||
return (Xowe_wiki[])rv.Xto_ary_and_clear(Xowe_wiki.class);
|
||||
}
|
||||
public Xowe_wiki Wiki_commons() {
|
||||
Xowe_wiki rv = this.Get_by_key_or_null(Xow_domain_.Domain_bry_commons);
|
||||
if (rv != null) rv.Init_assert();
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Xow_domain_ {
|
||||
, Domain_bry_wikimediafoundation = Bry_.new_ascii_("wikimediafoundation.org")
|
||||
, Domain_bry_species = Bry_.new_ascii_("species.wikimedia.org")
|
||||
;
|
||||
private static final byte Tid_int_null = Byte_.Max_value_127;
|
||||
public static final byte Tid_int_null = Byte_.Max_value_127;
|
||||
public static final int
|
||||
Tid_int_other = 0, Tid_int_home = 1
|
||||
, Tid_int_wikipedia = 2, Tid_int_wiktionary = 3, Tid_int_wikisource = 4, Tid_int_wikibooks = 5, Tid_int_wikiversity = 6, Tid_int_wikiquote = 7, Tid_int_wikinews = 8, Tid_int_wikivoyage = 9
|
||||
@@ -86,8 +86,9 @@ public class Xow_domain_ {
|
||||
.Add_bry_int(Tid_bry_other , Tid_int_other)
|
||||
;
|
||||
public static byte[] Tid__get_bry(int tid) {return Tid_bry__ary[tid];}
|
||||
public static int Tid__get_int(byte[] key) {
|
||||
Object o = hash_tid_by_bry.Get_by_bry(key);
|
||||
public static int Tid__get_int(byte[] key) {return Tid__get_int(key, 0, key.length);}
|
||||
public static int Tid__get_int(byte[] key, int bgn, int end) {
|
||||
Object o = hash_tid_by_bry.Get_by_mid(key, bgn, end);
|
||||
return o == null ? Tid_int_null : ((Int_obj_val)o).Val();
|
||||
}
|
||||
public static Xow_domain parse(byte[] raw) {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class Xowd_db_file {
|
||||
|
||||
public static final Xowd_db_file Null = null;
|
||||
public static Xowd_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
|
||||
Guid_adp guid = Guid_adp_.random_();
|
||||
Guid_adp guid = Guid_adp_.new_();
|
||||
Xob_info_file info_file = new Xob_info_file(id, Xowd_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
|
||||
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
|
||||
Xowd_db_file rv = new Xowd_db_file(cfg_tbl, info_session, info_file, props, Xowd_db_file_schema_props.make_(), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_create);
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Xowd_db_mgr {
|
||||
switch (db.Tid()) {
|
||||
case Xowd_db_file_.Tid_wiki_solo:
|
||||
case Xowd_db_file_.Tid_text_solo:
|
||||
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__search = db; break;}
|
||||
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__search = db__text = db; break;}
|
||||
case Xowd_db_file_.Tid_text : {db__text = db; break;}
|
||||
case Xowd_db_file_.Tid_html_data : {db__html = db; break;}
|
||||
case Xowd_db_file_.Tid_search_core : {if (db__search == null) db__search = db; break;}
|
||||
|
||||
@@ -210,7 +210,10 @@ public class Xowd_page_tbl implements RlsAble {
|
||||
;
|
||||
int limit = fwd ? max_results + 1 : max_results; // + 1 to get next item
|
||||
Db_qry__select_cmd qry = Db_qry_.select_cols_(tbl_name, crt, cols).Limit_(limit).OrderBy_(fld_title, fwd);
|
||||
return conn.Stmt_new(qry).Crt_int(fld_ns, ns_id).Crt_str(fld_title, ttl_frag_str).Crt_int(fld_len, min_page_len).Exec_select__rls_auto();
|
||||
Db_stmt stmt = conn.Stmt_new(qry).Crt_int(fld_ns, ns_id).Crt_str(fld_title, ttl_frag_str).Crt_int(fld_len, min_page_len);
|
||||
if (!include_redirects)
|
||||
stmt.Crt_bool_as_byte(fld_is_redirect, include_redirects);
|
||||
return stmt.Exec_select__rls_auto();
|
||||
}
|
||||
public void Select_for_special_all_pages(Cancelable cancelable, ListAdp rslt_list, Xowd_page_itm rslt_nxt, Xowd_page_itm rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
|
||||
Xowd_page_itm nxt_itm = null;
|
||||
|
||||
@@ -58,11 +58,15 @@ public class Xowd_search_word_tbl implements RlsAble {
|
||||
ListAdp list = ListAdp_.new_();
|
||||
Db_rdr rdr = stmt_select_in.Clear().Crt_bry_as_str(fld_text, Bry_.Replace(word, Byte_ascii.Asterisk, Byte_ascii.Percent)).Exec_select__rls_manual();
|
||||
try {
|
||||
int row_count = 0;
|
||||
while (rdr.Move_next()) {
|
||||
synchronized (cxl) {
|
||||
if (cxl.Canceled()) break;
|
||||
}
|
||||
list.Add(new_row(rdr));
|
||||
Xowd_search_word_row word_row = new_row(rdr);
|
||||
if (++row_count % 100 == 0)
|
||||
Xoa_app_.Usr_dlg().Prog_many("", "", "search; reading pages for word: word=~{0} pages=~{1}", word_row.Text(), word_row.Page_count());
|
||||
list.Add(word_row);
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
import gplx.core.primitives.*;
|
||||
public interface Xow_domain_crt_itm {
|
||||
boolean Matches(Xow_domain cur, Xow_domain comp);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
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.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
class Xow_domain_crt_itm__any_wiki implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return true;}
|
||||
public static final Xow_domain_crt_itm__any_wiki I = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
|
||||
private final Xow_domain_crt_itm[] ary;
|
||||
public Xow_domain_crt_itm__in(Xow_domain_crt_itm[] ary) {this.ary = ary;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_itm itm = ary[i];
|
||||
if (itm.Matches(cur, comp)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
class Xow_domain_crt_itm__any_standard implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {
|
||||
switch (comp.Domain_tid()) {
|
||||
case Xow_domain_.Tid_int_wikipedia:
|
||||
case Xow_domain_.Tid_int_wiktionary:
|
||||
case Xow_domain_.Tid_int_wikisource:
|
||||
case Xow_domain_.Tid_int_wikivoyage:
|
||||
case Xow_domain_.Tid_int_wikiquote:
|
||||
case Xow_domain_.Tid_int_wikibooks:
|
||||
case Xow_domain_.Tid_int_wikiversity:
|
||||
case Xow_domain_.Tid_int_wikinews: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static final Xow_domain_crt_itm__any_standard I = new Xow_domain_crt_itm__any_standard(); Xow_domain_crt_itm__any_standard() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__null implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {throw Err_.not_implemented_msg_("null criteria should not be called");}
|
||||
public static final Xow_domain_crt_itm I = new Xow_domain_crt_itm__null(); Xow_domain_crt_itm__null() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__self implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(cur.Domain_bry(), comp.Domain_bry());}
|
||||
public static final Xow_domain_crt_itm__self I = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_lang implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return cur.Lang_uid() == comp.Lang_uid();}
|
||||
public static final Xow_domain_crt_itm__same_lang I = new Xow_domain_crt_itm__same_lang(); Xow_domain_crt_itm__same_lang() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_type implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return cur.Domain_tid() == comp.Domain_tid();}
|
||||
public static final Xow_domain_crt_itm__same_type I = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__lang implements Xow_domain_crt_itm {
|
||||
private final int lang_uid;
|
||||
public Xow_domain_crt_itm__lang(int lang_uid) {this.lang_uid = lang_uid;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Lang_uid() == lang_uid;}
|
||||
}
|
||||
class Xow_domain_crt_itm__type implements Xow_domain_crt_itm {
|
||||
private final int wiki_tid;
|
||||
public Xow_domain_crt_itm__type(int wiki_tid) {this.wiki_tid = wiki_tid;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Domain_tid() == wiki_tid;}
|
||||
}
|
||||
class Xow_domain_crt_itm__wiki implements Xow_domain_crt_itm {
|
||||
private final byte[] domain;
|
||||
public Xow_domain_crt_itm__wiki(byte[] domain) {this.domain = domain;}
|
||||
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(comp.Domain_bry(), domain);}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.langs.*;
|
||||
class Xow_domain_crt_itm_parser {
|
||||
public Xow_domain_crt_kv[] Parse_as_kv_ary_or_null(byte[] raw) {
|
||||
ListAdp rv = ListAdp_.new_();
|
||||
byte[][] line_ary = Bry_.Split_lines(raw);
|
||||
int line_len = line_ary.length;
|
||||
for (int i = 0; i < line_len; ++i) {
|
||||
byte[] line = line_ary[i];
|
||||
if (line.length == 0) continue; // ignore blank lines
|
||||
byte[][] word_ary = Bry_.Split(line, Byte_ascii.Pipe);
|
||||
int word_len = word_ary.length;
|
||||
if (word_len != 2) return null; // not A|B; exit now;
|
||||
Xow_domain_crt_itm key_itm = Xow_domain_crt_itm_parser.I.Parse_as_in(word_ary[0]);
|
||||
if (key_itm == Xow_domain_crt_itm__null.I) return null; // invalid key; exit
|
||||
Xow_domain_crt_itm val_itm = Xow_domain_crt_itm_parser.I.Parse_as_in(word_ary[1]);
|
||||
if (val_itm == Xow_domain_crt_itm__null.I) return null; // invalid val; exit
|
||||
rv.Add(new Xow_domain_crt_kv(key_itm, val_itm));
|
||||
}
|
||||
return (Xow_domain_crt_kv[])rv.Xto_ary_and_clear(Xow_domain_crt_kv.class);
|
||||
}
|
||||
public Xow_domain_crt_itm Parse_as_in(byte[] raw) {
|
||||
byte[][] terms = Bry_.Split(raw, Byte_ascii.Comma, Bool_.Y);
|
||||
int len = terms.length;
|
||||
Xow_domain_crt_itm[] rv_ary = new Xow_domain_crt_itm[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv_ary[i] = Parse_itm(terms[i]);
|
||||
return new Xow_domain_crt_itm__in(rv_ary);
|
||||
}
|
||||
public Xow_domain_crt_itm Parse_itm(byte[] raw) {
|
||||
Xow_domain_crt_itm rv = (Xow_domain_crt_itm)itm_hash.Get_by_bry(raw); if (rv != null) return rv; // singleton; EX: <self>, <same_type>, etc..
|
||||
int raw_len = raw.length;
|
||||
if (Bry_.HasAtBgn(raw, Wild_lang)) { // EX: *.wikipedia
|
||||
int wiki_tid = Xow_domain_.Tid__get_int(raw, Wild_lang.length, raw_len);
|
||||
return wiki_tid == Xow_domain_.Tid_int_null ? Xow_domain_crt_itm__null.I : new Xow_domain_crt_itm__type(wiki_tid);
|
||||
}
|
||||
else if (Bry_.HasAtEnd(raw, Wild_type)) { // EX: en.*
|
||||
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(raw, 0, raw_len - Wild_type.length);
|
||||
return lang_itm == null ? Xow_domain_crt_itm__null.I : new Xow_domain_crt_itm__lang(lang_itm.Id());
|
||||
}
|
||||
else
|
||||
return new Xow_domain_crt_itm__wiki(raw); // EX: en.wikipedia.org
|
||||
}
|
||||
private static final Hash_adp_bry itm_hash = Hash_adp_bry.cs_()
|
||||
.Add_str_obj("<self>" , Xow_domain_crt_itm__self.I)
|
||||
.Add_str_obj("<same_type>" , Xow_domain_crt_itm__same_type.I)
|
||||
.Add_str_obj("<same_lang>" , Xow_domain_crt_itm__same_lang.I)
|
||||
.Add_str_obj("*.*" , Xow_domain_crt_itm__any_standard.I)
|
||||
;
|
||||
private static final byte[] Wild_lang = Bry_.new_ascii_("*."), Wild_type = Bry_.new_ascii_(".*");
|
||||
public static final Xow_domain_crt_itm_parser I = new Xow_domain_crt_itm_parser(); Xow_domain_crt_itm_parser() {}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xow_domain_crt_kv_mgr {
|
||||
private final ListAdp list = ListAdp_.new_();
|
||||
public void Clear() {list.Clear();}
|
||||
@gplx.Internal protected void Add(Xow_domain_crt_kv itm) {list.Add(list);}
|
||||
public boolean Parse(byte[] raw) {
|
||||
Xow_domain_crt_kv[] ary = Xow_domain_crt_itm_parser.I.Parse_as_kv_ary_or_null(raw);
|
||||
if (ary == null) return false; // invalid parse; leave current value as is and exit;
|
||||
this.Clear();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
this.Add(ary[i]);
|
||||
return true;
|
||||
}
|
||||
public Xow_domain_crt_itm Find(Xow_domain cur, Xow_domain comp) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_kv kv = (Xow_domain_crt_kv)list.FetchAt(i);
|
||||
if (kv.Key().Matches(cur, comp)) return kv.Val();
|
||||
}
|
||||
return Xow_domain_crt_itm__null.I;
|
||||
}
|
||||
}
|
||||
class Xow_domain_crt_kv {
|
||||
public Xow_domain_crt_kv(Xow_domain_crt_itm key, Xow_domain_crt_itm val) {this.key = key; this.val = val;}
|
||||
public Xow_domain_crt_itm Key() {return key;} private final Xow_domain_crt_itm key;
|
||||
public Xow_domain_crt_itm Val() {return val;} private final Xow_domain_crt_itm val;
|
||||
}
|
||||
@@ -62,6 +62,11 @@ public class Gallery_itm_parser {
|
||||
if (cur_itm.Link_bgn() != -1)
|
||||
lnki_tkn.Link_tkn_(new Arg_nde_tkn_mock("link", String_.new_utf8_(src, cur_itm.Link_bgn(), cur_itm.Link_end()))); // NOTE: hackish, but add the link as arg_nde, since gallery link is not parsed like a regular lnki
|
||||
cur_itm.Lnki_tkn_(lnki_tkn);
|
||||
if (cur_itm.Page_bgn() != -1) {
|
||||
int page_val = Bry_.Xto_int_or(src, cur_itm.Page_bgn(), cur_itm.Page_end(), -1);
|
||||
if (page_val == -1) Xoa_app_.Usr_dlg().Warn_many("", "", "page is not an int: wiki=~{0} ttl=~{1} page=~{2}", wiki.Domain_str(), ctx.Cur_page().Ttl().Page_db(), String_.new_utf8_(src, cur_itm.Page_bgn(), cur_itm.Page_end()));
|
||||
lnki_tkn.Page_(page_val);
|
||||
}
|
||||
byte[] lnki_caption = cur_itm.Caption_bry();
|
||||
if (Bry_.Len_gt_0(lnki_caption)) {
|
||||
Xop_root_tkn caption_tkn = wiki.Parser().Parse_text_to_wdom_old_ctx(ctx, lnki_caption, true);
|
||||
|
||||
@@ -80,6 +80,12 @@ public class Gallery_mgr_base_basic_tst {
|
||||
@Test public void Link() {
|
||||
fxt.Test_html_frag("<gallery>File:A.png|b|link=c</gallery>", "<a href=\"/wiki/C\" class=\"image\"");
|
||||
}
|
||||
@Test public void Page() { // PURPOSE: page was not being set; PAGE:pt.s:Portal:Diccionario_geographico_do_Brazil; DATE:2015-04-16
|
||||
fxt.Test_html_frag
|
||||
( "<gallery>File:A.pdf|b|page=8</gallery>"
|
||||
, "A.pdf/120px-8.jpg" // make sure page 8 shows up
|
||||
);
|
||||
}
|
||||
@Test public void Alt_caption_multiple() {
|
||||
fxt.Test_html_frag("<gallery>File:A.png|alt=b|c[[d|e]]f</gallery>", "<div class=\"gallerytext\"><p>c<a href=\"/wiki/D\">ef</a>\n</p>");
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public class Scrib_invoke_func extends Pf_func_base {
|
||||
String invoke_error = Err_msg_make(e);
|
||||
Error(bfr, wiki.Msg_mgr(), invoke_error);
|
||||
bfr.Add(Html_tag_.Comm_bgn).Add_str(Err_.Message_gplx_brief(e)).Add(Html_tag_.Comm_end);
|
||||
Scrib_err_filter_mgr err_filter_mgr = invoke_wkr.Err_filter_mgr();
|
||||
if (err_filter_mgr.Count_gt_0() && err_filter_mgr.Match(String_.new_utf8_(mod_name), String_.new_utf8_(fnc_name), invoke_error))
|
||||
Scrib_err_filter_mgr err_filter_mgr = invoke_wkr == null ? null : invoke_wkr.Err_filter_mgr();
|
||||
if (err_filter_mgr == null || (err_filter_mgr.Count_gt_0() && err_filter_mgr.Match(String_.new_utf8_(mod_name), String_.new_utf8_(fnc_name), invoke_error)))
|
||||
ctx.App().Usr_dlg().Warn_many("", "", "invoke failed: ~{0} ~{1} ~{2}", String_.new_utf8_(ctx.Cur_page().Ttl().Raw()), String_.new_utf8_(src, self.Src_bgn(), self.Src_end()), Err_.Message_gplx_brief(e));
|
||||
Scrib_core.Core_invalidate_when_page_changes(); // NOTE: invalidate core when page changes, not for rest of page, else page with many errors will be very slow due to multiple invalidations; PAGE:th.d:all; DATE:2014-10-03
|
||||
}
|
||||
|
||||
@@ -16,14 +16,7 @@ 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.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
interface Xow_wmf_api_wkr {
|
||||
void Api_init();
|
||||
void Api_term();
|
||||
boolean Api_wiki_enabled(String wiki_domain);
|
||||
String Api_qargs();
|
||||
boolean Api_exec(String wiki_domain, byte[] rslt);
|
||||
}
|
||||
class Xow_wmf_api_mgr {
|
||||
public class Xow_wmf_api_mgr {
|
||||
public void Trg_engine_key(String v) {this.trg_engine_key = v;} private String trg_engine_key = gplx.ios.IoEngine_.SysKey;
|
||||
public void Api_exec(Xow_wmf_api_wkr wkr) {this.Api_exec(Wikis, wkr);}
|
||||
public void Api_exec(String[] wiki_ary, Xow_wmf_api_wkr wkr) {
|
||||
@@ -864,6 +857,9 @@ class Xow_wmf_api_mgr {
|
||||
, "zu.wikipedia.org"
|
||||
, "zu.wiktionary.org"
|
||||
, "zu.wikibooks.org"
|
||||
, "ne.wikipedia.org"
|
||||
, "ne.wiktionary.org"
|
||||
, "ne.wikibooks.org"
|
||||
};
|
||||
//, "als.wikisource.org"
|
||||
//, "als.wikinews.org"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.wdatas.imports; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wdatas.*;
|
||||
public interface Xow_wmf_api_wkr {
|
||||
void Api_init();
|
||||
void Api_term();
|
||||
boolean Api_wiki_enabled(String wiki_domain);
|
||||
String Api_qargs();
|
||||
boolean Api_exec(String wiki_domain, byte[] rslt);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser {
|
||||
data_mgr__core_mgr = new Xowd_db_mgr(fsys_mgr.Root_dir(), domain_itm);
|
||||
Io_url core_url = gplx.xowa.wikis.Xow_fsys_mgr.Find_core_fil(fsys_mgr.Root_dir(), domain_str);
|
||||
data_mgr__core_mgr.Init_by_load(core_url);
|
||||
this.db_core_mgr = Fsdb_db_mgr_.new_detect(domain_str, fsys_mgr.Root_dir(), fsys_mgr.File_dir());
|
||||
this.db_core_mgr = Fsdb_db_mgr_.new_detect(this, fsys_mgr.Root_dir(), fsys_mgr.File_dir());
|
||||
if (db_core_mgr != null) // will be null for xowa db
|
||||
fsdb_mgr.Mnt_mgr().Ctor_by_load(db_core_mgr);
|
||||
file_mgr__repo_mgr.Add_repo(app, fsys_mgr.File_dir(), Bry_.new_utf8_("commons.wikimedia.org"), Bry_.new_utf8_("simple.wikipedia.org"));
|
||||
|
||||
Reference in New Issue
Block a user