mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.10.3.1
This commit is contained in:
@@ -18,6 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xoa_wiki_mgr {
|
||||
boolean Has(byte[] key);
|
||||
int Count();
|
||||
Xow_wiki Get_at_i(int i);
|
||||
Xow_wiki Get_by_key_or_null_i(byte[] key);
|
||||
Xow_wiki Get_by_key_or_make_init_y(byte[] key);
|
||||
Xow_wiki Get_by_key_or_make_init_n(byte[] key);
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ public class Xoa_wiki_regy {
|
||||
}
|
||||
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_type_.Bry__home, url.Wiki_bry()) // wiki is "home"
|
||||
&& !Bry_.Eq(Xow_domain_type_.Bry__home, url.Raw())) // raw is "home"; should be "home/wiki/Main_Page"; DATE:2014-02-09
|
||||
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.I.QueryDir_args(app.Fsys_mgr().Wiki_dir()).DirInclude_(true).Recur_(false).ExecAsUrlAry();
|
||||
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];
|
||||
@@ -46,6 +46,6 @@ public class Xoa_wiki_regy {
|
||||
}
|
||||
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.I.CreateDir(wiki_dir.GenSubDir(domain_str));
|
||||
Io_mgr.Instance.CreateDir(wiki_dir.GenSubDir(domain_str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.cfgs.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.domains.crts.*;
|
||||
import gplx.xowa.wikis.xwikis.cfgs.*;
|
||||
public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
|
||||
private Xoae_app app;
|
||||
private List_adp list = List_adp_.new_(); private Hash_adp_bry hash = Hash_adp_bry.ci_a7(); // ASCII:url_domain; EX:en.wikipedia.org
|
||||
@@ -29,16 +28,17 @@ public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
|
||||
wdata_mgr = new Wdata_wiki_mgr(app);
|
||||
}
|
||||
public Xoa_wiki_regy Wiki_regy() {return wiki_regy;} private Xoa_wiki_regy wiki_regy;
|
||||
public Cfg_nde_root Groups() {return groups;} Cfg_nde_root groups = new Cfg_nde_root().Root_(new Xoac_wiki_grp(Bry_.Empty), Xoac_lang_grp.Make_grp, Bry_.Ary_empty);
|
||||
public Xow_script_mgr Scripts() {return scripts;} private Xow_script_mgr scripts = new Xow_script_mgr();
|
||||
public Wdata_wiki_mgr Wdata_mgr() {return wdata_mgr;} Wdata_wiki_mgr wdata_mgr;
|
||||
public void Init_by_app() {
|
||||
wdata_mgr.Init_by_app();
|
||||
}
|
||||
public int Count() {return hash.Count();}
|
||||
public int Count() {return list.Count();}
|
||||
public void Del(byte[] key) {hash.Del(key);}
|
||||
public boolean Has(byte[] key) {return hash.Has(key);}
|
||||
public Xow_wiki Get_at_i(int i) {return (Xow_wiki)list.Get_at(i);}
|
||||
public Xowe_wiki Get_at(int i) {return Int_.Between(i, 0, this.Count() - 1) ? (Xowe_wiki)list.Get_at(i) : null;}
|
||||
public Xow_wiki Get_by_key_or_null_i(byte[] key) {return Bry_.Len_eq_0(key) ? null : (Xowe_wiki)hash.Get_by(key);}
|
||||
public Xowe_wiki Get_by_key_or_null(byte[] key) {return Bry_.Len_eq_0(key) ? null : (Xowe_wiki)hash.Get_by(key);}
|
||||
public Xowe_wiki Get_by_key_or_null(byte[] src, int bgn, int end) {return (Xowe_wiki)hash.Get_by_mid(src, bgn, end);}
|
||||
public Xow_wiki Get_by_key_or_make_init_y(byte[] key) {
|
||||
@@ -87,22 +87,21 @@ public class Xoae_wiki_mgr implements Xoa_wiki_mgr, GfoInvkAble {
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_by_key_or_make(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_groups)) return groups;
|
||||
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(m.ReadInt("v"));
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
} private static final String Invk_get = "get", Invk_groups = "groups", Invk_scripts = "scripts", Invk_wdata = "wdata";
|
||||
} 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";
|
||||
private Xowe_wiki New_wiki(byte[] key) {
|
||||
Xow_domain_itm domain_itm = Xow_domain_itm_.parse(key);
|
||||
byte[] lang_key = domain_itm.Lang_actl_key();
|
||||
if (lang_key == Xol_lang_itm_.Key__unknown) lang_key = Xol_lang_.Key_en; // unknown langs default to english; note that this makes nonwmf english by default
|
||||
Xol_lang lang = app.Lang_mgr().Get_by_key_or_new(lang_key);
|
||||
if (domain_itm.Domain_type_id() == Xow_domain_type_.Int__other) {
|
||||
lang = new Xol_lang(app.Lang_mgr(), Xol_lang_.Key_en).Kwd_mgr__strx_(true); // create a new english lang, but enable strx functions; DATE:2015-08-23
|
||||
Xol_lang_.Lang_init(lang);
|
||||
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_.Int__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);
|
||||
}
|
||||
Xow_ns_mgr ns_mgr = Xow_ns_mgr_.default_(lang.Case_mgr());
|
||||
Io_url wiki_dir = app.Fsys_mgr().Wiki_dir().GenSubDir(domain_itm.Domain_str());
|
||||
|
||||
@@ -26,7 +26,7 @@ public class Xow_fsys_mgr {
|
||||
|
||||
public static Io_url Find_core_fil(Xow_wiki wiki) {return Find_core_fil(wiki.Fsys_mgr().Root_dir(), wiki.Domain_str());}
|
||||
public static Io_url Find_core_fil(Io_url wiki_root_dir, String domain_str) {
|
||||
Io_url[] ary = Io_mgr.I.QueryDir_fils(wiki_root_dir);
|
||||
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;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.xtns.wdatas.*;
|
||||
public class Xow_page_tid {
|
||||
public static byte Identify(int wiki_tid, int ns_id, byte[] ttl) {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Xowv_repo_mgr implements Xow_repo_mgr {
|
||||
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_type_.Bry__home)) throw Err_mgr._.fmt_(GRP_KEY, "add_repo", "wiki keys do not match: ~{0} ~{1}", String_.new_u8(src_wiki_key), String_.new_u8(trg_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;
|
||||
|
||||
@@ -19,16 +19,16 @@ package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.apps.*;
|
||||
import gplx.xowa.gui.*;
|
||||
import gplx.xowa.guis.*;
|
||||
import gplx.xowa.langs.*; 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.*; import gplx.xowa.files.repos.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.wikis.ttls.*; import gplx.xowa.wikis.specials.*;
|
||||
import gplx.xowa.html.*; import gplx.xowa.html.wtrs.*; import gplx.xowa.html.hdumps.*; import gplx.xowa.html.hzips.*; import gplx.xowa.html.css.*; import gplx.xowa.html.bridges.dbuis.tbls.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.wtrs.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.htmls.hzips.*; import gplx.xowa.htmls.css.*; import gplx.xowa.htmls.bridges.dbuis.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.urls.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*;
|
||||
public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser {
|
||||
public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser, GfoInvkAble {
|
||||
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) {
|
||||
@@ -40,11 +40,11 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser {
|
||||
this.ns_mgr = Xow_ns_mgr_.default_(app.Utl_case_mgr());
|
||||
this.html__hzip_mgr = new Xow_hzip_mgr(app.Usr_dlg(), this);
|
||||
this.html__hdump_rdr = new Xohd_hdump_rdr(app, this);
|
||||
this.xwiki_mgr = new Xow_xwiki_mgr();
|
||||
this.special_mgr = new Xosp_special_mgr(this);
|
||||
this.fsys_mgr = new Xow_fsys_mgr(wiki_root_dir, app.Fsys_mgr().File_dir().GenSubDir(domain_str));
|
||||
this.fsdb_mgr = new Xof_fsdb_mgr__sql();
|
||||
this.url__parser = new Xoa_url_parser(this);
|
||||
this.xwiki_mgr = new Xow_xwiki_mgr(this);
|
||||
}
|
||||
public Xoa_app App() {return app;}
|
||||
public boolean Type_is_edit() {return Bool_.N;}
|
||||
@@ -66,14 +66,14 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser {
|
||||
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 Xow_hzip_mgr Html__hzip_mgr() {return html__hzip_mgr;} private final Xow_hzip_mgr html__hzip_mgr;
|
||||
public Xohd_hdump_rdr Html__hdump_rdr() {return html__hdump_rdr;} private final Xohd_hdump_rdr html__hdump_rdr;
|
||||
public Xoh_page_wtr_mgr_base Html__page_wtr_mgr() {return html__page_wtr_mgr;} private final Xohv_page_wtr_mgr html__page_wtr_mgr = new Xohv_page_wtr_mgr();
|
||||
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 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 Lang() {throw Err_.new_unimplemented();}
|
||||
public Xol_lang_itm Lang() {throw Err_.new_unimplemented();}
|
||||
public Xoa_url_parser Utl__url_parser() {return url__parser;} private final Xoa_url_parser url__parser;
|
||||
|
||||
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 Xow_xwiki_mgr xwiki_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 void Init_by_wiki() {
|
||||
if (!init_needed) return;
|
||||
@@ -106,4 +106,5 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser {
|
||||
byte[] raw = Bry_.Add(ns.Name_db_w_colon(), ttl);
|
||||
return Xoa_ttl.parse(app.Utl__bfr_mkr(), app.Utl_amp_mgr(), app.Utl_case_mgr(), xwiki_mgr, ns_mgr, app.Utl_msg_log(), raw, 0, raw.length);
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {throw Err_.new_unimplemented_w_msg("implemented for Xoa_cfg_mgr");}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.cfgs.*;
|
||||
import gplx.xowa.wikis.xwikis.sitelinks.*;
|
||||
public class Xow_cache_mgr {
|
||||
private Xowe_wiki wiki;
|
||||
public Xow_cache_mgr(Xowe_wiki wiki) {
|
||||
@@ -32,28 +32,16 @@ public class Xow_cache_mgr {
|
||||
public KeyVal[] Scrib_lang_names() {
|
||||
if (scrib_lang_names == null) {
|
||||
List_adp list = List_adp_.new_();
|
||||
Cfg_nde_root root = wiki.Appe().Lang_mgr().Groups();
|
||||
int len = root.Root_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Cfg_nde_obj nde = root.Root_get_at(i);
|
||||
Scrib_lang_names_grps(list, nde);
|
||||
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;
|
||||
} private static KeyVal[] scrib_lang_names;
|
||||
private void Scrib_lang_names_grps(List_adp list, Cfg_nde_obj nde) {
|
||||
int len = nde.Nde_subs_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Cfg_nde_obj lang_nde = nde.Nde_subs_get_at(i);
|
||||
if (lang_nde.Nde_typ_is_grp())
|
||||
Scrib_lang_names_grps(list, lang_nde);
|
||||
else {
|
||||
Xoac_lang_itm lang_itm = (Xoac_lang_itm)lang_nde;
|
||||
KeyVal kv = KeyVal_.new_(String_.new_u8(lang_itm.Key_bry()), String_.new_u8(lang_itm.Local_name_bry()));
|
||||
list.Add(kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Free_mem_all() {
|
||||
tmpl_result_cache.Clear();
|
||||
@@ -62,4 +50,5 @@ public class Xow_cache_mgr {
|
||||
lst_cache.Free_mem_all();
|
||||
scrib_lang_names = null;
|
||||
}
|
||||
private static KeyVal[] scrib_lang_names;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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.nss.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xow_defn_cache { // stores compiled Xot_defn
|
||||
private Xol_lang lang; // needed to lowercase names;
|
||||
private Xol_lang_itm lang; // needed to lowercase names;
|
||||
private Bry_bfr upper_1st_bfr = Bry_bfr.reset_(255);
|
||||
private Gfo_cache_mgr cache = new Gfo_cache_mgr().Max_size_(64 * 1024 * 1024).Reduce_by_(32 * 1024 * 1024);
|
||||
public Xow_defn_cache(Xol_lang lang) {this.lang = lang;}
|
||||
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 Free_mem_some() {cache.Reduce_recent();}
|
||||
|
||||
65
400_xowa/src/gplx/xowa/wikis/ctgs/Xoa_ctg_mgr.java
Normal file
65
400_xowa/src/gplx/xowa/wikis/ctgs/Xoa_ctg_mgr.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoa_ctg_mgr implements GfoInvkAble {
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
pagectgs_wtr = new Xoctg_pagelist_wtr().Init_by_app(app);
|
||||
}
|
||||
public boolean Pagecats_grouping_enabled() {return pagecats_grouping_enabled;} private boolean pagecats_grouping_enabled = false;
|
||||
public Xoctg_pagelist_wtr Pagectgs_wtr() {return pagectgs_wtr;} private Xoctg_pagelist_wtr pagectgs_wtr;
|
||||
public byte Missing_ctg_cls_tid() {return missing_ctg_cls_tid;} private byte missing_ctg_cls_tid = Missing_ctg_cls_red_tid;
|
||||
public byte[] Missing_ctg_cls_css() {
|
||||
switch (missing_ctg_cls_tid) {
|
||||
case Missing_ctg_cls_normal_tid: return Missing_ctg_cls_normal_css;
|
||||
case Missing_ctg_cls_hide_tid: return Missing_ctg_cls_hide_css;
|
||||
case Missing_ctg_cls_red_tid: return Missing_ctg_cls_red_css;
|
||||
default: throw Err_.new_unhandled(missing_ctg_cls_tid);
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_missing_ctg_cls)) return Missing_ctg_cls_tid_print(missing_ctg_cls_tid);
|
||||
else if (ctx.Match(k, Invk_missing_ctg_cls_)) missing_ctg_cls_tid = Missing_ctg_cls_tid_parse(m.ReadStr("v"));
|
||||
else if (ctx.Match(k, Invk_missing_ctg_cls_list)) return Options_missing_ctg_cls_list;
|
||||
else if (ctx.Match(k, Invk_pagecats_grouping_enabled)) return Yn.To_str(pagecats_grouping_enabled);
|
||||
else if (ctx.Match(k, Invk_pagecats_grouping_enabled_)) pagecats_grouping_enabled = m.ReadYn("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
private static final String Invk_missing_ctg_cls = "missing_ctg_cls", Invk_missing_ctg_cls_ = "missing_ctg_cls_", Invk_missing_ctg_cls_list = "missing_ctg_cls_list", Invk_pagecats_grouping_enabled = "pagecats_grouping_enabled", Invk_pagecats_grouping_enabled_ = "pagecats_grouping_enabled_";
|
||||
private static final byte Missing_ctg_cls_normal_tid = 0, Missing_ctg_cls_hide_tid = 1, Missing_ctg_cls_red_tid = 2;
|
||||
private static final String Missing_ctg_cls_normal_str = "normal", Missing_ctg_cls_hide_str = "hide", Missing_ctg_cls_red_str = "red_link";
|
||||
private static final byte[] Missing_ctg_cls_normal_css = Bry_.new_a7(".xowa-missing-category-entry {}"), Missing_ctg_cls_hide_css = Bry_.new_a7(".xowa-missing-category-entry {display: none;}"), Missing_ctg_cls_red_css = Bry_.new_a7(".xowa-missing-category-entry {color: red;}");
|
||||
private static KeyVal[] Options_missing_ctg_cls_list = KeyVal_.Ary(KeyVal_.new_(Missing_ctg_cls_normal_str), KeyVal_.new_(Missing_ctg_cls_hide_str), KeyVal_.new_(Missing_ctg_cls_red_str));
|
||||
private static byte Missing_ctg_cls_tid_parse(String v) {
|
||||
if (String_.Eq(v, Missing_ctg_cls_normal_str)) return Missing_ctg_cls_normal_tid;
|
||||
else if (String_.Eq(v, Missing_ctg_cls_hide_str)) return Missing_ctg_cls_hide_tid;
|
||||
else if (String_.Eq(v, Missing_ctg_cls_red_str)) return Missing_ctg_cls_red_tid;
|
||||
else throw Err_.new_unhandled(v);
|
||||
}
|
||||
private static String Missing_ctg_cls_tid_print(byte v) {
|
||||
switch (v) {
|
||||
case Missing_ctg_cls_normal_tid: return Missing_ctg_cls_normal_str;
|
||||
case Missing_ctg_cls_hide_tid: return Missing_ctg_cls_hide_str;
|
||||
case Missing_ctg_cls_red_tid: return Missing_ctg_cls_red_str;
|
||||
default: throw Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
public static final byte Version_null = Byte_.Zero, Version_1 = 1, Version_2 = 2;
|
||||
public static final byte Tid_null = Byte_.Max_value_127, Tid_subc = 0, Tid_file = 1, Tid_page = 2, Tid__max = 3;
|
||||
public static final byte Hidden_n = Byte_.Zero, Hidden_y = (byte)1;
|
||||
}
|
||||
30
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_cache.java
Normal file
30
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_cache.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_data_cache {
|
||||
private Hash_adp_bry regy = Hash_adp_bry.cs(); // NOTE: changed to cs from ci; cache is hashing page_ttls by ctg_name which is always ttl.Page_txt(); DATE:2014-07-07
|
||||
public Xoctg_data_ctg Get_or_null(byte[] ctg_name) {return (Xoctg_data_ctg)regy.Get_by_bry(ctg_name);}
|
||||
public Xoctg_data_ctg Load_or_null(Xowe_wiki wiki, byte[] ctg_name) {
|
||||
Gfo_usr_dlg usr_dlg = wiki.Appe().Usr_dlg();
|
||||
usr_dlg.Prog_many("", "", "loading file for category: ~{0}", String_.new_u8(ctg_name));
|
||||
Xoctg_data_ctg rv = new Xoctg_data_ctg(ctg_name);
|
||||
boolean found = wiki.Db_mgr().Load_mgr().Load_ctg_v2(rv, ctg_name); if (!found) return null;
|
||||
regy.Add(ctg_name, rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
38
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_ctg.java
Normal file
38
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_ctg.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_data_ctg {
|
||||
public Xoctg_data_ctg(byte[] ctg_name) {this.ctg_name = ctg_name;}
|
||||
public byte[] Ctg_name() {return ctg_name;} private byte[] ctg_name;
|
||||
public boolean Db_mgr_is_txt() {return db_mgr_is_txt;} public Xoctg_data_ctg Db_mgr_is_txt_(boolean v) {db_mgr_is_txt = v; return this;} private boolean db_mgr_is_txt = true;
|
||||
public int Total_by_tid(byte tid) {
|
||||
Xoctg_idx_mgr grp = Grp_by_tid(tid);
|
||||
return grp == null ? 0 : grp.Total();
|
||||
}
|
||||
public int Total_count() {
|
||||
int rv = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Xoctg_idx_mgr grp_mgr = grp_mgrs[i];
|
||||
if (grp_mgr != null) rv += grp_mgr.Total();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public boolean Hidden() {return hidden;} public Xoctg_data_ctg Hidden_(boolean v) {hidden = v; return this;} private boolean hidden;
|
||||
public Xoctg_idx_mgr[] Grp_mgrs() {return grp_mgrs;} private Xoctg_idx_mgr[] grp_mgrs = new Xoctg_idx_mgr[3];
|
||||
public Xoctg_idx_mgr Grp_by_tid(byte i) {return grp_mgrs[i];}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_ctg_tst.java
Normal file
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_data_ctg_tst.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xoctg_data_ctg_tst {
|
||||
// @Before public void init() {fxt.Clear();} private Xoctg_idx_mgr_fxt fxt = new Xoctg_idx_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
}
|
||||
}
|
||||
161
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_all.java
Normal file
161
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_all.java
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
class Xoctg_fmtr_all {
|
||||
public Xoctg_fmtr_all(byte tid) {this.Ctor(tid);}
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public byte[] Div_id() {return div_id;} private byte[] div_id;
|
||||
public int Msg_id_label() {return msg_id_label;} private int msg_id_label;
|
||||
public int Msg_id_stats() {return msg_id_stats;} private int msg_id_stats;
|
||||
public boolean Grps_enabled() {return grps_enabled;} private boolean grps_enabled;
|
||||
public Xoctg_fmtr_itm Fmtr_itm() {return fmtr_itm;} private Xoctg_fmtr_itm fmtr_itm;
|
||||
public int Grp_max() {return grp_max;} public Xoctg_fmtr_all Grp_max_(int v) {grp_max = v; return this;} private int grp_max = Xoctg_html_mgr.Grp_max_default;
|
||||
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all = Bry_fmtr.new_();
|
||||
public Bry_fmtr Html_nav() {return html_nav;} Bry_fmtr html_nav = Bry_fmtr.new_();
|
||||
public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm = Bry_fmtr.new_();
|
||||
public Bry_fmtr Html_itm_missing() {return html_itm_missing;} Bry_fmtr html_itm_missing = Bry_fmtr.new_();
|
||||
public byte[] Url_arg_bgn() {return url_arg_bgn;} private byte[] url_arg_bgn = null;
|
||||
public byte[] Url_arg_end() {return url_arg_end;} private byte[] url_arg_end = null;
|
||||
private void Ctor(byte tid) {
|
||||
this.tid = tid;
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: grps_enabled = Bool_.Y; msg_id_label = Xol_msg_itm_.Id_ctg_subc_label ; msg_id_stats = Xol_msg_itm_.Id_ctg_subc_count; div_id = Div_id_subc; url_arg_bgn = Url_arg_subc_bgn; url_arg_end = Url_arg_subc_end; this.fmtr_itm = Xoctg_fmtr_itm_subc.Instance; break;
|
||||
case Xoa_ctg_mgr.Tid_page: grps_enabled = Bool_.Y; msg_id_label = Xol_msg_itm_.Id_ctg_page_header; msg_id_stats = Xol_msg_itm_.Id_ctg_page_count; div_id = Div_id_page; url_arg_bgn = Url_arg_page_bgn; url_arg_end = Url_arg_page_end; this.fmtr_itm = Xoctg_fmtr_itm_page.Instance; break;
|
||||
case Xoa_ctg_mgr.Tid_file: grps_enabled = Bool_.Y; msg_id_label = Xol_msg_itm_.Id_ctg_file_header; msg_id_stats = Xol_msg_itm_.Id_ctg_file_count; div_id = Div_id_file; url_arg_bgn = Url_arg_file_bgn; url_arg_end = Url_arg_file_end; this.fmtr_itm = Xoctg_fmtr_itm_file.Instance; break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
html_all.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"~{div_id}\">"
|
||||
, " <h2>~{all_label}</h2>"
|
||||
, " <p>~{all_stats}</p>~{all_navs}"
|
||||
, " <div lang=\"~{lang_key}\" dir=\"~{lang_ltr}\" class=\"mw-content-~{lang_ltr}\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">~{grps}"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>~{all_navs}"
|
||||
, "</div>"
|
||||
))
|
||||
.Keys_
|
||||
("div_id", "all_label", "all_stats", "all_navs", "lang_key", "lang_ltr", "grps");
|
||||
html_nav.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " (<a href=\"~{nav_href}\" class=\"xowa_nav\" title=\"~{nav_title}\">~{nav_text}</a>)"
|
||||
))
|
||||
.Keys_("nav_href", "nav_title", "nav_text");
|
||||
html_itm.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li><a href=\"~{itm_href}\"~{itm_atr_cls} title=\"~{itm_title}\">~{itm_text}</a></li>"
|
||||
))
|
||||
.Keys_("itm_href", "itm_title", "itm_text", "itm_id", "itm_atr_cls");
|
||||
html_itm_missing.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #~{itm_id} might be talk/user page\">~{itm_text} (missing)</li>"
|
||||
))
|
||||
.Keys_("itm_href", "itm_title", "itm_text", "itm_id");
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc:
|
||||
html_itm.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li>"
|
||||
, " <div class=\"CategoryTreeSection\">"
|
||||
, " <div class=\"CategoryTreeItem\">"
|
||||
, " <span class=\"CategoryTreeBullet\">"
|
||||
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"~{itm_data_title}\" title=\"~{itm_title}\" data-ct-state=\"collapsed\">"
|
||||
, " </span> "
|
||||
, " </span>"
|
||||
, " <a href=\"~{itm_href}\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">~{itm_text}"
|
||||
, " </a>"
|
||||
, " <span title=\"~{itm_contains_title}\" dir=\"ltr\">~{itm_contains_text}"
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
)).Keys_("itm_data_title", "itm_title", "itm_href", "itm_text","itm_contains_title", "itm_contains_text");
|
||||
break;
|
||||
case Xoa_ctg_mgr.Tid_page:
|
||||
break;
|
||||
case Xoa_ctg_mgr.Tid_file:
|
||||
// html_all.Fmt_(String_.Concat_lines_nl_skip_last
|
||||
// ( ""
|
||||
// , "<div id=\"~{div_id}\">"
|
||||
// , " <h2>~{all_label}</h2>"
|
||||
// , " <p>~{all_stats}</p>"
|
||||
// , " <ul id=\"xowa_gallery_ul_0\" class=\"gallery\">~{grps}"
|
||||
// , " </ul>"
|
||||
// , "</div>"
|
||||
// ));
|
||||
break;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public byte[] Bld_bwd_fwd(Xowe_wiki wiki, Xoa_ttl ttl, Xoctg_view_grp view_grp) {
|
||||
if (view_grp.Total() < grp_max) return Bry_.Empty;
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Html_nav_bry(bfr, wiki, ttl, view_grp, Bool_.N);
|
||||
Html_nav_bry(bfr, wiki, ttl, view_grp, Bool_.Y);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
private void Html_nav_bry(Bry_bfr bfr, Xowe_wiki wiki, Xoa_ttl ttl, Xoctg_view_grp view_grp, boolean fill_at_bgn) {
|
||||
Bry_bfr href_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
Xoae_app app = wiki.Appe();
|
||||
app.Html__href_wtr().Build_to_bfr(href_bfr, app, wiki.Domain_bry(), ttl);
|
||||
byte[] arg_idx_lbl = null; byte[] arg_sortkey = null;
|
||||
if (fill_at_bgn) {
|
||||
arg_idx_lbl = url_arg_bgn;
|
||||
arg_sortkey = view_grp.Itms_last_sortkey();
|
||||
if (arg_sortkey == null)
|
||||
arg_sortkey = view_grp.Itms_at_last().Sortkey();
|
||||
}
|
||||
else {
|
||||
arg_idx_lbl = url_arg_end;
|
||||
arg_sortkey = view_grp.Itms_at_first().Sortkey();
|
||||
}
|
||||
href_bfr.Add_byte(Byte_ascii.Question).Add(arg_idx_lbl).Add_byte(Byte_ascii.Eq); // filefrom=
|
||||
href_bfr.Add(arg_sortkey); // Abc
|
||||
href_bfr.Add_byte(Byte_ascii.Hash).Add(div_id); // #mw-subcategories
|
||||
byte[] nav_href = href_bfr.To_bry_and_rls();
|
||||
byte[] nav_ttl = ttl.Full_url();
|
||||
int nav_text_id = fill_at_bgn ? Xol_msg_itm_.Id_next_results : Xol_msg_itm_.Id_prev_results;
|
||||
byte[] nav_text = wiki.Msg_mgr().Val_by_id_args(nav_text_id, grp_max); // fill_at_bgn 200 / previous 200
|
||||
html_nav.Bld_bfr(bfr, nav_href, nav_ttl, nav_text);
|
||||
}
|
||||
public static final byte[]
|
||||
Url_arg_from = Bry_.new_a7("from")
|
||||
, Url_arg_until = Bry_.new_a7("until")
|
||||
, Url_arg_subc_bgn = Bry_.new_a7("subcatfrom")
|
||||
, Url_arg_subc_end = Bry_.new_a7("subcatuntil")
|
||||
, Url_arg_page_bgn = Bry_.new_a7("pagefrom")
|
||||
, Url_arg_page_end = Bry_.new_a7("pageuntil")
|
||||
, Url_arg_file_bgn = Bry_.new_a7("filefrom")
|
||||
, Url_arg_file_end = Bry_.new_a7("fileuntil")
|
||||
, Div_id_subc = Bry_.new_a7("mw-subcategories")
|
||||
, Div_id_page = Bry_.new_a7("mw-pages")
|
||||
, Div_id_file = Bry_.new_a7("mw-category-media")
|
||||
;
|
||||
}
|
||||
interface Xoctg_fmtr_itm extends Bry_fmtr_arg {
|
||||
int Grp_end_idx();
|
||||
boolean Grp_end_at_col();
|
||||
int Col_idx(); void Col_idx_(int col_idx, int col_bgn);
|
||||
void Init_from_all(Xowe_wiki wiki, Xol_lang_itm lang, Xoctg_view_ctg ctg, Xoctg_fmtr_all mgr, Xoctg_view_grp itms_list, int itms_list_len);
|
||||
void Init_from_grp(byte[] grp_ttl, int i);
|
||||
}
|
||||
83
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_grp.java
Normal file
83
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_grp.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
class Xoctg_fmtr_grp implements Bry_fmtr_arg {
|
||||
public void Init_from_all(Xowe_wiki wiki, Xol_lang_itm lang, Xoctg_view_ctg ctg, Xoctg_fmtr_all mgr, Xoctg_view_grp itms_list) {
|
||||
this.wiki = wiki; this.mgr = mgr; this.itms_fmtr = mgr.Fmtr_itm(); this.itms_list = itms_list; len = itms_list.Len();
|
||||
itms_fmtr.Init_from_all(wiki, lang, ctg, mgr, itms_list, len);
|
||||
} private Xowe_wiki wiki; Xoctg_fmtr_itm itms_fmtr; Xoctg_view_grp itms_list; int len; Xoctg_fmtr_all mgr;
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
if (mgr.Grps_enabled()) {
|
||||
if (len == 0) return;
|
||||
int cur_idx = itms_list.Bgn(); int col_bgn = cur_idx;
|
||||
byte[] ttl_char_0 = Bry_.Empty; int col_idx = -1; boolean col_bgn_needed = true;
|
||||
while (cur_idx < len) {
|
||||
Xoctg_view_itm itm = itms_list.Itms()[cur_idx];
|
||||
byte[] itm_sortkey = itm.Sortkey();
|
||||
byte[] ttl_char_0_new = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(itm_sortkey, 0);
|
||||
byte[] grp_name = ttl_char_0_new;
|
||||
if (Bry_.Eq(ttl_char_0, ttl_char_0_new)) {
|
||||
grp_name = Bry_.Add(ttl_char_0, Byte_ascii.Space_bry, wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_list_continues));
|
||||
}
|
||||
ttl_char_0 = ttl_char_0_new;
|
||||
if (col_bgn_needed) {
|
||||
col_bgn = cur_idx;
|
||||
itms_fmtr.Col_idx_(++col_idx, col_bgn);
|
||||
html_col_bgn.Bld_bfr_many(bfr, 100 / Xoctg_html_mgr.Cols_max);
|
||||
}
|
||||
itms_fmtr.Init_from_grp(ttl_char_0, cur_idx);
|
||||
html_tbl.Bld_bfr_many(bfr, grp_name, itms_fmtr);
|
||||
cur_idx = itms_fmtr.Grp_end_idx(); col_bgn_needed = itms_fmtr.Grp_end_at_col();
|
||||
if (col_bgn_needed)
|
||||
html_col_end.Bld_bfr_many(bfr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
itms_fmtr.Col_idx_(0, len);
|
||||
itms_fmtr.Init_from_grp(Bry_.Empty, itms_list.Bgn());
|
||||
html_none.Bld_bfr_many(bfr, itms_fmtr);
|
||||
}
|
||||
}
|
||||
Bry_fmtr html_none = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "~{itms}"
|
||||
), "itms"
|
||||
);
|
||||
Bry_fmtr html_tbl = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <h3>~{grp_name}</h3>"
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
), "grp_name", "itms"
|
||||
);
|
||||
Bry_fmtr html_col_bgn = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td style=\"width: ~{width}%;\">"
|
||||
), "width"
|
||||
);
|
||||
Bry_fmtr html_col_end = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " </td>"
|
||||
));
|
||||
public static int Calc_col_max(int cols_total, int len, int col_idx) {
|
||||
if (len == 0) return 0;
|
||||
int col_max = ((len - 1) / cols_total) + 1; // NOTE: example is easiest explanation; EX: 4, 5, 6 should have max of 2, so (a) subtract 1; (b) divide by 3; (c) add 1
|
||||
return col_idx <= ((len - 1) % cols_total) ? col_max : col_max - 1; // NOTE: example is easiest explanation; EX: 4=2,1,1; 5=2,2,1; 6=2,2,2
|
||||
}
|
||||
}
|
||||
122
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_itm.java
Normal file
122
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_fmtr_itm.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.lnkis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
abstract class Xoctg_fmtr_itm_base implements Xoctg_fmtr_itm {
|
||||
public void Init_from_all(Xowe_wiki wiki, Xol_lang_itm lang, Xoctg_view_ctg ctg, Xoctg_fmtr_all mgr, Xoctg_view_grp itms_list, int itms_list_len) {
|
||||
this.wiki = wiki; this.lang = lang; this.ctg = ctg; this.list = itms_list; this.len = itms_list_len; this.msg_mgr = wiki.Msg_mgr();
|
||||
href_parser = wiki.Appe().Html__href_parser();
|
||||
html_itm = mgr.Html_itm();
|
||||
html_itm_missing = mgr.Html_itm_missing();
|
||||
history_mgr = wiki.Appe().Usere().History_mgr();
|
||||
} protected Xowe_wiki wiki; Xol_lang_itm lang; Xoctg_view_ctg ctg; protected int len; protected Xoh_href_parser href_parser; protected Bry_fmtr html_itm, html_itm_missing; protected Xoctg_view_grp list; protected Xow_msg_mgr msg_mgr;
|
||||
Xou_history_mgr history_mgr;
|
||||
public void Init_from_grp(byte[] ttl_char_0, int col_bgn) {this.ttl_char_0 = ttl_char_0; this.col_bgn = col_bgn;} private byte[] ttl_char_0; int col_bgn; int col_end;
|
||||
public int Col_idx() {return col_idx;}
|
||||
public void Col_idx_(int col_idx, int col_bgn) {
|
||||
this.col_idx = col_idx;
|
||||
this.col_bgn = col_bgn;
|
||||
col_end = col_bgn + Xoctg_fmtr_grp.Calc_col_max(Xoctg_html_mgr.Cols_max, len, col_idx);
|
||||
} int col_idx;
|
||||
public int Grp_end_idx() {return grp_end_idx;} private int grp_end_idx;
|
||||
public boolean Grp_end_at_col() {return grp_end_at_col;} private boolean grp_end_at_col;
|
||||
@gplx.Virtual public void Fmt__do(Bry_bfr bfr) {
|
||||
for (int i = col_bgn; i < len; i++) {
|
||||
if (i == col_end) {
|
||||
grp_end_idx = i;
|
||||
grp_end_at_col = true;
|
||||
return;
|
||||
}
|
||||
Xoctg_view_itm itm = list.Itms()[i];
|
||||
Xoa_ttl ttl = itm.Ttl();
|
||||
byte[] itm_sortkey = itm.Sortkey();
|
||||
byte[] ttl_bry = ttl.Page_txt();
|
||||
if (!Bry_.Has_at_bgn(itm_sortkey, ttl_char_0, 0, itm_sortkey.length)) {
|
||||
grp_end_idx = i;
|
||||
grp_end_at_col = i == col_end;
|
||||
return;
|
||||
}
|
||||
Bld_html(bfr, wiki, itm, ttl, ttl_bry, href_parser, html_itm);
|
||||
}
|
||||
grp_end_idx = len;
|
||||
grp_end_at_col = true;
|
||||
}
|
||||
@gplx.Virtual public void Bld_html(Bry_bfr bfr, Xowe_wiki wiki, Xoctg_view_itm itm, Xoa_ttl ttl, byte[] ttl_page, Xoh_href_parser href_parser, Bry_fmtr html_itm) {
|
||||
byte[] itm_href = wiki.App().Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
byte[] itm_full_ttl = ttl.Full_txt();// NOTE: ttl.Full_txt() to get full ns; EX: Template:A instead of just "A"
|
||||
byte[] itm_atr_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
Bry_fmtr fmtr = itm.Id_missing() ? html_itm_missing : html_itm;
|
||||
fmtr.Bld_bfr_many(bfr, itm_href, itm_full_ttl, itm_full_ttl, itm.Id(), itm_atr_cls);
|
||||
}
|
||||
}
|
||||
class Xoctg_fmtr_itm_page extends Xoctg_fmtr_itm_base {
|
||||
public static final Xoctg_fmtr_itm_page Instance = new Xoctg_fmtr_itm_page(); Xoctg_fmtr_itm_page() {}
|
||||
}
|
||||
class Xoctg_fmtr_itm_file extends Xoctg_fmtr_itm_base {
|
||||
// public override void Fmt__do(Bry_bfr bfr) {
|
||||
// html_itm = wiki.Html_mgr().Gallery_xtn_mgr().Html_gallery_itm_img();
|
||||
// for (int i = list.Bgn(); i < len; i++) {
|
||||
// Xoctg_view_itm itm = list.Itms()[i];
|
||||
// Xoa_ttl ttl = itm.Ttl();
|
||||
// byte[] ttl_page = ttl.Page_txt();
|
||||
// byte[] itm_href = href_parser.Build_to_bry(ttl, wiki);
|
||||
// html_itm.Bld_bfr_many(bfr
|
||||
// , 155 // "itm_box_width"
|
||||
// , 155 // "itm_div_width"
|
||||
// , 15 // "itm_margin"
|
||||
// , -1 // "img_id"
|
||||
// , ttl_page // "img_ttl"
|
||||
// , itm_href // "img_href"
|
||||
// , Bry_.Empty // "html_src"
|
||||
// , -1 // "img_width"
|
||||
// , -1 // "img_height"
|
||||
// , ttl_page // "itm_caption"
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
public static final Xoctg_fmtr_itm_file Instance = new Xoctg_fmtr_itm_file(); Xoctg_fmtr_itm_file() {}
|
||||
}
|
||||
class Xoctg_fmtr_itm_subc extends Xoctg_fmtr_itm_base {
|
||||
@Override public void Bld_html(Bry_bfr bfr, Xowe_wiki wiki, Xoctg_view_itm itm, Xoa_ttl ttl, byte[] ttl_page, Xoh_href_parser href_parser, Bry_fmtr html_itm) {
|
||||
byte[] itm_href = wiki.App().Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
int sub_ctgs = itm.Subs_ctgs();
|
||||
int sub_pages = itm.Subs_pages();
|
||||
int sub_files = itm.Subs_files();
|
||||
byte[] contains_title = msg_mgr.Val_by_id_args(Xol_msg_itm_.Id_ctgtree_subc_counts, sub_ctgs, sub_pages, sub_files);
|
||||
byte[] contains_text = Bld_contains_text(sub_ctgs, sub_pages, sub_files);
|
||||
html_itm.Bld_bfr_many(bfr, ttl.Page_db(), ttl_page, itm_href, ttl_page, contains_title, contains_text);
|
||||
}
|
||||
byte[] Bld_contains_text(int sub_ctgs, int sub_pages, int sub_files) {
|
||||
if (sub_ctgs == 0 && sub_pages == 0 && sub_files == 0) return Bry_.Empty;
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
bfr.Add_byte(Byte_ascii.Paren_bgn);
|
||||
Bld_contains_text_itm(bfr, Xol_msg_itm_.Id_ctgtree_subc_counts_ctg, sub_ctgs);
|
||||
Bld_contains_text_itm(bfr, Xol_msg_itm_.Id_ctgtree_subc_counts_page, sub_pages);
|
||||
Bld_contains_text_itm(bfr, Xol_msg_itm_.Id_ctgtree_subc_counts_file, sub_files);
|
||||
bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
private void Bld_contains_text_itm(Bry_bfr bfr, int msg_id, int val) {
|
||||
if (val == 0) return;
|
||||
if (bfr.Len() > 1) bfr.Add(Bld_contains_text_itm_dlm); // NOTE: 1 b/c Paren_bgn is always added
|
||||
bfr.Add(msg_mgr.Val_by_id_args(msg_id, val));
|
||||
} static final byte[] Bld_contains_text_itm_dlm = Bry_.new_a7(", ");
|
||||
public static final Xoctg_fmtr_itm_subc Instance = new Xoctg_fmtr_itm_subc(); Xoctg_fmtr_itm_subc() {}
|
||||
}
|
||||
135
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java
Normal file
135
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr.java
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xoctg_html_mgr implements GfoInvkAble {
|
||||
@gplx.Internal protected Xoctg_fmtr_grp Fmtr_grp() {return fmtr_grp;} private Xoctg_fmtr_grp fmtr_grp = new Xoctg_fmtr_grp();
|
||||
private final Xoctg_fmtr_all mgr_subcs = new Xoctg_fmtr_all(Xoa_ctg_mgr.Tid_subc);
|
||||
private final Xoctg_fmtr_all mgr_pages = new Xoctg_fmtr_all(Xoa_ctg_mgr.Tid_page);
|
||||
private final Xoctg_fmtr_all mgr_files = new Xoctg_fmtr_all(Xoa_ctg_mgr.Tid_file);
|
||||
public Xoctg_data_cache Data_cache() {return data_cache;} private Xoctg_data_cache data_cache = new Xoctg_data_cache();
|
||||
public void Bld_html(Xowe_wiki wiki, Xoae_page page, Bry_bfr bfr) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
try {
|
||||
if (wiki.Db_mgr().Category_version() == Xoa_ctg_mgr.Version_2)
|
||||
Bld_html_v2(wiki, page, tmp_bfr);
|
||||
else
|
||||
Bld_html_v1(wiki, page, tmp_bfr);
|
||||
bfr.Add_bfr_and_preserve(tmp_bfr.Mkr_rls());
|
||||
}
|
||||
catch (Exception e) { // ctg error should never cause page to fail
|
||||
tmp_bfr.Mkr_rls();
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to generate category: title=~{0} err=~{1}", String_.new_u8(page.Ttl().Full_txt()), Err_.Message_gplx_full(e));
|
||||
}
|
||||
} private Xoctg_url url_ctg = new Xoctg_url();
|
||||
private void Bld_html_v2(Xowe_wiki wiki, Xoae_page page, Bry_bfr bfr) {
|
||||
byte[] ttl_bry = page.Ttl().Page_db();
|
||||
Xoctg_view_ctg view_ctg = new Xoctg_view_ctg().Name_(page.Ttl().Page_txt());
|
||||
url_ctg.Parse(wiki.Appe().Usr_dlg(), page.Url());
|
||||
wiki.Db_mgr().Load_mgr().Load_ctg_v2a(view_ctg, url_ctg, ttl_bry, Grp_max_default);
|
||||
Bld_all(bfr, wiki, page.Lang(), view_ctg, Xoa_ctg_mgr.Tid_subc);
|
||||
Bld_all(bfr, wiki, page.Lang(), view_ctg, Xoa_ctg_mgr.Tid_page);
|
||||
Bld_all(bfr, wiki, page.Lang(), view_ctg, Xoa_ctg_mgr.Tid_file);
|
||||
}
|
||||
public void Get_titles(Gfo_usr_dlg usr_dlg, Xowe_wiki wiki, Xoctg_view_ctg ctg) {
|
||||
title_list.Clear();
|
||||
Add_titles(title_list, ctg.Subcs());
|
||||
Add_titles(title_list, ctg.Files());
|
||||
Add_titles(title_list, ctg.Pages());
|
||||
title_list.Sort_by(Xoctg_view_itm_sorter_id.Instance);
|
||||
int len = title_list.Count();
|
||||
int pct = len / 16;
|
||||
Xowd_page_itm dbo_page = new Xowd_page_itm();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoctg_view_itm itm = (Xoctg_view_itm)title_list.Get_at(i);
|
||||
if (pct != 0 && i % pct == 0) usr_dlg.Prog_many("", "", "loading title data: ~{0} / ~{1} -- ~{2}", i, len, String_.new_u8(itm.Sortkey()));
|
||||
boolean id_exists = wiki.Db_mgr().Load_mgr().Load_by_id(dbo_page, itm.Id());
|
||||
Xoa_ttl itm_ttl = null;
|
||||
if (id_exists)
|
||||
itm_ttl = Xoa_ttl.parse(wiki, dbo_page.Ns_id(), dbo_page.Ttl_page_db());
|
||||
else {
|
||||
itm_ttl = Xoa_ttl.parse(wiki, itm.Sortkey());
|
||||
if (itm_ttl == null)
|
||||
itm_ttl = Xoa_ttl.parse(wiki, Bry_missing);
|
||||
itm.Id_missing_(true);
|
||||
}
|
||||
itm.Ttl_(itm_ttl);
|
||||
}
|
||||
} List_adp title_list = List_adp_.new_(); static final byte[] Bry_missing = Bry_.new_a7("missing");
|
||||
private void Add_titles(List_adp title_list, Xoctg_view_grp grp) {
|
||||
int len = grp.Itms().length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoctg_view_itm itm = grp.Itms()[i];
|
||||
title_list.Add(itm);
|
||||
}
|
||||
}
|
||||
private void Bld_html_v1(Xowe_wiki wiki, Xoae_page page, Bry_bfr bfr) {
|
||||
Xoctg_view_ctg ctg = new Xoctg_view_ctg().Name_(page.Ttl().Page_txt());
|
||||
boolean found = wiki.Db_mgr().Load_mgr().Load_ctg_v1(ctg, page.Ttl().Page_db()); if (!found) return;
|
||||
Bld_all(bfr, wiki, page.Lang(), ctg, Xoa_ctg_mgr.Tid_subc);
|
||||
Bld_all(bfr, wiki, page.Lang(), ctg, Xoa_ctg_mgr.Tid_page);
|
||||
Bld_all(bfr, wiki, page.Lang(), ctg, Xoa_ctg_mgr.Tid_file);
|
||||
}
|
||||
@gplx.Internal protected void Bld_all(Bry_bfr bfr, Xowe_wiki wiki, Xol_lang_itm lang, Xoctg_view_ctg view_ctg, byte tid) {
|
||||
Xoctg_view_grp view_grp = view_ctg.Grp_by_tid(tid);
|
||||
int view_grp_len = view_grp.Itms().length; if (view_grp_len == 0) return;
|
||||
view_grp.End_(view_grp_len);
|
||||
Xoctg_fmtr_all fmtr_all = Fmtr(tid);
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] all_label = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_label(), view_ctg.Name());
|
||||
byte[] all_stats = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_stats(), view_grp.Len(), view_grp.Total());
|
||||
Xoa_ttl ctg_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, view_ctg.Name());
|
||||
byte[] all_navs = fmtr_all.Bld_bwd_fwd(wiki, ctg_ttl, view_grp);
|
||||
fmtr_grp.Init_from_all(wiki, lang, view_ctg, fmtr_all, view_grp);
|
||||
fmtr_all.Html_all().Bld_bfr_many(bfr, fmtr_all.Div_id(), all_label, all_stats, all_navs, lang.Key_bry(), lang.Dir_ltr_bry(), fmtr_grp);
|
||||
}
|
||||
public static final int Cols_max = 3;
|
||||
@gplx.Internal protected Xoctg_fmtr_all Fmtr(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: return mgr_subcs;
|
||||
case Xoa_ctg_mgr.Tid_page: return mgr_pages;
|
||||
case Xoa_ctg_mgr.Tid_file: return mgr_files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public static final int Grp_max_default = 200;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_grp_max)) return mgr_subcs.Grp_max();
|
||||
else if (ctx.Match(k, Invk_grp_max_)) {int grp_max = m.ReadInt("v"); mgr_subcs.Grp_max_(grp_max); mgr_files.Grp_max_(grp_max); mgr_pages.Grp_max_(grp_max);}
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_grp_max = "grp_max", Invk_grp_max_ = "grp_max_";
|
||||
}
|
||||
class Xoctg_view_itm_sorter_id implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_view_itm lhs = (Xoctg_view_itm)lhsObj;
|
||||
Xoctg_view_itm rhs = (Xoctg_view_itm)rhsObj;
|
||||
return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
}
|
||||
public static final Xoctg_view_itm_sorter_id Instance = new Xoctg_view_itm_sorter_id();
|
||||
}
|
||||
class Xoctg_view_itm_sorter_sortkey implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_view_itm lhs = (Xoctg_view_itm)lhsObj;
|
||||
Xoctg_view_itm rhs = (Xoctg_view_itm)rhsObj;
|
||||
return Bry_.Compare(lhs.Sortkey(), rhs.Sortkey());
|
||||
}
|
||||
public static final Xoctg_view_itm_sorter_sortkey Instance = new Xoctg_view_itm_sorter_sortkey();
|
||||
}
|
||||
270
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr_tst.java
Normal file
270
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_html_mgr_tst.java
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xoctg_html_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_ctg_page_fxt fxt = new Xoh_ctg_page_fxt();
|
||||
@Test public void Page_itm() {
|
||||
fxt .Init_itm_page("A1")
|
||||
.Test_html_page(Xoa_ctg_mgr.Tid_page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>")
|
||||
;
|
||||
}
|
||||
@Test public void Page_itm_missing() {
|
||||
fxt .Init_itm_page("A1");
|
||||
fxt .Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid_page).Itms()[0].Id_missing_(true);
|
||||
fxt .Test_html_page(Xoa_ctg_mgr.Tid_page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">A1 (missing)</li>");
|
||||
}
|
||||
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
|
||||
byte[] page_bry = Bry_.new_a7("A 1");
|
||||
Xoa_url url = Xoa_url.new_(Bry_.new_a7("en.wikipedia.org"), page_bry);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(fxt.Wiki(), page_bry);
|
||||
fxt.Wiki().Appe().Usere().History_mgr().Add(url, ttl, page_bry);
|
||||
fxt .Init_itm_page("A_1").Init_ctg_name_("Ctg_1").Init_ctg_pages_(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following page is in this category, out of 0 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A_1\" class=\"xowa-visited\" title=\"A 1\">A 1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Page_all() {
|
||||
fxt .Init_itm_page("A1").Init_ctg_name_("Ctg_1").Init_ctg_pages_(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following page is in this category, out of 0 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void File_all() {
|
||||
fxt .Init_itm_file("File:A1.png").Init_ctg_name_("Ctg_1").Init_ctg_files_(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_file, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-category-media\">"
|
||||
, " <h2>Media in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following file is in this category, out of 0 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/File:A1.png\" title=\"File:A1.png\">File:A1.png</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
// , " <ul id=\"xowa_gallery_ul_0\" class=\"gallery\">"
|
||||
// , " <li class=\"gallerybox\" style=\"width:155px;\">"
|
||||
// , " <div style=\"width:155px;\">"
|
||||
// , " <div class=\"thumb\" style=\"width:155px;\">"
|
||||
// , " <div id=\"xowa_gallery_div3_-1\" style=\"margin:15px auto;\">"
|
||||
// , " <a href=\"/wiki/File:A1.png\" class=\"image\">"
|
||||
// , " <img id=\"xowa_file_img_-1\" alt=\"A1.png\" src=\"\" width=\"-1\" height=\"-1\" />"
|
||||
// , " </a>"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " <div class=\"gallerytext\">A1.png"
|
||||
// , " </div>"
|
||||
// , " </div>"
|
||||
// , " </li>"
|
||||
// , ""
|
||||
// , " </ul>"
|
||||
}
|
||||
@Test public void Subc_all() {
|
||||
fxt .Init_itm_ctg("Category:Subc_1").Init_ctg_name_("Ctg_1").Init_ctg_files_(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_subc, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-subcategories\">"
|
||||
, " <h2>Subcategories</h2>"
|
||||
, " <p>This category has the following subcategory, out of 0 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>S</h3>"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <div class=\"CategoryTreeSection\">"
|
||||
, " <div class=\"CategoryTreeItem\">"
|
||||
, " <span class=\"CategoryTreeBullet\">"
|
||||
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"Subc_1\" title=\"Subc 1\" data-ct-state=\"collapsed\">"
|
||||
, " </span> "
|
||||
, " </span>"
|
||||
, " <a href=\"/wiki/Category:Subc_1\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">Subc 1"
|
||||
, " </a>"
|
||||
, " <span title=\"contains 0 subcategories, 0 pages, and 0 files\" dir=\"ltr\">"
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Page_all_cols() {
|
||||
fxt .Init_itm_page("A1", "A2", "A3", "B1", "C1").Init_ctg_name_("Ctg_1").Init_ctg_pages_(0, 5)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-pages\">"
|
||||
, " <h2>Pages in category \"Ctg_1\"</h2>"
|
||||
, " <p>The following 5 pages are in this category, out of 0 total.</p>"
|
||||
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
|
||||
, " <li><a href=\"/wiki/A2\" title=\"A2\">A2</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>A cont.</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/A3\" title=\"A3\">A3</a></li>"
|
||||
, " </ul>"
|
||||
, " <h3>B</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/B1\" title=\"B1\">B1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " <td style=\"width: 33%;\">"
|
||||
, " <h3>C</h3>"
|
||||
, " <ul>"
|
||||
, " <li><a href=\"/wiki/C1\" title=\"C1\">C1</a></li>"
|
||||
, " </ul>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Bld_rslts_lnk() {
|
||||
fxt.Init_itm_page("A1").Init_ctg_name_("Ctg_1").Init_ctg_pages_(1, 1)
|
||||
.Test_bld_rslts_lnk(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pageuntil=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 0</a>)"
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pagefrom=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 0</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Calc_col_max() {
|
||||
Tst_calc_col_max(3, 10, 0, 4);
|
||||
Tst_calc_col_max(3, 10, 1, 3);
|
||||
Tst_calc_col_max(3, 10, 2, 3);
|
||||
Tst_calc_col_max(3, 11, 0, 4);
|
||||
Tst_calc_col_max(3, 11, 1, 4);
|
||||
Tst_calc_col_max(3, 11, 2, 3);
|
||||
Tst_calc_col_max(3, 12, 0, 4);
|
||||
Tst_calc_col_max(3, 12, 1, 4);
|
||||
Tst_calc_col_max(3, 12, 2, 4);
|
||||
} public void Tst_calc_col_max(int cols_total, int len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmtr_grp.Calc_col_max(cols_total, len, col_idx));}
|
||||
}
|
||||
class Xoh_ctg_page_fxt {
|
||||
public Xoh_ctg_page_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
ctg_html = wiki.Html_mgr().Ns_ctg();
|
||||
ctg = new Xoctg_view_ctg();
|
||||
}
|
||||
return this;
|
||||
} private Xoae_app app; private Xoctg_html_mgr ctg_html;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoctg_view_ctg Ctg() {return ctg;} private Xoctg_view_ctg ctg;
|
||||
public void Test_bld_rslts_lnk(boolean next, String ctg_str, String expd) {
|
||||
byte[] actl = ctg_html.Fmtr(Xoa_ctg_mgr.Tid_page).Grp_max_(0).Bld_bwd_fwd(wiki, Xoa_ttl.parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid_page));
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
|
||||
}
|
||||
public Xoh_ctg_page_fxt Init_ctg_name_(String v) {ctg.Name_(Bry_.new_u8(v)); return this;}
|
||||
public Xoh_ctg_page_fxt Init_ctg_pages_(int bgn, int count) {ctg.Pages().Bgn_(bgn).All_(count).End_(count); return this;}
|
||||
public Xoh_ctg_page_fxt Init_ctg_files_(int bgn, int count) {ctg.Files().Bgn_(bgn).All_(count).End_(count); return this;}
|
||||
public Xoh_ctg_page_fxt Init_itm_page(String... titles) {ctg.Pages().Itms_(itms_(titles)).End_(titles.length); return this;}
|
||||
public Xoh_ctg_page_fxt Init_itm_file(String... titles) {ctg.Files().Itms_(itms_(titles)).End_(titles.length); return this;}
|
||||
public Xoh_ctg_page_fxt Init_itm_ctg(String... titles) {ctg.Subcs().Itms_(itms_(titles)).End_(titles.length); return this;}
|
||||
Xoctg_view_itm[] itms_(String... titles) {
|
||||
int len = titles.length;
|
||||
Xoctg_view_itm[] rv = new Xoctg_view_itm[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
String title = titles[i];
|
||||
byte[] title_bry = Bry_.new_u8(title);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, title_bry);
|
||||
rv[i] = new Xoctg_view_itm().Ttl_(ttl).Sortkey_(ttl.Page_txt());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Test_html_page(byte tid, byte grp_char_0, String expd) {
|
||||
Xoctg_fmtr_all list_mgr = ctg_html.Fmtr(tid);
|
||||
Xoctg_fmtr_itm fmtr_itm = list_mgr.Fmtr_itm();
|
||||
Xoctg_view_grp list = ctg.Grp_by_tid(tid);
|
||||
fmtr_itm.Init_from_all(wiki, wiki.Lang(), ctg, list_mgr, list, list.Len());
|
||||
fmtr_itm.Init_from_grp(new byte[] {grp_char_0}, 0);
|
||||
fmtr_itm.Col_idx_(0, 0);
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
fmtr_itm.Fmt__do(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
public void Test_html_grp(byte tid, String expd) {
|
||||
Xoctg_fmtr_all list_mgr = ctg_html.Fmtr(tid);
|
||||
Xoctg_fmtr_grp fmtr_grp = ctg_html.Fmtr_grp();
|
||||
fmtr_grp.Init_from_all(wiki, wiki.Lang(), ctg, list_mgr, ctg.Grp_by_tid(tid));
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
fmtr_grp.Fmt__do(bfr);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
public void Test_html_all(byte tid, String expd) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
ctg_html.Bld_all(bfr, wiki, wiki.Lang(), ctg, tid);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
}
|
||||
50
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_itm.java
Normal file
50
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_itm.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.flds.*;
|
||||
public class Xoctg_idx_itm {
|
||||
public int Pos() {return pos;} public Xoctg_idx_itm Pos_(int v) {pos = v; return this;} private int pos = -1;
|
||||
public int Id() {return id;} private int id;
|
||||
public int Timestamp() {return timestamp;} private int timestamp;
|
||||
public byte[] Sortkey() {return sortkey;} private byte[] sortkey;
|
||||
public int compareTo(Object obj) {Xoctg_idx_itm comp = (Xoctg_idx_itm)obj; return Int_.Compare(pos, comp.Pos());}
|
||||
public Xoctg_idx_itm Parse(Gfo_fld_rdr fld_rdr, int pos) {
|
||||
this.pos = pos;
|
||||
id = fld_rdr.Read_int_base85_len5();
|
||||
timestamp = fld_rdr.Read_int_base85_len5();
|
||||
sortkey = fld_rdr.Read_bry_escape();
|
||||
return this;
|
||||
}
|
||||
public void Load(int id, byte[] sortkey, int timestamp) {
|
||||
this.id = id; this.sortkey = sortkey; this.timestamp = timestamp;
|
||||
}
|
||||
public void Copy(Xoctg_idx_itm orig) {
|
||||
this.pos = orig.pos;
|
||||
this.id = orig.id;
|
||||
this.timestamp = orig.timestamp;
|
||||
this.sortkey = orig.sortkey;
|
||||
}
|
||||
}
|
||||
class Xoctg_idx_itm_sorter_sortkey implements gplx.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_idx_itm lhs = (Xoctg_idx_itm)lhsObj;
|
||||
Xoctg_idx_itm rhs = (Xoctg_idx_itm)rhsObj;
|
||||
return Bry_.Compare(lhs.Sortkey(), rhs.Sortkey());
|
||||
}
|
||||
public static final Xoctg_idx_itm_sorter_sortkey Instance = new Xoctg_idx_itm_sorter_sortkey();
|
||||
}
|
||||
157
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_mgr.java
Normal file
157
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_mgr.java
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.flds.*;
|
||||
public class Xoctg_idx_mgr implements GfoInvkAble {
|
||||
List_adp itms = List_adp_.new_();
|
||||
public int Block_len() {return block_len;} public Xoctg_idx_mgr Block_len_(int v) {this.block_len = v; return this;} private int block_len = Io_mgr.Len_mb;
|
||||
public int Itms_len() {return itms.Count();}
|
||||
public Xoctg_idx_itm Itms_get_at(int i) {return (Xoctg_idx_itm)itms.Get_at(i);}
|
||||
public void Itms_add(Xoctg_idx_itm itm) {itms.Add(itm);}
|
||||
public byte[] Src() {return src;} public Xoctg_idx_mgr Src_(byte[] v) {src = v; return this;} private byte[] src;
|
||||
public int Total() {return total;} public Xoctg_idx_mgr Total_(int v) {total = v; return this;} private int total;
|
||||
public void Index(Gfo_usr_dlg usr_dlg, byte[] ctg, byte[] src) {
|
||||
int len = src.length;
|
||||
// if (len < block_len) return; NOTE: do not exit early; need at least one entry or Itms_binary_search will fail
|
||||
itms.Clear();
|
||||
fld_rdr.Data_(src);
|
||||
int pipe_pos_cur = -1, pipe_pos_prv = -1;
|
||||
for (int i = block_len; i < len; i += block_len) {
|
||||
usr_dlg.Prog_many("", "", "indexing ~{0} ~{1}", i, len);
|
||||
pipe_pos_cur = Bry_find_.Find_fwd(src, Byte_ascii.Pipe, i, len); if (pipe_pos_cur == Bry_.NotFound) throw Err_.new_wo_type("ctg_idx_mgr could not find pipe.next", "ctg", String_.new_a7(ctg), "pos", i);
|
||||
if (pipe_pos_cur == len - 1) break;
|
||||
Index_itm(ctg, src, pipe_pos_cur + 1, len); // +1 to skip pipe
|
||||
pipe_pos_prv = pipe_pos_cur;
|
||||
}
|
||||
pipe_pos_cur = Bry_find_.Find_bwd(src, Byte_ascii.Pipe, len - 1, 0); if (pipe_pos_cur == Bry_.NotFound) pipe_pos_cur = 0; // 1 entry only; will not have preceding pipe
|
||||
if (pipe_pos_cur != pipe_pos_prv) // if last itm was not indexed, index it
|
||||
Index_itm(ctg, src, pipe_pos_cur + 1, len);
|
||||
}
|
||||
private void Index_itm(byte[] ctg, byte[] src, int bgn, int len) {
|
||||
int end = Bry_find_.Find_fwd(src, Byte_ascii.Pipe, bgn, len); if (end == Bry_.NotFound) throw Err_.new_wo_type("Ctg_idx_mgr could not find pipe.end", "ctg", String_.new_a7(ctg), "pos", bgn);
|
||||
fld_rdr.Pos_(bgn);
|
||||
Xoctg_idx_itm itm = new Xoctg_idx_itm().Parse(fld_rdr, bgn);
|
||||
itms.Add(itm);
|
||||
}
|
||||
public Xoctg_idx_itm Itms_binary_search(byte[] find, Int_obj_ref comp_rslt) {
|
||||
int max = itms.Count() - 1;
|
||||
int dif = max / 2;
|
||||
int pos = dif;
|
||||
Xoctg_idx_itm rv = null;
|
||||
int comp_prv = Int_.Min_value, comp_cur = 0;
|
||||
while (true) {
|
||||
rv = (Xoctg_idx_itm)itms.Get_at(pos);
|
||||
comp_cur = Bry_.Compare(find, rv.Sortkey());
|
||||
// Tfds.Write(dif, pos, comp_cur, comp_prv, String_.new_a7(find), String_.new_a7(rv.Sortkey()));
|
||||
if (comp_cur == CompareAble_.Same) break; // exact match; stop
|
||||
dif /= 2;
|
||||
if (dif == 0) dif = 1; // make sure dif is at least 1
|
||||
if (dif == 1 && comp_cur != comp_prv) break; // if dif == 1 && comp has switched; i.e: "interval is as small as it can be, and search has bounced over result (found item above and found item below)"
|
||||
pos = comp_cur == CompareAble_.More ? pos + dif : pos - dif;
|
||||
if (pos < 0 || pos > max) break;
|
||||
comp_prv = comp_cur;
|
||||
}
|
||||
comp_rslt.Val_(comp_cur);
|
||||
return rv;
|
||||
}
|
||||
public Xoctg_idx_itm Find_itm_near_bmk(byte[] src, int src_len, byte[] find, boolean arg_is_from, int bmk_comp, int bmk_bgn) {
|
||||
/*
|
||||
if arg_is_from
|
||||
. if find > idx.key, search bwd until find < idx; EX: A50 is find; A48A is idx; search bwd; A49 (still >); A48 (< break); take prv
|
||||
. if find < idx.key, search fwd until find > idx; EX: A50 is find; A51A is idx; search fwd; A51 (still <); A52 (> break); take cur
|
||||
else if arg_is_until
|
||||
. if find > idx.key, search fwd until find < idx; EX: A50 is find; A48A is idx; search bwd; A49 (still >); A48 (< break); take cur
|
||||
. if find < idx.key, search bwd until find > idx; EX: A50 is find; A51A is idx; search fwd; A51 (still <); A52 (> break); take prv
|
||||
*/
|
||||
boolean dir_fwd = bmk_comp == CompareAble_.More; // bmk is > than find; move forward
|
||||
fld_rdr.Data_(src);
|
||||
int comp_prv = bmk_comp, comp_cur = Int_.Min_value; int pos_cur = bmk_bgn;
|
||||
tmp_prv_itm.Parse(fld_rdr.Pos_(pos_cur), pos_cur); // fill prv_itm to whatever binary search found
|
||||
while (true) {
|
||||
int itm_bgn = dir_fwd ? Bry_find_.Find_fwd(src, Byte_ascii.Pipe, pos_cur, src_len) : Bry_find_.Find_bwd(src, Byte_ascii.Pipe, pos_cur);
|
||||
if (itm_bgn == Bry_.NotFound) { // stop: at first && searched bwd; note that at last && searched fwd will never return Bry_.NotFound b/c all srcs are terminated with |
|
||||
if (!arg_is_from) return null; // arg is until and nothing found; return null: EX: range of B-Y and find of until=A; no results
|
||||
else break; // arg is from; stop loop; (will use first item)
|
||||
}
|
||||
++itm_bgn; // position after pipe
|
||||
if (itm_bgn == src_len) { // stop: at last && searched fwd
|
||||
if (arg_is_from) return null; // arg is from and nothing found; return null: EX: range of B-Y and find of from=Z; no results
|
||||
else break; // arg is until; stop loop; (will use last item)
|
||||
}
|
||||
tmp_cur_itm.Parse(fld_rdr.Pos_(itm_bgn), itm_bgn);
|
||||
comp_cur = Bry_.Compare(find, tmp_cur_itm.Sortkey());
|
||||
if (comp_cur != comp_prv) break; // stop: comp_val switched; see note above
|
||||
pos_cur = dir_fwd ? itm_bgn : itm_bgn - 1; // -1 to position at pipe (note that -1 in FindBwd will position before)
|
||||
tmp_prv_itm.Copy(tmp_cur_itm);
|
||||
}
|
||||
// Tfds.Write(arg_is_from, dir_fwd, String_.new_u8(find), String_.new_u8(tmp_cur_itm.Sortkey()), String_.new_u8(tmp_prv_itm.Sortkey()));
|
||||
if (comp_cur == CompareAble_.Same) return tmp_cur_itm;
|
||||
return (arg_is_from && dir_fwd) || (!arg_is_from && !dir_fwd) ? tmp_cur_itm : tmp_prv_itm; // see note above
|
||||
} private Xoctg_idx_itm tmp_cur_itm = new Xoctg_idx_itm(), tmp_prv_itm = new Xoctg_idx_itm(); Gfo_fld_rdr fld_rdr = Gfo_fld_rdr.xowa_();
|
||||
public void Find(List_adp rv, byte[] src, boolean arg_is_from, byte[] find, int find_count, Xoctg_view_itm last_plus_one) {
|
||||
int tmp_pos = 0; int src_len = src.length;
|
||||
last_plus_one.Clear();
|
||||
if (find != null) { // find == null when no args passed; EX: "en.wikipedia.org/wiki/Category:A" (vs "en.wikipedia.org/wiki/Category:A?from=B")
|
||||
Xoctg_idx_itm itm_0 = Itms_binary_search(find, find_rslt.Val_(Byte_.Zero));
|
||||
if (find_rslt.Val() != CompareAble_.Same) {
|
||||
itm_0 = Find_itm_near_bmk(src, src_len, find, arg_is_from, find_rslt.Val(), itm_0.Pos());
|
||||
if (itm_0 == null) return; // itm out of range; EX: pages are B-Y and find is A or Z
|
||||
}
|
||||
tmp_pos = itm_0.Pos();
|
||||
if (!arg_is_from && Bry_.Compare(find, itm_0.Sortkey()) != CompareAble_.More) { // "until" means do *not* include last; go back one more; note: only do this logic if find is either < or == to slot; EX: find=AM && slot=AL; do not go back one more
|
||||
tmp_pos = Bry_find_.Find_bwd(src, Byte_ascii.Pipe, tmp_pos - 1); // -1 to position before pipe
|
||||
if (tmp_pos == Bry_.NotFound) return; // already 1st and nothing found
|
||||
else tmp_pos++;
|
||||
}
|
||||
}
|
||||
fld_rdr.Data_(src);
|
||||
for (int i = 0; i < find_count; i++) {
|
||||
fld_rdr.Pos_(tmp_pos);
|
||||
Xoctg_view_itm itm = new Xoctg_view_itm().Parse(fld_rdr.Pos_(tmp_pos), tmp_pos);
|
||||
rv.Add(itm);
|
||||
if (!arg_is_from && tmp_pos == 0) break; // 1st item and moving bwd; stop; note that 1st item does not have preceding |
|
||||
tmp_pos = arg_is_from ? Bry_find_.Find_fwd(src, Byte_ascii.Pipe, tmp_pos, src_len) : Bry_find_.Find_bwd(src, Byte_ascii.Pipe, tmp_pos - 1); // -1 to position before pipe
|
||||
if (tmp_pos == Bry_.NotFound) {
|
||||
if (arg_is_from) // moving fwd and no pipe found; exit;
|
||||
break;
|
||||
else // moving bwd and no pipe found; position at 1st item (which doesn't have a pipe); note that -1 will become 0
|
||||
tmp_pos = -1;
|
||||
}
|
||||
++tmp_pos; // position after pipe
|
||||
if (tmp_pos == src_len) break; // last pipe; stop
|
||||
}
|
||||
if (!arg_is_from)
|
||||
rv.Sort_by(Xoctg_view_itm_sorter_sortkey.Instance);
|
||||
int rv_count = rv.Count();
|
||||
if (rv_count > 0) {
|
||||
Xoctg_view_itm last_itm = (Xoctg_view_itm)rv.Get_at(rv_count - 1);
|
||||
int last_itm_pos = last_itm.Pos();
|
||||
tmp_pos = Bry_find_.Find_fwd(src, Byte_ascii.Pipe, last_itm_pos);
|
||||
if (tmp_pos != Bry_.NotFound && tmp_pos < src_len - 1) {
|
||||
++tmp_pos; // position after pipe
|
||||
last_plus_one.Parse(fld_rdr.Pos_(tmp_pos), tmp_pos);
|
||||
}
|
||||
}
|
||||
} Int_obj_ref find_rslt = Int_obj_ref.zero_();
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_block_len)) return block_len;
|
||||
else if (ctx.Match(k, Invk_block_len_)) block_len = m.ReadInt("v");
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_block_len = "block_len", Invk_block_len_ = "block_len_";
|
||||
}
|
||||
136
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_mgr_tst.java
Normal file
136
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_idx_mgr_tst.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.core.primitives.*;
|
||||
public class Xoctg_idx_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_idx_mgr_fxt fxt = new Xoctg_idx_mgr_fxt();
|
||||
@Test public void Index() {
|
||||
fxt .Init_block_len(Itm_len * 2);
|
||||
fxt .Test_index(fxt.Make_src(5), "A02", "A04");
|
||||
}
|
||||
@Test public void Binary_search_small() {
|
||||
fxt .Init_itms(Itm_len * 2, fxt.Make_src(5));
|
||||
fxt .Test_itms_binary_search("A02", "A02", CompareAble_.Same); // exact match
|
||||
fxt .Test_itms_binary_search("A03", "A02", CompareAble_.More); // >
|
||||
fxt .Test_itms_binary_search("A01", "A02", CompareAble_.Less); // <
|
||||
}
|
||||
@Test public void Binary_search_large() {
|
||||
fxt .Init_itms(Itm_len * 5, fxt.Make_src(99));
|
||||
fxt .Test_itms_binary_search("A50" , "A50", CompareAble_.Same);
|
||||
fxt .Test_itms_binary_search("A49" , "A50", CompareAble_.Less);
|
||||
fxt .Test_itms_binary_search("A51" , "A50", CompareAble_.More);
|
||||
fxt .Test_itms_binary_search("A44" , "A45", CompareAble_.Less);
|
||||
fxt .Test_itms_binary_search("A56" , "A55", CompareAble_.More);
|
||||
fxt .Test_itms_binary_search("A00" , "A05", CompareAble_.Less);
|
||||
fxt .Test_itms_binary_search("A99" , "A98", CompareAble_.More);
|
||||
}
|
||||
@Test public void Find_itm_near_bmk() {
|
||||
fxt .Init_src(fxt.Make_src(7));
|
||||
fxt .Test_find_itm_near_bmk(3, "A05A", CompareAble_.More, Bool_.Y, "A06");
|
||||
fxt .Test_find_itm_near_bmk(3, "A02A", CompareAble_.Less, Bool_.Y, "A03");
|
||||
fxt .Test_find_itm_near_bmk(3, "A05A", CompareAble_.More, Bool_.N, "A05");
|
||||
fxt .Test_find_itm_near_bmk(3, "A02A", CompareAble_.Less, Bool_.N, "A02");
|
||||
fxt .Test_find_itm_near_bmk(3, "A" , CompareAble_.Less, Bool_.Y, "A00");
|
||||
fxt .Test_find_itm_near_bmk(3, "A" , CompareAble_.Less, Bool_.N, null);
|
||||
fxt .Test_find_itm_near_bmk(3, "A99A", CompareAble_.More, Bool_.Y, null);
|
||||
fxt .Test_find_itm_near_bmk(3, "A05" , CompareAble_.More, Bool_.N, "A05"); // PURPOSE: if exact item found, return it
|
||||
}
|
||||
@Test public void Find() {
|
||||
fxt .Init_src(fxt.Make_src(99)).Init_block_len(100); // 100 bytes is roughly 7 items
|
||||
fxt .Test_find("A50" , Bool_.Y, String_.Ary("A50", "A51", "A52"), "A53");
|
||||
fxt .Test_find("A50" , Bool_.N, String_.Ary("A47", "A48", "A49"), "A50"); // check that "until" returns 49 (should not include 50)
|
||||
fxt .Test_find("A50A", Bool_.Y, String_.Ary("A51", "A52", "A53"), "A54");
|
||||
fxt .Test_find("A50A", Bool_.N, String_.Ary("A48", "A49", "A50"), "A51"); // check that "until" returns 50
|
||||
fxt .Test_find("A99A", Bool_.N, String_.Ary("A96", "A97", "A98"), null);
|
||||
fxt .Test_find("A99A", Bool_.Y, String_.Ary_empty, null);
|
||||
fxt .Test_find("A" , Bool_.Y, String_.Ary("A00", "A01", "A02"), "A03");
|
||||
fxt .Test_find("A" , Bool_.N, String_.Ary_empty, null);
|
||||
fxt .Test_find("A49A", Bool_.N, String_.Ary("A47", "A48", "A49"), "A50"); // check that "until" returns 49
|
||||
fxt .Test_find("A00" , Bool_.Y, String_.Ary("A00", "A01", "A02"), "A03"); // PURPOSE: special code for 1st item (which doesn't have a preceding pipe)
|
||||
fxt .Test_find("A98" , Bool_.Y, String_.Ary("A98"), null); // PURPOSE: handle premature end
|
||||
}
|
||||
public static final int Itm_len = 16; // 6(id|) + 6(timestamp|) + 4(A01|)
|
||||
}
|
||||
class Xoctg_idx_mgr_fxt {
|
||||
public Xoctg_idx_mgr_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.app_();
|
||||
wiki = Xoa_app_fxt.wiki_tst_(app);
|
||||
idx_mgr = new Xoctg_idx_mgr();
|
||||
}
|
||||
return this;
|
||||
} private Xoae_app app; Xowe_wiki wiki; Xoctg_idx_mgr idx_mgr; static final byte[] Ctg_name = Bry_.new_a7("Ctg_test");
|
||||
public byte[] Make_src(int len) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004().Mkr_rls();
|
||||
bfr.Add_byte_pipe(); // always have leading pipe
|
||||
for (int i = 0; i < len; i++) {
|
||||
bfr.Add_base85_len_5(i).Add_byte(Byte_ascii.Semic); // idx.Id() = i
|
||||
bfr.Add_base85_len_5(0).Add_byte(Byte_ascii.Semic); // idx.Timestamp() = ignore;
|
||||
bfr.Add_byte(Byte_ascii.Ltr_A);
|
||||
if (i < 10) bfr.Add_byte(Byte_ascii.Num_0);
|
||||
bfr.Add_int_variable(i).Add_byte_pipe();
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
public Xoctg_idx_mgr_fxt Init_itms(int block_len, byte[] src) {idx_mgr.Block_len_(block_len); idx_mgr.Index(Gfo_usr_dlg_.Test(), Ctg_name, src); return this;}
|
||||
public Xoctg_idx_mgr_fxt Init_block_len(int block_len) {idx_mgr.Block_len_(block_len); return this;}
|
||||
public Xoctg_idx_mgr_fxt Init_src(byte[] v) {src = v; src_len = v.length; return this;} private byte[] src; int src_len;
|
||||
public Xoctg_idx_mgr_fxt Test_index(byte[] src, String... expd) {
|
||||
idx_mgr.Index(Gfo_usr_dlg_.Test(), Ctg_name, src);
|
||||
Tfds.Eq_ary_str(expd, Idx_mgr_itms(idx_mgr));
|
||||
return this;
|
||||
}
|
||||
String[] Idx_mgr_itms(Xoctg_idx_mgr idx_mgr) {
|
||||
int len = idx_mgr.Itms_len();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
rv[i] = String_.new_a7(idx_mgr.Itms_get_at(i).Sortkey());
|
||||
return rv;
|
||||
}
|
||||
public Xoctg_idx_mgr_fxt Test_itms_binary_search(String find, String expd, int expd_comp) {
|
||||
comp_rslt.Val_zero_();
|
||||
Xoctg_idx_itm rslt = idx_mgr.Itms_binary_search(Bry_.new_a7(find), comp_rslt);
|
||||
Tfds.Eq(expd, String_.new_a7(rslt.Sortkey()));
|
||||
Tfds.Eq(expd_comp, comp_rslt.Val());
|
||||
return this;
|
||||
} Int_obj_ref comp_rslt = Int_obj_ref.zero_();
|
||||
public Xoctg_idx_mgr_fxt Test_find_itm_near_bmk(int idx_bgn, String find, int bmk_comp, boolean find_dir, String expd) {
|
||||
int idx_pos = (idx_bgn * Xoctg_idx_mgr_tst.Itm_len) + (bmk_comp == CompareAble_.Less ? 1 : 0);
|
||||
Xoctg_idx_itm rslt = idx_mgr.Find_itm_near_bmk(src, src_len, Bry_.new_a7(find), find_dir, bmk_comp, idx_pos);
|
||||
String actl = rslt == null ? null : String_.new_a7(rslt.Sortkey());
|
||||
Tfds.Eq(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public Xoctg_idx_mgr_fxt Test_find(String find, boolean fill_at_bgn, String[] expd_ary, String last_plus_one) {
|
||||
if (tmp_list == null) tmp_list = List_adp_.new_();
|
||||
idx_mgr.Index(Gfo_usr_dlg_.Test(), Bry_.Empty, src);
|
||||
tmp_list.Clear();
|
||||
idx_mgr.Find(tmp_list, src, fill_at_bgn, Bry_.new_a7(find), 3, tmp_last_plus_one);
|
||||
Tfds.Eq_ary(expd_ary, To_str_ary(tmp_list));
|
||||
Tfds.Eq(last_plus_one, String_.new_a7(tmp_last_plus_one.Sortkey()));
|
||||
return this;
|
||||
} List_adp tmp_list; Xoctg_view_itm tmp_last_plus_one = new Xoctg_view_itm();
|
||||
String[] To_str_ary(List_adp list) {
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
rv[i] = String_.new_a7(((Xoctg_view_itm)list.Get_at(i)).Sortkey());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_page_xtn.java
Normal file
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_page_xtn.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_page_xtn {
|
||||
public Xoctg_page_xtn(byte tid, byte[] sortkey) {this.tid = tid; this.sortkey = sortkey;}
|
||||
public byte[] Sortkey() {return sortkey;} public void Sortkey_(byte[] v) {this.sortkey = v;} private byte[] sortkey;
|
||||
public byte Tid() {return tid;} public void Tid_(byte v) {this.tid = v;} private byte tid;
|
||||
public byte Hidden() {return hidden;} public void Hidden_(byte v) {hidden = v;} private byte hidden = Bool_.__byte;
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_grp.java
Normal file
40
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_grp.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xoctg_pagelist_grp implements Bry_fmtr_arg {
|
||||
public void Init_app(Xoae_app app, boolean type_is_normal, Bry_fmtr fmtr_grp, Bry_fmtr fmtr_itm) {
|
||||
this.type_is_normal = type_is_normal;
|
||||
this.fmtr_grp = fmtr_grp;
|
||||
itms.Init_app(app, fmtr_itm);
|
||||
} private Bry_fmtr fmtr_grp;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
lbl_ctg_text = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hdr);
|
||||
lbl_ctg_help = Xol_msg_mgr_.Get_msg_val(wiki, wiki.Lang(), Key_pagecategorieslink, Bry_.Ary_empty);
|
||||
lbl_hidden = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hidden);
|
||||
itms.Init_wiki(wiki);
|
||||
} private byte[] lbl_ctg_help, lbl_ctg_text, lbl_hidden; private static final byte[] Key_pagecategorieslink = Bry_.new_a7("pagecategorieslink");
|
||||
public boolean Type_is_normal() {return type_is_normal;} private boolean type_is_normal;
|
||||
public Xoctg_pagelist_itms Itms() {return itms;} private Xoctg_pagelist_itms itms = new Xoctg_pagelist_itms();
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
if (type_is_normal)
|
||||
fmtr_grp.Bld_bfr_many(bfr, lbl_ctg_help, lbl_ctg_text, itms);
|
||||
else
|
||||
fmtr_grp.Bld_bfr_many(bfr, lbl_hidden, itms);
|
||||
}
|
||||
}
|
||||
44
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java
Normal file
44
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_itms.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
private Xoh_href_wtr href_wtr; private Xou_history_mgr history_mgr; private Bry_fmtr fmtr_itm;
|
||||
public void Init_app(Xoae_app app, Bry_fmtr fmtr_itm) {
|
||||
this.href_wtr = app.Html__href_wtr();
|
||||
this.history_mgr = app.Usere().History_mgr();
|
||||
this.fmtr_itm = fmtr_itm;
|
||||
}
|
||||
public void Init_wiki(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public void Itms_clear() {itms.Clear();} private List_adp itms = List_adp_.new_();
|
||||
public void Itms_add(Xowd_page_itm page) {itms.Add(page);}
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)itms.Get_at(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, page.Ttl_page_db());
|
||||
byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] lnki_href = href_wtr.Build_to_bry(wiki, ttl);
|
||||
byte[] lnki_ttl = ttl.Full_txt();
|
||||
byte[] lnki_text = ttl.Page_txt();
|
||||
fmtr_itm.Bld_bfr_many(bfr, lnki_cls, lnki_href, lnki_ttl, lnki_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_mgr.java
Normal file
35
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_mgr.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_pagelist_mgr implements Bry_fmtr_arg {
|
||||
public Xoctg_pagelist_mgr Init_by_app(Xoae_app app, Xoctg_pagelist_wtr hidden_wtr) {
|
||||
this.fmtr_all = hidden_wtr.Fmtr_all();
|
||||
grp_normal.Init_app(app, Bool_.Y, hidden_wtr.Fmtr_grp_normal(), hidden_wtr.Fmtr_itm());
|
||||
grp_hidden.Init_app(app, Bool_.N, hidden_wtr.Fmtr_grp_hidden(), hidden_wtr.Fmtr_itm());
|
||||
return this;
|
||||
} private Bry_fmtr fmtr_all;
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
grp_normal.Init_by_wiki(wiki);
|
||||
grp_hidden.Init_by_wiki(wiki);
|
||||
}
|
||||
public Xoctg_pagelist_grp Grp_normal() {return grp_normal;} private Xoctg_pagelist_grp grp_normal = new Xoctg_pagelist_grp();
|
||||
public Xoctg_pagelist_grp Grp_hidden() {return grp_hidden;} private Xoctg_pagelist_grp grp_hidden = new Xoctg_pagelist_grp();
|
||||
public void Fmt__do(Bry_bfr bfr) {
|
||||
fmtr_all.Bld_bfr_many(bfr, grp_normal, grp_hidden);
|
||||
}
|
||||
}
|
||||
69
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_wtr.java
Normal file
69
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_pagelist_wtr.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.users.history.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xoctg_pagelist_wtr {
|
||||
private Xoctg_pagelist_mgr pagelist_mgr = new Xoctg_pagelist_mgr();
|
||||
public Xoctg_pagelist_wtr Init_by_app(Xoae_app app) {pagelist_mgr.Init_by_app(app, this); return this;}
|
||||
public void Write(Bry_bfr bfr, Xowe_wiki wiki, Xoae_page page) {
|
||||
Xowd_page_itm[] page_ary = wiki.Db_mgr().Load_mgr().Load_ctg_list(page.Category_list());
|
||||
Print_hidden(bfr, wiki, page_ary);
|
||||
}
|
||||
public void Print_hidden(Bry_bfr bfr, Xowe_wiki wiki, Xowd_page_itm[] page_ary) {
|
||||
int len = page_ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = page_ary[i];
|
||||
Xowd_category_itm ctg_xtn = (Xowd_category_itm)page.Xtn();
|
||||
Xoctg_pagelist_grp list = ctg_xtn != null && ctg_xtn.Hidden() ? pagelist_mgr.Grp_hidden() : pagelist_mgr.Grp_normal();
|
||||
list.Itms().Itms_add(page);
|
||||
}
|
||||
pagelist_mgr.Init_by_wiki(wiki);
|
||||
pagelist_mgr.Fmt__do(bfr);
|
||||
pagelist_mgr.Grp_hidden().Itms().Itms_clear();
|
||||
pagelist_mgr.Grp_normal().Itms().Itms_clear();
|
||||
}
|
||||
public Bry_fmtr Fmtr_all() {return fmtr_all;} private Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">~{grp_normal}~{grp_hidden}"
|
||||
, "</div>"
|
||||
), "grp_normal", "grp_hidden"
|
||||
);
|
||||
public Bry_fmtr Fmtr_grp_normal() {return fmtr_grp_normal;} private Bry_fmtr fmtr_grp_normal = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " <a href=\"/wiki/~{ctg_help_page}\" title=\"~{ctg_help_page}\">~{ctg_text}</a>:"
|
||||
, " <ul>~{grp_itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
), "ctg_help_page", "ctg_text", "grp_itms"
|
||||
);
|
||||
public Bry_fmtr Fmtr_grp_hidden() {return fmtr_grp_hidden;} private Bry_fmtr fmtr_grp_hidden = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">~{hidden_ctg_txt}:"
|
||||
, " <ul>~{grp_itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
), "hidden_ctg_txt", "grp_itms"
|
||||
);
|
||||
public Bry_fmtr Fmtr_itm() {return fmtr_itm;} private Bry_fmtr fmtr_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <li>"
|
||||
, " <a~{lnki_cls} href=\"~{lnki_href}\" title=\"~{lnki_ttl}\">~{lnki_text}</a>"
|
||||
, " </li>"
|
||||
), "lnki_cls", "lnki_href", "lnki_ttl", "lnki_text"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xoctg_pagelist_wtr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_pagelist_mgr_fxt fxt = new Xoctg_pagelist_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init_ctg_hidden("A", "B", "C");
|
||||
fxt.Init_ctg_normal("D", "E", "F");
|
||||
fxt.Test_print_hidden(String_.Concat_lines_nl
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, " <div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, " <a href=\"/wiki/Special:Categories\" title=\"Special:Categories\">Categories</a>:"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:D\" title=\"Category:D\">D</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:E\" title=\"Category:E\">E</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:F\" title=\"Category:F\">F</a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, " <div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">Hidden categories:"
|
||||
, " <ul>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:A\" title=\"Category:A\">A</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:B\" title=\"Category:B\">B</a>"
|
||||
, " </li>"
|
||||
, " <li>"
|
||||
, " <a href=\"/wiki/Category:C\" title=\"Category:C\">C</a>"
|
||||
, " </li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xoctg_pagelist_mgr_fxt {
|
||||
public void Clear() {
|
||||
fxt = new Xop_fxt();
|
||||
app = fxt.App();
|
||||
hidden_wtr = new Xoctg_pagelist_wtr();
|
||||
hidden_wtr.Init_by_app(app);
|
||||
init_ctgs.Clear();
|
||||
} private Xop_fxt fxt; private Xoae_app app; private Xoctg_pagelist_wtr hidden_wtr;
|
||||
public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);}
|
||||
public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);}
|
||||
public void Init_ctg(boolean hidden, String[] ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
String ttl = ary[i];
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
Xowd_category_itm ctg_xtn = Xowd_category_itm.load_(0, 0, hidden, 0, 0, 0);
|
||||
page.Xtn_(ctg_xtn);
|
||||
page.Ttl_page_db_(Bry_.new_a7(ttl));
|
||||
init_ctgs.Add_many(page);
|
||||
}
|
||||
} private List_adp init_ctgs = List_adp_.new_();
|
||||
public void Test_print_hidden(String expd) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
Xowd_page_itm[] page_ary = (Xowd_page_itm[])init_ctgs.To_ary_and_clear(Xowd_page_itm.class);
|
||||
hidden_wtr.Print_hidden(bfr, fxt.Wiki(), page_ary);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
|
||||
// Tfds.Write(bfr.To_bry_and_clear());
|
||||
}
|
||||
}
|
||||
72
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_url.java
Normal file
72
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_url.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*;
|
||||
public class Xoctg_url {
|
||||
public byte[][] Grp_idxs() {return grp_idxs;} private byte[][] grp_idxs = new byte[3][];
|
||||
public byte[] Grp_fwds() {return grp_fwds;} private byte[] grp_fwds = new byte[3];
|
||||
private void Clear() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
grp_idxs[i] = null;
|
||||
}
|
||||
}
|
||||
public Xoctg_url Parse(Gfo_usr_dlg usr_dlg, Xoa_url url) {
|
||||
this.Clear();
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
byte[] arg_key = arg.Key_bry();
|
||||
Object tid_obj = Arg_keys.Get_by_bry(arg_key);
|
||||
if (tid_obj == null) {usr_dlg.Warn_many("", "", "unknown arg_key: ~{0}", String_.new_u8(arg_key)); continue;} // ignore invalid args
|
||||
byte[] arg_val = arg.Val_bry();
|
||||
byte tid = ((Byte_obj_val)tid_obj).Val();
|
||||
switch (tid) {
|
||||
case Tid_all_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break; // if "from", default all grps to val; DATE:2014-02-05
|
||||
case Tid_all_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_subc_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_subc_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_file_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_file_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_page_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_page_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Set_grp(byte[] val, byte fwd, byte... tids) {
|
||||
int tids_len = tids.length;
|
||||
for (int i = 0; i < tids_len; i++) {
|
||||
byte tid = tids[i];
|
||||
grp_fwds[tid] = fwd;
|
||||
grp_idxs[tid] = val;
|
||||
}
|
||||
}
|
||||
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
|
||||
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_from, Tid_all_bgn)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_until, Tid_all_end)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_subc_bgn, Tid_subc_bgn)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_subc_end, Tid_subc_end)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_file_bgn, Tid_file_bgn)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_file_end, Tid_file_end)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_page_bgn, Tid_page_bgn)
|
||||
.Add_bry_byte(Xoctg_fmtr_all.Url_arg_page_end, Tid_page_end)
|
||||
;
|
||||
}
|
||||
72
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_url_tst.java
Normal file
72
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_url_tst.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xoctg_url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_url_fxt fxt = new Xoctg_url_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("A?subcatfrom=B&filefrom=C&pagefrom=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?subcatuntil=B&fileuntil=C&pageuntil=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
fxt.Test_parse("A?from=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?until=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
}
|
||||
}
|
||||
class Xoctg_url_fxt {
|
||||
public Xoctg_url_chkr url() {return expd.Clear();} private Xoctg_url_chkr expd;
|
||||
public void Clear() {
|
||||
if (parser == null) {
|
||||
Xoa_app app = Xoa_app_fxt.app_();
|
||||
parser = app.User().Wikii().Utl__url_parser();
|
||||
page_url = Xoa_url.blank();
|
||||
ctg_url = new Xoctg_url();
|
||||
expd = new Xoctg_url_chkr();
|
||||
}
|
||||
} private Xoa_url_parser parser; Xoa_url page_url; Xoctg_url ctg_url;
|
||||
public void Test_parse(String url_str, Xoctg_url_chkr expd) {
|
||||
page_url = parser.Parse(Bry_.new_u8(url_str));
|
||||
ctg_url.Parse(Gfo_usr_dlg_.Test(), page_url);
|
||||
expd.Chk(ctg_url);
|
||||
expd.Clear();
|
||||
}
|
||||
}
|
||||
class Xoctg_url_chkr {
|
||||
public Xoctg_url_chkr Grp_idxs_(String subc, String file, String page) {
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_subc] = Bry_.new_a7(subc);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_file] = Bry_.new_a7(file);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_page] = Bry_.new_a7(page);
|
||||
return this;
|
||||
} byte[][] grp_idxs = new byte[Xoa_ctg_mgr.Tid__max][];
|
||||
public Xoctg_url_chkr Grp_fwds_(byte subc, byte file, byte page) {
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_subc] = subc;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_file] = file;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_page] = page;
|
||||
return this;
|
||||
} byte[] grp_fwds = new byte[Xoa_ctg_mgr.Tid__max];
|
||||
public void Chk(Xoctg_url actl) {
|
||||
Tfds.Eq_ary_str(String_.Ary(grp_idxs), String_.Ary(actl.Grp_idxs()));
|
||||
Tfds.Eq_ary(grp_fwds, actl.Grp_fwds());
|
||||
}
|
||||
public Xoctg_url_chkr Clear() {
|
||||
int len = Xoa_ctg_mgr.Tid__max;
|
||||
for (int i = 0; i < len; i++) {
|
||||
grp_idxs[i] = null;
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
57
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_ctg.java
Normal file
57
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_ctg.java
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_view_ctg {
|
||||
public byte[] Name() {return name;} public Xoctg_view_ctg Name_(byte[] v) {name = v; return this;} private byte[] name;
|
||||
public int Total_count() {return subcs.Total() + pages.Total() + files.Total();}
|
||||
public Xoctg_view_grp Subcs() {return subcs;} private Xoctg_view_grp subcs = new Xoctg_view_grp(Xoa_ctg_mgr.Tid_subc);
|
||||
public Xoctg_view_grp Pages() {return pages;} private Xoctg_view_grp pages = new Xoctg_view_grp(Xoa_ctg_mgr.Tid_page);
|
||||
public Xoctg_view_grp Files() {return files;} private Xoctg_view_grp files = new Xoctg_view_grp(Xoa_ctg_mgr.Tid_file).Hdr_exists_(false);
|
||||
public Xoctg_view_grp Grp_by_tid(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: return subcs;
|
||||
case Xoa_ctg_mgr.Tid_page: return pages;
|
||||
case Xoa_ctg_mgr.Tid_file: return files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public boolean Hidden() {return hidden;} private boolean hidden;
|
||||
public void Num_(Xoctg_data_ctg data_ctg) {
|
||||
this.hidden = data_ctg.Hidden();
|
||||
Num_set(data_ctg, Xoa_ctg_mgr.Tid_subc);
|
||||
Num_set(data_ctg, Xoa_ctg_mgr.Tid_file);
|
||||
Num_set(data_ctg, Xoa_ctg_mgr.Tid_page);
|
||||
}
|
||||
private void Num_set(Xoctg_data_ctg data_ctg, byte tid) {
|
||||
Xoctg_idx_mgr idx_mgr = data_ctg.Grp_by_tid(tid);
|
||||
if (idx_mgr != null) Grp_by_tid(tid).Total_(idx_mgr.Total());
|
||||
}
|
||||
public void Fill(Xoctg_url url_ctg, Xoctg_data_ctg data_ctg) {
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
|
||||
Fill_grp(url_ctg, data_ctg, i);
|
||||
}
|
||||
}
|
||||
private void Fill_grp(Xoctg_url url_ctg, Xoctg_data_ctg data_ctg, byte i) {
|
||||
Xoctg_view_grp view_grp = Grp_by_tid(i);
|
||||
Xoctg_idx_mgr data_grp = data_ctg.Grp_by_tid(i); if (data_grp == null) return; // no itms in grp
|
||||
byte[] url_bmk = url_ctg.Grp_idxs()[i]; byte url_bmk_fwd = url_ctg.Grp_fwds()[i];
|
||||
data_grp.Find(view_grp.Itms_list(), data_grp.Src(), url_bmk_fwd != Bool_.N_byte, url_bmk, 200, tmp_last_plus_one);
|
||||
view_grp.Itms_last_sortkey_(tmp_last_plus_one.Sortkey());
|
||||
view_grp.Itms_make();
|
||||
} private Xoctg_view_itm tmp_last_plus_one = new Xoctg_view_itm();
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_ctg_tst.java
Normal file
24
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_ctg_tst.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xoctg_view_ctg_tst {
|
||||
// @Before public void init() {fxt.Clear();} private Xoctg_idx_mgr_fxt fxt = new Xoctg_idx_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
}
|
||||
}
|
||||
41
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_grp.java
Normal file
41
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_grp.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoctg_view_grp {
|
||||
public Xoctg_view_grp(byte tid) {this.tid = tid;}
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public boolean Hdr_exists() {return hdr_exists;} public Xoctg_view_grp Hdr_exists_(boolean v) {hdr_exists = v; return this;} private boolean hdr_exists = true;
|
||||
public int Bgn() {return bgn;} public Xoctg_view_grp Bgn_(int v) {bgn = v; return this;} private int bgn;
|
||||
public int End() {return end;} public Xoctg_view_grp End_(int v) {end = v; return this;} private int end;
|
||||
public int Len() {return end - bgn;}
|
||||
public int Max() {return max;} public Xoctg_view_grp Max_(int v) {max = v; return this;} private int max;
|
||||
public int All() {return all;} public Xoctg_view_grp All_(int v) {all = v; return this;} private int all;
|
||||
public int Total() {return total;} public Xoctg_view_grp Total_(int v) {total = v; return this;} private int total;
|
||||
public Xoctg_view_itm[] Itms() {return itms;} public Xoctg_view_grp Itms_(Xoctg_view_itm[] v) {itms = v; return this;} private Xoctg_view_itm[] itms = Xoctg_view_itm.Ary_empty;
|
||||
public Xoctg_view_itm Itms_at_first() {return Itms_at(0);}
|
||||
public Xoctg_view_itm Itms_at_last() {return Itms_at(itms.length - 1);}
|
||||
Xoctg_view_itm Itms_at(int i) {
|
||||
if (i < 0 || i >= itms.length) throw Err_.new_wo_type("ctg.view: i is out of bounds", "i", i, "len", itms.length, "tid", tid);
|
||||
Xoctg_view_itm rv = itms[i]; if (rv == null) throw Err_.new_wo_type("ctg.view: itm is null", "i", i, "len", itms.length, "tid", tid);
|
||||
return rv;
|
||||
}
|
||||
public void Itms_add(Xoctg_view_itm sub) {tmp_list.Add(sub);}
|
||||
public List_adp Itms_list() {return tmp_list;} List_adp tmp_list = List_adp_.new_();
|
||||
public void Itms_make() {itms = (Xoctg_view_itm[])tmp_list.To_ary(Xoctg_view_itm.class);}
|
||||
public byte[] Itms_last_sortkey() {return itms_last_sortkey;} public Xoctg_view_grp Itms_last_sortkey_(byte[] v) {itms_last_sortkey = v; return this;} private byte[] itms_last_sortkey;
|
||||
}
|
||||
55
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_itm.java
Normal file
55
400_xowa/src/gplx/xowa/wikis/ctgs/Xoctg_view_itm.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.flds.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xoctg_view_itm implements gplx.CompareAble {
|
||||
public byte Tid() {return tid;} private byte tid;
|
||||
public int Id() {return id;} private int id;
|
||||
public boolean Id_missing() {return id_missing;} public Xoctg_view_itm Id_missing_(boolean v) {id_missing = v; return this;} private boolean id_missing;
|
||||
public int Timestamp() {return timestamp;} private int timestamp;
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xoctg_view_itm Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
|
||||
public int Page_size() {return page_size;} private int page_size;
|
||||
public int Subs_ctgs() {return subs_ctgs;} private int subs_ctgs;
|
||||
public int Subs_pages() {return subs_pages;} private int subs_pages;
|
||||
public int Subs_files() {return subs_files;} private int subs_files;
|
||||
public void Load_by_ttl_data(byte tid, int id, int timestamp, int page_size) {this.tid = tid; this.id = id; this.timestamp = timestamp; this.page_size = page_size;}
|
||||
public byte[] Sortkey() {return sortkey;} public Xoctg_view_itm Sortkey_(byte[] v) {sortkey = v; return this;} private byte[] sortkey;
|
||||
public void Subs_(int ctgs, int pages, int files) {this.subs_ctgs = ctgs; this.subs_pages = pages; this.subs_files = files;}
|
||||
public byte[] Ttl_bry() {return ttl_bry;} private byte[] ttl_bry;
|
||||
public Xow_ns Ns() {return ns;} private Xow_ns ns;
|
||||
public void Load_by_id_data(Xow_ns ns, byte[] ttl_bry) {
|
||||
this.ns = ns; this.ttl_bry = ttl_bry; this.sortkey = ttl_bry;
|
||||
}
|
||||
public static final Xoctg_view_itm[] Ary_empty = new Xoctg_view_itm[0];
|
||||
public int compareTo(Object obj) {Xoctg_view_itm comp = (Xoctg_view_itm)obj; return Int_.Compare(id, comp.Id());}
|
||||
public int Pos() {return pos;} public Xoctg_view_itm Pos_(int v) {pos = v; return this;} private int pos;
|
||||
public Xoctg_view_itm Parse(Gfo_fld_rdr fld_rdr, int pos) {
|
||||
this.pos = pos;
|
||||
id = fld_rdr.Read_int_base85_len5();
|
||||
timestamp = fld_rdr.Read_int_base85_len5();
|
||||
sortkey = fld_rdr.Read_bry_escape();
|
||||
return this;
|
||||
}
|
||||
public void Clear() {
|
||||
this.pos = 0;
|
||||
id = 0;
|
||||
timestamp = 0;
|
||||
sortkey = null;
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.lists.*; /*ComparerAble*/ import gplx.xowa.bldrs.cmds.ctgs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.vnts.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.gui.views.*;
|
||||
import gplx.xowa.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xow_data_mgr implements GfoInvkAble {
|
||||
@@ -46,7 +46,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09
|
||||
&& Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13
|
||||
) {
|
||||
Xol_lang lang = wiki.Lang();
|
||||
Xol_lang_itm lang = wiki.Lang();
|
||||
byte[] msg_key = ttl.Page_db();
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
msg_key = lang.Case_mgr().Case_build_1st_lower(tmp_bfr, msg_key, 0, msg_key.length);
|
||||
@@ -65,7 +65,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
while (true) {
|
||||
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl.Page_db());
|
||||
if (!exists) return rv.Missing_();
|
||||
if (wiki.App().App_type().Uid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
|
||||
if (wiki.App().Mode().Tid_is_gui()) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
|
||||
wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_u8(ttl.Raw()));
|
||||
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
|
||||
byte[] bry = db_page.Text();
|
||||
@@ -85,7 +85,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
}
|
||||
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl) {return Load_page_by_ttl(url, ttl, wiki.Lang(), wiki.Appe().Gui_mgr().Browser_win().Active_tab(), true);}
|
||||
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xog_tab_itm tab) {return Load_page_by_ttl(url, ttl, wiki.Lang(), tab, true);}
|
||||
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xol_lang lang, Xog_tab_itm tab, boolean parse_page) {
|
||||
public Xoae_page Load_page_by_ttl(Xoa_url url, Xoa_ttl ttl, Xol_lang_itm lang, Xog_tab_itm tab, boolean parse_page) {
|
||||
wiki.Init_assert();
|
||||
Xoae_page page = Xoae_page.new_(wiki, ttl); page.Tab_data().Tab_(tab);
|
||||
this.Get_page(page, url, ttl, false, false); // get page from data_mgr
|
||||
@@ -94,7 +94,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
Xol_vnt_mgr vnt_mgr = lang.Vnt_mgr();
|
||||
if (vnt_mgr.Enabled()) { // if vnt enabled, then try to load by vnt form; DATE:2015-09-15
|
||||
gplx.xowa.wikis.data.tbls.Xowd_page_itm page_itm = vnt_mgr.Convert_mgr().Convert_ttl(wiki, ttl);
|
||||
if (page_itm.Exists()) {
|
||||
if (page_itm != null && page_itm.Exists()) {
|
||||
Xoa_ttl vnt_ttl = Xoa_ttl.parse(wiki, ttl.Ns().Id(), page_itm.Ttl_page_db());
|
||||
page = this.Get_page(vnt_ttl, false);
|
||||
vnt_missing = page.Missing();
|
||||
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.tdbs.*;
|
||||
import gplx.xowa.nss.*;
|
||||
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(); Tfds.Now_enabled_y_();}
|
||||
@@ -151,14 +151,14 @@ class Xow_data_mgr_fxt {
|
||||
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.I.LoadFilStr(file_orig));
|
||||
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_.Id_main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Id_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.I.LoadFilStr(url));
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,5 +28,5 @@ public class Xow_page_fetcher_test implements Xow_page_fetcher {
|
||||
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_.Xto_str(ns_id) + "|" + String_.new_u8(ttl);}
|
||||
String Make_key(int ns_id, byte[] ttl) {return Int_.To_str(ns_id) + "|" + String_.new_u8(ttl);}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.dbs.metas.*; import gplx.xowa.bldrs.cmds.*; import gplx.xowa.dbs.*;
|
||||
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, Xowd_db_layout layout_text, Xowd_db_layout layout_html, Xowd_db_layout layout_file, byte zip_tid_text, byte zip_tid_html) {
|
||||
this.schema = schema;
|
||||
@@ -50,12 +50,12 @@ public class Xowd_core_db_props {
|
||||
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(Cfg_key__schema_version).To_int()
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_text).To_str())
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_html).To_str())
|
||||
, Xowd_db_layout.get_(cfg_hash.Get(Cfg_key__layout_file).To_str())
|
||||
, cfg_hash.Get(Cfg_key__zip_tid_text).To_byte()
|
||||
, cfg_hash.Get(Cfg_key__zip_tid_html).To_byte()
|
||||
( cfg_hash.Get_by(Cfg_key__schema_version).To_int()
|
||||
, Xowd_db_layout.get_(cfg_hash.Get_by(Cfg_key__layout_text).To_str())
|
||||
, Xowd_db_layout.get_(cfg_hash.Get_by(Cfg_key__layout_html).To_str())
|
||||
, Xowd_db_layout.get_(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()
|
||||
);
|
||||
}
|
||||
private static final String Cfg_grp = Xow_cfg_consts.Grp__wiki_core
|
||||
|
||||
@@ -81,7 +81,7 @@ public class Xowd_db_file {
|
||||
return rv;
|
||||
}
|
||||
public static Xowd_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.I.Get(url);
|
||||
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}", Xowd_db_file_.To_key(tid), url.Raw());
|
||||
conn = Db_conn_.Noop;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
class Xowd_db_file_hash {
|
||||
private final Ordered_hash hash = Ordered_hash_.new_();
|
||||
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 void Del(Xowd_db_file file) {
|
||||
@@ -31,7 +31,7 @@ class Xowd_db_file_hash {
|
||||
byte tid = file.Tid();
|
||||
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
|
||||
if (tids == null) {
|
||||
tids = Ordered_hash_.new_();
|
||||
tids = Ordered_hash_.New();
|
||||
hash.Add(tid, tids);
|
||||
}
|
||||
tids.Add(file.Id(), file);
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.xowa.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.bldrs.infos.*;
|
||||
public class Xowd_db_mgr {
|
||||
private Xowd_db_file[] dbs__ary = new Xowd_db_file[0]; private int dbs__ary_len = 0; private final Xowd_db_file_hash db_file_hash = new Xowd_db_file_hash();
|
||||
@@ -41,7 +41,7 @@ public class Xowd_db_mgr {
|
||||
}
|
||||
public Xowd_db_file Dbs__make_by_tid(byte tid, String ns_ids, int part_id, String file_name_suffix) {
|
||||
Io_url url = wiki_root_dir.GenSubFil(domain_itm.Domain_str() + file_name_suffix);
|
||||
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, dbs__ary_len, tid, url, ns_ids, part_id, db__core.Url().NameAndExt(), Db_conn_bldr.I.New(url));
|
||||
Xowd_db_file rv = Xowd_db_file.make_(db__core.Info_session(), props, dbs__ary_len, 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;
|
||||
@@ -52,7 +52,7 @@ public class Xowd_db_mgr {
|
||||
Xowd_db_file db = dbs__ary[i];
|
||||
if (!Byte_.In(db.Tid(), tids)) continue;
|
||||
db.Rls();
|
||||
Io_mgr.I.DeleteFil_args(db.Url()).MissingFails_off().Exec();
|
||||
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);
|
||||
@@ -60,7 +60,7 @@ public class Xowd_db_mgr {
|
||||
}
|
||||
public void Init_by_load(Io_url core_url) {
|
||||
db_file_hash.Clear();
|
||||
Db_conn core_conn = Db_conn_bldr.I.Get(core_url);
|
||||
Db_conn core_conn = Db_conn_bldr.Instance.Get(core_url);
|
||||
props = Xowd_core_db_props.Cfg_load(core_url, core_conn);
|
||||
Dbs__set_by_tid(Xowd_db_file.load_(props, Xowd_db_file_.Id_core, Core_db_tid(props.Layout_text()), core_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, Guid_adp_.Empty));
|
||||
dbs__ary = db__core.Tbl__db().Select_all(props, core_url.OwnerDir());
|
||||
@@ -77,7 +77,7 @@ public class Xowd_db_mgr {
|
||||
String core_file_name = Core_file_name(props.Layout_text(), domain_itm.Domain_str());
|
||||
byte core_db_tid = Core_db_tid(props.Layout_text());
|
||||
Io_url core_db_url = wiki_root_dir.GenSubFil(core_file_name);
|
||||
Db_conn conn = Db_conn_bldr.I.New(core_db_url);
|
||||
Db_conn conn = Db_conn_bldr.Instance.New(core_db_url);
|
||||
conn.Txn_bgn("make__core__tbls");
|
||||
Dbs__set_by_tid(Xowd_db_file.make_(info_session, props, Xowd_db_file_.Id_core, core_db_tid, core_db_url, Xob_info_file.Ns_ids_empty, Xob_info_file.Part_id_1st, core_file_name, conn));
|
||||
db__core.Tbl__db().Create_tbl();
|
||||
@@ -127,8 +127,8 @@ public class Xowd_db_mgr {
|
||||
String tid_idx_str = "";
|
||||
switch (tid) {
|
||||
case Xowd_db_file_.Tid_cat_core : break;
|
||||
case Xowd_db_file_.Tid_cat_link : tid_idx_str = "-db." + Int_.Xto_str_pad_bgn_zero(tid_idx, 3); break;
|
||||
default : tid_idx_str = tid_idx == 1 ? "" : "-db." + Int_.Xto_str_pad_bgn_zero(tid_idx, 3); break;
|
||||
case Xowd_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
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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.ctgs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.ctgs.*;
|
||||
public class Xowd_cat_link_tbl implements RlsAble {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_from, fld_to_id, fld_sortkey, fld_timestamp, fld_type_id;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.ctgs.*;
|
||||
import gplx.core.primitives.*; import gplx.xowa.wikis.ctgs.*;
|
||||
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 = Int_obj_val.new_(id); return id_val;} Int_obj_val id_val;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xowd_html_tbl implements RlsAble {
|
||||
private final String tbl_name = "html"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_page_id, fld_html_tid, fld_html_data;
|
||||
@@ -31,7 +31,7 @@ public class Xowd_html_tbl implements RlsAble {
|
||||
}
|
||||
public Db_conn Conn() {return conn;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.I, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_page_id, fld_html_tid));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_page_id, fld_html_tid));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__html__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public int Insert(int page_id, int tid, byte[] data) {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.nss.*;
|
||||
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;
|
||||
@@ -118,7 +118,7 @@ public class Xowd_page_itm {
|
||||
this.id_val = null;
|
||||
this.html_db_id = orig.html_db_id;
|
||||
}
|
||||
public void Srl_save(Bry_bfr bfr) {gplx.xowa.tdbs.Xotdb_page_itm_.Txt_id_save(bfr, this);}
|
||||
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;
|
||||
public static final Xowd_page_itm[] Ary_empty = new Xowd_page_itm[0];
|
||||
public static final Xowd_page_itm Null = null;
|
||||
|
||||
@@ -32,8 +32,8 @@ public class Xowd_page_itm_sorter implements ComparerAble {
|
||||
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.ctgs.Xoctg_page_xtn lhs_xtn = (gplx.xowa.ctgs.Xoctg_page_xtn)lhs.Xtn();
|
||||
gplx.xowa.ctgs.Xoctg_page_xtn rhs_xtn = (gplx.xowa.ctgs.Xoctg_page_xtn)rhs.Xtn();
|
||||
gplx.xowa.wikis.ctgs.Xoctg_page_xtn lhs_xtn = (gplx.xowa.wikis.ctgs.Xoctg_page_xtn)lhs.Xtn();
|
||||
gplx.xowa.wikis.ctgs.Xoctg_page_xtn rhs_xtn = (gplx.xowa.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;
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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.nss.*;
|
||||
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_() {
|
||||
|
||||
@@ -17,8 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.dbs.*; import gplx.dbs.qrys.*;
|
||||
import gplx.xowa.nss.*;
|
||||
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 RlsAble {
|
||||
private final String tbl_name = "page";
|
||||
private String fld_id, fld_ns, fld_title, fld_is_redirect, fld_touched, fld_len, fld_random_int, fld_text_db_id, fld_html_db_id, fld_redirect_id;
|
||||
@@ -134,7 +134,7 @@ public class Xowd_page_tbl implements RlsAble {
|
||||
public boolean Select_in__id(Cancelable cancelable, boolean skip_table_read, 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_();
|
||||
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];
|
||||
@@ -185,7 +185,7 @@ public class Xowd_page_tbl implements RlsAble {
|
||||
( "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_.Xto_str(ns.Id()), search_bgn, search_end, Int_.Xto_str(max_results)
|
||||
, 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();
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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.nss.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
class Xowd_page_tbl__ttl_ns extends Xowd_page_tbl__in_wkr__base {
|
||||
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
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import org.junit.*; import gplx.xowa.bldrs.*; import gplx.xowa.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() {
|
||||
|
||||
@@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xowd_pagelinks_tbl implements RlsAble {
|
||||
private final String tbl_name = "pagelinks"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String tbl_name = "pagelink"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_src_id, fld_trg_id;
|
||||
private final Db_conn conn;
|
||||
public Xowd_pagelinks_tbl(Db_conn conn) {
|
||||
@@ -31,7 +31,7 @@ public class Xowd_pagelinks_tbl implements RlsAble {
|
||||
public Db_conn Conn() {return conn;}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx__src_trg() {conn.Ddl_create_idx(Gfo_usr_dlg_.I, Db_meta_idx.new_unique_by_tbl(tbl_name, "src_trg", fld_src_id, fld_trg_id));}
|
||||
public void Create_idx__trg_src() {conn.Ddl_create_idx(Gfo_usr_dlg_.I, Db_meta_idx.new_unique_by_tbl(tbl_name, "trg_src", fld_trg_id, fld_src_id));}
|
||||
public void Create_idx__src_trg() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Db_meta_idx.new_unique_by_tbl(tbl_name, "src_trg", fld_src_id, fld_trg_id));}
|
||||
public void Create_idx__trg_src() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Db_meta_idx.new_unique_by_tbl(tbl_name, "trg_src", fld_trg_id, fld_src_id));}
|
||||
public void Rls() {}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.wikis.dbs.*; import gplx.dbs.cfgs.*;
|
||||
public class Xowd_pagelinks_temp_tbl implements RlsAble {
|
||||
private final String tbl_name = "pagelinks_temp"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_src_id, fld_trg_ns, fld_trg_ttl;
|
||||
@@ -32,7 +32,7 @@ public class Xowd_pagelinks_temp_tbl implements RlsAble {
|
||||
public Db_conn Conn() {return conn;}
|
||||
public String Tbl_name() {return tbl_name;}
|
||||
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.I, Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_src_id, fld_trg_ns, fld_trg_ttl));}
|
||||
public void Create_idx() {conn.Ddl_create_idx(Gfo_usr_dlg_.Instance, Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_src_id, fld_trg_ns, fld_trg_ttl));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("schema__pagelinks__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(int src_id, int trg_ns, byte[] trg_ttl) {
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.nss.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xowd_site_ns_tbl {
|
||||
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
|
||||
private final String fld_id, fld_name, fld_case, fld_count, fld_is_alias;
|
||||
|
||||
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.nss.*;
|
||||
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();}
|
||||
@@ -30,9 +30,9 @@ public class Xowd_wbase_qid_tbl_tst {
|
||||
class Xowd_wbase_qid_tbl_fxt {
|
||||
private Xowd_wbase_qid_tbl qid_tbl;
|
||||
public void Clear() {
|
||||
Io_mgr.I.InitEngine_mem();
|
||||
Db_conn_bldr.I.Reg_default_mem();
|
||||
Db_conn conn = Db_conn_bldr.I.New(Io_url_.mem_fil_("mem/db/wbase.xowa"));
|
||||
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();
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class Xowd_wbase_qid_tbl_fxt {
|
||||
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_.Xto_str(src_ns)), Bry_.new_u8(src_ttl));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Xowd_xowa_db_tbl {
|
||||
list.Add(Xowd_db_file.load_(props, rdr.Read_int(fld_id), rdr.Read_byte(fld_type), wiki_root_dir.GenSubFil(rdr.Read_str(fld_url)), ns_ids, part_id, guid));
|
||||
}
|
||||
} finally {rdr.Rls();}
|
||||
list.Sort_by(Xowd_db_file_sorter__id.I);
|
||||
list.Sort_by(Xowd_db_file_sorter__id.Instance);
|
||||
return (Xowd_db_file[])list.To_ary(Xowd_db_file.class);
|
||||
}
|
||||
public void Commit_all(Xowd_db_mgr core_data_mgr) {
|
||||
@@ -85,5 +85,5 @@ class Xowd_db_file_sorter__id implements gplx.lists.ComparerAble {
|
||||
Xowd_db_file rhs = (Xowd_db_file)rhsObj;
|
||||
return Int_.Compare(lhs.Id(), rhs.Id());
|
||||
}
|
||||
public static final Xowd_db_file_sorter__id I = new Xowd_db_file_sorter__id(); Xowd_db_file_sorter__id() {}
|
||||
public static final Xowd_db_file_sorter__id Instance = new Xowd_db_file_sorter__id(); Xowd_db_file_sorter__id() {}
|
||||
}
|
||||
|
||||
42
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr.java
Normal file
42
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
public interface Xodb_load_mgr {
|
||||
void Load_init (Xowe_wiki wiki);
|
||||
void Load_page (Xowd_page_itm rv, Xow_ns ns, boolean timestamp_enabled);
|
||||
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);
|
||||
int Load_ctg_count (byte[] ttl);
|
||||
boolean Load_ctg_v1 (Xoctg_view_ctg rv, byte[] ttl);
|
||||
boolean Load_ctg_v2 (Xoctg_data_ctg rv, byte[] ttl);
|
||||
void Load_ctg_v2a (Xoctg_view_ctg rv, Xoctg_url url_ctg, byte[] ttl_bry, int limit);
|
||||
Xowd_page_itm[] Load_ctg_list (byte[][] ctg_ttls);
|
||||
void Load_search (Cancelable cancelable, List_adp rv, byte[] search, int results_max);
|
||||
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);
|
||||
}
|
||||
205
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java
Normal file
205
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql.java
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*;
|
||||
import gplx.xowa.apps.gfs.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.metas.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
public Xodb_load_mgr_sql(Xodb_mgr_sql db_mgr, Xowd_db_mgr fsys_mgr) {this.db_mgr = db_mgr; this.fsys_mgr = fsys_mgr;} private Xodb_mgr_sql db_mgr; Xowd_db_mgr fsys_mgr;
|
||||
public byte Search_version() {
|
||||
if (search_version_init_needed) Search_version_init();
|
||||
return search_version;
|
||||
} private byte search_version = gplx.xowa.specials.search.Xows_page__search.Version_null;
|
||||
public void Search_version_refresh() {
|
||||
search_version_init_needed = true;
|
||||
Search_version_init();
|
||||
}
|
||||
public void Load_init(Xowe_wiki wiki) {
|
||||
Load_init_cfg(wiki);
|
||||
Xowd_db_file db_core = wiki.Data__core_mgr().Db__core();
|
||||
db_core.Tbl__site_stats().Select(wiki.Stats());
|
||||
db_core.Tbl__ns().Select_all(wiki.Ns_mgr());
|
||||
}
|
||||
private void Load_init_cfg(Xowe_wiki wiki) {
|
||||
String version_key = Xoa_gfs_wtr_.Write_func_chain(Xowe_wiki.Invk_props, Xow_wiki_props.Invk_bldr_version);
|
||||
Db_cfg_hash cfg_hash = db_mgr.Core_data_mgr().Tbl__cfg().Select_as_hash(Xow_cfg_consts.Grp__wiki_init);
|
||||
String version_val = cfg_hash.Get_by(version_key).To_str_or("");
|
||||
Xodb_upgrade_mgr.Upgrade(db_mgr, cfg_hash, version_key, version_val);
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Xoa_gfs_mgr gfs_mgr = wiki.Appe().Gfs_mgr();
|
||||
try {
|
||||
int len = cfg_hash.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Db_cfg_itm cfg_itm = cfg_hash.Get_at(i);
|
||||
Xoa_gfs_wtr_.Write_prop(bfr, Bry_.new_u8(cfg_itm.Key()), Bry_.new_u8(cfg_itm.To_str_or("")));
|
||||
}
|
||||
gfs_mgr.Run_str_for(wiki, bfr.To_str_and_clear());
|
||||
} finally {bfr.Mkr_rls();}
|
||||
}
|
||||
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, boolean timestamp_enabled) {
|
||||
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_at(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, rv, bgn, end);}
|
||||
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false;
|
||||
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return false;
|
||||
return Ctg_select_v1(db_mgr.Wiki(), db_mgr.Core_data_mgr(), rv, ctg.File_idx(), ctg);
|
||||
}
|
||||
public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.new_unimplemented();}
|
||||
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) {
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return;
|
||||
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return;
|
||||
List_adp list = List_adp_.new_();
|
||||
Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, ctg.File_idx(), list);
|
||||
Load_ctg_v2a_ui_sift(rv, ctg, list);
|
||||
}
|
||||
private void Load_ctg_v2a_db_retrieve(Xoctg_view_ctg rv, Xoctg_url ctg_url, int cat_page_id, int load_max, int cat_link_db_idx, List_adp list) {
|
||||
int len = Xoa_ctg_mgr.Tid__max;
|
||||
for (byte i = Xoa_ctg_mgr.Tid_subc; i < len; i++) {
|
||||
boolean arg_is_from = ctg_url.Grp_fwds()[i] == Bool_.N_byte;
|
||||
byte[] arg_sortkey = ctg_url.Grp_idxs()[i];
|
||||
Xowd_cat_link_tbl cat_link_tbl = db_mgr.Core_data_mgr().Dbs__get_at(cat_link_db_idx).Tbl__cat_link();
|
||||
int found = cat_link_tbl.Select_by_type(list, cat_page_id, i, arg_sortkey, arg_is_from, load_max);
|
||||
if (found > 0 && found == load_max + 1) {
|
||||
Xowd_page_itm last_page = (Xowd_page_itm)List_adp_.Pop(list);
|
||||
Xoctg_page_xtn last_ctg = (Xoctg_page_xtn)last_page.Xtn();
|
||||
rv.Grp_by_tid(i).Itms_last_sortkey_(last_ctg.Sortkey());
|
||||
}
|
||||
}
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_in__id(Cancelable_.Never, list);
|
||||
}
|
||||
private void Load_ctg_v2a_ui_sift(Xoctg_view_ctg rv, Xowd_category_itm ctg, List_adp list) {
|
||||
int len = list.Count();
|
||||
Xowe_wiki wiki = this.db_mgr.Wiki();
|
||||
byte prv_tid = Byte_.Max_value_127;
|
||||
Xoctg_view_grp view_grp = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm db_page = (Xowd_page_itm)list.Get_at(i);
|
||||
if (db_page.Ns_id() == Int_.Min_value) continue; // HACK: page not found; ignore
|
||||
Xoctg_page_xtn db_ctg = (Xoctg_page_xtn)db_page.Xtn();
|
||||
byte cur_tid = db_ctg.Tid();
|
||||
if (prv_tid != cur_tid) {
|
||||
view_grp = rv.Grp_by_tid(cur_tid);
|
||||
prv_tid = cur_tid;
|
||||
}
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, db_page.Ns_id(), db_page.Ttl_page_db());
|
||||
Xoctg_view_itm view_itm = new Xoctg_view_itm().Sortkey_(db_ctg.Sortkey()).Ttl_(ttl);
|
||||
view_itm.Load_by_ttl_data(cur_tid, db_page.Id(), Xowd_page_itm.Modified_on_null_int, db_page.Text_len());
|
||||
view_grp.Itms_add(view_itm);
|
||||
}
|
||||
len = Xoa_ctg_mgr.Tid__max;
|
||||
for (byte i = Xoa_ctg_mgr.Tid_subc; i < len; i++) {
|
||||
view_grp = rv.Grp_by_tid(i);
|
||||
view_grp.Itms_make();
|
||||
view_grp.Total_(ctg.Count_by_tid(i));
|
||||
}
|
||||
}
|
||||
private boolean search_version_init_needed = true;
|
||||
private void Search_version_init() {
|
||||
if (search_version_init_needed) {
|
||||
search_version_init_needed = false;
|
||||
Xowd_db_file search_db = db_mgr.Core_data_mgr().Db__search();
|
||||
search_version = search_db == Xowd_db_file.Null ? Xows_page__search.Version_1 : Xows_page__search.Version_2;
|
||||
}
|
||||
}
|
||||
public void Load_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
|
||||
if (search_version_init_needed) Search_version_init();
|
||||
if (search_version == gplx.xowa.specials.search.Xows_page__search.Version_1)
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_by_search(cancelable, rv, search, results_max);
|
||||
else {
|
||||
Xowd_db_mgr core_data_mgr = db_mgr.Core_data_mgr();
|
||||
core_data_mgr.Db__search().Tbl__search_word().Select_by_word(cancelable, core_data_mgr.Db__search().Tbl__search_link(), rv, search, results_max);
|
||||
core_data_mgr.Tbl__page().Select_in__id(cancelable, true, rv);
|
||||
}
|
||||
}
|
||||
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 int Load_ctg_count(byte[] ttl) {
|
||||
if (db_mgr.Core_data_mgr().Db__cat_core() == null) return 0;
|
||||
int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ttl);
|
||||
if (page_id == Xowd_page_itm.Id_null) return 0; // title not found; return 0;
|
||||
return db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select(page_id).Count_all();
|
||||
}
|
||||
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() {}
|
||||
public Xowd_page_itm[] Load_ctg_list(byte[][] ctg_ttls) {
|
||||
if (db_mgr.Core_data_mgr().Db__cat_core() == null) return Xowd_page_itm.Ary_empty;
|
||||
int len = ctg_ttls.length;
|
||||
Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
byte[] ttl = Xoa_ttl.Replace_spaces(ctg_ttls[i]); // NOTE: ctg_ttls has spaces since v1 rendered it literally;
|
||||
page.Ttl_page_db_(ttl);
|
||||
if (!hash.Has(ttl))
|
||||
hash.Add(ttl, page);
|
||||
}
|
||||
len = hash.Count(); // must update len (!hash.Has() may have skipped titles)
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Id_category, 0, len);
|
||||
Ordered_hash hash2 = Ordered_hash_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
if (!hash2.Has(page.Id_val()))
|
||||
hash2.Add(page.Id_val(), page);
|
||||
}
|
||||
len = hash2.Count(); // must update len (!hash2.Has() may have skipped titles)
|
||||
db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select_by_cat_id_in(Cancelable_.Never, hash2, 0, len);
|
||||
return (Xowd_page_itm[])hash.To_ary(Xowd_page_itm.class);
|
||||
}
|
||||
private static boolean Ctg_select_v1(Xowe_wiki wiki, Xowd_db_mgr core_data_mgr, Xoctg_view_ctg view_ctg, int link_db_id, Xowd_category_itm ctg) {
|
||||
List_adp link_list = List_adp_.new_();
|
||||
core_data_mgr.Dbs__get_at(link_db_id).Tbl__cat_link().Select_in(link_list, ctg.Id());
|
||||
int link_list_len = link_list.Count();
|
||||
link_list.Sort_by(Xowd_page_itm_sorter.IdAsc);
|
||||
core_data_mgr.Tbl__page().Select_in__id(Cancelable_.Never, false, link_list, 0, link_list_len);
|
||||
link_list.Sort_by(Xowd_page_itm_sorter.Ns_id_TtlAsc);
|
||||
boolean rv = false;
|
||||
for (int i = 0; i < link_list.Count(); i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)link_list.Get_at(i);
|
||||
if (page.Ns_id() == Int_.Min_value) continue; // HACK: page not found; ignore
|
||||
byte ctg_tid = Xodb_load_mgr_txt.Load_ctg_v1_tid(page.Ns_id());
|
||||
Xoctg_view_grp ctg_grp = view_ctg.Grp_by_tid(ctg_tid);
|
||||
Xoctg_view_itm ctg_itm = new Xoctg_view_itm();
|
||||
ctg_itm.Load_by_ttl_data(ctg_tid, page.Id(), 0, page.Text_len());
|
||||
ctg_itm.Ttl_(Xoa_ttl.parse(wiki, page.Ns_id(), page.Ttl_page_db()));
|
||||
ctg_itm.Sortkey_(page.Ttl_page_db());
|
||||
ctg_grp.Itms_add(ctg_itm);
|
||||
rv = true;
|
||||
}
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
|
||||
Xoctg_view_grp ctg_grp = view_ctg.Grp_by_tid(i);
|
||||
ctg_grp.Itms_make();
|
||||
ctg_grp.Total_(ctg_grp.Itms().length);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
173
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java
Normal file
173
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_sql_tst.java
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.bldrs.*; import gplx.xowa.wikis.ctgs.*; import gplx.dbs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xodb_load_mgr_sql_tst {
|
||||
@Before public void init() {if (Xoa_test_.Db_skip()) return; fxt.Clear();} private Xodb_load_mgr_sql_fxt fxt = new Xodb_load_mgr_sql_fxt();
|
||||
@After public void term() {if (Xoa_test_.Db_skip()) return; fxt.Rls();}
|
||||
@Test public void Load_ctg_ttls() {
|
||||
if (Xoa_test_.Db_skip()) return;
|
||||
Xowd_page_itm[] ctgs = fxt.pages_
|
||||
( fxt.ctg_(1, "Ctg_1", Bool_.Y, 10, 11, 12)
|
||||
, fxt.ctg_(2, "Ctg_2", Bool_.N, 20, 21, 22)
|
||||
, fxt.ctg_(3, "Ctg_3", Bool_.Y, 30, 31, 32)
|
||||
);
|
||||
fxt.Init_save_ctgs(ctgs);
|
||||
fxt.Test_load_ctg_list(ctgs);
|
||||
}
|
||||
}
|
||||
class Xoctg_url_mok extends Xoctg_url { public Xoctg_url_mok Page_bgn_(String v) {return Grp(Xoa_ctg_mgr.Tid_page, Bool_.Y, v);}
|
||||
public Xoctg_url_mok Page_end_(String v) {return Grp(Xoa_ctg_mgr.Tid_page, Bool_.N, v);}
|
||||
Xoctg_url_mok Grp(byte tid, boolean v, String bmk) {
|
||||
this.Grp_fwds()[tid] = v ? Bool_.Y_byte : Bool_.N_byte;
|
||||
this.Grp_idxs()[tid] = Bry_.new_a7(bmk);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Xodb_load_mgr_sql_fxt {
|
||||
Db_mgr_fxt fxt; Int_obj_ref next_id = Int_obj_ref.new_(1); Xoae_app app; Xowe_wiki wiki;
|
||||
public void Clear() {
|
||||
if (fxt == null) {
|
||||
fxt = new Db_mgr_fxt();
|
||||
fxt.Ctor_fsys();
|
||||
fxt.Init_db_sqlite();
|
||||
wiki = fxt.Wiki();
|
||||
app = wiki.Appe();
|
||||
}
|
||||
}
|
||||
public void Rls() {fxt.Rls();}
|
||||
public Xowd_page_itm[] pages_(Xowd_page_itm... ary) {return ary;}
|
||||
public Xowd_page_itm ctg_(int id, String ttl, boolean hidden, int count_subcs, int count_files, int count_pages) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl));
|
||||
Xowd_category_itm ctg = Xowd_category_itm.load_(id, 0, hidden, count_subcs, count_files, count_pages);
|
||||
rv.Xtn_(ctg);
|
||||
return rv;
|
||||
}
|
||||
public void Init_save_ctgs(Xowd_page_itm[] ary) {
|
||||
int len = ary.length;
|
||||
Xodb_mgr_sql db_mgr = wiki.Db_mgr_as_sql();
|
||||
Xowd_cat_core_tbl cat_core_tbl = db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Create_tbl();
|
||||
DateAdp modified = DateAdp_.Now();
|
||||
Xowd_page_tbl tbl_page = wiki.Db_mgr_as_sql().Core_data_mgr().Tbl__page();
|
||||
tbl_page.Insert_bgn();
|
||||
cat_core_tbl.Insert_bgn();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = ary[i];
|
||||
tbl_page.Insert_cmd_by_batch(page.Id(), page.Ns_id(), page.Ttl_page_db(), false, modified, 10, page.Id(), 0, 0);
|
||||
Xowd_category_itm ctg_itm = (Xowd_category_itm)page.Xtn();
|
||||
cat_core_tbl.Insert_cmd_by_batch(ctg_itm.Id(), ctg_itm.Count_pages(), ctg_itm.Count_subcs(), ctg_itm.Count_files(), Bool_.To_byte(ctg_itm.Hidden()), 0);
|
||||
}
|
||||
cat_core_tbl.Insert_end();
|
||||
tbl_page.Insert_end();
|
||||
}
|
||||
public void Test_load_ctg_list(Xowd_page_itm[] ary) {
|
||||
int len = ary.length;
|
||||
byte[][] ttls = new byte[len][];
|
||||
for (int i = 0; i < len; i++) {
|
||||
ttls[i] = ary[i].Ttl_page_db();
|
||||
}
|
||||
Xowd_page_itm[] actl = wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_list(ttls);
|
||||
Tfds.Eq_str_lines(Xto_str(ary), Xto_str(actl));
|
||||
}
|
||||
private static String Xto_str(Xowd_page_itm[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr.new_();
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = ary[i];
|
||||
Xowd_category_itm ctg_itm = (Xowd_category_itm)page.Xtn();
|
||||
bfr.Add_int_variable(page.Id()).Add_byte_pipe();
|
||||
bfr.Add(page.Ttl_page_db()).Add_byte_pipe();
|
||||
bfr.Add_byte(Bool_.To_byte(ctg_itm.Hidden())).Add_byte_nl();
|
||||
}
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
|
||||
public Xoctg_url_mok ctg_url_() {return new Xoctg_url_mok();}
|
||||
public Xodb_load_mgr_sql_fxt Init_limit_(int v) {limit = v; return this;} private int limit = 3;
|
||||
public void Test_select(Xoctg_url ctg_url, Xoctg_mok_ctg expd) {
|
||||
Xoctg_view_ctg view_ctg = new Xoctg_view_ctg();
|
||||
wiki.Db_mgr_as_sql().Load_mgr().Load_ctg_v2a(view_ctg, ctg_url, expd.Ttl(), limit);
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
|
||||
Xoctg_view_grp view_grp = view_ctg.Grp_by_tid(i);
|
||||
Xoctg_mok_grp mok_grp = expd.Grps_get_or_new(i);
|
||||
Tfds.Eq_ary_str(Xto_str(mok_grp), Xto_str(view_grp));
|
||||
Tfds.Eq(String_.new_a7(mok_grp.Last_plus_one_sortkey()), String_.new_a7(view_grp.Itms_last_sortkey()));
|
||||
}
|
||||
}
|
||||
String[] Xto_str(Xoctg_view_grp grp) {
|
||||
Xoctg_view_itm[] ary = grp.Itms();
|
||||
int len = ary.length;
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i< len; i++) {
|
||||
Xoctg_view_itm itm = ary[i];
|
||||
rv[i] = itm.Ttl().Page_db_as_str();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
String[] Xto_str(Xoctg_mok_grp grp) {
|
||||
List_adp list = grp.Itms();
|
||||
int len = list.Count();
|
||||
String[] rv = new String[len];
|
||||
for (int i = 0; i< len; i++) {
|
||||
Xowd_page_itm itm = (Xowd_page_itm)list.Get_at(i);
|
||||
rv[i] = String_.new_a7(itm.Ttl_page_db());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xoctg_mok_ctg ctg_() {
|
||||
Xoctg_mok_ctg rv = new Xoctg_mok_ctg(next_id);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Xoctg_mok_grp {
|
||||
public byte Tid() {return tid;} public Xoctg_mok_grp Tid_(byte v) {this.tid = v; return this;} private byte tid;
|
||||
public byte[] Last_plus_one_sortkey() {return last_plus_one_sortkey;} public Xoctg_mok_grp Last_plus_one_sortkey_(byte[] v) {this.last_plus_one_sortkey = v; return this;} private byte[] last_plus_one_sortkey;
|
||||
public List_adp Itms() {return itms;} List_adp itms = List_adp_.new_();
|
||||
}
|
||||
class Xoctg_mok_ctg {
|
||||
public Xoctg_mok_ctg(Int_obj_ref next_id) {this.next_id = next_id;} Int_obj_ref next_id;
|
||||
public byte[] Ttl() {return ttl;}
|
||||
public Xoctg_mok_ctg Ttl_(String v) {return Ttl_(Bry_.new_a7(v));}
|
||||
public Xoctg_mok_ctg Ttl_(byte[] v) {this.ttl = v; return this;} private byte[] ttl;
|
||||
public Xoctg_mok_grp[] Grps() {return grps;} private Xoctg_mok_grp[] grps = new Xoctg_mok_grp[3];
|
||||
public Xoctg_mok_grp Grps_get_or_new(byte tid) {
|
||||
Xoctg_mok_grp rv = grps[tid];
|
||||
if (rv == null) {
|
||||
rv = new Xoctg_mok_grp().Tid_(tid);
|
||||
grps[tid] = rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xoctg_mok_ctg Grp_pages_(int count) {return Grp_pages_(0, count, null);}
|
||||
public Xoctg_mok_ctg Grp_pages_(int bgn, int end, String last_itm_plus_one_sortkey) {
|
||||
Xoctg_mok_grp grp = Grps_get_or_new(Xoa_ctg_mgr.Tid_page);
|
||||
byte[] ttl_prefix = Bry_.new_a7("Page_");
|
||||
int ns_id = Xow_ns_.Id_main;
|
||||
byte ctg_tid = Xoa_ctg_mgr.Tid_page;
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte[] ttl = Bry_.Add(ttl_prefix, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 3)));
|
||||
Xoctg_page_xtn db_ctg = new Xoctg_page_xtn(ctg_tid, ttl);
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
int page_id = next_id.Val_add_post();
|
||||
page.Id_(page_id).Ns_id_(ns_id).Ttl_page_db_(ttl).Xtn_(db_ctg);
|
||||
grp.Itms().Add(page);
|
||||
}
|
||||
grp.Last_plus_one_sortkey_(Bry_.new_a7(last_itm_plus_one_sortkey));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
571
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java
Normal file
571
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_load_mgr_txt.java
Normal file
@@ -0,0 +1,571 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.*; import gplx.core.flds.*; import gplx.xowa.bldrs.cmds.ctgs.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.specials.search.*;
|
||||
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.guis.views.*;
|
||||
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, boolean timestamp_enabled) {Load_page(rv, rv.Text_db_id(), rv.Tdb_row_idx(), ns, timestamp_enabled, 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 = gplx.ios.Io_stream_rdr_.Load_all(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());
|
||||
rv.Exists_(true);
|
||||
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_utl.XtoStrByAry(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 = Xows_page__search.Match_tid_all;
|
||||
if (search_len > 0 && search[search_len - 1] == Byte_ascii.Star) {
|
||||
search = Bry_.Mid(search, 0, search_len - 1);
|
||||
match_tid = Xows_page__search.Match_tid_bgn;
|
||||
}
|
||||
int bgn_idx = this.Find_file_idx_by_ns(Xotdb_dir_info_.Tid_search_ttl, ns, search);
|
||||
if (bgn_idx == Xow_data_mgr.File_idx_unknown) return;
|
||||
if (match_tid == Xows_page__search.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_.NotFound) throw wiki.Appe().Usr_dlg().Fail_many(GRP_KEY, "invalid_search_file", "search file is invalid");
|
||||
pos += Int_.Const_dlm_len; // pipe
|
||||
|
||||
while (pos < itm_end) {
|
||||
int page_id = Base85_utl.XtoIntByAry(raw, pos, pos + 4);
|
||||
pos += 6; // 5 + 1 for semic;
|
||||
int page_len = Base85_utl.XtoIntByAry(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_ctg_v2(Xoctg_data_ctg ctg, byte[] name) {
|
||||
boolean rv = Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_category2_link, name, true); if (!rv) return false;
|
||||
byte[] src = tmp_xdat_itm.Itm_bry();
|
||||
Load_ctg_v2_data(wiki.Appe().Usr_dlg(), wiki.Appe().Utl_fld_rdr(), ctg, name, src, tmp_ctg_grp_lens);
|
||||
Load_ctg_v2_main(ctg, name);
|
||||
return true;
|
||||
} int[] tmp_ctg_grp_lens = new int[3];
|
||||
private void Load_ctg_v2_data(Gfo_usr_dlg usr_dlg, Gfo_fld_rdr fld_rdr, Xoctg_data_ctg ctg, byte[] ctg_name, byte[] src, int[] tmp_grp_lens) { // Name|subc_len|file_len|page_len|subc_bfr|file_bfr|page_bfr
|
||||
fld_rdr.Data_(src); fld_rdr.Read_bry_escape(); // 1st field is name; skip;
|
||||
Load_ctg_v2_data_lens(fld_rdr, tmp_grp_lens);
|
||||
Load_ctg_v2_data_mgrs(usr_dlg, ctg_name, src, fld_rdr.Pos(), tmp_grp_lens, ctg.Grp_mgrs());
|
||||
}
|
||||
private void Load_ctg_v2_data_lens(Gfo_fld_rdr fld_rdr, int[] grp_lens) {
|
||||
for (int i = 0; i < 3; i++)
|
||||
grp_lens[i] = fld_rdr.Read_int_base85_len5();
|
||||
}
|
||||
private void Load_ctg_v2_data_mgrs(Gfo_usr_dlg usr_dlg, byte[] ctg_name, byte[] src, int bgn, int[] grp_lens, Xoctg_idx_mgr[] grp_mgrs) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int grp_len = grp_lens[i]; if (grp_len == 0) continue;
|
||||
int end = bgn + grp_len;
|
||||
Xoctg_idx_mgr grp_mgr = new Xoctg_idx_mgr();
|
||||
byte[] grp_src = Bry_.Mid(src, bgn, end);
|
||||
grp_mgr.Src_(grp_src);
|
||||
grp_mgr.Index(usr_dlg, ctg_name, grp_src);
|
||||
grp_mgrs[i] = grp_mgr;
|
||||
bgn = end;
|
||||
}
|
||||
}
|
||||
private void Load_ctg_v2_main(Xoctg_data_ctg rv, byte[] name) {
|
||||
if (!Load_xdat_itm(tmp_xdat_itm, Xotdb_dir_info_.Tid_category2_main, name, true)) return;
|
||||
if (tmp_xdat_itm.Missing()) return;
|
||||
byte[] bry = tmp_xdat_itm.Itm_bry();
|
||||
int bgn = name.length + 1;
|
||||
boolean hidden = bry[bgn] == Byte_ascii.Ltr_y;
|
||||
int count_subcs = Base85_utl.XtoIntByAry(bry, bgn + 2, bgn + 6);
|
||||
int count_files = Base85_utl.XtoIntByAry(bry, bgn + 8, bgn + 12);
|
||||
int count_pages = Base85_utl.XtoIntByAry(bry, bgn + 14, bgn + 18);
|
||||
rv.Hidden_(hidden);
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
|
||||
Xoctg_idx_mgr idx_mgr = rv.Grp_by_tid(i);
|
||||
if (idx_mgr == null) continue;
|
||||
int count = 0;
|
||||
switch (i) {
|
||||
case Xoa_ctg_mgr.Tid_subc: count = count_subcs; break;
|
||||
case Xoa_ctg_mgr.Tid_file: count = count_files; break;
|
||||
case Xoa_ctg_mgr.Tid_page: count = count_pages; break;
|
||||
default: throw Err_.new_unhandled(i);
|
||||
}
|
||||
idx_mgr.Total_(count);
|
||||
}
|
||||
}
|
||||
public boolean Load_by_id(Xowd_page_itm page, int id) {Base85_utl.XtoStrByAry(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.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.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 = CompareAble_.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 boolean Load_ctg_v1(Xoctg_view_ctg view_ctg, byte[] ctg_ttl) {return Load_ctg_v1_wkr(view_ctg, ctg_ttl, null);}
|
||||
private boolean Load_ctg_v1_wkr(Xoctg_view_ctg view_ctg, byte[] ctg_ttl, Int_obj_ref count_only) {
|
||||
Xowd_regy_mgr ctg_regy = Get_regy_by_site(Xotdb_dir_info_.Tid_category);
|
||||
int fil_idx = ctg_regy.Files_find(ctg_ttl);
|
||||
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
|
||||
Io_url fil = fsys_mgr.Url_site_fil(Xotdb_dir_info_.Tid_category, fil_idx);
|
||||
Load_xdat_file(Cancelable_.Never, tmp_xdat_file, fil);
|
||||
tmp_xdat_file.Find(tmp_xdat_itm, ctg_ttl, 0, Byte_ascii.Pipe, true);
|
||||
if (tmp_xdat_itm.Missing()) return false;
|
||||
List_adp ctgs = List_adp_.new_();
|
||||
Load_ctg_v1_parse(ctgs, wiki.Appe().Usr_dlg(), tmp_xdat_itm.Itm_bry());
|
||||
ctgs.Sort_by(Xowd_page_itm_sorter.IdAsc);
|
||||
this.Load_by_ids(Cancelable_.Never, ctgs, 0, ctgs.Count());
|
||||
ctgs.Sort_by(Xowd_page_itm_sorter.Ns_id_TtlAsc);
|
||||
|
||||
int ctgs_len = ctgs.Count(); if (ctgs_len == 0) return false;
|
||||
if (count_only != null) { // Ctg_count specificed
|
||||
count_only.Val_(ctgs_len);
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < ctgs_len; i++) {
|
||||
Xowd_page_itm itm = (Xowd_page_itm)ctgs.Get_at(i);
|
||||
byte itm_tid = Load_ctg_v1_tid(itm.Ns_id());
|
||||
Xoctg_view_itm sub = Load_ctg_v1_sub(itm_tid, itm);
|
||||
sub.Ttl_(Xoa_ttl.parse(wiki, itm.Ns_id(), itm.Ttl_page_db())).Sortkey_(itm.Ttl_page_db());
|
||||
view_ctg.Grp_by_tid(itm_tid).Itms_add(sub);
|
||||
}
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; i++) {
|
||||
Xoctg_view_grp grp = view_ctg.Grp_by_tid(i);
|
||||
grp.Itms_make();
|
||||
grp.Total_(grp.Itms().length);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static void Load_ctg_v1_parse(List_adp rv, Gfo_usr_dlg usr_dlg, byte[] ary) {
|
||||
int aryLen = ary.length;
|
||||
int pos = Bry_find_.Find_fwd(ary, Byte_ascii.Pipe, 0, aryLen);
|
||||
int rowCount = (aryLen - pos + 1) / (Base85_utl.Len_int + gplx.xowa.apps.progs.Xoa_prog_mgr.Len_dlm_fld);
|
||||
rv.Clear();
|
||||
boolean garbage = false;
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
Xowd_page_itm row = new Xowd_page_itm();
|
||||
rv.Add(row);
|
||||
if (garbage) continue;
|
||||
int bgn = pos + 1 + (i * (Base85_utl.Len_int + gplx.xowa.apps.progs.Xoa_prog_mgr.Len_dlm_fld));
|
||||
try {
|
||||
int id = Base85_utl.XtoIntByAry(ary, bgn, bgn + Base85_utl.Len_int - 1);
|
||||
if (id < 0) throw Err_.new_wo_type("invalid id", "id", id);
|
||||
row.Id_(id);
|
||||
}
|
||||
catch (Exception e) {
|
||||
row.Id_(0);
|
||||
usr_dlg.Warn_many("xowa.ttl_request", "parse", "failed to parse row: row=~{0} err=~{1}", String_.new_u8(ary), Err_.Message_lang(e));
|
||||
garbage = true;
|
||||
continue; // NOTE: must break b/c rest of ids are garbage
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte Load_ctg_v1_tid(int ns_id) {
|
||||
switch (ns_id) {
|
||||
case Xow_ns_.Id_category: return Xoa_ctg_mgr.Tid_subc;
|
||||
case Xow_ns_.Id_file: return Xoa_ctg_mgr.Tid_file;
|
||||
default: return Xoa_ctg_mgr.Tid_page;
|
||||
}
|
||||
}
|
||||
private static Xoctg_view_itm Load_ctg_v1_sub(byte tid, Xowd_page_itm data) {
|
||||
Xoctg_view_itm rv = new Xoctg_view_itm();
|
||||
rv.Load_by_ttl_data(tid, data.Id(), 0, data.Text_len());
|
||||
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_utl.XtoIntByAry(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_(Bit_.Xto_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_utl.XtoIntByAry(src, timestamp_bgn, timestamp_end - 1);
|
||||
page.Modified_on_(Bit_.Xto_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.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.wdatas.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.wdatas.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;
|
||||
public int Load_ctg_count(byte[] ttl) {return wiki.Db_mgr().Category_version() == Xoa_ctg_mgr.Version_1 ? Load_ctg_count_v1(ttl) : Load_ctg_count_v2(ttl);}
|
||||
int Load_ctg_count_v1(byte[] ttl) {
|
||||
Xoctg_view_ctg view_ctg = new Xoctg_view_ctg();
|
||||
Int_obj_ref count = Int_obj_ref.zero_();
|
||||
Load_ctg_v1_wkr(view_ctg, ttl, count);
|
||||
return count.Val();
|
||||
}
|
||||
int Load_ctg_count_v2(byte[] ttl) {
|
||||
Xoctg_data_ctg data_ctg = new Xoctg_data_ctg(ttl);
|
||||
Load_ctg_v2(data_ctg, ttl);
|
||||
return data_ctg.Total_count();
|
||||
}
|
||||
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 void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url url_ctg, byte[] ttl_bry, int limit) {
|
||||
Xoctg_html_mgr ctg_mgr = wiki.Html_mgr().Ns_ctg();
|
||||
Xoctg_data_cache data_cache = ctg_mgr.Data_cache();
|
||||
Xoctg_data_ctg data_ctg = data_cache.Get_or_null(ttl_bry);
|
||||
if (data_ctg == null) {
|
||||
data_ctg = data_cache.Load_or_null(wiki, ttl_bry);
|
||||
if (data_ctg == null) return;
|
||||
}
|
||||
rv.Fill(url_ctg, data_ctg);
|
||||
ctg_mgr.Get_titles(wiki.Appe().Usr_dlg(), wiki, rv);
|
||||
rv.Num_(data_ctg);
|
||||
}
|
||||
public Xowd_page_itm[] Load_ctg_list(byte[][] ttls) {
|
||||
int len = ttls.length;
|
||||
Xowd_page_itm[] rv = new Xowd_page_itm[len];
|
||||
Xow_ns ns = wiki.Ns_mgr().Ns_category();
|
||||
|
||||
Xoctg_data_ctg ctg_temp = new Xoctg_data_ctg(Bry_.Empty);
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] ttl = Xoa_ttl.Replace_spaces(ttls[i]); // NOTE: ctg_ttls has spaces since v1 rendered it literally;
|
||||
Xowd_page_itm page = new Xowd_page_itm();
|
||||
this.Load_by_ttl(page, ns, ttl);
|
||||
|
||||
Load_ctg_v2_main(ctg_temp, page.Ttl_page_db());
|
||||
Xowd_category_itm ctg_itm = Xowd_category_itm.load_(page.Id(), page.Text_db_id(), ctg_temp.Hidden(), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_subc), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_file), ctg_temp.Total_by_tid(Xoa_ctg_mgr.Tid_page));
|
||||
page.Xtn_(ctg_itm);
|
||||
rv[i] = page;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
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.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() {}
|
||||
}
|
||||
28
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr.java
Normal file
28
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.htmls.hdumps.*;
|
||||
public interface Xodb_mgr extends GfoInvkAble {
|
||||
byte Tid();
|
||||
String Tid_name();
|
||||
byte Category_version();
|
||||
byte Search_version(); void Search_version_refresh();
|
||||
Xodb_load_mgr Load_mgr();
|
||||
Xodb_save_mgr Save_mgr();
|
||||
DateAdp Dump_date_query(); // used by maint_mgr
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_sql.java
Normal file
63
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_sql.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.ios.*; 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.wikis.ctgs.*; import gplx.xowa.htmls.hdumps.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
|
||||
public class Xodb_mgr_sql implements Xodb_mgr, GfoInvkAble {
|
||||
public Xodb_mgr_sql(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
this.core_data_mgr = new Xowd_db_mgr(wiki, wiki.Fsys_mgr().Root_dir(), wiki.Domain_itm());
|
||||
this.load_mgr = new Xodb_load_mgr_sql(this, core_data_mgr);
|
||||
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 Xowd_db_mgr Core_data_mgr() {return core_data_mgr;} private final Xowd_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 byte Search_version() {return load_mgr.Search_version();} public void Search_version_refresh() {load_mgr.Search_version_refresh();}
|
||||
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 = Xow_cfg_consts.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_.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 this.Search_version();
|
||||
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"
|
||||
;
|
||||
}
|
||||
61
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java
Normal file
61
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_mgr_txt.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.ios.*; import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.ctgs.*; import gplx.xowa.htmls.hdumps.*; import gplx.xowa.wikis.tdbs.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public Xodb_mgr_txt(Xowe_wiki wiki, Xow_data_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.ios.Io_stream_.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_.Id_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.specials.search.Xows_page__search.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_.Obsolete_to_str(data_storage_format);
|
||||
else if (ctx.Match(k, Invk_data_storage_format_)) data_storage_format = Io_stream_.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"
|
||||
;
|
||||
}
|
||||
24
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr.java
Normal file
24
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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();
|
||||
}
|
||||
40
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr__sql.java
Normal file
40
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr__sql.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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 Xowd_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();
|
||||
}
|
||||
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_at(page.Text_db_id()).Tbl__text();
|
||||
page.Text_(text_tbl.Select(page.Id()));
|
||||
return true;
|
||||
}
|
||||
public void Rls() {
|
||||
rdr.Rls();
|
||||
}
|
||||
}
|
||||
|
||||
88
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr__tdb.java
Normal file
88
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_page_rdr__tdb.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.ios.*;
|
||||
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_stream_rdr_.Load_all(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;
|
||||
}
|
||||
}
|
||||
27
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr.java
Normal file
27
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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);
|
||||
void 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();
|
||||
}
|
||||
80
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr_sql.java
Normal file
80
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr_sql.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.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 void Data_create(Xoa_ttl ttl, byte[] text_raw) {
|
||||
int ns_id = ttl.Ns().Id();
|
||||
Xowd_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("db", "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_new(Db_qry_sql.rdr_("SELECT (Max(page_id) + 1) AS max_page_id FROM page;")).Exec_select__rls_manual();
|
||||
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()), Db_meta_fld.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("db", "page.id_next", page_id + 1);
|
||||
} finally {rdr.Rls();}
|
||||
}
|
||||
|
||||
Xowd_db_mgr fsys_mgr = db_mgr.Core_data_mgr();
|
||||
Xowd_db_file page_text_db = fsys_mgr.Db__text();
|
||||
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, DateAdp_.Now(), text_zip, text_raw.length, ns_count, page_text_db.Id(), -1);
|
||||
db_file.Tbl__ns().Update_ns_count(ns_id, ns_count);
|
||||
db_file.Tbl__cfg().Update_int("db", "page.id_next", page_id + 1);
|
||||
} finally {
|
||||
page_core_tbl.Insert_end();
|
||||
page_text_tbl.Insert_end();
|
||||
}
|
||||
}
|
||||
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 ? DateAdp_.Now() : page.Revision_data().Modified_on();
|
||||
int page_id = page.Revision_data().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.Revision_data().Id());
|
||||
Xowd_text_tbl text_tbl = db_mgr.Core_data_mgr().Dbs__get_at(db_page.Text_db_id()).Tbl__text();
|
||||
text_tbl.Update(page.Revision_data().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.Revision_data().Id(), trg_ns, trg_ttl);
|
||||
}
|
||||
public void Clear() {}
|
||||
}
|
||||
122
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr_txt.java
Normal file
122
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_save_mgr_txt.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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 void 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, DateAdp_.Now(), 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 = gplx.ios.Io_stream_rdr_.Load_all(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
|
||||
}
|
||||
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_.Int__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 = DateAdp_.Now();
|
||||
page.Revision_data().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.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_.NotFound) lhs_bgn = -1;
|
||||
int rhs_bgn = Bry_find_.Find_bwd(rhs, Byte_ascii.Pipe); if (rhs_bgn == Bry_.NotFound) 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();
|
||||
}
|
||||
68
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_upgrade_mgr.java
Normal file
68
400_xowa/src/gplx/xowa/wikis/dbs/Xodb_upgrade_mgr.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
class Xodb_upgrade_mgr {
|
||||
public static void Upgrade(Xodb_mgr_sql db_mgr, Db_cfg_hash cfg_hash, String version_key, String version_val) {
|
||||
// String version_new = null;
|
||||
// if (String_.Eq(version_val, "0.6.2.0")) {
|
||||
// Xodb_upgrade_mgr_v0_6_2_0.Upgrade(db_mgr, kv_ary);
|
||||
// version_new = "0.6.2.1";
|
||||
// }
|
||||
// if (version_new != null) {
|
||||
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, version_key, version_new);
|
||||
// }
|
||||
}
|
||||
}
|
||||
// class Xodb_upgrade_mgr_v0_6_2_0 {
|
||||
// public static void Upgrade(Xodb_mgr_sql db_mgr, KeyVal[] kv_ary) {
|
||||
// Db_conn p = db_mgr.Fsys_mgr().Core_provider();
|
||||
// Fix_storage_format(p, db_mgr, kv_ary);
|
||||
// Fix_category_version(p, db_mgr);
|
||||
// }
|
||||
// private static void Fix_storage_format(Db_conn p, Xodb_mgr_sql db_mgr, KeyVal[] kv_ary) { // storage_format saved incorrectly as int
|
||||
// int len = kv_ary.length;
|
||||
// String gfs_data_storage_format = Xoa_gfs_mgr.Build_code(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format);
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// KeyVal kv = kv_ary[i];
|
||||
// String kv_key = kv.Key();
|
||||
// if (String_.Eq(kv_key, gfs_data_storage_format)) {
|
||||
// byte data_storage_format_byte = Byte_.parse(kv.Val_to_str_or_empty());
|
||||
// String data_storage_format_name = Xoi_dump_mgr.Wtr_tid_to_str(data_storage_format_byte);
|
||||
// kv.Val_(data_storage_format_name); // update memory
|
||||
// db_mgr.Tbl_xowa_cfg().Update(Xodb_mgr_sql.Grp__wiki_init, gfs_data_storage_format, data_storage_format_name); // update_database
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// private static void Fix_category_version(Db_conn p, Xodb_mgr_sql db_mgr) {
|
||||
// Db_qry qry = Db_qry_.select_().From_(Xodb_categorylinks_tbl.Tbl_name).Cols_(Xodb_categorylinks_tbl.Fld_cl_type_id).Where_(Db_crt_.eq_(Xodb_categorylinks_tbl.Fld_cl_type_id, ));
|
||||
// Db_stmt stmt = Db_stmt_.Null;
|
||||
// DataRdr rdr = DataRdr_.Null;
|
||||
// int types = 0;
|
||||
// try {
|
||||
// stmt = db_mgr.Fsys_mgr().Category_provider().Prepare(qry);
|
||||
// rdr = stmt.Exec_select();
|
||||
// while (rdr.MoveNextPeer()) {
|
||||
// ++types;
|
||||
// }
|
||||
// } finally {rdr.Rls(); stmt.Rls();}
|
||||
// boolean schema_is_1 = types <= 1; // if 0 or 1 types assume version_1 (1=page only; 0=not set up)
|
||||
// db_mgr.Category_version_update(true); // assume version_1; will be wrong if user actually did version_2, but currently version_1 vs version_2 has no
|
||||
// }
|
||||
// }
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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_itm lang_actl, int domain_type) {
|
||||
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;
|
||||
@@ -26,6 +26,6 @@ public class Xow_abrv_wm {
|
||||
}
|
||||
public byte[] Raw() {return raw;} private final byte[] raw;
|
||||
public byte[] Lang_domain() {return lang_domain;} private final byte[] lang_domain;
|
||||
public Xol_lang_itm Lang_actl() {return lang_actl;} private final Xol_lang_itm lang_actl;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Xow_abrv_wm_ {
|
||||
Object o = bry_trie.Match_bgn(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_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(src, 0, bry_trie.Match_pos() + 1);
|
||||
Xol_lang_stub lang_itm = Xol_lang_stub_.Get_by_key_or_intl(src, 0, bry_trie.Match_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
|
||||
@@ -48,22 +48,22 @@ public class Xow_abrv_wm_ {
|
||||
domain_type = ((Int_obj_ref)o).Val();
|
||||
}
|
||||
switch (domain_type) {
|
||||
case Xow_domain_type_.Int__wmfblog: return Xow_domain_itm_.Bry__wmforg;
|
||||
case Xow_domain_type_.Int__wikidata: return Xow_domain_itm_.Bry__wikidata;
|
||||
case Xow_domain_type_.Int__mediawiki: return Xow_domain_itm_.Bry__mediawiki;
|
||||
case Xow_domain_type_.Int__commons: return Xow_domain_itm_.Bry__commons;
|
||||
case Xow_domain_type_.Int__species: return Xow_domain_itm_.Bry__species;
|
||||
case Xow_domain_type_.Int__meta: return Xow_domain_itm_.Bry__meta;
|
||||
case Xow_domain_type_.Int__incubator: return Xow_domain_itm_.Bry__incubator;
|
||||
case Xow_domain_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikinews:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikimedia:
|
||||
case Xow_domain_tid_.Int__wmfblog: return Xow_domain_itm_.Bry__wmforg;
|
||||
case Xow_domain_tid_.Int__wikidata: return Xow_domain_itm_.Bry__wikidata;
|
||||
case Xow_domain_tid_.Int__mediawiki: return Xow_domain_itm_.Bry__mediawiki;
|
||||
case Xow_domain_tid_.Int__commons: return Xow_domain_itm_.Bry__commons;
|
||||
case Xow_domain_tid_.Int__species: return Xow_domain_itm_.Bry__species;
|
||||
case Xow_domain_tid_.Int__meta: return Xow_domain_itm_.Bry__meta;
|
||||
case Xow_domain_tid_.Int__incubator: return Xow_domain_itm_.Bry__incubator;
|
||||
case Xow_domain_tid_.Int__wikipedia:
|
||||
case Xow_domain_tid_.Int__wiktionary:
|
||||
case Xow_domain_tid_.Int__wikisource:
|
||||
case Xow_domain_tid_.Int__wikibooks:
|
||||
case Xow_domain_tid_.Int__wikiversity:
|
||||
case Xow_domain_tid_.Int__wikiquote:
|
||||
case Xow_domain_tid_.Int__wikinews:
|
||||
case Xow_domain_tid_.Int__wikivoyage:
|
||||
case Xow_domain_tid_.Int__wikimedia:
|
||||
if (lang == null) {
|
||||
lang = Bry_.Mid(src, 0, bry_trie.Match_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
|
||||
@@ -72,7 +72,7 @@ public class Xow_abrv_wm_ {
|
||||
return Bry_.Add
|
||||
( lang
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_type_.Get_type_as_bry(domain_type) // wikipedia
|
||||
, Xow_domain_tid_.Get_type_as_bry(domain_type) // wikipedia
|
||||
, Byte_ascii.Dot_bry // .
|
||||
, Xow_domain_itm_.Seg__org // org
|
||||
);
|
||||
@@ -82,14 +82,14 @@ public class Xow_abrv_wm_ {
|
||||
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_type_.Int__commons:
|
||||
case Xow_domain_type_.Int__species:
|
||||
case Xow_domain_type_.Int__meta:
|
||||
case Xow_domain_type_.Int__incubator:
|
||||
case Xow_domain_type_.Int__wikidata:
|
||||
case Xow_domain_type_.Int__mediawiki:
|
||||
case Xow_domain_type_.Int__wmfblog: bfr.Add(suffix_bry); break;
|
||||
case Xow_domain_type_.Int__other: break;
|
||||
case Xow_domain_tid_.Int__commons:
|
||||
case Xow_domain_tid_.Int__species:
|
||||
case Xow_domain_tid_.Int__meta:
|
||||
case Xow_domain_tid_.Int__incubator:
|
||||
case Xow_domain_tid_.Int__wikidata:
|
||||
case Xow_domain_tid_.Int__mediawiki:
|
||||
case Xow_domain_tid_.Int__wmfblog: bfr.Add(suffix_bry); break;
|
||||
case Xow_domain_tid_.Int__other: break;
|
||||
default: bfr.Add(lang_key).Add(suffix_bry); break;
|
||||
}
|
||||
}
|
||||
@@ -97,22 +97,22 @@ public class Xow_abrv_wm_ {
|
||||
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_type_.Int__commons:
|
||||
case Xow_domain_type_.Int__species:
|
||||
case Xow_domain_type_.Int__meta:
|
||||
case Xow_domain_type_.Int__incubator:
|
||||
case Xow_domain_type_.Int__wikidata:
|
||||
case Xow_domain_type_.Int__mediawiki:
|
||||
case Xow_domain_type_.Int__wmfblog: return suffix;
|
||||
case Xow_domain_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikinews:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikimedia: return Bry_.Add(domain_itm.Lang_orig_key(), suffix);
|
||||
case Xow_domain_tid_.Int__commons:
|
||||
case Xow_domain_tid_.Int__species:
|
||||
case Xow_domain_tid_.Int__meta:
|
||||
case Xow_domain_tid_.Int__incubator:
|
||||
case Xow_domain_tid_.Int__wikidata:
|
||||
case Xow_domain_tid_.Int__mediawiki:
|
||||
case Xow_domain_tid_.Int__wmfblog: return suffix;
|
||||
case Xow_domain_tid_.Int__wikipedia:
|
||||
case Xow_domain_tid_.Int__wiktionary:
|
||||
case Xow_domain_tid_.Int__wikisource:
|
||||
case Xow_domain_tid_.Int__wikibooks:
|
||||
case Xow_domain_tid_.Int__wikiversity:
|
||||
case Xow_domain_tid_.Int__wikiquote:
|
||||
case Xow_domain_tid_.Int__wikinews:
|
||||
case Xow_domain_tid_.Int__wikivoyage:
|
||||
case Xow_domain_tid_.Int__wikimedia: return Bry_.Add(domain_itm.Lang_orig_key(), suffix);
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
@@ -121,22 +121,22 @@ public class Xow_abrv_wm_ {
|
||||
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_type_.Int__wikipedia);
|
||||
Init_trie_itm(rv, int_hash, "wiktionary" , Xow_domain_type_.Int__wiktionary);
|
||||
Init_trie_itm(rv, int_hash, "wikisource" , Xow_domain_type_.Int__wikisource);
|
||||
Init_trie_itm(rv, int_hash, "wikibooks" , Xow_domain_type_.Int__wikibooks);
|
||||
Init_trie_itm(rv, int_hash, "wikiversity" , Xow_domain_type_.Int__wikiversity);
|
||||
Init_trie_itm(rv, int_hash, "wikiquote" , Xow_domain_type_.Int__wikiquote);
|
||||
Init_trie_itm(rv, int_hash, "wikinews" , Xow_domain_type_.Int__wikinews);
|
||||
Init_trie_itm(rv, int_hash, "wikivoyage" , Xow_domain_type_.Int__wikivoyage);
|
||||
Init_trie_itm(rv, int_hash, "wikimedia" , Xow_domain_type_.Int__wikimedia);
|
||||
Init_trie_itm(rv, int_hash, "commonswiki" , Xow_domain_type_.Int__commons);
|
||||
Init_trie_itm(rv, int_hash, "specieswiki" , Xow_domain_type_.Int__species);
|
||||
Init_trie_itm(rv, int_hash, "metawiki" , Xow_domain_type_.Int__meta);
|
||||
Init_trie_itm(rv, int_hash, "incubatorwiki" , Xow_domain_type_.Int__incubator);
|
||||
Init_trie_itm(rv, int_hash, "wikidatawiki" , Xow_domain_type_.Int__wikidata);
|
||||
Init_trie_itm(rv, int_hash, "mediawikiwiki" , Xow_domain_type_.Int__mediawiki);
|
||||
Init_trie_itm(rv, int_hash, "foundationwiki" , Xow_domain_type_.Int__wmfblog);
|
||||
Init_trie_itm(rv, int_hash, "wiki" , Xow_domain_tid_.Int__wikipedia);
|
||||
Init_trie_itm(rv, int_hash, "wiktionary" , Xow_domain_tid_.Int__wiktionary);
|
||||
Init_trie_itm(rv, int_hash, "wikisource" , Xow_domain_tid_.Int__wikisource);
|
||||
Init_trie_itm(rv, int_hash, "wikibooks" , Xow_domain_tid_.Int__wikibooks);
|
||||
Init_trie_itm(rv, int_hash, "wikiversity" , Xow_domain_tid_.Int__wikiversity);
|
||||
Init_trie_itm(rv, int_hash, "wikiquote" , Xow_domain_tid_.Int__wikiquote);
|
||||
Init_trie_itm(rv, int_hash, "wikinews" , Xow_domain_tid_.Int__wikinews);
|
||||
Init_trie_itm(rv, int_hash, "wikivoyage" , Xow_domain_tid_.Int__wikivoyage);
|
||||
Init_trie_itm(rv, int_hash, "wikimedia" , Xow_domain_tid_.Int__wikimedia);
|
||||
Init_trie_itm(rv, int_hash, "commonswiki" , Xow_domain_tid_.Int__commons);
|
||||
Init_trie_itm(rv, int_hash, "specieswiki" , Xow_domain_tid_.Int__species);
|
||||
Init_trie_itm(rv, int_hash, "metawiki" , Xow_domain_tid_.Int__meta);
|
||||
Init_trie_itm(rv, int_hash, "incubatorwiki" , Xow_domain_tid_.Int__incubator);
|
||||
Init_trie_itm(rv, int_hash, "wikidatawiki" , Xow_domain_tid_.Int__wikidata);
|
||||
Init_trie_itm(rv, int_hash, "mediawikiwiki" , Xow_domain_tid_.Int__mediawiki);
|
||||
Init_trie_itm(rv, int_hash, "foundationwiki" , Xow_domain_tid_.Int__wmfblog);
|
||||
return rv;
|
||||
}
|
||||
private static void Init_trie_itm(Btrie_bwd_mgr trie, Hash_adp hash, String str, int tid) {
|
||||
@@ -159,18 +159,18 @@ class Xow_abrv_wm_override {
|
||||
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_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: ar means Argentina not Arabic
|
||||
itm_hash__add(rv, lang_hash, "br.wikimedia.org", "brwikimedia", "br", Xol_lang_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: br means Brazil not Breto
|
||||
itm_hash__add(rv, lang_hash, "co.wikimedia.org", "cowikimedia", "co", Xol_lang_itm_.Id_es, Xow_domain_type_.Int__wikimedia); // NOTE: co means Columbia not Corsican
|
||||
itm_hash__add(rv, lang_hash, "ua.wikimedia.org", "ukwikimedia", "ua", Xol_lang_itm_.Id_uk, Xow_domain_type_.Int__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_itm_.Id_en, Xow_domain_type_.Int__wikimedia); // NOTE: ca means Canada not Catalan
|
||||
itm_hash__add(rv, lang_hash, "be.wikimedia.org", "bewikimedia", "be", Xol_lang_itm_.Id_en, Xow_domain_type_.Int__wikimedia); // NOTE: be means Belgium not Belarusian
|
||||
itm_hash__add(rv, lang_hash, "se.wikimedia.org", "sewikimedia", "se", Xol_lang_itm_.Id_sv, Xow_domain_type_.Int__wikimedia); // NOTE: se means Swedish not Northern Sami
|
||||
itm_hash__add(rv, lang_hash, "ar.wikimedia.org", "arwikimedia", "ar", Xol_lang_stub_.Id_es, Xow_domain_tid_.Int__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_.Int__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_.Int__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_.Int__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_.Int__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_.Int__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_.Int__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_itm lang_actl_itm = Xol_lang_itm_.Get_by_id(lang_actl);
|
||||
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());
|
||||
|
||||
@@ -20,28 +20,28 @@ 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_itm_.Id__intl , Xow_domain_type_.Int__wmfblog);
|
||||
fxt.Test_parse("wikidatawiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__wikidata);
|
||||
fxt.Test_parse("mediawikiwiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__mediawiki);
|
||||
fxt.Test_parse("commonswiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__commons);
|
||||
fxt.Test_parse("specieswiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__species);
|
||||
fxt.Test_parse("metawiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__meta);
|
||||
fxt.Test_parse("incubatorwiki" , Xol_lang_itm_.Id__intl , Xow_domain_type_.Int__incubator);
|
||||
fxt.Test_parse("enwiki" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikipedia);
|
||||
fxt.Test_parse("enwiktionary" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wiktionary);
|
||||
fxt.Test_parse("enwikisource" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikisource);
|
||||
fxt.Test_parse("enwikibooks" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikibooks);
|
||||
fxt.Test_parse("enwikiversity" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikiversity);
|
||||
fxt.Test_parse("enwikiquote" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikiquote);
|
||||
fxt.Test_parse("enwikinews" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikinews);
|
||||
fxt.Test_parse("enwikivoyage" , Xol_lang_itm_.Id_en , Xow_domain_type_.Int__wikivoyage);
|
||||
fxt.Test_parse("frwiki" , Xol_lang_itm_.Id_fr , Xow_domain_type_.Int__wikipedia);
|
||||
fxt.Test_parse("foundationwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__wmfblog);
|
||||
fxt.Test_parse("wikidatawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__wikidata);
|
||||
fxt.Test_parse("mediawikiwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__mediawiki);
|
||||
fxt.Test_parse("commonswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__commons);
|
||||
fxt.Test_parse("specieswiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__species);
|
||||
fxt.Test_parse("metawiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__meta);
|
||||
fxt.Test_parse("incubatorwiki" , Xol_lang_stub_.Id__intl , Xow_domain_tid_.Int__incubator);
|
||||
fxt.Test_parse("enwiki" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikipedia);
|
||||
fxt.Test_parse("enwiktionary" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wiktionary);
|
||||
fxt.Test_parse("enwikisource" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikisource);
|
||||
fxt.Test_parse("enwikibooks" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikibooks);
|
||||
fxt.Test_parse("enwikiversity" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikiversity);
|
||||
fxt.Test_parse("enwikiquote" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikiquote);
|
||||
fxt.Test_parse("enwikinews" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikinews);
|
||||
fxt.Test_parse("enwikivoyage" , Xol_lang_stub_.Id_en , Xow_domain_tid_.Int__wikivoyage);
|
||||
fxt.Test_parse("frwiki" , Xol_lang_stub_.Id_fr , Xow_domain_tid_.Int__wikipedia);
|
||||
fxt.Test_parse_null("unknown");
|
||||
fxt.Test_parse("plwikimedia" , Xol_lang_itm_.Id_pl , Xow_domain_type_.Int__wikimedia);
|
||||
fxt.Test_parse("plwikimedia" , Xol_lang_stub_.Id_pl , Xow_domain_tid_.Int__wikimedia);
|
||||
}
|
||||
@Test public void Parse_override() {
|
||||
fxt.Test_parse("arwikimedia" , Xol_lang_itm_.Id_es , Xow_domain_type_.Int__wikimedia);
|
||||
fxt.Test_parse("ukwikimedia" , Xol_lang_itm_.Id_uk , Xow_domain_type_.Int__wikimedia);
|
||||
fxt.Test_parse("arwikimedia" , Xol_lang_stub_.Id_es , Xow_domain_tid_.Int__wikimedia);
|
||||
fxt.Test_parse("ukwikimedia" , Xol_lang_stub_.Id_uk , Xow_domain_tid_.Int__wikimedia);
|
||||
}
|
||||
@Test public void To_domain_itm() {
|
||||
fxt.Test_to_domain_itm("enwiki" , "en" , "en.wikipedia.org");
|
||||
@@ -59,15 +59,15 @@ public class Xow_abrv_wm_tst {
|
||||
fxt.Test_to_abrv("commons.wikimedia.org" , "commonswiki");
|
||||
}
|
||||
@Test public void To_abrv_by_lang() {
|
||||
fxt.Test_to_abrv_by_lang("en", Xow_domain_type_.Int__wikipedia, "enwiki");
|
||||
fxt.Test_to_abrv_by_lang("en", Xow_domain_tid_.Int__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_itm actl_lang_itm = abrv.Lang_actl();
|
||||
Tfds.Eq(expd_lang_id , actl_lang_itm == null ? Xol_lang_itm_.Id__unknown : actl_lang_itm.Id());
|
||||
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) {
|
||||
@@ -83,7 +83,7 @@ class Xow_abrv_wm_fxt {
|
||||
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.Xto_str_and_clear(), "to_abrv");
|
||||
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))));
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xow_abrv_xo_ {
|
||||
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_type type) { // en.wikipedia.org -> en.w
|
||||
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);
|
||||
@@ -34,18 +34,18 @@ public class Xow_abrv_xo_ {
|
||||
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_type type = null;
|
||||
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_type_.Get_abrv_as_itm(src, dot_pos + 1, src_len);
|
||||
type = Xow_domain_tid_.Get_abrv_as_itm(src, dot_pos + 1, src_len);
|
||||
if (type != null) { // type found; EX: ".w"
|
||||
Xol_lang_itm lang = Xol_lang_itm_.Get_by_key(src, 0, dot_pos);
|
||||
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_type_.Get_abrv_as_itm(src, 0, src_len);
|
||||
type = Xow_domain_tid_.Get_abrv_as_itm(src, 0, src_len);
|
||||
if (type != null) { // type found; EX: "c"
|
||||
domain_bry = type.Domain_bry();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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_type domain_type, Xol_lang_itm lang_actl_itm, byte[] lang_orig_key) {
|
||||
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);
|
||||
@@ -26,23 +26,23 @@ public class Xow_domain_itm {
|
||||
}
|
||||
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_type Domain_type() {return domain_type;} private final Xow_domain_type domain_type;
|
||||
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 Xol_lang_itm Lang_actl_itm() {return lang_actl_itm;} private final Xol_lang_itm lang_actl_itm; // EX: zh
|
||||
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_itm lang_actl_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_actl_itm, lang_actl_itm.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_itm lang_actl, byte[] lang_orig) {
|
||||
return new Xow_domain_itm(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_actl, lang_orig);
|
||||
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_type_.Get_type_as_itm(domain_tid), Xol_lang_itm_.Get_by_key_or_intl(lang_actl_key), 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,50 +29,50 @@ public class Xow_domain_itm_ {
|
||||
int raw_len = raw.length;
|
||||
int dot_0 = Bry_find_.Find_fwd(raw, Byte_ascii.Dot, 0, raw_len);
|
||||
if (dot_0 == Bry_.NotFound) { // 0 dots; check for "home"
|
||||
return Bry_.Eq(raw, Xow_domain_type_.Bry__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_.NotFound) { // 1 dot; check for "wikimediafoundation.org"
|
||||
return Bry_.Match(raw, 0, dot_0, Xow_domain_type_.Bry__wmforg)
|
||||
? Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wmfblog, Xol_lang_itm_.Key__unknown)
|
||||
return Bry_.Match(raw, 0, dot_0, Xow_domain_tid_.Bry__wmforg)
|
||||
? Xow_domain_itm.new_(raw, Xow_domain_tid_.Int__wmfblog, Xol_lang_stub_.Key__unknown)
|
||||
: new_other(raw);
|
||||
}
|
||||
// 2 dots
|
||||
int seg_1_tid = Xow_domain_type_.Get_type_as_tid(raw, dot_0 + 1, dot_1); // parse middle; EX: ".wikipedia."
|
||||
if (seg_1_tid == Xow_domain_type_.Int__null) return new_other(raw); // seg_1 is unknown; return other;
|
||||
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_.Int__null) return new_other(raw); // seg_1 is unknown; return other;
|
||||
switch (seg_1_tid) {
|
||||
case Xow_domain_type_.Int__wikipedia: case Xow_domain_type_.Int__wiktionary: case Xow_domain_type_.Int__wikisource: case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity: case Xow_domain_type_.Int__wikiquote: case Xow_domain_type_.Int__wikinews: case Xow_domain_type_.Int__wikivoyage: // ~{lang}.~{type}.org
|
||||
case Xow_domain_tid_.Int__wikipedia: case Xow_domain_tid_.Int__wiktionary: case Xow_domain_tid_.Int__wikisource: case Xow_domain_tid_.Int__wikibooks:
|
||||
case Xow_domain_tid_.Int__wikiversity: case Xow_domain_tid_.Int__wikiquote: case Xow_domain_tid_.Int__wikinews: case Xow_domain_tid_.Int__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_type_.Int__wikidata: case Xow_domain_type_.Int__mediawiki:// ~www.~{type}.org
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, Xol_lang_itm_.Key__unknown);
|
||||
case Xow_domain_type_.Int__wikimedia: // ~{type}.wikimedia.org;
|
||||
int seg_0_tid = Xow_domain_type_.Get_type_as_tid(raw, 0, dot_0); // try to get "incubator", "meta", etc..
|
||||
if (seg_0_tid == Xow_domain_type_.Int__null) { // not a known name; try language
|
||||
case Xow_domain_tid_.Int__wikidata: case Xow_domain_tid_.Int__mediawiki:// ~www.~{type}.org
|
||||
return Xow_domain_itm.new_(raw, seg_1_tid, Xol_lang_stub_.Key__unknown);
|
||||
case Xow_domain_tid_.Int__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_.Int__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_itm wikimedia_lang = Xol_lang_itm_.Get_by_key_or_null(raw, 0, dot_0);
|
||||
return wikimedia_lang == null ? new_other(raw) : Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wikimedia, wikimedia_lang.Key());
|
||||
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_.Int__wikimedia, wikimedia_lang.Key());
|
||||
}
|
||||
else
|
||||
return Xow_domain_itm.new_(raw, Xow_domain_type_.Int__wikimedia, lang_override, Bry_.Mid(raw, 0, dot_0));
|
||||
return Xow_domain_itm.new_(raw, Xow_domain_tid_.Int__wikimedia, lang_override, Bry_.Mid(raw, 0, dot_0));
|
||||
}
|
||||
switch (seg_0_tid) {
|
||||
case Xow_domain_type_.Int__commons: case Xow_domain_type_.Int__species: case Xow_domain_type_.Int__meta: case Xow_domain_type_.Int__incubator:
|
||||
return Xow_domain_itm.new_(raw, seg_0_tid, Xol_lang_itm_.Key__unknown); // NOTE: seg_tids must match wiki_tids; NOTE: lang_key is "en" (really, "multi" but making things easier)
|
||||
case Xow_domain_tid_.Int__commons: case Xow_domain_tid_.Int__species: case Xow_domain_tid_.Int__meta: case Xow_domain_tid_.Int__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_type_.Int__other:
|
||||
case Xow_domain_tid_.Int__other:
|
||||
default:
|
||||
return new_other(raw);
|
||||
}
|
||||
}
|
||||
private static Xow_domain_itm new_other(byte[] raw) {return Xow_domain_itm.new_(raw, Xow_domain_type_.Int__other, Xol_lang_itm_.Key__unknown);}
|
||||
private static Xow_domain_itm new_other(byte[] raw) {return Xow_domain_itm.new_(raw, Xow_domain_tid_.Int__other, Xol_lang_stub_.Key__unknown);}
|
||||
private static byte[] Get_lang_code_for_mw_messages_file(byte[] v) {
|
||||
Object o = lang_to_gfs_hash.Get_by_bry(v);
|
||||
return o == null ? v : (byte[])o;
|
||||
@@ -103,6 +103,7 @@ public class Xow_domain_itm_ {
|
||||
, 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");
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.
|
||||
import org.junit.*;
|
||||
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_type_.Int__wikipedia);}
|
||||
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , "fr" , Xow_domain_type_.Int__wikipedia);}
|
||||
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , "en" , Xow_domain_type_.Int__wiktionary);}
|
||||
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "zh-classical" , "lzh" , Xow_domain_type_.Int__wikipedia);}
|
||||
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , "" , Xow_domain_type_.Int__commons);}
|
||||
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , "" , Xow_domain_type_.Int__species);}
|
||||
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , "ru" , Xow_domain_type_.Int__wikimedia);}
|
||||
@Test public void Parse_home() {fxt.Test_parse("home" , "" , "" , Xow_domain_type_.Int__home);}
|
||||
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , "" , Xow_domain_type_.Int__other);}
|
||||
@Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_type_.Int__wikimedia);}
|
||||
@Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_type_.Int__wikimedia);}
|
||||
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , "en" , Xow_domain_tid_.Int__wikipedia);}
|
||||
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , "fr" , Xow_domain_tid_.Int__wikipedia);}
|
||||
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , "en" , Xow_domain_tid_.Int__wiktionary);}
|
||||
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "zh-classical" , "lzh" , Xow_domain_tid_.Int__wikipedia);}
|
||||
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , "" , Xow_domain_tid_.Int__commons);}
|
||||
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , "" , Xow_domain_tid_.Int__species);}
|
||||
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , "ru" , Xow_domain_tid_.Int__wikimedia);}
|
||||
@Test public void Parse_home() {fxt.Test_parse("home" , "" , "" , Xow_domain_tid_.Int__home);}
|
||||
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , "" , Xow_domain_tid_.Int__other);}
|
||||
@Test public void Parse_ua_wikimedia_org() {fxt.Test_parse("ua.wikimedia.org" , "ua" , "uk" , Xow_domain_tid_.Int__wikimedia);}
|
||||
@Test public void Parse_ar_wikimedia_org() {fxt.Test_parse("ar.wikimedia.org" , "ar" , "es" , Xow_domain_tid_.Int__wikimedia);}
|
||||
}
|
||||
class Xow_domain_fxt {
|
||||
public void Test_parse(String domain, String expd_orig_lang, String expd_actl_lang, int expd_tid) {
|
||||
|
||||
@@ -16,8 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_type {
|
||||
public Xow_domain_type(boolean multi_lang, int src, int tid, byte[] key_bry, byte[] abrv, byte[] domain_bry) {
|
||||
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);
|
||||
}
|
||||
@@ -28,6 +28,7 @@ public class Xow_domain_type {
|
||||
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
|
||||
}
|
||||
class Xow_domain_type_src_ {
|
||||
public static final int
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_domain_type_ {
|
||||
public class Xow_domain_tid_ {
|
||||
public static final int
|
||||
Int__null = 0
|
||||
, Int__wikipedia = 1
|
||||
@@ -79,10 +79,10 @@ public class Xow_domain_type_ {
|
||||
, Bry__home = Bry_.new_a7(Str__home)
|
||||
, Bry__other = Bry_.new_a7(Str__other)
|
||||
;
|
||||
private static final Xow_domain_type[] ary = new Xow_domain_type[Int___len];
|
||||
private static final Xow_domain_tid[] ary = new Xow_domain_tid[Int___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_type
|
||||
public static final Xow_domain_tid
|
||||
Itm__wikipedia = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikipedia , Bry__wikipedia , "w" , ".wikipedia.org")
|
||||
, Itm__wiktionary = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wiktionary , Bry__wiktionary , "d" , ".wiktionary.org")
|
||||
, Itm__wikisource = new_(Bool_.Y , Xow_domain_type_src_.Int__wmf , Int__wikisource , Bry__wikisource , "s" , ".wikisource.org")
|
||||
@@ -102,20 +102,20 @@ public class Xow_domain_type_ {
|
||||
, Itm__home = new_(Bool_.N , Xow_domain_type_src_.Int__xowa, Int__home , Bry__home , "home" , Xow_domain_itm_.Str__home)
|
||||
, Itm__other = new_(Bool_.N , Xow_domain_type_src_.Int__mw , Int__other , Bry__other , "" , "")
|
||||
;
|
||||
private static Xow_domain_type new_(boolean multi_lang, int src, int tid, byte[] key_bry, String abrv_xo_str, String domain_bry) {
|
||||
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_type rv = new Xow_domain_type(multi_lang, src, tid, key_bry, abrv_xo_bry, Bry_.new_u8(domain_bry));
|
||||
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_type Get_abrv_as_itm(byte[] src, int bgn, int end) {return (Xow_domain_type)abrv_regy.Get_by_mid(src, bgn, end);}
|
||||
public static Xow_domain_type Get_type_as_itm(int tid) {return ary[tid];}
|
||||
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_type_.Int__null : ((Xow_domain_type)o).Tid();
|
||||
return o == null ? Xow_domain_tid_.Int__null : ((Xow_domain_tid)o).Tid();
|
||||
}
|
||||
}
|
||||
@@ -44,23 +44,23 @@ public class Xow_domain_uid_ {
|
||||
public static int To_int(Xow_domain_itm domain) {
|
||||
int domain_tid = 0;
|
||||
switch (domain.Domain_type_id()) {
|
||||
case Xow_domain_type_.Int__home: return Tid_xowa;
|
||||
case Xow_domain_type_.Int__commons: return Tid_commons;
|
||||
case Xow_domain_type_.Int__wikidata: return Tid_wikidata;
|
||||
case Xow_domain_type_.Int__mediawiki: return Tid_mediawiki;
|
||||
case Xow_domain_type_.Int__meta: return Tid_meta;
|
||||
case Xow_domain_type_.Int__incubator: return Tid_incubator;
|
||||
case Xow_domain_type_.Int__wmfblog: return Tid_wmfblog;
|
||||
case Xow_domain_type_.Int__species: return Tid_species;
|
||||
case Xow_domain_type_.Int__wikipedia: domain_tid = Tid_sub_wikipedia; break;
|
||||
case Xow_domain_type_.Int__wiktionary: domain_tid = Tid_sub_wiktionary; break;
|
||||
case Xow_domain_type_.Int__wikisource: domain_tid = Tid_sub_wikisource; break;
|
||||
case Xow_domain_type_.Int__wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
|
||||
case Xow_domain_type_.Int__wikiquote: domain_tid = Tid_sub_wikiquote; break;
|
||||
case Xow_domain_type_.Int__wikibooks: domain_tid = Tid_sub_wikibooks; break;
|
||||
case Xow_domain_type_.Int__wikiversity: domain_tid = Tid_sub_wikiversity; break;
|
||||
case Xow_domain_type_.Int__wikinews: domain_tid = Tid_sub_wikinews; break;
|
||||
case Xow_domain_type_.Int__wikimedia: domain_tid = Tid_sub_wikimedia; break;
|
||||
case Xow_domain_tid_.Int__home: return Tid_xowa;
|
||||
case Xow_domain_tid_.Int__commons: return Tid_commons;
|
||||
case Xow_domain_tid_.Int__wikidata: return Tid_wikidata;
|
||||
case Xow_domain_tid_.Int__mediawiki: return Tid_mediawiki;
|
||||
case Xow_domain_tid_.Int__meta: return Tid_meta;
|
||||
case Xow_domain_tid_.Int__incubator: return Tid_incubator;
|
||||
case Xow_domain_tid_.Int__wmfblog: return Tid_wmfblog;
|
||||
case Xow_domain_tid_.Int__species: return Tid_species;
|
||||
case Xow_domain_tid_.Int__wikipedia: domain_tid = Tid_sub_wikipedia; break;
|
||||
case Xow_domain_tid_.Int__wiktionary: domain_tid = Tid_sub_wiktionary; break;
|
||||
case Xow_domain_tid_.Int__wikisource: domain_tid = Tid_sub_wikisource; break;
|
||||
case Xow_domain_tid_.Int__wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
|
||||
case Xow_domain_tid_.Int__wikiquote: domain_tid = Tid_sub_wikiquote; break;
|
||||
case Xow_domain_tid_.Int__wikibooks: domain_tid = Tid_sub_wikibooks; break;
|
||||
case Xow_domain_tid_.Int__wikiversity: domain_tid = Tid_sub_wikiversity; break;
|
||||
case Xow_domain_tid_.Int__wikinews: domain_tid = Tid_sub_wikinews; break;
|
||||
case Xow_domain_tid_.Int__wikimedia: domain_tid = Tid_sub_wikimedia; break;
|
||||
default: throw Err_.new_unhandled(domain.Domain_type_id());
|
||||
}
|
||||
return Const_system_reserved // reserve first 100 slots
|
||||
@@ -70,35 +70,35 @@ public class Xow_domain_uid_ {
|
||||
}
|
||||
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_type_.Int__home, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_commons: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__commons, Xow_domain_type_.Int__commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wikidata: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wikidata, Xow_domain_type_.Int__commons, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_mediawiki: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__mediawiki, Xow_domain_type_.Int__mediawiki, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_meta: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__meta, Xow_domain_type_.Int__meta, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_incubator: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__incubator, Xow_domain_type_.Int__incubator, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_wmfblog: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wmforg, Xow_domain_type_.Int__wmfblog, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_species: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__species, Xow_domain_type_.Int__species, Xol_lang_itm_.Key__unknown);
|
||||
case Tid_xowa: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__home, Xow_domain_tid_.Int__home, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_commons: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__commons, Xow_domain_tid_.Int__commons, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_wikidata: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wikidata, Xow_domain_tid_.Int__commons, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_mediawiki: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__mediawiki, Xow_domain_tid_.Int__mediawiki, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_meta: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__meta, Xow_domain_tid_.Int__meta, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_incubator: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__incubator, Xow_domain_tid_.Int__incubator, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_wmfblog: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__wmforg, Xow_domain_tid_.Int__wmfblog, Xol_lang_stub_.Key__unknown);
|
||||
case Tid_species: return Xow_domain_itm.new_(Xow_domain_itm_.Bry__species, Xow_domain_tid_.Int__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_type_.Int__wikipedia; tid_bry = Xow_domain_type_.Bry__wikipedia; break;
|
||||
case Tid_sub_wiktionary: tid_int = Xow_domain_type_.Int__wiktionary; tid_bry = Xow_domain_type_.Bry__wiktionary; break;
|
||||
case Tid_sub_wikisource: tid_int = Xow_domain_type_.Int__wikisource; tid_bry = Xow_domain_type_.Bry__wikisource; break;
|
||||
case Tid_sub_wikivoyage: tid_int = Xow_domain_type_.Int__wikivoyage; tid_bry = Xow_domain_type_.Bry__wikivoyage; break;
|
||||
case Tid_sub_wikiquote: tid_int = Xow_domain_type_.Int__wikiquote; tid_bry = Xow_domain_type_.Bry__wikiquote; break;
|
||||
case Tid_sub_wikibooks: tid_int = Xow_domain_type_.Int__wikibooks; tid_bry = Xow_domain_type_.Bry__wikibooks; break;
|
||||
case Tid_sub_wikiversity: tid_int = Xow_domain_type_.Int__wikiversity; tid_bry = Xow_domain_type_.Bry__wikiversity; break;
|
||||
case Tid_sub_wikinews: tid_int = Xow_domain_type_.Int__wikinews; tid_bry = Xow_domain_type_.Bry__wikinews; break;
|
||||
case Tid_sub_wikimedia: tid_int = Xow_domain_type_.Int__wikimedia; tid_bry = Xow_domain_type_.Bry__wikimedia; break;
|
||||
case Tid_sub_wikipedia: tid_int = Xow_domain_tid_.Int__wikipedia; tid_bry = Xow_domain_tid_.Bry__wikipedia; break;
|
||||
case Tid_sub_wiktionary: tid_int = Xow_domain_tid_.Int__wiktionary; tid_bry = Xow_domain_tid_.Bry__wiktionary; break;
|
||||
case Tid_sub_wikisource: tid_int = Xow_domain_tid_.Int__wikisource; tid_bry = Xow_domain_tid_.Bry__wikisource; break;
|
||||
case Tid_sub_wikivoyage: tid_int = Xow_domain_tid_.Int__wikivoyage; tid_bry = Xow_domain_tid_.Bry__wikivoyage; break;
|
||||
case Tid_sub_wikiquote: tid_int = Xow_domain_tid_.Int__wikiquote; tid_bry = Xow_domain_tid_.Bry__wikiquote; break;
|
||||
case Tid_sub_wikibooks: tid_int = Xow_domain_tid_.Int__wikibooks; tid_bry = Xow_domain_tid_.Bry__wikibooks; break;
|
||||
case Tid_sub_wikiversity: tid_int = Xow_domain_tid_.Int__wikiversity; tid_bry = Xow_domain_tid_.Bry__wikiversity; break;
|
||||
case Tid_sub_wikinews: tid_int = Xow_domain_tid_.Int__wikinews; tid_bry = Xow_domain_tid_.Bry__wikinews; break;
|
||||
case Tid_sub_wikimedia: tid_int = Xow_domain_tid_.Int__wikimedia; tid_bry = Xow_domain_tid_.Bry__wikimedia; break;
|
||||
default: throw Err_.new_unhandled(type_id);
|
||||
}
|
||||
Xol_lang_itm lang = Xol_lang_itm_.Get_by_id(lang_id);
|
||||
Xol_lang_stub lang = Xol_lang_stub_.Get_by_id(lang_id);
|
||||
Bry_bfr bfr = Xoa_app_.Utl__bfr_mkr().Get_b128();
|
||||
bfr.Add(lang.Key()).Add_byte_dot().Add(tid_bry).Add_byte_dot().Add(Xow_domain_itm_.Seg__org);
|
||||
byte[] domain_bry = bfr.Xto_bry_and_clear();
|
||||
byte[] domain_bry = bfr.To_bry_and_clear();
|
||||
bfr.Mkr_rls();
|
||||
return Xow_domain_itm.new_(domain_bry, tid_int, lang, lang.Key());
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ 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_type_.Int__commons);
|
||||
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_type_.Int__wikipedia);
|
||||
fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_tid_.Int__commons);
|
||||
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_tid_.Int__wikipedia);
|
||||
}
|
||||
}
|
||||
class Xow_domain_uid__fxt {
|
||||
|
||||
@@ -21,7 +21,7 @@ class Xow_domain_crt_itm_ {
|
||||
}
|
||||
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 I = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
|
||||
public static final Xow_domain_crt_itm__any_wiki Instance = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
|
||||
private final Xow_domain_crt_itm[] ary;
|
||||
@@ -38,34 +38,34 @@ class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
|
||||
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_type_.Int__wikipedia:
|
||||
case Xow_domain_type_.Int__wiktionary:
|
||||
case Xow_domain_type_.Int__wikisource:
|
||||
case Xow_domain_type_.Int__wikivoyage:
|
||||
case Xow_domain_type_.Int__wikiquote:
|
||||
case Xow_domain_type_.Int__wikibooks:
|
||||
case Xow_domain_type_.Int__wikiversity:
|
||||
case Xow_domain_type_.Int__wikinews: return true;
|
||||
default: return false;
|
||||
case Xow_domain_tid_.Int__wikipedia:
|
||||
case Xow_domain_tid_.Int__wiktionary:
|
||||
case Xow_domain_tid_.Int__wikisource:
|
||||
case Xow_domain_tid_.Int__wikivoyage:
|
||||
case Xow_domain_tid_.Int__wikiquote:
|
||||
case Xow_domain_tid_.Int__wikibooks:
|
||||
case Xow_domain_tid_.Int__wikiversity:
|
||||
case Xow_domain_tid_.Int__wikinews: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
public static final Xow_domain_crt_itm__any_standard I = new Xow_domain_crt_itm__any_standard(); Xow_domain_crt_itm__any_standard() {}
|
||||
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__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 I = new Xow_domain_crt_itm__none(); Xow_domain_crt_itm__none() {}
|
||||
public static final Xow_domain_crt_itm__none Instance = new Xow_domain_crt_itm__none(); Xow_domain_crt_itm__none() {}
|
||||
}
|
||||
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 I = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
|
||||
public static final Xow_domain_crt_itm__self Instance = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_lang implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_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 I = new Xow_domain_crt_itm__same_lang(); Xow_domain_crt_itm__same_lang() {}
|
||||
public static final Xow_domain_crt_itm__same_lang Instance = new Xow_domain_crt_itm__same_lang(); Xow_domain_crt_itm__same_lang() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__same_type implements Xow_domain_crt_itm {
|
||||
public boolean Matches(Xow_domain_itm cur, Xow_domain_itm comp) {return cur.Domain_type_id() == comp.Domain_type_id();}
|
||||
public static final Xow_domain_crt_itm__same_type I = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
|
||||
public static final Xow_domain_crt_itm__same_type Instance = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
|
||||
}
|
||||
class Xow_domain_crt_itm__lang implements Xow_domain_crt_itm {
|
||||
private final byte[] lang_key;
|
||||
|
||||
@@ -36,15 +36,15 @@ class Xow_domain_crt_itm_parser {
|
||||
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.I.Parse_as_in(word_ary[0]);
|
||||
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.I.Parse_as_ary(word_ary[1]);
|
||||
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.I.Parse_as_in(word_ary[1]);
|
||||
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));
|
||||
}
|
||||
@@ -70,22 +70,22 @@ class Xow_domain_crt_itm_parser {
|
||||
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_type_.Get_type_as_tid(raw, Wild_lang.length, raw_len);
|
||||
return wiki_tid == Xow_domain_type_.Int__null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__type(wiki_tid);
|
||||
int wiki_tid = Xow_domain_tid_.Get_type_as_tid(raw, Wild_lang.length, raw_len);
|
||||
return wiki_tid == Xow_domain_tid_.Int__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_itm lang_itm = Xol_lang_itm_.Get_by_key(raw, 0, raw_len - Wild_type.length);
|
||||
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.I)
|
||||
.Add_str_obj("<same_type>" , Xow_domain_crt_itm__same_type.I)
|
||||
.Add_str_obj("<same_lang>" , Xow_domain_crt_itm__same_lang.I)
|
||||
.Add_str_obj("<any>" , Xow_domain_crt_itm__any_wiki.I)
|
||||
.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 I = new Xow_domain_crt_itm_parser(); Xow_domain_crt_itm_parser() {}
|
||||
public static final Xow_domain_crt_itm_parser Instance = new Xow_domain_crt_itm_parser(); Xow_domain_crt_itm_parser() {}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Xow_domain_crt_kv_itm_mgr {
|
||||
@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.I.Parse_as_kv_itms_or_null(raw);
|
||||
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)
|
||||
@@ -31,7 +31,7 @@ public class Xow_domain_crt_kv_itm_mgr {
|
||||
}
|
||||
public boolean Parse_as_arys(byte[] raw) {
|
||||
this.Clear();
|
||||
Xow_domain_crt_kv_ary[] ary = Xow_domain_crt_itm_parser.I.Parse_as_kv_arys_or_null(raw);
|
||||
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)
|
||||
@@ -44,7 +44,7 @@ public class Xow_domain_crt_kv_itm_mgr {
|
||||
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.I;
|
||||
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();
|
||||
|
||||
@@ -20,7 +20,7 @@ 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._.Exec_bry(cmd, wiki);
|
||||
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) {
|
||||
|
||||
@@ -30,9 +30,9 @@ public class Xow_script_mgr implements GfoInvkAble {
|
||||
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_type_.Get_type_as_bry(wiki_tid), wiki.Lang().Key_bry());
|
||||
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.Xto_str_and_clear(), Op_sys.Wnt.Nl_str(), Op_sys.Lnx.Nl_str());
|
||||
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();
|
||||
}
|
||||
@@ -41,12 +41,12 @@ public class Xow_script_mgr implements GfoInvkAble {
|
||||
int len = wiki_tid_names.length;
|
||||
int[] wiki_tids = new int[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
wiki_tids[i] = Xow_domain_type_.Get_type_as_tid(wiki_tid_names[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_();
|
||||
public Ordered_hash hash = Ordered_hash_.New_bry();
|
||||
}
|
||||
class Xow_script_itm {
|
||||
public Xow_script_itm(byte[] key, int[] wiki_tids, byte[] script) {
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.html.hrefs.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xow_wiki_props implements GfoInvkAble {
|
||||
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 Xow_wiki_props Main_page_(byte[] v) {main_page = v; return this;}
|
||||
@@ -42,7 +42,7 @@ public class Xow_wiki_props implements GfoInvkAble {
|
||||
public byte[] Siteinfo_misc() {return siteinfo_misc;}
|
||||
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 Xow_wiki_props SiteName_(int v) {site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_type_.Get_type_as_bry(v)))); return this;}
|
||||
public Xow_wiki_props SiteName_(int v) {site_name = Bry_.new_a7(String_.UpperFirst(String_.new_a7(Xow_domain_tid_.Get_type_as_bry(v)))); return this;}
|
||||
public Xow_wiki_props Siteinfo_misc_(byte[] v) {
|
||||
siteinfo_misc = v;
|
||||
int pipe_0 = Bry_find_.Find_fwd(v, Byte_ascii.Pipe);
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.metas; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.nss.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xow_wiki_stats implements GfoInvkAble {
|
||||
public Xow_wiki_stats(Xowe_wiki wiki) {this.wiki = wiki;} private Xowe_wiki wiki;
|
||||
public int NumPages() {return num_pages;} public Xow_wiki_stats NumPages_(int v) {num_pages = v; return this;} private int num_pages; // in entire wiki: 28,433,596
|
||||
|
||||
@@ -21,8 +21,8 @@ public class Xow_module_base implements GfoInvkAble {
|
||||
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.Xto_nullable_str(enabled);
|
||||
else if (ctx.Match(k, Invk_enabled_)) enabled = Yn.Xto_nullable_byte(m.ReadStr("v"));
|
||||
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 GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.html.heads.*; import gplx.xowa.html.modules.popups.*;
|
||||
import gplx.xowa.htmls.heads.*; import gplx.xowa.htmls.modules.popups.*;
|
||||
public class Xow_module_mgr implements GfoInvkAble {
|
||||
private Hash_adp_bry regy = Hash_adp_bry.cs();
|
||||
public Xow_module_mgr(Xowe_wiki wiki) {
|
||||
|
||||
105
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java
Normal file
105
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.cmds.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xow_ns implements GfoInvkAble {
|
||||
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_.Id_main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test"
|
||||
this.name_str = "";
|
||||
this.name_bry = Bry_.Empty;
|
||||
this.name_db_w_colon = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
this.name_bry = v;
|
||||
this.name_db_w_colon = Bry_.Add(v, Byte_ascii.Colon);
|
||||
this.name_str = String_.new_u8(v);
|
||||
}
|
||||
this.num_str = Int_.To_str_pad_bgn_zero(id, 3);
|
||||
this.num_bry = Bry_.new_a7(num_str);
|
||||
this.name_enc = Xoa_url_encoder.Instance.Encode(name_bry);
|
||||
this.name_txt = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
this.name_txt_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
}
|
||||
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
|
||||
public String Name_str() {return name_str;} private String name_str;
|
||||
public byte[] Name_txt() {return name_txt;} private byte[] name_txt;
|
||||
public byte[] Name_enc() {return name_enc;} private byte[] name_enc;
|
||||
public byte[] Name_db_w_colon() {return name_db_w_colon;} private byte[] name_db_w_colon;
|
||||
public byte[] Name_txt_w_colon() {return name_txt_w_colon;} private byte[] name_txt_w_colon; // PERF: for Xoa_ttl
|
||||
public byte[] Name_ui() {return id == Xow_ns_.Id_main ? Xow_ns_.Name_ui_main : name_txt;}
|
||||
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_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_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk
|
||||
public int Id_alt_id() {if (id < 0) return id; return Id_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk
|
||||
public boolean Id_subj() {return !Id_talk();} // REF.MW: Namespace.php|isMain
|
||||
public boolean Id_talk() {return id > Xow_ns_.Id_main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk
|
||||
public boolean Id_file() {return id == Xow_ns_.Id_file;}
|
||||
public boolean Id_file_or_media() {return id == Xow_ns_.Id_file || id == Xow_ns_.Id_media;}
|
||||
public boolean Id_tmpl() {return id == Xow_ns_.Id_template;}
|
||||
public boolean Id_ctg() {return id == Xow_ns_.Id_category;}
|
||||
public boolean Id_main() {return id == Xow_ns_.Id_main;}
|
||||
public boolean Id_media() {return id == Xow_ns_.Id_media;}
|
||||
public boolean Id_special() {return id == Xow_ns_.Id_special;}
|
||||
public boolean Id_module() {return id == gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_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_talk() ? ord - 1 : ord;} // id< 0: special/media returns self
|
||||
public int Ord_talk_id() {if (id < 0) return ord; return Id_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_.Id_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_.Id_user || id == Xow_ns_.Id_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_.Id_main;} // ASSUME: only Main
|
||||
public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?)
|
||||
public boolean Is_movable() {return id > Xow_ns_.Id_special;} // ASSUME: only Special, Media cannot move (be renamed?)
|
||||
public boolean Is_meta() {return id < Xow_ns_.Id_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_.Id_main ? page : Bry_.Add(name_db_w_colon, page);}
|
||||
public void Aliases_add(String alias) {
|
||||
if (String_.Eq(alias, name_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 boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
|
||||
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_txt;
|
||||
else if (ctx.Match(k, Invk_name_ui)) return Name_ui();
|
||||
else return GfoInvkAble_.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";
|
||||
}
|
||||
89
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java
Normal file
89
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_.java
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xow_ns_ {
|
||||
public static final int // PAGE:en.w:http://www.mediawiki.org/wiki/Help:Namespaces
|
||||
Id_media = -2
|
||||
, Id_special = -1
|
||||
, Id_main = 0 , Id_talk = 1
|
||||
, Id_user = 2 , Id_user_talk = 3
|
||||
, Id_project = 4 , Id_project_talk = 5
|
||||
, Id_file = 6 , Id_file_talk = 7
|
||||
, Id_mediawiki = 8 , Id_mediaWiki_talk = 9
|
||||
, Id_template = 10 , Id_template_talk = 11
|
||||
, Id_help = 12 , Id_help_talk = 13
|
||||
, Id_category = 14 , Id_category_talk = 15
|
||||
, Id_portal = 100 , Id_portal_talk = 101
|
||||
, Id_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"
|
||||
;
|
||||
public static final byte[] Bry_template = Bry_.new_a7(Key_template);
|
||||
public static final byte[] Name_ui_main = Bry_.new_a7(Key_main);
|
||||
public static int Canonical_id(byte[] canonical_name) {
|
||||
if (canonical_hash == null) {
|
||||
Xow_ns[] ary = Canonical;
|
||||
int len = ary.length;
|
||||
canonical_hash = Ordered_hash_.New_bry();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ary[i];
|
||||
canonical_hash.Add(ns.Name_bry(), Int_obj_val.new_(ns.Id()));
|
||||
}
|
||||
}
|
||||
Object rv_obj = canonical_hash.Get_by(canonical_name);
|
||||
return rv_obj == null ? Xow_ns_.Id_null : ((Int_obj_val)rv_obj).Val();
|
||||
} private static Ordered_hash canonical_hash;
|
||||
public static int Canonical_idx_media = 0;
|
||||
public static final Xow_ns[] Canonical = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames
|
||||
{ Canonical_new_(Id_media, Key_media)
|
||||
, Canonical_new_(Id_special, Key_special)
|
||||
, Canonical_new_(Id_talk, Key_talk)
|
||||
, Canonical_new_(Id_user, Key_user)
|
||||
, Canonical_new_(Id_user_talk, Key_user_talk)
|
||||
, Canonical_new_(Id_project, Key_project)
|
||||
, Canonical_new_(Id_project_talk, Key_project_talk)
|
||||
, Canonical_new_(Id_file, Key_file)
|
||||
, Canonical_new_(Id_file_talk, Key_file_talk)
|
||||
, Canonical_new_(Id_mediawiki, Key_mediaWiki)
|
||||
, Canonical_new_(Id_mediaWiki_talk, Key_mediaWiki_talk)
|
||||
, Canonical_new_(Id_template, Key_template)
|
||||
, Canonical_new_(Id_template_talk, Key_template_talk)
|
||||
, Canonical_new_(Id_help, Key_help)
|
||||
, Canonical_new_(Id_help_talk, Key_help_talk)
|
||||
, Canonical_new_(Id_category, Key_category)
|
||||
, Canonical_new_(Id_category_talk, Key_category_talk)
|
||||
};
|
||||
public static final String Ns_name_wikipedia = "Wikipedia";
|
||||
public static final byte[] Ns_name_main_bry = Bry_.new_a7(Key_main);
|
||||
public static final byte[] Ns_prefix_main = Bry_.new_a7("Main:");
|
||||
private static Xow_ns Canonical_new_(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Id_1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
|
||||
}
|
||||
35
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_case_.java
Normal file
35
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_case_.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xow_ns_case_ {
|
||||
public static final byte Id_all = 0, Id_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 parse(String s) {
|
||||
if (String_.Eq(s, Key_1st)) return Id_1st;
|
||||
else if (String_.Eq(s, Key_all)) return Id_all;
|
||||
else throw Err_.new_unhandled(s);
|
||||
}
|
||||
public static String To_str(byte uid) {
|
||||
switch (uid) {
|
||||
case Id_all: return Key_all;
|
||||
case Id_1st: return Key_1st;
|
||||
default: throw Err_.new_unhandled(uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
263
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java
Normal file
263
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr.java
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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 GfoInvkAble, gplx.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;
|
||||
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) {return (Xow_ns)id_hash.Get_by(ns_hash_lkp.Val_(id));} private Int_obj_ref ns_hash_lkp = Int_obj_ref.zero_();
|
||||
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_.NotFound) 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_.NotFound) return Bry_.NotFound;
|
||||
Object o = tmpl_hash.Get_by_mid(src, bgn, colon_pos + 1); // +1 to include colon_pos
|
||||
return o == null ? Bry_.NotFound : ((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, Int_obj_val.new_(ns_id));
|
||||
aliases.Add_if_dupe_use_nth(name, kv);
|
||||
return this;
|
||||
}
|
||||
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_.Id_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_bry());
|
||||
if (ns.Id_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_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_bry();
|
||||
if (Bry_find_.Find_fwd(ns.Name_bry(), Project_talk_fmt_arg)== Bry_.NotFound) 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_bry()));
|
||||
} 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_.NotFound) // 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_.Id_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_.Id_file_talk, "Image_talk");
|
||||
Aliases_add(Xow_ns_.Id_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(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_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_.Id_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_.Id_main: ns_main = ns; break;
|
||||
case Xow_ns_.Id_template: ns_template = ns; break;
|
||||
case Xow_ns_.Id_portal: ns_portal = ns; break;
|
||||
case Xow_ns_.Id_project: ns_project = ns; break;
|
||||
case Xow_ns_.Id_mediawiki: ns_mediawiki = ns; break;
|
||||
case Scrib_xtn_mgr.Ns_id_module: ns_module = ns; break;
|
||||
case Xow_ns_.Id_file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file
|
||||
case Xow_ns_.Id_category:
|
||||
ns_category = ns;
|
||||
if (category_trie == null)
|
||||
category_trie = Btrie_slim_mgr.new_(ns.Case_match() == Xow_ns_case_.Id_all);
|
||||
category_trie.Add_obj(ns.Name_bry(), this);
|
||||
break;
|
||||
}
|
||||
++ns_count;
|
||||
if (!id_hash.Has(ns_hash_lkp.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_bry(), new Xow_ns_mgr_name_itm(ns.Name_bry(), 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, Bry_.new_by_int(ns_id), Xow_ns_case_.Id_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_.Id_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_txt_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_load)) Xow_cfg_wiki_core.Load_ns_(this, m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_clear)) this.Clear();
|
||||
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: called by #cfg files for setting Subpages_enabled; if ns doesn't exist, returning empty is fine; DATE:2014-02-15
|
||||
else return GfoInvkAble_.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();
|
||||
}
|
||||
}
|
||||
51
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java
Normal file
51
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.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(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module).Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module_talk, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_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);
|
||||
ns.Name_bry_(ns_name.Name_bry());
|
||||
}
|
||||
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_str());
|
||||
}
|
||||
ns_mgr.Init();
|
||||
}
|
||||
}
|
||||
79
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java
Normal file
79
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_mgr_tst.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
public class Xow_ns_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xow_ns_mgr_fxt fxt = new Xow_ns_mgr_fxt();
|
||||
@Test public void Basic() {fxt.ini_ns_(-2, 0, 1).run_Ords_sort().tst_Ords(-2, -100, 0, 1);}
|
||||
@Test public void Talk_skip() {fxt.ini_ns_(-2, 0, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
|
||||
@Test public void Subj_skip() {fxt.ini_ns_(-2, 1, 2, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
|
||||
@Test public void Out_of_order() {fxt.ini_ns_(3, 1, 2, -2).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
|
||||
@Test public void Skip_odd() {fxt.ini_ns_(-2, 1, 3).run_Ords_sort().tst_Ords(-2, -100, 0, 1, 2, 3);}
|
||||
@Test public void Skip_even() {fxt.ini_ns_(-2, 2, 4).run_Ords_sort().tst_Ords(-2, -100, 2, 3, 4, 5);}
|
||||
@Test public void Ns_alias() {
|
||||
fxt.Ns_mgr().Aliases_clear();
|
||||
fxt.Ns_mgr().Add_new(Xow_ns_.Id_template, "Template");
|
||||
fxt.Ns_mgr().Aliases_add(Xow_ns_.Id_template, "Templatex");
|
||||
fxt.Ns_mgr().Init();
|
||||
byte[] name = Bry_.new_a7("Templatex:Abc");
|
||||
Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length));
|
||||
}
|
||||
@Test public void Utf8() {// PURPOSE: handle different casings for ns_names; PAGE:ru.w:Портрет_итальянского_Ренессанса DATE:2014-07-04
|
||||
Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.U8());
|
||||
ns_mgr.Add_new(1234, "Test");
|
||||
ns_mgr.Add_new(1235, "файл");
|
||||
fxt.Ns_mgr_(ns_mgr);
|
||||
fxt.Test_ns_name(1234, "Test", "test", "TEST", "tesT");
|
||||
fxt.Test_ns_name(1235, "файл", "Файл");
|
||||
}
|
||||
}
|
||||
class Xow_ns_mgr_fxt {
|
||||
private Xow_ns_mgr ns_mgr = new Xow_ns_mgr(Xol_case_mgr_.A7());
|
||||
public Xow_ns_mgr Ns_mgr() {return ns_mgr;}
|
||||
public void Ns_mgr_(Xow_ns_mgr v) {this.ns_mgr = v;}
|
||||
public void Clear() {ns_mgr.Clear();}
|
||||
public Xow_ns_mgr_fxt ini_ns_(int... ids) {
|
||||
int ids_len = ids.length;
|
||||
for (int i = 0; i < ids_len; i++) {
|
||||
int id = ids[i];
|
||||
ns_mgr.Add_new(id, Int_.To_str(id));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public Xow_ns_mgr_fxt run_Ords_sort() {ns_mgr.Init(); return this;}
|
||||
public Xow_ns_mgr_fxt tst_Ords(int... expd) {
|
||||
int actl_len = ns_mgr.Ords_len();
|
||||
int[] actl = new int[actl_len];
|
||||
for (int i = 0; i < actl_len; i++) {
|
||||
Xow_ns ns_itm = ns_mgr.Ords_ary()[i];
|
||||
actl[i] = ns_itm == null ? -100 : ns_itm.Id();
|
||||
}
|
||||
Tfds.Eq_ary(expd, actl);
|
||||
return this;
|
||||
}
|
||||
public void Test_ns_name(int expd_id, String... ns_names) {
|
||||
int ns_names_len = ns_names.length;
|
||||
for (int i = 0; i < ns_names_len; ++i) {
|
||||
String ns_name = ns_names[i];
|
||||
Xow_ns actl_ns = ns_mgr.Names_get_or_null(Bry_.new_u8(ns_name));
|
||||
int actl_id = actl_ns == null ? Int_.Min_value : actl_ns.Id();
|
||||
Tfds.Eq(expd_id, actl_id, ns_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
63
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java
Normal file
63
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_tst.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*;
|
||||
public class Xow_ns_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xow_ns_fxt fxt = new Xow_ns_fxt();
|
||||
@Test public void Category() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
|
||||
.Expd_id_subj_(Bool_.Y)
|
||||
.Expd_id_talk_(Bool_.N)
|
||||
.Test(Xow_ns_.Id_category)
|
||||
;
|
||||
}
|
||||
@Test public void Category_talk() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
|
||||
.Expd_id_subj_(Bool_.N)
|
||||
.Expd_id_talk_(Bool_.Y)
|
||||
.Test(Xow_ns_.Id_category_talk)
|
||||
;
|
||||
}
|
||||
@Test public void Special() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_special)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_special)
|
||||
.Expd_id_subj_(Bool_.Y)
|
||||
.Expd_id_talk_(Bool_.N)
|
||||
.Test(Xow_ns_.Id_special)
|
||||
;
|
||||
}
|
||||
}
|
||||
class Xow_ns_fxt {
|
||||
public void Clear() {
|
||||
expd_id_subjId = expd_id_talkId = Int_.Max_value;
|
||||
expd_id_subj = expd_id_talk = false;
|
||||
}
|
||||
public Xow_ns_fxt Expd_id_subjId_(int v) {expd_id_subjId = v; return this;} private int expd_id_subjId;
|
||||
public Xow_ns_fxt Expd_id_talkId_(int v) {expd_id_talkId = v; return this;} private int expd_id_talkId;
|
||||
public Xow_ns_fxt Expd_id_subj_(boolean v) {expd_id_subj = v; return this;} private boolean expd_id_subj;
|
||||
public Xow_ns_fxt Expd_id_talk_(boolean v) {expd_id_talk = v; return this;} private boolean expd_id_talk;
|
||||
public void Test(int nsId) {
|
||||
Xow_ns actl = new Xow_ns(nsId, Xow_ns_case_.Id_1st, Bry_.Empty, false);
|
||||
Tfds.Eq(expd_id_subjId, actl.Id_subj_id());
|
||||
Tfds.Eq(expd_id_talkId, actl.Id_talk_id());
|
||||
Tfds.Eq(expd_id_subj, actl.Id_subj());
|
||||
Tfds.Eq(expd_id_talk, actl.Id_talk());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xoa_page__commons_mgr {
|
||||
public boolean Xowa_mockup() {return xowa_mockup;} public void Xowa_mockup_(boolean v) {xowa_mockup = v;} private boolean xowa_mockup;
|
||||
public Xow_wiki Source_wiki() {return source_wiki;} public void Source_wiki_(Xow_wiki v) {source_wiki = v;} private Xow_wiki source_wiki;
|
||||
public Xow_wiki Source_wiki_or(Xow_wiki or) {return source_wiki == null ? or : source_wiki;}
|
||||
public void Clear() {
|
||||
this.xowa_mockup = false;
|
||||
this.source_wiki = null;
|
||||
}
|
||||
}
|
||||
93
400_xowa/src/gplx/xowa/wikis/pages/Xopg_html_data.java
Normal file
93
400_xowa/src/gplx/xowa/wikis/pages/Xopg_html_data.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.heads.*; import gplx.xowa.wikis.pages.skins.*; import gplx.xowa.xtns.indicators.*;
|
||||
public class Xopg_html_data {
|
||||
private Ordered_hash ctg_hash;
|
||||
public boolean Html_restricted() {return html_restricted;} private boolean html_restricted = true;
|
||||
public void Html_restricted_(boolean v) {html_restricted = v;} public void Html_restricted_n_() {Html_restricted_(Bool_.N);} public void Html_restricted_y_() {Html_restricted_(Bool_.Y);}
|
||||
public byte[] Display_ttl() {
|
||||
return ( display_ttl_vnt != null // -{T}- was in document
|
||||
&& display_ttl == null // {{DISPLAYTITLE}} does not exist
|
||||
&& lang_convert_content // __NOCONVERTCONTENT__ exists
|
||||
&& lang_convert_title // __NOCONVERTTITLE__ exists
|
||||
)
|
||||
? display_ttl_vnt // return variant title; DATE:2014-08-29
|
||||
: display_ttl // return normal title
|
||||
;
|
||||
}
|
||||
public Xopg_html_data Display_ttl_(byte[] v) {display_ttl = v; return this;} private byte[] display_ttl;
|
||||
public boolean Mode_wtxt_shown() {synchronized (this) {return mode_wtxt_shown;}} public void Mode_wtxt_shown_y_() {synchronized (this) {this.mode_wtxt_shown = true;}} private boolean mode_wtxt_shown;
|
||||
public byte[] Display_ttl_vnt() {return display_ttl_vnt;} public void Display_ttl_vnt_(byte[] v) {display_ttl_vnt = v;} private byte[] display_ttl_vnt;
|
||||
public byte[] Content_sub() {return content_sub;} public void Content_sub_(byte[] v) {content_sub = v;} private byte[] content_sub;
|
||||
public String Bmk_pos() {return html_bmk_pos;} public void Bmk_pos_(String v) {html_bmk_pos = v;} private String html_bmk_pos;
|
||||
public Bry_bfr Portal_div_xtn() {return portal_div_xtn;} private Bry_bfr portal_div_xtn = Bry_bfr.reset_(255);
|
||||
public byte[] Edit_preview_w_dbg() {return Bry_.Add(xtn_scribunto_dbg, edit_preview);} public void Edit_preview_(byte[] v) {edit_preview = v;} private byte[] edit_preview = Bry_.Empty;
|
||||
public int Lnke_autonumber_next() {return lnke_autonumber++;} private int lnke_autonumber = 1;
|
||||
public boolean Lang_convert_content() {return lang_convert_content;} public void Lang_convert_content_(boolean v) {lang_convert_content = v;} private boolean lang_convert_content = true;
|
||||
public boolean Lang_convert_title() {return lang_convert_title;} public void Lang_convert_title_(boolean v) {lang_convert_title = v;} private boolean lang_convert_title = true;
|
||||
public Xopg_xtn_skin_mgr Xtn_skin_mgr() {return xtn_skin_mgr;} private Xopg_xtn_skin_mgr xtn_skin_mgr = new Xopg_xtn_skin_mgr();
|
||||
public Indicator_html_bldr Indicators() {return indicators;} private final Indicator_html_bldr indicators = new Indicator_html_bldr();
|
||||
public int Xtn_gallery_next_id() {return ++xtn_gallery_next_id;} private int xtn_gallery_next_id = -1;
|
||||
public boolean Xtn_gallery_packed_exists() {return xtn_gallery_packed_exists;} public void Xtn_gallery_packed_exists_y_() {xtn_gallery_packed_exists = true;} private boolean xtn_gallery_packed_exists;
|
||||
public boolean Xtn_imap_exists() {return xtn_imap_exists;} public void Xtn_imap_exists_y_() {xtn_imap_exists = true;} private boolean xtn_imap_exists;
|
||||
public int Xtn_imap_next_id() {return ++xtn_imap_next_id;} private int xtn_imap_next_id; // NOTE: must keep separate imap_id b/c html_elem_id is not always set;
|
||||
public byte[] Xtn_search_text() {return xtn_search_txt;} public void Xtn_search_text_(byte[] v) {xtn_search_txt = v;} private byte[] xtn_search_txt = Bry_.Empty;
|
||||
public byte[] Xtn_scribunto_dbg() {return xtn_scribunto_dbg;} public void Xtn_scribunto_dbg_(byte[] v) {xtn_scribunto_dbg = Bry_.Add(xtn_scribunto_dbg, v);} private byte[] xtn_scribunto_dbg = Bry_.Empty;
|
||||
public Xoh_head_mgr Head_mgr() {return module_mgr;} private Xoh_head_mgr module_mgr = new Xoh_head_mgr();
|
||||
public byte[] Custom_html() {return custom_html;} public Xopg_html_data Custom_html_(byte[] v) {custom_html = v; return this;} private byte[] custom_html;
|
||||
public byte[] Custom_tab_name() {return custom_tab_name;} public Xopg_html_data Custom_tab_name_(byte[] v) {custom_tab_name = v; return this;} private byte[] custom_tab_name;
|
||||
public byte[] Custom_head_end() {return custom_head_end;}
|
||||
public byte[] Custom_html_end() {return custom_html_end;}
|
||||
public void Custom_head_end_concat(byte[] v) {
|
||||
if (v == null)
|
||||
custom_head_end = v;
|
||||
else
|
||||
custom_head_end = Bry_.Add(custom_head_end, v);
|
||||
} private byte[] custom_head_end;
|
||||
public void Custom_html_end_concat(byte[] v) {
|
||||
if (v == null)
|
||||
custom_html_end = v;
|
||||
else
|
||||
custom_html_end = Bry_.Add(custom_html_end, v);
|
||||
} private byte[] custom_html_end;
|
||||
public void Clear() {
|
||||
html_restricted = true;
|
||||
display_ttl = content_sub = display_ttl_vnt = null;
|
||||
lang_convert_content = lang_convert_title = true;
|
||||
lnke_autonumber = 1;
|
||||
xtn_skin_mgr.Clear();
|
||||
xtn_gallery_packed_exists = false;
|
||||
xtn_imap_next_id = 0; xtn_gallery_next_id = -1;
|
||||
xtn_imap_exists = false;
|
||||
xtn_search_txt = Bry_.Empty;
|
||||
xtn_scribunto_dbg = Bry_.Empty;
|
||||
module_mgr.Clear();
|
||||
custom_html = custom_html_end = custom_head_end = custom_tab_name = null;
|
||||
if (ctg_hash != null) ctg_hash.Clear();
|
||||
indicators.Clear();
|
||||
this.mode_wtxt_shown = false;
|
||||
}
|
||||
public byte[][] Ctgs_to_ary() {return ctg_hash == null ? Bry_.Ary_empty : (byte[][])ctg_hash.To_ary(byte[].class);}
|
||||
public void Ctgs_add(Xoa_ttl ttl) {
|
||||
if (ctg_hash == null) ctg_hash = Ordered_hash_.New_bry();
|
||||
byte[] ttl_bry = ttl.Page_txt();
|
||||
if (ctg_hash.Has(ttl_bry)) return;
|
||||
ctg_hash.Add(ttl_bry, ttl_bry);
|
||||
}
|
||||
}
|
||||
21
400_xowa/src/gplx/xowa/wikis/pages/Xopg_page_.java
Normal file
21
400_xowa/src/gplx/xowa/wikis/pages/Xopg_page_.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xopg_page_ {
|
||||
public static final byte Tid_read = 0, Tid_edit = 1, Tid_html = 2;
|
||||
}
|
||||
26
400_xowa/src/gplx/xowa/wikis/pages/Xopg_revision_data.java
Normal file
26
400_xowa/src/gplx/xowa/wikis/pages/Xopg_revision_data.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
public class Xopg_revision_data {
|
||||
public int Id() {return id;} public Xopg_revision_data Id_(int v) {id = v; return this;} private int id;
|
||||
public DateAdp Modified_on() {return modified_on;} public Xopg_revision_data Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on = DateAdp_.MinValue;
|
||||
public byte[] User() {return user;} public Xopg_revision_data User_(byte[] v) {user = v; return this;} private byte[] user = Bry_.Empty;
|
||||
public byte[] Protection_level() {return protection_level;} public Xopg_revision_data Protection_level_(byte[] v) {protection_level = v; return this;} private byte[] protection_level = Bry_.Empty;
|
||||
public int Html_db_id() {return html_db_id;} public void Html_db_id_(int v) {html_db_id = v;} private int html_db_id = -1;
|
||||
public void Clear() {}// NOTE: do not clear data b/c saving in Edit will call clear and id will be reset to 0
|
||||
}
|
||||
29
400_xowa/src/gplx/xowa/wikis/pages/Xopg_tab_data.java
Normal file
29
400_xowa/src/gplx/xowa/wikis/pages/Xopg_tab_data.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.guis.views.*;
|
||||
public class Xopg_tab_data {
|
||||
public Xog_tab_itm Tab() {return tab;} public void Tab_(Xog_tab_itm v) {this.tab = v;} private Xog_tab_itm tab;
|
||||
public boolean Cancel_show() {return cancel_show;} public void Cancel_show_y_() {this.cancel_show = true;} private boolean cancel_show; // used for Special:Search
|
||||
public Xog_tab_close_mgr Close_mgr() {return close_mgr;} private final Xog_tab_close_mgr close_mgr = new Xog_tab_close_mgr();
|
||||
public void Clear() {
|
||||
this.cancel_show = false;
|
||||
this.tab = null;
|
||||
close_mgr.Clear();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user