mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Create core dbs in proper subdirectory
This commit is contained in:
@@ -13,15 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoa_wiki_mgr extends Gfo_invk {
|
||||
int Count();
|
||||
boolean Has(byte[] key);
|
||||
Xow_wiki Get_at(int idx);
|
||||
Xow_wiki Get_by_or_null(byte[] key);
|
||||
Xow_wiki Get_by_or_make_init_y(byte[] key);
|
||||
Xow_wiki Get_by_or_make_init_n(byte[] key);
|
||||
void Add(Xow_wiki wiki);
|
||||
Xow_wiki Make(byte[] domain_bry, Io_url wiki_root_dir);
|
||||
Xow_wiki Import_by_url(Io_url fil);
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xoa_wiki_mgr_ {
|
||||
public static Xow_wiki Import_by_url(Xoa_app app, Xoa_wiki_mgr wiki_mgr, Io_url url) {
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get_or_noop(url); if (conn == Db_conn_.Noop) return null; // invalid url
|
||||
Db_cfg_tbl cfg_tbl = Xowd_cfg_tbl_.Get_or_null(conn); if (cfg_tbl == null) return null; // no xowa_cfg;
|
||||
byte[] wiki_domain = cfg_tbl.Select_bry(Xowd_cfg_key_.Grp__bldr_session, Xob_info_session.Cfg_key__wiki_domain); if (wiki_domain == null) return null;
|
||||
Io_url wiki_root_dir = url.OwnerDir();
|
||||
Xow_wiki rv = wiki_mgr.Make(wiki_domain, wiki_root_dir);
|
||||
wiki_mgr.Add(rv);
|
||||
rv.Init_by_wiki(); // must init for Modified_latest
|
||||
String wiki_date = rv.Props().Modified_latest__yyyy_MM_dd();
|
||||
app.User().User_db_mgr().Site_mgr().Import(rv.Domain_str(), rv.Domain_str(), wiki_root_dir.Raw(), wiki_date, "");
|
||||
if (app.Tid_is_edit()) {
|
||||
// get_or_new wiki and mark it offline so it can show up in wikis sidebar
|
||||
gplx.xowa.wikis.xwikis.Xow_xwiki_itm xwiki = app.User().Wikii().Xwiki_mgr().Get_by_key(wiki_domain);
|
||||
if (xwiki == null)
|
||||
xwiki = app.User().Wikii().Xwiki_mgr().Add_by_atrs(wiki_domain, wiki_domain);
|
||||
xwiki.Offline_(true);
|
||||
((Xoae_app)app).Gui_mgr().Html_mgr().Portal_mgr().Wikis().Itms_reset(); // dirty wiki list so that next refresh will load itm
|
||||
}
|
||||
rv.Rls(); // rls wiki, else open connections will cause later file copies to fail; DATE:2016-06-26
|
||||
rv.Init_needed_y_(); // mark Init_needed_y_(), else wiki may have NOOP connection which will hang around on next release
|
||||
return rv;
|
||||
}
|
||||
public static final String Invk__import_by_url = "import_by_url";
|
||||
}
|
||||
|
||||
@@ -13,37 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xoa_wiki_regy {
|
||||
private Xoae_app app;
|
||||
private boolean init_needed = true;
|
||||
private Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public Xoa_wiki_regy(Xoae_app app) {this.app = app;}
|
||||
public boolean Has(byte[] domain) {if (init_needed) Init(); return hash.Has(domain);}
|
||||
public void Clear() {
|
||||
hash.Clear();
|
||||
init_needed = true;
|
||||
}
|
||||
public boolean Url_is_invalid_domain(Xoa_url url) {
|
||||
if (!Bry_.Eq(url.Page_bry(), Xoa_page_.Main_page_bry)) return false; // page is not "Main_Page"; assume not an invalid domain str; EX: "uk/wiki/Main_Page"
|
||||
if ( Bry_.Eq(Xow_domain_tid_.Bry__home, url.Wiki_bry()) // wiki is "home"
|
||||
&& !Bry_.Eq(Xow_domain_tid_.Bry__home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
|
||||
return false; // special case to handle "home" which should mean "home" in any wiki, but "home/wiki/Main_Page" in home wiki
|
||||
return !this.Has(url.Wiki_bry());
|
||||
}
|
||||
private void Init() {
|
||||
init_needed = false;
|
||||
Io_url[] wiki_dirs = Io_mgr.Instance.QueryDir_args(app.Fsys_mgr().Wiki_dir()).DirInclude_(true).Recur_(false).ExecAsUrlAry();
|
||||
int wiki_dirs_len = wiki_dirs.length;
|
||||
for (int i = 0; i < wiki_dirs_len; i++) {
|
||||
Io_url wiki_dir = wiki_dirs[i];
|
||||
byte[] domain_bry = Bry_.new_u8(wiki_dir.NameOnly());
|
||||
hash.Add(domain_bry, domain_bry);
|
||||
}
|
||||
}
|
||||
public static void Make_wiki_dir(Xoa_app app, String domain_str) { // TEST: fake wiki_dir for Parse_from_url_bar; DATE:2014-02-16
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir();
|
||||
Io_mgr.Instance.CreateDir(wiki_dir.GenSubDir(domain_str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,118 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wbases.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.domains.crts.*; import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.metas.*;
|
||||
import gplx.xowa.addons.wikis.directorys.dbs.*;
|
||||
public class Xoae_wiki_mgr implements Xoa_wiki_mgr, Gfo_invk {
|
||||
private final Xoae_app app;
|
||||
private final List_adp list = List_adp_.New(); private final Hash_adp_bry hash = Hash_adp_bry.ci_a7(); // ASCII:url_domain; EX:en.wikipedia.org
|
||||
private Xowdir_db_mgr db_mgr;
|
||||
public Xoae_wiki_mgr(Xoae_app app) {
|
||||
this.app = app;
|
||||
this.wiki_regy = new Xoa_wiki_regy(app);
|
||||
this.wdata_mgr = new Wdata_wiki_mgr(app);
|
||||
}
|
||||
public Xoa_wiki_regy Wiki_regy() {return wiki_regy;} private final Xoa_wiki_regy wiki_regy;
|
||||
public Xow_script_mgr Scripts() {return scripts;} private final Xow_script_mgr scripts = new Xow_script_mgr();
|
||||
public Wdata_wiki_mgr Wdata_mgr() {return wdata_mgr;} private final Wdata_wiki_mgr wdata_mgr;
|
||||
public Xowe_wiki Wiki_commons() {
|
||||
synchronized (this) { // LOCK:app-level; DATE:2016-07-06
|
||||
Xowe_wiki rv = (Xowe_wiki)this.Get_by_or_null(Xow_domain_itm_.Bry__commons);
|
||||
if (rv != null) rv.Init_assert();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
public void Init_by_app() {
|
||||
this.db_mgr = new Xowdir_db_mgr(app.User().User_db_mgr().Conn());
|
||||
wdata_mgr.Init_by_app();
|
||||
}
|
||||
public int Count() {return list.Count();}
|
||||
public boolean Has(byte[] key) {return hash.Has(key);}
|
||||
public Xow_wiki Get_at(int idx) {return (Xow_wiki)list.Get_at(idx);}
|
||||
public Xowe_wiki Get_at_or_null(int i) {return Int_.Between(i, 0, this.Count() - 1) ? (Xowe_wiki)list.Get_at(i) : null;}
|
||||
public Xow_wiki Get_by_or_null(byte[] key) {return Bry_.Len_eq_0(key) ? null : (Xowe_wiki)hash.Get_by(key);}
|
||||
public Xow_wiki Get_by_or_make_init_y(byte[] key) {
|
||||
synchronized (this) { // LOCK:app-level; DATE:2016-07-06
|
||||
Xowe_wiki rv = (Xowe_wiki)this.Get_by_or_null(key); if (rv == null) rv = Make_and_add(key);
|
||||
rv.Init_assert();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
public Xow_wiki Get_by_or_make_init_n(byte[] key) {return Get_by_or_make(key);}
|
||||
public Xowe_wiki Get_by_or_make(byte[] key) {
|
||||
Xowe_wiki rv = (Xowe_wiki)this.Get_by_or_null(key); if (rv == null) rv = Make_and_add(key);
|
||||
return rv;
|
||||
}
|
||||
public void Add(Xow_wiki wiki) {
|
||||
if (hash.Get_by_bry(wiki.Domain_bry()) != null) return; // if already there, don't add again; basically, Add_if_dupe_use_1st
|
||||
hash.Add(wiki.Domain_bry(), wiki);
|
||||
list.Add(wiki);
|
||||
}
|
||||
public Xowe_wiki Make_and_add(byte[] domain_bry) {
|
||||
// get wiki_root_url from either user_wiki or /xowa/wiki/
|
||||
Xowdir_wiki_itm user_wiki_itm = db_mgr == null
|
||||
? null // TEST:
|
||||
: db_mgr.Tbl__wiki().Select_by_key_or_null(String_.new_u8(domain_bry));
|
||||
|
||||
Xowe_wiki rv = null;
|
||||
if (user_wiki_itm == null) {
|
||||
rv = (Xowe_wiki)Make(domain_bry, app.Fsys_mgr().Wiki_dir().GenSubDir(String_.new_a7(domain_bry)));
|
||||
Add(rv);
|
||||
}
|
||||
else {
|
||||
rv = gplx.xowa.addons.wikis.directorys.specials.items.bldrs.Xow_wiki_factory.Load_personal(app, domain_bry, user_wiki_itm.Url().OwnerDir());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xow_wiki Make(byte[] domain_bry, Io_url wiki_root_dir) {
|
||||
// init domain
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
|
||||
// get lang from domain; if not wmf, default to en
|
||||
byte[] lang_key = domain_itm.Lang_actl_key();
|
||||
if (lang_key == Xol_lang_stub_.Key__unknown) lang_key = Xol_lang_itm_.Key_en; // unknown langs default to english; note that this makes nonwmf english by default
|
||||
Xol_lang_itm lang = app.Lang_mgr().Get_by_or_new(lang_key);
|
||||
if (domain_itm.Domain_type_id() == Xow_domain_tid_.Tid__other) {
|
||||
lang = new Xol_lang_itm(app.Lang_mgr(), Xol_lang_itm_.Key_en).Kwd_mgr__strx_(true); // create a new english lang, but enable strx functions; DATE:2015-08-23
|
||||
Xol_lang_itm_.Lang_init(lang);
|
||||
}
|
||||
|
||||
// load ns from site_meta
|
||||
Xow_ns_mgr ns_mgr = app.Dbmeta_mgr().Ns__get_or_load(domain_bry);
|
||||
if (ns_mgr.Ids_len() == 0) ns_mgr = Xow_ns_mgr_.default_(lang.Case_mgr()); // non-wmf wikis will use default ns_mgr
|
||||
|
||||
return new Xowe_wiki(app, lang, ns_mgr, domain_itm, wiki_root_dir);
|
||||
}
|
||||
public Xow_wiki Import_by_url(Io_url url) {return Xoa_wiki_mgr_.Import_by_url(app, this, url);}
|
||||
public void Del(byte[] key) {hash.Del(key);}
|
||||
public void Clear() {hash.Clear(); list.Clear();}
|
||||
public void Free_mem(boolean clear_ctx) {
|
||||
int list_len = list.Count();
|
||||
for (int i = 0; i < list_len; i++) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)list.Get_at(i);
|
||||
// wiki.Defn_cache().ReduceCache();
|
||||
if (clear_ctx) wiki.Parser_mgr().Ctx().Clear_all(); // NOTE: clear_ctx will reset toc and refs
|
||||
wiki.Cache_mgr().Page_cache().Free_mem(true);
|
||||
wiki.Cache_mgr().Tmpl_result_cache().Clear();
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)list.Get_at(i);
|
||||
wiki.Rls();
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_by_or_make(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_scripts)) return scripts;
|
||||
else if (ctx.Match(k, Invk_wdata)) return wdata_mgr;
|
||||
else if (ctx.Match(k, Invk_len)) return this.Count();
|
||||
else if (ctx.Match(k, Invk_get_at)) return this.Get_at_or_null(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Xoa_wiki_mgr_.Invk__import_by_url)) return this.Import_by_url(m.ReadIoUrl("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_get = "get", Invk_scripts = "scripts", Invk_wdata = "wdata";
|
||||
private static final String Invk_len = "len", Invk_get_at = "get_at";
|
||||
}
|
||||
|
||||
@@ -13,30 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.xtns.wbases.*;
|
||||
public class Xow_page_tid {
|
||||
public static byte Identify(int wiki_tid, int ns_id, byte[] ttl) {
|
||||
switch (ns_id) {
|
||||
case Xow_ns_.Tid__mediawiki:
|
||||
byte rv = Identify_by_ttl(ttl);
|
||||
return rv == Tid_wikitext ? Tid_msg : rv; // if mediawiki ns, but not css / js, return msg, not wikitext; DATE:2016-09-12
|
||||
case Xow_ns_.Tid__user:
|
||||
return Identify_by_ttl(ttl);
|
||||
case Xow_ns_.Tid__module:
|
||||
return (Bry_.Has_at_end(ttl, Ext_doc))
|
||||
? Tid_wikitext : Tid_lua;
|
||||
default:
|
||||
return Wdata_wiki_mgr.Wiki_page_is_json(wiki_tid, ns_id)
|
||||
? Tid_json : Tid_wikitext;
|
||||
}
|
||||
}
|
||||
public static byte Identify_by_ttl(byte[] ttl) {
|
||||
if (Bry_.Has_at_end(ttl, Ext_css)) return Tid_css;
|
||||
else if (Bry_.Has_at_end(ttl, Ext_js)) return Tid_js;
|
||||
else return Tid_wikitext;
|
||||
}
|
||||
private static final byte[] Ext_js = Bry_.new_a7(".js"), Ext_css = Bry_.new_a7(".css"), Ext_doc= Bry_.new_a7("/doc");
|
||||
public static final byte Tid_wikitext = 1, Tid_json = 2, Tid_js = 3, Tid_css = 4, Tid_lua = 5, Tid_msg = 6;
|
||||
}
|
||||
|
||||
@@ -13,58 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.files.repos.*;
|
||||
public class Xowv_repo_mgr implements Xow_repo_mgr {
|
||||
private final List_adp repos = List_adp_.New();
|
||||
public Xof_repo_pair[] Repos_ary() {return (Xof_repo_pair[])repos.To_ary(Xof_repo_pair.class);}
|
||||
public Xof_repo_pair Repos_get_by_wiki(byte[] wiki) {
|
||||
int len = repos.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_pair pair = (Xof_repo_pair)repos.Get_at(i);
|
||||
if (Bry_.Eq(wiki, pair.Wiki_domain()))
|
||||
return pair;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_pair Repos_get_at(int i) {return (Xof_repo_pair)repos.Get_at(i);}
|
||||
private Xof_repo_pair Repos_get_by_id(int id) {
|
||||
int len = repos.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xof_repo_pair pair = (Xof_repo_pair)repos.Get_at(i);
|
||||
if (pair.Id() == id) return pair;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xof_repo_itm Get_trg_by_id_or_null(int id, byte[] lnki_ttl, byte[] page_url) {
|
||||
Xof_repo_pair pair = Repos_get_by_id(id);
|
||||
if (pair == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "repo_mgr.invalid_repo: repo=~{0} lnki_ttl=~{1} page_url=~{2}", id, lnki_ttl, page_url);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return pair.Trg();
|
||||
}
|
||||
public Xof_repo_itm Get_src_by_id_or_null(int id, byte[] lnki_ttl, byte[] page_url) {
|
||||
Xof_repo_pair pair = Repos_get_by_id(id);
|
||||
if (pair == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "repo_mgr.invalid_repo: repo=~{0} lnki_ttl=~{1} page_url=~{2}", id, lnki_ttl, page_url);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return pair.Src();
|
||||
}
|
||||
public Xof_repo_pair Add_repo(Xoa_app app, Io_url wiki_root, byte[] src_repo_key, byte[] trg_repo_key) {
|
||||
Xof_repo_itm src_repo = Add(app, wiki_root, src_repo_key), trg_repo = Add(app, wiki_root, trg_repo_key);
|
||||
byte[] src_wiki_key = src_repo.Wiki_domain();//, trg_wiki_key = trg_repo.Wiki_key();
|
||||
// if (!Bry_.Eq(src_wiki_key, trg_wiki_key) && !Bry_.Eq(src_wiki_key, Xow_domain_tid_.Bry__home)) throw Err_mgr.Instance.fmt_(GRP_KEY, "add_repo", "wiki keys do not match: ~{0} ~{1}", String_.new_u8(src_wiki_key), String_.new_u8(trg_wiki_key));
|
||||
Xof_repo_pair pair = new Xof_repo_pair((byte)repos.Count(), src_wiki_key, src_repo, trg_repo);
|
||||
repos.Add(pair);
|
||||
return pair;
|
||||
}
|
||||
private Xof_repo_itm Add(Xoa_app app, Io_url wiki_root, byte[] wiki_domain) {
|
||||
Xof_repo_itm itm = new Xof_repo_itm(wiki_domain, app.Fsys_mgr(), null, wiki_domain);
|
||||
itm.Root_str_(wiki_root.Raw());
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,131 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.brys.*; import gplx.core.ios.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.apps.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.origs.*; import gplx.xowa.files.fsdb.*; import gplx.xowa.files.bins.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.site_stats.*; import gplx.xowa.wikis.data.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.addons.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.htmls.utls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.hzips.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.fsys.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*;
|
||||
import gplx.xowa.specials.mgrs.*;
|
||||
import gplx.xowa.addons.wikis.htmls.css.bldrs.*; import gplx.xowa.addons.wikis.htmls.css.mgrs.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser, Gfo_invk {
|
||||
private final Xof_fsdb_mgr__sql fsdb_mgr; private Fsdb_db_mgr db_core_mgr;
|
||||
private boolean init_needed = true;
|
||||
public Xowv_wiki(Xoav_app app, byte[] domain_bry, Io_url wiki_root_dir) {
|
||||
this.app = app;
|
||||
|
||||
// domain vars
|
||||
this.domain_bry = domain_bry;
|
||||
this.domain_str = String_.new_u8(domain_bry);
|
||||
this.domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
this.domain_tid = domain_itm.Domain_type_id();
|
||||
this.domain_abrv = Xow_abrv_wm_.To_abrv(domain_itm);
|
||||
|
||||
this.fsys_mgr = new Xow_fsys_mgr(wiki_root_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str));
|
||||
|
||||
this.ns_mgr = Xow_ns_mgr_.default_(app.Utl_case_mgr());
|
||||
this.lang = app.Lang_mgr().Get_by_or_en(domain_itm.Lang_actl_key()); // NOTE: must not be null, or causes null ref exception on redlinks in drd; DATE:2016-06-28
|
||||
this.msg_mgr = new Xow_msg_mgr(this, lang);
|
||||
this.html__hdump_mgr = new Xow_hdump_mgr(this);
|
||||
this.special_mgr = new Xosp_special_mgr(this);
|
||||
this.fsdb_mgr = new Xof_fsdb_mgr__sql();
|
||||
this.url__parser = new Xow_url_parser(this);
|
||||
this.xwiki_mgr = new Xow_xwiki_mgr(this);
|
||||
this.stats = new Xowd_site_stats_mgr(this);
|
||||
this.lnki_bldr = new Xoh_lnki_bldr(app, href_wtr);
|
||||
this.ctg_catpage_mgr = new Xoctg_catpage_mgr(this);
|
||||
}
|
||||
public Xoa_app App() {return app;}
|
||||
public boolean Type_is_edit() {return Bool_.N;}
|
||||
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private final String domain_str;
|
||||
public Xow_domain_itm Domain_itm() {return domain_itm;} private final Xow_domain_itm domain_itm;
|
||||
public int Domain_tid() {return domain_tid;} private final int domain_tid;
|
||||
public byte[] Domain_abrv() {return domain_abrv;} private final byte[] domain_abrv;
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;} private final Xow_ns_mgr ns_mgr;
|
||||
public Xow_fsys_mgr Fsys_mgr() {return fsys_mgr;} private Xow_fsys_mgr fsys_mgr;
|
||||
public Xow_db_mgr Data__core_mgr() {return data_mgr__core_mgr;} private Xow_db_mgr data_mgr__core_mgr;
|
||||
public Xow_repo_mgr File__repo_mgr() {return file_mgr__repo_mgr;} private Xowv_repo_mgr file_mgr__repo_mgr = new Xowv_repo_mgr();
|
||||
public Xof_fsdb_mode File__fsdb_mode() {return file_mgr__fsdb_mode;} private final Xof_fsdb_mode file_mgr__fsdb_mode = Xof_fsdb_mode.New__v2__gui();
|
||||
public Fsdb_db_mgr File__fsdb_core() {return db_core_mgr;}
|
||||
public Xof_orig_mgr File__orig_mgr() {return orig_mgr;} private final Xof_orig_mgr orig_mgr = new Xof_orig_mgr();
|
||||
public Xof_bin_mgr File__bin_mgr() {return fsdb_mgr.Bin_mgr();}
|
||||
public Fsm_mnt_mgr File__mnt_mgr() {return fsdb_mgr.Mnt_mgr();}
|
||||
public Xoh_lnki_bldr Html__lnki_bldr() {return lnki_bldr;} private final Xoh_lnki_bldr lnki_bldr;
|
||||
public Xoh_href_wtr Html__href_wtr() {return href_wtr;} private final Xoh_href_wtr href_wtr = new Xoh_href_wtr();
|
||||
public boolean Html__hdump_enabled() {return Bool_.Y;}
|
||||
public Xow_hdump_mgr Html__hdump_mgr() {return html__hdump_mgr;} private final Xow_hdump_mgr html__hdump_mgr;
|
||||
public boolean Html__css_installing() {return html__css_installing;} public void Html__css_installing_(boolean v) {html__css_installing = v;} private boolean html__css_installing;
|
||||
public Xoh_page_wtr_mgr Html__wtr_mgr() {return html__wtr_mgr;} private final Xoh_page_wtr_mgr html__wtr_mgr = new Xoh_page_wtr_mgr(Bool_.Y);
|
||||
public Xoctg_pagebox_wtr Ctg__pagebox_wtr() {return ctg_pagebox_wtr;} private final Xoctg_pagebox_wtr ctg_pagebox_wtr = new Xoctg_pagebox_wtr();
|
||||
public Xoctg_catpage_mgr Ctg__catpage_mgr() {return ctg_catpage_mgr;} private final Xoctg_catpage_mgr ctg_catpage_mgr;
|
||||
public Xow_msg_mgr Msg_mgr() {return msg_mgr;} private final Xow_msg_mgr msg_mgr;
|
||||
public byte[] Wtxt__expand_tmpl(byte[] src) {return src;}
|
||||
public Xow_mw_parser_mgr Mw_parser_mgr() {return mw_parser_mgr;} private final Xow_mw_parser_mgr mw_parser_mgr = new Xow_mw_parser_mgr();
|
||||
public Xow_wiki_props Props() {return props;} private final Xow_wiki_props props = new Xow_wiki_props();
|
||||
public Xol_lang_itm Lang() {return lang;} private final Xol_lang_itm lang;
|
||||
public Xol_case_mgr Case_mgr() {if (case_mgr == null) case_mgr = Xol_case_mgr_.U8(); return case_mgr;} private Xol_case_mgr case_mgr;
|
||||
public Xowd_site_stats_mgr Stats() {return stats;} private final Xowd_site_stats_mgr stats;
|
||||
public Bry_bfr_mkr Utl__bfr_mkr() {return utl__bry_bfr_mkr;} private final Bry_bfr_mkr utl__bry_bfr_mkr = new Bry_bfr_mkr();
|
||||
public Io_stream_zip_mgr Utl__zip_mgr() {return utl__zip_mgr;} private final Io_stream_zip_mgr utl__zip_mgr = new Io_stream_zip_mgr();
|
||||
public Xow_url_parser Utl__url_parser() {return url__parser;} private final Xow_url_parser url__parser;
|
||||
public Xoax_addon_mgr Addon_mgr() {return addon_mgr;} private final Xoax_addon_mgr addon_mgr = new Xoax_addon_mgr();
|
||||
public Xosp_special_mgr Special_mgr() {return special_mgr;} private Xosp_special_mgr special_mgr;
|
||||
public Xow_xwiki_mgr Xwiki_mgr() {return xwiki_mgr;} private final Xow_xwiki_mgr xwiki_mgr;
|
||||
public Xoav_app Appv() {return app;} private final Xoav_app app;
|
||||
public boolean Embeddable_enabled() {return embeddable_enabled;} public void Embeddable_enabled_(boolean v) {this.embeddable_enabled = v;} private boolean embeddable_enabled;
|
||||
public void Init_by_wiki() {
|
||||
if (!init_needed) return;
|
||||
init_needed = false;
|
||||
if (String_.Eq(domain_str, "xowa")) return; // HACK: ignore "xowa" for now; WHEN:converting xowa to sqlitedb
|
||||
data_mgr__core_mgr = new Xow_db_mgr(fsys_mgr.Root_dir(), this.domain_str);
|
||||
Xow_db_mgr.Init_by_load(this, gplx.xowa.wikis.data.Xow_db_file__core_.Find_core_fil_or_null(this));
|
||||
app.Html__css_installer().Install(this, Xowd_css_core_mgr.Key_mobile); // must init after data_mgr
|
||||
this.db_core_mgr = Fsdb_db_mgr_.new_detect(this, fsys_mgr.Root_dir(), fsys_mgr.File_dir());
|
||||
if (db_core_mgr == null) // no fsdb; occurs during merge; also, will be null for xowa_db; DATE:2016-05-31
|
||||
db_core_mgr = Fsdb_db_mgr__v2_bldr.Get_or_make(this, true);
|
||||
else // fsdb exists; load it
|
||||
fsdb_mgr.Mnt_mgr().Ctor_by_load(db_core_mgr);
|
||||
file_mgr__repo_mgr.Add_repo(app, fsys_mgr.File_dir(), Xow_domain_itm_.Bry__commons, Xow_domain_itm_.Bry__commons);
|
||||
file_mgr__repo_mgr.Add_repo(app, fsys_mgr.File_dir(), domain_bry, domain_bry);
|
||||
Xof_orig_tbl[] orig_tbls = db_core_mgr == null ? new Xof_orig_tbl[0] : db_core_mgr.File__orig_tbl_ary();
|
||||
orig_mgr.Init_by_wiki(this, file_mgr__fsdb_mode, orig_tbls, Xof_url_bldr.new_v2());
|
||||
fsdb_mgr.Init_by_wiki(this);
|
||||
data_mgr__core_mgr.Db__core().Tbl__ns().Select_all(ns_mgr);
|
||||
data_mgr__core_mgr.Db__core().Tbl__site_stats().Select(stats);
|
||||
html__hdump_mgr.Init_by_db(this);
|
||||
app.Addon_mgr().Load_by_wiki(this);
|
||||
ctg_pagebox_wtr.Init_by_wiki(this);
|
||||
ctg_catpage_mgr.Init_by_wiki(this);
|
||||
}
|
||||
public void Init_by_wiki__force() {init_needed = true; Init_by_wiki();}
|
||||
public void Init_by_make(Xowd_core_db_props props, gplx.xowa.bldrs.infos.Xob_info_session info_session) {
|
||||
data_mgr__core_mgr = new Xow_db_mgr(fsys_mgr.Root_dir(), this.domain_str);
|
||||
data_mgr__core_mgr.Init_by_make(props, info_session);
|
||||
html__hdump_mgr.Init_by_db(this);
|
||||
}
|
||||
public void Rls() {
|
||||
data_mgr__core_mgr.Rls();
|
||||
fsdb_mgr.Rls();
|
||||
}
|
||||
public void Pages_get(Xoh_page rv, Gfo_url url, Xoa_ttl ttl) {
|
||||
if (init_needed) Init_by_wiki();
|
||||
if (ttl.Ns().Id_is_special())
|
||||
special_mgr.Get_by_ttl(rv, url, ttl);
|
||||
else
|
||||
html__hdump_mgr.Load_mgr().Load_by_xowh(rv, ttl, Bool_.Y);
|
||||
}
|
||||
public Xoa_ttl Ttl_parse(byte[] ttl) {return Ttl_parse(ttl, 0, ttl.length);}
|
||||
public Xoa_ttl Ttl_parse(byte[] src, int src_bgn, int src_end) {return Xoa_ttl.Parse(app.Utl_amp_mgr(), app.Utl_case_mgr(), xwiki_mgr, ns_mgr, src, src_bgn, src_end);}
|
||||
public Xoa_ttl Ttl_parse(int ns_id, byte[] ttl) {return Xoa_ttl.Parse(this, ns_id, ttl);}
|
||||
public void Init_needed_y_() {this.init_needed = true;}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {throw Err_.new_unimplemented_w_msg("implemented for Xoa_cfg_mgr");}
|
||||
}
|
||||
|
||||
@@ -13,72 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.caches.*;
|
||||
import gplx.xowa.wikis.xwikis.sitelinks.*;
|
||||
public class Xow_cache_mgr {
|
||||
private final Xowe_wiki wiki;
|
||||
public Xow_cache_mgr(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.page_cache = new Xow_page_cache(wiki);
|
||||
this.defn_cache = new Xow_defn_cache(wiki.Lang());
|
||||
this.ifexist_cache = new Xow_ifexist_cache(wiki, page_cache);
|
||||
}
|
||||
public Hash_adp Tmpl_result_cache() {return tmpl_result_cache;} private final Hash_adp tmpl_result_cache = Hash_adp_bry.cs();
|
||||
public Xow_defn_cache Defn_cache() {return defn_cache;} private final Xow_defn_cache defn_cache;
|
||||
public Hash_adp_bry Lst_cache() {return lst_cache;} private final Hash_adp_bry lst_cache = Hash_adp_bry.cs();
|
||||
public Hash_adp Misc_cache() {return misc_cache;} private final Hash_adp misc_cache = Hash_adp_.New();
|
||||
public Xow_page_cache Page_cache() {return page_cache;} private Xow_page_cache page_cache;
|
||||
public Gfo_cache_mgr Commons_cache() {return commons_cache;} private Gfo_cache_mgr commons_cache = new Gfo_cache_mgr().Max_size_(64 * Io_mgr.Len_mb).Reduce_by_(32 * Io_mgr.Len_mb);
|
||||
public Xow_ifexist_cache Ifexist_cache() {return ifexist_cache;} private Xow_ifexist_cache ifexist_cache;
|
||||
|
||||
public Xow_cache_mgr Page_cache_(Xow_page_cache v) {this.page_cache = v; return this;}
|
||||
public Xow_cache_mgr Commons_cache_(Gfo_cache_mgr v) {this.commons_cache = v; return this;}
|
||||
public Xow_cache_mgr Ifexist_cache_(Xow_ifexist_cache v) {this.ifexist_cache = v; return this;}
|
||||
public void Load_wkr_(Xow_page_cache_wkr v) {
|
||||
page_cache.Load_wkr_(v);
|
||||
ifexist_cache.Load_wkr_(v);
|
||||
}
|
||||
public Keyval[] Scrib_lang_names() {
|
||||
if (scrib_lang_names == null) {
|
||||
List_adp list = List_adp_.New();
|
||||
Xoa_sitelink_itm_mgr itm_mgr = wiki.App().Xwiki_mgr__sitelink_mgr().Itm_mgr();
|
||||
int len = itm_mgr.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoa_sitelink_itm itm = itm_mgr.Get_at(i);
|
||||
Keyval kv = Keyval_.new_(String_.new_u8(itm.Key()), String_.new_u8(itm.Name()));
|
||||
list.Add(kv);
|
||||
}
|
||||
scrib_lang_names = (Keyval[])list.To_ary(Keyval.class);
|
||||
}
|
||||
return scrib_lang_names;
|
||||
}
|
||||
public void Free_mem__page() {this.Free_mem(Free_mem__page_tid);}
|
||||
public void Free_mem__wbase() {this.Free_mem(Free_mem__wbase_tid);}
|
||||
public void Free_mem__all() {this.Free_mem(Free_mem__all_tid);}
|
||||
private void Free_mem(int level) {
|
||||
switch (level) {
|
||||
case Free_mem__page_tid:
|
||||
page_cache.Free_mem(false);
|
||||
break;
|
||||
case Free_mem__wbase_tid:
|
||||
page_cache.Free_mem(false);
|
||||
wiki.Appe().Wiki_mgr().Wdata_mgr().Clear();
|
||||
break;
|
||||
case Free_mem__all_tid:
|
||||
page_cache.Free_mem(true);
|
||||
wiki.Appe().Wiki_mgr().Wdata_mgr().Clear();
|
||||
commons_cache.Clear();
|
||||
ifexist_cache.Clear();
|
||||
break;
|
||||
}
|
||||
wiki.Ctg__catpage_mgr().Free_mem_all();
|
||||
tmpl_result_cache.Clear();
|
||||
defn_cache.Free_mem_all();
|
||||
lst_cache.Clear();
|
||||
misc_cache.Clear();
|
||||
// scrib_lang_names = null;
|
||||
}
|
||||
private static final int Free_mem__page_tid = 0, Free_mem__wbase_tid = 1, Free_mem__all_tid = 2;
|
||||
private static Keyval[] scrib_lang_names;
|
||||
}
|
||||
|
||||
@@ -13,24 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.intls.*; import gplx.core.caches.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xow_defn_cache { // stores compiled Xot_defn
|
||||
private final Xol_lang_itm lang; // needed to lowercase names;
|
||||
private final Bry_bfr upper_1st_bfr = Bry_bfr_.Reset(255);
|
||||
private final Gfo_cache_mgr cache = new Gfo_cache_mgr().Max_size_(64 * 1024 * 1024).Reduce_by_(32 * 1024 * 1024);
|
||||
public Xow_defn_cache(Xol_lang_itm lang) {this.lang = lang;}
|
||||
public Xot_defn Get_by_key(byte[] name) {return (Xot_defn)cache.Get_by_key(name);}
|
||||
public void Free_mem_all() {cache.Clear();}
|
||||
public void Add(Xot_defn defn, byte case_match) {
|
||||
byte[] name = defn.Name();
|
||||
cache.Add_replace(name, defn, defn.Cache_size());
|
||||
if (case_match == Xow_ns_case_.Tid__1st) {
|
||||
name = lang.Case_mgr().Case_build_1st_upper(upper_1st_bfr, name, 0, name.length);
|
||||
cache.Add_replace(name, defn, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,79 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.caches.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_ifexist_cache {
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xow_page_cache page_cache;
|
||||
private final Gfo_cache_mgr cache_mgr = new Gfo_cache_mgr().Max_size_(64 * Io_mgr.Len_mb).Reduce_by_(32 * Io_mgr.Len_mb);
|
||||
private final Hash_adp ns_loaded_hash = Hash_adp_.New();
|
||||
private final Xow_ifexist_itm itm__exists = new Xow_ifexist_itm(Bool_.Y), itm__missing = new Xow_ifexist_itm(Bool_.N);
|
||||
public Xow_ifexist_cache(Xowe_wiki wiki, Xow_page_cache page_cache) {
|
||||
this.wiki = wiki;
|
||||
this.page_cache = page_cache;
|
||||
}
|
||||
public Xow_ifexist_cache Cache_sizes_(int max, int reduce) {
|
||||
cache_mgr.Max_size_(max).Reduce_by_(reduce);
|
||||
return this;
|
||||
}
|
||||
public void Load_wkr_(Xow_page_cache_wkr v) {this.load_wkr = v;} private Xow_page_cache_wkr load_wkr;
|
||||
public void Clear() {
|
||||
cache_mgr.Clear();
|
||||
ns_loaded_hash.Clear();
|
||||
}
|
||||
public void Add(Xoa_ttl ttl) {
|
||||
byte[] key = ttl.Full_db();
|
||||
cache_mgr.Add(key, itm__exists, key.length);
|
||||
}
|
||||
public void Add_ns_loaded(int... ns_ids) {
|
||||
for (int ns_id : ns_ids)
|
||||
ns_loaded_hash.Add(ns_id, ns_id);
|
||||
}
|
||||
public byte Get_by_mem(Xoa_ttl ttl) {
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
|
||||
// check cache_mgr
|
||||
Xow_ifexist_itm found = (Xow_ifexist_itm)cache_mgr.Get_by_key(ttl_full_db);
|
||||
if (found != null) return found.Exists() ? Bool_.Y_byte : Bool_.N_byte;
|
||||
|
||||
// check ns_loaded cache (xomp only); if exists, return false, since all pages in ns are loaded, and still not found
|
||||
if (ns_loaded_hash.Has(ttl.Ns().Id())) return Bool_.N_byte;
|
||||
|
||||
// check page_cache since full page + text could be loaded there
|
||||
Xow_page_cache_itm itm = (Xow_page_cache_itm)page_cache.Get_or_null(ttl_full_db);
|
||||
if (itm == Xow_page_cache_itm.Missing)
|
||||
return Bool_.N_byte;
|
||||
else if (itm != null)
|
||||
return Bool_.Y_byte;
|
||||
|
||||
return Bool_.__byte;
|
||||
}
|
||||
public boolean Load(Xoa_ttl ttl) {
|
||||
byte[] key = ttl.Full_db();
|
||||
Xow_ifexist_itm itm = null;
|
||||
// gplx.core.consoles.Console_adp__sys.Instance.Write_str("ifexist_cache:" + String_.new_u8(key));
|
||||
|
||||
if (load_wkr != null) {
|
||||
// load_wkr; should call ifexist method, but for now, load entire page
|
||||
byte[] page_text = load_wkr.Get_page_or_null(key);
|
||||
itm = page_text == null ? itm__missing : itm__exists;
|
||||
}
|
||||
else {
|
||||
// page_tbl
|
||||
Xowd_page_itm page_itm = new Xowd_page_itm();
|
||||
wiki.Db_mgr().Load_mgr().Load_by_ttl(page_itm, ttl.Ns(), ttl.Page_db());
|
||||
itm = page_itm.Exists() ? itm__exists : itm__missing;
|
||||
}
|
||||
|
||||
// add
|
||||
cache_mgr.Add(key, itm, key.length);
|
||||
return itm == itm__exists;
|
||||
}
|
||||
}
|
||||
class Xow_ifexist_itm implements Rls_able {
|
||||
public Xow_ifexist_itm(boolean exists) {this.exists = exists;}
|
||||
public boolean Exists() {return exists;} private final boolean exists;
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -13,112 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_page_cache {
|
||||
private final Object thread_lock = new Object();
|
||||
private final Xowe_wiki wiki;
|
||||
private final Ordered_hash cache = Ordered_hash_.New_bry(); // NOTE: wiki titles are not case-sensitive when ns is "1st-letter" (EX: w:earth an w:Earth); in these cases, two entries will be stored
|
||||
private final List_adp deleted = List_adp_.New();
|
||||
public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;}
|
||||
public void Load_wkr_(Xow_page_cache_wkr v) {this.load_wkr = v;} private Xow_page_cache_wkr load_wkr;
|
||||
public Xow_page_cache_itm Get_or_null(byte[] ttl_full_db) {return (Xow_page_cache_itm)cache.Get_by(ttl_full_db);}
|
||||
public byte[] Get_or_load_as_src(Xoa_ttl ttl) {
|
||||
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
|
||||
return rv == null ? null : rv.Wtxt__direct();
|
||||
}
|
||||
public void Add(byte[] ttl_full_db, Xow_page_cache_itm itm) {
|
||||
cache.Add(ttl_full_db, itm);
|
||||
}
|
||||
private void Add_safe(byte[] ttl_full_db, Xow_page_cache_itm itm) {
|
||||
synchronized (thread_lock) { // LOCK:high-usage;DATE:2016-07-14
|
||||
if (!cache.Has(ttl_full_db)) { // check again that itm is not in cache; note that this is necessary as cache.Get is not in "synchronized" block (for performance reasons); DATE:2016-12-12
|
||||
cache.Add(ttl_full_db, itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Del(byte[] ttl_full_db) {
|
||||
cache.Del(ttl_full_db);
|
||||
}
|
||||
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by(ttl_full_db);
|
||||
if (rv == Xow_page_cache_itm.Missing) {
|
||||
return null;
|
||||
}
|
||||
else if (rv == null) {
|
||||
return Load_page(ttl, ttl_full_db);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private Xow_page_cache_itm Load_page(Xoa_ttl ttl, byte[] ttl_full_db) {
|
||||
Xow_page_cache_itm rv = null;
|
||||
Xoa_ttl page_ttl = ttl;
|
||||
boolean page_exists = false;
|
||||
byte[] page_text = null;
|
||||
byte[] page_redirect_from = null;
|
||||
// gplx.core.consoles.Console_adp__sys.Instance.Write_str("page_cache:" + String_.new_u8(ttl_full_db));
|
||||
if (load_wkr != null) {
|
||||
page_text = load_wkr.Get_page_or_null(ttl_full_db);
|
||||
page_exists = page_text != null;
|
||||
}
|
||||
if (page_text == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
page_ttl = page.Ttl();
|
||||
page_text = page.Db().Text().Text_bry();
|
||||
page_exists = page.Db().Page().Exists();
|
||||
page_redirect_from = page.Redirect_trail().Itms__get_wtxt_at_0th_or_null();
|
||||
}
|
||||
if (page_exists) {
|
||||
rv = new Xow_page_cache_itm(false, page_ttl, page_text, page_redirect_from);
|
||||
Add_safe(ttl_full_db, rv);
|
||||
}
|
||||
else {
|
||||
Add_safe(ttl_full_db, Xow_page_cache_itm.Missing);
|
||||
rv = null;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xow_page_cache_itm Get_or_load_as_itm_2(Xoa_ttl ttl) { // NOTE: same as Get_or_load_as_itm, but handles redirects to missing pages; DATE:2016-05-02
|
||||
byte[] ttl_full_db = ttl.Full_db();
|
||||
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by(ttl_full_db);
|
||||
if (rv == Xow_page_cache_itm.Missing) return null;
|
||||
else if (rv == null) {
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
|
||||
if ( page.Db().Page().Exists() // page exists
|
||||
|| page.Redirect_trail().Itms__len() > 0 ) { // page redirects to missing page; note that page.Missing == true and page.Redirected_src() != null; PAGE: en.w:Shah_Rukh_Khan; DATE:2016-05-02
|
||||
rv = new Xow_page_cache_itm(false, page.Ttl(), page.Db().Text().Text_bry(), page.Redirect_trail().Itms__get_wtxt_at_0th_or_null());
|
||||
Add_safe(ttl_full_db, rv);
|
||||
}
|
||||
else {
|
||||
Add_safe(ttl_full_db, Xow_page_cache_itm.Missing);
|
||||
rv = null;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Free_mem(boolean clear_permanent_itms) {
|
||||
synchronized (thread_lock) { // LOCK:app-level; DATE:2016-07-06
|
||||
if (clear_permanent_itms) {
|
||||
cache.Clear();
|
||||
}
|
||||
else {
|
||||
// gather non-permanent items
|
||||
int len = cache.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_page_cache_itm itm = (Xow_page_cache_itm)cache.Get_at(i);
|
||||
if (!itm.Cache_permanently())
|
||||
deleted.Add(itm);
|
||||
}
|
||||
|
||||
// remove non-permanent items
|
||||
len = deleted.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_page_cache_itm itm = (Xow_page_cache_itm)deleted.Get_at(i);
|
||||
if (itm.Ttl() != null) // missing is null
|
||||
cache.Del(itm.Ttl().Full_db());
|
||||
}
|
||||
deleted.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,32 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_page_cache_itm implements Xowd_text_bry_owner {
|
||||
public Xow_page_cache_itm(boolean cache_permanently, Xoa_ttl ttl, byte[] wtxt__direct, byte[] wtxt__redirect) {
|
||||
this.cache_permanently = cache_permanently;
|
||||
this.ttl = ttl; this.wtxt__direct = wtxt__direct; this.wtxt__redirect = wtxt__redirect;
|
||||
}
|
||||
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
|
||||
public byte[] Wtxt__direct() {return wtxt__direct;} private byte[] wtxt__direct;
|
||||
public byte[] Wtxt__redirect() {return wtxt__redirect;} private byte[] wtxt__redirect;
|
||||
public byte[] Wtxt__redirect_or_direct() {
|
||||
return wtxt__redirect == null ? wtxt__direct : wtxt__redirect;
|
||||
}
|
||||
public boolean Cache_permanently() {return cache_permanently;} private final boolean cache_permanently;
|
||||
|
||||
// used by xomp
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public int Redirect_id() {return redirect_id;} private int redirect_id;
|
||||
public void Set_text_bry_by_db(byte[] v) {this.wtxt__direct = v;}
|
||||
public void Set_page_ids(int page_id, int redirect_id) {this.page_id = page_id; this.redirect_id = redirect_id;}
|
||||
public void Set_redirect(Xoa_ttl ttl, byte[] trg_wtxt) {
|
||||
this.ttl = ttl;
|
||||
this.wtxt__redirect = wtxt__direct;
|
||||
this.wtxt__direct = trg_wtxt;
|
||||
}
|
||||
|
||||
public static final Xow_page_cache_itm Null = null;
|
||||
public static final Xow_page_cache_itm Missing = new Xow_page_cache_itm(false, null, null, null);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public interface Xow_page_cache_wkr {
|
||||
byte[] Get_page_or_null(byte[] full_db);
|
||||
}
|
||||
|
||||
@@ -13,150 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.tdbs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xow_data_mgr_tst {
|
||||
Xow_data_mgr_fxt fxt = new Xow_data_mgr_fxt();
|
||||
@Before public void init() {fxt.Clear(); Datetime_now.Manual_y_();}
|
||||
@After public void term() {Datetime_now.Manual_n_();}
|
||||
@Test public void Create() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!;|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Update() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Update("B12", "B12 changed")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!>|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 changed\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Update_zip() {
|
||||
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.streams.Io_stream_tid_.Tid__zip);
|
||||
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
|
||||
// fxt .Create("A1", "A1 data")
|
||||
// .Create("B12", "B12 data")
|
||||
// .Create("C123", "C123 data")
|
||||
// .Update("B12", "B12 changed")
|
||||
// .Tst_regy_title("0|A1|C123|3\n")
|
||||
// .Tst_data_title(String_.Concat_lines_nl
|
||||
// ( "!!!!>|!!!!?|!!!!@|"
|
||||
// , "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
// , "!!!!\"|!!!!!|!!!!\"|0|!!!!,|B12"
|
||||
// , "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
// ))
|
||||
// .Tst_data_page(String_.Concat_lines_nl
|
||||
// ( "zipped:!!!!9|!!!!>|!!!!=|"
|
||||
// , "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
// , "!!!!\"\t##PX/\tB12\tB12 changed\t"
|
||||
// , "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
// ))
|
||||
// ;
|
||||
}
|
||||
@Test public void Create_out_of_order() {
|
||||
fxt .Create("C123", "C123 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("A1", "A1 data")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!=|!!!!;|!!!!9|"
|
||||
, "!!!!!\t##PX+\tC123\tC123 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tA1\tA1 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
@Test public void Rename() {
|
||||
fxt .Create("A1", "A1 data")
|
||||
.Create("B12", "B12 data")
|
||||
.Create("C123", "C123 data")
|
||||
.Rename("C123", "C1234")
|
||||
.Tst_regy_title("0|A1|C123|3\n")
|
||||
.Tst_data_title(String_.Concat_lines_nl
|
||||
( "!!!!>|!!!!?|!!!!@|"
|
||||
, "!!!!!|!!!!!|!!!!!|0|!!!!(|A1"
|
||||
, "!!!!\"|!!!!!|!!!!\"|0|!!!!)|B12"
|
||||
, "!!!!#|!!!!!|!!!!#|0|!!!!*|C123"
|
||||
))
|
||||
.Tst_data_page(String_.Concat_lines_nl
|
||||
( "!!!!9|!!!!;|!!!!=|"
|
||||
, "!!!!!\t##PX+\tA1\tA1 data\t"
|
||||
, "!!!!\"\t##PX/\tB12\tB12 data\t"
|
||||
, "!!!!#\t##PX0\tC123\tC123 data\t"
|
||||
))
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xow_data_mgr_fxt {
|
||||
Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public void Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
wiki.Db_mgr().Save_mgr().Page_id_next_(0);
|
||||
}
|
||||
public Xow_data_mgr_fxt Create(String ttl_str, String data) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
|
||||
wiki.Db_mgr().Save_mgr().Data_create(ttl, Bry_.new_u8(data));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Update(String ttl_str, String data) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttl_str));
|
||||
Xoae_page page = Xoae_page.New_test(wiki, ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_update(page, Bry_.new_u8(data));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Rename(String old_ttl, String new_ttl) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(old_ttl));
|
||||
Xoae_page page = Xoae_page.New_test(wiki, ttl);
|
||||
wiki.Db_mgr().Save_mgr().Data_rename(page, ttl.Ns().Id(), Bry_.new_u8(new_ttl));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Tst_regy_title(String expd) {return Tst_regy(Xotdb_dir_info_.Name_title, expd);}
|
||||
Xow_data_mgr_fxt Tst_regy(String name, String expd) {
|
||||
Io_url file_orig = Io_url_.mem_fil_("mem/xowa/wiki/en.wikipedia.org/ns/000/" + name + "/reg.csv");
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Tid__main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Tid__main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,101 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.infos.*;
|
||||
import gplx.xowa.wikis.data.site_stats.*;
|
||||
import gplx.xowa.htmls.core.dbs.*; import gplx.xowa.addons.wikis.searchs.dbs.*;
|
||||
import gplx.xowa.addons.wikis.htmls.css.dbs.*;
|
||||
import gplx.xowa.xtns.wbases.dbs.*;
|
||||
public class Xow_db_file {
|
||||
protected Xow_db_file(Db_cfg_tbl cfg_tbl, Xowd_core_db_props props, Xob_info_session info_session, Xob_info_file info_file, Xow_db_file_schema_props schema_props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid, Db_conn conn, byte cmd_mode) {
|
||||
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid; this.db_props = props;
|
||||
this.conn = conn; this.cmd_mode = cmd_mode;
|
||||
this.url_rel = url.NameAndExt();
|
||||
boolean schema_is_1 = props.Schema_is_1();
|
||||
this.tbl__cfg = cfg_tbl;
|
||||
this.tbl__db = new Xowd_xowa_db_tbl(conn, schema_is_1);
|
||||
this.tbl__ns = new Xowd_site_ns_tbl(conn, schema_is_1);
|
||||
this.tbl__site_stats = new Xowd_site_stats_tbl(conn, schema_is_1);
|
||||
this.tbl__page = new Xowd_page_tbl(conn, schema_is_1);
|
||||
this.tbl__text = new Xowd_text_tbl(conn, schema_is_1, props.Zip_tid_text());
|
||||
this.tbl__html = new Xowd_html_tbl(conn);
|
||||
this.tbl__css_core = new Xowd_css_core_tbl(conn);
|
||||
this.tbl__css_file = new Xowd_css_file_tbl(conn);
|
||||
this.tbl__cat_core = new Xowd_cat_core_tbl(conn, schema_is_1);
|
||||
this.tbl__cat_link = new Xowd_cat_link_tbl(conn, schema_is_1);
|
||||
this.tbl__wbase_qid = new Xowd_wbase_qid_tbl(conn, schema_is_1, schema_props == null ? Bool_.N : schema_props.Wbase__qid__src_ttl_has_spaces());
|
||||
this.tbl__wbase_pid = new Xowd_wbase_pid_tbl(conn, schema_is_1);
|
||||
this.tbl__wbase_prop = new Xowb_prop_tbl(conn);
|
||||
this.info_session = info_session;
|
||||
this.info_file = info_file;
|
||||
this.schema_props = schema_props;
|
||||
}
|
||||
public int Id() {return id;} private final int id; // unique id in xowa_db
|
||||
public byte Tid() {return tid;} private final byte tid;
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public Io_url Url() {return url;} private final Io_url url;
|
||||
public String Url_rel() {return url_rel;} private final String url_rel;
|
||||
public Xowd_core_db_props Db_props() {return db_props;} private final Xowd_core_db_props db_props;
|
||||
public String Ns_ids() {return ns_ids;} private final String ns_ids;
|
||||
public int Ns_id_or_fail() {return Int_.Parse(ns_ids);}
|
||||
public int Part_id() {return part_id;} private final int part_id;
|
||||
public Guid_adp Guid() {return guid;} private final Guid_adp guid;
|
||||
public byte Cmd_mode() {return cmd_mode;} public Xow_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
|
||||
public long File_len() {return file_len;} public Xow_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
|
||||
public long File_max() {return file_max;} public Xow_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
|
||||
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
|
||||
public Xowd_xowa_db_tbl Tbl__db() {return tbl__db;} private final Xowd_xowa_db_tbl tbl__db;
|
||||
public Xowd_site_ns_tbl Tbl__ns() {return tbl__ns;} private final Xowd_site_ns_tbl tbl__ns;
|
||||
public Xowd_page_tbl Tbl__page() {return tbl__page;} private Xowd_page_tbl tbl__page;
|
||||
public Xowd_text_tbl Tbl__text() {return tbl__text;} private final Xowd_text_tbl tbl__text;
|
||||
public Xowd_html_tbl Tbl__html() {return tbl__html;} private final Xowd_html_tbl tbl__html;
|
||||
public Xowd_css_core_tbl Tbl__css_core() {return tbl__css_core;} private final Xowd_css_core_tbl tbl__css_core;
|
||||
public Xowd_css_file_tbl Tbl__css_file() {return tbl__css_file;} private final Xowd_css_file_tbl tbl__css_file;
|
||||
public Xowd_cat_core_tbl Tbl__cat_core() {return tbl__cat_core;} private final Xowd_cat_core_tbl tbl__cat_core;
|
||||
public Xowd_cat_link_tbl Tbl__cat_link() {return tbl__cat_link;} private final Xowd_cat_link_tbl tbl__cat_link;
|
||||
public Xowd_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xowd_site_stats_tbl tbl__site_stats;
|
||||
public Xowd_wbase_qid_tbl Tbl__wbase_qid() {return tbl__wbase_qid;} private final Xowd_wbase_qid_tbl tbl__wbase_qid;
|
||||
public Xowd_wbase_pid_tbl Tbl__wbase_pid() {return tbl__wbase_pid;} private final Xowd_wbase_pid_tbl tbl__wbase_pid;
|
||||
public Xowb_prop_tbl Tbl__wbase_prop() {return tbl__wbase_prop;} private final Xowb_prop_tbl tbl__wbase_prop;
|
||||
public Xob_info_session Info_session() {
|
||||
if (info_session == null) // NOTE: null when load; !null when make
|
||||
info_session = Xob_info_session.Load(tbl__cfg);
|
||||
return info_session;
|
||||
} private Xob_info_session info_session;
|
||||
public Xob_info_file Info_file() {
|
||||
if (info_file == null) // NOTE: null when load; !null when make
|
||||
info_file = Xob_info_file.Load(tbl__cfg);
|
||||
return info_file;
|
||||
} private Xob_info_file info_file;
|
||||
public Xow_db_file_schema_props Schema_props() {
|
||||
if (schema_props == null)
|
||||
schema_props = Xow_db_file_schema_props.load_(tbl__cfg, tid, this.Info_session().Version()); // NOTE: must call .Info_session
|
||||
return schema_props;
|
||||
} private Xow_db_file_schema_props schema_props;
|
||||
|
||||
public void Rls() {conn.Rls_conn();}
|
||||
public Xowd_page_tbl Tbl__page__rebind() {
|
||||
this.tbl__page = new Xowd_page_tbl(tbl__page.Conn(), tbl__page.schema_is_1);
|
||||
return tbl__page;
|
||||
}
|
||||
|
||||
public static final Xow_db_file Null = null;
|
||||
public static Xow_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_.New();
|
||||
Xob_info_file info_file = new Xob_info_file(id, Xow_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
|
||||
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn);
|
||||
Xow_db_file rv = new Xow_db_file(cfg_tbl, props, info_session, info_file, Xow_db_file_schema_props.make_(), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_create);
|
||||
cfg_tbl.Create_tbl(); // always create cfg in each db
|
||||
return rv;
|
||||
}
|
||||
public static Xow_db_file Load(Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid) {
|
||||
Db_conn conn = Db_conn_bldr.Instance.Get(url);
|
||||
if (conn == null) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "wiki.db:missing db; tid=~{0} url=~{1}", Xow_db_file_.To_key(tid), url.Raw());
|
||||
conn = Db_conn_.Noop;
|
||||
}
|
||||
Db_cfg_tbl cfg_tbl = gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn); // NOTE: this loads the cfg tbl for the current db, not the core db
|
||||
return new Xow_db_file(cfg_tbl, props, null, null, null, id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_ignore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,49 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_db_file_ {
|
||||
public static final int Uid__core = 0;
|
||||
public static final byte
|
||||
Tid__core = 1, Tid__text = 2, Tid__cat = 3, Tid__search_core = 4, Tid__wbase = 5 // SERIALIZED:v1
|
||||
, Tid__cat_core = 6, Tid__cat_link = 7 // SERIALIZED:v2
|
||||
, Tid__wiki_solo = 8, Tid__text_solo = 9
|
||||
, Tid__html_solo = 10, Tid__html_data = 11
|
||||
, Tid__file_solo = 12, Tid__file_core = 13, Tid__file_data = 14, Tid__file_user = 15
|
||||
, Tid__search_link = 16, Tid__random = 17, Tid__css = 18
|
||||
, Tid__html_user = 19
|
||||
;
|
||||
private static final String
|
||||
Key__core = "core", Key__text = "text", Key__cat = "xtn.category", Key__search_core = "xtn.search.core", Key__wbase = "core.wbase"
|
||||
, Key__cat_core = "xtn.category.core", Key__cat_link = "xtn.category.link"
|
||||
, Key__text_solo = "text.solo", Key__wiki_solo = "wiki.solo"
|
||||
, Key__html_solo = "html.solo", Key__html_data = "html"
|
||||
, Key__file_solo = "file.solo", Key__file_core = "file.core", Key__file_data = "file.data", Key__file_user = "file.user"
|
||||
, Key__search_link = "xtn.search.link", Key__random = "xtn.random", Key__css = "xtn.css"
|
||||
, Key__html_user = "html.user"
|
||||
;
|
||||
public static String To_key(byte v) {
|
||||
switch (v) {
|
||||
case Tid__core: return Key__core;
|
||||
case Tid__text: return Key__text;
|
||||
case Tid__cat: return Key__cat;
|
||||
case Tid__search_core: return Key__search_core;
|
||||
case Tid__wbase: return Key__wbase;
|
||||
case Tid__cat_core: return Key__cat_core;
|
||||
case Tid__cat_link: return Key__cat_link;
|
||||
case Tid__wiki_solo: return Key__wiki_solo;
|
||||
case Tid__text_solo: return Key__text_solo;
|
||||
case Tid__html_solo: return Key__html_solo;
|
||||
case Tid__html_data: return Key__html_data;
|
||||
case Tid__file_solo: return Key__file_solo;
|
||||
case Tid__file_core: return Key__file_core;
|
||||
case Tid__file_data: return Key__file_data;
|
||||
case Tid__file_user: return Key__file_user;
|
||||
case Tid__search_link: return Key__search_link;
|
||||
case Tid__random: return Key__random;
|
||||
case Tid__css: return Key__css;
|
||||
case Tid__html_user: return Key__html_user;
|
||||
default: throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,119 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xow_db_file__core_ {
|
||||
public static Io_url Find_core_fil_or_null(Xow_wiki wiki) {return Find_core_fil_or_null(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());}
|
||||
public static Io_url Find_core_fil_or_null(Io_url wiki_root_dir, String domain_str) {
|
||||
Io_url[] ary = Io_mgr.Instance.QueryDir_fils(wiki_root_dir);
|
||||
int ary_len = ary.length; if (ary.length == 0) return null;
|
||||
Io_url rv = Find_core_fil__xowa(ary, ary_len, domain_str);
|
||||
return rv == null ? Find_core_fil__sqlite3(wiki_root_dir, ary, ary_len, domain_str) : rv;
|
||||
}
|
||||
private static Io_url Find_core_fil__xowa(Io_url[] ary, int ary_len, String domain_str) {
|
||||
// search for ALL ("en.wikipedia.org") or FEW / LOT ("en.wikipedia.org-core")
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Io_url itm = ary[i];
|
||||
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
|
||||
if ( String_.Eq(itm.NameOnly(), domain_str) // EX: "en.wikipedia.org"
|
||||
|| String_.Eq(itm.NameOnly(), domain_str + "-core") // EX: "en.wikipedia.org-core"
|
||||
) {
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2.standard: url=~{0}", itm.Raw());
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
|
||||
// handle old "FEW" layout where "-text" existed, but not "-core"; DB.FEW: DATE:2016-06-07
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Io_url itm = ary[i];
|
||||
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
|
||||
if (String_.Eq(itm.NameOnly(), domain_str + "-text")) { // EX: "en.wikipedia.org-text"
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2.old_few: url=~{0}", itm.Raw());
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
|
||||
// handle renamed directories; EX: "en.wikipedia.org" -> "en.wikipedia.org-201609"; DATE:2016-10-13
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Io_url itm = ary[i];
|
||||
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
|
||||
if (String_.Has_at_end(itm.NameOnly(), "-core")){ // only check "-core" databases. note that this can also include "en.wikipedia.org-file-core.xowa"
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.Get_or_fail(itm);
|
||||
|
||||
// if db has "xowa_db" then assume that it is the core
|
||||
if (core_conn.Meta_tbl_exists(gplx.xowa.wikis.data.tbls.Xowd_xowa_db_tbl.TBL_NAME)) {
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2.renamed: url=~{0}", itm.Raw());
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private static Io_url Find_core_fil__sqlite3(Io_url wiki_root_dir, Io_url[] ary, int ary_len, String domain_str) {
|
||||
Io_url rv = null;
|
||||
String v0_str = domain_str + ".000";
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Io_url itm = ary[i];
|
||||
if (!String_.Eq(itm.Ext(), ".sqlite3")) continue;
|
||||
if (String_.Eq(itm.NameOnly(), v0_str)) { // EX: "en.wikipedia.org.000"
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v1: url=~{0}", itm.Raw());
|
||||
return itm;
|
||||
}
|
||||
if (ary_len == 1) {
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.custom: url=~{0}", itm.Raw());
|
||||
return rv; // 1 folder and 1 sqlite file; return it; custom wikis?
|
||||
}
|
||||
}
|
||||
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.none: dir=~{0}", wiki_root_dir.Raw());
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static boolean Is_core_fil_name(String domain_name, String fil_name) {
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(Bry_.new_u8(domain_name));
|
||||
if (domain_itm.Domain_type_id() == Xow_domain_tid_.Tid__other) {
|
||||
return String_.Has_at_end(fil_name, ".xowa");
|
||||
}
|
||||
String domain_str = domain_itm.Domain_str();
|
||||
return ( String_.Eq(fil_name, domain_str + "-text.xowa")
|
||||
|| String_.Eq(fil_name, domain_str + "-core.xowa")
|
||||
|| String_.Eq(fil_name, domain_str + ".xowa")
|
||||
);
|
||||
}
|
||||
|
||||
public static Xow_db_file Make_core_db(Xowd_core_db_props props, Xob_info_session info_session, Io_url wiki_root_dir, String domain_str) {
|
||||
String core_file_name = Xow_db_file__core_.Core_file_name(props.Layout_text(), domain_str);
|
||||
byte core_db_tid = Xow_db_file__core_.Core_db_tid(props.Layout_text());
|
||||
Io_url core_db_url = wiki_root_dir.GenSubFil(core_file_name);
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.New(core_db_url);
|
||||
|
||||
// make tbls
|
||||
Xow_db_file rv = Xow_db_file.Make(info_session, props, Xow_db_file_.Uid__core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, core_conn);
|
||||
rv.Tbl__db().Create_tbl();
|
||||
rv.Tbl__ns().Create_tbl();
|
||||
rv.Tbl__site_stats().Create_tbl();
|
||||
rv.Tbl__page().Create_tbl();
|
||||
if (props.Layout_text().Tid_is_all_or_few()) { // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
|
||||
rv.Tbl__cat_core().Create_tbl();
|
||||
rv.Tbl__cat_link().Create_tbl();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
private static String Core_file_name(Xow_db_layout layout, String domain_name) {
|
||||
switch (layout.Tid()) {
|
||||
case Xow_db_layout.Tid__all: return domain_name + ".xowa"; // EX: en.wikipedia.org.xowa
|
||||
case Xow_db_layout.Tid__few: //return domain_name + "-text.xowa"; // EX: en.wikipedia.org-text.xowa // DB.FEW: DATE:2016-06-07
|
||||
case Xow_db_layout.Tid__lot: return domain_name + "-core.xowa"; // EX: en.wikipedia.org-core.xowa
|
||||
default: throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
public static byte Core_db_tid(Xow_db_layout layout) {
|
||||
switch (layout.Tid()) {
|
||||
case Xow_db_layout.Tid__all: return Xow_db_file_.Tid__wiki_solo;
|
||||
case Xow_db_layout.Tid__few: // return Xow_db_file_.Tid__core; // DB.FEW: DATE:2016-06-07
|
||||
case Xow_db_layout.Tid__lot: return Xow_db_file_.Tid__core;
|
||||
default: throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
class Xow_db_file_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.New();
|
||||
public int Count_total() {return count_total;} private int count_total;
|
||||
public void Clear() {hash.Clear(); count_total = 0;}
|
||||
public Ordered_hash Get_by_tid_or_null(byte tid) {return (Ordered_hash)hash.Get_by(tid);}
|
||||
public void Add_or_new(Xow_db_file file) {
|
||||
byte tid = file.Tid();
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
|
||||
if (tids == null) {
|
||||
tids = Ordered_hash_.New();
|
||||
hash.Add(tid, tids);
|
||||
}
|
||||
tids.Add(file.Id(), file);
|
||||
++count_total;
|
||||
}
|
||||
public void Del(Xow_db_file file) {
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(file.Tid());
|
||||
if (tids == null) throw Err_.new_wo_type("unknown file.tid", "url", file.Url());
|
||||
if (!tids.Has(file.Id())) throw Err_.new_wo_type("unknown file.id", "url", file.Url());
|
||||
tids.Del(file.Id());
|
||||
--count_total;
|
||||
}
|
||||
public int Count_of_tid(byte tid) {
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
|
||||
return tids == null ? 0 : tids.Count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,24 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.cfgs.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xow_db_file_schema_props {
|
||||
Xow_db_file_schema_props(boolean search__word__page_count_exists, boolean wbase__qid__src_ttl_has_spaces) {
|
||||
this.search__word__page_count_exists = search__word__page_count_exists;
|
||||
this.wbase__qid__src_ttl_has_spaces = wbase__qid__src_ttl_has_spaces;
|
||||
}
|
||||
public boolean Search__word__page_count_exists() {return search__word__page_count_exists;} private final boolean search__word__page_count_exists;
|
||||
public boolean Wbase__qid__src_ttl_has_spaces() {return wbase__qid__src_ttl_has_spaces;} private final boolean wbase__qid__src_ttl_has_spaces;
|
||||
public static Xow_db_file_schema_props make_() {return new Xow_db_file_schema_props(Bool_.Y, Bool_.N);}
|
||||
public static Xow_db_file_schema_props load_(Db_cfg_tbl tbl, int tid, String version) {
|
||||
boolean search__word__page_count_exists = tbl.Select_yn_or(Grp, Key__col_search_word_page_count, Bool_.N);
|
||||
boolean wbase__qid__src_ttl_has_spaces = String_.In(version, "2.4.2.1", "2.4.3.1", "2.4.3.2");
|
||||
return new Xow_db_file_schema_props(search__word__page_count_exists, wbase__qid__src_ttl_has_spaces);
|
||||
}
|
||||
public static final String Grp = Xowd_cfg_key_.Grp__wiki_schema;
|
||||
public static final String
|
||||
Key__tbl_css_core = "tbl.css_core" // VERSION:2.4.1
|
||||
, Key__col_search_word_page_count = "col.search_word.word_page_count" // VERSION:2.4.2
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,33 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_db_layout {
|
||||
public Xow_db_layout(int tid) {this.tid = tid;}
|
||||
public int Tid() {return tid;} private final int tid;
|
||||
public boolean Tid_is_all() {return tid == Tid__all;}
|
||||
public boolean Tid_is_all_or_few() {return tid != Tid__lot;}
|
||||
public boolean Tid_is_lot() {return tid == Tid__lot;}
|
||||
public String Key() {
|
||||
switch (tid) {
|
||||
case Xow_db_layout.Tid__all: return Key__all;
|
||||
case Xow_db_layout.Tid__few: return Key__few;
|
||||
case Xow_db_layout.Tid__lot: return Key__lot;
|
||||
default: throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
|
||||
public static final int Tid__all = 1, Tid__few = 2, Tid__lot = 3;
|
||||
public static final String Key__all = "all", Key__few = "few", Key__lot = "lot";
|
||||
public static final Xow_db_layout
|
||||
Itm_all = new Xow_db_layout(Tid__all)
|
||||
, Itm_few = new Xow_db_layout(Tid__few)
|
||||
, Itm_lot = new Xow_db_layout(Tid__lot)
|
||||
;
|
||||
public static Xow_db_layout Get_by_name(String v) {
|
||||
if (String_.Eq(v, Key__all)) return Itm_all;
|
||||
else if (String_.Eq(v, Key__few)) return Itm_few;
|
||||
else if (String_.Eq(v, Key__lot)) return Itm_lot;
|
||||
else throw Err_.new_unimplemented();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,218 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.core.lists.hashs.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*; import gplx.xowa.wikis.metas.*;
|
||||
public class Xow_db_mgr {
|
||||
private final Io_url wiki_root_dir;
|
||||
private final String domain_str; // needed for generating new files; EX: en.wikipedia.org-text.ns.001.xowa
|
||||
private final Ordered_hash hash_by_id = Ordered_hash_.New(); private final Xow_db_file_hash hash_by_tids = new Xow_db_file_hash();
|
||||
private int db_id_next = 0;
|
||||
public Xow_db_mgr(Io_url wiki_root_dir, String domain_str) {
|
||||
this.wiki_root_dir = wiki_root_dir;
|
||||
this.domain_str = domain_str;
|
||||
}
|
||||
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
|
||||
public Db_cfg_tbl Tbl__cfg() {return db__core.Tbl__cfg();}
|
||||
public Xowd_page_tbl Tbl__page() {return db__core.Tbl__page();}
|
||||
public Xow_db_file Db__core() {return db__core;} private Xow_db_file db__core;
|
||||
public Xow_db_file Db__text() {return db__text;} private Xow_db_file db__text;
|
||||
public Xow_db_file Db__html() {return db__html;} private Xow_db_file db__html;
|
||||
public Xow_db_file Db__cat_core() {return db__cat_core;} private Xow_db_file db__cat_core;
|
||||
public Xow_db_file Db__wbase() {return db__wbase;} private Xow_db_file db__wbase; public void Db__wbase_(Xow_db_file v) {db__wbase = v;}
|
||||
public void Init_by_load(Io_url core_url) {
|
||||
// clear lists
|
||||
hash_by_id.Clear();
|
||||
hash_by_tids.Clear();
|
||||
|
||||
// create core_conn / core_db
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
|
||||
props = Xowd_core_db_props.Cfg_load(core_conn); // load props to get layout_text
|
||||
Dbs__set_by_tid(Xow_db_file.Load(props, Xow_db_file_.Uid__core, Xow_db_file__core_.Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
|
||||
|
||||
// load dbs from "xowa_db" tbl
|
||||
Xow_db_file[] ary = db__core.Tbl__db().Select_all(props, core_url.OwnerDir());
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_db_file db = ary[i];
|
||||
Dbs__set_by_tid(db);
|
||||
Dbs__add(db);
|
||||
}
|
||||
}
|
||||
public void Init_by_make(Xowd_core_db_props props, Xob_info_session info_session) {
|
||||
this.props = props;
|
||||
|
||||
// save data
|
||||
Xow_db_file core_db = Xow_db_file__core_.Make_core_db(props, info_session, wiki_root_dir, domain_str);
|
||||
Dbs__set_by_tid(core_db);
|
||||
Dbs__add_and_save(core_db);
|
||||
props.Cfg_save(db__core.Tbl__cfg()); // NOTE: must save cfg now, especially zip_tid; latter will be reloaded after import is done;
|
||||
}
|
||||
public void Rls() {
|
||||
int len = hash_by_id.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_db_file db_file = (Xow_db_file)hash_by_id.Get_at(i);
|
||||
db_file.Rls();
|
||||
}
|
||||
}
|
||||
|
||||
public int Dbs__len() {return hash_by_id.Len();}
|
||||
public Xow_db_file Dbs__get_at(int i) {return (Xow_db_file)hash_by_id.Get_at(i);}
|
||||
public Xow_db_file Dbs__get_by_id_or_fail(int id) {return (Xow_db_file)hash_by_id.Get_by_or_fail(id);}
|
||||
public Xow_db_file Dbs__get_by_id_or_null(int id) {return (Xow_db_file)hash_by_id.Get_by(id);}
|
||||
public Xow_db_file Dbs__get_by_tid_or_core(byte... tids_ary) {Xow_db_file rv = Dbs__get_by_tid_or_null(tids_ary); return rv == null ? db__core : rv;}
|
||||
public Xow_db_file Dbs__get_by_tid_or_null(byte... tids_ary) {
|
||||
int tids_len = tids_ary.length;
|
||||
for (int i = 0; i < tids_len; ++i) {
|
||||
byte tid = tids_ary[i];
|
||||
Ordered_hash tid_dbs = hash_by_tids.Get_by_tid_or_null(tid); if (tid_dbs == null) continue;
|
||||
int tid_dbs_len = tid_dbs.Len();
|
||||
if (tid_dbs_len != 1) { // NOTE: occurs when multiple search imports fail; DATE:2016-04-04
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "expecting only 1 db for tid; tid=~{0} len=~{1} db_api=~{2}", tid, tid_dbs.Len(), db__core.Conn().Conn_info().Db_api());
|
||||
}
|
||||
return (Xow_db_file)tid_dbs.Get_at(tid_dbs_len - 1); // get last idx;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Xow_db_file Dbs__assert_by_tid(byte tid) {
|
||||
Xow_db_file rv = Dbs__get_by_tid_or_null(tid);
|
||||
if (rv == null) {
|
||||
rv = Dbs__make_by_tid(tid);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Ordered_hash Dbs__get_hash_by_tid(int tid) {return hash_by_tids.Get_by_tid_or_null((byte)tid);}
|
||||
public Xow_db_file Dbs__make_by_tid(byte tid) {
|
||||
int tid_idx = Get_tid_idx(hash_by_tids, tid);
|
||||
return Dbs__make_by_tid(tid, Xob_info_file.Ns_ids_empty, tid_idx, Get_tid_name(tid_idx, tid));
|
||||
}
|
||||
public Xow_db_file Dbs__make_by_tid(byte tid, String ns_ids, int part_id, String file_name_suffix) {
|
||||
return Dbs__make_by_id(db_id_next++, tid, ns_ids, part_id, file_name_suffix);
|
||||
}
|
||||
public Xow_db_file Dbs__make_by_id(int id, byte tid, String ns_ids, int part_id, String file_name_suffix) {
|
||||
Io_url url = wiki_root_dir.GenSubFil(domain_str + file_name_suffix);
|
||||
Xow_db_file rv = Xow_db_file.Make(db__core.Info_session(), props, id, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.Instance.New(url));
|
||||
Dbs__add_and_save(rv);
|
||||
Dbs__set_by_tid(rv);
|
||||
return rv;
|
||||
}
|
||||
public Xow_db_file Dbs__remake_by_tid(byte tid) {
|
||||
Dbs__delete_by_tid(tid);
|
||||
return Dbs__make_by_tid(tid);
|
||||
}
|
||||
public void Dbs__delete_by_tid(byte... tids) {
|
||||
int len = hash_by_id.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_db_file db = (Xow_db_file)hash_by_id.Get_at(i);
|
||||
if (!Byte_.Match_any(db.Tid(), tids)) continue;
|
||||
db.Rls();
|
||||
Io_mgr.Instance.DeleteFil_args(db.Url()).MissingFails_off().Exec();
|
||||
db.Cmd_mode_(Db_cmd_mode.Tid_delete);
|
||||
}
|
||||
db__core.Tbl__db().Commit_all(this);
|
||||
|
||||
// call init again to regen list of dbs
|
||||
this.Init_by_load(db__core.Url());
|
||||
}
|
||||
public Xow_db_file Dbs__get_for_create(byte tid, int ns_id) {
|
||||
Xow_db_file[] ary = Dbs__get_ary(tid, ns_id);
|
||||
if (ary.length == 0) throw Err_.new_wo_type("no dbs exist; wiki=~{0} type=~{1}", domain_str, tid);
|
||||
return ary[ary.length - 1];
|
||||
}
|
||||
public Xow_db_file[] Dbs__get_ary(byte tid, int ns_id) {
|
||||
List_adp rv = List_adp_.New();
|
||||
|
||||
// loop all dbs
|
||||
int len = this.Dbs__len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
boolean add = false;
|
||||
Xow_db_file db = this.Dbs__get_at(i);
|
||||
switch (tid) {
|
||||
// cat_link requested
|
||||
case Xow_db_file_.Tid__cat_link:
|
||||
switch (db.Tid()) {
|
||||
case Xow_db_file_.Tid__core:
|
||||
add = props.Layout_text().Tid_is_all_or_few(); // cat_link will be in "core" if "all" or "few" (-text, -html, -file)
|
||||
break;
|
||||
case Xow_db_file_.Tid__cat_link:
|
||||
add = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// text requested
|
||||
case Xow_db_file_.Tid__text:
|
||||
switch (db.Tid()) {
|
||||
case Xow_db_file_.Tid__core:
|
||||
add = props.Layout_text().Tid_is_all(); // text will be in "core" if "all"
|
||||
break;
|
||||
case Xow_db_file_.Tid__text_solo: // EX: "en.wikipedia.org-text.xowa"
|
||||
add = true; // text will be in db if solo;
|
||||
break;
|
||||
case Xow_db_file_.Tid__text: // EX: "en.wikipedia.org-text-ns.000.xowa"
|
||||
int[] db_ns_ids = Int_ary_.Parse(db.Ns_ids(), "|"); // need to handle both "0" and "0|4"
|
||||
for (int db_ns_id : db_ns_ids) {
|
||||
if (db_ns_id == ns_id) {
|
||||
add = true; // text will be in db if ns matches; EX: en.wikipedia.org-text-ns.014.xowa
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (add)
|
||||
rv.Add(db);
|
||||
}
|
||||
|
||||
return (Xow_db_file[])rv.To_ary_and_clear(Xow_db_file.class);
|
||||
}
|
||||
public void Create_page(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
|
||||
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id, -1);
|
||||
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
|
||||
}
|
||||
private void Dbs__set_by_tid(Xow_db_file db) {
|
||||
switch (db.Tid()) {
|
||||
case Xow_db_file_.Tid__wiki_solo:
|
||||
case Xow_db_file_.Tid__text_solo:
|
||||
case Xow_db_file_.Tid__core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__text = db; break;}
|
||||
case Xow_db_file_.Tid__text : {db__text = db; break;}
|
||||
case Xow_db_file_.Tid__html_data : {db__html = db; break;}
|
||||
case Xow_db_file_.Tid__wbase : {if (db__wbase == null) db__wbase = db; break;}
|
||||
case Xow_db_file_.Tid__cat_core :
|
||||
case Xow_db_file_.Tid__cat : {if (db__cat_core == null) db__cat_core = db; break;}
|
||||
}
|
||||
}
|
||||
private void Dbs__add(Xow_db_file db_file) {
|
||||
int db_id = db_file.Id();
|
||||
hash_by_id.Add(db_id, db_file);
|
||||
hash_by_tids.Add_or_new(db_file);
|
||||
if (db_id >= db_id_next) // always set db_id_next to largest value in given set of dbs; EX: dbs=[0,1,10]; db_id_next should be 11
|
||||
db_id_next = db_id + 1;
|
||||
}
|
||||
private void Dbs__add_and_save(Xow_db_file db_file) {
|
||||
Dbs__add(db_file);
|
||||
|
||||
db__core.Tbl__db().Commit_all(this);
|
||||
db_file.Info_file().Save(db_file.Tbl__cfg());
|
||||
db_file.Info_session().Save(db_file.Tbl__cfg());
|
||||
}
|
||||
private int Get_tid_idx(Xow_db_file_hash hash, byte tid) {return hash.Count_of_tid(tid) + Int_.Base1;}
|
||||
private static String Get_tid_name(int tid_idx, byte tid) {
|
||||
String tid_name = Xow_db_file_.To_key(tid);
|
||||
String tid_idx_str = "";
|
||||
switch (tid) {
|
||||
case Xow_db_file_.Tid__cat_core : break;
|
||||
case Xow_db_file_.Tid__cat_link : tid_idx_str = "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
|
||||
default : tid_idx_str = tid_idx == 1 ? "" : "-db." + Int_.To_str_pad_bgn_zero(tid_idx, 3); break;
|
||||
}
|
||||
return String_.Format("-{0}{1}.xowa", tid_name, tid_idx_str); // EX: en.wikipedia.org-text-001.sqlite3
|
||||
}
|
||||
|
||||
// helper method for wikis to (a) init db_mgr; (b) load wiki.props; should probably be moved to more generic "wiki.Init_by_db()"
|
||||
public static void Init_by_load(Xow_wiki wiki, Io_url core_url) {
|
||||
wiki.Data__core_mgr().Init_by_load(core_url);
|
||||
wiki.Props().Init_by_load(wiki.App(), wiki.Data__core_mgr().Tbl__cfg()); // load Main_page
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xowd_cfg_key_ {
|
||||
public static final String
|
||||
Grp__empty = ""
|
||||
, Grp__wiki_schema = "xowa.wiki.schema"
|
||||
, Grp__bldr_session = "xowa.bldr.session"
|
||||
, Grp__bldr_db = "xowa.bldr.db"
|
||||
, Grp__bldr_fsdb = "xowa.bldr.fsdb"
|
||||
|
||||
, Grp__wiki_init = "wiki.init"
|
||||
, Key__init__main_page = "props.main_page"
|
||||
, Key__init__bldr_version = "props.bldr_version"
|
||||
, Key__init__modified_latest = "props.modified_latest"
|
||||
, Key__init__siteinfo_misc = "props.siteinfo_misc"
|
||||
, Key__init__siteinfo_mainpage = "props.siteinfo_mainpage"
|
||||
|
||||
, Grp__wiki__core = "xowa.wiki.core"
|
||||
, Key__wiki__core__domain = "xowa.wiki.core.domain"
|
||||
, Key__wiki__core__name = "xowa.wiki.core.name"
|
||||
|
||||
, Key__wiki__upgrade__version = "xowa.wiki.upgrade.version"
|
||||
|
||||
, Grp__db = "db"
|
||||
, Key__wiki__page__id_next = "page.id_next"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,33 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xowd_cfg_tbl_ {
|
||||
public static final String Tbl_name = "xowa_cfg";
|
||||
public static Db_cfg_tbl New(gplx.dbs.Db_conn conn) {return New(conn, Tbl_name);}
|
||||
public static Db_cfg_tbl New(gplx.dbs.Db_conn conn, String tbl_name) {return new Db_cfg_tbl(conn, tbl_name);}
|
||||
public static Db_cfg_tbl Get_or_null(Db_conn conn) {
|
||||
return conn.Meta_tbl_exists(Tbl_name) ? new Db_cfg_tbl(conn, Tbl_name) : null;
|
||||
}
|
||||
public static Db_cfg_tbl Get_or_fail(Db_conn conn) {
|
||||
Db_cfg_tbl rv = Get_or_null(conn);
|
||||
if (rv == null) throw Err_.New("xowa_cfg tbl does not exist: file={0}", conn.Conn_info().Raw());
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static void Upsert__import(Xowe_wiki wiki) {
|
||||
Db_cfg_tbl cfg_tbl = wiki.Data__core_mgr().Db__core().Tbl__cfg();
|
||||
cfg_tbl.Upsert_bry(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__bldr_version, wiki.Props().Bldr_version());
|
||||
cfg_tbl.Upsert_bry(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__siteinfo_misc, wiki.Props().Siteinfo_misc());
|
||||
cfg_tbl.Upsert_bry(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__siteinfo_mainpage, wiki.Props().Siteinfo_mainpage());
|
||||
}
|
||||
public static void Upsert__create(Xowe_wiki wiki) {Upsert__create(wiki.Data__core_mgr().Db__core().Tbl__cfg(), wiki.Domain_str(), wiki.Domain_str(), wiki.Props().Main_page());}
|
||||
public static void Upsert__create(Db_cfg_tbl cfg_tbl, String domain, String name, byte[] main_page) {
|
||||
cfg_tbl.Upsert_str(Xowd_cfg_key_.Grp__empty , Xowd_cfg_key_.Key__wiki__core__domain , domain);
|
||||
cfg_tbl.Upsert_str(Xowd_cfg_key_.Grp__empty , Xowd_cfg_key_.Key__wiki__core__name , name);
|
||||
cfg_tbl.Upsert_int(Xowd_cfg_key_.Grp__empty , Xowd_cfg_key_.Key__wiki__upgrade__version , gplx.xowa.addons.wikis.directorys.specials.items.bldrs.Xow_wiki_upgrade_.Upgrade_version__cur);
|
||||
cfg_tbl.Upsert_bry(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__main_page , main_page);
|
||||
cfg_tbl.Upsert_str(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__modified_latest , Datetime_now.Get().XtoStr_fmt(DateAdp_.Fmt_iso8561_date_time));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,68 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.dbs.metas.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.wikis.dbs.*;
|
||||
public class Xowd_core_db_props {
|
||||
public Xowd_core_db_props(int schema, Xow_db_layout layout_text, Xow_db_layout layout_html, Xow_db_layout layout_file
|
||||
, byte zip_tid_text, byte zip_tid_html, boolean hzip_enabled, boolean hzip_mode_is_b256) {
|
||||
this.schema = schema;
|
||||
this.layout_text = layout_text; this.layout_html = layout_html; this.layout_file = layout_file;
|
||||
this.zip_tid_text = zip_tid_text; this.zip_tid_html = zip_tid_html;
|
||||
this.hzip_enabled = hzip_enabled; this.hzip_mode_is_b256 = hzip_mode_is_b256;
|
||||
}
|
||||
public int Schema() {return schema;} private final int schema;
|
||||
public boolean Schema_is_1() {return schema == 1;}
|
||||
public Xow_db_layout Layout_text() {return layout_text;} private final Xow_db_layout layout_text;
|
||||
public Xow_db_layout Layout_html() {return layout_html;} private final Xow_db_layout layout_html;
|
||||
public Xow_db_layout Layout_file() {return layout_file;} private final Xow_db_layout layout_file;
|
||||
public byte Zip_tid_text() {return zip_tid_text;} private final byte zip_tid_text;
|
||||
public byte Zip_tid_html() {return zip_tid_html;} private final byte zip_tid_html;
|
||||
public boolean Hzip_enabled() {return hzip_enabled;} private final boolean hzip_enabled;
|
||||
public boolean Hzip_mode_is_b256() {return hzip_mode_is_b256;} private final boolean hzip_mode_is_b256;
|
||||
public void Cfg_save(Db_cfg_tbl tbl) {
|
||||
tbl.Conn().Txn_bgn("make__core__cfg__save");
|
||||
tbl.Insert_int (Cfg_grp, Cfg_key__schema_version , schema);
|
||||
tbl.Insert_str (Cfg_grp, Cfg_key__layout_text , layout_text.Key());
|
||||
tbl.Insert_str (Cfg_grp, Cfg_key__layout_html , layout_html.Key());
|
||||
tbl.Insert_str (Cfg_grp, Cfg_key__layout_file , layout_file.Key());
|
||||
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_text , zip_tid_text);
|
||||
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_html , zip_tid_html);
|
||||
tbl.Insert_yn (Cfg_grp, Cfg_key__hzip_enabled , hzip_enabled);
|
||||
tbl.Insert_yn (Cfg_grp, Cfg_key__hzip_mode_is_b256 , hzip_mode_is_b256);
|
||||
tbl.Conn().Txn_end();
|
||||
}
|
||||
public static Xowd_core_db_props Cfg_load(Db_conn conn) {return Cfg_load(conn, gplx.xowa.wikis.data.Xowd_cfg_tbl_.New(conn));}
|
||||
public static Xowd_core_db_props Cfg_load(Db_conn conn, Db_cfg_tbl cfg_tbl) {
|
||||
return cfg_tbl.Select_int_or(Cfg_grp, Cfg_key__schema_version, 1) == 1
|
||||
? new Xowd_core_db_props
|
||||
( 1, Xow_db_layout.Itm_lot, Xow_db_layout.Itm_lot, Xow_db_layout.Itm_lot, cfg_tbl.Select_byte_or(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format
|
||||
, Io_stream_tid_.Tid__gzip), Io_stream_tid_.Tid__gzip, Bool_.Y, Bool_.N)
|
||||
: Cfg_load(cfg_tbl);
|
||||
}
|
||||
private static Xowd_core_db_props Cfg_load(Db_cfg_tbl tbl) {
|
||||
Db_cfg_hash cfg_hash = tbl.Select_as_hash(Cfg_grp);
|
||||
return new Xowd_core_db_props
|
||||
( cfg_hash.Get_by(Cfg_key__schema_version).To_int()
|
||||
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_text).To_str())
|
||||
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_html).To_str())
|
||||
, Xow_db_layout.Get_by_name(cfg_hash.Get_by(Cfg_key__layout_file).To_str())
|
||||
, cfg_hash.Get_by(Cfg_key__zip_tid_text).To_byte()
|
||||
, cfg_hash.Get_by(Cfg_key__zip_tid_html).To_byte()
|
||||
, cfg_hash.Get_by(Cfg_key__hzip_enabled).To_yn_or(Bool_.N)
|
||||
, cfg_hash.Get_by(Cfg_key__hzip_mode_is_b256).To_yn_or(Bool_.N)
|
||||
);
|
||||
}
|
||||
private static final String Cfg_grp = gplx.xowa.wikis.data.Xowd_cfg_key_.Grp__wiki__core
|
||||
, Cfg_key__schema_version = "schema_version"
|
||||
, Cfg_key__layout_text = "layout_text"
|
||||
, Cfg_key__layout_html = "layout_html"
|
||||
, Cfg_key__layout_file = "layout_file"
|
||||
, Cfg_key__zip_tid_text = "zip_tid_text"
|
||||
, Cfg_key__zip_tid_html = "zip_tid_html"
|
||||
, Cfg_key__hzip_enabled = "hzip_enabled"
|
||||
, Cfg_key__hzip_mode_is_b256 = "hzip_mode_is_b256"
|
||||
;
|
||||
public static final Xowd_core_db_props Test = new Xowd_core_db_props(2, Xow_db_layout.Itm_few, Xow_db_layout.Itm_few, Xow_db_layout.Itm_few, Io_stream_tid_.Tid__raw, Io_stream_tid_.Tid__raw, Bool_.Y, Bool_.Y);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public interface Xow_page_fetcher {
|
||||
Xow_page_fetcher Wiki_(Xowe_wiki v);
|
||||
byte[] Get_by(int ns_id, byte[] ttl);
|
||||
void Clear();
|
||||
}
|
||||
|
||||
@@ -13,18 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_page_fetcher_test implements Xow_page_fetcher {
|
||||
public Xow_page_fetcher Wiki_(Xowe_wiki v) {return this;}
|
||||
public void Clear() {pages.Clear();} private Hash_adp pages = Hash_adp_.New();
|
||||
public void Add(int ns_id, byte[] ttl, byte[] text) {
|
||||
Xowd_page_itm page = new Xowd_page_itm().Ns_id_(ns_id).Ttl_page_db_(ttl).Text_(text);
|
||||
pages.Add(Make_key(ns_id, ttl), page);
|
||||
}
|
||||
public byte[] Get_by(int ns_id, byte[] ttl) {
|
||||
Xowd_page_itm rv = (Xowd_page_itm)pages.Get_by(Make_key(ns_id, ttl));
|
||||
return rv == null ? null : rv.Text();
|
||||
}
|
||||
String Make_key(int ns_id, byte[] ttl) {return Int_.To_str(ns_id) + "|" + String_.new_u8(ttl);}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.fetchers; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xow_page_fetcher_wiki implements Xow_page_fetcher {
|
||||
public Xow_page_fetcher Wiki_(Xowe_wiki v) {this.wiki = v; return this;} private Xowe_wiki wiki;
|
||||
public void Clear() {}
|
||||
public byte[] Get_by(int ns_id, byte[] ttl_bry) {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, ns_id, ttl_bry);
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl); // go through data_mgr in case of redirects
|
||||
return page.Db().Page().Exists_n() ? null : page.Db().Text().Text_bry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,42 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_site_stats_mgr implements Gfo_invk { // REF.MW:https://www.mediawiki.org/wiki/Manual:Site_stats_table
|
||||
private final Xow_wiki wiki;
|
||||
public Xowd_site_stats_mgr(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public long Num_pages() {return num_pages;} private long num_pages; // ss_total_pages; pages in entire wiki: 16,299,475
|
||||
public long Num_articles() {return num_articles;} private long num_articles; // ss_good_articles; pages in main ns w/o redirect: 5,072,469
|
||||
public long Num_views() {return num_views;} private long num_views; // ss_total_views
|
||||
public long Num_edits() {return num_edits;} private long num_edits; // ss_total_edits
|
||||
public long Num_users() {return num_users;} private long num_users; // ss_users
|
||||
public long Num_active() {return num_active;} private long num_active; // ss_active_users
|
||||
public int Num_admins() {return num_admins;} private int num_admins; // ss_admins
|
||||
public int Num_files() {return num_files;} private int num_files; // ss_images
|
||||
public void Load_by_db(long num_pages, long num_articles, int num_files, long num_edits, long num_views, long num_users, long num_active, int num_admins) {
|
||||
this.num_pages = num_pages;
|
||||
this.num_articles = num_articles;
|
||||
this.num_files = num_files;
|
||||
this.num_edits = num_edits;
|
||||
this.num_views = num_views;
|
||||
this.num_users = num_users;
|
||||
this.num_active = num_active;
|
||||
this.num_admins = num_admins;
|
||||
}
|
||||
private Object Number_of_articles_in_ns_(GfoMsg m) {
|
||||
int ns_id = m.ReadInt("ns_id");
|
||||
int count = m.ReadInt("count");
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(ns_id);
|
||||
if (ns != null) ns.Count_(count);
|
||||
return this;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_number_of_pages_)) num_pages = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_number_of_articles_)) num_articles = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_number_of_files_)) num_files = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_number_of_articles_in_ns_)) return Number_of_articles_in_ns_(m);
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_number_of_pages_ = "number_of_pages_", Invk_number_of_articles_ = "number_of_articles_", Invk_number_of_files_ = "number_of_files_", Invk_number_of_articles_in_ns_ = "number_of_articles_in_ns_";
|
||||
}
|
||||
|
||||
@@ -13,46 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.site_stats; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.site_stats.*;
|
||||
public class Xowd_site_stats_tbl implements Db_tbl {
|
||||
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
|
||||
private final Db_conn conn; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
public Xowd_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
fld_row_id = flds.Add_int_pkey("ss_row_id");
|
||||
fld_good_articles = flds.Add_long("ss_good_articles");
|
||||
fld_total_pages = flds.Add_long("ss_total_pages");
|
||||
fld_images = flds.Add_int("ss_images");
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public void Create_tbl() {
|
||||
conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));
|
||||
conn.Stmt_insert(tbl_name, flds).Val_int(fld_row_id, Site_stats_row_id).Val_long(fld_good_articles, 0).Val_long(fld_total_pages, 0).Val_int(fld_images, 0).Exec_insert();
|
||||
}
|
||||
public void Update(long num_articles, long num_pages, int num_files) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.site_stats: update started: num_articles=~{0} num_pages=~{1} num_files=~{2}", num_articles, num_pages, num_files);
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_row_id), fld_good_articles, fld_total_pages, fld_images);
|
||||
stmt.Val_long(fld_good_articles, num_articles).Val_long(fld_total_pages, num_pages).Val_int(fld_images, num_files)
|
||||
.Crt_int(fld_row_id, Site_stats_row_id)
|
||||
.Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.site_stats: update done");
|
||||
}
|
||||
public void Select(Xowd_site_stats_mgr stats) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_row_id).Crt_int(fld_row_id, Site_stats_row_id).Exec_select__rls_auto();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
stats.Load_by_db
|
||||
( rdr.Read_long(fld_total_pages)
|
||||
, rdr.Read_long(fld_good_articles)
|
||||
, rdr.Read_int(fld_images)
|
||||
, 0, 0, 0, 0, 0);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {}
|
||||
private static final int Site_stats_row_id = 1;
|
||||
|
||||
public static final String TBL_NAME = "site_stats";
|
||||
public static Xowd_site_stats_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_site_stats_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -13,42 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*;
|
||||
public interface Select_in_cbk {
|
||||
int Hash_max();
|
||||
void Write_sql(Bry_bfr bfr, int idx);
|
||||
void Read_data(Db_rdr rdr);
|
||||
}
|
||||
class Select_in_wkr {
|
||||
private final byte[] sql_bgn;
|
||||
public Select_in_wkr(byte[] sql_bgn) {this.sql_bgn = sql_bgn;}
|
||||
public int Make_sql_or_null(Bry_bfr bfr, Select_in_cbk cbk, int bgn) {
|
||||
// read 50 at a time
|
||||
int max = cbk.Hash_max();
|
||||
int end = bgn + 50; if (end > max) end = max;
|
||||
if (bgn == end) return -1; // at eos; return;
|
||||
|
||||
// concat itms
|
||||
bfr.Add(sql_bgn);
|
||||
for (int i = bgn; i < end; ++i) {
|
||||
if (i != bgn) bfr.Add_str_a7(", ");
|
||||
cbk.Write_sql(bfr, i);
|
||||
}
|
||||
bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
return end;
|
||||
}
|
||||
public static Select_in_wkr New(Bry_bfr bfr, String tbl_name, String[] select_flds, String where_fld) {
|
||||
bfr.Add_str_a7("SELECT ");
|
||||
int select_flds_len = select_flds.length;
|
||||
for (int i = 0; i < select_flds_len; ++i) {
|
||||
String select_fld = select_flds[i];
|
||||
if (i != 0) bfr.Add_str_a7(", ");
|
||||
bfr.Add_str_u8(select_fld);
|
||||
}
|
||||
bfr.Add_str_a7(" FROM ").Add_str_u8(tbl_name);
|
||||
bfr.Add_str_a7(" WHERE ").Add_str_u8(where_fld);
|
||||
bfr.Add_str_a7(" IN (");
|
||||
return new Select_in_wkr(bfr.To_bry_and_clear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,100 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xowd_cat_core_tbl implements Db_tbl {
|
||||
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_id, fld_pages, fld_subcats, fld_files, fld_hidden, fld_link_db_id;
|
||||
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
|
||||
private final Xowd_cat_core_tbl__in_wkr in_wkr = new Xowd_cat_core_tbl__in_wkr();
|
||||
public Db_conn Conn() {return conn;}
|
||||
public Xowd_cat_core_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_link_db_id_name = "";
|
||||
if (schema_is_1) {tbl_name = "category"; fld_link_db_id_name = "cat_file_idx";}
|
||||
else {tbl_name = "cat_core"; fld_link_db_id_name = "cat_link_db_id";}
|
||||
fld_id = flds.Add_int_pkey ("cat_id");
|
||||
fld_pages = flds.Add_int ("cat_pages");
|
||||
fld_subcats = flds.Add_int ("cat_subcats");
|
||||
fld_files = flds.Add_int ("cat_files");
|
||||
fld_hidden = flds.Add_byte ("cat_hidden");
|
||||
fld_link_db_id = flds.Add_int(fld_link_db_id_name);
|
||||
in_wkr.Ctor(this, tbl_name, flds, fld_id);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__cat_core__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int id, int pages, int subcats, int files, byte hidden, int link_db_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_id, id).Val_int(fld_pages, pages).Val_int(fld_subcats, subcats).Val_int(fld_files, files)
|
||||
.Val_byte(fld_hidden, hidden).Val_int(fld_link_db_id, link_db_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Update_bgn() {conn.Txn_bgn("schema__cat_core__update"); stmt_update = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_hidden);}
|
||||
public void Update_end() {conn.Txn_end(); stmt_update = Db_stmt_.Rls(stmt_update);}
|
||||
public void Update_by_batch(int id, byte hidden) {
|
||||
stmt_update.Clear().Val_byte(fld_hidden, hidden).Crt_int(fld_id, id).Exec_update();
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.cat_core: delete started: db=~{0} page_id=~{1}", conn.Conn_info().Raw(), page_id);
|
||||
conn.Stmt_delete(tbl_name, fld_id).Crt_int(fld_id, page_id).Exec_delete();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.cat_core: delete done");
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
|
||||
public void Update_page_id(int old_id, int new_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.cat_core: update page_id started: db=~{0} old_id=~{1} new_id=~{2}", conn.Conn_info().Raw(), old_id, new_id);
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_id).Val_int(fld_id, new_id).Crt_int(fld_id, old_id).Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.cat_core: update page_id done");
|
||||
}
|
||||
public void Update(Xowd_category_itm itm) {
|
||||
conn.Stmt_update_exclude(tbl_name, flds, fld_id).Clear()
|
||||
.Val_int(fld_pages, itm.Count_pages())
|
||||
.Val_int(fld_subcats, itm.Count_subcs())
|
||||
.Val_int(fld_files, itm.Count_files())
|
||||
.Val_bool_as_byte(fld_hidden, itm.Hidden())
|
||||
.Val_int(fld_link_db_id, itm.File_idx())
|
||||
.Crt_int(fld_id, itm.Id())
|
||||
.Exec_update();
|
||||
}
|
||||
public Xowd_category_itm Select(int id) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_id, id).Exec_select__rls_manual();
|
||||
try {return rdr.Move_next() ? Load_itm(rdr) : Xowd_category_itm.Null;} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_cat_id_in(Cancelable cancelable, Ordered_hash rv, int bgn, int end) {
|
||||
in_wkr.Init(rv);
|
||||
in_wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public void Select_by_cat_id_many(Select_in_cbk cbk) {
|
||||
int pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Select_in_wkr wkr = Select_in_wkr.New(bfr, tbl_name, String_.Ary(fld_id, fld_pages, fld_subcats, fld_files, fld_hidden), fld_id);
|
||||
while (true) {
|
||||
pos = wkr.Make_sql_or_null(bfr, cbk, pos);
|
||||
if (pos == -1) break;
|
||||
Db_rdr rdr = conn.Stmt_sql(bfr.To_str_and_clear()).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
cbk.Read_data(rdr);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
public Xowd_category_itm Load_itm(Db_rdr rdr) {
|
||||
return Xowd_category_itm.load_
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_link_db_id)
|
||||
, rdr.Read_bool_by_byte(fld_hidden)
|
||||
, rdr.Read_int(fld_subcats)
|
||||
, rdr.Read_int(fld_files)
|
||||
, rdr.Read_int(fld_pages)
|
||||
);
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_update = Db_stmt_.Rls(stmt_update);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,31 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
class Xowd_cat_core_tbl__in_wkr extends Db_in_wkr__base {
|
||||
private Xowd_cat_core_tbl tbl;
|
||||
private String tbl_name, fld_cat_id; private Dbmeta_fld_list flds; private Ordered_hash hash;
|
||||
public void Ctor(Xowd_cat_core_tbl tbl, String tbl_name, Dbmeta_fld_list flds, String fld_cat_id) {
|
||||
this.tbl = tbl; this.tbl_name = tbl_name; this.flds = flds; this.fld_cat_id = fld_cat_id;
|
||||
}
|
||||
public void Init(Ordered_hash hash) {this.hash = hash;}
|
||||
@Override protected Db_qry Make_qry(int bgn, int end) {
|
||||
Object[] part_ary = In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_(tbl_name, Db_crt_.New_in(fld_cat_id, part_ary), flds.To_str_ary());
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm itm = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Crt_int(fld_cat_id, itm.Id());
|
||||
}
|
||||
}
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_category_itm ctg_data = tbl.Load_itm(rdr);
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_by(ctg_data.Id_val());
|
||||
page.Xtn_(ctg_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,76 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
public class Xowd_cat_link_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_from, fld_to_id, fld_sortkey, fld_timestamp, fld_type_id;
|
||||
private Db_stmt stmt_insert, stmt_select_in;
|
||||
public Xowd_cat_link_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = schema_is_1 ? "categorylinks" : "cat_link";
|
||||
fld_from = flds.Add_int ("cl_from"); // page_id
|
||||
fld_to_id = flds.Add_int ("cl_to_id"); // cat_id
|
||||
fld_type_id = flds.Add_byte ("cl_type_id");
|
||||
fld_sortkey = flds.Add_str ("cl_sortkey", 230);
|
||||
fld_timestamp = flds.Add_str ("cl_timestamp", 14);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx() {
|
||||
conn.Meta_idx_create(Xoa_app_.Usr_dlg()
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "main", fld_to_id, fld_type_id, fld_sortkey, fld_from)
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "from", fld_from)
|
||||
);
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__cat_link__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, int ctg_page_id, byte ctg_tid, byte[] sortkey, int timestamp) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_from , page_id)
|
||||
.Val_int(fld_to_id , ctg_page_id)
|
||||
.Val_byte(fld_type_id , ctg_tid)
|
||||
.Val_bry_as_str(fld_sortkey , sortkey)
|
||||
.Val_int(fld_timestamp , timestamp)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Delete_all() {conn.Stmt_delete(tbl_name, Dbmeta_fld_itm.Str_ary_empty).Exec_delete();}
|
||||
public int Select_by_type(List_adp list, int cat_page_id, byte arg_tid, byte[] arg_sortkey, boolean arg_is_from, int limit) {
|
||||
String arg_sortkey_str = arg_sortkey == null ? "" : String_.new_u8(arg_sortkey);
|
||||
gplx.core.criterias.Criteria comp_crt = !arg_is_from
|
||||
? Db_crt_.New_mte(fld_sortkey, arg_sortkey_str) // from: sortkey >= 'val'
|
||||
: Db_crt_.New_lte(fld_sortkey, arg_sortkey_str); // until: sortkey <= 'val'
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_from, fld_sortkey).From_(tbl_name)
|
||||
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.New_eq(fld_to_id, -1), Db_crt_.New_eq(fld_type_id, arg_tid), comp_crt))
|
||||
.Order_(fld_sortkey, !arg_is_from)
|
||||
.Limit_(limit + 1); // + 1 to get last_plus_one for next page / previous page
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Crt_int(fld_to_id, cat_page_id).Crt_byte(fld_type_id, arg_tid).Crt_str(fld_sortkey, arg_sortkey_str).Exec_select__rls_auto();
|
||||
int count = 0;
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int itm_page_id = rdr.Read_int(fld_from);
|
||||
byte[] itm_sortkey = rdr.Read_bry_by_str(fld_sortkey);
|
||||
Xowd_page_itm itm = new Xowd_page_itm().Id_(itm_page_id).Xtn_(new Xoctg_page_xtn(arg_tid, itm_sortkey));
|
||||
list.Add(itm);
|
||||
++count;
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
list.Sort_by(Xowd_page_itm_sorter.Ctg_tid_sortkey_asc);
|
||||
return count;
|
||||
}
|
||||
public void Select_in(List_adp rv, int cat_id) {
|
||||
if (stmt_select_in == null) stmt_select_in = conn.Stmt_select(tbl_name, flds, fld_to_id);
|
||||
Db_rdr rdr = stmt_select_in.Clear().Crt_int(fld_to_id, cat_id).Exec_select__rls_manual();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
rv.Add(new Xowd_page_itm().Id_(rdr.Read_int(fld_from)));
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,39 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_category_itm {
|
||||
public int Id() {return id;} private int id;
|
||||
public Int_obj_val Id_val() {if (id_val == null) id_val = new Int_obj_val(id); return id_val;} Int_obj_val id_val;
|
||||
public int File_idx() {return file_idx;} private int file_idx;
|
||||
public boolean Hidden() {return hidden;} private boolean hidden;
|
||||
public int Count_all() {return count_subcs + count_files + count_pages;}
|
||||
public int Count_subcs() {return count_subcs;} private int count_subcs;
|
||||
public int Count_files() {return count_files;} private int count_files;
|
||||
public int Count_pages() {return count_pages;} private int count_pages;
|
||||
public int Count_by_tid(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid__subc: return count_subcs;
|
||||
case Xoa_ctg_mgr.Tid__page: return count_pages;
|
||||
case Xoa_ctg_mgr.Tid__file: return count_files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Adjust(int ns, int val) {
|
||||
switch (ns) {
|
||||
case Xow_ns_.Tid__category: count_subcs += val; break;
|
||||
case Xow_ns_.Tid__file : count_files += val; break;
|
||||
default : count_pages += val; break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Xowd_category_itm load_(int id, int file_idx, boolean hidden, int count_subcs, int count_files, int count_pages) {
|
||||
Xowd_category_itm rv = new Xowd_category_itm();
|
||||
rv.id = id; rv.file_idx = file_idx; rv.hidden = hidden;
|
||||
rv.count_subcs = count_subcs; rv.count_files = count_files; rv.count_pages = count_pages;
|
||||
return rv;
|
||||
}
|
||||
public static final Xowd_category_itm Null = new Xowd_category_itm(); Xowd_category_itm() {}
|
||||
}
|
||||
|
||||
@@ -13,146 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_page_itm {
|
||||
public Xowd_page_itm() {this.Clear();}
|
||||
public int Id() {return id;} public Xowd_page_itm Id_(int v) {id = v; id_val = null; return this;} private int id;
|
||||
public Int_obj_val Id_val() {if (id_val == null) id_val = new Int_obj_val(id); return id_val;} private Int_obj_val id_val;
|
||||
public int Ns_id() {return ns_id;} public Xowd_page_itm Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
|
||||
public byte[] Ttl_page_db() {return ttl_page_db;} public Xowd_page_itm Ttl_page_db_(byte[] v) {ttl_page_db = v; return this;} private byte[] ttl_page_db; // EX: Category1
|
||||
public byte[] Ttl_full_db() {return ttl_full_db;} private byte[] ttl_full_db; // EX: Category:Category1
|
||||
public boolean Redirected() {return redirected;} public Xowd_page_itm Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
|
||||
public int Text_len() {return text_len;} public Xowd_page_itm Text_len_(int v) {text_len = v; return this;} private int text_len;
|
||||
public int Text_db_id() {return text_db_id;} public Xowd_page_itm Text_db_id_(int v) {text_db_id = v; return this;} private int text_db_id;
|
||||
public int Html_db_id() {return html_db_id;} private int html_db_id;
|
||||
public int Cat_db_id() {return cat_db_id;} private int cat_db_id = -1; // NOTE: cannot be 0, else catpage loader will try to load cat_links from db.id=0
|
||||
public byte[] Text() {return text;} public Xowd_page_itm Text_(byte[] v) {text = v; if (v != null) text_len = v.length; return this;} private byte[] text;
|
||||
public int Random_int() {return random_int;} private int random_int;
|
||||
public int Redirect_id() {return redirect_id;} private int redirect_id;
|
||||
public DateAdp Modified_on() {return modified_on;} public Xowd_page_itm Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on;
|
||||
public boolean Exists() {return exists;} private boolean exists;
|
||||
public int Score() {return score;} private int score;
|
||||
public Xow_ns Ns() {return ns;} private Xow_ns ns;
|
||||
public Object Xtn() {return xtn;} public Xowd_page_itm Xtn_(Object v) {this.xtn = v; return this;} private Object xtn;
|
||||
public int Tdb_row_idx() {return tdb_row_idx;} public void Tdb_row_idx_(int v) {tdb_row_idx = v;} private int tdb_row_idx;
|
||||
public int Rank() {return text_len;}
|
||||
public Xowd_page_itm Init(int id, byte[] ttl_page_db, boolean redirected, int text_len, int text_db_id, int tdb_row_idx) {
|
||||
this.id = id; this.ttl_page_db = ttl_page_db; this.redirected = redirected;
|
||||
this.text_len = text_len; this.text_db_id = text_db_id; this.tdb_row_idx = tdb_row_idx;
|
||||
id_val = null;
|
||||
return this;
|
||||
}
|
||||
public void Init_by_load__idx(int id, int ns_id, byte[] ttl_page_db, int text_len) {
|
||||
this.exists = true; // COMMENT: DATE:2016-08-28
|
||||
this.id = id;
|
||||
this.id_val = null;
|
||||
this.ns_id = ns_id;
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
this.text_len = text_len;
|
||||
}
|
||||
public void Init_by_load__all(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int random_int, int text_db_id, int html_db_id, int redirect_id, int score, int cat_db_id) {
|
||||
// same as Init_by_load__idx; COMMENT: DATE:2016-08-28
|
||||
this.exists = true;
|
||||
this.id = id;
|
||||
this.id_val = null;
|
||||
this.ns_id = ns_id;
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
this.text_len = text_len;
|
||||
|
||||
// other props
|
||||
this.redirected = redirected;
|
||||
this.text_db_id = text_db_id;
|
||||
this.modified_on = modified_on;
|
||||
this.random_int = random_int;
|
||||
this.html_db_id = html_db_id;
|
||||
this.redirect_id = redirect_id;
|
||||
this.score = score;
|
||||
this.cat_db_id = cat_db_id;
|
||||
}
|
||||
public void Init_by_tdb(int id, int text_db_id, int tdb_row_idx, boolean redirected, int text_len, int ns_id, byte[] ttl_page_db) {
|
||||
// same as Init_by_load__idx; COMMENT: DATE:2016-08-28
|
||||
this.exists = true;
|
||||
this.id = id;
|
||||
this.id_val = null;
|
||||
this.ns_id = ns_id;
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
this.text_len = text_len;
|
||||
|
||||
// other props
|
||||
this.redirected = redirected;
|
||||
this.text_db_id = text_db_id;
|
||||
|
||||
this.tdb_row_idx = tdb_row_idx;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(Xow_ns ns, byte[] ttl_page_db) {
|
||||
this.ns = ns;
|
||||
ns_id = ns.Id();
|
||||
this.ttl_page_db = ttl_page_db;
|
||||
this.ttl_full_db = ns.Gen_ttl(ttl_page_db);
|
||||
return this;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(Xoa_ttl ttl) {
|
||||
ttl_full_db = ttl.Full_txt_w_ttl_case();
|
||||
ttl_page_db = ttl.Page_db();
|
||||
ns = ttl.Ns();
|
||||
ns_id = ns.Id();
|
||||
return this;
|
||||
}
|
||||
public Xowd_page_itm Ttl_(byte[] v, Xow_ns_mgr ns_mgr) {
|
||||
ttl_full_db = v;
|
||||
Object o = ns_mgr.Names_get_w_colon(v, 0, v.length);
|
||||
if (o == null) {
|
||||
ns = ns_mgr.Ns_main();
|
||||
ttl_page_db = v;
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
ttl_page_db = Bry_.Mid(v, ns.Name_ui_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
|
||||
}
|
||||
ns_id = ns.Id();
|
||||
return this;
|
||||
}
|
||||
public Xowd_page_itm Clear() {
|
||||
id = Id_null; text_len = 0; // text_len should be 0 b/c text defaults to 0;
|
||||
text_db_id = tdb_row_idx = 0; // default to 0, b/c some tests do not set and will fail at -1
|
||||
ns_id = Int_.Min_value;
|
||||
ttl_full_db = ttl_page_db = null; text = Bry_.Empty; // default to Ary_empty for entries that have <text />
|
||||
ns = null;
|
||||
redirected = exists = false;
|
||||
modified_on = DateAdp_.MinValue;
|
||||
id_val = null;
|
||||
html_db_id = cat_db_id = -1;
|
||||
redirect_id = -1;
|
||||
return this;
|
||||
}
|
||||
public void Copy(Xowd_page_itm orig) {
|
||||
this.id = orig.id;
|
||||
this.text_len = orig.text_len;
|
||||
this.text_db_id = orig.text_db_id;
|
||||
this.tdb_row_idx = orig.tdb_row_idx;
|
||||
this.ns_id = orig.ns_id;
|
||||
this.ttl_full_db = orig.ttl_full_db;
|
||||
this.ttl_page_db = orig.ttl_page_db;
|
||||
this.text = orig.text;
|
||||
this.ns = orig.ns;
|
||||
this.redirected = orig.redirected;
|
||||
this.exists = orig.exists;
|
||||
this.modified_on = orig.modified_on;
|
||||
this.id_val = null;
|
||||
this.html_db_id = orig.html_db_id;
|
||||
this.cat_db_id = orig.cat_db_id;
|
||||
}
|
||||
public void Srl_save(Bry_bfr bfr) {gplx.xowa.wikis.tdbs.Xotdb_page_itm_.Txt_id_save(bfr, this);}
|
||||
public static final int Id_null = -1, Modified_on_null_int = 0, Redirect_id_null = -1;
|
||||
public static final Xowd_page_itm[] Ary_empty = new Xowd_page_itm[0];
|
||||
public static final Xowd_page_itm Null = null;
|
||||
public static Xowd_page_itm new_tmp() {return new Xowd_page_itm();}
|
||||
public static Xowd_page_itm new_srch(int id, int text_len) {return new Xowd_page_itm().Id_(id).Text_len_(text_len);}
|
||||
|
||||
public static final int Db_row_size_fixed =
|
||||
(8 * 4) // page_id, page_namespace, page_random_int, page_text_db_id, page_html_db_id, page_redirect_id, page_score, page_is_redirect (assume byte saved as int in SQLITE)
|
||||
+ 14 // page_touched
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,39 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.lists.*; /*ComparerAble*/ import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_page_itm_sorter implements ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xowd_page_itm lhs = (Xowd_page_itm)lhsObj, rhs = (Xowd_page_itm)rhsObj;
|
||||
return order * Compare_rows(compareType, lhs, rhs);
|
||||
}
|
||||
private static int Compare_rows(byte compareType, Xowd_page_itm lhs, Xowd_page_itm rhs) {
|
||||
switch (compareType) {
|
||||
case Tid_ns_ttl: {
|
||||
int rv = Int_.Compare(lhs.Ns_id(), rhs.Ns_id());
|
||||
return rv == CompareAble_.Same ? Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db()) : rv;
|
||||
}
|
||||
case Tid_itm_len: return Int_.Compare(lhs.Text_len(), rhs.Text_len());
|
||||
case Tid_id: return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
case Tid_ttl: return Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db());
|
||||
case Tid_ctg_tid_sortkey:
|
||||
gplx.xowa.addons.wikis.ctgs.Xoctg_page_xtn lhs_xtn = (gplx.xowa.addons.wikis.ctgs.Xoctg_page_xtn)lhs.Xtn();
|
||||
gplx.xowa.addons.wikis.ctgs.Xoctg_page_xtn rhs_xtn = (gplx.xowa.addons.wikis.ctgs.Xoctg_page_xtn)rhs.Xtn();
|
||||
if (lhs_xtn == null || rhs_xtn == null) return CompareAble_.Same;
|
||||
int tid_comparable = Byte_.Compare(lhs_xtn.Tid(), rhs_xtn.Tid());
|
||||
if (tid_comparable != CompareAble_.Same) return tid_comparable;
|
||||
return Bry_.Compare(lhs_xtn.Sortkey(), rhs_xtn.Sortkey());
|
||||
default: throw Err_.new_unhandled(compareType);
|
||||
}
|
||||
}
|
||||
Xowd_page_itm_sorter(byte compareType, int order) {this.compareType = compareType; this.order = order;}
|
||||
byte compareType; int order;
|
||||
static final byte Tid_ns_ttl = 0, Tid_itm_len = 2, Tid_id = 3, Tid_ttl = 4, Tid_ctg_tid_sortkey = 5;
|
||||
static final int Asc = 1, Dsc = -1;
|
||||
public static final Xowd_page_itm_sorter TitleAsc = new Xowd_page_itm_sorter(Tid_ttl , Asc);
|
||||
public static final Xowd_page_itm_sorter EnyLenDsc = new Xowd_page_itm_sorter(Tid_itm_len , Dsc);
|
||||
public static final Xowd_page_itm_sorter IdAsc = new Xowd_page_itm_sorter(Tid_id , Asc);
|
||||
public static final Xowd_page_itm_sorter Ns_id_TtlAsc = new Xowd_page_itm_sorter(Tid_ns_ttl , Asc);
|
||||
public static final Xowd_page_itm_sorter Ctg_tid_sortkey_asc = new Xowd_page_itm_sorter(Tid_ctg_tid_sortkey , Asc);
|
||||
}
|
||||
|
||||
@@ -13,28 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_page_itm_tst {
|
||||
@Before public void init() {fxt.Init();} private Xowd_page_itm_fxt fxt = new Xowd_page_itm_fxt();
|
||||
@Test public void Ttl_() {
|
||||
fxt.Test_ttl_("User_talk:A", Xow_ns_.Tid__user_talk, "A");
|
||||
fxt.Test_ttl_("User talk:A", Xow_ns_.Tid__user_talk, "A");
|
||||
}
|
||||
}
|
||||
class Xowd_page_itm_fxt {
|
||||
public void Init() {
|
||||
if (ns_mgr == null) {
|
||||
ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
ns_mgr.Add_new(Xow_ns_.Tid__main, "");
|
||||
ns_mgr.Add_new(Xow_ns_.Tid__user_talk, "User talk");
|
||||
ns_mgr.Init_w_defaults();
|
||||
tmp_page = new Xowd_page_itm();
|
||||
}
|
||||
} private Xow_ns_mgr ns_mgr; Xowd_page_itm tmp_page;
|
||||
public void Test_ttl_(String ttl, int expd_ns, String expd_ttl) {
|
||||
tmp_page.Ttl_(Bry_.new_a7(ttl), ns_mgr);
|
||||
Tfds.Eq(expd_ns, tmp_page.Ns_id());
|
||||
Tfds.Eq(expd_ttl, String_.new_a7(tmp_page.Ttl_page_db()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,400 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.primitives.*; import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.xowa.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_page_tbl implements Db_tbl {
|
||||
private final Object thread_lock = new Object();
|
||||
public final boolean schema_is_1;
|
||||
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_score, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_cat_db_id;
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert;
|
||||
private final String[] flds_select_all, flds_select_idx;
|
||||
public Xowd_page_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn; this.schema_is_1 = schema_is_1;
|
||||
String fld_text_db_id_name = "";
|
||||
String fld_cat_db_id_name = Dbmeta_fld_itm.Key_null;
|
||||
if (schema_is_1) {fld_text_db_id_name = "page_file_idx";}
|
||||
else {
|
||||
fld_text_db_id_name = "page_text_db_id";
|
||||
if (conn.Meta_fld_exists(tbl_name, "page_cat_db_id"))
|
||||
fld_cat_db_id_name = "page_cat_db_id";
|
||||
}
|
||||
fld_id = flds.Add_int_pkey("page_id"); // int(10); unsigned -- MW:same
|
||||
fld_ns = flds.Add_int("page_namespace"); // int(11); -- MW:same
|
||||
fld_title = flds.Add_str("page_title", 255); // varbinary(255); -- MW:blob
|
||||
fld_is_redirect = flds.Add_int("page_is_redirect"); // tinyint(3); -- MW:same
|
||||
fld_touched = flds.Add_str("page_touched", 14); // binary(14); -- MW:blob; NOTE: should be revision!rev_timestamp, but needs extra join
|
||||
fld_len = flds.Add_int("page_len"); // int(10); unsigned -- MW:same except NULL REF: WikiPage.php!updateRevisionOn;"
|
||||
fld_random_int = flds.Add_int("page_random_int"); // MW:XOWA
|
||||
fld_text_db_id = flds.Add_int(fld_text_db_id_name); // MW:XOWA
|
||||
fld_html_db_id = flds.Add_int_dflt("page_html_db_id", -1); // MW:XOWA
|
||||
fld_redirect_id = flds.Add_int_dflt("page_redirect_id", -1); // MW:XOWA
|
||||
fld_score = flds.Add_int_dflt(Fld__page_score__key, -1); // MW:XOWA
|
||||
if (fld_cat_db_id_name != Dbmeta_fld_itm.Key_null)
|
||||
fld_cat_db_id = flds.Add_int_dflt(fld_cat_db_id_name, -1);// MW:XOWA
|
||||
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_random_int, fld_text_db_id, fld_html_db_id, fld_redirect_id, fld_score, fld_cat_db_id);
|
||||
flds_select_idx = String_.Ary_wo_null(fld_ns, fld_title, fld_id, fld_len, fld_score);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public Dbmeta_fld_list Flds__all() {return flds;}
|
||||
public String Fld_page_id() {return fld_id;}
|
||||
public String Fld_page_ns() {return fld_ns;}
|
||||
public String Fld_page_title() {return fld_title;}
|
||||
public String Fld_page_len() {return fld_len;}
|
||||
public String Fld_page_score() {return fld_score;} public static final String Fld__page_score__key = "page_score";
|
||||
public String Fld_text_db_id() {return fld_text_db_id;}
|
||||
public String Fld_html_db_id() {return fld_html_db_id;}
|
||||
public String Fld_is_redirect() {return fld_is_redirect;}
|
||||
public String Fld_random_int() {return fld_random_int;}
|
||||
public String Fld_modified_on() {return fld_touched;}
|
||||
public String Fld_redirect_id() {return fld_redirect_id;}
|
||||
public String[] Flds_select_idx() {return flds_select_idx;}
|
||||
public String[] Flds_select_all() {return flds_select_all;}
|
||||
public void Flds__assert() {
|
||||
conn.Meta_fld_assert(tbl_name, this.Fld_html_db_id() , Dbmeta_fld_tid.Itm__int, -1);
|
||||
conn.Meta_fld_assert(tbl_name, this.Fld_redirect_id() , Dbmeta_fld_tid.Itm__int, -1);
|
||||
conn.Meta_fld_assert(tbl_name, Fld__page_score__key , Dbmeta_fld_tid.Itm__int, -1);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds.To_fld_ary()));}
|
||||
public void Insert(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
|
||||
this.Insert_bgn();
|
||||
this.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, page_is_redirect, modified_on, page_len, random_int, text_db_id, html_db_id, -1);
|
||||
this.Insert_end();
|
||||
}
|
||||
public void Insert_bgn() {conn.Txn_bgn("page__insert_bulk"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch
|
||||
(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int
|
||||
, int text_db_id, int html_db_id, int cat_db_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_id, page_id)
|
||||
.Val_int(fld_ns, ns_id)
|
||||
.Val_bry_as_str(fld_title, ttl_wo_ns)
|
||||
.Val_bool_as_byte(fld_is_redirect, page_is_redirect)
|
||||
.Val_str(fld_touched, modified_on.XtoStr_fmt(Page_touched_fmt))
|
||||
.Val_int(fld_len, page_len)
|
||||
.Val_int(fld_random_int, random_int)
|
||||
.Val_int(fld_text_db_id, text_db_id)
|
||||
.Val_int(fld_html_db_id, html_db_id)
|
||||
.Val_int(fld_redirect_id, -1)
|
||||
.Val_int(fld_score, -1)
|
||||
.Val_int(fld_cat_db_id, cat_db_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Insert_by_itm(Db_stmt stmt, Xowd_page_itm itm, int html_db_id) {
|
||||
stmt.Clear()
|
||||
.Val_int (fld_id , itm.Id())
|
||||
.Val_int (fld_ns , itm.Ns_id())
|
||||
.Val_bry_as_str (fld_title , itm.Ttl_page_db())
|
||||
.Val_bool_as_byte (fld_is_redirect , itm.Redirected())
|
||||
.Val_str (fld_touched , itm.Modified_on().XtoStr_fmt(Xowd_page_tbl.Page_touched_fmt))
|
||||
.Val_int (fld_len , itm.Text_len())
|
||||
.Val_int (fld_random_int , itm.Random_int())
|
||||
.Val_int (fld_text_db_id , itm.Text_db_id())
|
||||
.Val_int (fld_html_db_id , html_db_id)
|
||||
.Val_int (fld_redirect_id , itm.Redirect_id())
|
||||
.Val_int (fld_score , itm.Score())
|
||||
.Val_int (fld_cat_db_id , -1)
|
||||
.Exec_insert();
|
||||
}
|
||||
public Xowd_page_itm Select_by_ttl_as_itm_or_null(Xoa_ttl ttl) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm();
|
||||
return Select_by_ttl(rv, ttl) ? rv : null;
|
||||
}
|
||||
public boolean Select_by_ttl(Xowd_page_itm rv, Xoa_ttl ttl) {return Select_by_ttl(rv, ttl.Ns(), ttl.Page_db());}
|
||||
public boolean Select_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) {
|
||||
if (stmt_select_all_by_ttl == null) stmt_select_all_by_ttl = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_ns, fld_title));
|
||||
synchronized (thread_lock) { // LOCK:stmt-rls; DATE:2016-07-06
|
||||
Db_rdr rdr = stmt_select_all_by_ttl.Clear().Crt_int(fld_ns, ns.Id()).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
Read_page__all(rv, rdr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Xowd_page_itm Select_by_id_or_null(int page_id) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm();
|
||||
boolean exists = Select_by_id(rv, page_id);
|
||||
return exists ? rv : null;
|
||||
}
|
||||
public boolean Select_by_id(Xowd_page_itm rv, int page_id) {
|
||||
if (stmt_select_all_by_id == null) stmt_select_all_by_id = conn.Stmt_select(tbl_name, flds_select_all, fld_id);
|
||||
Db_rdr rdr = stmt_select_all_by_id.Clear().Crt_int(fld_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
if (rdr.Move_next()) {
|
||||
Read_page__all(rv, rdr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
return false;
|
||||
}
|
||||
public Db_rdr Select_all__id__ttl() {
|
||||
Db_qry__select_cmd qry = new Db_qry__select_cmd().From_(tbl_name).Cols_(fld_id, fld_title).Order_asc_(fld_id);
|
||||
return conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
}
|
||||
public int Select_id(int ns_id, byte[] ttl) {
|
||||
if (stmt_select_id_by_ttl == null) stmt_select_id_by_ttl = conn.Stmt_select(tbl_name, flds_select_all, fld_ns, fld_title);
|
||||
Db_rdr rdr = stmt_select_id_by_ttl.Clear().Crt_int(fld_ns, ns_id).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_int(fld_id) : Xowd_page_itm.Id_null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_in__id(Select_in_cbk cbk) {
|
||||
int pos = 0;
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
Select_in_wkr wkr = Select_in_wkr.New(bfr, tbl_name, Flds_select_all(), fld_id);
|
||||
while (true) {
|
||||
pos = wkr.Make_sql_or_null(bfr, cbk, pos);
|
||||
if (pos == -1) break;
|
||||
Db_rdr rdr = conn.Stmt_sql(bfr.To_str_and_clear()).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next())
|
||||
cbk.Read_data(rdr);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
public void Select_in__ttl(Cancelable cancelable, Ordered_hash rv, int ns_id, int bgn, int end) {
|
||||
Xowd_page_tbl__ttl wkr = new Xowd_page_tbl__ttl();
|
||||
wkr.Ctor(this, tbl_name, fld_title);
|
||||
wkr.Init(rv, ns_id);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public void Select_in__ns_ttl(Cancelable cancelable, Ordered_hash rv, Xow_ns_mgr ns_mgr, boolean fill_idx_fields_only, int bgn, int end) {
|
||||
Xowd_page_tbl__ttl_ns wkr = new Xowd_page_tbl__ttl_ns();
|
||||
wkr.Fill_idx_fields_only_(fill_idx_fields_only);
|
||||
wkr.Ctor(this, tbl_name, fld_title);
|
||||
wkr.Init(this, ns_mgr, rv);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
}
|
||||
public boolean Select_in__id(Cancelable cancelable, boolean show_progress, List_adp rv) {return Select_in__id(cancelable, false, show_progress, rv, 0, rv.Count());}
|
||||
public boolean Select_in__id(Cancelable cancelable, boolean skip_table_read, boolean show_progress, List_adp rv, int bgn, int end) {
|
||||
Xowd_page_itm[] page_ary = (Xowd_page_itm[])rv.To_ary(Xowd_page_itm.class);
|
||||
int len = page_ary.length; if (len == 0) return false;
|
||||
Ordered_hash hash = Ordered_hash_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (cancelable.Canceled()) return false;
|
||||
Xowd_page_itm p = page_ary[i];
|
||||
if (!hash.Has(p.Id_val())) // NOTE: must check if file already exists b/c dynamicPageList currently allows dupes; DATE:2013-07-22
|
||||
hash.Add(p.Id_val(), p);
|
||||
}
|
||||
hash.Sort_by(Xowd_page_itm_sorter.IdAsc); // sort by ID to reduce disk thrashing; DATE:2015-03-31
|
||||
Xowd_page_tbl__id wkr = new Xowd_page_tbl__id(rv, hash, show_progress);
|
||||
wkr.Ctor(this, tbl_name, fld_id);
|
||||
wkr.Select_in(cancelable, conn, bgn, end);
|
||||
return true;
|
||||
}
|
||||
public byte[] Select_random(Xow_ns ns) {// ns should be ns_main
|
||||
int random_int = RandomAdp_.new_().Next(ns.Count());
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_title), fld_random_int, fld_ns)
|
||||
.Crt_int(fld_random_int, random_int).Crt_int(fld_ns, ns.Id())
|
||||
.Exec_select__rls_auto();
|
||||
try {return rdr.Move_next() ? rdr.Read_bry_by_str(fld_title) : null;}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_by_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
|
||||
if (Bry_.Len_eq_0(search)) return; // do not allow empty search
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.New_eq(fld_ns, Xow_ns_.Tid__main), Db_crt_.New_like(fld_title, ""));
|
||||
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Cols_(fld_id, fld_len, fld_ns, fld_title).Where_(crt); // NOTE: use fields from main index only
|
||||
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Tid__main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
this.Read_page__idx(page, rdr);
|
||||
rv.Add(page);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Select_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
|
||||
String search_bgn = String_.new_u8(key);
|
||||
String search_end = String_.new_u8(gplx.core.intls.Utf8_.Increment_char_at_last_pos(key));
|
||||
String sql = String_.Format
|
||||
( "SELECT {0}, {1}, {2}, {3} FROM {4} INDEXED BY {4}__title WHERE {1} = {5} AND {2} BETWEEN '{6}' AND '{7}' ORDER BY {3} DESC LIMIT {8};"
|
||||
, fld_id, fld_ns, fld_title, fld_len
|
||||
, tbl_name
|
||||
, Int_.To_str(ns.Id()), search_bgn, search_end, Int_.To_str(max_results)
|
||||
);
|
||||
Db_qry qry = Db_qry_sql.rdr_(sql);
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
Read_page__idx(page, rdr);
|
||||
rslt_list.Add(page);
|
||||
}
|
||||
rslt_list.Sort_by(Xowd_page_itm_sorter.TitleAsc);
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_count_all() {return conn.Exec_select_count_as_int(tbl_name, -1);}
|
||||
private Db_rdr Load_ttls_starting_with_rdr(int ns_id, byte[] ttl_frag, boolean include_redirects, int max_results, int min_page_len, int browse_len, boolean fwd, boolean search_suggest) {
|
||||
String ttl_frag_str = String_.new_u8(ttl_frag);
|
||||
Criteria crt_ttl = fwd ? Db_crt_.New_mte(fld_title, ttl_frag_str) : Db_crt_.New_lt(fld_title, ttl_frag_str);
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.New_eq(fld_ns, ns_id), crt_ttl, Db_crt_.New_mte(fld_len, min_page_len));
|
||||
if (!include_redirects)
|
||||
crt = Criteria_.And(crt, Db_crt_.New_eq(fld_is_redirect, Byte_.Zero));
|
||||
String[] cols = search_suggest
|
||||
? flds_select_idx
|
||||
: flds_select_all
|
||||
;
|
||||
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).Order_(fld_title, fwd);
|
||||
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, List_adp 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;
|
||||
int rslt_idx = 0;
|
||||
boolean max_val_check = max_results == Int_.Max_value;
|
||||
Db_rdr rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, true, true);
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
Read_page__idx(page, rdr);
|
||||
if (max_val_check && !Bry_.Has_at_bgn(page.Ttl_page_db(), key)) break;
|
||||
nxt_itm = page;
|
||||
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
|
||||
else {
|
||||
rslt_list.Add(page);
|
||||
++rslt_idx;
|
||||
}
|
||||
}
|
||||
if (rslt_nxt != null && nxt_itm != null) // occurs when range is empty; EX: "Module:A" in simplewikibooks
|
||||
rslt_nxt.Copy(nxt_itm);
|
||||
if (fetch_prv_item) { // NOTE: Special:AllPages passes in true, but Search_suggest passes in false
|
||||
if (cancelable.Canceled()) return;
|
||||
rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, false, false);
|
||||
Xowd_page_itm prv_itm = new Xowd_page_itm();
|
||||
boolean found = false;
|
||||
while (rdr.Move_next()) {
|
||||
Read_page__all(prv_itm, rdr);
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
rslt_prv.Copy(prv_itm);
|
||||
else { // at beginning of range, so no items found; EX: "Module:A" is search, but 1st Module is "Module:B"
|
||||
if (rslt_list.Count() > 0) // use 1st item
|
||||
rslt_prv.Copy((Xowd_page_itm)rslt_list.Get_at(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
rslt_count.Val_(rslt_idx);
|
||||
}
|
||||
public void Read_page__idx(Xowd_page_itm page, Db_rdr rdr) {
|
||||
page.Init_by_load__idx
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_ns)
|
||||
, rdr.Read_bry_by_str(fld_title)
|
||||
, rdr.Read_int(fld_len)
|
||||
);
|
||||
}
|
||||
public void Read_page__all(Xowd_page_itm page, Db_rdr rdr) {
|
||||
// handle page_score defaulting to page_len
|
||||
int page_len = rdr.Read_int(fld_len);
|
||||
int page_score = fld_score == Dbmeta_fld_itm.Key_null ? page_len : rdr.Read_int(fld_score);
|
||||
int cat_db_id = fld_cat_db_id == Dbmeta_fld_itm.Key_null ? -1 : rdr.Read_int(fld_cat_db_id);
|
||||
|
||||
page.Init_by_load__all
|
||||
( rdr.Read_int(fld_id)
|
||||
, rdr.Read_int(fld_ns)
|
||||
, rdr.Read_bry_by_str(fld_title)
|
||||
, DateAdp_.parse_fmt(rdr.Read_str(fld_touched), Page_touched_fmt)
|
||||
, rdr.Read_bool_by_byte(fld_is_redirect)
|
||||
, page_len
|
||||
, rdr.Read_int(fld_random_int)
|
||||
, rdr.Read_int(fld_text_db_id)
|
||||
, rdr.Read_int(fld_html_db_id)
|
||||
, rdr.Read_int(fld_redirect_id)
|
||||
, page_score
|
||||
, cat_db_id
|
||||
);
|
||||
}
|
||||
public void Update__html_db_id(int page_id, int html_db_id) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_html_db_id);
|
||||
stmt.Val_int(fld_html_db_id, html_db_id).Crt_int(fld_id, page_id).Exec_update();
|
||||
}
|
||||
public void Update__cat_db_id(int page_id, int cat_db_id) {
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_cat_db_id);
|
||||
stmt.Val_int(fld_cat_db_id, cat_db_id).Crt_int(fld_id, page_id).Exec_update();
|
||||
}
|
||||
public void Update__ns__ttl(int page_id, int trg_ns, byte[] trg_ttl) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
try {
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_ns, fld_title)
|
||||
.Val_int(fld_ns, trg_ns).Val_bry_as_str(fld_title, trg_ttl)
|
||||
.Crt_int(fld_id, page_id)
|
||||
.Exec_update();
|
||||
break;
|
||||
} catch (Exception exc) {
|
||||
if (String_.Has(Err_.Message_gplx_full(exc), "columns page_namespace, page_random_int are not unique")) { // HACK: terrible hack, but moving pages across ns will break UNIQUE index
|
||||
conn.Exec_sql_args("DROP INDEX {0}__name_random;", tbl_name); // is UNIQUE by default
|
||||
conn.Exec_sql_args("CREATE INDEX {0}__name_random ON {0} ({1}, {2});", tbl_name, fld_ns, fld_random_int);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Update__redirect__modified(int page_id, boolean redirect, DateAdp modified) {
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_is_redirect, fld_touched)
|
||||
.Val_int(fld_is_redirect, redirect ? 1 : 0)
|
||||
.Val_str(fld_touched, modified.XtoStr_fmt(Page_touched_fmt))
|
||||
.Crt_int(fld_id, page_id)
|
||||
.Exec_update()
|
||||
;
|
||||
}
|
||||
public void Update__redirect(int redirect_to_id, int page_id) {
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_is_redirect, fld_redirect_id)
|
||||
.Val_int(fld_is_redirect, Bool_.Y_int)
|
||||
.Val_int(fld_redirect_id, redirect_to_id)
|
||||
.Crt_int(fld_id, page_id)
|
||||
.Exec_update()
|
||||
;
|
||||
}
|
||||
|
||||
public void Delete(int page_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.page: delete started: page_id=~{0}", page_id);
|
||||
conn.Stmt_delete(tbl_name, fld_id).Crt_int(fld_id, page_id).Exec_delete();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.page: delete done");
|
||||
}
|
||||
public void Update_page_id(int old_id, int new_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.page: update page_id started: old_id=~{0} new_id=~{1}", old_id, new_id);
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_id).Val_int(fld_id, new_id).Crt_int(fld_id, old_id).Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.page: update page_id done");
|
||||
}
|
||||
public void Create_idx() {
|
||||
conn.Meta_idx_create(Xoa_app_.Usr_dlg()
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "title" , fld_title, fld_ns)
|
||||
, Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "random" , fld_random_int)
|
||||
);
|
||||
}
|
||||
public int Fld_page_score_eval(Db_rdr rdr, int page_len) {
|
||||
return fld_score == Dbmeta_fld_itm.Key_null ? page_len : rdr.Read_int(fld_score);
|
||||
}
|
||||
public void Rls() {
|
||||
synchronized (thread_lock) {// LOCK:stmt-rls; DATE:2016-07-06
|
||||
stmt_select_all_by_ttl = Db_stmt_.Rls(stmt_select_all_by_ttl);
|
||||
stmt_select_all_by_id = Db_stmt_.Rls(stmt_select_all_by_id);
|
||||
stmt_select_id_by_ttl = Db_stmt_.Rls(stmt_select_id_by_ttl);
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
||||
public static final String Page_touched_fmt = "yyyyMMddHHmmss";
|
||||
public static final String TBL_NAME = "page", FLD__page_cat_db_id = "page_cat_db_id";
|
||||
public static Xowd_page_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_page_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
public static final int INVALID_PAGE_ID = -1;
|
||||
}
|
||||
|
||||
@@ -13,26 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
class Xowd_page_tbl__id extends Xowd_page_tbl__in_wkr__base {
|
||||
private final List_adp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
|
||||
private final Ordered_hash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
|
||||
public Xowd_page_tbl__id(List_adp list, Ordered_hash hash, boolean show_progress) {
|
||||
this.show_progress = show_progress;
|
||||
this.list = list; this.hash = hash;
|
||||
this.Fill_idx_fields_only_(true);
|
||||
}
|
||||
@Override protected boolean Show_progress() {return show_progress;} private final boolean show_progress;
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
return Db_crt_.New_in(this.In_fld_name(), part_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)list.Get_at(i);
|
||||
stmt.Val_int(page.Id());
|
||||
}
|
||||
}
|
||||
@Override protected Xowd_page_itm Get_page_or_null(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Id_val());}
|
||||
}
|
||||
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
abstract class Xowd_page_tbl__in_wkr__base extends Db_in_wkr__base {
|
||||
protected Xowd_page_tbl tbl; private String tbl_name, fld_in_name;
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public void Ctor(Xowd_page_tbl tbl, String tbl_name, String fld_in_name) {this.tbl = tbl; this.tbl_name = tbl_name; this.fld_in_name = fld_in_name;}
|
||||
public String In_fld_name() {return fld_in_name;}
|
||||
protected abstract Criteria In_filter(Object[] part_ary);
|
||||
protected abstract Xowd_page_itm Get_page_or_null(Xowd_page_itm rdr_page);
|
||||
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public void Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v;} private boolean fill_idx_fields_only;
|
||||
@Override protected Db_qry Make_qry(int bgn, int end) {
|
||||
Object[] part_ary = In_ary(end - bgn);
|
||||
return Db_qry_.select_cols_
|
||||
( this.Tbl_name()
|
||||
, In_filter(part_ary)
|
||||
, fill_idx_fields_only ? tbl.Flds_select_idx() : tbl.Flds_select_all()
|
||||
);
|
||||
}
|
||||
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
|
||||
Xowd_page_itm load = new Xowd_page_itm();
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
if (fill_idx_fields_only)
|
||||
tbl.Read_page__idx(load, rdr);
|
||||
else
|
||||
tbl.Read_page__all(load, rdr);
|
||||
|
||||
// get page reference from list; copy load values into it; COMMENT:2016-08-28
|
||||
Xowd_page_itm page = this.Get_page_or_null(load);
|
||||
if (page == null) continue; // page not found
|
||||
page.Copy(load);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
class Xowd_page_tbl__ttl extends Xowd_page_tbl__in_wkr__base {
|
||||
private Ordered_hash hash; private int in_ns;
|
||||
@Override protected int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Ordered_hash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.New_eq(fld_ns, in_ns), Db_crt_.New_eq(fld_ttl, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Val_int(in_ns);
|
||||
stmt.Val_bry_as_str(page.Ttl_page_db());
|
||||
}
|
||||
}
|
||||
@Override protected Xowd_page_itm Get_page_or_null(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_page_db());}
|
||||
}
|
||||
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.criterias.*;
|
||||
import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
class Xowd_page_tbl__ttl_ns extends Xowd_page_tbl__in_wkr__base {
|
||||
private Xowd_page_tbl page_tbl;
|
||||
private Xow_ns_mgr ns_mgr; private Ordered_hash hash;
|
||||
@Override protected int Interval() {return 64;} // NOTE: 96+ overflows; PAGE:en.w:Space_Liability_Convention; DATE:2013-10-24
|
||||
public void Init(Xowd_page_tbl page_tbl, Xow_ns_mgr ns_mgr, Ordered_hash hash) {
|
||||
this.page_tbl = page_tbl;
|
||||
this.ns_mgr = ns_mgr; this.hash = hash;
|
||||
}
|
||||
@Override protected Criteria In_filter(Object[] part_ary) {
|
||||
int len = part_ary.length;
|
||||
Criteria[] crt_ary = new Criteria[len];
|
||||
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
|
||||
for (int i = 0; i < len; i++)
|
||||
crt_ary[i] = Criteria_.And(Db_crt_.New_eq(fld_ns, 0), Db_crt_.New_eq(fld_ttl, Bry_.Empty));
|
||||
return Criteria_.Or_many(crt_ary);
|
||||
}
|
||||
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
|
||||
for (int i = bgn; i < end; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
stmt.Crt_int(page_tbl.Fld_page_ns(), page.Ns_id());
|
||||
stmt.Crt_bry_as_str(page_tbl.Fld_page_title(), page.Ttl_page_db());
|
||||
}
|
||||
}
|
||||
@Override protected Xowd_page_itm Get_page_or_null(Xowd_page_itm rdr_page) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(rdr_page.Ns_id());
|
||||
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
|
||||
byte[] ttl_wo_ns = rdr_page.Ttl_page_db();
|
||||
rdr_page.Ttl_(ns, ttl_wo_ns);
|
||||
return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_full_db());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import org.junit.*; import gplx.xowa.bldrs.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xowd_page_tbl_tst {
|
||||
private Xowd_page_tbl_fxt fxt = new Xowd_page_tbl_fxt();
|
||||
@Test public void Find_search_end() {
|
||||
fxt.Test_find_search_end("ab", "ac");
|
||||
fxt.Test_find_search_end("ab%", "ac%");
|
||||
}
|
||||
}
|
||||
class Xowd_page_tbl_fxt {
|
||||
public void Test_find_search_end(String val, String expd) {Tfds.Eq(expd, String_.new_u8(Find_search_end(Bry_.new_u8(val))));}
|
||||
private static byte[] Find_search_end(byte[] orig) { // NOTE: moved from old Xowd_page_tbl; is probably obsolete
|
||||
byte[] rv = Bry_.Copy(orig);
|
||||
int rv_len = rv.length;
|
||||
int increment_pos = rv[rv_len - 1] == Byte_ascii.Percent ? rv_len - 2 : rv_len - 1; // increment last char, unless it is %; if %, increment one before it
|
||||
return Bry_.Increment_last(rv, increment_pos);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,77 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_site_ns_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_id, fld_name, fld_case, fld_count, fld_is_alias;
|
||||
private final Db_conn conn;
|
||||
public Xowd_site_ns_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = schema_is_1 ? "xowa_ns" : "site_ns";
|
||||
fld_id = flds.Add_int_pkey ("ns_id");
|
||||
fld_name = flds.Add_str ("ns_name", 255);
|
||||
fld_case = flds.Add_byte ("ns_case");
|
||||
fld_is_alias = flds.Add_bool ("ns_is_alias");
|
||||
fld_count = flds.Add_int ("ns_count");
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert(Xow_ns_mgr ns_mgr) {
|
||||
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
int len = ns_mgr.Ids_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_at(i);
|
||||
stmt.Clear()
|
||||
.Val_int(fld_id, ns.Id())
|
||||
.Val_str(fld_name, ns.Name_db_str())
|
||||
.Val_byte(fld_case, ns.Case_match())
|
||||
.Val_bool_as_byte(fld_is_alias, ns.Is_alias())
|
||||
.Val_int(fld_count, ns.Count())
|
||||
.Exec_insert();
|
||||
;
|
||||
}
|
||||
}
|
||||
public void Select_all(Xow_ns_mgr ns_mgr) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
ns_mgr.Clear();
|
||||
while (rdr.Move_next()) {
|
||||
int ns_id = rdr.Read_int(fld_id);
|
||||
byte[] ns_name = rdr.Read_bry_by_str(fld_name);
|
||||
byte ns_case_match = rdr.Read_byte(fld_case);
|
||||
int ns_count = rdr.Read_int(fld_count);
|
||||
boolean ns_is_alias = rdr.Read_byte(fld_is_alias) == Bool_.Y_byte;
|
||||
ns_mgr.Add_new(ns_id, ns_name, ns_case_match, ns_is_alias);
|
||||
if (ns_id < 0) continue; // don't load counts for Special / Media
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
|
||||
ns.Count_(ns_count);
|
||||
if (ns_count > 0) ns.Exists_(true); // ns has article; mark it as exists, else Talk tab won't show; DATE:2013-12-04
|
||||
}
|
||||
ns_mgr.Init();
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public int Select_ns_count(int ns_id) {
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_id))
|
||||
.Crt_int(fld_id, ns_id)
|
||||
.Exec_select__rls_auto();
|
||||
try {
|
||||
return rdr.Move_next() ? Int_.Cast(rdr.Read_int(fld_count)) : 0;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
public void Update_ns_count(int ns_id, int ns_count) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.site_ns: update started: ns_id=~{0} ns_count=~{1}", ns_id, ns_count);
|
||||
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_count);
|
||||
stmt.Clear()
|
||||
.Val_int(fld_count, ns_count)
|
||||
.Crt_int(fld_id, ns_id)
|
||||
.Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.site_ns: update done");
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
public static final String TBL_NAME = "site_ns";
|
||||
public static Xowd_site_ns_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_site_ns_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public interface Xowd_text_bry_owner {
|
||||
int Page_id();
|
||||
void Set_text_bry_by_db(byte[] v);
|
||||
}
|
||||
|
||||
@@ -13,12 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xowd_text_row {
|
||||
public final int page_id;
|
||||
public final byte[] text;
|
||||
public Xowd_text_row(int page_id, byte[] text) {
|
||||
this.page_id = page_id;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,82 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.ios.*; import gplx.dbs.*; import gplx.dbs.utls.*;
|
||||
public class Xowd_text_tbl implements Db_tbl {
|
||||
private final Object thread_lock = new Object();
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_page_id, fld_text_data;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
|
||||
private final Io_stream_zip_mgr zip_mgr = new Io_stream_zip_mgr(); private final byte zip_tid;
|
||||
public String Fld_text_data() {return fld_text_data;}
|
||||
public Xowd_text_tbl(Db_conn conn, boolean schema_is_1, byte zip_tid) {
|
||||
this.conn = conn; this.zip_tid = zip_tid;
|
||||
String fld_text_data_name = "";
|
||||
fld_text_data_name = schema_is_1 ? "old_text" : "text_data";
|
||||
fld_page_id = flds.Add_int_pkey("page_id");
|
||||
fld_text_data = flds.Add_bry(fld_text_data_name);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name = TBL_NAME;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__text__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, byte[] text_data) {
|
||||
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_bry(fld_text_data, text_data).Exec_insert();
|
||||
}
|
||||
public void Update(int page_id, byte[] text) {
|
||||
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
|
||||
text = zip_mgr.Zip(zip_tid, text);
|
||||
stmt.Clear().Val_bry(fld_text_data, text).Crt_int(fld_page_id, page_id).Exec_update();
|
||||
}
|
||||
public void Delete(int page_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.text: delete started: db=~{0} page_id=~{1}", conn.Conn_info().Raw(), page_id);
|
||||
conn.Stmt_delete(tbl_name, fld_page_id).Crt_int(fld_page_id, page_id).Exec_delete();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.text: delete done");
|
||||
}
|
||||
public void Update_page_id(int old_id, int new_id) {
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.text: update page_id started: db=~{0} old_id=~{1} new_id=~{2}", conn.Conn_info().Raw(), old_id, new_id);
|
||||
conn.Stmt_update(tbl_name, String_.Ary(fld_page_id), fld_page_id).Val_int(fld_page_id, new_id).Crt_int(fld_page_id, old_id).Exec_update();
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "db.text: update page_id done");
|
||||
}
|
||||
public byte[] Select(int page_id) {
|
||||
synchronized (thread_lock) { // LOCK:stmt-rls; DATE:2016-07-06
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
|
||||
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_manual();
|
||||
try {
|
||||
byte[] rv = Bry_.Empty;
|
||||
if (rdr.Move_next()) {
|
||||
rv = rdr.Read_bry(fld_text_data);
|
||||
if (rv == null) rv = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert null to empty String; DATE:2015-11-08
|
||||
rv = zip_mgr.Unzip(zip_tid, rv);
|
||||
}
|
||||
return rv;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
public Xowd_text_row[] Select_where(byte[] query) {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_sql(Db_sql_.Make_by_fmt(String_.Ary("SELECT * FROM text WHERE text_data LIKE '{0}'") , query)).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
int page_id = rdr.Read_int(fld_page_id);
|
||||
byte[] text = rdr.Read_bry(fld_text_data);
|
||||
if (text == null) text = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert null to empty String; DATE:2015-11-08
|
||||
text = zip_mgr.Unzip(zip_tid, text);
|
||||
list.Add(new Xowd_text_row(page_id, text));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
return (Xowd_text_row[])list.To_ary_and_clear(Xowd_text_row.class);
|
||||
}
|
||||
public byte[] Zip(byte[] data) {return zip_mgr.Zip(zip_tid, data);}
|
||||
public void Rls() {
|
||||
synchronized (thread_lock) { // LOCK:stmt-rls; DATE:2016-07-06
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String TBL_NAME = "text";
|
||||
public static Xowd_text_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_text_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
|
||||
@@ -13,52 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.xowa.xtns.wbases.*;
|
||||
public class Xowd_wbase_pid_tbl implements Rls_able {
|
||||
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_src_lang, fld_src_ttl, fld_trg_ttl;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
|
||||
public Xowd_wbase_pid_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "wdata_pids"; fld_prefix = "wp_";}
|
||||
else {tbl_name = "wbase_pid";}
|
||||
fld_src_lang = flds.Add_str(fld_prefix + "src_lang", 255);
|
||||
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
|
||||
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_lang, fld_src_ttl));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__wbase_pid__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl) {
|
||||
stmt_insert.Clear()
|
||||
.Val_bry_as_str(fld_src_lang, src_lang).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl, trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public int Select_pid(byte[] src_lang, byte[] src_ttl) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_lang, fld_src_ttl);
|
||||
Db_rdr rdr = stmt_select.Clear()
|
||||
.Crt_bry_as_str(fld_src_lang, src_lang).Crt_bry_as_str(fld_src_ttl, src_ttl)
|
||||
.Exec_select__rls_manual();
|
||||
try {
|
||||
if (!rdr.Move_next()) return Wdata_wiki_mgr.Pid_null; // occurs when pid exists, but does not have entry for language; see hu.w:Marco Polo argali; DATE: 2014-02-01
|
||||
byte[] pid_bry = rdr.Read_bry_by_str(fld_trg_ttl);
|
||||
return pid_bry == null ? Wdata_wiki_mgr.Pid_null : Bry_.To_int_or(pid_bry, 1, pid_bry.length, Wdata_wiki_mgr.Pid_null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "db.wdata_pids:failed to select pid; lang=~{0} src_ttl=~{1} err=~{2}", src_lang, src_ttl, Err_.Message_gplx_log(e));
|
||||
try {stmt_select.Rls();}
|
||||
catch (Exception e2) {Gfo_usr_dlg_.Instance.Warn_many("", "", "db.wdata_pids: failed to rls stmt; err=~{0}", Err_.Message_gplx_log(e2));}
|
||||
stmt_select = null;
|
||||
return Wdata_wiki_mgr.Pid_null;
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,50 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xowd_wbase_qid_tbl implements Rls_able {
|
||||
private final Object thread_lock = new Object();
|
||||
private final String tbl_name; private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_src_wiki, fld_src_ns, fld_src_ttl, fld_trg_ttl;
|
||||
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
|
||||
private boolean src_ttl_has_spaces;
|
||||
public Xowd_wbase_qid_tbl(Db_conn conn, boolean schema_is_1, boolean src_ttl_has_spaces) {
|
||||
this.conn = conn; this.src_ttl_has_spaces = src_ttl_has_spaces;
|
||||
String fld_prefix = "";
|
||||
if (schema_is_1) {tbl_name = "wdata_qids"; fld_prefix = "wq_";}
|
||||
else {tbl_name = "wbase_qid";}
|
||||
fld_src_wiki = flds.Add_str(fld_prefix + "src_wiki", 255);
|
||||
fld_src_ns = flds.Add_int(fld_prefix + "src_ns");
|
||||
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
|
||||
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Meta_idx_create(Xoa_app_.Usr_dlg(), Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "src", fld_src_wiki, fld_src_ns, fld_src_ttl));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__wbase_qid__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(byte[] src_wiki, int src_ns, byte[] src_ttl, byte[] trg_ttl) {
|
||||
stmt_insert.Clear()
|
||||
.Val_bry_as_str(fld_src_wiki, src_wiki).Val_int(fld_src_ns, src_ns).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl,trg_ttl)
|
||||
.Exec_insert();
|
||||
}
|
||||
public byte[] Select_qid(byte[] src_wiki, byte[] src_ns, byte[] src_ttl) {
|
||||
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_wiki, fld_src_ns, fld_src_ttl);
|
||||
synchronized (stmt_select) { // LOCK:stmt-rls; DATE:2016-07-06
|
||||
if (src_ttl_has_spaces) src_ttl = Xoa_ttl.Replace_unders(src_ttl); // NOTE: v2.4.2.1-v2.4.3.2 stores ttl in spaces ("A B"), while xowa will use under form ("A_B"); DATE:2015-04-21
|
||||
Db_rdr rdr = stmt_select.Clear()
|
||||
.Crt_bry_as_str(fld_src_wiki, src_wiki).Crt_int(fld_src_ns, Bry_.To_int_or_neg1(src_ns)).Crt_bry_as_str(fld_src_ttl, src_ttl)
|
||||
.Exec_select__rls_manual();
|
||||
try {
|
||||
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_trg_ttl) : null;
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
synchronized (thread_lock) {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
stmt_select = Db_stmt_.Rls(stmt_select);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,34 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import org.junit.*; import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_wbase_qid_tbl_tst {
|
||||
private final Xowd_wbase_qid_tbl_fxt fxt = new Xowd_wbase_qid_tbl_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Space() {
|
||||
fxt.Exec_insert("enwiki", Xow_ns_.Tid__main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A_B", "q1");
|
||||
}
|
||||
}
|
||||
class Xowd_wbase_qid_tbl_fxt {
|
||||
private Xowd_wbase_qid_tbl qid_tbl;
|
||||
public void Clear() {
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
Db_conn_bldr.Instance.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.Instance.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
this.qid_tbl = new Xowd_wbase_qid_tbl(conn, Bool_.N, Bool_.Y); // simulate v2.4.2 with bad "spaces"
|
||||
qid_tbl.Create_tbl();
|
||||
}
|
||||
public void Exec_insert(String src_wiki, int src_ns, String src_ttl, String trg_ttl) {
|
||||
qid_tbl.Insert_bgn();
|
||||
qid_tbl.Insert_cmd_by_batch(Bry_.new_u8(src_wiki), src_ns, Bry_.new_u8(src_ttl), Bry_.new_u8(trg_ttl));
|
||||
qid_tbl.Insert_end();
|
||||
}
|
||||
public void Test_select(String src_wiki, int src_ns, String src_ttl, String expd) {
|
||||
byte[] actl = qid_tbl.Select_qid(Bry_.new_u8(src_wiki), Bry_.new_a7(Int_.To_str(src_ns)), Bry_.new_u8(src_ttl));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,85 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.data.*;
|
||||
public class Xowd_xowa_db_tbl implements Db_tbl {
|
||||
public static final String Fld_id = "db_id", Fld_type = "db_type", Fld_url = "db_url";
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_id, fld_type, fld_url, fld_ns_ids, fld_part_id, fld_guid; private boolean schema_is_1;
|
||||
private final Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr();
|
||||
public Xowd_xowa_db_tbl(Db_conn conn, boolean schema_is_1) {
|
||||
this.conn = conn; this.schema_is_1 = schema_is_1;
|
||||
this.tbl_name = TBL_NAME;
|
||||
fld_id = flds.Add_int_pkey (Fld_id);
|
||||
fld_type = flds.Add_byte (Fld_type);
|
||||
fld_url = flds.Add_str (Fld_url, 512);
|
||||
if (schema_is_1) {
|
||||
fld_ns_ids = fld_part_id = fld_guid = Dbmeta_fld_itm.Key_null;
|
||||
}
|
||||
else {
|
||||
fld_ns_ids = flds.Add_str ("db_ns_ids", 255);
|
||||
fld_part_id = flds.Add_int ("db_part_id");
|
||||
fld_guid = flds.Add_str ("db_guid", 36);
|
||||
}
|
||||
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
|
||||
}
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name; public static final String TBL_NAME = "xowa_db";
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public Xow_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
|
||||
List_adp list = List_adp_.New();
|
||||
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
String ns_ids = ""; int part_id = -1; Guid_adp guid = Guid_adp_.Empty;
|
||||
if (!schema_is_1) {
|
||||
ns_ids = rdr.Read_str(fld_ns_ids);
|
||||
part_id = rdr.Read_int(fld_part_id);
|
||||
guid = Guid_adp_.Parse(rdr.Read_str(fld_guid));
|
||||
}
|
||||
int db_id = rdr.Read_int(fld_id);
|
||||
Xow_db_file db_file = Xow_db_file.Load(props, db_id, rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid);
|
||||
list.Add(db_file);
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
list.Sort_by(Xow_db_file_sorter__id.Instance);
|
||||
return (Xow_db_file[])list.To_ary_and_clear(Xow_db_file.class);
|
||||
}
|
||||
public void Commit_all(Xow_db_mgr core_data_mgr) {
|
||||
stmt_bldr.Batch_bgn();
|
||||
try {
|
||||
int len = core_data_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; i++)
|
||||
Commit_itm(core_data_mgr.Dbs__get_at(i));
|
||||
} finally {stmt_bldr.Batch_end();}
|
||||
}
|
||||
public void Upsert(int id, byte tid, String url, String ns_ids, int part_id, String guid) {
|
||||
gplx.dbs.utls.Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_id), id, tid, url, ns_ids, part_id, guid);
|
||||
}
|
||||
private void Commit_itm(Xow_db_file itm) {
|
||||
Db_stmt stmt = stmt_bldr.Get(itm.Cmd_mode());
|
||||
switch (itm.Cmd_mode()) {
|
||||
case Db_cmd_mode.Tid_create: stmt.Clear().Val_int(fld_id, itm.Id()); Commit_itm_vals(stmt, itm); stmt.Exec_insert(); break;
|
||||
case Db_cmd_mode.Tid_update: stmt.Clear(); Commit_itm_vals(stmt, itm); stmt.Crt_int(fld_id, itm.Id()).Exec_update(); break;
|
||||
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_id, itm.Id()).Exec_delete(); break;
|
||||
case Db_cmd_mode.Tid_ignore: break;
|
||||
default: throw Err_.new_unhandled(itm.Cmd_mode());
|
||||
}
|
||||
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
|
||||
}
|
||||
private void Commit_itm_vals(Db_stmt stmt, Xow_db_file itm) {
|
||||
stmt.Val_byte(fld_type, itm.Tid()).Val_str(fld_url, itm.Url_rel()).Val_str(fld_ns_ids, itm.Ns_ids()).Val_int(fld_part_id, itm.Part_id()).Val_str(fld_guid, itm.Guid().To_str());
|
||||
}
|
||||
public void Rls() {}
|
||||
|
||||
public static Xowd_xowa_db_tbl Get_by_key(Db_tbl_owner owner) {return (Xowd_xowa_db_tbl)owner.Tbls__get_by_key(TBL_NAME);}
|
||||
}
|
||||
class Xow_db_file_sorter__id implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xow_db_file lhs = (Xow_db_file)lhsObj;
|
||||
Xow_db_file rhs = (Xow_db_file)rhsObj;
|
||||
return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
}
|
||||
public static final Xow_db_file_sorter__id Instance = new Xow_db_file_sorter__id(); Xow_db_file_sorter__id() {}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.bldrs.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public interface Xodb_load_mgr {
|
||||
void Load_init (Xowe_wiki wiki);
|
||||
void Load_page (Xowd_page_itm rv, Xow_ns ns);
|
||||
boolean Load_by_id (Xowd_page_itm rv, int id);
|
||||
void Load_by_ids (Cancelable cancelable, List_adp rv, int bgn, int end);
|
||||
boolean Load_by_ttl (Xowd_page_itm rv, Xow_ns ns, byte[] ttl);
|
||||
void Load_by_ttls (Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end);
|
||||
void Load_ttls_for_all_pages (Cancelable cancelable, List_adp 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);
|
||||
void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item);
|
||||
byte[] Find_random_ttl (Xow_ns ns);
|
||||
void Clear(); // TEST:helper function
|
||||
byte[] Load_qid (byte[] wiki_alias, byte[] ns_num, byte[] ttl);
|
||||
int Load_pid (byte[] lang_key, byte[] pid_name);
|
||||
Xodb_page_rdr Get_page_rdr (Xowe_wiki wiki);
|
||||
}
|
||||
|
||||
@@ -13,68 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.apps.gfs.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
private final Xodb_mgr_sql db_mgr;
|
||||
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr) {this.db_mgr = db_mgr;}
|
||||
public void Load_init(Xowe_wiki wiki) {
|
||||
Xow_db_file db_core = wiki.Data__core_mgr().Db__core();
|
||||
Load_cfg(wiki);
|
||||
db_core.Tbl__site_stats().Select(wiki.Stats());
|
||||
db_core.Tbl__ns().Select_all(wiki.Ns_mgr());
|
||||
}
|
||||
private static void Load_cfg(Xow_wiki wiki) {
|
||||
byte[] main_page = null, bldr_version = null, siteinfo_misc = null, siteinfo_mainpage = null;
|
||||
DateAdp modified_latest = null;
|
||||
|
||||
// load from xowa_cfg
|
||||
gplx.dbs.cfgs.Db_cfg_hash prop_hash = wiki.Data__core_mgr().Db__core().Tbl__cfg().Select_as_hash(Xowd_cfg_key_.Grp__wiki_init);
|
||||
int len = prop_hash.Len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
gplx.dbs.cfgs.Db_cfg_itm prop = prop_hash.Get_at(i);
|
||||
String prop_key = prop.Key();
|
||||
try {
|
||||
if (String_.Eq(prop_key, Xowd_cfg_key_.Key__init__main_page)) main_page = Bry_.new_u8(prop.Val());
|
||||
else if (String_.Eq(prop_key, Xowd_cfg_key_.Key__init__bldr_version)) bldr_version = Bry_.new_u8(prop.Val());
|
||||
else if (String_.Eq(prop_key, Xowd_cfg_key_.Key__init__siteinfo_misc)) siteinfo_misc = Bry_.new_u8(prop.Val());
|
||||
else if (String_.Eq(prop_key, Xowd_cfg_key_.Key__init__siteinfo_mainpage)) siteinfo_mainpage = Bry_.new_u8(prop.Val());
|
||||
else if (String_.Eq(prop_key, Xowd_cfg_key_.Key__init__modified_latest)) modified_latest = DateAdp_.parse_gplx(prop.Val());
|
||||
} catch (Exception exc) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to set prop; key=~{0} val=~{1} err=~{2}", prop_key, prop.Val(), Err_.Message_gplx_log(exc));
|
||||
}
|
||||
}
|
||||
|
||||
wiki.Props().Init_by_load_2(main_page, bldr_version, siteinfo_misc, siteinfo_mainpage, modified_latest);
|
||||
}
|
||||
public boolean Load_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) {
|
||||
return db_mgr.Core_data_mgr().Tbl__page().Select_by_ttl(rv, ns, ttl);
|
||||
}
|
||||
public void Load_by_ttls(Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end) {
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_in__ns_ttl(cancelable, rv, db_mgr.Wiki().Ns_mgr(), fill_idx_fields_only, bgn, end);
|
||||
}
|
||||
public void Load_page(Xowd_page_itm rv, Xow_ns ns) {
|
||||
if (rv.Text_db_id() == -1) return; // NOTE: page_sync will create pages with -1 text_db_id; DATE:2017-05-06
|
||||
|
||||
// get text
|
||||
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_by_id_or_fail(rv.Text_db_id()).Tbl__text();
|
||||
byte[] text_bry = text_tbl.Select(rv.Id());
|
||||
rv.Text_(text_bry);
|
||||
}
|
||||
public boolean Load_by_id (Xowd_page_itm rv, int id) {return db_mgr.Core_data_mgr().Tbl__page().Select_by_id(rv, id);}
|
||||
public void Load_by_ids(Cancelable cancelable, List_adp rv, int bgn, int end) {db_mgr.Core_data_mgr().Tbl__page().Select_in__id(cancelable, false, true, rv, bgn, end);}
|
||||
public void Load_ttls_for_all_pages(Cancelable cancelable, List_adp 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) {
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_for_special_all_pages(cancelable, rslt_list, rslt_nxt, rslt_prv, rslt_count, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
|
||||
}
|
||||
public void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_for_search_suggest(cancelable, rslt_list, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
|
||||
}
|
||||
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {return db_mgr.Core_data_mgr().Db__wbase().Tbl__wbase_qid().Select_qid(wiki_alias, ns_num, ttl);}
|
||||
public int Load_pid(byte[] lang_key, byte[] pid_name) {return db_mgr.Core_data_mgr().Db__wbase().Tbl__wbase_pid().Select_pid(lang_key, pid_name);}
|
||||
public byte[] Find_random_ttl(Xow_ns ns) {return db_mgr.Core_data_mgr().Tbl__page().Select_random(ns);}
|
||||
public Xodb_page_rdr Get_page_rdr(Xowe_wiki wiki) {return new Xodb_page_rdr__sql(wiki);}
|
||||
public void Clear() {}
|
||||
}
|
||||
|
||||
@@ -13,397 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.flds.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.bldrs.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.core.encoders.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
private final Xob_xdat_file tmp_xdat_file = new Xob_xdat_file(); private final Xob_xdat_itm tmp_xdat_itm = new Xob_xdat_itm();
|
||||
private final Xowd_page_itm tmp_page = new Xowd_page_itm();
|
||||
private final Object thread_lock = new Object();
|
||||
private Xowe_wiki wiki; private Xotdb_fsys_mgr fsys_mgr;
|
||||
public Xodb_load_mgr_txt(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.fsys_mgr = wiki.Tdb_fsys_mgr();
|
||||
}
|
||||
public void Load_init (Xowe_wiki wiki) {}
|
||||
public void Load_page(Xowd_page_itm rv, Xow_ns ns) {Load_page(rv, rv.Text_db_id(), rv.Tdb_row_idx(), ns, false, tmp_xdat_file, tmp_xdat_itm);}
|
||||
public void Load_page(Xowd_page_itm rv, int txt_fil_idx, int txt_row_idx, Xow_ns ns, boolean timestamp_enabled, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm) {
|
||||
Io_url file = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns.Id(), txt_fil_idx);
|
||||
byte[] bry = Io_mgr.Instance.LoadFilBry(file); int bry_len = bry.length;
|
||||
xdat_file.Clear().Parse(bry, bry_len, file).GetAt(xdat_itm, txt_row_idx);
|
||||
Load_page_parse(rv, bry, bry_len, xdat_itm.Itm_bgn(), xdat_itm.Itm_end(), timestamp_enabled);
|
||||
}
|
||||
public boolean Load_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) { // NOTE: ttl must be correct case; EX: "Example title"
|
||||
if (!Env_.Mode_testing() && wiki.Init_needed()) wiki.Init_assert(); // NOTE: need to call assert as wiki_finder (and possibly elsewhere) may call load on commons_wiki without ever asserting; DATE:2013-03-19
|
||||
if (!Load_xdat_itm(tmp_xdat_itm, ns, Xotdb_dir_info_.Tid_ttl, ttl, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, true)) return false;
|
||||
Xotdb_page_itm_.Txt_ttl_load(rv, tmp_xdat_itm.Itm_bry());
|
||||
return Bry_.Eq(rv.Ttl_page_db(), ttl);
|
||||
}
|
||||
public void Load_by_ttls(Cancelable cancelable, Ordered_hash rv, boolean fill_idx_fields_only, int bgn, int end) {// NOTE: Load_by_ttls just a wrapper around Load_by_ttl; for xdat, Load_by_ttl is fast enough
|
||||
for (int i = bgn; i < end; i++) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm page = (Xowd_page_itm)rv.Get_at(i);
|
||||
Load_by_ttl(page, page.Ns(), page.Ttl_page_db());
|
||||
}
|
||||
}
|
||||
public void Load_by_ids(Cancelable cancelable, List_adp list, int bgn, int end) {
|
||||
int prv_fil_idx = -1;
|
||||
byte[] id_bry = new byte[5];
|
||||
int len = end - bgn;
|
||||
Gfo_usr_dlg_fmt msg_wtr = Gfo_usr_dlg_fmt.fmt_(GRP_KEY, "search2_ids", "resolving ids: ~{0} of ~{1} (~{2})", len, 10f);
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (cancelable.Canceled()) return;
|
||||
Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i + bgn);
|
||||
Base85_.Set_bry(itm.Id(), id_bry, 0, 5);
|
||||
int cur_fil_idx = this.Find_file_idx_by_site(Xotdb_dir_info_.Tid_id, id_bry);
|
||||
if (cur_fil_idx != prv_fil_idx) {
|
||||
if (!this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_id, cur_fil_idx)) continue; // file not found; ignore
|
||||
prv_fil_idx = cur_fil_idx;
|
||||
}
|
||||
if (!this.Load_by_id(tmp_page, tmp_xdat_file, id_bry)) continue; // id not found in file; ignore
|
||||
itm.Ns_id_(tmp_page.Ns_id()).Ttl_page_db_(tmp_page.Ttl_page_db());
|
||||
msg_wtr.Write_prog_cur(i, wiki.Appe().Usr_dlg());
|
||||
}
|
||||
}
|
||||
public void Load_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
|
||||
Xow_ns ns = wiki.Ns_mgr().Ns_main();
|
||||
int search_len = search.length;
|
||||
byte match_tid = Srch_special_page.Match_tid_all;
|
||||
if (search_len > 0 && search[search_len - 1] == Byte_ascii.Star) {
|
||||
search = Bry_.Mid(search, 0, search_len - 1);
|
||||
match_tid = Srch_special_page.Match_tid_bgn;
|
||||
}
|
||||
int bgn_idx = this.Find_file_idx_by_ns(Xotdb_dir_info_.Tid_search_ttl, ns, search);
|
||||
if (bgn_idx == Xodb_save_mgr_txt.File_idx_unknown) return;
|
||||
if (match_tid == Srch_special_page.Match_tid_all) {
|
||||
if (!this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_search_ttl, ns, bgn_idx)) return;
|
||||
tmp_xdat_file.Find(tmp_xdat_itm, search, 0, Byte_ascii.Pipe, true);
|
||||
if (tmp_xdat_itm.Missing()) return;
|
||||
Find_ttls__add_itms(rv, tmp_xdat_file, tmp_xdat_itm);
|
||||
}
|
||||
else {
|
||||
byte[] end_ttl = Bry_.Increment_last(Bry_.Copy(search));
|
||||
int end_idx = this.Find_file_idx_by_ns(Xotdb_dir_info_.Tid_search_ttl, ns, end_ttl);
|
||||
for (int i = bgn_idx; i <= end_idx; i++) {
|
||||
if (cancelable.Canceled()) return;
|
||||
this.Load_xdat_file(cancelable, tmp_xdat_file, Xotdb_dir_info_.Tid_search_ttl, ns, i);
|
||||
if (cancelable.Canceled()) return;
|
||||
int itm_bgn_idx = 0;
|
||||
if (i == bgn_idx) {
|
||||
tmp_xdat_file.Find(tmp_xdat_itm, search, 0, Byte_ascii.Pipe, false);
|
||||
itm_bgn_idx = tmp_xdat_itm.Itm_idx();
|
||||
}
|
||||
int itm_end_idx = tmp_xdat_file.Count();
|
||||
if (i == end_idx) {
|
||||
tmp_xdat_file.Find(tmp_xdat_itm, end_ttl, 0, Byte_ascii.Pipe, false);
|
||||
itm_end_idx = tmp_xdat_itm.Itm_idx();
|
||||
}
|
||||
for (int j = itm_bgn_idx; j < itm_end_idx; j++) {
|
||||
tmp_xdat_file.GetAt(tmp_xdat_itm, j);
|
||||
Find_ttls__add_itms(rv, tmp_xdat_file, tmp_xdat_itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Find_ttls__add_itms(List_adp rv, Xob_xdat_file rdr, Xob_xdat_itm xdat_itm) {
|
||||
byte[] raw = rdr.Src();
|
||||
int itm_bgn = xdat_itm.Itm_bgn(), itm_end = xdat_itm.Itm_end();
|
||||
int pos = Bry_find_.Find_fwd(raw, Byte_ascii.Pipe, itm_bgn, raw.length);
|
||||
if (pos == Bry_find_.Not_found) throw wiki.Appe().Usr_dlg().Fail_many(GRP_KEY, "invalid_search_file", "search file is invalid");
|
||||
pos += Byte_ascii.Len_1; // pipe len
|
||||
|
||||
while (pos < itm_end) {
|
||||
int page_id = Base85_.To_int_by_bry(raw, pos, pos + 4);
|
||||
pos += 6; // 5 + 1 for semic;
|
||||
int page_len = Base85_.To_int_by_bry(raw, pos, pos + 4);
|
||||
rv.Add(Xowd_page_itm.new_srch(page_id, page_len));
|
||||
pos += 6; // 5 + 1 for pipe
|
||||
// if (match.Itms_len() == max_results) break;
|
||||
}
|
||||
}
|
||||
public boolean Load_by_id(Xowd_page_itm page, int id) {Base85_.Set_bry(id, tmp_id_bry, 0, 5); return Load_by_id(page, tmp_id_bry);} private byte[] tmp_id_bry = new byte[5];
|
||||
boolean Load_by_id(Xowd_page_itm page, byte[] id_bry) {
|
||||
if (!Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_id, id_bry, true)) return false;;
|
||||
Xotdb_page_itm_.Txt_id_load(page, tmp_xdat_itm.Itm_bry());
|
||||
return true;
|
||||
}
|
||||
boolean Load_by_id(Xowd_page_itm page, Xob_xdat_file xdat_file, byte[] id_bry) {
|
||||
xdat_file.Find(tmp_xdat_itm, id_bry, 0, Byte_ascii.Pipe, true);
|
||||
if (tmp_xdat_itm.Missing()) return false;
|
||||
Xotdb_page_itm_.Txt_id_load(page, tmp_xdat_itm.Itm_bry());
|
||||
return true;
|
||||
}
|
||||
private boolean Load_xdat_itm(Xob_xdat_itm xdat_itm, byte regy_tid, byte[] key, boolean exact) {return Load_xdat_itm(xdat_itm, null, regy_tid, key, 0, Byte_ascii.Pipe, exact);}
|
||||
private boolean Load_xdat_itm(Xob_xdat_itm xdat_itm, Xow_ns ns, byte regy_tid, byte[] key, int parse_bgn, byte parse_dlm, boolean exact) {
|
||||
// get regy
|
||||
Xowd_regy_mgr regy = null;
|
||||
if (ns == null)
|
||||
regy = Get_regy_by_site(regy_tid);
|
||||
else {
|
||||
regy = Get_regy_by_ns(ns);
|
||||
if (regy == null) return false;
|
||||
}
|
||||
// find file
|
||||
int fil_idx = regy.Files_find(key);
|
||||
if (fil_idx == Xowd_regy_mgr.Regy_null) return false; // NOTE: must check for -1, not 0; else defect in which entries in file 0 are ignored; DATE:2013-04-11
|
||||
// load file
|
||||
Io_url fil = ns == null ? fsys_mgr.Url_site_fil(regy_tid, fil_idx) : fsys_mgr.Url_ns_fil(regy_tid, ns.Id(), fil_idx);
|
||||
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, fil);
|
||||
// find itm by key
|
||||
tmp_xdat_file.Find(xdat_itm, key, parse_bgn, parse_dlm, exact);
|
||||
return !xdat_itm.Missing();
|
||||
} private final Int_obj_ref tmp_len = Int_obj_ref.New_zero();
|
||||
public boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, byte regy_tid, int fil_idx) {return Load_xdat_file(cancelable, xdat_file, regy_tid, null, fil_idx);}
|
||||
boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, byte regy_tid, Xow_ns ns, int fil_idx) {
|
||||
Io_url fil = ns == null ? fsys_mgr.Url_site_fil(regy_tid, fil_idx) : fsys_mgr.Url_ns_fil(regy_tid, ns.Id(), fil_idx);
|
||||
return Load_xdat_file(cancelable, xdat_file, fil);
|
||||
}
|
||||
public boolean Load_xdat_file(Cancelable cancelable, Xob_xdat_file xdat_file, Io_url url) {
|
||||
boolean rv = false;
|
||||
synchronized (thread_lock) {
|
||||
if (cancelable.Canceled()) return false;
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
byte[] tmp_bry = tmp_bfr.Bfr();
|
||||
if (cancelable.Canceled()) return false;
|
||||
tmp_bry = Io_mgr.Instance.LoadFilBry_reuse(url, tmp_bry, tmp_len);
|
||||
if (cancelable.Canceled()) return false;
|
||||
if (tmp_bry.length == 0)
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "file.empty", "hive file is empty: ~{0}", url.Raw());
|
||||
else {
|
||||
int src_len = tmp_len.Val();
|
||||
xdat_file.Clear().Parse(tmp_bry, src_len, url);
|
||||
xdat_file.Src_len_(src_len);
|
||||
rv = true;
|
||||
}
|
||||
if (cancelable.Canceled()) return false;
|
||||
tmp_bfr.Clear_and_rls();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
int Find_file_idx_by_ns(byte regy_tid, Xow_ns ns, byte[] key) {
|
||||
Xowd_regy_mgr regy = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), regy_tid));
|
||||
return regy.Files_find(key);
|
||||
}
|
||||
public int Find_file_idx_by_site(byte regy_tid, byte[] key) {
|
||||
Xowd_regy_mgr regy = site_regys[regy_tid];
|
||||
if (regy == null) {
|
||||
regy = new Xowd_regy_mgr(fsys_mgr.Url_site_reg(regy_tid));
|
||||
site_regys[regy_tid] = regy;
|
||||
}
|
||||
return regy.Files_find(key);
|
||||
}
|
||||
public void Clear() {
|
||||
int len = ns_regys.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
ns_regys[i] = null;
|
||||
len = site_regys.length;
|
||||
for (int i = 0; i < len; i++)
|
||||
site_regys[i] = null;
|
||||
}
|
||||
public byte[] Find_random_ttl(Xow_ns ns) {
|
||||
Xowd_regy_mgr regy_mgr = this.Get_regy_by_ns(ns);
|
||||
Int_obj_ref count = Int_obj_ref.New_zero();
|
||||
Xob_random_itm[] files = Build_random_itms(regy_mgr, count);
|
||||
int random_idx = RandomAdp_.new_().Next(count.Val() - 1); // get a random idx; -1 since count is super 1 (EX: count of 1 mil; random_idx of 0 - 999,999)
|
||||
int file_idx = Xowd_regy_mgr_.FindSlot(Xob_random_itm_comparer.Instance, files, new Xob_random_itm(-1, random_idx, -1));
|
||||
Io_url file_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_ttl, ns.Id(), file_idx);
|
||||
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, file_url);
|
||||
Xob_random_itm file = files[file_idx];
|
||||
tmp_xdat_file.GetAt(tmp_xdat_itm, random_idx - file.Bgn()); // get nth row; EX: random_idx=120; .Bgn=103 -> get 17th
|
||||
Xowd_page_itm page = Xotdb_page_itm_.Txt_ttl_load(tmp_xdat_itm.Itm_bry());
|
||||
return page.Ttl_page_db();
|
||||
}
|
||||
private static Xob_random_itm[] Build_random_itms(Xowd_regy_mgr mgr, Int_obj_ref count) {
|
||||
// convert regy to list of random_itms (similar to regy_itms, but has integer bgn / end; EX: [0]:0,50; [1]:51-102; [2]:103-130)
|
||||
Xowd_hive_regy_itm[] files_ary = mgr.Files_ary();
|
||||
int len = files_ary.length;
|
||||
Xob_random_itm[] rv = new Xob_random_itm[len];
|
||||
int tmp_count = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_hive_regy_itm file = files_ary[i];
|
||||
rv[i] = new Xob_random_itm(i, tmp_count, file.Count());
|
||||
tmp_count += file.Count();
|
||||
}
|
||||
count.Val_(tmp_count);
|
||||
return rv;
|
||||
}
|
||||
public static boolean Load_page_or_false(Xowd_page_itm page, Xob_xdat_itm xdat, int ns_id) {
|
||||
byte[] src = xdat.Src(); int itm_end = xdat.Itm_end();
|
||||
int bgn = xdat.Itm_bgn();
|
||||
int timestamp = Base85_.To_int_by_bry(src, bgn + 6 , bgn + 10);
|
||||
int ttl_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, bgn + 12, itm_end);
|
||||
if (ttl_end == -1) return false;
|
||||
byte[] ttl = Bry_.Mid (src, bgn + 12 , ttl_end);
|
||||
byte[] text = Bry_.Mid (src, ttl_end + 1 , itm_end - 1);
|
||||
page.Init_by_tdb(-1, -1, xdat.Itm_idx(), Bool_.N, text.length, ns_id, ttl);
|
||||
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
|
||||
page.Text_(text);
|
||||
return true;
|
||||
}
|
||||
private void Load_page_parse(Xowd_page_itm page, byte[] src, int src_len, int row_bgn, int row_end, boolean timestamp_enabled) { // \n\tdate5\tpage_title\tpage_text
|
||||
int timestamp_bgn = row_bgn + 5 + 1;
|
||||
int timestamp_end = timestamp_bgn + 5;
|
||||
if (timestamp_enabled) {
|
||||
int timestamp = Base85_.To_int_by_bry(src, timestamp_bgn, timestamp_end - 1);
|
||||
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
|
||||
}
|
||||
int name_bgn = timestamp_end + 1;
|
||||
int name_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, name_bgn, src_len);
|
||||
page.Text_(Bry_.Mid(src, name_end + 1, row_end - 1)); // +1 to skip dlm
|
||||
}
|
||||
Xowd_regy_mgr Get_regy_by_site(byte regy_tid) {
|
||||
Xowd_regy_mgr rv = site_regys[regy_tid];
|
||||
if (rv == null) {
|
||||
rv = new Xowd_regy_mgr(fsys_mgr.Url_site_reg(regy_tid));
|
||||
site_regys[regy_tid] = rv;
|
||||
}
|
||||
return rv;
|
||||
} private Xowd_regy_mgr[] site_regys = new Xowd_regy_mgr[Xotdb_dir_info_.Regy_tid_max];
|
||||
Xowd_regy_mgr Get_regy_by_ns(Xow_ns ns) {
|
||||
int ns_ord = ns.Ord();
|
||||
Xowd_regy_mgr rv = ns_regys[ns_ord];
|
||||
if (rv == null) {
|
||||
Io_url file = fsys_mgr.Url_ns_reg(ns.Num_str(), Xotdb_dir_info_.Tid_ttl);
|
||||
if (!Io_mgr.Instance.ExistsFil(file)) return null;
|
||||
rv = new Xowd_regy_mgr(file);
|
||||
ns_regys[ns_ord] = rv;
|
||||
}
|
||||
return rv;
|
||||
} private Xowd_regy_mgr[] ns_regys = new Xowd_regy_mgr[Xow_ns_mgr_.Ordinal_max];
|
||||
private Xowd_page_itm tmp_rslt_nxt = new Xowd_page_itm(), tmp_rslt_prv = new Xowd_page_itm(); private Int_obj_ref tmp_rslt_count = Int_obj_ref.New_zero();
|
||||
public void Load_ttls_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
|
||||
this.Load_ttls_for_all_pages(cancelable, rslt_list, tmp_rslt_nxt, tmp_rslt_prv, tmp_rslt_count, ns, key, max_results, min_page_len, browse_len, include_redirects, fetch_prv_item);
|
||||
}
|
||||
public void Load_ttls_for_all_pages(Cancelable cancelable, List_adp 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) {
|
||||
byte dir_tid = Xotdb_dir_info_.Tid_ttl;
|
||||
Xob_xdat_file cur_xdat_file = new Xob_xdat_file();
|
||||
Xob_xdat_itm cur_xdat_itm = new Xob_xdat_itm();
|
||||
Xowd_regy_mgr regy = new Xowd_regy_mgr(fsys_mgr.Url_ns_reg(ns.Num_str(), dir_tid));
|
||||
int fil_idx = regy.Files_find(key); if (fil_idx == Xowd_regy_mgr.Regy_null) return;
|
||||
if (!this.Load_xdat_file(Cancelable_.Never, cur_xdat_file, dir_tid, ns, fil_idx)) return;
|
||||
cur_xdat_file.Find(cur_xdat_itm, key, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Tab, false);
|
||||
int itm_idx = cur_xdat_itm.Itm_idx();
|
||||
if (itm_idx == -1) itm_idx = 0; // nothing found; return;
|
||||
Special_allpages_query_fwd(rslt_list, rslt_nxt, rslt_count , dir_tid, ns, include_redirects, browse_len, fil_idx, itm_idx , cur_xdat_file, cur_xdat_itm, regy);
|
||||
Special_allpages_query_bwd(rslt_list, rslt_prv , dir_tid, ns, include_redirects, browse_len, fil_idx, itm_idx - 1, cur_xdat_file, cur_xdat_itm);
|
||||
}
|
||||
private void Special_allpages_query_fwd(List_adp rslt_list, Xowd_page_itm rslt_nxt, Int_obj_ref rslt_count, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm, Xowd_regy_mgr regy) {
|
||||
int count = 0; ++total;
|
||||
boolean loop = true;
|
||||
int regy_len = regy.Files_ary().length;
|
||||
int rslt_list_len = rslt_count.Val();
|
||||
Xowd_page_itm nxt_itm = null;
|
||||
while (loop) {
|
||||
if (fil_idx == regy_len) break;
|
||||
if (xdat_file == null) {
|
||||
xdat_file = new Xob_xdat_file();
|
||||
this.Load_xdat_file(Cancelable_.Never, xdat_file, dir_tid, ns, fil_idx);
|
||||
row_idx = 0;
|
||||
}
|
||||
int rows_len = xdat_file.Count();
|
||||
for (; row_idx < rows_len; row_idx++) {
|
||||
xdat_file.GetAt(xdat_itm, row_idx);
|
||||
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
if (!include_redirects && ttl_itm.Redirected()) continue;
|
||||
++count;
|
||||
nxt_itm = ttl_itm;
|
||||
if (count == total) {
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
rslt_list.Add(ttl_itm);
|
||||
++rslt_list_len;
|
||||
}
|
||||
}
|
||||
xdat_file = null;
|
||||
++fil_idx;
|
||||
}
|
||||
rslt_count.Val_(rslt_list_len);
|
||||
if (rslt_nxt != null)
|
||||
rslt_nxt.Copy(nxt_itm);
|
||||
}
|
||||
private void Special_allpages_query_bwd(List_adp rslt_list, Xowd_page_itm rslt_prv, byte dir_tid, Xow_ns ns, boolean include_redirects, int total, int fil_idx, int row_idx, Xob_xdat_file xdat_file, Xob_xdat_itm xdat_itm) {
|
||||
if (row_idx < 0) {
|
||||
--fil_idx;
|
||||
row_idx = -1;
|
||||
}
|
||||
int count = 0;
|
||||
boolean loop = true;
|
||||
Xowd_page_itm prv_itm = null;
|
||||
while (loop) {
|
||||
if (fil_idx == -1) break;
|
||||
if (xdat_file == null) {
|
||||
xdat_file = new Xob_xdat_file();
|
||||
this.Load_xdat_file(Cancelable_.Never, xdat_file, dir_tid, ns, fil_idx);
|
||||
row_idx = -1;
|
||||
}
|
||||
if (row_idx == -1)
|
||||
row_idx = xdat_file.Count() - 1;
|
||||
for (; row_idx > -1; row_idx--) {
|
||||
xdat_file.GetAt(xdat_itm, row_idx);
|
||||
Xowd_page_itm ttl_itm = Xotdb_page_itm_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
|
||||
if (!include_redirects && ttl_itm.Redirected()) continue;
|
||||
// list.Add(ttl_itm);
|
||||
++count;
|
||||
prv_itm = ttl_itm;
|
||||
if (count == total) {
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// rslt_list_ttls[rslt_list_len++] = ttl_itm;
|
||||
}
|
||||
}
|
||||
xdat_file = null;
|
||||
--fil_idx;
|
||||
}
|
||||
if (prv_itm == null && rslt_list.Count() > 0) {
|
||||
prv_itm = (Xowd_page_itm)rslt_list.Get_at(0);
|
||||
}
|
||||
if (rslt_prv != null)
|
||||
rslt_prv.Copy(prv_itm);
|
||||
}
|
||||
public byte[] Load_qid(byte[] wiki_alias, byte[] ns_num, byte[] ttl) {
|
||||
String xwiki_key = String_.new_a7(wiki_alias);
|
||||
if (qids_root == null)
|
||||
qids_root = wiki.Appe().Wiki_mgr().Wdata_mgr().Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "qid");
|
||||
Xob_xdat_itm qid_itm = Load_xdat_itm_by_dir(qids_root.GenSubDir_nest(xwiki_key, String_.new_a7(ns_num)), ttl); if (qid_itm == null) return null;
|
||||
return Bry_.Mid(qid_itm.Src(), qid_itm.Itm_bgn() + ttl.length + 1, qid_itm.Itm_end()); // extract qid; note that all itms have format of "ttl|qid"
|
||||
} Io_url qids_root;
|
||||
public int Load_pid(byte[] lang_key, byte[] pid_name) {
|
||||
if (pids_root == null)
|
||||
pids_root = wiki.Appe().Wiki_mgr().Wdata_mgr().Wdata_wiki().Tdb_fsys_mgr().Site_dir().GenSubDir_nest("data", "pid");
|
||||
Xob_xdat_itm pid_itm = Load_xdat_itm_by_dir(pids_root.GenSubDir(String_.new_u8(lang_key)), pid_name); if (pid_itm == null) return gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Pid_null;
|
||||
return Bry_.To_int_or(pid_itm.Src(), pid_itm.Itm_bgn() + pid_name.length + 1 + 1, pid_itm.Itm_end(), gplx.xowa.xtns.wbases.Wdata_wiki_mgr.Pid_null); // extract pid; note that all itms have format of "ttl|pid"; +1=skip pipe; +1 skip p
|
||||
} Io_url pids_root;
|
||||
Xob_xdat_itm Load_xdat_itm_by_dir(Io_url dir, byte[] ttl) {
|
||||
Xoa_hive_mgr hive_mgr = wiki.Appe().Hive_mgr();
|
||||
int fil_idx = hive_mgr.Find_fil(dir, ttl); if (fil_idx == Xowd_regy_mgr.Regy_null) return null; // sub_dir not found; EX: commonswiki if qid; fr if pid;
|
||||
Xob_xdat_file rdr = hive_mgr.Get_rdr(dir, Xotdb_dir_info_.Bry_xdat, fil_idx);
|
||||
rdr.Find(tmp_xdat_itm, ttl, 0, Byte_ascii.Pipe, true);
|
||||
return tmp_xdat_itm.Found_exact() ? tmp_xdat_itm : null;
|
||||
}
|
||||
public Xodb_page_rdr Get_page_rdr(Xowe_wiki wiki) {return new Xodb_page_rdr__tdb(wiki);}
|
||||
static final String GRP_KEY = "xowa.wiki.db.load";
|
||||
}
|
||||
class Xob_random_itm {
|
||||
public int Idx() {return idx;} private int idx;
|
||||
public int Bgn() {return bgn;} private int bgn;
|
||||
public int End() {return bgn + len;}
|
||||
public int Len() {return len;} private int len;
|
||||
public Xob_random_itm(int idx, int bgn, int len) {this.idx = idx; this.bgn = bgn; this.len = len;}
|
||||
}
|
||||
class Xob_random_itm_comparer implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
return Int_.Compare(((Xob_random_itm)lhsObj).End(), ((Xob_random_itm)rhsObj).End());
|
||||
}
|
||||
public static final Xob_random_itm_comparer Instance = new Xob_random_itm_comparer(); Xob_random_itm_comparer() {}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.htmls.core.*;
|
||||
public interface Xodb_mgr extends Gfo_invk {
|
||||
byte Tid();
|
||||
String Tid_name();
|
||||
byte Category_version();
|
||||
Xodb_load_mgr Load_mgr();
|
||||
Xodb_save_mgr Save_mgr();
|
||||
DateAdp Dump_date_query(); // used by maint_mgr
|
||||
}
|
||||
|
||||
@@ -13,48 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.dbs.engines.sqlite.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.htmls.core.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xodb_mgr_sql implements Xodb_mgr, Gfo_invk {
|
||||
public Xodb_mgr_sql(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.core_data_mgr = new Xow_db_mgr(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());
|
||||
this.load_mgr = new Xodb_load_mgr_sql(this);
|
||||
this.save_mgr = new Xodb_save_mgr_sql(this);
|
||||
}
|
||||
public byte Tid() {return Tid_sql;} public String Tid_name() {return "sqlite3";} public static final byte Tid_sql = 1;
|
||||
public Xow_db_mgr Core_data_mgr() {return core_data_mgr;} private final Xow_db_mgr core_data_mgr;
|
||||
public Xowe_wiki Wiki() {return wiki;} private final Xowe_wiki wiki;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private final Xodb_load_mgr_sql load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private final Xodb_save_mgr_sql save_mgr;
|
||||
public byte Category_version() {return category_version;} private byte category_version = Xoa_ctg_mgr.Version_null;
|
||||
public DateAdp Dump_date_query() {
|
||||
DateAdp rv = wiki.Props().Modified_latest(); if (rv != null) return rv;
|
||||
Io_url url = core_data_mgr.Db__core().Url();
|
||||
return Io_mgr.Instance.QueryFil(url).ModifiedTime();
|
||||
}
|
||||
public void Category_version_update(boolean version_is_1) {
|
||||
String grp = Xowd_cfg_key_.Grp__wiki_init;
|
||||
String key = Xoa_gfs_wtr_.Write_func_chain(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_category_version);
|
||||
core_data_mgr.Tbl__cfg().Delete_val(grp, key);// always delete ctg version
|
||||
category_version = version_is_1 ? Xoa_ctg_mgr.Version_1 : Xoa_ctg_mgr.Version_2;
|
||||
core_data_mgr.Tbl__cfg().Insert_byte(grp, key, category_version);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_data_storage_format)) return Io_stream_tid_.Obsolete_to_str(core_data_mgr.Props().Zip_tid_text());
|
||||
else if (ctx.Match(k, Invk_data_storage_format_)) {} // SERIALIZED:000.sqlite3|xowa_cfg; ignore; read from Xow_db_props
|
||||
else if (ctx.Match(k, Invk_category_version)) return category_version;
|
||||
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
|
||||
else if (ctx.Match(k, Invk_search_version)) {return 1;} // return this.Search_version(); // REMOVED: DATE:2016-02-26
|
||||
else if (ctx.Match(k, Invk_tid_name)) return this.Tid_name();
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_" // SERIALIZED:000.sqlite3|xowa_cfg
|
||||
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_" // SERIALIZED:000.sqlite3|xowa_cfg
|
||||
, Invk_search_version = "search_version"
|
||||
, Invk_tid_name = "tid_name"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,49 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.htmls.core.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.pages.*;
|
||||
public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public Xodb_mgr_txt(Xowe_wiki wiki, Xow_page_mgr data_mgr) {
|
||||
this.wiki = wiki;
|
||||
load_mgr = new Xodb_load_mgr_txt(wiki);
|
||||
save_mgr = new Xodb_save_mgr_txt(wiki, load_mgr);
|
||||
} private Xowe_wiki wiki;
|
||||
public byte Tid() {return Tid_txt;} public static final byte Tid_txt = 0;
|
||||
public String Tid_name() {return "xdat";}
|
||||
public byte Data_storage_format() {return data_storage_format;} public void Data_storage_format_(byte v) {data_storage_format = v;} private byte data_storage_format = gplx.core.ios.streams.Io_stream_tid_.Tid__raw;
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
|
||||
public DateAdp Dump_date_query() {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 0);
|
||||
return Io_mgr.Instance.QueryFil(url).ModifiedTime();
|
||||
}
|
||||
public byte Category_version() {
|
||||
if (category_version == Xoa_ctg_mgr.Version_null) {
|
||||
if (Io_mgr.Instance.ExistsDir(wiki.Tdb_fsys_mgr().Url_site_dir(Xotdb_dir_info_.Tid_category2_link)))
|
||||
category_version = Xoa_ctg_mgr.Version_2;
|
||||
else
|
||||
category_version = Xoa_ctg_mgr.Version_1;
|
||||
}
|
||||
return category_version;
|
||||
} byte category_version = Xoa_ctg_mgr.Version_null;
|
||||
public byte Search_version() {return gplx.xowa.addons.wikis.searchs.specials.Srch_special_page.Version_2;}
|
||||
public void Search_version_refresh() {throw Err_.new_unimplemented();}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_data_storage_format)) return Io_stream_tid_.Obsolete_to_str(data_storage_format);
|
||||
else if (ctx.Match(k, Invk_data_storage_format_)) data_storage_format = Io_stream_tid_.Obsolete_to_tid(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_category_version)) return this.Category_version();
|
||||
else if (ctx.Match(k, Invk_category_version_)) category_version = m.ReadByte("v");
|
||||
else if (ctx.Match(k, Invk_search_version)) return this.Search_version();
|
||||
else if (ctx.Match(k, Invk_tid_name)) return Tid_name();
|
||||
return this;
|
||||
}
|
||||
public static final String
|
||||
Invk_data_storage_format = "data_storage_format", Invk_data_storage_format_ = "data_storage_format_"
|
||||
, Invk_category_version = "category_version", Invk_category_version_ = "category_version_"
|
||||
, Invk_search_version = "search_version"
|
||||
, Invk_tid_name = "tid_name"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public interface Xodb_page_rdr {
|
||||
boolean Move_next();
|
||||
boolean Read(Xowd_page_itm page);
|
||||
void Rls();
|
||||
}
|
||||
|
||||
@@ -13,26 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
class Xodb_page_rdr__sql implements Xodb_page_rdr {
|
||||
private final Xow_db_mgr db_mgr;
|
||||
private final Xowd_page_tbl page_tbl; private final Db_rdr rdr;
|
||||
public Xodb_page_rdr__sql(Xowe_wiki wiki) {
|
||||
this.db_mgr = wiki.Data__core_mgr();
|
||||
this.page_tbl = db_mgr.Tbl__page();
|
||||
this.rdr = page_tbl.Select_all__id__ttl();
|
||||
}
|
||||
public boolean Move_next() {return rdr.Move_next();}
|
||||
public boolean Read(Xowd_page_itm page) {
|
||||
page_tbl.Read_page__all(page, rdr);
|
||||
Xowd_text_tbl text_tbl = db_mgr.Dbs__get_by_id_or_fail(page.Text_db_id()).Tbl__text();
|
||||
page.Text_(text_tbl.Select(page.Id()));
|
||||
return true;
|
||||
}
|
||||
public void Rls() {
|
||||
rdr.Rls();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,74 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.ios.*; import gplx.core.ios.streams.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
public class Xodb_page_rdr__tdb implements Xodb_page_rdr {
|
||||
private final Xow_ns_mgr ns_mgr; private final Xotdb_fsys_mgr fsys_mgr;
|
||||
private int cur_ns_ord = -1; private Xow_ns cur_ns; private Io_url[] cur_file_ary; private Io_url cur_file; private int cur_file_idx = -1;
|
||||
private final Xob_xdat_file cur_xdat_file = new Xob_xdat_file(); private int cur_xdat_len, cur_xdat_idx; private final Xob_xdat_itm cur_xdat_itm = new Xob_xdat_itm();
|
||||
private int page_id = 0;
|
||||
public Xodb_page_rdr__tdb(Xowe_wiki wiki) {
|
||||
this.ns_mgr = wiki.Ns_mgr(); this.fsys_mgr = wiki.Tdb_fsys_mgr();
|
||||
}
|
||||
public boolean Move_next() {
|
||||
while (true) {
|
||||
if (cur_ns == null) {
|
||||
++this.cur_ns_ord;
|
||||
if (cur_ns_ord >= ns_mgr.Ords_len()) return false; // no more ns; return false;
|
||||
this.cur_ns = ns_mgr.Ords_get_at(cur_ns_ord);
|
||||
this.cur_file_ary = Get_page_url_ary(cur_ns);
|
||||
if (cur_file_ary == null) { // ns doesn't have files; try next ns;
|
||||
cur_ns = null;
|
||||
continue;
|
||||
}
|
||||
this.cur_file_idx = -1;
|
||||
this.cur_file = null;
|
||||
}
|
||||
if (cur_file == null) {
|
||||
++this.cur_file_idx;
|
||||
if (cur_file_idx == cur_file_ary.length) { // no more files in ns; try next ns;
|
||||
cur_ns = null;
|
||||
continue;
|
||||
}
|
||||
this.cur_file = cur_file_ary[cur_file_idx];
|
||||
byte[] bry = Io_mgr.Instance.LoadFilBry(cur_file);
|
||||
cur_xdat_file.Clear().Parse(bry, bry.length, cur_file);
|
||||
this.cur_xdat_len = cur_xdat_file.Count();
|
||||
this.cur_xdat_idx = -1;
|
||||
}
|
||||
++this.cur_xdat_idx;
|
||||
if (cur_xdat_idx == cur_xdat_len) { // no more rows in file; try next file
|
||||
cur_file = null;
|
||||
continue;
|
||||
}
|
||||
cur_xdat_file.GetAt(cur_xdat_itm, cur_xdat_idx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public boolean Read(Xowd_page_itm page) {
|
||||
boolean rv = Xodb_load_mgr_txt.Load_page_or_false(page, cur_xdat_itm, cur_ns.Id());
|
||||
if (!rv)
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "page_rdr.tdb; unable to read page; ns=~{0}, file=~{1} itm_idx=~{2}", cur_ns.Id(), cur_file.Raw(), cur_xdat_idx);
|
||||
// wiki.Db_mgr().Load_mgr().Load_by_ttl(page, cur_ns, page.Ttl_page_db());
|
||||
page.Id_(++page_id);
|
||||
return rv;
|
||||
}
|
||||
public void Rls() {}
|
||||
private Io_url[] Get_page_url_ary(Xow_ns ns) {
|
||||
Io_url reg_url = fsys_mgr.Url_ns_reg(ns.Num_str(), Xotdb_dir_info_.Tid_ttl);
|
||||
if (!Io_mgr.Instance.ExistsFil(reg_url)) return null;
|
||||
Xowd_regy_mgr reg_mgr = new Xowd_regy_mgr(reg_url);
|
||||
Xowd_hive_regy_itm[] file_ary = reg_mgr.Files_ary();
|
||||
int len = file_ary.length;
|
||||
Io_url[] rv = new Io_url[len];
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int fil_idx = file_ary[i].Idx();
|
||||
rv[i] = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns.Id(), fil_idx);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public interface Xodb_save_mgr {
|
||||
boolean Create_enabled(); void Create_enabled_(boolean v);
|
||||
boolean Update_modified_on_enabled(); void Update_modified_on_enabled_(boolean v);
|
||||
int Page_id_next(); void Page_id_next_(int v);
|
||||
int Data_create(Xoa_ttl ttl, byte[] text);
|
||||
void Data_update(Xoae_page page, byte[] text);
|
||||
void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl);
|
||||
void Clear();
|
||||
}
|
||||
|
||||
@@ -13,66 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
public class Xodb_save_mgr_sql implements Xodb_save_mgr {
|
||||
private final Xodb_mgr_sql db_mgr;
|
||||
public Xodb_save_mgr_sql(Xodb_mgr_sql db_mgr) {this.db_mgr = db_mgr;}
|
||||
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
|
||||
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
|
||||
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next;
|
||||
public int Data_create(Xoa_ttl ttl, byte[] text_raw) {
|
||||
int ns_id = ttl.Ns().Id();
|
||||
Xow_db_file db_file = db_mgr.Core_data_mgr().Db__core();
|
||||
int ns_count = db_file.Tbl__ns().Select_ns_count(ns_id) + 1;
|
||||
int page_id = db_file.Tbl__cfg().Select_int_or(Xowd_cfg_key_.Grp__db, Xowd_cfg_key_.Key__wiki__page__id_next, -1);
|
||||
if (page_id == -1) { // HACK: changed for tests; was dbs.qrys.Db_qry_sql.rdr_("SELECT (Max(page_id) + 1) AS max_page_id FROM page;")
|
||||
Db_rdr rdr = db_mgr.Core_data_mgr().Tbl__page().Conn().Stmt_select(db_file.Tbl__page().Tbl_name(), String_.Ary(db_file.Tbl__page().Fld_page_id()), Dbmeta_fld_itm.Str_ary_empty).Exec_select__rls_auto();
|
||||
try {
|
||||
int max_page_id = -1;
|
||||
while (rdr.Move_next()) {
|
||||
int cur_page_id = rdr.Read_int("page_id");
|
||||
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().Upsert_int(Xowd_cfg_key_.Grp__db, Xowd_cfg_key_.Key__wiki__page__id_next, page_id + 1);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
Xow_db_mgr fsys_mgr = db_mgr.Core_data_mgr();
|
||||
Xow_db_file page_text_db = fsys_mgr.Db__text();
|
||||
if (page_text_db == null) page_text_db = fsys_mgr.Db__core(); // HACK: needed for create new wiki DATE:2016-10-29
|
||||
Xowd_text_tbl page_text_tbl = page_text_db.Tbl__text();
|
||||
byte[] text_zip = page_text_tbl.Zip(text_raw);
|
||||
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text_raw, text_raw.length);
|
||||
Xowd_page_tbl page_core_tbl = db_mgr.Core_data_mgr().Tbl__page();
|
||||
page_core_tbl.Insert_bgn();
|
||||
page_text_tbl.Insert_bgn();
|
||||
try {
|
||||
db_mgr.Core_data_mgr().Create_page(page_core_tbl, page_text_tbl, page_id, ns_id, ttl.Page_db(), redirect, Datetime_now.Get(), 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(Xowd_cfg_key_.Grp__db, Xowd_cfg_key_.Key__wiki__page__id_next, page_id + 1);
|
||||
} finally {
|
||||
page_core_tbl.Insert_end();
|
||||
page_text_tbl.Insert_end();
|
||||
}
|
||||
return page_id;
|
||||
}
|
||||
public void Data_update(Xoae_page page, byte[] text_raw) {
|
||||
boolean redirect = db_mgr.Wiki().Redirect_mgr().Is_redirect(text_raw, text_raw.length);
|
||||
DateAdp modified = update_modified_on_enabled ? Datetime_now.Get() : page.Db().Page().Modified_on();
|
||||
int page_id = page.Db().Page().Id();
|
||||
db_mgr.Core_data_mgr().Tbl__page().Update__redirect__modified(page_id, redirect, modified);
|
||||
Xowd_page_itm db_page = new Xowd_page_itm();
|
||||
db_mgr.Load_mgr().Load_by_id(db_page, page_id);
|
||||
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_by_id_or_fail(db_page.Text_db_id()).Tbl__text();
|
||||
text_tbl.Update(page_id, text_raw);
|
||||
// int html_db_id = db_page.Html_db_id();
|
||||
// if (html_db_id != -1)
|
||||
// db_mgr.Core_data_mgr().Tbl__page().Update__html_db_id(page_id, -1); // zap html_db_id so that next load will repopulate it
|
||||
}
|
||||
public void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl) {
|
||||
db_mgr.Core_data_mgr().Tbl__page().Update__ns__ttl(page.Db().Page().Id(), trg_ns, trg_ttl);
|
||||
}
|
||||
public void Clear() {}
|
||||
}
|
||||
|
||||
@@ -13,109 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.tdbs.hives.*; import gplx.xowa.wikis.tdbs.xdats.*;
|
||||
public class Xodb_save_mgr_txt implements Xodb_save_mgr {
|
||||
public Xodb_save_mgr_txt(Xowe_wiki wiki, Xodb_load_mgr_txt load_mgr) {
|
||||
this.wiki = wiki;
|
||||
this.load_mgr = load_mgr;
|
||||
this.fsys_mgr = wiki.Tdb_fsys_mgr();
|
||||
this.redirect_mgr = wiki.Redirect_mgr();
|
||||
} private Xowe_wiki wiki; private Xotdb_fsys_mgr fsys_mgr; private Xodb_load_mgr_txt load_mgr; private Xop_redirect_mgr redirect_mgr;
|
||||
public boolean Create_enabled() {return create_enabled;} public void Create_enabled_(boolean v) {create_enabled = v;} private boolean create_enabled;
|
||||
public boolean Update_modified_on_enabled() {return update_modified_on_enabled;} public void Update_modified_on_enabled_(boolean v) {update_modified_on_enabled = v;} private boolean update_modified_on_enabled;
|
||||
public int Page_id_next() {return page_id_next;} public void Page_id_next_(int v) {page_id_next = v;} private int page_id_next = 0;
|
||||
public void Clear() {page_id_next = 0;} // TEST: needed for ctg_test
|
||||
public int Data_create(Xoa_ttl ttl, byte[] text) {
|
||||
Xow_ns ns_itm = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
|
||||
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
boolean found = load_mgr.Load_by_ttl(db_page, ns_itm, ttl_bry);
|
||||
if (found) throw Err_.new_wo_type("create requested but title already exists", "ttl", String_.new_u8(ttl_bry));
|
||||
int text_len = text.length;
|
||||
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_m001();
|
||||
int page_id = page_id_next++;
|
||||
int fil_idx = 0;
|
||||
int ns_id = ttl.Ns().Id();
|
||||
Xotdb_page_itm_.Txt_page_save(tmp, page_id, Datetime_now.Get(), ttl_bry, text, true);
|
||||
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ns_id, fil_idx);
|
||||
byte[] page_rdr_bry = Io_mgr.Instance.LoadFilBry(page_rdr_url);
|
||||
Xob_xdat_file page_rdr = new Xob_xdat_file();
|
||||
if (Bry_.Len_gt_0(page_rdr_bry)) page_rdr.Parse(page_rdr_bry, page_rdr_bry.length, page_rdr_url);
|
||||
int row_idx = page_rdr.Count();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
page_rdr.Insert(tmp_bfr, tmp.To_bry_and_clear());
|
||||
this.Data_save(Xotdb_dir_info_.Tid_page, page_rdr, page_rdr_url, tmp_bfr);
|
||||
tmp_bfr.Mkr_rls();
|
||||
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
|
||||
db_page.Init(page_id, ttl.Page_db(), redirect_ttl != null, text_len, fil_idx, row_idx);
|
||||
Xotdb_page_itm_.Txt_ttl_save(tmp, db_page);
|
||||
byte[] ttl_row_bry = tmp.To_bry_and_rls();
|
||||
Xowd_hive_mgr ttl_hive = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_ttl);
|
||||
ttl_hive.Create(ttl.Ns(), ttl.Page_db(), ttl_row_bry, Bry_comparer_fld_last.Instance);
|
||||
wiki.Db_mgr().Load_mgr().Clear(); // NOTE: need to clear cached regy_ary in load_mgr
|
||||
return page_id;
|
||||
}
|
||||
public void Data_update(Xoae_page page, byte[] text) {Data_update_under(page, text, null);}
|
||||
public void Data_rename(Xoae_page page, int trg_ns, byte[] trg_ttl) {
|
||||
if (wiki.Domain_tid() != Xow_domain_tid_.Tid__home) {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "Only pages in the home wiki can be renamed");
|
||||
return;
|
||||
}
|
||||
Data_update_under(page, null, trg_ttl);
|
||||
}
|
||||
private void Data_update_under(Xoae_page page, byte[] text, byte[] new_ttl) {
|
||||
Xoa_ttl ttl = page.Ttl();
|
||||
Xow_ns ns = ttl.Ns(); byte[] ttl_bry = ttl.Page_db();
|
||||
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
|
||||
if (!load_mgr.Load_by_ttl(db_page, ns, ttl_bry)) throw Err_.new_wo_type("update requested but title does not exist", "ttl", String_.new_u8(ttl_bry));
|
||||
byte[] old_ttl = ttl_bry;
|
||||
if (new_ttl != null) {
|
||||
ttl_bry = new_ttl;
|
||||
db_page.Ttl_page_db_(new_ttl);
|
||||
}
|
||||
// update page
|
||||
Xob_xdat_file page_rdr = new Xob_xdat_file(); Xob_xdat_itm page_itm = new Xob_xdat_itm();
|
||||
load_mgr.Load_page(tmp_page, db_page.Text_db_id(), db_page.Tdb_row_idx(), ns, true, page_rdr, page_itm);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
if (text == null) text = tmp_page.Text();
|
||||
int text_len = text.length;
|
||||
DateAdp modified_on = tmp_page.Modified_on();
|
||||
if (update_modified_on_enabled) {
|
||||
modified_on = Datetime_now.Get();
|
||||
page.Db().Page().Modified_on_(modified_on);
|
||||
}
|
||||
Xotdb_page_itm_.Txt_page_save(tmp_bfr, db_page.Id(), modified_on, ttl_bry, text, true);
|
||||
page_rdr.Update(tmp_bfr, page_itm, tmp_bfr.To_bry_and_clear());
|
||||
Io_url page_rdr_url = fsys_mgr.Url_ns_fil(Xotdb_dir_info_.Tid_page, ttl.Ns().Id(), db_page.Text_db_id());
|
||||
this.Data_save(Xotdb_dir_info_.Tid_page, page_rdr, page_rdr_url, tmp_bfr);
|
||||
tmp_bfr.Mkr_rls();
|
||||
// update ttl
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(text, text_len);
|
||||
db_page.Text_len_(text_len);
|
||||
db_page.Redirected_(redirect_ttl != null);
|
||||
Bry_bfr tmp = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Xotdb_page_itm_.Txt_ttl_save(tmp, db_page);
|
||||
byte[] ttl_row_bry = tmp.To_bry_and_clear();
|
||||
tmp.Mkr_rls();
|
||||
Xowd_hive_mgr ttl_hive = new Xowd_hive_mgr(wiki, Xotdb_dir_info_.Tid_ttl);
|
||||
ttl_hive.Update(ns, old_ttl, new_ttl, ttl_row_bry, Xotdb_page_itm_.Txt_ttl_pos, Byte_ascii.Pipe, true, true);
|
||||
}
|
||||
private void Data_save(byte dir_tid, Xob_xdat_file xdat_file, Io_url url, Bry_bfr tmp_bfr) {
|
||||
xdat_file.Save(url);
|
||||
}
|
||||
private Xowd_page_itm tmp_page = new Xowd_page_itm();
|
||||
public static final int File_idx_unknown = -1;
|
||||
}
|
||||
class Bry_comparer_fld_last implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
byte[] lhs = (byte[])lhsObj, rhs = (byte[])rhsObj;
|
||||
int lhs_bgn = Bry_find_.Find_bwd(lhs, Byte_ascii.Pipe); if (lhs_bgn == Bry_find_.Not_found) lhs_bgn = -1;
|
||||
int rhs_bgn = Bry_find_.Find_bwd(rhs, Byte_ascii.Pipe); if (rhs_bgn == Bry_find_.Not_found) rhs_bgn = -1;
|
||||
return Bry_.Compare(lhs, lhs_bgn + 1, lhs.length, rhs, rhs_bgn + 1, rhs.length);
|
||||
}
|
||||
public static final Bry_comparer_fld_last Instance = new Bry_comparer_fld_last();
|
||||
}
|
||||
|
||||
@@ -13,17 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm {
|
||||
public Xow_abrv_wm(byte[] raw, byte[] lang_domain, Xol_lang_stub lang_actl, int domain_type) {
|
||||
this.raw = raw;
|
||||
this.lang_domain = lang_domain;
|
||||
this.lang_actl = lang_actl;
|
||||
this.domain_type = domain_type;
|
||||
}
|
||||
public byte[] Raw() {return raw;} private final byte[] raw;
|
||||
public byte[] Lang_domain() {return lang_domain;} private final byte[] lang_domain;
|
||||
public Xol_lang_stub Lang_actl() {return lang_actl;} private final Xol_lang_stub lang_actl;
|
||||
public int Domain_type() {return domain_type;} private final int domain_type;
|
||||
}
|
||||
|
||||
@@ -13,166 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm_ {
|
||||
public static Xow_abrv_wm Parse_to_abrv_or_null(byte[] src) { // EX: parse "enwiki" to abrv_itm
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return null; // empty bry
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
Object o = bry_trie.Match_at(trv, src, src_len - 1, -1); if (o == null) return null;
|
||||
Xow_abrv_wm rv = Xow_abrv_wm_override.To_abrv_itm_or_null(src); if (rv != null) return rv;
|
||||
int domain_type = ((Int_obj_ref)o).Val();
|
||||
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_intl(src, 0, trv.Pos() + 1);
|
||||
return new Xow_abrv_wm(src, lang_itm.Key(), lang_itm, domain_type);
|
||||
}
|
||||
public static Xow_domain_itm Parse_to_domain_itm(byte[] src) { // EX: parse "enwiki" to "en.wikipedia.org" itm
|
||||
if (Bry_.Has(src, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
|
||||
src = Bry_.Replace_create(src, Byte_ascii.Underline, Byte_ascii.Dash);
|
||||
return Xow_domain_itm_.parse(Xow_abrv_wm_.Parse_to_domain_bry(src));
|
||||
}
|
||||
public static byte[] Parse_to_domain_bry(byte[] src) { // EX: parse "enwiki" to en.wikipedia.org
|
||||
if (src == null) return null;
|
||||
int src_len = src.length; if (src_len == 0) return null; // empty bry
|
||||
Btrie_rv trv = new Btrie_rv();
|
||||
Object o = bry_trie.Match_at(trv, src, src_len - 1, - 1); if (o == null) return null;
|
||||
int domain_type = -1;
|
||||
byte[] lang = null;
|
||||
Xow_abrv_wm rv = Xow_abrv_wm_override.To_abrv_itm_or_null(src);
|
||||
if (rv != null) {
|
||||
lang = rv.Lang_domain();
|
||||
domain_type = rv.Domain_type();
|
||||
}
|
||||
else {
|
||||
domain_type = ((Int_obj_ref)o).Val();
|
||||
}
|
||||
switch (domain_type) {
|
||||
case Xow_domain_tid_.Tid__wmfblog: return Xow_domain_itm_.Bry__wmforg;
|
||||
case Xow_domain_tid_.Tid__wikidata: return Xow_domain_itm_.Bry__wikidata;
|
||||
case Xow_domain_tid_.Tid__mediawiki: return Xow_domain_itm_.Bry__mediawiki;
|
||||
case Xow_domain_tid_.Tid__commons: return Xow_domain_itm_.Bry__commons;
|
||||
case Xow_domain_tid_.Tid__species: return Xow_domain_itm_.Bry__species;
|
||||
case Xow_domain_tid_.Tid__meta: return Xow_domain_itm_.Bry__meta;
|
||||
case Xow_domain_tid_.Tid__incubator: return Xow_domain_itm_.Bry__incubator;
|
||||
case Xow_domain_tid_.Tid__wikipedia:
|
||||
case Xow_domain_tid_.Tid__wiktionary:
|
||||
case Xow_domain_tid_.Tid__wikisource:
|
||||
case Xow_domain_tid_.Tid__wikibooks:
|
||||
case Xow_domain_tid_.Tid__wikiversity:
|
||||
case Xow_domain_tid_.Tid__wikiquote:
|
||||
case Xow_domain_tid_.Tid__wikinews:
|
||||
case Xow_domain_tid_.Tid__wikivoyage:
|
||||
case Xow_domain_tid_.Tid__wikimedia:
|
||||
if (lang == null) {
|
||||
lang = Bry_.Mid(src, 0, trv.Pos() + 1); // en
|
||||
if (Bry_.Has(lang, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
|
||||
lang = Bry_.Replace_create(lang, Byte_ascii.Underline, Byte_ascii.Dash);
|
||||
}
|
||||
return Bry_.Add
|
||||
( lang
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_tid_.Get_type_as_bry(domain_type) // wikipedia
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_itm_.Seg__org // org
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void To_abrv(Bry_bfr bfr, byte[] lang_key, Int_obj_ref domain_type) {
|
||||
byte[] suffix_bry = (byte[])int_hash.Get_by(domain_type); if (suffix_bry == null) return;
|
||||
switch (domain_type.Val()) {
|
||||
case Xow_domain_tid_.Tid__commons:
|
||||
case Xow_domain_tid_.Tid__species:
|
||||
case Xow_domain_tid_.Tid__meta:
|
||||
case Xow_domain_tid_.Tid__incubator:
|
||||
case Xow_domain_tid_.Tid__wikidata:
|
||||
case Xow_domain_tid_.Tid__mediawiki:
|
||||
case Xow_domain_tid_.Tid__wmfblog: bfr.Add(suffix_bry); break;
|
||||
case Xow_domain_tid_.Tid__other: break;
|
||||
default: bfr.Add(lang_key).Add(suffix_bry); break;
|
||||
}
|
||||
}
|
||||
public static byte[] To_abrv(Xow_domain_itm domain_itm) {
|
||||
int tid = domain_itm.Domain_type_id();
|
||||
byte[] suffix = (byte[])int_hash.Get_by(Int_obj_ref.New(tid)); if (suffix == null) return null;
|
||||
switch (tid) {
|
||||
case Xow_domain_tid_.Tid__commons:
|
||||
case Xow_domain_tid_.Tid__species:
|
||||
case Xow_domain_tid_.Tid__meta:
|
||||
case Xow_domain_tid_.Tid__incubator:
|
||||
case Xow_domain_tid_.Tid__wikidata:
|
||||
case Xow_domain_tid_.Tid__mediawiki:
|
||||
case Xow_domain_tid_.Tid__wmfblog: return suffix;
|
||||
case Xow_domain_tid_.Tid__wikipedia:
|
||||
case Xow_domain_tid_.Tid__wiktionary:
|
||||
case Xow_domain_tid_.Tid__wikisource:
|
||||
case Xow_domain_tid_.Tid__wikibooks:
|
||||
case Xow_domain_tid_.Tid__wikiversity:
|
||||
case Xow_domain_tid_.Tid__wikiquote:
|
||||
case Xow_domain_tid_.Tid__wikinews:
|
||||
case Xow_domain_tid_.Tid__wikivoyage:
|
||||
case Xow_domain_tid_.Tid__wikimedia: return Bry_.Add(domain_itm.Lang_orig_key(), suffix);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
private static final Btrie_bwd_mgr bry_trie = Init_trie();
|
||||
private static Hash_adp int_hash;
|
||||
private static Btrie_bwd_mgr Init_trie() {
|
||||
int_hash = Hash_adp_.New();
|
||||
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
|
||||
Init_trie_itm(rv, int_hash, "wiki" , Xow_domain_tid_.Tid__wikipedia);
|
||||
Init_trie_itm(rv, int_hash, "wiktionary" , Xow_domain_tid_.Tid__wiktionary);
|
||||
Init_trie_itm(rv, int_hash, "wikisource" , Xow_domain_tid_.Tid__wikisource);
|
||||
Init_trie_itm(rv, int_hash, "wikibooks" , Xow_domain_tid_.Tid__wikibooks);
|
||||
Init_trie_itm(rv, int_hash, "wikiversity" , Xow_domain_tid_.Tid__wikiversity);
|
||||
Init_trie_itm(rv, int_hash, "wikiquote" , Xow_domain_tid_.Tid__wikiquote);
|
||||
Init_trie_itm(rv, int_hash, "wikinews" , Xow_domain_tid_.Tid__wikinews);
|
||||
Init_trie_itm(rv, int_hash, "wikivoyage" , Xow_domain_tid_.Tid__wikivoyage);
|
||||
Init_trie_itm(rv, int_hash, "wikimedia" , Xow_domain_tid_.Tid__wikimedia);
|
||||
Init_trie_itm(rv, int_hash, "commonswiki" , Xow_domain_tid_.Tid__commons);
|
||||
Init_trie_itm(rv, int_hash, "specieswiki" , Xow_domain_tid_.Tid__species);
|
||||
Init_trie_itm(rv, int_hash, "metawiki" , Xow_domain_tid_.Tid__meta);
|
||||
Init_trie_itm(rv, int_hash, "incubatorwiki" , Xow_domain_tid_.Tid__incubator);
|
||||
Init_trie_itm(rv, int_hash, "wikidatawiki" , Xow_domain_tid_.Tid__wikidata);
|
||||
Init_trie_itm(rv, int_hash, "mediawikiwiki" , Xow_domain_tid_.Tid__mediawiki);
|
||||
Init_trie_itm(rv, int_hash, "foundationwiki" , Xow_domain_tid_.Tid__wmfblog);
|
||||
return rv;
|
||||
}
|
||||
private static void Init_trie_itm(Btrie_bwd_mgr trie, Hash_adp hash, String str, int tid) {
|
||||
Int_obj_ref itm = Int_obj_ref.New(tid);
|
||||
trie.Add(str, itm);
|
||||
hash.Add(itm, Bry_.new_u8(str));
|
||||
}
|
||||
}
|
||||
class Xow_abrv_wm_override {
|
||||
public static Xow_abrv_wm To_abrv_itm_or_null(byte[] abrv) {
|
||||
Object o = itm_hash.Get_by_bry(abrv);
|
||||
return o == null ? null : (Xow_abrv_wm)o;
|
||||
}
|
||||
public static byte[] To_lang_key_or_null(byte[] domain_bry) {
|
||||
Object o = lang_hash.Get_by_bry(domain_bry);
|
||||
return o == null ? null : (byte[])o;
|
||||
}
|
||||
private static final Hash_adp_bry itm_hash = itm_hash__make();
|
||||
private static Hash_adp_bry lang_hash;
|
||||
private static Hash_adp_bry itm_hash__make() {
|
||||
Hash_adp_bry rv = Hash_adp_bry.cs();
|
||||
lang_hash = Hash_adp_bry.cs();
|
||||
itm_hash__add(rv, lang_hash, "ar.wikimedia.org", "arwikimedia", "ar", Xol_lang_stub_.Id_es, Xow_domain_tid_.Tid__wikimedia); // NOTE: ar means Argentina not Arabic
|
||||
itm_hash__add(rv, lang_hash, "br.wikimedia.org", "brwikimedia", "br", Xol_lang_stub_.Id_es, Xow_domain_tid_.Tid__wikimedia); // NOTE: br means Brazil not Breto
|
||||
itm_hash__add(rv, lang_hash, "co.wikimedia.org", "cowikimedia", "co", Xol_lang_stub_.Id_es, Xow_domain_tid_.Tid__wikimedia); // NOTE: co means Columbia not Corsican
|
||||
itm_hash__add(rv, lang_hash, "ua.wikimedia.org", "ukwikimedia", "ua", Xol_lang_stub_.Id_uk, Xow_domain_tid_.Tid__wikimedia); // NOTE: ua means Ukrainian; NOTE: uk does not means United Kingdom (which redirects to https://wikimedia.org.uk)
|
||||
itm_hash__add(rv, lang_hash, "ca.wikimedia.org", "cawikimedia", "ca", Xol_lang_stub_.Id_en, Xow_domain_tid_.Tid__wikimedia); // NOTE: ca means Canada not Catalan
|
||||
itm_hash__add(rv, lang_hash, "be.wikimedia.org", "bewikimedia", "be", Xol_lang_stub_.Id_en, Xow_domain_tid_.Tid__wikimedia); // NOTE: be means Belgium not Belarusian
|
||||
itm_hash__add(rv, lang_hash, "se.wikimedia.org", "sewikimedia", "se", Xol_lang_stub_.Id_sv, Xow_domain_tid_.Tid__wikimedia); // NOTE: se means Swedish not Northern Sami
|
||||
return rv;
|
||||
}
|
||||
private static void itm_hash__add(Hash_adp_bry hash, Hash_adp_bry lang_hash, String domain, String raw, String lang_domain, int lang_actl, int domain_type) {
|
||||
byte[] abrv_bry = Bry_.new_u8(raw);
|
||||
Xol_lang_stub lang_actl_itm = Xol_lang_stub_.Get_by_id(lang_actl);
|
||||
Xow_abrv_wm itm = new Xow_abrv_wm(abrv_bry, Bry_.new_a7(lang_domain), lang_actl_itm, domain_type);
|
||||
hash.Add_bry_obj(abrv_bry, itm);
|
||||
lang_hash.Add_str_obj(domain, lang_actl_itm.Key());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,82 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_wm_tst {
|
||||
private Xow_abrv_wm_fxt fxt = new Xow_abrv_wm_fxt();
|
||||
@Test public void Parse() {
|
||||
fxt.Test_parse("foundationwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__wmfblog);
|
||||
fxt.Test_parse("wikidatawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__wikidata);
|
||||
fxt.Test_parse("mediawikiwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__mediawiki);
|
||||
fxt.Test_parse("commonswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__commons);
|
||||
fxt.Test_parse("specieswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__species);
|
||||
fxt.Test_parse("metawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__meta);
|
||||
fxt.Test_parse("incubatorwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Tid__incubator);
|
||||
fxt.Test_parse("enwiki" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikipedia);
|
||||
fxt.Test_parse("enwiktionary" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wiktionary);
|
||||
fxt.Test_parse("enwikisource" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikisource);
|
||||
fxt.Test_parse("enwikibooks" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikibooks);
|
||||
fxt.Test_parse("enwikiversity" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikiversity);
|
||||
fxt.Test_parse("enwikiquote" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikiquote);
|
||||
fxt.Test_parse("enwikinews" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikinews);
|
||||
fxt.Test_parse("enwikivoyage" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Tid__wikivoyage);
|
||||
fxt.Test_parse("frwiki" , Xol_lang_stub_.Id_fr , Xow_domain_tid_.Tid__wikipedia);
|
||||
fxt.Test_parse_null("unknown");
|
||||
fxt.Test_parse("plwikimedia" , Xol_lang_stub_.Id_pl , Xow_domain_tid_.Tid__wikimedia);
|
||||
}
|
||||
@Test public void Parse_override() {
|
||||
fxt.Test_parse("arwikimedia" , Xol_lang_stub_.Id_es , Xow_domain_tid_.Tid__wikimedia);
|
||||
fxt.Test_parse("ukwikimedia" , Xol_lang_stub_.Id_uk , Xow_domain_tid_.Tid__wikimedia);
|
||||
}
|
||||
@Test public void To_domain_itm() {
|
||||
fxt.Test_to_domain_itm("enwiki" , "en" , "en.wikipedia.org");
|
||||
fxt.Test_to_domain_itm("zh_yuewiki" , "zh-yue" , "zh-yue.wikipedia.org");
|
||||
}
|
||||
@Test public void To_domain_bry() {
|
||||
fxt.Test_to_domain_bry("enwiki" , "en.wikipedia.org");
|
||||
fxt.Test_to_domain_bry("zh_yuewiki" , "zh-yue.wikipedia.org");
|
||||
fxt.Test_to_domain_bry("arwikimedia", "ar.wikimedia.org");
|
||||
fxt.Test_to_domain_bry("ukwikimedia", "ua.wikimedia.org");
|
||||
}
|
||||
@Test public void To_abrv() {
|
||||
fxt.Test_to_abrv("simple.wikipedia.org" , "simplewiki");
|
||||
fxt.Test_to_abrv("en.wikipedia.org" , "enwiki");
|
||||
fxt.Test_to_abrv("commons.wikimedia.org" , "commonswiki");
|
||||
}
|
||||
@Test public void To_abrv_by_lang() {
|
||||
fxt.Test_to_abrv_by_lang("en", Xow_domain_tid_.Tid__wikipedia, "enwiki");
|
||||
}
|
||||
}
|
||||
class Xow_abrv_wm_fxt {
|
||||
public void Test_parse(String raw, int expd_lang_id, int expd_domain_tid) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry);
|
||||
Xol_lang_stub actl_lang_itm = abrv.Lang_actl();
|
||||
Tfds.Eq(expd_lang_id , actl_lang_itm == null ? Xol_lang_stub_.Id__unknown : actl_lang_itm.Id());
|
||||
Tfds.Eq(expd_domain_tid , abrv.Domain_type());
|
||||
}
|
||||
public void Test_parse_null(String raw) {
|
||||
byte[] raw_bry = Bry_.new_a7(raw);
|
||||
Xow_abrv_wm abrv = Xow_abrv_wm_.Parse_to_abrv_or_null(raw_bry);
|
||||
Tfds.Eq_true(abrv == null);
|
||||
}
|
||||
public void Test_to_abrv(String domain_str, String expd) {
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_a7(domain_str));
|
||||
byte[] actl = Xow_abrv_wm_.To_abrv(domain);
|
||||
Tfds.Eq(expd, String_.new_a7(actl));
|
||||
}
|
||||
public void Test_to_abrv_by_lang(String lang_key, int wiki_tid, String expd) {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
|
||||
Xow_abrv_wm_.To_abrv(tmp_bfr, Bry_.new_a7(lang_key), gplx.core.primitives.Int_obj_ref.New(wiki_tid));
|
||||
Tfds.Eq_str(expd, tmp_bfr.To_str_and_clear(), "to_abrv");
|
||||
}
|
||||
public void Test_to_domain_bry(String wmf_key, String expd_domain) {
|
||||
Tfds.Eq(expd_domain , String_.new_a7(Xow_abrv_wm_.Parse_to_domain_bry(Bry_.new_a7(wmf_key))));
|
||||
}
|
||||
public void Test_to_domain_itm(String wmf_key, String expd_lang_key, String expd_domain) {
|
||||
Xow_domain_itm domain = Xow_abrv_wm_.Parse_to_domain_itm(Bry_.new_a7(wmf_key));
|
||||
Tfds.Eq(expd_lang_key , String_.new_a7(domain.Lang_actl_key()));
|
||||
Tfds.Eq(expd_domain , String_.new_a7(domain.Domain_bry()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,41 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_abrv_xo_ {
|
||||
public static byte[] To_bry(byte[] domain_bry) {
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(domain_bry);
|
||||
return Xow_abrv_xo_.To_bry(domain_itm.Domain_bry(), domain_itm.Lang_orig_key(), domain_itm.Domain_type());
|
||||
}
|
||||
public static byte[] To_bry(byte[] domain_bry, byte[] lang_key, Xow_domain_tid type) { // en.wikipedia.org -> en.w
|
||||
byte[] type_abrv = type.Abrv();
|
||||
if (type.Multi_lang()) // wikipedia,wiktionary,etc..
|
||||
return Bry_.Add(lang_key, Byte_ascii.Dot_bry, type_abrv);
|
||||
else if (type_abrv.length > 0) // commons,wbase,species,etc..
|
||||
return type_abrv;
|
||||
else // home;wikia;others
|
||||
return domain_bry;
|
||||
}
|
||||
public static Xow_domain_itm To_itm(byte[] src) {
|
||||
int src_len = src.length;
|
||||
byte[] domain_bry = src; // default to src; handles unknown abrv like "a.wikia.com";"xowa";others
|
||||
Xow_domain_tid type = null;
|
||||
int dot_pos = Bry_find_.Find_fwd(src, Byte_ascii.Dot);
|
||||
if (dot_pos != Bry_find_.Not_found) { // dot found; EX: "en.w"
|
||||
type = Xow_domain_tid_.Get_abrv_as_itm(src, dot_pos + 1, src_len);
|
||||
if (type != null) { // type found; EX: ".w"
|
||||
Xol_lang_stub lang = Xol_lang_stub_.Get_by_key_or_null(src, 0, dot_pos);
|
||||
if (lang != null) // lang found; EX: "en."
|
||||
domain_bry = Bry_.Add(lang.Key(), type.Domain_bry());
|
||||
}
|
||||
}
|
||||
else { // dot missing; EX: "c"
|
||||
type = Xow_domain_tid_.Get_abrv_as_itm(src, 0, src_len);
|
||||
if (type != null) { // type found; EX: "c"
|
||||
domain_bry = type.Domain_bry();
|
||||
}
|
||||
}
|
||||
return Xow_domain_itm_.parse(domain_bry); // for consolidation's sake, parse abrv to domain_bry and pass to Xow_domain_itm_.parse()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,29 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xow_abrv_xo__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_abrv_xo__fxt fxt = new Xow_abrv_xo__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test("en.wikipedia.org" , "en.w"); // multi.enwiki
|
||||
fxt.Test("fr.wiktionary.org" , "fr.d"); // multi.frwiktionary
|
||||
fxt.Test("commons.wikimedia.org" , "c"); // important.unique.commons
|
||||
fxt.Test("species.wikimedia.org" , "species"); // important.unique.species
|
||||
fxt.Test("www.wikidata.org" , "wd"); // important.unique.wikidata
|
||||
fxt.Test("home" , "home"); // important.unique.xowa
|
||||
fxt.Test("meta.wikimedia.org" , "meta"); // wikimedia.unique
|
||||
fxt.Test("pl.wikimedia.org" , "pl.m"); // wikimedia.multi
|
||||
fxt.Test("a.b.c" , "a.b.c"); // unkonwn
|
||||
}
|
||||
}
|
||||
class Xow_abrv_xo__fxt {
|
||||
public void Clear() {}
|
||||
public void Test(String domain_str, String expd_abrv) {
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domain_str));
|
||||
byte[] actl_abrv = Xow_abrv_xo_.To_bry(domain.Domain_bry(), domain.Lang_actl_key(), domain.Domain_type());
|
||||
Tfds.Eq(expd_abrv, String_.new_u8(actl_abrv), "To_bry");
|
||||
domain = Xow_abrv_xo_.To_itm(actl_abrv);
|
||||
Tfds.Eq(domain_str, domain.Domain_str(), "To_itm");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,36 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_itm {
|
||||
Xow_domain_itm(byte[] domain_bry, Xow_domain_tid domain_type, Xol_lang_stub lang_actl_itm, byte[] lang_orig_key) {
|
||||
this.domain_bry = domain_bry; this.domain_type = domain_type; this.lang_actl_itm = lang_actl_itm; this.lang_orig_key = lang_orig_key;
|
||||
this.domain_str = String_.new_u8(domain_bry);
|
||||
this.abrv_wm = Xow_abrv_wm_.To_abrv(this);
|
||||
this.abrv_xo = Xow_abrv_xo_.To_bry(domain_bry, lang_orig_key, domain_type);
|
||||
this.abrv_xo_str = String_.new_u8(abrv_xo);
|
||||
}
|
||||
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry;
|
||||
public String Domain_str() {return domain_str;} private final String domain_str;
|
||||
public Xow_domain_tid Domain_type() {return domain_type;} private final Xow_domain_tid domain_type;
|
||||
public int Domain_type_id() {return domain_type.Tid();}
|
||||
public byte[] Abrv_wm() {return abrv_wm;} private final byte[] abrv_wm; // EX: enwiki
|
||||
public byte[] Abrv_xo() {return abrv_xo;} private final byte[] abrv_xo; // EX: en.w
|
||||
public String Abrv_xo_str() {return abrv_xo_str;} private final String abrv_xo_str; // EX: en.w
|
||||
public Xol_lang_stub Lang_actl_itm() {return lang_actl_itm;} private final Xol_lang_stub lang_actl_itm; // EX: zh
|
||||
public int Lang_actl_uid() {return lang_actl_itm.Id();}
|
||||
public byte[] Lang_actl_key() {return lang_actl_itm.Key();}
|
||||
public byte[] Lang_orig_key() {return lang_orig_key;} private final byte[] lang_orig_key; // EX: lzh
|
||||
public int Sort_idx() {return sort_idx;} public void Sort_idx_(int v) {sort_idx = v;} private int sort_idx = -1; // used for Search
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, byte[] lang_key) {
|
||||
Xol_lang_stub lang_actl_itm = Xol_lang_stub_.Get_by_key_or_intl(lang_key);
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_tid_.Get_type_as_itm(domain_tid), lang_actl_itm, lang_actl_itm.Key());
|
||||
}
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, Xol_lang_stub lang_actl, byte[] lang_orig) {
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_tid_.Get_type_as_itm(domain_tid), lang_actl, lang_orig);
|
||||
}
|
||||
public static Xow_domain_itm new_(byte[] domain_bry, int domain_tid, byte[] lang_actl_key, byte[] lang_orig_key) {
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_tid_.Get_type_as_itm(domain_tid), Xol_lang_stub_.Get_by_key_or_intl(lang_actl_key), lang_orig_key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,138 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_itm_ {
|
||||
public static final Xow_domain_itm[] Ary_empty = new Xow_domain_itm[0];
|
||||
public static Xow_domain_itm parse(byte[] raw) {
|
||||
/*
|
||||
~{type}.org EX: wikimediafoundation
|
||||
~{type}.wikimedia.org EX: commons; species; meta; incubator
|
||||
~{lang}.~{type}.org EX: en.wikipedia, etc;
|
||||
~www.~{type}.org EX: mediawiki; wikidata;
|
||||
*/
|
||||
int raw_len = raw.length;
|
||||
int dot_0 = Bry_find_.Find_fwd(raw, Byte_ascii.Dot, 0, raw_len);
|
||||
if (dot_0 == Bry_find_.Not_found) { // 0 dots; check for "home"
|
||||
return Bry_.Eq(raw, Xow_domain_tid_.Bry__home)
|
||||
? Xow_domain_uid_.To_domain(Xow_domain_uid_.Tid_xowa)
|
||||
: new_other(raw);
|
||||
}
|
||||
int dot_1 = Bry_find_.Find_fwd(raw, Byte_ascii.Dot, dot_0 + 1, raw_len);
|
||||
if (dot_1 == Bry_find_.Not_found) { // 1 dot; check for "wikimediafoundation.org"
|
||||
return Bry_.Match(raw, 0, dot_0, Xow_domain_tid_.Bry__wmforg)
|
||||
? Xow_domain_itm.new_(raw, Xow_domain_tid_.Tid__wmfblog, Xol_lang_stub_.Key__unknown)
|
||||
: new_other(raw);
|
||||
}
|
||||
// 2 dots
|
||||
int seg_1_tid = Xow_domain_tid_.Get_type_as_tid(raw, dot_0 + 1, dot_1); // parse middle; EX: ".wikipedia."
|
||||
if (seg_1_tid == Xow_domain_tid_.Tid__null) return new_other(raw); // seg_1 is unknown; return other;
|
||||
switch (seg_1_tid) {
|
||||
case Xow_domain_tid_.Tid__wikipedia: case Xow_domain_tid_.Tid__wiktionary: case Xow_domain_tid_.Tid__wikisource: case Xow_domain_tid_.Tid__wikibooks:
|
||||
case Xow_domain_tid_.Tid__wikiversity: case Xow_domain_tid_.Tid__wikiquote: case Xow_domain_tid_.Tid__wikinews: case Xow_domain_tid_.Tid__wikivoyage: // ~{lang}.~{type}.org
|
||||
byte[] lang_orig = Bry_.Mid(raw, 0, dot_0);
|
||||
byte[] lang_actl = Get_lang_code_for_mw_messages_file(lang_orig);
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, lang_actl, lang_orig); // NOTE: seg_tids must match wiki_tids
|
||||
case Xow_domain_tid_.Tid__wikidata: case Xow_domain_tid_.Tid__mediawiki:// ~www.~{type}.org
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, Xol_lang_stub_.Key__unknown);
|
||||
case Xow_domain_tid_.Tid__wikimedia: // ~{type}.wikimedia.org;
|
||||
int seg_0_tid = Xow_domain_tid_.Get_type_as_tid(raw, 0, dot_0); // try to get "incubator", "meta", etc..
|
||||
if (seg_0_tid == Xow_domain_tid_.Tid__null) { // not a known name; try language
|
||||
byte[] lang_override = Xow_abrv_wm_override.To_lang_key_or_null(raw); // handle "lang-like" wikimedia domains like "ar.wikimedia.org" which is actually to "Argentina Wikimedia"
|
||||
if (lang_override == null) {
|
||||
Xol_lang_stub wikimedia_lang = Xol_lang_stub_.Get_by_key_or_null(raw, 0, dot_0);
|
||||
return wikimedia_lang == null ? new_other(raw) : Xow_domain_itm.new_(raw, Xow_domain_tid_.Tid__wikimedia, wikimedia_lang.Key());
|
||||
}
|
||||
else
|
||||
return Xow_domain_itm.new_(raw, Xow_domain_tid_.Tid__wikimedia, lang_override, Bry_.Mid(raw, 0, dot_0));
|
||||
}
|
||||
switch (seg_0_tid) {
|
||||
case Xow_domain_tid_.Tid__commons: case Xow_domain_tid_.Tid__species: case Xow_domain_tid_.Tid__meta: case Xow_domain_tid_.Tid__incubator:
|
||||
return Xow_domain_itm.new_(raw, seg_0_tid, Xol_lang_stub_.Key__unknown); // NOTE: seg_tids must match wiki_tids; NOTE: lang_key is "en" (really, "multi" but making things easier)
|
||||
default:
|
||||
return new_other(raw);
|
||||
}
|
||||
case Xow_domain_tid_.Tid__other:
|
||||
default:
|
||||
return new_other(raw);
|
||||
}
|
||||
}
|
||||
public static boolean Match_lang(Xow_domain_itm domain, String match) {
|
||||
// exit early if "*"
|
||||
if (String_.Eq(match, Lang_key__all)) return true;
|
||||
|
||||
// get lang
|
||||
String cur = String_.new_u8(domain.Lang_actl_key());
|
||||
|
||||
// return true if direct match; EX: "en" <-> "en"; "de" <-> "de"
|
||||
if (String_.Eq(cur, match)) return true;
|
||||
|
||||
// handle special cases
|
||||
if (String_.Eq(match, "en"))
|
||||
return String_.In(domain.Domain_str(), "simple.wikipedia.org", "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org");
|
||||
else if (String_.Eq(match, "zh"))
|
||||
return String_.Eq(cur, "lzh");
|
||||
return false;
|
||||
}
|
||||
public static boolean Match_type(Xow_domain_itm domain, String match) {
|
||||
// exit early if "*"
|
||||
if (String_.Eq(match, Type_key__all)) return true;
|
||||
|
||||
// get lang
|
||||
String cur = domain.Domain_type().Key_str();
|
||||
|
||||
// return true if direct match; EX: "wiki" <-> "wiki"; "wiktionary" <-> "wiktionary"
|
||||
if (String_.Eq(cur, match)) return true;
|
||||
|
||||
// handle special cases
|
||||
if (String_.Eq(match, "wikimisc"))
|
||||
return String_.In(domain.Domain_str(), "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org");
|
||||
return false;
|
||||
}
|
||||
public static final String Lang_key__all = "*", Type_key__all = "*";
|
||||
|
||||
private static Xow_domain_itm new_other(byte[] raw) {return Xow_domain_itm.new_(raw, Xow_domain_tid_.Tid__other, Xol_lang_stub_.Key__unknown);}
|
||||
private static byte[] Get_lang_code_for_mw_messages_file(byte[] v) {
|
||||
Object o = alt_domain__lang_by_subdomain.Get_by_bry(v);
|
||||
return o == null ? v : (byte[])o;
|
||||
}
|
||||
public static byte[] Alt_domain__get_subdomain_by_lang(byte[] lang) {
|
||||
Object o = alt_domain__subdomain_by_lang.Get_by_bry(lang);
|
||||
return o == null ? lang : (byte[])o;
|
||||
}
|
||||
private static final Hash_adp_bry alt_domain__lang_by_subdomain = Hash_adp_bry.ci_a7() // ASCII:lang_code
|
||||
.Add_str_obj("simple" , Bry_.new_a7("en"))
|
||||
.Add_str_obj("zh-classical" , Bry_.new_a7("lzh"))
|
||||
.Add_str_obj("no" , Bry_.new_a7("nb"))
|
||||
;
|
||||
private static final Hash_adp_bry alt_domain__subdomain_by_lang = Hash_adp_bry.ci_a7() // ASCII:lang_code
|
||||
.Add_str_obj("lzh" , Bry_.new_a7("zh-classical"))
|
||||
.Add_str_obj("nb" , Bry_.new_a7("no"))
|
||||
;
|
||||
public static final String
|
||||
Str__enwiki = "en.wikipedia.org"
|
||||
, Str__species = "species.wikimedia.org"
|
||||
, Str__commons = "commons.wikimedia.org"
|
||||
, Str__wikidata = "www.wikidata.org"
|
||||
, Str__mediawiki = "www.mediawiki.org"
|
||||
, Str__meta = "meta.wikimedia.org"
|
||||
, Str__incubator = "incubator.wikimedia.org"
|
||||
, Str__wmforg = "wikimediafoundation.org"
|
||||
, Str__home = "home"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__enwiki = Bry_.new_a7(Str__enwiki)
|
||||
, Bry__species = Bry_.new_a7(Str__species)
|
||||
, Bry__commons = Bry_.new_a7(Str__commons)
|
||||
, Bry__wikidata = Bry_.new_a7(Str__wikidata)
|
||||
, Bry__mediawiki = Bry_.new_a7(Str__mediawiki)
|
||||
, Bry__meta = Bry_.new_a7(Str__meta)
|
||||
, Bry__incubator = Bry_.new_a7(Str__incubator)
|
||||
, Bry__wmforg = Bry_.new_a7(Str__wmforg)
|
||||
, Bry__home = Bry_.new_a7(Str__home)
|
||||
, Bry__simplewiki = Bry_.new_a7("simple.wikipedia.org")
|
||||
;
|
||||
public static final byte[] Seg__org = Bry_.new_a7("org"), Seg__www = Bry_.new_a7("www");
|
||||
}
|
||||
|
||||
@@ -13,41 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xow_domain_itm_tst {
|
||||
private final Xow_domain_fxt fxt = new Xow_domain_fxt();
|
||||
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , "en" , Xow_domain_tid_.Tid__wikipedia);}
|
||||
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , "fr" , Xow_domain_tid_.Tid__wikipedia);}
|
||||
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , "en" , Xow_domain_tid_.Tid__wiktionary);}
|
||||
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "zh-classical" , "lzh" , Xow_domain_tid_.Tid__wikipedia);}
|
||||
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , "" , Xow_domain_tid_.Tid__commons);}
|
||||
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , "" , Xow_domain_tid_.Tid__species);}
|
||||
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , "ru" , Xow_domain_tid_.Tid__wikimedia);}
|
||||
@Test public void Parse_home() {fxt.Test_parse("home" , "" , "" , Xow_domain_tid_.Tid__home);}
|
||||
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , "" , Xow_domain_tid_.Tid__other);}
|
||||
@Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_tid_.Tid__wikimedia);}
|
||||
@Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_tid_.Tid__wikimedia);}
|
||||
@Test public void Parse_blank() {fxt.Test_parse("" , "" , "" , Xow_domain_tid_.Tid__other);}
|
||||
@Test public void Match_lang() {
|
||||
fxt.Test__match_lang_y("en", "en.wikipedia.org", "en.wiktionary.org", "simple.wikipedia.org", "species.wikimedia.org", "www.wikidata.org", "commons.wikimedia.org");
|
||||
fxt.Test__match_lang_y("fr", "fr.wikipedia.org", "fr.wiktionary.org");
|
||||
fxt.Test__match_lang_y("zh", "zh-classical.wikipedia.org");
|
||||
}
|
||||
}
|
||||
class Xow_domain_fxt {
|
||||
public void Test_parse(String domain, String expd_orig_lang, String expd_actl_lang, int expd_tid) {
|
||||
Xow_domain_itm actl = Xow_domain_itm_.parse(Bry_.new_a7(domain));
|
||||
Tfds.Eq_str(expd_orig_lang, String_.new_a7((actl.Lang_orig_key())));
|
||||
Tfds.Eq_str(expd_actl_lang, String_.new_a7((actl.Lang_actl_key())));
|
||||
Tfds.Eq_int(expd_tid, actl.Domain_type_id());
|
||||
}
|
||||
public void Test__match_lang_y(String lang_code, String... domains) {Test__match_lang(Bool_.Y, lang_code, domains);}
|
||||
public void Test__match_lang(boolean expd, String lang_key_str, String[] domains) {
|
||||
int len = domains.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_itm domain = Xow_domain_itm_.parse(Bry_.new_u8(domains[i]));
|
||||
Gftest.Eq__bool(expd, Xow_domain_itm_.Match_lang(domain, lang_key_str), lang_key_str + "|" + domains[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,850 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_regy {
|
||||
public static String[] All = new String[]
|
||||
{ "commons.wikimedia.org"
|
||||
, "species.wikimedia.org"
|
||||
, "meta.wikimedia.org"
|
||||
, "incubator.wikimedia.org"
|
||||
, "www.wikidata.org"
|
||||
, "www.mediawiki.org"
|
||||
, "wikimediafoundation.org"
|
||||
, "en.wikipedia.org"
|
||||
, "en.wiktionary.org"
|
||||
, "en.wikisource.org"
|
||||
, "en.wikibooks.org"
|
||||
, "en.wikiversity.org"
|
||||
, "en.wikiquote.org"
|
||||
, "en.wikinews.org"
|
||||
, "en.wikivoyage.org"
|
||||
, "de.wikipedia.org"
|
||||
, "de.wiktionary.org"
|
||||
, "de.wikisource.org"
|
||||
, "de.wikibooks.org"
|
||||
, "de.wikiversity.org"
|
||||
, "de.wikiquote.org"
|
||||
, "de.wikinews.org"
|
||||
, "de.wikivoyage.org"
|
||||
, "es.wikipedia.org"
|
||||
, "es.wiktionary.org"
|
||||
, "es.wikisource.org"
|
||||
, "es.wikibooks.org"
|
||||
, "es.wikiversity.org"
|
||||
, "es.wikiquote.org"
|
||||
, "es.wikinews.org"
|
||||
, "es.wikivoyage.org"
|
||||
, "fr.wikipedia.org"
|
||||
, "fr.wiktionary.org"
|
||||
, "fr.wikisource.org"
|
||||
, "fr.wikibooks.org"
|
||||
, "fr.wikiversity.org"
|
||||
, "fr.wikiquote.org"
|
||||
, "fr.wikinews.org"
|
||||
, "fr.wikivoyage.org"
|
||||
, "it.wikipedia.org"
|
||||
, "it.wiktionary.org"
|
||||
, "it.wikisource.org"
|
||||
, "it.wikibooks.org"
|
||||
, "it.wikiversity.org"
|
||||
, "it.wikiquote.org"
|
||||
, "it.wikinews.org"
|
||||
, "it.wikivoyage.org"
|
||||
, "ja.wikipedia.org"
|
||||
, "ja.wiktionary.org"
|
||||
, "ja.wikisource.org"
|
||||
, "ja.wikibooks.org"
|
||||
, "ja.wikiversity.org"
|
||||
, "ja.wikiquote.org"
|
||||
, "ja.wikinews.org"
|
||||
, "nl.wikipedia.org"
|
||||
, "nl.wiktionary.org"
|
||||
, "nl.wikisource.org"
|
||||
, "nl.wikibooks.org"
|
||||
, "nl.wikiquote.org"
|
||||
, "nl.wikinews.org"
|
||||
, "nl.wikivoyage.org"
|
||||
, "nl.wikimedia.org"
|
||||
, "pl.wikipedia.org"
|
||||
, "pl.wiktionary.org"
|
||||
, "pl.wikisource.org"
|
||||
, "pl.wikibooks.org"
|
||||
, "pl.wikiquote.org"
|
||||
, "pl.wikinews.org"
|
||||
, "pl.wikivoyage.org"
|
||||
, "pl.wikimedia.org"
|
||||
, "pt.wikipedia.org"
|
||||
, "pt.wiktionary.org"
|
||||
, "pt.wikisource.org"
|
||||
, "pt.wikibooks.org"
|
||||
, "pt.wikiversity.org"
|
||||
, "pt.wikiquote.org"
|
||||
, "pt.wikinews.org"
|
||||
, "pt.wikivoyage.org"
|
||||
, "ru.wikipedia.org"
|
||||
, "ru.wiktionary.org"
|
||||
, "ru.wikisource.org"
|
||||
, "ru.wikibooks.org"
|
||||
, "ru.wikiversity.org"
|
||||
, "ru.wikiquote.org"
|
||||
, "ru.wikinews.org"
|
||||
, "ru.wikivoyage.org"
|
||||
, "ru.wikimedia.org"
|
||||
, "ar.wikipedia.org"
|
||||
, "ar.wiktionary.org"
|
||||
, "ar.wikisource.org"
|
||||
, "ar.wikibooks.org"
|
||||
, "ar.wikiversity.org"
|
||||
, "ar.wikiquote.org"
|
||||
, "ar.wikinews.org"
|
||||
, "ar.wikimedia.org"
|
||||
, "ca.wikipedia.org"
|
||||
, "ca.wiktionary.org"
|
||||
, "ca.wikisource.org"
|
||||
, "ca.wikibooks.org"
|
||||
, "ca.wikiquote.org"
|
||||
, "ca.wikinews.org"
|
||||
, "ca.wikimedia.org"
|
||||
, "cs.wikipedia.org"
|
||||
, "cs.wiktionary.org"
|
||||
, "cs.wikisource.org"
|
||||
, "cs.wikibooks.org"
|
||||
, "cs.wikiversity.org"
|
||||
, "cs.wikiquote.org"
|
||||
, "cs.wikinews.org"
|
||||
, "da.wikipedia.org"
|
||||
, "da.wiktionary.org"
|
||||
, "da.wikisource.org"
|
||||
, "da.wikibooks.org"
|
||||
, "da.wikiquote.org"
|
||||
, "eo.wikipedia.org"
|
||||
, "eo.wiktionary.org"
|
||||
, "eo.wikisource.org"
|
||||
, "eo.wikibooks.org"
|
||||
, "eo.wikiquote.org"
|
||||
, "eo.wikinews.org"
|
||||
, "fa.wikipedia.org"
|
||||
, "fa.wiktionary.org"
|
||||
, "fa.wikisource.org"
|
||||
, "fa.wikibooks.org"
|
||||
, "fa.wikiquote.org"
|
||||
, "fa.wikinews.org"
|
||||
, "fa.wikivoyage.org"
|
||||
, "fi.wikipedia.org"
|
||||
, "fi.wiktionary.org"
|
||||
, "fi.wikisource.org"
|
||||
, "fi.wikivoyage.org"
|
||||
, "fi.wikibooks.org"
|
||||
, "fi.wikiversity.org"
|
||||
, "fi.wikiquote.org"
|
||||
, "fi.wikinews.org"
|
||||
, "fi.wikimedia.org"
|
||||
, "hu.wikipedia.org"
|
||||
, "hu.wiktionary.org"
|
||||
, "hu.wikisource.org"
|
||||
, "hu.wikibooks.org"
|
||||
, "hu.wikiquote.org"
|
||||
, "hu.wikinews.org"
|
||||
, "id.wikipedia.org"
|
||||
, "id.wiktionary.org"
|
||||
, "id.wikisource.org"
|
||||
, "id.wikibooks.org"
|
||||
, "id.wikiquote.org"
|
||||
, "kk.wikipedia.org"
|
||||
, "kk.wiktionary.org"
|
||||
, "kk.wikibooks.org"
|
||||
, "kk.wikiquote.org"
|
||||
, "ko.wikipedia.org"
|
||||
, "ko.wiktionary.org"
|
||||
, "ko.wikisource.org"
|
||||
, "ko.wikibooks.org"
|
||||
, "ko.wikiversity.org"
|
||||
, "ko.wikiquote.org"
|
||||
, "ko.wikinews.org"
|
||||
, "lt.wikipedia.org"
|
||||
, "lt.wiktionary.org"
|
||||
, "lt.wikisource.org"
|
||||
, "lt.wikibooks.org"
|
||||
, "lt.wikiquote.org"
|
||||
, "no.wikipedia.org"
|
||||
, "no.wiktionary.org"
|
||||
, "no.wikisource.org"
|
||||
, "no.wikibooks.org"
|
||||
, "no.wikiquote.org"
|
||||
, "no.wikinews.org"
|
||||
, "no.wikimedia.org"
|
||||
, "ro.wikipedia.org"
|
||||
, "ro.wiktionary.org"
|
||||
, "ro.wikisource.org"
|
||||
, "ro.wikibooks.org"
|
||||
, "ro.wikiquote.org"
|
||||
, "ro.wikinews.org"
|
||||
, "ro.wikivoyage.org"
|
||||
, "sk.wikipedia.org"
|
||||
, "sk.wiktionary.org"
|
||||
, "sk.wikisource.org"
|
||||
, "sk.wikibooks.org"
|
||||
, "sk.wikiquote.org"
|
||||
, "sr.wikipedia.org"
|
||||
, "sr.wiktionary.org"
|
||||
, "sr.wikisource.org"
|
||||
, "sr.wikibooks.org"
|
||||
, "sr.wikiquote.org"
|
||||
, "sr.wikinews.org"
|
||||
, "sv.wikipedia.org"
|
||||
, "sv.wiktionary.org"
|
||||
, "sv.wikisource.org"
|
||||
, "sv.wikibooks.org"
|
||||
, "sv.wikiversity.org"
|
||||
, "sv.wikiquote.org"
|
||||
, "sv.wikinews.org"
|
||||
, "sv.wikivoyage.org"
|
||||
, "tr.wikipedia.org"
|
||||
, "tr.wiktionary.org"
|
||||
, "tr.wikisource.org"
|
||||
, "tr.wikibooks.org"
|
||||
, "tr.wikiquote.org"
|
||||
, "tr.wikinews.org"
|
||||
, "tr.wikimedia.org"
|
||||
, "uk.wikipedia.org"
|
||||
, "uk.wiktionary.org"
|
||||
, "uk.wikisource.org"
|
||||
, "uk.wikibooks.org"
|
||||
, "uk.wikiquote.org"
|
||||
, "uk.wikinews.org"
|
||||
, "uk.wikivoyage.org"
|
||||
, "ua.wikimedia.org"
|
||||
, "vi.wikipedia.org"
|
||||
, "vi.wiktionary.org"
|
||||
, "vi.wikisource.org"
|
||||
, "vi.wikibooks.org"
|
||||
, "vi.wikiquote.org"
|
||||
, "vi.wikivoyage.org"
|
||||
, "zh.wikipedia.org"
|
||||
, "zh.wiktionary.org"
|
||||
, "zh.wikisource.org"
|
||||
, "zh.wikibooks.org"
|
||||
, "zh.wikiquote.org"
|
||||
, "zh.wikinews.org"
|
||||
, "zh.wikivoyage.org"
|
||||
, "bg.wikipedia.org"
|
||||
, "bg.wiktionary.org"
|
||||
, "bg.wikisource.org"
|
||||
, "bg.wikibooks.org"
|
||||
, "bg.wikiquote.org"
|
||||
, "bg.wikinews.org"
|
||||
, "el.wikipedia.org"
|
||||
, "el.wiktionary.org"
|
||||
, "el.wikisource.org"
|
||||
, "el.wikibooks.org"
|
||||
, "el.wikiversity.org"
|
||||
, "el.wikiquote.org"
|
||||
, "el.wikinews.org"
|
||||
, "el.wikivoyage.org"
|
||||
, "et.wikipedia.org"
|
||||
, "et.wiktionary.org"
|
||||
, "et.wikisource.org"
|
||||
, "et.wikibooks.org"
|
||||
, "et.wikiquote.org"
|
||||
, "et.wikimedia.org"
|
||||
, "eu.wikipedia.org"
|
||||
, "eu.wiktionary.org"
|
||||
, "eu.wikibooks.org"
|
||||
, "eu.wikiquote.org"
|
||||
, "gl.wikipedia.org"
|
||||
, "gl.wiktionary.org"
|
||||
, "gl.wikisource.org"
|
||||
, "gl.wikibooks.org"
|
||||
, "gl.wikiquote.org"
|
||||
, "he.wikipedia.org"
|
||||
, "he.wiktionary.org"
|
||||
, "he.wikisource.org"
|
||||
, "he.wikibooks.org"
|
||||
, "he.wikiquote.org"
|
||||
, "he.wikinews.org"
|
||||
, "he.wikivoyage.org"
|
||||
, "hr.wikipedia.org"
|
||||
, "hr.wiktionary.org"
|
||||
, "hr.wikisource.org"
|
||||
, "hr.wikibooks.org"
|
||||
, "hr.wikiquote.org"
|
||||
, "ms.wikipedia.org"
|
||||
, "ms.wiktionary.org"
|
||||
, "ms.wikibooks.org"
|
||||
, "nn.wikipedia.org"
|
||||
, "nn.wiktionary.org"
|
||||
, "nn.wikiquote.org"
|
||||
, "sh.wikipedia.org"
|
||||
, "sh.wiktionary.org"
|
||||
, "simple.wikipedia.org"
|
||||
, "simple.wiktionary.org"
|
||||
, "simple.wikibooks.org"
|
||||
, "simple.wikiquote.org"
|
||||
, "sl.wikipedia.org"
|
||||
, "sl.wiktionary.org"
|
||||
, "sl.wikisource.org"
|
||||
, "sl.wikibooks.org"
|
||||
, "sl.wikiversity.org"
|
||||
, "sl.wikiquote.org"
|
||||
, "th.wikipedia.org"
|
||||
, "th.wiktionary.org"
|
||||
, "th.wikisource.org"
|
||||
, "th.wikibooks.org"
|
||||
, "th.wikiquote.org"
|
||||
, "th.wikinews.org"
|
||||
, "vo.wikipedia.org"
|
||||
, "vo.wiktionary.org"
|
||||
, "vo.wikibooks.org"
|
||||
, "vo.wikiquote.org"
|
||||
, "hi.wikipedia.org"
|
||||
, "hi.wiktionary.org"
|
||||
, "hi.wikibooks.org"
|
||||
, "hi.wikiquote.org"
|
||||
, "ia.wikipedia.org"
|
||||
, "ia.wiktionary.org"
|
||||
, "ia.wikibooks.org"
|
||||
, "la.wikipedia.org"
|
||||
, "la.wiktionary.org"
|
||||
, "la.wikisource.org"
|
||||
, "la.wikibooks.org"
|
||||
, "la.wikiquote.org"
|
||||
, "aa.wikipedia.org"
|
||||
, "aa.wiktionary.org"
|
||||
, "aa.wikibooks.org"
|
||||
, "ab.wikipedia.org"
|
||||
, "ab.wiktionary.org"
|
||||
, "ace.wikipedia.org"
|
||||
, "af.wikipedia.org"
|
||||
, "af.wiktionary.org"
|
||||
, "af.wikibooks.org"
|
||||
, "af.wikiquote.org"
|
||||
, "ak.wikipedia.org"
|
||||
, "ak.wiktionary.org"
|
||||
, "ak.wikibooks.org"
|
||||
, "als.wikipedia.org"
|
||||
, "als.wiktionary.org"
|
||||
, "als.wikibooks.org"
|
||||
, "als.wikiquote.org"
|
||||
, "am.wikipedia.org"
|
||||
, "am.wiktionary.org"
|
||||
, "am.wikiquote.org"
|
||||
, "an.wikipedia.org"
|
||||
, "an.wiktionary.org"
|
||||
, "ang.wikipedia.org"
|
||||
, "ang.wiktionary.org"
|
||||
, "ang.wikisource.org"
|
||||
, "ang.wikibooks.org"
|
||||
, "ang.wikiquote.org"
|
||||
, "arc.wikipedia.org"
|
||||
, "arz.wikipedia.org"
|
||||
, "as.wikipedia.org"
|
||||
, "as.wiktionary.org"
|
||||
, "as.wikisource.org"
|
||||
, "as.wikibooks.org"
|
||||
, "ast.wikipedia.org"
|
||||
, "ast.wiktionary.org"
|
||||
, "ast.wikibooks.org"
|
||||
, "ast.wikiquote.org"
|
||||
, "av.wikipedia.org"
|
||||
, "av.wiktionary.org"
|
||||
, "ay.wikipedia.org"
|
||||
, "ay.wiktionary.org"
|
||||
, "ay.wikibooks.org"
|
||||
, "az.wikipedia.org"
|
||||
, "az.wiktionary.org"
|
||||
, "az.wikisource.org"
|
||||
, "az.wikibooks.org"
|
||||
, "az.wikiquote.org"
|
||||
, "ba.wikipedia.org"
|
||||
, "ba.wikibooks.org"
|
||||
, "bar.wikipedia.org"
|
||||
, "bat-smg.wikipedia.org"
|
||||
, "bcl.wikipedia.org"
|
||||
, "be.wikipedia.org"
|
||||
, "be.wiktionary.org"
|
||||
, "be.wikisource.org"
|
||||
, "be.wikibooks.org"
|
||||
, "be.wikiquote.org"
|
||||
, "be.wikimedia.org"
|
||||
, "be-x-old.wikipedia.org"
|
||||
, "bh.wikipedia.org"
|
||||
, "bh.wiktionary.org"
|
||||
, "bi.wikipedia.org"
|
||||
, "bi.wiktionary.org"
|
||||
, "bi.wikibooks.org"
|
||||
, "bjn.wikipedia.org"
|
||||
, "bm.wikipedia.org"
|
||||
, "bm.wiktionary.org"
|
||||
, "bm.wikibooks.org"
|
||||
, "bm.wikiquote.org"
|
||||
, "bn.wikipedia.org"
|
||||
, "bn.wiktionary.org"
|
||||
, "bn.wikisource.org"
|
||||
, "bn.wikibooks.org"
|
||||
, "bo.wikipedia.org"
|
||||
, "bo.wiktionary.org"
|
||||
, "bo.wikibooks.org"
|
||||
, "bpy.wikipedia.org"
|
||||
, "br.wikipedia.org"
|
||||
, "br.wiktionary.org"
|
||||
, "br.wikisource.org"
|
||||
, "br.wikiquote.org"
|
||||
, "br.wikimedia.org"
|
||||
, "bs.wikipedia.org"
|
||||
, "bs.wiktionary.org"
|
||||
, "bs.wikisource.org"
|
||||
, "bs.wikibooks.org"
|
||||
, "bs.wikiquote.org"
|
||||
, "bs.wikinews.org"
|
||||
, "bug.wikipedia.org"
|
||||
, "bxr.wikipedia.org"
|
||||
, "cbk-zam.wikipedia.org"
|
||||
, "cdo.wikipedia.org"
|
||||
, "ce.wikipedia.org"
|
||||
, "ceb.wikipedia.org"
|
||||
, "ch.wikipedia.org"
|
||||
, "ch.wiktionary.org"
|
||||
, "ch.wikibooks.org"
|
||||
, "cho.wikipedia.org"
|
||||
, "chr.wikipedia.org"
|
||||
, "chr.wiktionary.org"
|
||||
, "chy.wikipedia.org"
|
||||
, "ckb.wikipedia.org"
|
||||
, "co.wikipedia.org"
|
||||
, "co.wiktionary.org"
|
||||
, "co.wikibooks.org"
|
||||
, "co.wikiquote.org"
|
||||
, "co.wikimedia.org"
|
||||
, "cr.wikipedia.org"
|
||||
, "cr.wiktionary.org"
|
||||
, "cr.wikiquote.org"
|
||||
, "crh.wikipedia.org"
|
||||
, "csb.wikipedia.org"
|
||||
, "csb.wiktionary.org"
|
||||
, "cu.wikipedia.org"
|
||||
, "cv.wikipedia.org"
|
||||
, "cv.wikibooks.org"
|
||||
, "cy.wikipedia.org"
|
||||
, "cy.wiktionary.org"
|
||||
, "cy.wikisource.org"
|
||||
, "cy.wikibooks.org"
|
||||
, "cy.wikiquote.org"
|
||||
, "diq.wikipedia.org"
|
||||
, "dsb.wikipedia.org"
|
||||
, "dv.wikipedia.org"
|
||||
, "dv.wiktionary.org"
|
||||
, "dz.wikipedia.org"
|
||||
, "dz.wiktionary.org"
|
||||
, "ee.wikipedia.org"
|
||||
, "eml.wikipedia.org"
|
||||
, "ext.wikipedia.org"
|
||||
, "ff.wikipedia.org"
|
||||
, "fiu-vro.wikipedia.org"
|
||||
, "fj.wikipedia.org"
|
||||
, "fj.wiktionary.org"
|
||||
, "fo.wikipedia.org"
|
||||
, "fo.wiktionary.org"
|
||||
, "fo.wikisource.org"
|
||||
, "frp.wikipedia.org"
|
||||
, "frr.wikipedia.org"
|
||||
, "fur.wikipedia.org"
|
||||
, "fy.wikipedia.org"
|
||||
, "fy.wiktionary.org"
|
||||
, "fy.wikibooks.org"
|
||||
, "ga.wikipedia.org"
|
||||
, "ga.wiktionary.org"
|
||||
, "ga.wikibooks.org"
|
||||
, "ga.wikiquote.org"
|
||||
, "gag.wikipedia.org"
|
||||
, "gan.wikipedia.org"
|
||||
, "gd.wikipedia.org"
|
||||
, "gd.wiktionary.org"
|
||||
, "glk.wikipedia.org"
|
||||
, "gn.wikipedia.org"
|
||||
, "gn.wiktionary.org"
|
||||
, "gn.wikibooks.org"
|
||||
, "got.wikipedia.org"
|
||||
, "got.wikibooks.org"
|
||||
, "gu.wikipedia.org"
|
||||
, "gu.wiktionary.org"
|
||||
, "gu.wikisource.org"
|
||||
, "gu.wikibooks.org"
|
||||
, "gu.wikiquote.org"
|
||||
, "gv.wikipedia.org"
|
||||
, "gv.wiktionary.org"
|
||||
, "ha.wikipedia.org"
|
||||
, "ha.wiktionary.org"
|
||||
, "hak.wikipedia.org"
|
||||
, "haw.wikipedia.org"
|
||||
, "hif.wikipedia.org"
|
||||
, "ho.wikipedia.org"
|
||||
, "hsb.wikipedia.org"
|
||||
, "hsb.wiktionary.org"
|
||||
, "ht.wikipedia.org"
|
||||
, "ht.wikisource.org"
|
||||
, "hy.wikipedia.org"
|
||||
, "hy.wiktionary.org"
|
||||
, "hy.wikisource.org"
|
||||
, "hy.wikibooks.org"
|
||||
, "hy.wikiquote.org"
|
||||
, "hz.wikipedia.org"
|
||||
, "ie.wikipedia.org"
|
||||
, "ie.wiktionary.org"
|
||||
, "ie.wikibooks.org"
|
||||
, "ig.wikipedia.org"
|
||||
, "ii.wikipedia.org"
|
||||
, "ik.wikipedia.org"
|
||||
, "ik.wiktionary.org"
|
||||
, "ilo.wikipedia.org"
|
||||
, "io.wikipedia.org"
|
||||
, "io.wiktionary.org"
|
||||
, "is.wikipedia.org"
|
||||
, "is.wiktionary.org"
|
||||
, "is.wikisource.org"
|
||||
, "is.wikibooks.org"
|
||||
, "is.wikiquote.org"
|
||||
, "iu.wikipedia.org"
|
||||
, "iu.wiktionary.org"
|
||||
, "jbo.wikipedia.org"
|
||||
, "jbo.wiktionary.org"
|
||||
, "jv.wikipedia.org"
|
||||
, "jv.wiktionary.org"
|
||||
, "ka.wikipedia.org"
|
||||
, "ka.wiktionary.org"
|
||||
, "ka.wikibooks.org"
|
||||
, "ka.wikiquote.org"
|
||||
, "kaa.wikipedia.org"
|
||||
, "kab.wikipedia.org"
|
||||
, "kbd.wikipedia.org"
|
||||
, "kg.wikipedia.org"
|
||||
, "ki.wikipedia.org"
|
||||
, "kj.wikipedia.org"
|
||||
, "kl.wikipedia.org"
|
||||
, "kl.wiktionary.org"
|
||||
, "km.wikipedia.org"
|
||||
, "km.wiktionary.org"
|
||||
, "km.wikibooks.org"
|
||||
, "kn.wikipedia.org"
|
||||
, "kn.wiktionary.org"
|
||||
, "kn.wikisource.org"
|
||||
, "kn.wikibooks.org"
|
||||
, "kn.wikiquote.org"
|
||||
, "koi.wikipedia.org"
|
||||
, "kr.wikipedia.org"
|
||||
, "kr.wikiquote.org"
|
||||
, "krc.wikipedia.org"
|
||||
, "ks.wikipedia.org"
|
||||
, "ks.wiktionary.org"
|
||||
, "ks.wikibooks.org"
|
||||
, "ks.wikiquote.org"
|
||||
, "ksh.wikipedia.org"
|
||||
, "ku.wikipedia.org"
|
||||
, "ku.wiktionary.org"
|
||||
, "ku.wikibooks.org"
|
||||
, "ku.wikiquote.org"
|
||||
, "kv.wikipedia.org"
|
||||
, "kw.wikipedia.org"
|
||||
, "kw.wiktionary.org"
|
||||
, "kw.wikiquote.org"
|
||||
, "ky.wikipedia.org"
|
||||
, "ky.wiktionary.org"
|
||||
, "ky.wikibooks.org"
|
||||
, "ky.wikiquote.org"
|
||||
, "lad.wikipedia.org"
|
||||
, "lb.wikipedia.org"
|
||||
, "lb.wiktionary.org"
|
||||
, "lb.wikibooks.org"
|
||||
, "lb.wikiquote.org"
|
||||
, "lbe.wikipedia.org"
|
||||
, "lez.wikipedia.org"
|
||||
, "lg.wikipedia.org"
|
||||
, "li.wikipedia.org"
|
||||
, "li.wiktionary.org"
|
||||
, "li.wikisource.org"
|
||||
, "li.wikibooks.org"
|
||||
, "li.wikiquote.org"
|
||||
, "lij.wikipedia.org"
|
||||
, "lmo.wikipedia.org"
|
||||
, "ln.wikipedia.org"
|
||||
, "ln.wiktionary.org"
|
||||
, "ln.wikibooks.org"
|
||||
, "lo.wikipedia.org"
|
||||
, "lo.wiktionary.org"
|
||||
, "ltg.wikipedia.org"
|
||||
, "lv.wikipedia.org"
|
||||
, "lv.wiktionary.org"
|
||||
, "lv.wikibooks.org"
|
||||
, "mai.wikipedia.org"
|
||||
, "map-bms.wikipedia.org"
|
||||
, "mdf.wikipedia.org"
|
||||
, "mg.wikipedia.org"
|
||||
, "mg.wiktionary.org"
|
||||
, "mg.wikibooks.org"
|
||||
, "mh.wikipedia.org"
|
||||
, "mh.wiktionary.org"
|
||||
, "mhr.wikipedia.org"
|
||||
, "mi.wikipedia.org"
|
||||
, "mi.wiktionary.org"
|
||||
, "mi.wikibooks.org"
|
||||
, "min.wikipedia.org"
|
||||
, "mk.wikipedia.org"
|
||||
, "mk.wiktionary.org"
|
||||
, "mk.wikisource.org"
|
||||
, "mk.wikibooks.org"
|
||||
, "mk.wikimedia.org"
|
||||
, "ml.wikipedia.org"
|
||||
, "ml.wiktionary.org"
|
||||
, "ml.wikisource.org"
|
||||
, "ml.wikibooks.org"
|
||||
, "ml.wikiquote.org"
|
||||
, "mn.wikipedia.org"
|
||||
, "mn.wiktionary.org"
|
||||
, "mn.wikibooks.org"
|
||||
, "mo.wikipedia.org"
|
||||
, "mo.wiktionary.org"
|
||||
, "mr.wikipedia.org"
|
||||
, "mr.wiktionary.org"
|
||||
, "mr.wikisource.org"
|
||||
, "mr.wikibooks.org"
|
||||
, "mr.wikiquote.org"
|
||||
, "mrj.wikipedia.org"
|
||||
, "mt.wikipedia.org"
|
||||
, "mt.wiktionary.org"
|
||||
, "mus.wikipedia.org"
|
||||
, "mwl.wikipedia.org"
|
||||
, "my.wikipedia.org"
|
||||
, "my.wiktionary.org"
|
||||
, "my.wikibooks.org"
|
||||
, "myv.wikipedia.org"
|
||||
, "mzn.wikipedia.org"
|
||||
, "na.wikipedia.org"
|
||||
, "na.wiktionary.org"
|
||||
, "na.wikibooks.org"
|
||||
, "na.wikiquote.org"
|
||||
, "nah.wikipedia.org"
|
||||
, "nah.wiktionary.org"
|
||||
, "nah.wikibooks.org"
|
||||
, "nap.wikipedia.org"
|
||||
, "nds.wikipedia.org"
|
||||
, "nds.wiktionary.org"
|
||||
, "nds.wikibooks.org"
|
||||
, "nds.wikiquote.org"
|
||||
, "nds-nl.wikipedia.org"
|
||||
, "ne.wikipedia.org"
|
||||
, "ne.wiktionary.org"
|
||||
, "ne.wikibooks.org"
|
||||
, "new.wikipedia.org"
|
||||
, "ng.wikipedia.org"
|
||||
, "nov.wikipedia.org"
|
||||
, "nrm.wikipedia.org"
|
||||
, "nso.wikipedia.org"
|
||||
, "nv.wikipedia.org"
|
||||
, "ny.wikipedia.org"
|
||||
, "oc.wikipedia.org"
|
||||
, "oc.wiktionary.org"
|
||||
, "oc.wikibooks.org"
|
||||
, "om.wikipedia.org"
|
||||
, "om.wiktionary.org"
|
||||
, "or.wikipedia.org"
|
||||
, "or.wiktionary.org"
|
||||
, "or.wikisource.org"
|
||||
, "os.wikipedia.org"
|
||||
, "pa.wikipedia.org"
|
||||
, "pa.wiktionary.org"
|
||||
, "pa.wikibooks.org"
|
||||
, "pag.wikipedia.org"
|
||||
, "pam.wikipedia.org"
|
||||
, "pap.wikipedia.org"
|
||||
, "pcd.wikipedia.org"
|
||||
, "pdc.wikipedia.org"
|
||||
, "pfl.wikipedia.org"
|
||||
, "pi.wikipedia.org"
|
||||
, "pi.wiktionary.org"
|
||||
, "pih.wikipedia.org"
|
||||
, "pms.wikipedia.org"
|
||||
, "pnb.wikipedia.org"
|
||||
, "pnb.wiktionary.org"
|
||||
, "pnt.wikipedia.org"
|
||||
, "ps.wikipedia.org"
|
||||
, "ps.wiktionary.org"
|
||||
, "ps.wikibooks.org"
|
||||
, "qu.wikipedia.org"
|
||||
, "qu.wiktionary.org"
|
||||
, "qu.wikibooks.org"
|
||||
, "qu.wikiquote.org"
|
||||
, "rm.wikipedia.org"
|
||||
, "rm.wiktionary.org"
|
||||
, "rm.wikibooks.org"
|
||||
, "rmy.wikipedia.org"
|
||||
, "rn.wikipedia.org"
|
||||
, "rn.wiktionary.org"
|
||||
, "roa-rup.wikipedia.org"
|
||||
, "roa-rup.wiktionary.org"
|
||||
, "roa-tara.wikipedia.org"
|
||||
, "rue.wikipedia.org"
|
||||
, "rw.wikipedia.org"
|
||||
, "rw.wiktionary.org"
|
||||
, "sa.wikipedia.org"
|
||||
, "sa.wiktionary.org"
|
||||
, "sa.wikisource.org"
|
||||
, "sa.wikibooks.org"
|
||||
, "sa.wikiquote.org"
|
||||
, "sah.wikipedia.org"
|
||||
, "sah.wikisource.org"
|
||||
, "sc.wikipedia.org"
|
||||
, "sc.wiktionary.org"
|
||||
, "scn.wikipedia.org"
|
||||
, "scn.wiktionary.org"
|
||||
, "sco.wikipedia.org"
|
||||
, "sd.wikipedia.org"
|
||||
, "sd.wiktionary.org"
|
||||
, "sd.wikinews.org"
|
||||
, "se.wikipedia.org"
|
||||
, "se.wikibooks.org"
|
||||
, "se.wikimedia.org"
|
||||
, "sg.wikipedia.org"
|
||||
, "sg.wiktionary.org"
|
||||
, "si.wikipedia.org"
|
||||
, "si.wiktionary.org"
|
||||
, "si.wikibooks.org"
|
||||
, "sm.wikipedia.org"
|
||||
, "sm.wiktionary.org"
|
||||
, "sn.wikipedia.org"
|
||||
, "sn.wiktionary.org"
|
||||
, "so.wikipedia.org"
|
||||
, "so.wiktionary.org"
|
||||
, "sq.wikipedia.org"
|
||||
, "sq.wiktionary.org"
|
||||
, "sq.wikibooks.org"
|
||||
, "sq.wikiquote.org"
|
||||
, "sq.wikinews.org"
|
||||
, "srn.wikipedia.org"
|
||||
, "ss.wikipedia.org"
|
||||
, "ss.wiktionary.org"
|
||||
, "st.wikipedia.org"
|
||||
, "st.wiktionary.org"
|
||||
, "stq.wikipedia.org"
|
||||
, "su.wikipedia.org"
|
||||
, "su.wiktionary.org"
|
||||
, "su.wikibooks.org"
|
||||
, "su.wikiquote.org"
|
||||
, "sw.wikipedia.org"
|
||||
, "sw.wiktionary.org"
|
||||
, "sw.wikibooks.org"
|
||||
, "szl.wikipedia.org"
|
||||
, "ta.wikipedia.org"
|
||||
, "ta.wiktionary.org"
|
||||
, "ta.wikisource.org"
|
||||
, "ta.wikibooks.org"
|
||||
, "ta.wikiquote.org"
|
||||
, "ta.wikinews.org"
|
||||
, "te.wikipedia.org"
|
||||
, "te.wiktionary.org"
|
||||
, "te.wikisource.org"
|
||||
, "te.wikibooks.org"
|
||||
, "te.wikiquote.org"
|
||||
, "tet.wikipedia.org"
|
||||
, "tg.wikipedia.org"
|
||||
, "tg.wiktionary.org"
|
||||
, "tg.wikibooks.org"
|
||||
, "ti.wikipedia.org"
|
||||
, "ti.wiktionary.org"
|
||||
, "tk.wikipedia.org"
|
||||
, "tk.wiktionary.org"
|
||||
, "tk.wikibooks.org"
|
||||
, "tk.wikiquote.org"
|
||||
, "tl.wikipedia.org"
|
||||
, "tl.wiktionary.org"
|
||||
, "tl.wikibooks.org"
|
||||
, "tn.wikipedia.org"
|
||||
, "tn.wiktionary.org"
|
||||
, "to.wikipedia.org"
|
||||
, "to.wiktionary.org"
|
||||
, "tpi.wikipedia.org"
|
||||
, "tpi.wiktionary.org"
|
||||
, "ts.wikipedia.org"
|
||||
, "ts.wiktionary.org"
|
||||
, "tt.wikipedia.org"
|
||||
, "tt.wiktionary.org"
|
||||
, "tt.wikibooks.org"
|
||||
, "tt.wikiquote.org"
|
||||
, "tum.wikipedia.org"
|
||||
, "tw.wikipedia.org"
|
||||
, "tw.wiktionary.org"
|
||||
, "ty.wikipedia.org"
|
||||
, "tyv.wikipedia.org"
|
||||
, "udm.wikipedia.org"
|
||||
, "ug.wikipedia.org"
|
||||
, "ug.wiktionary.org"
|
||||
, "ug.wikibooks.org"
|
||||
, "ug.wikiquote.org"
|
||||
, "ur.wikipedia.org"
|
||||
, "ur.wiktionary.org"
|
||||
, "ur.wikibooks.org"
|
||||
, "ur.wikiquote.org"
|
||||
, "uz.wikipedia.org"
|
||||
, "uz.wiktionary.org"
|
||||
, "uz.wikibooks.org"
|
||||
, "uz.wikiquote.org"
|
||||
, "ve.wikipedia.org"
|
||||
, "vec.wikipedia.org"
|
||||
, "vec.wiktionary.org"
|
||||
, "vec.wikisource.org"
|
||||
, "vep.wikipedia.org"
|
||||
, "vls.wikipedia.org"
|
||||
, "wa.wikipedia.org"
|
||||
, "wa.wiktionary.org"
|
||||
, "wa.wikibooks.org"
|
||||
, "war.wikipedia.org"
|
||||
, "wo.wikipedia.org"
|
||||
, "wo.wiktionary.org"
|
||||
, "wo.wikiquote.org"
|
||||
, "wuu.wikipedia.org"
|
||||
, "xal.wikipedia.org"
|
||||
, "xh.wikipedia.org"
|
||||
, "xh.wiktionary.org"
|
||||
, "xh.wikibooks.org"
|
||||
, "xmf.wikipedia.org"
|
||||
, "yi.wikipedia.org"
|
||||
, "yi.wiktionary.org"
|
||||
, "yi.wikisource.org"
|
||||
, "yo.wikipedia.org"
|
||||
, "yo.wiktionary.org"
|
||||
, "yo.wikibooks.org"
|
||||
, "za.wikipedia.org"
|
||||
, "za.wiktionary.org"
|
||||
, "za.wikibooks.org"
|
||||
, "za.wikiquote.org"
|
||||
, "zea.wikipedia.org"
|
||||
, "zh-classical.wikipedia.org"
|
||||
, "zh-min-nan.wikipedia.org"
|
||||
, "zh-min-nan.wiktionary.org"
|
||||
, "zh-min-nan.wikisource.org"
|
||||
, "zh-min-nan.wikibooks.org"
|
||||
, "zh-min-nan.wikiquote.org"
|
||||
, "zh-yue.wikipedia.org"
|
||||
, "zu.wikipedia.org"
|
||||
, "zu.wiktionary.org"
|
||||
, "zu.wikibooks.org"
|
||||
, "gom.wikipedia.org"
|
||||
, "lrc.wikipedia.org"
|
||||
, "azb.wikipedia.org"
|
||||
, "ady.wikipedia.org"
|
||||
, "jam.wikipedia.org"
|
||||
, "tcy.wikipedia.org"
|
||||
, "olo.wikipedia.org"
|
||||
, "dty.wikipedia.org"
|
||||
, "pa.wikisource.org"
|
||||
, "atj.wikipedia.org"
|
||||
, "kbp.wikipedia.org"
|
||||
, "din.wikipedia.org"
|
||||
, "hi.wikiversity.org"
|
||||
};
|
||||
//, "als.wikisource.org"
|
||||
//, "als.wikinews.org"
|
||||
//, "nds.wikinews.org"
|
||||
//, "ba.wiktionary.org"
|
||||
//, "tokipona.wikibooks.org"
|
||||
//, "ve.wikimedia.org" // NOTE: moved:DATE:2015-04-06
|
||||
}
|
||||
|
||||
@@ -13,25 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_tid {
|
||||
public Xow_domain_tid(boolean multi_lang, int src, int tid, byte[] key_bry, byte[] abrv, byte[] domain_bry) {
|
||||
this.multi_lang = multi_lang; this.src = src; this.tid = tid; this.key_bry = key_bry; this.abrv = abrv; this.domain_bry = domain_bry;
|
||||
this.key_str = String_.new_u8(key_bry);
|
||||
}
|
||||
public boolean Multi_lang() {return multi_lang;} private final boolean multi_lang; // EX: y
|
||||
public int Src() {return src;} private final int src; // EX: 1 (wm,mw,wk,xo)
|
||||
public int Tid() {return tid;} private final int tid; // EX: 1 (Tid_wikipedia)
|
||||
public String Key_str() {return key_str;} private final String key_str; // EX: wikipedia
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry; // EX: wikipedia
|
||||
public byte[] Abrv() {return abrv;} private final byte[] abrv; // EX: w
|
||||
public byte[] Domain_bry() {return domain_bry;} private byte[] domain_bry; // EX: .wikipedia.org
|
||||
public byte[] Display_bry() {return Bry_.Ucase__1st(key_bry);} // EX: Wikipedia
|
||||
|
||||
public static final int
|
||||
Src__wmf = 1 // administered by wmf; wikipedia, etc.
|
||||
, Src__wikia = 2 // *.wikia.com
|
||||
, Src__mw = 3 // mediawiki installations not part of wmf, wikia
|
||||
, Src__xowa = 4 // xowa
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,107 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_tid_ {
|
||||
public static final int
|
||||
Tid__null = 0
|
||||
, Tid__wikipedia = 1
|
||||
, Tid__wiktionary = 2
|
||||
, Tid__wikisource = 3
|
||||
, Tid__wikivoyage = 4
|
||||
, Tid__wikiquote = 5
|
||||
, Tid__wikibooks = 6
|
||||
, Tid__wikiversity = 7
|
||||
, Tid__wikinews = 8
|
||||
, Tid__wikimedia = 9
|
||||
, Tid__species = 10
|
||||
, Tid__commons = 11
|
||||
, Tid__wikidata = 12
|
||||
, Tid__mediawiki = 13
|
||||
, Tid__meta = 14
|
||||
, Tid__incubator = 15
|
||||
, Tid__wmfblog = 16
|
||||
, Tid__home = 17
|
||||
, Tid__other = 18
|
||||
, Tid___len = 19
|
||||
;
|
||||
public static final String // SERIALIZED:xowa.gfs
|
||||
Str__wikipedia = "wikipedia"
|
||||
, Str__wiktionary = "wiktionary"
|
||||
, Str__wikisource = "wikisource"
|
||||
, Str__wikivoyage = "wikivoyage"
|
||||
, Str__wikiquote = "wikiquote"
|
||||
, Str__wikibooks = "wikibooks"
|
||||
, Str__wikiversity = "wikiversity"
|
||||
, Str__wikinews = "wikinews"
|
||||
, Str__wikimedia = "wikimedia"
|
||||
, Str__species = "species"
|
||||
, Str__commons = "commons"
|
||||
, Str__wikidata = "wikidata"
|
||||
, Str__mediawiki = "mediawiki"
|
||||
, Str__meta = "meta"
|
||||
, Str__incubator = "incubator"
|
||||
, Str__wmforg = "wikimediafoundation"
|
||||
, Str__home = "home"
|
||||
, Str__other = "other"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__wikipedia = Bry_.new_a7(Str__wikipedia)
|
||||
, Bry__wiktionary = Bry_.new_a7(Str__wiktionary)
|
||||
, Bry__wikisource = Bry_.new_a7(Str__wikisource)
|
||||
, Bry__wikivoyage = Bry_.new_a7(Str__wikivoyage)
|
||||
, Bry__wikiquote = Bry_.new_a7(Str__wikiquote)
|
||||
, Bry__wikibooks = Bry_.new_a7(Str__wikibooks)
|
||||
, Bry__wikiversity = Bry_.new_a7(Str__wikiversity)
|
||||
, Bry__wikinews = Bry_.new_a7(Str__wikinews)
|
||||
, Bry__wikimedia = Bry_.new_a7(Str__wikimedia)
|
||||
, Bry__species = Bry_.new_a7(Str__species)
|
||||
, Bry__commons = Bry_.new_a7(Str__commons)
|
||||
, Bry__wikidata = Bry_.new_a7(Str__wikidata)
|
||||
, Bry__mediawiki = Bry_.new_a7(Str__mediawiki)
|
||||
, Bry__meta = Bry_.new_a7(Str__meta)
|
||||
, Bry__incubator = Bry_.new_a7(Str__incubator)
|
||||
, Bry__wmforg = Bry_.new_a7(Str__wmforg)
|
||||
, Bry__home = Bry_.new_a7(Str__home)
|
||||
, Bry__other = Bry_.new_a7(Str__other)
|
||||
;
|
||||
private static final Xow_domain_tid[] ary = new Xow_domain_tid[Tid___len];
|
||||
private static final Hash_adp_bry type_regy = Hash_adp_bry.ci_a7(); // LOC:must go before new_()
|
||||
private static final Hash_adp_bry abrv_regy = Hash_adp_bry.cs(); // LOC:must go before new_()
|
||||
public static final Xow_domain_tid
|
||||
Itm__wikipedia = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikipedia , Bry__wikipedia , "w" , ".wikipedia.org")
|
||||
, Itm__wiktionary = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wiktionary , Bry__wiktionary , "d" , ".wiktionary.org")
|
||||
, Itm__wikisource = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikisource , Bry__wikisource , "s" , ".wikisource.org")
|
||||
, Itm__wikivoyage = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikivoyage , Bry__wikivoyage , "v" , ".wikivoyage.org")
|
||||
, Itm__wikiquote = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikiquote , Bry__wikiquote , "q" , ".wikiquote.org")
|
||||
, Itm__wikibooks = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikibooks , Bry__wikibooks , "b" , ".wikibooks.org")
|
||||
, Itm__wikiversity = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikiversity , Bry__wikiversity , "u" , ".wikiversity.org")
|
||||
, Itm__wikinews = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikinews , Bry__wikinews , "n" , ".wikinews.org")
|
||||
, Itm__wikimedia = new_(Bool_.Y , Xow_domain_tid.Src__wmf , Tid__wikimedia , Bry__wikimedia , "m" , ".wikimedia.org")
|
||||
, Itm__species = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__species , Bry__species , "species" , Xow_domain_itm_.Str__species)
|
||||
, Itm__commons = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__commons , Bry__commons , "c" , Xow_domain_itm_.Str__commons)
|
||||
, Itm__wikidata = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__wikidata , Bry__wikidata , "wd" , Xow_domain_itm_.Str__wikidata)
|
||||
, Itm__mediawiki = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__mediawiki , Bry__mediawiki , "mw" , Xow_domain_itm_.Str__mediawiki)
|
||||
, Itm__meta = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__meta , Bry__meta , "meta" , Xow_domain_itm_.Str__meta)
|
||||
, Itm__incubator = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__incubator , Bry__incubator , "qb" , Xow_domain_itm_.Str__incubator)
|
||||
, Itm__wmforg = new_(Bool_.N , Xow_domain_tid.Src__wmf , Tid__wmfblog , Bry__wmforg , "wmf" , Xow_domain_itm_.Str__wmforg)
|
||||
, Itm__home = new_(Bool_.N , Xow_domain_tid.Src__xowa, Tid__home , Bry__home , "home" , Xow_domain_itm_.Str__home)
|
||||
, Itm__other = new_(Bool_.N , Xow_domain_tid.Src__mw , Tid__other , Bry__other , "" , "")
|
||||
;
|
||||
private static Xow_domain_tid new_(boolean multi_lang, int src, int tid, byte[] key_bry, String abrv_xo_str, String domain_bry) {
|
||||
byte[] abrv_xo_bry = Bry_.new_u8(abrv_xo_str);
|
||||
Xow_domain_tid rv = new Xow_domain_tid(multi_lang, src, tid, key_bry, abrv_xo_bry, Bry_.new_u8(domain_bry));
|
||||
ary[tid] = rv;
|
||||
type_regy.Add(key_bry, rv);
|
||||
abrv_regy.Add(abrv_xo_bry, rv);
|
||||
return rv;
|
||||
}
|
||||
public static Xow_domain_tid Get_abrv_as_itm(byte[] src, int bgn, int end) {return (Xow_domain_tid)abrv_regy.Get_by_mid(src, bgn, end);}
|
||||
public static Xow_domain_tid Get_type_as_itm(int tid) {return ary[tid];}
|
||||
public static byte[] Get_type_as_bry(int tid) {return ary[tid].Key_bry();}
|
||||
public static int Get_type_as_tid(byte[] src) {return Get_type_as_tid(src, 0, src.length);}
|
||||
public static int Get_type_as_tid(byte[] src, int bgn, int end) {
|
||||
Object o = type_regy.Get_by_mid(src, bgn, end);
|
||||
return o == null ? Xow_domain_tid_.Tid__null : ((Xow_domain_tid)o).Tid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,88 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*;
|
||||
public class Xow_domain_uid_ {
|
||||
public static final int
|
||||
Tid_null = 0
|
||||
, Tid_xowa = 1
|
||||
, Tid_commons = 2
|
||||
, Tid_wikidata = 3
|
||||
, Tid_mediawiki = 20
|
||||
, Tid_meta = 21
|
||||
, Tid_incubator = 22
|
||||
, Tid_wmfblog = 23
|
||||
, Tid_species = 24
|
||||
;
|
||||
private static final int
|
||||
Tid_sub_wikipedia = 0
|
||||
, Tid_sub_wiktionary = 1
|
||||
, Tid_sub_wikisource = 2
|
||||
, Tid_sub_wikivoyage = 3
|
||||
, Tid_sub_wikiquote = 4
|
||||
, Tid_sub_wikibooks = 5
|
||||
, Tid_sub_wikiversity = 6
|
||||
, Tid_sub_wikinews = 7
|
||||
, Tid_sub_wikimedia = 8
|
||||
;
|
||||
private static final int Const_system_reserved = 100, Const_lang_reserved = 20;
|
||||
public static int To_int(Xow_domain_itm domain) {
|
||||
int domain_tid = 0;
|
||||
switch (domain.Domain_type_id()) {
|
||||
case Xow_domain_tid_.Tid__home: return Tid_xowa;
|
||||
case Xow_domain_tid_.Tid__commons: return Tid_commons;
|
||||
case Xow_domain_tid_.Tid__wikidata: return Tid_wikidata;
|
||||
case Xow_domain_tid_.Tid__mediawiki: return Tid_mediawiki;
|
||||
case Xow_domain_tid_.Tid__meta: return Tid_meta;
|
||||
case Xow_domain_tid_.Tid__incubator: return Tid_incubator;
|
||||
case Xow_domain_tid_.Tid__wmfblog: return Tid_wmfblog;
|
||||
case Xow_domain_tid_.Tid__species: return Tid_species;
|
||||
case Xow_domain_tid_.Tid__wikipedia: domain_tid = Tid_sub_wikipedia; break;
|
||||
case Xow_domain_tid_.Tid__wiktionary: domain_tid = Tid_sub_wiktionary; break;
|
||||
case Xow_domain_tid_.Tid__wikisource: domain_tid = Tid_sub_wikisource; break;
|
||||
case Xow_domain_tid_.Tid__wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
|
||||
case Xow_domain_tid_.Tid__wikiquote: domain_tid = Tid_sub_wikiquote; break;
|
||||
case Xow_domain_tid_.Tid__wikibooks: domain_tid = Tid_sub_wikibooks; break;
|
||||
case Xow_domain_tid_.Tid__wikiversity: domain_tid = Tid_sub_wikiversity; break;
|
||||
case Xow_domain_tid_.Tid__wikinews: domain_tid = Tid_sub_wikinews; break;
|
||||
case Xow_domain_tid_.Tid__wikimedia: domain_tid = Tid_sub_wikimedia; break;
|
||||
default: throw Err_.new_unhandled(domain.Domain_type_id());
|
||||
}
|
||||
return Const_system_reserved // reserve first 100 slots
|
||||
+ domain_tid // domain_tid assigned above
|
||||
+ (domain.Lang_actl_uid() * Const_lang_reserved) // reserve 20 wikis per lang
|
||||
;
|
||||
}
|
||||
public static Xow_domain_itm To_domain(int tid) {
|
||||
switch (tid) {
|
||||
case Tid_xowa: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__home, Xow_domain_tid_.Tid__home, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_commons: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__commons, Xow_domain_tid_.Tid__commons, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_wikidata: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wikidata, Xow_domain_tid_.Tid__commons, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_mediawiki: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__mediawiki, Xow_domain_tid_.Tid__mediawiki, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_meta: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__meta, Xow_domain_tid_.Tid__meta, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_incubator: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__incubator, Xow_domain_tid_.Tid__incubator, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_wmfblog: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wmforg, Xow_domain_tid_.Tid__wmfblog, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_species: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__species, Xow_domain_tid_.Tid__species, Xol_lang_stub_.Key__unknown);
|
||||
}
|
||||
int tmp = tid - Const_system_reserved;
|
||||
int lang_id = tmp / 20;
|
||||
int type_id = tmp % 20;
|
||||
int tid_int = 0; byte[] tid_bry = null;
|
||||
switch (type_id) {
|
||||
case Tid_sub_wikipedia: tid_int = Xow_domain_tid_.Tid__wikipedia; tid_bry = Xow_domain_tid_.Bry__wikipedia; break;
|
||||
case Tid_sub_wiktionary: tid_int = Xow_domain_tid_.Tid__wiktionary; tid_bry = Xow_domain_tid_.Bry__wiktionary; break;
|
||||
case Tid_sub_wikisource: tid_int = Xow_domain_tid_.Tid__wikisource; tid_bry = Xow_domain_tid_.Bry__wikisource; break;
|
||||
case Tid_sub_wikivoyage: tid_int = Xow_domain_tid_.Tid__wikivoyage; tid_bry = Xow_domain_tid_.Bry__wikivoyage; break;
|
||||
case Tid_sub_wikiquote: tid_int = Xow_domain_tid_.Tid__wikiquote; tid_bry = Xow_domain_tid_.Bry__wikiquote; break;
|
||||
case Tid_sub_wikibooks: tid_int = Xow_domain_tid_.Tid__wikibooks; tid_bry = Xow_domain_tid_.Bry__wikibooks; break;
|
||||
case Tid_sub_wikiversity: tid_int = Xow_domain_tid_.Tid__wikiversity; tid_bry = Xow_domain_tid_.Bry__wikiversity; break;
|
||||
case Tid_sub_wikinews: tid_int = Xow_domain_tid_.Tid__wikinews; tid_bry = Xow_domain_tid_.Bry__wikinews; break;
|
||||
case Tid_sub_wikimedia: tid_int = Xow_domain_tid_.Tid__wikimedia; tid_bry = Xow_domain_tid_.Bry__wikimedia; break;
|
||||
default: throw Err_.new_unhandled(type_id);
|
||||
}
|
||||
Xol_lang_stub lang = Xol_lang_stub_.Get_by_id(lang_id);
|
||||
byte[] domain_bry = Bry_.Add(lang.Key(), Byte_ascii.Dot_bry, tid_bry, Byte_ascii.Dot_bry, Xow_domain_itm_.Seg__org);
|
||||
return Xow_domain_itm.new_(domain_bry, tid_int, lang, lang.Key());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,23 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xow_domain_uid__tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_domain_uid__fxt fxt = new Xow_domain_uid__fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_tid_.Tid__commons);
|
||||
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_tid_.Tid__wikipedia);
|
||||
}
|
||||
}
|
||||
class Xow_domain_uid__fxt {
|
||||
public void Clear() {}
|
||||
public void Test(int tid, String domain_str, String expd_lang, int expd_tid) {
|
||||
byte[] domain_bry = Bry_.new_a7(domain_str);
|
||||
Xow_domain_itm actl_domain = Xow_domain_uid_.To_domain(tid);
|
||||
Tfds.Eq_bry(domain_bry , actl_domain.Domain_bry());
|
||||
Tfds.Eq_bry(Bry_.new_a7(expd_lang) , actl_domain.Lang_actl_key());
|
||||
Tfds.Eq(expd_tid , actl_domain.Domain_type_id());
|
||||
Tfds.Eq(tid, Xow_domain_uid_.To_int(actl_domain));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_itm cur, Xow_domain_itm comp);
|
||||
}
|
||||
|
||||
@@ -13,50 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_ {
|
||||
public static final Xow_domain_crt_itm Null = null;
|
||||
}
|
||||
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_itm cur, Xow_domain_itm 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_itm cur, Xow_domain_itm comp) {
|
||||
switch (comp.Domain_type_id()) {
|
||||
case Xow_domain_tid_.Tid__wikipedia:
|
||||
case Xow_domain_tid_.Tid__wiktionary:
|
||||
case Xow_domain_tid_.Tid__wikisource:
|
||||
case Xow_domain_tid_.Tid__wikivoyage:
|
||||
case Xow_domain_tid_.Tid__wikiquote:
|
||||
case Xow_domain_tid_.Tid__wikibooks:
|
||||
case Xow_domain_tid_.Tid__wikiversity:
|
||||
case Xow_domain_tid_.Tid__wikinews: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static final Xow_domain_crt_itm__any_standard Instance = new Xow_domain_crt_itm__any_standard(); Xow_domain_crt_itm__any_standard() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__lang implements Xow_domain_crt_itm {
|
||||
private final byte[] lang_key;
|
||||
public Xow_domain_crt_itm__lang(byte[] lang_key) {this.lang_key = lang_key;}
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(comp.Lang_orig_key(), lang_key);}
|
||||
}
|
||||
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_itm cur, Xow_domain_itm comp) {return comp.Domain_type_id() == 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_itm cur, Xow_domain_itm comp) {return Bry_.Eq(comp.Domain_bry(), domain);}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_itm cur, Xow_domain_itm comp) {return true;}
|
||||
public static final Xow_domain_crt_itm__any_wiki Instance = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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__none implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return false;}
|
||||
public static final Xow_domain_crt_itm__none Instance = new Xow_domain_crt_itm__none(); Xow_domain_crt_itm__none() {}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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__same_lang implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(cur.Lang_orig_key(), comp.Lang_orig_key());}
|
||||
public static final Xow_domain_crt_itm__same_lang Instance = new Xow_domain_crt_itm__same_lang(); Xow_domain_crt_itm__same_lang() {}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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__same_type implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return cur.Domain_type_id() == comp.Domain_type_id();}
|
||||
public static final Xow_domain_crt_itm__same_type Instance = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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__self implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return Bry_.Eq(cur.Domain_bry(), comp.Domain_bry());}
|
||||
public static final Xow_domain_crt_itm__self Instance = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
|
||||
}
|
||||
|
||||
@@ -13,77 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_itm[] Parse_as_kv_itms_or_null(byte[] raw) {
|
||||
List_adp rv = Parse_as_obj_or_null(raw, Bool_.N);
|
||||
return rv == null ? null : (Xow_domain_crt_kv_itm[])rv.To_ary_and_clear(Xow_domain_crt_kv_itm.class);
|
||||
}
|
||||
public Xow_domain_crt_kv_ary[] Parse_as_kv_arys_or_null(byte[] raw) {
|
||||
List_adp rv = Parse_as_obj_or_null(raw, Bool_.Y);
|
||||
return rv == null ? null : (Xow_domain_crt_kv_ary[])rv.To_ary_and_clear(Xow_domain_crt_kv_ary.class);
|
||||
}
|
||||
public List_adp Parse_as_obj_or_null(byte[] raw, boolean is_ary) {
|
||||
List_adp rv = List_adp_.New();
|
||||
byte[][] line_ary = Bry_split_.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_.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.Instance.Parse_as_in(word_ary[0]);
|
||||
if (key_itm == Xow_domain_crt_itm_.Null) return null; // invalid key; exit;
|
||||
if (is_ary) {
|
||||
Xow_domain_crt_itm[] ary_itm = Xow_domain_crt_itm_parser.Instance.Parse_as_ary(word_ary[1]);
|
||||
if (ary_itm == null) return null;
|
||||
rv.Add(new Xow_domain_crt_kv_ary(key_itm, ary_itm));
|
||||
}
|
||||
else {
|
||||
Xow_domain_crt_itm val_itm = Xow_domain_crt_itm_parser.Instance.Parse_as_in(word_ary[1]);
|
||||
if (val_itm == Xow_domain_crt_itm_.Null) return null; // invalid val; exit;
|
||||
rv.Add(new Xow_domain_crt_kv_itm(key_itm, val_itm));
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xow_domain_crt_itm Parse_as_in(byte[] raw) {
|
||||
Xow_domain_crt_itm[] in_ary = Parse_as_ary(raw);
|
||||
return in_ary == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__in(in_ary);
|
||||
}
|
||||
public Xow_domain_crt_itm[] Parse_as_ary(byte[] raw) {
|
||||
byte[][] terms = Bry_split_.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) {
|
||||
Xow_domain_crt_itm itm = Parse_itm(terms[i]);
|
||||
if (itm == Xow_domain_crt_itm_.Null) return null; // invalid val; exit;
|
||||
rv_ary[i] = itm;
|
||||
}
|
||||
return 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_.Has_at_bgn(raw, Wild_lang)) { // EX: *.wikipedia
|
||||
int wiki_tid = Xow_domain_tid_.Get_type_as_tid(raw, Wild_lang.length, raw_len);
|
||||
return wiki_tid == Xow_domain_tid_.Tid__null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__type(wiki_tid);
|
||||
}
|
||||
else if (Bry_.Has_at_end(raw, Wild_type)) { // EX: en.*
|
||||
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_null(raw, 0, raw_len - Wild_type.length);
|
||||
return lang_itm == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__lang(lang_itm.Key());
|
||||
}
|
||||
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.Instance)
|
||||
.Add_str_obj("<same_type>" , Xow_domain_crt_itm__same_type.Instance)
|
||||
.Add_str_obj("<same_lang>" , Xow_domain_crt_itm__same_lang.Instance)
|
||||
.Add_str_obj("<any>" , Xow_domain_crt_itm__any_wiki.Instance)
|
||||
;
|
||||
private static final byte[] Wild_lang = Bry_.new_a7("*."), Wild_type = Bry_.new_a7(".*");
|
||||
public static final Xow_domain_crt_itm_parser Instance = new Xow_domain_crt_itm_parser(); Xow_domain_crt_itm_parser() {}
|
||||
}
|
||||
|
||||
@@ -13,53 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
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_itm_mgr {
|
||||
private final List_adp list = List_adp_.New();
|
||||
public void Clear() {list.Clear();}
|
||||
@gplx.Internal protected void Add(Xow_domain_crt_kv_itm itm) {list.Add(itm);}
|
||||
public boolean Parse_as_itms(byte[] raw) {
|
||||
this.Clear();
|
||||
Xow_domain_crt_kv_itm[] ary = Xow_domain_crt_itm_parser.Instance.Parse_as_kv_itms_or_null(raw);
|
||||
if (ary == null) return false; // invalid parse; leave current value as is and exit;
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
this.Add(ary[i]);
|
||||
return true;
|
||||
}
|
||||
public boolean Parse_as_arys(byte[] raw) {
|
||||
this.Clear();
|
||||
Xow_domain_crt_kv_ary[] ary = Xow_domain_crt_itm_parser.Instance.Parse_as_kv_arys_or_null(raw);
|
||||
if (ary == null) return false; // invalid parse; leave current value as is and exit;
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
list.Add(ary[i]);
|
||||
return true;
|
||||
}
|
||||
public Xow_domain_crt_itm Find_itm(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_kv_itm kv = (Xow_domain_crt_kv_itm)list.Get_at(i);
|
||||
if (kv.Key().Matches(cur, comp)) return kv.Val();
|
||||
}
|
||||
return Xow_domain_crt_itm__none.Instance;
|
||||
}
|
||||
public Xow_domain_crt_itm[] Find_ary(Xow_domain_itm cur, Xow_domain_itm comp) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_domain_crt_kv_ary kv = (Xow_domain_crt_kv_ary)list.Get_at(i);
|
||||
if (kv.Key().Matches(cur, comp)) return kv.Val();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class Xow_domain_crt_kv_itm {
|
||||
public Xow_domain_crt_kv_itm(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;
|
||||
}
|
||||
class Xow_domain_crt_kv_ary {
|
||||
public Xow_domain_crt_kv_ary(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;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.fsys; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.apps.fsys.*;
|
||||
import gplx.xowa.users.*;
|
||||
public class Xow_fsys_mgr {
|
||||
public Xow_fsys_mgr(Io_url root_dir, Io_url file_dir) {
|
||||
this.root_dir = root_dir; this.file_dir = file_dir; this.tmp_dir = root_dir.GenSubDir("tmp");
|
||||
}
|
||||
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
|
||||
public Io_url File_dir() {return file_dir;} private final Io_url file_dir;
|
||||
public Io_url Tmp_dir() {return tmp_dir;} private final Io_url tmp_dir;
|
||||
}
|
||||
|
||||
@@ -13,19 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.langs.gfs.*;
|
||||
public class Bfmtr_eval_wiki implements Bry_fmtr_eval_mgr {
|
||||
public Bfmtr_eval_wiki(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public boolean Enabled() {return enabled;} public void Enabled_(boolean v) {enabled = v;} private boolean enabled = true;
|
||||
public byte[] Eval(byte[] cmd) {
|
||||
Object rslt = GfsCore.Instance.Exec_bry(cmd, wiki);
|
||||
return Bry_.new_u8(Object_.Xto_str_strict_or_null_mark(rslt));
|
||||
}
|
||||
public void Eval_mgr_(Bry_fmtr... fmtrs) {
|
||||
int fmtrs_len = fmtrs.length;
|
||||
for (int i = 0; i < fmtrs_len; i++)
|
||||
fmtrs[i].Eval_mgr_(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,22 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_html_util implements Gfo_invk {
|
||||
public Xow_html_util(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_if_bool)) return If_bool(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else if (ctx.Match(k, Invk_if_yn)) return If_yn(m.ReadStr("expr"), m.ReadStr("true_val"), m.ReadStr("false_val"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_if_bool = "if_bool", Invk_if_yn = "if_yn";
|
||||
String If_bool(String expr, String true_val, String false_val) {
|
||||
Object o = wiki.Appe().Gfs_mgr().Run_str(expr);
|
||||
try {return Bool_.Cast(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
String If_yn(String expr, String true_val, String false_val) {
|
||||
String o = String_.as_(wiki.Appe().Gfs_mgr().Run_str(expr));
|
||||
try {return Yn.parse(o) ? true_val : false_val;}
|
||||
catch (Exception e) {Err_.Noop(e); return "expr failed: " + expr;}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,45 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.brys.fmtrs.*; import gplx.core.envs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
public class Xow_script_mgr implements Gfo_invk {
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_set)) Set(m.ReadBry("key"), m.ReadBry("wiki_type"), m.ReadBry("script"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_set = "set";
|
||||
public void Exec(Xowe_wiki wiki) {
|
||||
int len = hash.Count();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_script_itm itm = (Xow_script_itm)hash.Get_at(i);
|
||||
int wiki_tid = wiki.Domain_tid();
|
||||
if (Int_.In(wiki_tid, itm.Wiki_tids())) // wiki_tid matches itm
|
||||
itm.Fmtr().Bld_bfr_many(bfr, wiki.Domain_bry(), Xow_domain_tid_.Get_type_as_bry(wiki_tid), wiki.Lang().Key_bry());
|
||||
}
|
||||
String gfs_script = String_.Replace(bfr.To_str_and_clear(), Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
|
||||
wiki.Appe().Gfs_mgr().Run_str(gfs_script);
|
||||
bfr.Mkr_rls();
|
||||
}
|
||||
public void Set(byte[] key, byte[] wiki_types_raw, byte[] script) {
|
||||
byte[][] wiki_tid_names = Bry_split_.Split(wiki_types_raw, Byte_ascii.Tilde);
|
||||
int len = wiki_tid_names.length;
|
||||
int[] wiki_tids = new int[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
wiki_tids[i] = Xow_domain_tid_.Get_type_as_tid(wiki_tid_names[i]);
|
||||
|
||||
Xow_script_itm itm = new Xow_script_itm(key, wiki_tids, script);
|
||||
hash.Add_if_dupe_use_nth(itm.Key(), itm);
|
||||
}
|
||||
public Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
}
|
||||
class Xow_script_itm {
|
||||
public Xow_script_itm(byte[] key, int[] wiki_tids, byte[] script) {
|
||||
this.key = key; this.wiki_tids = wiki_tids; this.fmtr = Bry_fmtr.new_bry_(script, "wiki_key", "wiki_type_name", "wiki_lang");
|
||||
}
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public int[] Wiki_tids() {return wiki_tids;} private int[] wiki_tids;
|
||||
public Bry_fmtr Fmtr() {return fmtr;} Bry_fmtr fmtr;
|
||||
}
|
||||
|
||||
@@ -13,19 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_sys_cfg implements Gfo_invk {
|
||||
public Xow_sys_cfg(Xowe_wiki wiki) {}
|
||||
public boolean Xowa_cmd_enabled() {return xowa_cmd_enabled;} public Xow_sys_cfg Xowa_cmd_enabled_(boolean v) {xowa_cmd_enabled = v; return this;} private boolean xowa_cmd_enabled;
|
||||
public boolean Xowa_proto_enabled() {return xowa_proto_enabled;} public Xow_sys_cfg Xowa_proto_enabled_(boolean v) {xowa_proto_enabled = v; return this;} private boolean xowa_proto_enabled;
|
||||
public void Copy(Xow_sys_cfg src) {
|
||||
this.xowa_cmd_enabled = src.xowa_cmd_enabled;
|
||||
this.xowa_proto_enabled = src.xowa_proto_enabled;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, "xowa_cmd_enabled_")) xowa_cmd_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, "xowa_proto_enabled_")) xowa_proto_enabled = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_user implements Gfo_invk {
|
||||
public byte[] Name() {return name;} private byte[] name = Bry_.new_a7("anonymous");
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_name_ = "name_";
|
||||
}
|
||||
|
||||
@@ -13,83 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xow_wiki_props {
|
||||
// MW props for Pfunc_wiki_props and Scrib_lib; EX: {{SITENAME}}
|
||||
public byte[] Site_name() {return site_name;} private byte[] site_name = Bry_.Empty;
|
||||
public byte[] Server_name() {return server_name;} private byte[] server_name = Bry_.new_a7("localhost");
|
||||
public byte[] Server() {return server;} private byte[] server = Bry_.new_a7("http://localhost");
|
||||
public byte[] Article_path() {return article_path;} private byte[] article_path = Xoh_href_.Bry__wiki;
|
||||
public byte[] Script_path() {return script_path;} private byte[] script_path = Bry_.new_a7("/wiki");
|
||||
public byte[] Style_path() {return style_path;} private byte[] style_path = Bry_.new_a7("/wiki/skins");
|
||||
public byte[] Content_language() {return content_language;} private byte[] content_language = Bry_.Empty;
|
||||
public byte[] Direction_mark() {return direction_mark;} private byte[] direction_mark = Bry_.Empty;
|
||||
public byte[] Current_version() {return CURRENT_VERSION;} private static final byte[] CURRENT_VERSION = Bry_.new_a7("1.21wmf11"); // approximate level of compatibility
|
||||
|
||||
// XO props
|
||||
public byte Protocol_tid() {return protocol_tid;} private final byte protocol_tid = gplx.core.net.Gfo_protocol_itm.Tid_https; // NOTE: default protocol to https; handles external links like [//a.org]; may need to be changed for wikia or other non-WMF wikis; DATE:2015-07-27
|
||||
public byte[] Main_page() {return main_page;} private byte[] main_page = Xoa_page_.Main_page_bry; // HACK: default to Main_Page b/c some code tries to do Xoa_ttl.Parse() which will not work with ""; DATE:2014-02-16
|
||||
public byte[] Bldr_version() {return bldr_version;} private byte[] bldr_version = Bry_.Empty;
|
||||
public int Css_version() {return css_version;} private int css_version = 1;
|
||||
public byte[] Siteinfo_misc() {return siteinfo_misc;} private byte[] siteinfo_misc = Bry_.Empty;
|
||||
public byte[] Siteinfo_mainpage() {return siteinfo_mainpage;} private byte[] siteinfo_mainpage = Bry_.Empty;
|
||||
public DateAdp Modified_latest() {return modified_latest;} private DateAdp modified_latest;
|
||||
public String Modified_latest__yyyy_MM_dd() {return modified_latest == null ? "" : modified_latest.XtoStr_fmt_yyyy_MM_dd();}
|
||||
|
||||
// setters
|
||||
public void ContentLanguage_ (byte[] v) {content_language = v;}
|
||||
public void Bldr_version_ (byte[] v) {bldr_version = v;}
|
||||
public void Main_page_ (byte[] v) {main_page = v;}
|
||||
public void Siteinfo_mainpage_(byte[] v) {siteinfo_mainpage = v;}
|
||||
public void Siteinfo_misc_(byte[] v) {
|
||||
if (v == null) return; // exit else will fail for personal wikis which don't have a siteinfo_misc
|
||||
this.siteinfo_misc = v;
|
||||
int pipe_0 = Bry_find_.Find_fwd(v, Byte_ascii.Pipe);
|
||||
if (pipe_0 != Bry_find_.Not_found)
|
||||
this.site_name = Bry_.Mid(siteinfo_misc, 0, pipe_0);
|
||||
}
|
||||
|
||||
// Init_by_ctor initializes by domain_name, not by db
|
||||
public void Init_by_ctor(int domain_tid, byte[] domain_bry) {
|
||||
// initialize site_name to something based on domain_tid; EX: "Wikipedia"
|
||||
// note that "home" becomes "Home"; will be changed back to "home" in Init_by_load_2
|
||||
this.site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_tid_.Get_type_as_bry(domain_tid))));
|
||||
|
||||
// server_name is domain; EX: "en.wikipedia.org"
|
||||
this.server_name = domain_bry;
|
||||
|
||||
// server_name is https: + domain EX: "https://en.wikipedia.org"
|
||||
this.server = Bry_.Add(gplx.core.net.Gfo_protocol_itm.Itm_https.Text_bry(), domain_bry);
|
||||
}
|
||||
// Init_by_load initializes by db; called after Init_by_ctor but before Init_by_load_2; should be replaced by Init_by_load_2, but leaving as separate proc b/c of "if (app.Bldr__running())"; DATE:2017-02-17
|
||||
public void Init_by_load(Xoa_app app, gplx.dbs.cfgs.Db_cfg_tbl cfg_tbl) {
|
||||
if (app.Bldr__running()) return; // never load main_page during bldr; note that Init_by_load is called by bldr cmds like css; DATE:2015-07-24
|
||||
|
||||
// load from xowa_cfg
|
||||
this.main_page = cfg_tbl.Select_bry_or (Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__main_page, null);
|
||||
if (main_page == null) { // main_page not found
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "mw_props.load; main_page not found; conn=~{0}", cfg_tbl.Conn().Conn_info().Db_api());
|
||||
this.main_page = Xoa_page_.Main_page_bry;
|
||||
}
|
||||
|
||||
this.modified_latest = cfg_tbl.Select_date_or(Xowd_cfg_key_.Grp__wiki_init, Xowd_cfg_key_.Key__init__modified_latest, null);
|
||||
}
|
||||
// Init_by_load_2 is called by Xodb_load_mgr_sql; note that it might be called during bldr; DATE:2017-02-17
|
||||
public void Init_by_load_2(byte[] main_page, byte[] bldr_version, byte[] siteinfo_misc, byte[] siteinfo_mainpage, DateAdp modified_latest) {
|
||||
this.main_page = main_page;
|
||||
if (main_page == null) { // main_page not found
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "mw_props.load; main_page not found2");
|
||||
this.main_page = Xoa_page_.Main_page_bry;
|
||||
}
|
||||
|
||||
this.bldr_version = bldr_version;
|
||||
this.siteinfo_mainpage = siteinfo_mainpage;
|
||||
this.modified_latest = modified_latest;
|
||||
|
||||
// note that Siteinfo_misc_ must be called b/c site_name should come from xowa_cfg / dump.xml's siteinfo_misc, not Init_by_ctor's Get_type_as_bry
|
||||
// doing "this.siteinfo_misc = siteinfo_misc" will cause "home" to be "Home" and diag will fail; DATE:2017-02-21
|
||||
this.Siteinfo_misc_(siteinfo_misc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_module_base implements Gfo_invk {
|
||||
public byte Enabled() {return enabled;} private byte enabled = Bool_.__byte;
|
||||
public boolean Enabled_y() {return enabled == Bool_.Y_byte;}
|
||||
public boolean Enabled_n() {return enabled == Bool_.N_byte;}
|
||||
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_enabled)) return Yn.To_nullable_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) enabled = Yn.To_nullable_byte(m.ReadStr("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
|
||||
}
|
||||
|
||||
@@ -13,40 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.modules.popups.*;
|
||||
public class Xow_module_mgr implements Gfo_invk {
|
||||
private Hash_adp_bry regy = Hash_adp_bry.cs();
|
||||
public Xow_module_mgr(Xowe_wiki wiki) {
|
||||
this.popup_mgr = new Xow_popup_mgr(wiki);
|
||||
regy.Add_bry_obj(Xoh_head_itm_.Key__top_icon , itm__top_icon);
|
||||
regy.Add_bry_obj(Xoh_head_itm_.Key__navframe , itm__navframe);
|
||||
regy.Add_bry_obj(Xoh_head_itm_.Key__title_rewrite , itm__title_rewrite);
|
||||
}
|
||||
public boolean Collapsible__toc() {return collapsible__toc;} private boolean collapsible__toc;
|
||||
public boolean Collapsible__collapsible() {return collapsible__collapsible;} private boolean collapsible__collapsible;
|
||||
public boolean Collapsible__navframe() {return collapsible__navframe;} private boolean collapsible__navframe;
|
||||
public Xow_module_base Itm__top_icon() {return itm__top_icon;} private Xow_module_base itm__top_icon = new Xow_module_base();
|
||||
public Xow_module_base Itm__navframe() {return itm__navframe;} private Xow_module_base itm__navframe = new Xow_module_base();
|
||||
public Xow_module_base Itm__title_rewrite() {return itm__title_rewrite;} private Xow_module_base itm__title_rewrite = new Xow_module_base();
|
||||
public Xow_popup_mgr Popup_mgr() {return popup_mgr;} private Xow_popup_mgr popup_mgr;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
popup_mgr.Init_by_wiki(wiki);
|
||||
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__collapsible__toc, Cfg__collapsible__collapsible, Cfg__collapsible__navframe);
|
||||
}
|
||||
public Xow_module_base Get(byte[] key) {return (Xow_module_base)regy.Get_by_bry(key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Cfg__collapsible__toc)) collapsible__toc = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Cfg__collapsible__collapsible)) collapsible__collapsible = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Cfg__collapsible__navframe)) collapsible__navframe = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_get = "get";
|
||||
|
||||
private static final String
|
||||
Cfg__collapsible__toc = "xowa.html.collapsibles.toc"
|
||||
, Cfg__collapsible__collapsible = "xowa.html.collapsibles.navbox"
|
||||
, Cfg__collapsible__navframe = "xowa.html.collapsibles.navframe"
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,95 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.cmds.*; import gplx.xowa.apps.utls.*;
|
||||
public class Xow_ns implements Gfo_invk {
|
||||
public Xow_ns(int id, byte case_match, byte[] name, boolean is_alias) {
|
||||
this.id = id; this.case_match = case_match; this.is_alias = is_alias;
|
||||
Name_bry_(name);
|
||||
}
|
||||
public void Name_bry_(byte[] v) {
|
||||
if (id == Xow_ns_.Tid__main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test"
|
||||
this.name_db_str = "";
|
||||
this.name_db = Bry_.Empty;
|
||||
this.name_db_w_colon = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
this.name_db = v;
|
||||
this.name_db_w_colon = Bry_.Add(v, Byte_ascii.Colon);
|
||||
this.name_db_str = String_.new_u8(v);
|
||||
}
|
||||
this.num_str = Int_.To_str_pad_bgn_zero(id, 3);
|
||||
this.num_bry = Bry_.new_a7(num_str);
|
||||
synchronized (url_encoder) { // LOCK:static-obj
|
||||
this.name_enc = url_encoder.Encode(name_db);
|
||||
}
|
||||
this.name_ui = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
this.name_ui_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
}
|
||||
public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
|
||||
public byte[] Name_db() {return name_db;} private byte[] name_db;
|
||||
public byte[] Name_db_w_colon() {return name_db_w_colon;} private byte[] name_db_w_colon;
|
||||
public String Name_db_str() {return name_db_str;} private String name_db_str;
|
||||
public byte[] Name_ui() {return name_ui;} private byte[] name_ui;
|
||||
public byte[] Name_ui_w_colon() {return name_ui_w_colon;} private byte[] name_ui_w_colon; // PERF: for Xoa_ttl
|
||||
public byte[] Name_enc() {return name_enc;} private byte[] name_enc;
|
||||
public byte[] Name_combo() {return id == Xow_ns_.Tid__main ? Xow_ns_.Bry__main: name_ui;} // for combo boxes; namely "(Main)"
|
||||
public String Num_str() {return num_str;} private String num_str;
|
||||
public byte[] Num_bry() {return num_bry;} private byte[] num_bry;
|
||||
public int Id() {return id;} private int id;
|
||||
public int Id_subj_id() {if (id < 0) return id; return Id_is_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject
|
||||
public int Id_talk_id() {if (id < 0) return id; return Id_is_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk
|
||||
public int Id_alt_id() {if (id < 0) return id; return Id_is_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk
|
||||
public boolean Id_is_subj() {return !Id_is_talk();} // REF.MW: Namespace.php|isMain
|
||||
public boolean Id_is_talk() {return id > Xow_ns_.Tid__main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk
|
||||
public boolean Id_is_media() {return id == Xow_ns_.Tid__media;}
|
||||
public boolean Id_is_special() {return id == Xow_ns_.Tid__special;}
|
||||
public boolean Id_is_main() {return id == Xow_ns_.Tid__main;}
|
||||
public boolean Id_is_file() {return id == Xow_ns_.Tid__file;}
|
||||
public boolean Id_is_file_or_media() {return id == Xow_ns_.Tid__file || id == Xow_ns_.Tid__media;}
|
||||
public boolean Id_is_tmpl() {return id == Xow_ns_.Tid__template;}
|
||||
public boolean Id_is_ctg() {return id == Xow_ns_.Tid__category;}
|
||||
public boolean Id_is_module() {return id == Xow_ns_.Tid__module;}
|
||||
public int Ord() {return ord;} public void Ord_(int v) {this.ord = v;} private int ord;
|
||||
public int Ord_subj_id() {if (id < 0) return ord; return Id_is_talk() ? ord - 1 : ord;} // id< 0: special/media returns self
|
||||
public int Ord_talk_id() {if (id < 0) return ord; return Id_is_talk() ? ord : ord + 1;}
|
||||
public byte Case_match() {return case_match;} public void Case_match_(byte v) {case_match = v;} private byte case_match;
|
||||
public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Tid__special; only Special, Media does not have subpages; DATE:2013-10-07
|
||||
public Xow_ns Subpages_enabled_(boolean v) {subpages_enabled = v; return this;}
|
||||
public boolean Is_gender_aware() {return id == Xow_ns_.Tid__user || id == Xow_ns_.Tid__user_talk;} // ASSUME: only User, User_talk are gender aware
|
||||
public boolean Is_capitalized() {return false;} // ASSUME: always false (?)
|
||||
public boolean Is_content() {return id == Xow_ns_.Tid__main;} // ASSUME: only Main
|
||||
public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?)
|
||||
public boolean Is_movable() {return id > Xow_ns_.Tid__special;} // ASSUME: only Special, Media cannot move (be renamed?)
|
||||
public boolean Is_meta() {return id < Xow_ns_.Tid__main;} // ASSUME: only Special, Media
|
||||
public boolean Is_alias() {return is_alias;} private boolean is_alias;
|
||||
public int Count() {return count;} public Xow_ns Count_(int v) {count = v; return this;} private int count;
|
||||
public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Tid__main ? page : Bry_.Add(name_db_w_colon, page);}
|
||||
public void Aliases_add(String alias) {
|
||||
if (String_.Eq(alias, name_db_str)) return;
|
||||
if (aliases == null) aliases = Ordered_hash_.New();
|
||||
aliases.Add_if_dupe_use_1st(alias, alias);
|
||||
} private Ordered_hash aliases;
|
||||
public Keyval[] Aliases_as_scrib_ary() { // NOTE: intended for Scrib_lib_site; DATE:2014-02-15
|
||||
if (aliases == null) return Keyval_.Ary_empty;
|
||||
int len = aliases.Count();
|
||||
Keyval[] rv = new Keyval[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
String alias = (String)aliases.Get_at(i);
|
||||
rv[i] = Keyval_.int_(i + List_adp_.Base1, alias);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xob_ns_file_itm Bldr_data() {return bldr_data;} public void Bldr_data_(Xob_ns_file_itm v) {bldr_data = v;} private Xob_ns_file_itm bldr_data;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_subpages_enabled_)) this.subpages_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_id)) return id;
|
||||
else if (ctx.Match(k, Invk_name_txt)) return name_ui;
|
||||
else if (ctx.Match(k, Invk_name_ui)) return Name_combo();
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_subpages_enabled_ = "subpages_enabled_", Invk_id = "id", Invk_name_txt = "name_txt", Invk_name_ui = "name_ui";
|
||||
|
||||
private static final Xoa_url_encoder url_encoder = new Xoa_url_encoder();
|
||||
}
|
||||
|
||||
@@ -13,61 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_ns_ {
|
||||
public static final int // PAGE:en.w:http://www.mediawiki.org/wiki/Help:Namespaces
|
||||
Tid__media = -2
|
||||
, Tid__special = -1
|
||||
, Tid__main = 0 , Tid__talk = 1
|
||||
, Tid__user = 2 , Tid__user_talk = 3
|
||||
, Tid__project = 4 , Tid__project_talk = 5
|
||||
, Tid__file = 6 , Tid__file_talk = 7
|
||||
, Tid__mediawiki = 8 , Tid__mediawiki_talk = 9
|
||||
, Tid__template = 10 , Tid__template_talk = 11
|
||||
, Tid__help = 12 , Tid__help_talk = 13
|
||||
, Tid__category = 14 , Tid__category_talk = 15
|
||||
, Tid__portal = 100 , Tid__portal_talk = 101
|
||||
, Tid__module = 828 , Tid__module_talk = 829
|
||||
, Tid__null = Int_.Min_value
|
||||
;
|
||||
public static final String
|
||||
Key__media = "Media"
|
||||
, Key__special = "Special"
|
||||
, Key__main = "(Main)" , Key__talk = "Talk"
|
||||
, Key__user = "User" , Key__user_talk = "User_talk"
|
||||
, Key__project = "Project" , Key__project_talk = "Project_talk"
|
||||
, Key__file = "File" , Key__file_talk = "File_talk"
|
||||
, Key__mediawiki = "MediaWiki" , Key__mediawiki_talk = "MediaWiki_talk"
|
||||
, Key__template = "Template" , Key__template_talk = "Template_talk"
|
||||
, Key__help = "Help" , Key__help_talk = "Help_talk"
|
||||
, Key__category = "Category" , Key__category_talk = "Category_talk"
|
||||
, Key__portal = "Portal" , Key__portal_talk = "Portal_talk"
|
||||
, Key__module = "Module" , Key__module_talk = "Module_talk"
|
||||
, Key__null = "null"
|
||||
, Key__wikipedia = "Wikipedia"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__media = Bry_.new_a7(Key__media)
|
||||
, Bry__special = Bry_.new_a7(Key__special)
|
||||
, Bry__main = Bry_.new_a7(Key__main) , Bry__talk = Bry_.new_a7(Key__talk)
|
||||
, Bry__user = Bry_.new_a7(Key__user) , Bry__user_talk = Bry_.new_a7(Key__user_talk)
|
||||
, Bry__project = Bry_.new_a7(Key__project) , Bry__project_talk = Bry_.new_a7(Key__project_talk)
|
||||
, Bry__file = Bry_.new_a7(Key__file) , Bry__file_talk = Bry_.new_a7(Key__file_talk)
|
||||
, Bry__mediawiki = Bry_.new_a7(Key__mediawiki) , Bry__mediawiki_talk = Bry_.new_a7(Key__mediawiki_talk)
|
||||
, Bry__template = Bry_.new_a7(Key__template) , Bry__template_talk = Bry_.new_a7(Key__template_talk)
|
||||
, Bry__help = Bry_.new_a7(Key__help) , Bry__help_talk = Bry_.new_a7(Key__help_talk)
|
||||
, Bry__category = Bry_.new_a7(Key__category) , Bry__category_talk = Bry_.new_a7(Key__category_talk)
|
||||
, Bry__portal = Bry_.new_a7(Key__portal) , Bry__portal_talk = Bry_.new_a7(Key__portal_talk)
|
||||
, Bry__module = Bry_.new_a7(Key__module) , Bry__module_talk = Bry_.new_a7(Key__module_talk)
|
||||
, Bry__null = Bry_.new_a7(Key__null)
|
||||
;
|
||||
public static final String
|
||||
Alias__wikipedia = "Wikipedia"
|
||||
, Alias__image = "Image"
|
||||
;
|
||||
public static final byte[] Alias__image__bry = Bry_.new_a7(Alias__image);
|
||||
public static final byte[]
|
||||
Bry__template_w_colon = Bry_.new_a7(Key__template + ":")
|
||||
, Bry__module_w_colon = Bry_.new_a7(Key__module + ":")
|
||||
;
|
||||
}
|
||||
|
||||
@@ -13,116 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xow_ns_canonical_ {
|
||||
public static final Xow_ns[] Ary = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames
|
||||
{ New_itm(Xow_ns_.Tid__media , Xow_ns_.Key__media)
|
||||
, New_itm(Xow_ns_.Tid__special , Xow_ns_.Key__special)
|
||||
, New_itm(Xow_ns_.Tid__talk , Xow_ns_.Key__talk)
|
||||
, New_itm(Xow_ns_.Tid__user , Xow_ns_.Key__user)
|
||||
, New_itm(Xow_ns_.Tid__user_talk , Xow_ns_.Key__user_talk)
|
||||
, New_itm(Xow_ns_.Tid__project , Xow_ns_.Key__project)
|
||||
, New_itm(Xow_ns_.Tid__project_talk , Xow_ns_.Key__project_talk)
|
||||
, New_itm(Xow_ns_.Tid__file , Xow_ns_.Key__file)
|
||||
, New_itm(Xow_ns_.Tid__file_talk , Xow_ns_.Key__file_talk)
|
||||
, New_itm(Xow_ns_.Tid__mediawiki , Xow_ns_.Key__mediawiki)
|
||||
, New_itm(Xow_ns_.Tid__mediawiki_talk , Xow_ns_.Key__mediawiki_talk)
|
||||
, New_itm(Xow_ns_.Tid__template , Xow_ns_.Key__template)
|
||||
, New_itm(Xow_ns_.Tid__template_talk , Xow_ns_.Key__template_talk)
|
||||
, New_itm(Xow_ns_.Tid__help , Xow_ns_.Key__help)
|
||||
, New_itm(Xow_ns_.Tid__help_talk , Xow_ns_.Key__help_talk)
|
||||
, New_itm(Xow_ns_.Tid__category , Xow_ns_.Key__category)
|
||||
, New_itm(Xow_ns_.Tid__category_talk , Xow_ns_.Key__category_talk)
|
||||
, New_itm(Xow_ns_.Tid__module , Xow_ns_.Key__module)
|
||||
, New_itm(Xow_ns_.Tid__module_talk , Xow_ns_.Key__module_talk)
|
||||
};
|
||||
private static Xow_ns New_itm(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
|
||||
private static Ordered_hash id_hash;
|
||||
public static int To_id(byte[] key) {
|
||||
if (id_hash == null) {
|
||||
id_hash = Ordered_hash_.New_bry();
|
||||
int len = Ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_ns ns = Ary[i];
|
||||
id_hash.Add(ns.Name_db(), new Int_obj_val(ns.Id()));
|
||||
}
|
||||
}
|
||||
Object rv_obj = id_hash.Get_by(key);
|
||||
return rv_obj == null ? Xow_ns_.Tid__null : ((Int_obj_val)rv_obj).Val();
|
||||
}
|
||||
public static String To_canonical_or_local_as_str(Xow_ns ns) { // NOTE: prefer canonical names if they exist; otherwise use local; PAGE:sh.w:Koprno; DATE:2015-11-08
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Tid__media: return Xow_ns_.Key__media;
|
||||
case Xow_ns_.Tid__special: return Xow_ns_.Key__special;
|
||||
case Xow_ns_.Tid__talk: return Xow_ns_.Key__talk;
|
||||
case Xow_ns_.Tid__user: return Xow_ns_.Key__user;
|
||||
case Xow_ns_.Tid__user_talk: return Xow_ns_.Key__user_talk;
|
||||
case Xow_ns_.Tid__project: return Xow_ns_.Key__project;
|
||||
case Xow_ns_.Tid__project_talk: return Xow_ns_.Key__project_talk;
|
||||
case Xow_ns_.Tid__file: return Xow_ns_.Key__file;
|
||||
case Xow_ns_.Tid__file_talk: return Xow_ns_.Key__file_talk;
|
||||
case Xow_ns_.Tid__mediawiki: return Xow_ns_.Key__mediawiki;
|
||||
case Xow_ns_.Tid__mediawiki_talk: return Xow_ns_.Key__mediawiki_talk;
|
||||
case Xow_ns_.Tid__template: return Xow_ns_.Key__template;
|
||||
case Xow_ns_.Tid__template_talk: return Xow_ns_.Key__template_talk;
|
||||
case Xow_ns_.Tid__help: return Xow_ns_.Key__help;
|
||||
case Xow_ns_.Tid__help_talk: return Xow_ns_.Key__help_talk;
|
||||
case Xow_ns_.Tid__category: return Xow_ns_.Key__category;
|
||||
case Xow_ns_.Tid__category_talk: return Xow_ns_.Key__category_talk;
|
||||
case Xow_ns_.Tid__module: return Xow_ns_.Key__module;
|
||||
case Xow_ns_.Tid__module_talk: return Xow_ns_.Key__module_talk;
|
||||
default: return String_.new_u8(ns.Name_ui());
|
||||
}
|
||||
}
|
||||
public static byte[] To_canonical_or_local_as_bry(Xow_ns ns) {
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Tid__media: return Xow_ns_.Bry__media;
|
||||
case Xow_ns_.Tid__special: return Xow_ns_.Bry__special;
|
||||
case Xow_ns_.Tid__talk: return Xow_ns_.Bry__talk;
|
||||
case Xow_ns_.Tid__user: return Xow_ns_.Bry__user;
|
||||
case Xow_ns_.Tid__user_talk: return Xow_ns_.Bry__user_talk;
|
||||
case Xow_ns_.Tid__project: return Xow_ns_.Bry__project;
|
||||
case Xow_ns_.Tid__project_talk: return Xow_ns_.Bry__project_talk;
|
||||
case Xow_ns_.Tid__file: return Xow_ns_.Bry__file;
|
||||
case Xow_ns_.Tid__file_talk: return Xow_ns_.Bry__file_talk;
|
||||
case Xow_ns_.Tid__mediawiki: return Xow_ns_.Bry__mediawiki;
|
||||
case Xow_ns_.Tid__mediawiki_talk: return Xow_ns_.Bry__mediawiki_talk;
|
||||
case Xow_ns_.Tid__template: return Xow_ns_.Bry__template;
|
||||
case Xow_ns_.Tid__template_talk: return Xow_ns_.Bry__template_talk;
|
||||
case Xow_ns_.Tid__help: return Xow_ns_.Bry__help;
|
||||
case Xow_ns_.Tid__help_talk: return Xow_ns_.Bry__help_talk;
|
||||
case Xow_ns_.Tid__category: return Xow_ns_.Bry__category;
|
||||
case Xow_ns_.Tid__category_talk: return Xow_ns_.Bry__category_talk;
|
||||
case Xow_ns_.Tid__module: return Xow_ns_.Bry__module;
|
||||
case Xow_ns_.Tid__module_talk: return Xow_ns_.Bry__module_talk;
|
||||
default: return ns.Name_ui();
|
||||
}
|
||||
}
|
||||
public static byte[] To_canonical_or_local_as_bry_w_colon(Xow_ns ns) {
|
||||
byte[] rv = null;
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Tid__media: rv = Xow_ns_.Bry__media; break;
|
||||
case Xow_ns_.Tid__special: rv = Xow_ns_.Bry__special; break;
|
||||
case Xow_ns_.Tid__talk: rv = Xow_ns_.Bry__talk; break;
|
||||
case Xow_ns_.Tid__user: rv = Xow_ns_.Bry__user; break;
|
||||
case Xow_ns_.Tid__user_talk: rv = Xow_ns_.Bry__user_talk; break;
|
||||
case Xow_ns_.Tid__project: rv = Xow_ns_.Bry__project; break;
|
||||
case Xow_ns_.Tid__project_talk: rv = Xow_ns_.Bry__project_talk; break;
|
||||
case Xow_ns_.Tid__file: rv = Xow_ns_.Bry__file; break;
|
||||
case Xow_ns_.Tid__file_talk: rv = Xow_ns_.Bry__file_talk; break;
|
||||
case Xow_ns_.Tid__mediawiki: rv = Xow_ns_.Bry__mediawiki; break;
|
||||
case Xow_ns_.Tid__mediawiki_talk: rv = Xow_ns_.Bry__mediawiki_talk; break;
|
||||
case Xow_ns_.Tid__template: rv = Xow_ns_.Bry__template; break;
|
||||
case Xow_ns_.Tid__template_talk: rv = Xow_ns_.Bry__template_talk; break;
|
||||
case Xow_ns_.Tid__help: rv = Xow_ns_.Bry__help; break;
|
||||
case Xow_ns_.Tid__help_talk: rv = Xow_ns_.Bry__help_talk; break;
|
||||
case Xow_ns_.Tid__category: rv = Xow_ns_.Bry__category; break;
|
||||
case Xow_ns_.Tid__category_talk: rv = Xow_ns_.Bry__category_talk; break;
|
||||
case Xow_ns_.Tid__module: rv = Xow_ns_.Bry__module; break;
|
||||
case Xow_ns_.Tid__module_talk: rv = Xow_ns_.Bry__module_talk; break;
|
||||
default: return ns.Name_db_w_colon();
|
||||
}
|
||||
return Bry_.Add(rv, Byte_ascii.Colon_bry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_ns_case_ {
|
||||
public static final byte Tid__all = 0, Tid__1st = 1;
|
||||
public static final String Key__all = "case-sensitive", Key__1st = "first-letter";
|
||||
public static final byte[] Bry__all = Bry_.new_a7(Key__all), Bry__1st = Bry_.new_a7(Key__1st);
|
||||
public static byte To_tid(String s) {
|
||||
if (String_.Eq(s, Key__1st)) return Tid__1st;
|
||||
else if (String_.Eq(s, Key__all)) return Tid__all;
|
||||
else throw Err_.new_unhandled(s);
|
||||
}
|
||||
public static String To_str(byte tid) {
|
||||
switch (tid) {
|
||||
case Tid__all: return Key__all;
|
||||
case Tid__1st: return Key__1st;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,253 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.xowa.langs.cases.*;
|
||||
import gplx.xowa.bldrs.installs.*;
|
||||
import gplx.xowa.xtns.scribunto.*;
|
||||
public class Xow_ns_mgr implements Gfo_invk, gplx.core.lists.ComparerAble {
|
||||
private Ordered_hash id_hash = Ordered_hash_.New(); // hash for retrieval by id
|
||||
private Hash_adp_bry name_hash; // hash for retrieval by name; note that ns names are case-insensitive "File:" == "fILe:"
|
||||
private Hash_adp_bry tmpl_hash; // hash for retrieval by name; PERF for templates
|
||||
private Ordered_hash aliases = Ordered_hash_.New(); // hash to store aliases; used to populate name_hash;
|
||||
private final Int_obj_ref id_hash_ref = Int_obj_ref.New_zero();
|
||||
public Xow_ns_mgr(Xol_case_mgr case_mgr) {
|
||||
name_hash = Hash_adp_bry.ci_u8(case_mgr);
|
||||
tmpl_hash = Hash_adp_bry.ci_u8(case_mgr);
|
||||
}
|
||||
public Xow_ns_mgr Clear() {
|
||||
name_hash.Clear();
|
||||
id_hash.Clear();
|
||||
tmpl_hash.Clear();
|
||||
for (int i = 0; i < ords_len; i++)
|
||||
ords[i] = null;
|
||||
ords_len = 0;
|
||||
ns_count = 0;
|
||||
ns_file = null;
|
||||
return this;
|
||||
}
|
||||
public Btrie_slim_mgr Category_trie() {return category_trie;} private Btrie_slim_mgr category_trie;
|
||||
public Xow_ns Ns_main() {return ns_main;} private Xow_ns ns_main;
|
||||
public Xow_ns Ns_template() {return ns_template;} private Xow_ns ns_template;
|
||||
public Xow_ns Ns_file() {return ns_file;} private Xow_ns ns_file;
|
||||
public Xow_ns Ns_category() {return ns_category;} private Xow_ns ns_category;
|
||||
public Xow_ns Ns_portal() {return ns_portal;} private Xow_ns ns_portal;
|
||||
public Xow_ns Ns_project() {return ns_project;} private Xow_ns ns_project;
|
||||
public Xow_ns Ns_module() {return ns_module;} private Xow_ns ns_module;
|
||||
public Xow_ns Ns_mediawiki() {return ns_mediawiki;} private Xow_ns ns_mediawiki;
|
||||
public int Ns_page_id() {return ns_page_id;} public void Ns_page_id_(int v) {ns_page_id = v;} private int ns_page_id = Int_.Min_value;
|
||||
public int Count() {return ns_count;} private int ns_count = 0;
|
||||
public Xow_ns[] Ords_ary() {return ords;} private Xow_ns[] ords = new Xow_ns[Xow_ns_mgr_.Ordinal_max];
|
||||
public int Ords_len() {return ords_len;} private int ords_len;
|
||||
public Xow_ns Ords_get_at(int ord) {return ords[ord];}
|
||||
public int Ids_len() {return id_hash.Count();}
|
||||
public Xow_ns Ids_get_at(int idx) {return (Xow_ns)id_hash.Get_at(idx);}
|
||||
public Xow_ns Ids_get_or_null(int id) {synchronized (id_hash_ref) {return (Xow_ns)id_hash.Get_by(id_hash_ref.Val_(id));}} // LOCK:hash-key; DATE:2016-07-06
|
||||
private Xow_ns Ids_get_or_empty(int id) {
|
||||
Xow_ns rv = Ids_get_or_null(id);
|
||||
return rv == null ? Ns__empty : rv;
|
||||
} private static final Xow_ns Ns__empty = new Xow_ns(Int_.Max_value, Byte_.Zero, Bry_.Empty, false);
|
||||
public Xow_ns Names_get_or_null(byte[] name_bry) {return this.Names_get_or_null(name_bry, 0, name_bry.length);}
|
||||
public Xow_ns Names_get_or_null(byte[] src, int bgn, int end) {
|
||||
Object rv = name_hash.Get_by_mid(src, bgn, end);
|
||||
return rv == null ? null : ((Xow_ns_mgr_name_itm)rv).Ns();
|
||||
}
|
||||
public Xow_ns Names_get_or_main(byte[] name_bry) {
|
||||
Xow_ns rv = this.Names_get_or_null(name_bry, 0, name_bry.length);
|
||||
return rv == null ? this.Ns_main() : rv;
|
||||
}
|
||||
public Object Names_get_w_colon(byte[] src, int bgn, int end) { // NOTE: get ns for a name with a ":"; EX: "Template:A" should return "Template" ns
|
||||
int colon_pos = Bry_find_.Find_fwd(src, Byte_ascii.Colon, bgn, end);
|
||||
if (colon_pos == Bry_find_.Not_found) return null; // name does not have ":"; return;
|
||||
Object rv = name_hash.Get_by_mid(src, bgn, colon_pos);
|
||||
return rv == null ? null : ((Xow_ns_mgr_name_itm)rv).Ns();
|
||||
}
|
||||
public int Tmpls_get_w_colon(byte[] src, int bgn, int end) { // NOTE: get length of template name with a ":"; EX: "Template:A" returns 10; PERF
|
||||
int colon_pos = Bry_find_.Find_fwd(src, Byte_ascii.Colon, bgn, end);
|
||||
if (colon_pos == Bry_find_.Not_found) return Bry_find_.Not_found;
|
||||
Object o = tmpl_hash.Get_by_mid(src, bgn, colon_pos + 1); // +1 to include colon_pos
|
||||
return o == null ? Bry_find_.Not_found : ((byte[])o).length;
|
||||
}
|
||||
public void Aliases_clear() {aliases.Clear();}
|
||||
public Xow_ns_mgr Aliases_add(int ns_id, String name) {
|
||||
Keyval kv = Keyval_.new_(name, new Int_obj_val(ns_id));
|
||||
aliases.Add_if_dupe_use_nth(name, kv);
|
||||
return this;
|
||||
}
|
||||
public void Aliases_del(String name) {aliases.Del(name);}
|
||||
public Xow_ns_mgr Init() {
|
||||
this.Ords_sort();
|
||||
this.Rebuild_hashes();
|
||||
return this;
|
||||
}
|
||||
public void Init_w_defaults() {
|
||||
this.Add_defaults();
|
||||
this.Init();
|
||||
}
|
||||
private void Rebuild_hashes() {
|
||||
name_hash.Clear(); tmpl_hash.Clear();
|
||||
for (int i = 0; i < ords_len; i++) {
|
||||
Xow_ns ns = ords[i];
|
||||
if (ns == null) continue; // TEST: allow gaps in ns numbers; see Talk_skip test and related
|
||||
if (ns.Id() == Xow_ns_.Tid__project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort
|
||||
Rebuild_hashes__add(name_hash, ns, ns.Name_db());
|
||||
if (ns.Id_is_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon());
|
||||
}
|
||||
int aliases_len = aliases.Count();
|
||||
for (int i = 0; i < aliases_len; i++) {
|
||||
Keyval kv = (Keyval)aliases.Get_at(i);
|
||||
int ns_id = ((Int_obj_val)kv.Val()).Val();
|
||||
Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) continue; // happens when alias exists, but not ns; EX: test has Image alias, but not File alias; should not happen "live" but don't want to fail
|
||||
ns.Aliases_add(kv.Key()); // register alias with official ns; EX: "Image" will be placed in "File"'s .Aliases
|
||||
byte[] alias_bry = Bry_.new_u8(kv.Key());
|
||||
Rebuild_hashes__add(name_hash, ns, alias_bry);
|
||||
if (ns.Id_is_tmpl()) {
|
||||
byte[] alias_name = Bry_.new_u8(kv.Key());
|
||||
alias_name = Bry_.Add(alias_name, Byte_ascii.Colon);
|
||||
tmpl_hash.Add_if_dupe_use_nth(alias_name, alias_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Fix_project_talk(Xow_ns ns) {
|
||||
byte[] ns_name = ns.Name_db();
|
||||
if (Bry_find_.Find_fwd(ns.Name_db(), Project_talk_fmt_arg)== Bry_find_.Not_found) return; // no $1 found; exit
|
||||
Xow_ns project_ns = ords[ns.Ord_subj_id()];
|
||||
if (project_ns == null) return; // should warn or throw error; for now just exit
|
||||
ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_db()));
|
||||
} private static final byte[] Project_talk_fmt_arg = Bry_.new_a7("$1");
|
||||
private void Rebuild_hashes__add(Hash_adp_bry hash, Xow_ns ns, byte[] key) {
|
||||
Xow_ns_mgr_name_itm ns_itm = new Xow_ns_mgr_name_itm(key, ns);
|
||||
hash.Add_if_dupe_use_nth(key, ns_itm);
|
||||
if (Bry_find_.Find_fwd(key, Byte_ascii.Underline) != Bry_find_.Not_found) // ns has _; add another entry for space; EX: Help_talk -> Help talk
|
||||
hash.Add_if_dupe_use_nth(Bry_.Replace(key, Byte_ascii.Underline, Byte_ascii.Space), ns_itm);
|
||||
}
|
||||
public Xow_ns_mgr Add_defaults() { // NOTE: needs to happen after File ns is added; i.e.: cannot be put in Xow_ns_mgr() {} ctor
|
||||
Aliases_add(Xow_ns_.Tid__file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well
|
||||
Aliases_add(Xow_ns_.Tid__file_talk , "Image_talk");
|
||||
Aliases_add(Xow_ns_.Tid__project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages
|
||||
Aliases_add(Xow_ns_.Tid__module , "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module
|
||||
return this;
|
||||
}
|
||||
public Xow_ns_mgr Add_new(int nsId, String name) {return Add_new(nsId, Bry_.new_u8(name), Xow_ns_case_.Tid__1st, false);} // for tst_ constructor
|
||||
public Xow_ns_mgr Add_new(int ns_id, byte[] name, byte caseMatchId, boolean alias) {
|
||||
Bry_.Replace_all_direct(name, Byte_ascii.Space, Byte_ascii.Underline); // standardize on _; EX: User talk -> User_talk; DATE:2013-04-21
|
||||
Xow_ns ns = new Xow_ns(ns_id, caseMatchId, name, alias);
|
||||
switch (ns_id) {
|
||||
case Xow_ns_.Tid__main: ns_main = ns; break;
|
||||
case Xow_ns_.Tid__template: ns_template = ns; break;
|
||||
case Xow_ns_.Tid__portal: ns_portal = ns; break;
|
||||
case Xow_ns_.Tid__project: ns_project = ns; break;
|
||||
case Xow_ns_.Tid__mediawiki: ns_mediawiki = ns; break;
|
||||
case Xow_ns_.Tid__module: ns_module = ns; break;
|
||||
case Xow_ns_.Tid__file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file
|
||||
case Xow_ns_.Tid__category:
|
||||
ns_category = ns;
|
||||
if (category_trie == null)
|
||||
category_trie = Btrie_slim_mgr.new_(ns.Case_match() == Xow_ns_case_.Tid__all);
|
||||
category_trie.Add_obj(ns.Name_db(), this);
|
||||
break;
|
||||
}
|
||||
++ns_count;
|
||||
synchronized (id_hash_ref) { // LOCK:hash-key; DATE:2016-07-06
|
||||
if (!id_hash.Has(id_hash_ref.Val_(ns_id))) // NOTE: do not add if already exists; avoids alias
|
||||
id_hash.Add(Int_obj_ref.New(ns.Id()), ns);
|
||||
}
|
||||
name_hash.Add_if_dupe_use_nth(ns.Name_db(), new Xow_ns_mgr_name_itm(ns.Name_db(), ns));
|
||||
return this;
|
||||
}
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xow_ns lhs = (Xow_ns)lhsObj;
|
||||
Xow_ns rhs = (Xow_ns)rhsObj;
|
||||
return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
}
|
||||
private void Ords_sort() {
|
||||
int ords_cur = 0;
|
||||
int ns_len = id_hash.Count();
|
||||
id_hash.Sort_by(this);
|
||||
// assert that all items are grouped in pairs of subj, talk; note that subj is even and talk is odd
|
||||
int nxt_ns_id = Int_.Min_value;
|
||||
int prv_ns_id = Int_.Min_value;
|
||||
for (int i = 0; i < ns_len; i++) {
|
||||
Xow_ns ns = (Xow_ns)id_hash.Get_at(i);
|
||||
int ns_id = ns.Id();
|
||||
if (ns_id < 0 // ignore negative ns (which don't have subj/talk pairing)
|
||||
|| ns.Is_alias() // ignore alias
|
||||
) continue;
|
||||
if (nxt_ns_id != Int_.Min_value) { // nxt_ns_id is set
|
||||
if (nxt_ns_id != ns_id) // prv was subj, but cur does not match expected talk_id; create talk for prv subj
|
||||
Ords_sort_add(nxt_ns_id);
|
||||
nxt_ns_id = Int_.Min_value; // always reset value
|
||||
}
|
||||
if (ns_id % 2 == 0) // subj
|
||||
nxt_ns_id = ns_id + 1; // anticipate nxt_ns_id
|
||||
else { // talk
|
||||
if (prv_ns_id != ns_id - 1) // prv was not subj for cur; create subj for current talk
|
||||
Ords_sort_add(ns_id - 1);
|
||||
}
|
||||
prv_ns_id = ns_id;
|
||||
}
|
||||
if (nxt_ns_id != Int_.Min_value) // handle trailing ns_id; EX: 0, 1, 2; need to make 3
|
||||
Ords_sort_add(nxt_ns_id);
|
||||
|
||||
// sort again b/c new ns may have been added
|
||||
id_hash.Sort_by(this);
|
||||
ns_len = id_hash.Count();
|
||||
// assign ords; assert that subj has even ordinal index
|
||||
ords_len = 0;
|
||||
for (int i = 0; i < ns_len; i++) {
|
||||
Xow_ns ns = (Xow_ns)id_hash.Get_at(i);
|
||||
int ns_id = ns.Id();
|
||||
if (ns.Is_alias()) continue; // ignore alias
|
||||
if (ns_id < 0) {}
|
||||
else {
|
||||
if (ns_id % 2 == 0) { // subj
|
||||
if (ords_cur % 2 != 0) { // current ordinal is not even; skip
|
||||
++ords_len;
|
||||
++ords_cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
ns.Ord_(ords_cur);
|
||||
ords[ords_cur++] = ns;
|
||||
++ords_len;
|
||||
}
|
||||
}
|
||||
private void Ords_sort_add(int ns_id) {
|
||||
this.Add_new(ns_id, Int_.To_bry(ns_id), Xow_ns_case_.Tid__1st, false); // NOTE: name and case_match are mostly useless defaults; note that in theory this proc should not be called (all siteInfos should be well-formed) but just in case, create items now so that Get_by_ord() does not fail
|
||||
}
|
||||
public byte[] Bld_ttl_w_ns(Bry_bfr bfr, boolean text_form, boolean literalize, int ns_id, byte[] ttl) {
|
||||
if (ns_id == Xow_ns_.Tid__main) return ttl;
|
||||
Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "ns_mgr:uknown ns_id; ns_id=~{0} ttl=~{1}", ns_id, ttl); return ttl;}
|
||||
if (literalize) bfr.Add_byte(Byte_ascii.Colon); // NOTE: add : to literalize ns; EX: [[Category:A]] will get thrown into category list; [[:Category:A]] will print
|
||||
bfr.Add(text_form ? ns.Name_ui_w_colon() : ns.Name_db_w_colon());
|
||||
bfr.Add(ttl);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
class Xow_ns_mgr_name_itm {
|
||||
public Xow_ns_mgr_name_itm(byte[] name, Xow_ns ns) {this.name = name; this.name_len = name.length; this.ns = ns;}
|
||||
public byte[] Name() {return name;} private byte[] name;
|
||||
public int Name_len() {return name_len;} private int name_len;
|
||||
public Xow_ns Ns() {return ns;} private Xow_ns ns;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_clear)) this.Clear();
|
||||
// NOTE: called by /xowa/bin/any/xowa/cfg/wiki/core/*.gfs for (a) aliases; (b) Subpages_enabled
|
||||
else if (ctx.Match(k, Invk_add_alias_bulk)) Exec_add_alias_bulk(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_get_by_id_or_new)) return this.Ids_get_or_empty(m.ReadInt("v")); // NOTE: if ns doesn't exist, returning empty is fine; DATE:2014-02-15
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_add_alias_bulk = "add_alias_bulk", Invk_get_by_id_or_new = "get_by_id_or_new";
|
||||
public static final String Invk_load = "load", Invk_clear = "clear";
|
||||
private void Exec_add_alias_bulk(byte[] raw) {
|
||||
byte[][] lines = Bry_split_.Split(raw, Byte_ascii.Nl);
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
byte[] line = lines[i];
|
||||
if (line.length == 0) continue;
|
||||
byte[][] flds = Bry_split_.Split(line, Byte_ascii.Pipe);
|
||||
int cur_id = Bry_.To_int_or(flds[0], Int_.Min_value);
|
||||
this.Aliases_add(cur_id, String_.new_u8(flds[1]));
|
||||
}
|
||||
Ords_sort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,38 +13,3 @@ The terms of each license can be found in the source code repository:
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.cases.*; import gplx.xowa.langs.bldrs.*;
|
||||
public class Xow_ns_mgr_ {
|
||||
public static final int Ordinal_max = 255; // ASSUME: no more than 255 ns in a wiki; choosing 255 to align with byte (no particular reason why it needs to be a byte, but better than 500, 1000, etc)
|
||||
public static Xow_ns_mgr default_(Xol_case_mgr case_mgr) { // NOTE: same as en.wikipedia.org's ns circa 2012-01 (currently omitting ns:446,447,710,711)
|
||||
Xow_ns_mgr rv = new Xow_ns_mgr(case_mgr);
|
||||
rv = rv.Add_new(-2, "Media").Add_new(-1, "Special").Add_new(0, "").Add_new(1, "Talk").Add_new(2, "User").Add_new(3, "User_talk").Add_new(4, "Wikipedia").Add_new(5, "Wikipedia_talk")
|
||||
.Add_new(6, "File").Add_new(7, "File_talk").Add_new(8, "MediaWiki").Add_new(9, "MediaWiki_talk").Add_new(10, "Template").Add_new(11, "Template_talk")
|
||||
.Add_new(12, "Help").Add_new(13, "Help_talk").Add_new(14, "Category").Add_new(15, "Category_talk").Add_new(100, "Portal").Add_new(101, "Portal_talk").Add_new(108, "Book").Add_new(109, "Book_talk")
|
||||
.Add_new(Xow_ns_.Tid__module, Xow_ns_.Key__module).Add_new(Xow_ns_.Tid__module_talk, Xow_ns_.Key__module_talk)
|
||||
.Add_defaults()
|
||||
;
|
||||
rv.Init();
|
||||
return rv;
|
||||
}
|
||||
public static void rebuild_(Xol_lang_itm lang, Xow_ns_mgr ns_mgr) {
|
||||
Xol_ns_grp ns_names = lang.Ns_names();
|
||||
int ns_names_len = ns_names.Len();
|
||||
for (int i = 0; i < ns_names_len; i++) {
|
||||
Xow_ns ns_name = ns_names.Get_at(i);
|
||||
int ns_id = ns_name.Id();
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
|
||||
if (ns == null) continue; // ns_id of -2 will not be found in site_ns
|
||||
ns.Name_bry_(ns_name.Name_db());
|
||||
}
|
||||
ns_names = lang.Ns_aliases();
|
||||
ns_names_len = ns_names.Len();
|
||||
for (int i = 0; i < ns_names_len; i++) {
|
||||
Xow_ns ns_name = ns_names.Get_at(i);
|
||||
int ns_id = ns_name.Id();
|
||||
ns_mgr.Aliases_add(ns_id, ns_name.Name_db_str());
|
||||
}
|
||||
ns_mgr.Init();
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user