1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
public interface Xoa_wiki_mgr {
Xow_wiki Get_by_key_or_make_init_y(byte[] key);
Xow_wiki Get_by_key_or_make_init_n(byte[] key);
}

View File

@@ -0,0 +1,46 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xoa_wiki_regy {
private Xoae_app app;
private boolean init_needed = true;
private Hash_adp_bry hash = Hash_adp_bry.cs_();
public Xoa_wiki_regy(Xoae_app app) {this.app = app;}
public boolean Has(byte[] domain) {if (init_needed) Init(); return hash.Has(domain);}
public 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_.Key_bry_home, url.Wiki_bry()) // wiki is "home"
&& !Bry_.Eq(Xow_domain_type_.Key_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() {
Io_url[] wiki_dirs = Io_mgr.I.QueryDir_args(app.Fsys_mgr().Wiki_dir()).DirInclude_(true).Recur_(false).ExecAsUrlAry();
int wiki_dirs_len = wiki_dirs.length;
for (int i = 0; i < wiki_dirs_len; i++) {
Io_url wiki_dir = wiki_dirs[i];
byte[] domain_bry = Bry_.new_u8(wiki_dir.NameOnly());
hash.Add(domain_bry, domain_bry);
}
init_needed = true;
}
public static void Make_wiki_dir(Xoae_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));
}
}

View File

@@ -0,0 +1,108 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.*; import gplx.xowa.xtns.wdatas.*; import gplx.xowa.wikis.domains.crts.*;
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_ascii_(); // ASCII:url_domain; EX:en.wikipedia.org
public Xoae_wiki_mgr(Xoae_app app) {
this.app = app;
wiki_regy = new Xoa_wiki_regy(app);
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 void Del(byte[] key) {hash.Del(key);}
public Xowe_wiki Get_at(int i) {return Int_.Between(i, 0, this.Count() - 1) ? (Xowe_wiki)list.Get_at(i) : null;}
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) {
Xowe_wiki rv = this.Get_by_key_or_null(key);
if (rv == null) rv = New_wiki(key);
rv.Init_assert();
return rv;
}
public Xow_wiki Get_by_key_or_make_init_n(byte[] key) {return Get_by_key_or_make(key);}
public Xowe_wiki Get_by_key_or_make(byte[] key) {
Xowe_wiki rv = this.Get_by_key_or_null(key);
if (rv == null) rv = New_wiki(key);
return rv;
}
public Xowe_wiki Wiki_commons() {
Xowe_wiki rv = this.Get_by_key_or_null(Xow_domain_.Domain_bry_commons);
if (rv != null) rv.Init_assert();
return rv;
}
public Xowe_wiki Add(Xowe_wiki wiki) {
Xowe_wiki rv = (Xowe_wiki)hash.Get_by_bry(wiki.Domain_bry());
if (rv == null) {
hash.Add(wiki.Domain_bry(), wiki);
list.Add(wiki);
rv = wiki;
}
return rv;
}
public void Free_mem(boolean clear_ctx) {
int list_len = list.Count();
for (int i = 0; i < list_len; i++) {
Xowe_wiki wiki = (Xowe_wiki)list.Get_at(i);
// wiki.Defn_cache().ReduceCache();
if (clear_ctx) wiki.Ctx().Clear(); // NOTE: clear_ctx will reset toc and refs
wiki.Cache_mgr().Page_cache().Free_mem_all();
wiki.Cache_mgr().Tmpl_result_cache().Clear();
}
}
public void Clear() {hash.Clear(); list.Clear();}
public void Rls() {
int len = list.Count();
for (int i = 0; i < len; i++) {
Xowe_wiki wiki = (Xowe_wiki)list.Get_at(i);
wiki.Rls();
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get_by_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_len = "len", Invk_get_at = "get_at";
private Xowe_wiki New_wiki(byte[] key) {
Xow_domain domain_itm = Xow_domain_.parse(key);
byte[] lang_key = domain_itm.Lang_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 =
domain_itm.Domain_tid() == Xow_domain_type_.Tid_other
? new Xol_lang(app.Lang_mgr(), Xol_lang_.Key_en).Kwd_mgr__strx_(true)
: app.Lang_mgr().Get_by_key_or_new(lang_key);
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());
Xowe_wiki rv = new Xowe_wiki(app, lang, ns_mgr, domain_itm, wiki_dir);
Add(rv);
return rv;
}
}

View 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; import gplx.*; import gplx.xowa.*;
public class Xow_cfg_consts {
public static final String
Grp__wiki_core = "xowa.wiki.core"
, Grp__wiki_schema = "xowa.wiki.schema"
, Grp__bldr_session = "xowa.bldr.session"
, Grp__bldr_db = "xowa.bldr.db"
, Grp__bldr_fsdb = "xowa.bldr.fsdb"
, Grp__wiki_init = "wiki.init"
, Key__init__main_page = "props.main_page"
;
}

View 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
public class Xow_domain {
Xow_domain(byte[] domain_bry, Xow_domain_type domain_type, Xol_lang_itm lang_itm, Xol_lang_itm lang_orig_itm) {
this.domain_bry = domain_bry; this.domain_type = domain_type; this.lang_itm = lang_itm; this.lang_orig_itm = lang_orig_itm;
this.domain_str = String_.new_u8(domain_bry);
this.abrv_xo = Xow_domain_abrv_xo_.To_bry(domain_bry, lang_orig_itm, domain_type);
}
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 int Domain_tid() {return domain_type.Tid();}
public Xow_domain_type Domain_type() {return domain_type;} private final Xow_domain_type domain_type;
public byte[] Abrv_wm() {return abrv_wm;} public void Abrv_wm_(byte[] v) {abrv_wm = v;} private byte[] abrv_wm; // EX: enwiki
public byte[] Abrv_xo() {return abrv_xo;} private final byte[] abrv_xo;
public Xol_lang_itm Lang_itm() {return lang_itm;} private final Xol_lang_itm lang_itm;
public int Lang_uid() {return lang_itm.Id();}
public byte[] Lang_key() {return lang_itm.Key();}
public Xol_lang_itm Lang_orig_itm() {return lang_orig_itm;} private final Xol_lang_itm lang_orig_itm;
public int Lang_orig_uid() {return lang_orig_itm.Id();}
public byte[] Lang_orig_key() {return lang_orig_itm.Key();}
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 new_(byte[] domain_bry, int domain_tid, byte[] lang_key) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_itm, lang_itm);
}
public static Xow_domain new_(byte[] domain_bry, int domain_tid, Xol_lang_itm lang) {return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang, lang);}
public static Xow_domain new_orig(byte[] domain_bry, int domain_tid, byte[] lang_key, byte[] lang_orig_key) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(lang_key);
Xol_lang_itm lang_orig_itm = Bry_.Eq(lang_key, lang_orig_key) ? lang_itm : Xol_lang_itm_.Get_by_key_or_intl(lang_orig_key);
return new Xow_domain(domain_bry, Xow_domain_type_.Get_type_as_itm(domain_tid), lang_itm, lang_orig_itm);
}
}

View File

@@ -0,0 +1,104 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*;
import gplx.xowa.langs.*;
public class Xow_domain_ {
public static final String
Domain_str_enwiki = "en.wikipedia.org"
, Domain_str_species = "species.wikimedia.org"
, Domain_str_commons = "commons.wikimedia.org"
, Domain_str_wikidata = "www.wikidata.org"
, Domain_str_mediawiki = "www.mediawiki.org"
, Domain_str_meta = "meta.wikimedia.org"
, Domain_str_incubator = "incubator.wikimedia.org"
, Domain_str_wmforg = "wikimediafoundation.org"
, Domain_str_home = "home"
;
public static final byte[]
Domain_bry_enwiki = Bry_.new_a7(Domain_str_enwiki)
, Domain_bry_species = Bry_.new_a7(Domain_str_species)
, Domain_bry_commons = Bry_.new_a7(Domain_str_commons)
, Domain_bry_wikidata = Bry_.new_a7(Domain_str_wikidata)
, Domain_bry_mediawiki = Bry_.new_a7(Domain_str_mediawiki)
, Domain_bry_meta = Bry_.new_a7(Domain_str_meta)
, Domain_bry_incubator = Bry_.new_a7(Domain_str_incubator)
, Domain_bry_wmforg = Bry_.new_a7(Domain_str_wmforg)
, Domain_bry_home = Bry_.new_a7(Domain_str_home)
;
public static final byte[] Seg_bry_org = Bry_.new_a7("org"), Seg_bry_www = Bry_.new_u8("www");
public static Xow_domain parse(byte[] raw) {
/*
~{type}.org EX: wikimediafoundation
~{type}.wikimedia.org EX: commons; species; meta; incubator
~{lang}.~{type}.org EX: en.wikipedia, etc;
~www.~{type}.org EX: mediawiki; wikidata;
*/
int raw_len = raw.length;
int dot_0 = Bry_finder.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_.Key_bry_home)
? Xow_domain_uid_.To_domain(Xow_domain_uid_.Tid_xowa)
: new_other(raw);
}
int dot_1 = Bry_finder.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_.Key_bry_wmforg)
? Xow_domain.new_(raw, Xow_domain_type_.Tid_wmfblog, Xol_lang_itm_.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_.Tid_null) return new_other(raw); // seg_1 is unknown; return other;
switch (seg_1_tid) {
case Xow_domain_type_.Tid_wikipedia: case Xow_domain_type_.Tid_wiktionary: case Xow_domain_type_.Tid_wikisource: case Xow_domain_type_.Tid_wikibooks:
case Xow_domain_type_.Tid_wikiversity: case Xow_domain_type_.Tid_wikiquote: case Xow_domain_type_.Tid_wikinews: case Xow_domain_type_.Tid_wikivoyage: // ~{lang}.~{type}.org
byte[] lang_orig = Bry_.Mid(raw, 0, dot_0);
byte[] lang_actl = Get_lang_code_for_mw_messages_file(lang_orig);
return Xow_domain.new_orig(raw, seg_1_tid, lang_actl, lang_orig); // NOTE: seg_tids must match wiki_tids
case Xow_domain_type_.Tid_wikidata: case Xow_domain_type_.Tid_mediawiki: // ~www.~{type}.org
return Xow_domain.new_(raw, seg_1_tid, Xol_lang_itm_.Key__unknown);
case Xow_domain_type_.Tid_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_.Tid_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.new_(raw, Xow_domain_type_.Tid_wikimedia, wikimedia_lang.Key());
}
switch (seg_0_tid) {
case Xow_domain_type_.Tid_commons: case Xow_domain_type_.Tid_species: case Xow_domain_type_.Tid_meta: case Xow_domain_type_.Tid_incubator:
return Xow_domain.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)
default:
return new_other(raw);
}
case Xow_domain_type_.Tid_other:
default:
return new_other(raw);
}
}
private static Xow_domain new_other(byte[] raw) {return Xow_domain.new_(raw, Xow_domain_type_.Tid_other, Xol_lang_itm_.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;
}
private static final Hash_adp_bry lang_to_gfs_hash = Hash_adp_bry.ci_ascii_() // ASCII:lang_code
.Add_str_obj("simple" , Bry_.new_a7("en"))
.Add_str_obj("zh-classical" , Bry_.new_a7("lzh"))
.Add_str_obj("no" , Bry_.new_a7("nb"))
;
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
import org.junit.*;
public class Xow_domain_tst {
@Before public void init() {fxt.Clear();} private final Xow_domain_fxt fxt = new Xow_domain_fxt();
@Test public void Parse_en_wikipedia() {fxt.Test_parse("en.wikipedia.org" , "en" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_fr_wikipedia() {fxt.Test_parse("fr.wikipedia.org" , "fr" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_en_wiktionary() {fxt.Test_parse("en.wiktionary.org" , "en" , Xow_domain_type_.Tid_wiktionary);}
@Test public void Parse_zh_classical_wikipedia() {fxt.Test_parse("zh-classical.wikipedia.org" , "lzh" , Xow_domain_type_.Tid_wikipedia);}
@Test public void Parse_commons() {fxt.Test_parse("commons.wikimedia.org" , "" , Xow_domain_type_.Tid_commons);}
@Test public void Parse_species() {fxt.Test_parse("species.wikimedia.org" , "" , Xow_domain_type_.Tid_species);}
@Test public void Parse_ru_wikimedia_org() {fxt.Test_parse("ru.wikimedia.org" , "ru" , Xow_domain_type_.Tid_wikimedia);}
@Test public void Parse_home() {fxt.Test_parse("home" , "" , Xow_domain_type_.Tid_home);}
@Test public void Parse_other() {fxt.Test_parse("other.wiki" , "" , Xow_domain_type_.Tid_other);}
}
class Xow_domain_fxt {
public void Clear() {}
public void Test_parse(String domain, String expd_lang, int expd_tid) {
Xow_domain actl = Xow_domain_.parse(Bry_.new_a7(domain));
Tfds.Eq(expd_lang, String_.new_a7((actl.Lang_key())));
Tfds.Eq(expd_tid, actl.Domain_tid());
}
}

View File

@@ -0,0 +1,31 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xow_domain_type {
public Xow_domain_type(boolean multi_lang, int src, int tid, byte[] key_bry, byte[] abrv, byte[] domain_bry) {
this.multi_lang = multi_lang; this.src = src; this.tid = tid; this.key_bry = key_bry; this.abrv = abrv; this.domain_bry = domain_bry;
this.key_str = String_.new_u8(key_bry);
}
public boolean Multi_lang() {return multi_lang;} private final boolean multi_lang; // EX: y
public int Src() {return src;} private final int src; // EX: 1 (wm,mw,wk,xo)
public int Tid() {return tid;} private final int tid; // EX: 1
public String Key_str() {return key_str;} private final String key_str; // EX: wikipedia
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry; // EX: wikipedia
public byte[] Abrv() {return abrv;} private final byte[] abrv; // EX: w
public byte[] Domain_bry() {return domain_bry;} private byte[] domain_bry; // EX: .wikipedia.org
}

View File

@@ -0,0 +1,131 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xow_domain_type_ {
public static final int
Tid_null = 0
, Tid_wikipedia = 1
, Tid_wiktionary = 2
, Tid_wikisource = 3
, Tid_wikivoyage = 4
, Tid_wikiquote = 5
, Tid_wikibooks = 6
, Tid_wikiversity = 7
, Tid_wikinews = 8
, Tid_wikimedia = 9
, Tid_species = 10
, Tid_commons = 11
, Tid_wikidata = 12
, Tid_mediawiki = 13
, Tid_meta = 14
, Tid_incubator = 15
, Tid_wmfblog = 16
, Tid_home = 17
, Tid_other = 18
, Tid__len = 19
;
public static final String // SERIALIZED:xowa.gfs
Key_str_wikipedia = "wikipedia"
, Key_str_wiktionary = "wiktionary"
, Key_str_wikisource = "wikisource"
, Key_str_wikivoyage = "wikivoyage"
, Key_str_wikiquote = "wikiquote"
, Key_str_wikibooks = "wikibooks"
, Key_str_wikiversity = "wikiversity"
, Key_str_wikinews = "wikinews"
, Key_str_wikimedia = "wikimedia"
, Key_str_species = "species"
, Key_str_commons = "commons"
, Key_str_wikidata = "wikidata"
, Key_str_mediawiki = "mediawiki"
, Key_str_meta = "meta"
, Key_str_incubator = "incubator"
, Key_str_wmforg = "wikimediafoundation"
, Key_str_home = "home"
, Key_str_other = "other"
;
public static final byte[]
Key_bry_wikipedia = Bry_.new_a7(Key_str_wikipedia)
, Key_bry_wiktionary = Bry_.new_a7(Key_str_wiktionary)
, Key_bry_wikisource = Bry_.new_a7(Key_str_wikisource)
, Key_bry_wikivoyage = Bry_.new_a7(Key_str_wikivoyage)
, Key_bry_wikiquote = Bry_.new_a7(Key_str_wikiquote)
, Key_bry_wikibooks = Bry_.new_a7(Key_str_wikibooks)
, Key_bry_wikiversity = Bry_.new_a7(Key_str_wikiversity)
, Key_bry_wikinews = Bry_.new_a7(Key_str_wikinews)
, Key_bry_wikimedia = Bry_.new_a7(Key_str_wikimedia)
, Key_bry_species = Bry_.new_a7(Key_str_species)
, Key_bry_commons = Bry_.new_a7(Key_str_commons)
, Key_bry_wikidata = Bry_.new_a7(Key_str_wikidata)
, Key_bry_mediawiki = Bry_.new_a7(Key_str_mediawiki)
, Key_bry_meta = Bry_.new_a7(Key_str_meta)
, Key_bry_incubator = Bry_.new_a7(Key_str_incubator)
, Key_bry_wmforg = Bry_.new_a7(Key_str_wmforg)
, Key_bry_home = Bry_.new_a7(Key_str_home)
, Key_bry_other = Bry_.new_a7(Key_str_other)
;
private static final Xow_domain_type[] ary = new Xow_domain_type[Tid__len];
private static final Hash_adp_bry type_regy = Hash_adp_bry.ci_ascii_(); // 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
Itm_wikipedia = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikipedia , Key_bry_wikipedia , "w" , ".wikipedia.org")
, Itm_wiktionary = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wiktionary , Key_bry_wiktionary , "d" , ".wiktionary.org")
, Itm_wikisource = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikisource , Key_bry_wikisource , "s" , ".wikisource.org")
, Itm_wikivoyage = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikivoyage , Key_bry_wikivoyage , "v" , ".wikivoyage.org")
, Itm_wikiquote = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikiquote , Key_bry_wikiquote , "q" , ".wikiquote.org")
, Itm_wikibooks = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikibooks , Key_bry_wikibooks , "b" , ".wikibooks.org")
, Itm_wikiversity = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikiversity , Key_bry_wikiversity , "u" , ".wikiversity.org")
, Itm_wikinews = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikinews , Key_bry_wikinews , "n" , ".wikinews.org")
, Itm_wikimedia = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_wikimedia , Key_bry_wikimedia , "m" , ".wikimedia.org")
, Itm_species = new_(Bool_.Y , Xow_domain_type_src_.Tid_wmf , Tid_species , Key_bry_species , "species" , Xow_domain_.Domain_str_species)
, Itm_commons = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_commons , Key_bry_commons , "c" , Xow_domain_.Domain_str_commons)
, Itm_wikidata = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_wikidata , Key_bry_wikidata , "wd" , Xow_domain_.Domain_str_wikidata)
, Itm_mediawiki = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_mediawiki , Key_bry_mediawiki , "mw" , Xow_domain_.Domain_str_mediawiki)
, Itm_meta = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_meta , Key_bry_meta , "meta" , Xow_domain_.Domain_str_meta)
, Itm_incubator = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_incubator , Key_bry_incubator , "qb" , Xow_domain_.Domain_str_incubator)
, Itm_wmforg = new_(Bool_.N , Xow_domain_type_src_.Tid_wmf , Tid_wmfblog , Key_bry_wmforg , "wmf" , Xow_domain_.Domain_str_wmforg)
, Itm_home = new_(Bool_.N , Xow_domain_type_src_.Tid_xowa , Tid_home , Key_bry_home , "home" , Xow_domain_.Domain_str_home)
, Itm_other = new_(Bool_.N , Xow_domain_type_src_.Tid_mw , Tid_other , Key_bry_other , "" , "")
;
private static Xow_domain_type new_(boolean multi_lang, int src, int tid, byte[] key_bry, String abrv_str, String domain_bry) {
byte[] abrv_bry = Bry_.new_u8(abrv_str);
Xow_domain_type rv = new Xow_domain_type(multi_lang, src, tid, key_bry, abrv_bry, Bry_.new_u8(domain_bry));
ary[tid] = rv;
type_regy.Add(key_bry , rv);
abrv_regy.Add(abrv_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 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_.Tid_null : ((Xow_domain_type)o).Tid();
}
}
class Xow_domain_type_src_ {
public static final int
Tid_wmf = 1 // administered by wmf; wikipedia, etc.
, Tid_wikia = 2 // *.wikia.com
, Tid_mw = 3 // mediawiki installations not part of wmf, wikia
, Tid_xowa = 4 // xowa
;
}

View File

@@ -0,0 +1,66 @@
/*
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; import gplx.*; import gplx.xowa.*;
public class Xow_fsys_mgr {
public Xow_fsys_mgr(Io_url root_dir, Io_url file_dir) {
this.root_dir = root_dir; this.file_dir = file_dir; this.tmp_dir = root_dir.GenSubDir("tmp");
}
public Io_url Root_dir() {return root_dir;} private final Io_url root_dir;
public Io_url File_dir() {return file_dir;} private final Io_url file_dir;
public Io_url Tmp_dir() {return tmp_dir;} private final Io_url tmp_dir;
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);
int ary_len = ary.length; if (ary.length == 0) return null;
Io_url rv = Find_core_fil__xowa(ary, ary_len, domain_str);
return rv == null ? Find_core_fil__sqlite3(wiki_root_dir, ary, ary_len, domain_str) : rv;
}
private static Io_url Find_core_fil__xowa(Io_url[] ary, int ary_len, String domain_str) {
for (int i = 0; i < ary_len; i++) {
Io_url itm = ary[i];
if (!String_.Eq(itm.Ext(), ".xowa")) continue;
if ( String_.Eq(itm.NameOnly(), domain_str) // EX: "en.wikipedia.org"
|| String_.Eq(itm.NameOnly(), domain_str + "-text") // EX: "en.wikipedia.org-text"
|| String_.Eq(itm.NameOnly(), domain_str + "-core") // EX: "en.wikipedia.org-core"
) {
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v2: url=~{0}", itm.Raw());
return itm;
}
}
return null;
}
private static Io_url Find_core_fil__sqlite3(Io_url wiki_root_dir, Io_url[] ary, int ary_len, String domain_str) {
Io_url rv = null;
String v0_str = domain_str + ".000";
for (int i = 0; i < ary_len; i++) {
Io_url itm = ary[i];
if (!String_.Eq(itm.Ext(), ".sqlite3")) continue;
if (String_.Eq(itm.NameOnly(), v0_str)) { // EX: "en.wikipedia.org.000"
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.v1: url=~{0}", itm.Raw());
return itm;
}
if (ary_len == 1) {
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.custom: url=~{0}", itm.Raw());
return rv; // 1 folder and 1 sqlite file; return it; custom wikis?
}
}
Xoa_app_.Usr_dlg().Log_many("", "", "wiki.db_core.none: dir=~{0}", wiki_root_dir.Raw());
return rv;
}
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xow_page_mgr {
public void Create(Xowd_page_tbl core_tbl, Xowd_text_tbl text_tbl, int page_id, int ns_id, byte[] ttl_wo_ns, boolean redirect, DateAdp modified_on, byte[] text_zip_data, int text_raw_len, int random_int, int text_db_id, int html_db_id) {
core_tbl.Insert_cmd_by_batch(page_id, ns_id, ttl_wo_ns, redirect, modified_on, text_raw_len, random_int, text_db_id, html_db_id);
text_tbl.Insert_cmd_by_batch(page_id, text_zip_data);
}
}

View 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.xtns.wdatas.*;
public class Xow_page_tid {
public static byte Identify(int wiki_tid, int ns_id, byte[] ttl) {
switch (ns_id) {
case Xow_ns_.Id_mediawiki:
case Xow_ns_.Id_user:
return Identify_by_ttl(ttl);
case gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module:
return (Bry_.Has_at_end(ttl, Ext_doc))
? Tid_wikitext : Tid_lua;
default:
return Wdata_wiki_mgr.Wiki_page_is_json(wiki_tid, ns_id)
? Tid_json : Tid_wikitext;
}
}
public static byte Identify_by_ttl(byte[] ttl) {
if (Bry_.Has_at_end(ttl, Ext_css)) return Tid_css;
else if (Bry_.Has_at_end(ttl, Ext_js)) return Tid_js;
else return Tid_wikitext;
}
private static final byte[] Ext_js = Bry_.new_a7(".js"), Ext_css = Bry_.new_a7(".css"), Ext_doc= Bry_.new_a7("/doc");
public static final byte Tid_wikitext = 1, Tid_json = 2, Tid_js = 3, Tid_css = 4, Tid_lua = 5;
}

View 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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.langs.*;
public class Xow_wiki_abrv {
public Xol_lang_itm Lang_itm() {return lang_itm;} private Xol_lang_itm lang_itm;
public byte Domain_tid() {return domain_tid;} private byte domain_tid;
public void Ctor_by_parse(Xol_lang_itm lang_itm, byte domain_tid) {
this.lang_itm = lang_itm; this.domain_tid = domain_tid;
}
public void Clear() {
lang_itm = null;
domain_tid = Xow_wiki_abrv_.Tid_null;
}
}

View File

@@ -0,0 +1,73 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
import gplx.xowa.langs.*;
public class Xow_wiki_abrv_ {
public static boolean parse_(Xow_wiki_abrv rv, byte[] src, int bgn, int end) {
rv.Clear();
if (end - bgn == 0) return false; // empty bry
Object o = trie.Match_bgn(src, end - 1, bgn - 1); if (o == null) return false;
byte tid = ((Byte_obj_val)o).Val();
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key_or_intl(src, bgn, trie.Match_pos() + 1);
rv.Ctor_by_parse(lang_itm, tid);
return true;
}
public static final byte
Tid_null = Xow_domain_type_.Tid_other
, Tid_wikipedia = Xow_domain_type_.Tid_wikipedia
, Tid_wiktionary = Xow_domain_type_.Tid_wiktionary
, Tid_wikisource = Xow_domain_type_.Tid_wikisource
, Tid_wikibooks = Xow_domain_type_.Tid_wikibooks
, Tid_wikiversity = Xow_domain_type_.Tid_wikiversity
, Tid_wikiquote = Xow_domain_type_.Tid_wikiquote
, Tid_wikinews = Xow_domain_type_.Tid_wikinews
, Tid_wikivoyage = Xow_domain_type_.Tid_wikivoyage
, Tid_commons = Xow_domain_type_.Tid_commons
, Tid_species = Xow_domain_type_.Tid_species
, Tid_meta = Xow_domain_type_.Tid_meta
, Tid_incubator = Xow_domain_type_.Tid_incubator
, Tid_wikidata = Xow_domain_type_.Tid_wikidata
, Tid_mediawiki = Xow_domain_type_.Tid_mediawiki
, Tid_wmfblog = Xow_domain_type_.Tid_wmfblog
;
private static final Btrie_bwd_mgr trie = Init_trie();
private static Btrie_bwd_mgr Init_trie() {
Btrie_bwd_mgr rv = new Btrie_bwd_mgr(false);
Init_trie_itm(rv, "wiki" , Tid_wikipedia);
Init_trie_itm(rv, "wiktionary" , Tid_wiktionary);
Init_trie_itm(rv, "wikisource" , Tid_wikisource);
Init_trie_itm(rv, "wikibooks" , Tid_wikibooks);
Init_trie_itm(rv, "wikiversity" , Tid_wikiversity);
Init_trie_itm(rv, "wikiquote" , Tid_wikiquote);
Init_trie_itm(rv, "wikinews" , Tid_wikinews);
Init_trie_itm(rv, "wikivoyage" , Tid_wikivoyage);
Init_trie_itm(rv, "commonswiki" , Tid_commons);
Init_trie_itm(rv, "specieswiki" , Tid_species);
Init_trie_itm(rv, "metawiki" , Tid_meta);
Init_trie_itm(rv, "incubatorwiki" , Tid_incubator);
Init_trie_itm(rv, "wikidatawiki" , Tid_wikidata);
Init_trie_itm(rv, "mediawikiwiki" , Tid_mediawiki);
Init_trie_itm(rv, "foundationwiki" , Tid_wmfblog);
return rv;
}
private static void Init_trie_itm(Btrie_bwd_mgr rv, String abrv_name, byte abrv_tid) {
rv.Add(abrv_name, Byte_obj_val.new_(abrv_tid));
}
}

View File

@@ -0,0 +1,52 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.xowa.langs.*;
public class Xow_wiki_abrv_tst {
@Before public void init() {fxt.Clear();} private Xow_wiki_abrv_fxt fxt = new Xow_wiki_abrv_fxt();
@Test public void Parse() {
fxt.Parse("foundationwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_wmfblog);
fxt.Parse("wikidatawiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_wikidata);
fxt.Parse("mediawikiwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_mediawiki);
fxt.Parse("commonswiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_commons);
fxt.Parse("specieswiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_species);
fxt.Parse("metawiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_meta);
fxt.Parse("incubatorwiki" , Xol_lang_itm_.Id__intl , Xow_wiki_abrv_.Tid_incubator);
fxt.Parse("enwiki" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikipedia);
fxt.Parse("enwiktionary" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wiktionary);
fxt.Parse("enwikisource" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikisource);
fxt.Parse("enwikibooks" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikibooks);
fxt.Parse("enwikiversity" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikiversity);
fxt.Parse("enwikiquote" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikiquote);
fxt.Parse("enwikinews" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikinews);
fxt.Parse("enwikivoyage" , Xol_lang_itm_.Id_en , Xow_wiki_abrv_.Tid_wikivoyage);
fxt.Parse("frwiki" , Xol_lang_itm_.Id_fr , Xow_wiki_abrv_.Tid_wikipedia);
fxt.Parse("unknown" , Xol_lang_itm_.Id__unknown , Xow_wiki_abrv_.Tid_null);
}
}
class Xow_wiki_abrv_fxt {
private Xow_wiki_abrv abrv = new Xow_wiki_abrv();
public void Clear() {}
public void Parse(String raw, int expd_lang_id, byte expd_domain_tid) {
byte[] raw_bry = Bry_.new_a7(raw);
Xow_wiki_abrv_.parse_(abrv, raw_bry, 0, raw_bry.length);
Xol_lang_itm actl_lang_itm = abrv.Lang_itm();
Tfds.Eq(expd_lang_id , actl_lang_itm == null ? Xol_lang_itm_.Id__unknown : actl_lang_itm.Id());
Tfds.Eq(expd_domain_tid , abrv.Domain_tid());
}
}

View File

@@ -0,0 +1,244 @@
/*
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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*; import gplx.core.btries.*;
public class Xow_wiki_alias {
public Io_url Fil() {return fil;} public Xow_wiki_alias Fil_(Io_url v) {fil = v; return this;} Io_url fil;
public byte Tid() {return tid;} private byte tid;
public byte[] Domain() {return domain;} private byte[] domain;
public String Date() {return date;} private String date; // needs to be String to handle "latest"
public Xow_wiki_alias Parse(String fil_name) {return Parse(Bry_.new_a7(fil_name));}
public Xow_wiki_alias Parse(byte[] fil_name) {
int fil_name_len = fil_name.length;
int dash_0 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, 0 , fil_name_len); if (dash_0 == Bry_.NotFound) throw Exc_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(fil_name));
int dash_1 = Bry_finder.Find_fwd(fil_name, Byte_ascii.Dash, dash_0 + 1 , fil_name_len); if (dash_1 == Bry_.NotFound) throw Exc_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(fil_name));
domain = Parse__domain_name(fil_name, 0, dash_0);
date = String_.new_a7(fil_name, dash_0 + 1, dash_1);
tid = Parse__tid(fil_name, dash_1 + 1, fil_name_len);
return this;
}
public static int Extract_lang(byte[] src) {
if (alias_bry_trie == null) Init_aliases();
Object o = alias_bry_trie.Match_bgn(src, src.length - 1, 0 - 1);
return (o == null) ? -1 : alias_bry_trie.Match_pos();
}
public static byte[] Build_alias(Xow_domain wiki_type) {
if (alias_bry_trie == null) Init_aliases();
int tid = wiki_type.Domain_tid();
byte[] alias = (byte[])alias_val_hash.Get_by(Int_obj_ref.new_(tid));
if (alias == null) return null;
switch (tid) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator:
case Xow_domain_type_.Tid_wikidata:
case Xow_domain_type_.Tid_mediawiki:
case Xow_domain_type_.Tid_wmfblog:
return alias;
case Xow_domain_type_.Tid_wikipedia:
case Xow_domain_type_.Tid_wiktionary:
case Xow_domain_type_.Tid_wikisource:
case Xow_domain_type_.Tid_wikibooks:
case Xow_domain_type_.Tid_wikiversity:
case Xow_domain_type_.Tid_wikiquote:
case Xow_domain_type_.Tid_wikinews:
case Xow_domain_type_.Tid_wikivoyage:
case Xow_domain_type_.Tid_wikimedia:
return Bry_.Add(wiki_type.Lang_orig_key(), alias);
default:
throw Exc_.new_unhandled(tid);
}
}
public static byte[] Parse_wmf_key(byte[] src) {return Parse__domain_name(src, 0, src.length);}
public static byte[] Parse__domain_name_null = null;
public static byte[] Parse__domain_name(byte[] src, int bgn, int end) {
if (end - bgn == 0) return null; // empty bry;
if (alias_bry_trie == null) Init_aliases();
Object o = alias_bry_trie.Match_bgn(src, end - 1, bgn - 1); if (o == null) return Parse__domain_name_null;
int domain_tid = ((Int_obj_ref)o).Val();
Bry_bfr bfr = Bry_bfr.reset_(255);
switch (domain_tid) {
case Domain_wikimediafoundation: return bfr.Add(Xow_domain_type_.Key_bry_wmforg).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_wikidata:
case Domain_mediawiki: return bfr.Add(Xow_domain_.Seg_bry_www).Add_byte(Byte_ascii.Dot).Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_commons:
case Domain_species:
case Domain_meta:
case Domain_incubator: return bfr.Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_type_.Key_bry_wikimedia).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
case Domain_wikipedia:
case Domain_wiktionary:
case Domain_wikisource:
case Domain_wikibooks:
case Domain_wikiversity:
case Domain_wikiquote:
case Domain_wikinews:
case Domain_wikivoyage:
case Domain_wikimedia:
bfr.Add_mid(src, 0, alias_bry_trie.Match_pos() + 1);
bfr.Add_byte(Byte_ascii.Dot);
return bfr.Add(Xow_domain_type_.Get_type_as_bry(domain_tid)).Add_byte(Byte_ascii.Dot).Add(Xow_domain_.Seg_bry_org).Xto_bry_and_clear();
}
return null;
}
// TODO: swap out above with below
// public byte[] Domain() {if (domain == null) domain = Domain_init(lang_itm, domain_tid); return domain;} private byte[] domain;
// private static byte[] Domain_init(Xol_lang_itm lang_itm, byte domain_tid) {
// switch (domain_tid) {
// case Xow_wiki_abrv_.Tid_wmfblog: return Xow_domain_.Bry_wikimediafoundation;
// case Xow_wiki_abrv_.Tid_wikidata: return Xow_domain_.Domain_bry_wikidata;
// case Xow_wiki_abrv_.Tid_mediawiki: return Xow_domain_.Bry_mediawiki;
// case Xow_wiki_abrv_.Tid_commons: return Xow_domain_.Domain_bry_commons;
// case Xow_wiki_abrv_.Tid_species: return Xow_domain_.Bry_species;
// case Xow_wiki_abrv_.Tid_meta: return Xow_domain_.Bry_meta;
// case Xow_wiki_abrv_.Tid_incubator: return Xow_domain_.Bry_incubator;
// case Xow_wiki_abrv_.Tid_wikipedia:
// case Xow_wiki_abrv_.Tid_wiktionary:
// case Xow_wiki_abrv_.Tid_wikisource:
// case Xow_wiki_abrv_.Tid_wikibooks:
// case Xow_wiki_abrv_.Tid_wikiversity:
// case Xow_wiki_abrv_.Tid_wikiquote:
// case Xow_wiki_abrv_.Tid_wikinews:
// case Xow_wiki_abrv_.Tid_wikivoyage:
// return Bry_.Add
// ( lang_itm.Key() // en
// , Byte_ascii.Dot_bry // .
// , Xow_domain_type_.Get_type_as_bry(domain_tid) // wikipedia
// , Byte_ascii.Dot_bry // .
// , Xow_domain_.Seg_bry_org // org
// );
// default:
// return Bry_.Empty;
// }
// }
public static byte Parse__tid(String src) {return Parse__tid(Bry_.new_u8(src));}
public static byte Parse__tid(byte[] src) {return Parse__tid(src, 0, src.length);}
public static byte Parse__tid(byte[] src, int bgn, int end) {
if (tid_bry_trie == null) Init_tids();
Object o = tid_bry_trie.Match_bgn(src, bgn, end); if (o == null) throw Exc_.new_parse_type(Xow_wiki_alias.class, String_.new_u8(src));
return ((Byte_obj_ref)o).Val();
}
public static void Build_alias_by_lang_tid(Bry_bfr bfr, byte[] lang_key, Int_obj_ref wiki_tid) {
if (alias_bry_trie == null) Init_aliases();
byte[] domain_suffix = (byte[])alias_val_hash.Get_by(wiki_tid);
if (domain_suffix == null) return;
switch (wiki_tid.Val()) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator:
case Xow_domain_type_.Tid_wikidata:
case Xow_domain_type_.Tid_mediawiki:
case Xow_domain_type_.Tid_wmfblog:
bfr.Add(domain_suffix);
break;
case Xow_domain_type_.Tid_other:
break;
default:
bfr.Add(lang_key).Add(domain_suffix);
break;
}
}
public static Xow_domain parse_by_wmf_key(byte[] wmf_key) {
if (Bry_.Has(wmf_key, Byte_ascii.Underline)) // convert "_" to "-"; note that wmf_keys have a strict format of langtype; EX: "zh_yuewiki"; DATE:2014-10-06
wmf_key = Bry_.Replace_create(wmf_key, Byte_ascii.Underline, Byte_ascii.Dash);
byte[] domain_bry = Parse__domain_name(wmf_key, 0, wmf_key.length);
Xow_domain rv = Xow_domain_.parse(domain_bry);
rv.Abrv_wm_(wmf_key);
return rv;
}
public static final byte Tid_null = 0, Tid_pages_articles = 1, Tid_pages_meta_current = 2, Tid_categorylinks = 3, Tid_page_props = 4, Tid_image = 5;
public static final String Key_null = ""
, Key_pages_articles = "pages-articles", Key_pages_meta_current = "pages-meta-current"
, Key_categorylinks = "categorylinks", Key_page_props = "page_props"
, Key_image = "image"
;
private static final byte
Domain_wikipedia = Xow_domain_type_.Tid_wikipedia
, Domain_wiktionary = Xow_domain_type_.Tid_wiktionary
, Domain_wikisource = Xow_domain_type_.Tid_wikisource
, Domain_wikibooks = Xow_domain_type_.Tid_wikibooks
, Domain_wikiversity = Xow_domain_type_.Tid_wikiversity
, Domain_wikiquote = Xow_domain_type_.Tid_wikiquote
, Domain_wikinews = Xow_domain_type_.Tid_wikinews
, Domain_wikivoyage = Xow_domain_type_.Tid_wikivoyage
, Domain_wikimedia = Xow_domain_type_.Tid_wikimedia
, Domain_commons = Xow_domain_type_.Tid_commons
, Domain_species = Xow_domain_type_.Tid_species
, Domain_meta = Xow_domain_type_.Tid_meta
, Domain_incubator = Xow_domain_type_.Tid_incubator
, Domain_wikidata = Xow_domain_type_.Tid_wikidata
, Domain_mediawiki = Xow_domain_type_.Tid_mediawiki
, Domain_wikimediafoundation = Xow_domain_type_.Tid_wmfblog;
private static void Init_aliases() {
alias_bry_trie = new Btrie_bwd_mgr(false);
alias_val_hash = Hash_adp_.new_();
Init_alias("wiki" , Domain_wikipedia);
Init_alias("wiktionary" , Domain_wiktionary);
Init_alias("wikisource" , Domain_wikisource);
Init_alias("wikibooks" , Domain_wikibooks);
Init_alias("wikiversity" , Domain_wikiversity);
Init_alias("wikiquote" , Domain_wikiquote);
Init_alias("wikinews" , Domain_wikinews);
Init_alias("wikivoyage" , Domain_wikivoyage);
Init_alias("wikimedia" , Domain_wikimedia);
Init_alias("commonswiki" , Domain_commons);
Init_alias("specieswiki" , Domain_species);
Init_alias("metawiki" , Domain_meta);
Init_alias("incubatorwiki" , Domain_incubator);
Init_alias("wikidatawiki" , Domain_wikidata);
Init_alias("mediawikiwiki" , Domain_mediawiki);
Init_alias("foundationwiki" , Domain_wikimediafoundation);
}
private static void Init_alias(String alias_str, byte domain) {
byte[] alias_bry = Bry_.new_a7(alias_str);
Int_obj_ref domain_bval = Int_obj_ref.new_(domain);
alias_bry_trie.Add(alias_bry, domain_bval);
alias_val_hash.Add(domain_bval, alias_bry);
}
private static void Init_tids() {
tid_bry_trie = Btrie_slim_mgr.ci_ascii_(); // NOTE:ci.ascii:MW_const.en
tid_val_hash = Hash_adp_.new_();
Init_tid(Key_pages_articles , Tid_pages_articles);
Init_tid(Key_pages_meta_current , Tid_pages_meta_current);
Init_tid(Key_categorylinks , Tid_categorylinks);
Init_tid(Key_page_props , Tid_page_props);
Init_tid(Key_image , Tid_image);
}
public static String Tid_to_str(byte v) {
switch (v) {
case Tid_pages_articles : return Key_pages_articles;
case Tid_pages_meta_current : return Key_pages_meta_current;
case Tid_categorylinks : return Key_categorylinks;
case Tid_page_props : return Key_page_props;
case Tid_image : return Key_image;
default : throw Exc_.new_unhandled(v);
}
}
private static void Init_tid(String tid_str, byte tid) {
byte[] tid_bry = Bry_.new_a7(tid_str);
Byte_obj_ref tid_val = Byte_obj_ref.new_(tid);
tid_bry_trie.Add_obj(tid_bry, tid_val);
tid_val_hash.Add(tid_val, tid_bry);
}
private static Hash_adp alias_val_hash;
private static Btrie_bwd_mgr alias_bry_trie;
private static Hash_adp tid_val_hash;
private static Btrie_slim_mgr tid_bry_trie;
}

View File

@@ -0,0 +1,97 @@
/*
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; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.primitives.*; import gplx.xowa.wikis.*;
public class Xow_wiki_alias_tst {
Xow_wiki_alias_fxt fxt = new Xow_wiki_alias_fxt();
@Test public void Parse() {fxt.Parse("enwiki-20121201-pages-articles.xml.bz2", "en.wikipedia.org", "20121201", Xow_wiki_alias.Tid_pages_articles);}
@Test public void Parse__domain_name() {
fxt.Parse__domain_name("foundationwiki" , "wikimediafoundation.org");
fxt.Parse__domain_name("wikidatawiki" , "www.wikidata.org");
fxt.Parse__domain_name("mediawikiwiki" , "www.mediawiki.org");
fxt.Parse__domain_name("commonswiki" , "commons.wikimedia.org");
fxt.Parse__domain_name("specieswiki" , "species.wikimedia.org");
fxt.Parse__domain_name("metawiki" , "meta.wikimedia.org");
fxt.Parse__domain_name("incubatorwiki" , "incubator.wikimedia.org");
fxt.Parse__domain_name("enwiki" , "en.wikipedia.org");
fxt.Parse__domain_name("enwiktionary" , "en.wiktionary.org");
fxt.Parse__domain_name("enwikisource" , "en.wikisource.org");
fxt.Parse__domain_name("enwikibooks" , "en.wikibooks.org");
fxt.Parse__domain_name("enwikiversity" , "en.wikiversity.org");
fxt.Parse__domain_name("enwikiquote" , "en.wikiquote.org");
fxt.Parse__domain_name("enwikinews" , "en.wikinews.org");
fxt.Parse__domain_name("enwikivoyage" , "en.wikivoyage.org");
fxt.Parse__domain_name("plwikimedia" , "pl.wikimedia.org");
}
@Test public void Parse__tid() {
fxt.Parse__tid("pages-articles.xml" , Xow_wiki_alias.Tid_pages_articles);
fxt.Parse__tid("pages-meta-current.xml" , Xow_wiki_alias.Tid_pages_meta_current);
}
@Test public void Build_alias() {
fxt.Build_alias("simple.wikipedia.org", "simplewiki");
fxt.Build_alias("en.wikipedia.org", "enwiki");
fxt.Build_alias("commons.wikimedia.org", "commonswiki");
}
@Test public void Build_wmf_src_dir() {
fxt.Build_wmf_src_dir("simplewiki", "latest", "http://dumps.wikimedia.your.org/simplewiki/latest/");
}
@Test public void Build_wmf_src_name() {
fxt.Build_wmf_src_name("simplewiki", "latest", Xow_wiki_alias.Key_pages_articles, "simplewiki-latest-pages-articles.xml.bz2");
}
@Test public void Build_alias_by_lang_tid() {
fxt.Build_alias_by_lang_tid("en", Xow_domain_type_.Tid_wikipedia, "enwiki");
}
@Test public void Parse_by_wmf_key() {
fxt.Test_parse_by_wmf_key("enwiki", "en", "en.wikipedia.org");
fxt.Test_parse_by_wmf_key("zh_yuewiki", "zh-yue", "zh-yue.wikipedia.org");
}
}
class Xow_wiki_alias_fxt {
Xow_wiki_alias file = new Xow_wiki_alias();
public void Parse(String name, String domain, String date, byte tid) {
Io_url fil = Io_url_.mem_fil_("mem/xowa/temp/" + name);
file.Fil_(fil).Parse(fil.NameOnly());
Tfds.Eq(domain , String_.new_a7(file.Domain()));
Tfds.Eq(date , file.Date());
Tfds.Eq(tid , file.Tid());
}
public void Parse__domain_name(String raw_str, String expd) {byte[] raw = Bry_.new_a7(raw_str); Tfds.Eq(expd, String_.new_a7(Xow_wiki_alias.Parse__domain_name(raw, 0, raw.length)));}
public void Parse__tid(String raw_str, byte expd) {Tfds.Eq(expd, Xow_wiki_alias.Parse__tid(raw_str));}
public void Build_alias(String domain_str, String expd) {
Xow_domain domain = Xow_domain_.parse(Bry_.new_a7(domain_str));
byte[] actl = Xow_wiki_alias.Build_alias(domain);
Tfds.Eq(expd, String_.new_a7(actl));
} private Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public void Build_wmf_src_dir(String alias, String date, String expd) {
byte[] actl = Xob_dump_file_.Bld_dump_dir_url(Bry_.new_a7(Xob_dump_file_.Server_your_org), Bry_.new_a7(alias), Bry_.new_a7(date));
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Build_wmf_src_name(String alias, String date, String dump_type, String expd) {
byte[] actl = Xob_dump_file_.Bld_dump_file_name(Bry_.new_a7(alias), Bry_.new_a7(date), Bry_.new_a7(dump_type), Xob_dump_file_.Ext_xml_bz2);
Tfds.Eq(expd, String_.new_a7(actl));
}
public void Build_alias_by_lang_tid(String lang_key, int wiki_tid, String expd) {
Xow_wiki_alias.Build_alias_by_lang_tid(tmp_bfr, Bry_.new_a7(lang_key), wiki_tid_ref.Val_(wiki_tid));
Tfds.Eq_bry(Bry_.new_u8(expd), tmp_bfr.Xto_bry_and_clear());
} static final Int_obj_ref wiki_tid_ref = Int_obj_ref.zero_();
public void Test_parse_by_wmf_key(String wmf_key, String expd_lang_key, String expd_domain) {
Xow_domain domain = Xow_wiki_alias.parse_by_wmf_key(Bry_.new_a7(wmf_key));
Tfds.Eq(expd_lang_key , String_.new_a7(domain.Lang_key()));
Tfds.Eq(expd_domain , String_.new_a7(domain.Domain_bry()));
}
}

View File

@@ -0,0 +1,64 @@
/*
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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_cache_mgr {
private Xowe_wiki wiki;
public Xow_cache_mgr(Xowe_wiki wiki) {
this.wiki = wiki;
page_cache = new Xow_page_cache(wiki);
defn_cache = new Xow_defn_cache(wiki.Lang());
lst_cache = new Xow_defn_cache(wiki.Lang());
}
public Hash_adp Tmpl_result_cache() {return tmpl_result_cache;} private Hash_adp tmpl_result_cache = Hash_adp_bry.cs_();
public Xow_page_cache Page_cache() {return page_cache;} private Xow_page_cache page_cache;
public Xow_defn_cache Defn_cache() {return defn_cache;} private Xow_defn_cache defn_cache;
public Xow_defn_cache Lst_cache() {return lst_cache;} private Xow_defn_cache lst_cache;
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);
}
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();
defn_cache.Free_mem_all();
page_cache.Free_mem_all();
lst_cache.Free_mem_all();
scrib_lang_names = null;
}
}

View File

@@ -0,0 +1,37 @@
/*
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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.intl.*;
public class Xow_defn_cache { // stores compiled Xot_defn
private Xol_lang 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 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();}
public void Add(Xot_defn defn, byte case_match) {
byte[] name = defn.Name();
int cache_size = defn.Cache_size(); // OBSOLETE: * 2 b/c it has src and root;
cache.Add_replace(name, defn, cache_size);
if (case_match == Xow_ns_case_.Id_1st) {
name = lang.Case_mgr().Case_build_1st_upper(upper_1st_bfr, name, 0, name.length);
cache.Add_replace(name, defn, 0);
}
}
}

View 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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_cache {
private Xowe_wiki wiki;
private Hash_adp_bry cache = Hash_adp_bry.cs_(); // NOTE: wiki titles are not case-sensitive when ns is "1st-letter" (EX: w:earth an w:Earth); in these cases, two entries will be stored
public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;}
public byte[] Get_or_load_as_src(Xoa_ttl ttl) {
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
return rv == null ? null : rv.Wtxt();
}
public Xow_page_cache_itm Get_or_load_as_itm(Xoa_ttl ttl) {
byte[] ttl_full_db = ttl.Full_db();
Xow_page_cache_itm rv = (Xow_page_cache_itm)cache.Get_by_bry(ttl_full_db);
if (rv == null) {
Xoae_page page = wiki.Data_mgr().Get_page(ttl, true); // NOTE: do not call Db_mgr.Load_page; need to handle redirects
if (!page.Missing()) {
rv = new Xow_page_cache_itm(page.Ttl(), page.Data_raw(), page.Redirected_src());
cache.Add_bry_obj(ttl_full_db, rv);
}
}
return rv;
}
public void Free_mem_all() {cache.Clear();}
}

View 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.caches; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_cache_itm {
public Xow_page_cache_itm(Xoa_ttl ttl, byte[] wtxt, byte[] redirected_src_wtxt) {
this.ttl = ttl; this.wtxt = wtxt; this.redirected_src_wtxt = redirected_src_wtxt;
}
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
public byte[] Wtxt() {return wtxt;} private byte[] wtxt;
public byte[] Redirected_src_wtxt() {return redirected_src_wtxt;} private byte[] redirected_src_wtxt;
public static final Xow_page_cache_itm Null = null;
}

View 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.wikis.data.tbls.*;
public interface Xow_page_fetcher {
Xow_page_fetcher Wiki_(Xowe_wiki v);
byte[] Get_by(int ns_id, byte[] ttl);
void Clear();
}

View File

@@ -0,0 +1,32 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xow_page_fetcher_test implements Xow_page_fetcher {
public Xow_page_fetcher Wiki_(Xowe_wiki v) {return this;}
public void Clear() {pages.Clear();} private Hash_adp pages = Hash_adp_.new_();
public void Add(int ns_id, byte[] ttl, byte[] text) {
Xowd_page_itm page = new Xowd_page_itm().Ns_id_(ns_id).Ttl_page_db_(ttl).Text_(text);
pages.Add(Make_key(ns_id, ttl), page);
}
public byte[] Get_by(int ns_id, byte[] ttl) {
Xowd_page_itm rv = (Xowd_page_itm)pages.Get_by(Make_key(ns_id, ttl));
return rv == null ? null : rv.Text();
}
String Make_key(int ns_id, byte[] ttl) {return Int_.Xto_str(ns_id) + "|" + String_.new_u8(ttl);}
}

View 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_page_fetcher_wiki implements Xow_page_fetcher {
public Xow_page_fetcher Wiki_(Xowe_wiki v) {this.wiki = v; return this;} private Xowe_wiki wiki;
public void Clear() {}
public byte[] Get_by(int ns_id, byte[] ttl_bry) {
Xoa_ttl ttl = Xoa_ttl.parse_(wiki, ns_id, ttl_bry);
Xoae_page page = wiki.Data_mgr().Get_page(ttl, false); // go through data_mgr in case of redirects
return page.Missing() ? null : page.Data_raw();
}
}

View File

@@ -0,0 +1,70 @@
/*
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.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.*;
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;
this.layout_text = layout_text; this.layout_html = layout_html; this.layout_file = layout_file;
this.zip_tid_text = zip_tid_text; this.zip_tid_html = zip_tid_html;
}
public int Schema() {return schema;} private final int schema;
public boolean Schema_is_1() {return schema == 1;}
public Xowd_db_layout Layout_text() {return layout_text;} private final Xowd_db_layout layout_text;
public Xowd_db_layout Layout_html() {return layout_html;} private final Xowd_db_layout layout_html;
public Xowd_db_layout Layout_file() {return layout_file;} private final Xowd_db_layout layout_file;
public byte Zip_tid_text() {return zip_tid_text;} private final byte zip_tid_text;
public byte Zip_tid_html() {return zip_tid_html;} private final byte zip_tid_html;
public void Cfg_save(Db_cfg_tbl tbl) {
tbl.Conn().Txn_bgn();
tbl.Insert_int (Cfg_grp, Cfg_key__schema_version , schema);
tbl.Insert_str (Cfg_grp, Cfg_key__layout_text , layout_text.Name());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_html , layout_html.Name());
tbl.Insert_str (Cfg_grp, Cfg_key__layout_file , layout_file.Name());
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_text , zip_tid_text);
tbl.Insert_byte (Cfg_grp, Cfg_key__zip_tid_html , zip_tid_html);
tbl.Conn().Txn_end();
}
public static Xowd_core_db_props Cfg_load(Io_url url, Db_conn conn) {
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
return cfg_tbl.Select_int_or(Cfg_grp, Cfg_key__schema_version, 1) == 1
? new Xowd_core_db_props(1, Xowd_db_layout.Itm_lot, Xowd_db_layout.Itm_lot, Xowd_db_layout.Itm_lot, cfg_tbl.Select_byte_or(Xowe_wiki.Invk_db_mgr, Xodb_mgr_sql.Invk_data_storage_format, Io_stream_.Tid_gzip), Io_stream_.Tid_gzip)
: Cfg_load(cfg_tbl);
}
private static Xowd_core_db_props Cfg_load(Db_cfg_tbl tbl) {
Db_cfg_hash cfg_hash = tbl.Select_as_hash(Cfg_grp);
return new Xowd_core_db_props
( cfg_hash.Get(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()
);
}
private static final String Cfg_grp = Xow_cfg_consts.Grp__wiki_core
, Cfg_key__schema_version = "schema_version"
, Cfg_key__layout_text = "layout_text"
, Cfg_key__layout_html = "layout_html"
, Cfg_key__layout_file = "layout_file"
, Cfg_key__zip_tid_text = "zip_tid_text"
, Cfg_key__zip_tid_html = "zip_tid_html"
;
public static final Xowd_core_db_props Test = new Xowd_core_db_props(2, Xowd_db_layout.Itm_few, Xowd_db_layout.Itm_few, Xowd_db_layout.Itm_few, Io_stream_.Tid_raw, Io_stream_.Tid_raw);
}

View File

@@ -0,0 +1,94 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_file {
Xowd_db_file(Db_cfg_tbl cfg_tbl, Xob_info_session info_session, Xob_info_file info_file, Xowd_core_db_props props, Xowd_db_file_schema_props schema_props, int id, byte tid, Io_url url, String ns_ids, int part_id, Guid_adp guid, Db_conn conn, byte cmd_mode) {
this.id = id; this.tid = tid; this.url = url; this.ns_ids = ns_ids; this.part_id = part_id; this.guid = guid;
this.conn = conn; this.cmd_mode = cmd_mode;
this.url_rel = url.NameAndExt();
boolean schema_is_1 = props.Schema_is_1();
this.tbl__cfg = cfg_tbl;
this.tbl__db = new Xowd_xowa_db_tbl(conn, schema_is_1);
this.tbl__ns = new Xowd_site_ns_tbl(conn, schema_is_1);
this.tbl__site_stats = new Xowd_site_stats_tbl(conn, schema_is_1);
this.tbl__page = new Xowd_page_tbl(conn, schema_is_1);
this.tbl__text = new Xowd_text_tbl(conn, schema_is_1, props.Zip_tid_text());
this.tbl__html = new Xowd_html_tbl(conn, props.Zip_tid_html());
this.tbl__css_core = new Xowd_css_core_tbl(conn);
this.tbl__css_file = new Xowd_css_file_tbl(conn);
this.tbl__cat_core = new Xowd_cat_core_tbl(conn, schema_is_1);
this.tbl__cat_link = new Xowd_cat_link_tbl(conn, schema_is_1);
this.tbl__wbase_qid = new Xowd_wbase_qid_tbl(conn, schema_is_1, schema_props.Wbase__qid__src_ttl_has_spaces());
this.tbl__wbase_pid = new Xowd_wbase_pid_tbl(conn, schema_is_1);
this.tbl__search_word = new Xowd_search_word_tbl(conn, schema_is_1, schema_props.Search__word__page_count_exists());
this.tbl__search_link = new Xowd_search_link_tbl(conn, schema_is_1);
this.info_session = info_session;
this.info_file = info_file;
}
public int Id() {return id;} private final int id; // unique id in xowa_db
public byte Tid() {return tid;} private final byte tid;
public Io_url Url() {return url;} private final Io_url url;
public String Url_rel() {return url_rel;} private final String url_rel;
public String Ns_ids() {return ns_ids;} private final String ns_ids;
public int Part_id() {return part_id;} private final int part_id;
public Guid_adp Guid() {return guid;} private final Guid_adp guid;
public Db_conn Conn() {return conn;} private final Db_conn conn;
public byte Cmd_mode() {return cmd_mode;} public Xowd_db_file Cmd_mode_(byte v) {cmd_mode = v; return this;} private byte cmd_mode;
public long File_len() {return file_len;} public Xowd_db_file File_len_add(int v) {file_len += v; return this;} private long file_len;
public long File_max() {return file_max;} public Xowd_db_file File_max_(long v) {file_max = v; return this;} private long file_max;
public Xob_info_session Info_session() {return info_session;} private final Xob_info_session info_session;
public Xob_info_file Info_file() {return info_file;} private final Xob_info_file info_file;
public Db_cfg_tbl Tbl__cfg() {return tbl__cfg;} private final Db_cfg_tbl tbl__cfg;
public Xowd_xowa_db_tbl Tbl__db() {return tbl__db;} private final Xowd_xowa_db_tbl tbl__db;
public Xowd_site_ns_tbl Tbl__ns() {return tbl__ns;} private final Xowd_site_ns_tbl tbl__ns;
public Xowd_page_tbl Tbl__page() {return tbl__page;} private final Xowd_page_tbl tbl__page;
public Xowd_text_tbl Tbl__text() {return tbl__text;} private final Xowd_text_tbl tbl__text;
public Xowd_html_tbl Tbl__html() {return tbl__html;} private final Xowd_html_tbl tbl__html;
public Xowd_css_core_tbl Tbl__css_core() {return tbl__css_core;} private final Xowd_css_core_tbl tbl__css_core;
public Xowd_css_file_tbl Tbl__css_file() {return tbl__css_file;} private final Xowd_css_file_tbl tbl__css_file;
public Xowd_cat_core_tbl Tbl__cat_core() {return tbl__cat_core;} private final Xowd_cat_core_tbl tbl__cat_core;
public Xowd_cat_link_tbl Tbl__cat_link() {return tbl__cat_link;} private final Xowd_cat_link_tbl tbl__cat_link;
public Xowd_search_word_tbl Tbl__search_word() {return tbl__search_word;} private final Xowd_search_word_tbl tbl__search_word;
public Xowd_search_link_tbl Tbl__search_link() {return tbl__search_link;} private final Xowd_search_link_tbl tbl__search_link;
public Xowd_site_stats_tbl Tbl__site_stats() {return tbl__site_stats;} private final Xowd_site_stats_tbl tbl__site_stats;
public Xowd_wbase_qid_tbl Tbl__wbase_qid() {return tbl__wbase_qid;} private final Xowd_wbase_qid_tbl tbl__wbase_qid;
public Xowd_wbase_pid_tbl Tbl__wbase_pid() {return tbl__wbase_pid;} private final Xowd_wbase_pid_tbl tbl__wbase_pid;
public void Rls() {conn.Rls_conn();}
public static final Xowd_db_file Null = null;
public static Xowd_db_file make_(Xob_info_session info_session, Xowd_core_db_props props, int id, byte tid, Io_url url, String ns_ids, int part_id, String core_file_name, Db_conn conn) {
Guid_adp guid = Guid_adp_.new_();
Xob_info_file info_file = new Xob_info_file(id, Xowd_db_file_.To_key(tid), ns_ids, part_id, guid, props.Schema(), core_file_name, url.NameAndExt());
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg");
Xowd_db_file rv = new Xowd_db_file(cfg_tbl, info_session, info_file, props, Xowd_db_file_schema_props.make_(), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_create);
cfg_tbl.Create_tbl(); // always create cfg in each db
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);
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;
}
Db_cfg_tbl cfg_tbl = new Db_cfg_tbl(conn, "xowa_cfg"); // NOTE: this loads the cfg tbl for the current db, not the core db
Xob_info_session info_session = Xob_info_session.Load(cfg_tbl);
Xob_info_file info_file = Xob_info_file.Load(cfg_tbl);
return new Xowd_db_file(cfg_tbl, info_session, info_file, props, Xowd_db_file_schema_props.load_(cfg_tbl, tid, info_session.Version()), id, tid, url, ns_ids, part_id, guid, conn, Db_cmd_mode.Tid_ignore);
}
}

View 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xowd_db_file_ {
public static final int Id_core = 0;
public static final byte
Tid_core = 1, Tid_text = 2, Tid_cat = 3, Tid_search_core = 4, Tid_wbase = 5 // SERIALIZED:v1
, Tid_cat_core = 6, Tid_cat_link = 7 // SERIALIZED:v2
, Tid_wiki_solo = 8, Tid_text_solo = 9
, Tid_html_solo = 10, Tid_html_data = 11
, Tid_file_solo = 12, Tid_file_core = 13, Tid_file_data = 14, Tid_file_user = 15
;
private static final String
Key_core = "core", Key_text = "text", Key_cat = "xtn.category", Key_search_core = "xtn.search.core", Key_wbase = "core.wbase"
, Key_cat_core = "xtn.category.core", Key_cat_link = "xtn.category.link"
, Key_text_solo = "text.solo", Key_wiki_solo = "wiki.solo"
, Key_html_solo = "html.solo", Key_html_data = "html"
, Key_file_solo = "file.solo", Key_file_core = "file.core", Key_file_data = "file.data", Key_file_user = "file.user"
;
public static String To_key(byte v) {
switch (v) {
case Tid_core: return Key_core;
case Tid_text: return Key_text;
case Tid_cat: return Key_cat;
case Tid_search_core: return Key_search_core;
case Tid_wbase: return Key_wbase;
case Tid_cat_core: return Key_cat_core;
case Tid_cat_link: return Key_cat_link;
case Tid_wiki_solo: return Key_wiki_solo;
case Tid_text_solo: return Key_text_solo;
case Tid_html_solo: return Key_html_solo;
case Tid_html_data: return Key_html_data;
case Tid_file_solo: return Key_file_solo;
case Tid_file_core: return Key_file_core;
case Tid_file_data: return Key_file_data;
case Tid_file_user: return Key_file_user;
default: throw Exc_.new_unhandled(v);
}
}
}

View 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
class Xowd_db_file_hash {
private final Ordered_hash hash = Ordered_hash_.new_();
public int Count_total() {return count_total;} private int count_total;
public void Clear() {hash.Clear(); count_total = 0;}
public void Del(Xowd_db_file file) {
Ordered_hash tids = (Ordered_hash)hash.Get_by(file.Tid());
if (tids == null) throw Exc_.new_("unknown file.tid", "url", file.Url());
if (!tids.Has(file.Id())) throw Exc_.new_("unknown file.id", "url", file.Url());
tids.Del(file.Id());
--count_total;
}
public void Add_or_new(Xowd_db_file file) {
byte tid = file.Tid();
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
if (tids == null) {
tids = Ordered_hash_.new_();
hash.Add(tid, tids);
}
tids.Add(file.Id(), file);
++count_total;
}
public int Count_of_tid(byte tid) {
Ordered_hash tids = (Ordered_hash)hash.Get_by(tid);
return tids == null ? 0 : tids.Count();
}
}

View 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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.dbs.cfgs.*; import gplx.xowa.bldrs.infos.*;
public class Xowd_db_file_schema_props {
Xowd_db_file_schema_props(boolean search__word__page_count_exists, boolean wbase__qid__src_ttl_has_spaces) {
this.search__word__page_count_exists = search__word__page_count_exists;
this.wbase__qid__src_ttl_has_spaces = wbase__qid__src_ttl_has_spaces;
}
public boolean Search__word__page_count_exists() {return search__word__page_count_exists;} private final boolean search__word__page_count_exists;
public boolean Wbase__qid__src_ttl_has_spaces() {return wbase__qid__src_ttl_has_spaces;} private final boolean wbase__qid__src_ttl_has_spaces;
public static Xowd_db_file_schema_props make_() {return new Xowd_db_file_schema_props(Bool_.Y, Bool_.N);}
public static Xowd_db_file_schema_props load_(Db_cfg_tbl tbl, int tid, String version) {
boolean search__word__page_count_exists = tbl.Select_yn_or(Grp, Key__col_search_word_page_count, Bool_.N);
boolean wbase__qid__src_ttl_has_spaces = String_.In(version, "2.4.2.1", "2.4.3.1", "2.4.3.2");
return new Xowd_db_file_schema_props(search__word__page_count_exists, wbase__qid__src_ttl_has_spaces);
}
public static final String Grp = Xow_cfg_consts.Grp__wiki_schema;
public static final String
Key__tbl_css_core = "tbl.css_core" // VERSION:2.4.1
, Key__col_search_word_page_count = "col.search_word.word_page_count" // VERSION:2.4.2
;
}

View File

@@ -0,0 +1,46 @@
/*
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.data; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xowd_db_layout {
public Xowd_db_layout(int tid) {this.tid = tid;}
public int Tid() {return tid;} private final int tid;
public boolean Tid_is_all() {return tid == Const_all;}
public boolean Tid_is_all_or_few() {return tid != Const_lot;}
public boolean Tid_is_lot() {return tid == Const_lot;}
public String Name() {
switch (tid) {
case Const_all: return Name_all;
case Const_few: return Name_few;
case Const_lot: return Name_lot;
default: throw Exc_.new_unimplemented();
}
}
public static final String Name_all = "all", Name_few = "few", Name_lot = "lot";
public static final int Const_all = 1, Const_few = 2, Const_lot = 3;
public static final Xowd_db_layout
Itm_all = new Xowd_db_layout(Const_all)
, Itm_few = new Xowd_db_layout(Const_few)
, Itm_lot = new Xowd_db_layout(Const_lot)
;
public static Xowd_db_layout get_(String v) {
if (String_.Eq(v, Name_all)) return Itm_all;
else if (String_.Eq(v, Name_few)) return Itm_few;
else if (String_.Eq(v, Name_lot)) return Itm_lot;
else throw Exc_.new_unimplemented();
}
}

View File

@@ -0,0 +1,147 @@
/*
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.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.*; 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();
private final Xow_wiki wiki; private final Io_url wiki_root_dir; private final Xow_domain domain_itm;
public Xowd_db_mgr(Xow_wiki wiki, Io_url wiki_root_dir, Xow_domain domain_itm) {this.wiki = wiki; this.wiki_root_dir = wiki_root_dir; this.domain_itm = domain_itm;}
public Xowd_core_db_props Props() {return props;} private Xowd_core_db_props props = Xowd_core_db_props.Test;
public Db_cfg_tbl Tbl__cfg() {return db__core.Tbl__cfg();}
public Xowd_page_tbl Tbl__page() {return db__core.Tbl__page();}
public Xowd_db_file Db__core() {return db__core;} private Xowd_db_file db__core;
public Xowd_db_file Db__text() {return db__text;} private Xowd_db_file db__text;
public Xowd_db_file Db__html() {return db__html;} private Xowd_db_file db__html;
public Xowd_db_file Db__cat_core() {return db__cat_core;} private Xowd_db_file db__cat_core;
public Xowd_db_file Db__search() {return db__search;} private Xowd_db_file db__search;
public Xowd_db_file Db__wbase() {return db__wbase;} private Xowd_db_file db__wbase;
public int Dbs__len() {return dbs__ary.length;}
public void Db__wbase_(Xowd_db_file v) {db__wbase = v;}
public Xowd_db_file Dbs__get_at(int i) {return dbs__ary[i];}
public Xowd_db_file Dbs__make_by_tid(byte tid) {
int tid_idx = Get_tid_idx(db_file_hash, tid);
return Dbs__make_by_tid(tid, Xob_info_file.Ns_ids_empty, tid_idx, Get_tid_name(db_file_hash, tid_idx, tid));
}
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));
Dbs__add_and_save(rv);
Dbs__set_by_tid(rv);
return rv;
}
public void Dbs__delete_by_tid(byte... tids) {
int len = dbs__ary_len;
for (int i = 0; i < len; ++i) {
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();
db.Cmd_mode_(Db_cmd_mode.Tid_delete);
}
db__core.Tbl__db().Commit_all(this);
this.Init_by_load(db__core.Url());
}
public void Init_by_load(Io_url core_url) {
db_file_hash.Clear();
Db_conn core_conn = Db_conn_bldr.I.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());
dbs__ary_len = dbs__ary.length;
for (int i = 0; i < dbs__ary_len; i++) {
Xowd_db_file db = dbs__ary[i];
Dbs__set_by_tid(db);
db_file_hash.Add_or_new(db);
}
wiki.Props().Init_by_load(Tbl__cfg());
}
public void Init_by_make(Xowd_core_db_props props, Xob_info_session info_session) {
this.props = props;
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);
conn.Txn_bgn();
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();
db__core.Tbl__ns().Create_tbl();
db__core.Tbl__site_stats().Create_tbl();
db__core.Tbl__page().Create_tbl();
if (props.Layout_text().Tid_is_all_or_few()) { // create in advance else will fail for v2; import wiki -> wiki loads and tries to load categories; v2 category processes and builds tbl; DATE:2015-03-22
db__core.Tbl__cat_core().Create_tbl();
db__core.Tbl__cat_link().Create_tbl();
}
Dbs__add_and_save(db__core);
props.Cfg_save(db__core.Tbl__cfg()); // NOTE: must save cfg now, especially zip_tid; latter will be reloaded after import is done;
conn.Txn_end();
}
private void Dbs__set_by_tid(Xowd_db_file db) {
switch (db.Tid()) {
case Xowd_db_file_.Tid_wiki_solo:
case Xowd_db_file_.Tid_text_solo:
case Xowd_db_file_.Tid_core : {db__core = db; if (props.Layout_text().Tid_is_all_or_few()) db__cat_core = db__search = db__text = db; break;}
case Xowd_db_file_.Tid_text : {db__text = db; break;}
case Xowd_db_file_.Tid_html_data : {db__html = db; break;}
case Xowd_db_file_.Tid_search_core : {if (db__search == null) db__search = db; break;}
case Xowd_db_file_.Tid_wbase : {if (db__wbase == null) db__wbase = db; break;}
case Xowd_db_file_.Tid_cat_core :
case Xowd_db_file_.Tid_cat : {if (db__cat_core == null) db__cat_core = db; break;}
}
}
private void Dbs__add_and_save(Xowd_db_file rv) {
dbs__ary = (Xowd_db_file[])Array_.Resize(dbs__ary, dbs__ary_len + 1);
dbs__ary[dbs__ary_len++] = rv;
db__core.Tbl__db().Commit_all(this);
rv.Info_file().Save(rv.Tbl__cfg());
rv.Info_session().Save(rv.Tbl__cfg());
db_file_hash.Add_or_new(rv);
}
public void Rls() {
for (int i = 0; i < dbs__ary_len; i++)
dbs__ary[i].Rls();
}
private int Get_tid_idx(Xowd_db_file_hash hash, byte tid) {return hash.Count_of_tid(tid) + Int_.Base1;}
private String Get_tid_name(Xowd_db_file_hash hash, int tid_idx, byte tid) {
String tid_name = Xowd_db_file_.To_key(tid);
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;
}
return String_.Format("-{0}{1}.xowa", tid_name, tid_idx_str); // EX: en.wikipedia.org-text-001.sqlite3
}
private static String Core_file_name(Xowd_db_layout layout, String domain_name) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return domain_name + ".xowa"; // EX: en.wikipedia.org.xowa
case Xowd_db_layout.Const_few: return domain_name + "-text.xowa"; // EX: en.wikipedia.org-text.xowa
case Xowd_db_layout.Const_lot: return domain_name + "-core.xowa"; // EX: en.wikipedia.org-core.xowa
default: throw Exc_.new_unimplemented();
}
}
private static byte Core_db_tid(Xowd_db_layout layout) {
switch (layout.Tid()) {
case Xowd_db_layout.Const_all: return Xowd_db_file_.Tid_wiki_solo;
case Xowd_db_layout.Const_few: return Xowd_db_file_.Tid_text_solo;
case Xowd_db_layout.Const_lot: return Xowd_db_file_.Tid_core;
default: throw Exc_.new_unimplemented();
}
}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_cat_core_tbl implements RlsAble {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_id, fld_pages, fld_subcats, fld_files, fld_hidden, fld_link_db_id;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_update, stmt_select;
private final Xowd_cat_core_tbl__in_wkr in_wkr = new Xowd_cat_core_tbl__in_wkr();
public Db_conn Conn() {return conn;}
public Xowd_cat_core_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_link_db_id_name = "";
if (schema_is_1) {tbl_name = "category"; fld_link_db_id_name = "cat_file_idx";}
else {tbl_name = "cat_core"; fld_link_db_id_name = "cat_link_db_id";}
fld_id = flds.Add_int_pkey ("cat_id");
fld_pages = flds.Add_int ("cat_pages");
fld_subcats = flds.Add_int ("cat_subcats");
fld_files = flds.Add_int ("cat_files");
fld_hidden = flds.Add_byte ("cat_hidden");
fld_link_db_id = flds.Add_int(fld_link_db_id_name);
in_wkr.Ctor(this, tbl_name, flds, fld_id);
conn.Rls_reg(this);
}
public Xowd_cat_core_tbl Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds)); return this;}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int id, int pages, int subcats, int files, byte hidden, int link_db_id) {
stmt_insert.Clear()
.Val_int(fld_id, id).Val_int(fld_pages, pages).Val_int(fld_subcats, subcats).Val_int(fld_files, files)
.Val_byte(fld_hidden, hidden).Val_int(fld_link_db_id, link_db_id)
.Exec_insert();
}
public void Update_bgn() {conn.Txn_bgn(); stmt_update = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_hidden);}
public void Update_end() {conn.Txn_end(); stmt_update = Db_stmt_.Rls(stmt_update);}
public void Update_by_batch(int id, byte hidden) {
stmt_update.Clear().Val_byte(fld_hidden, hidden).Crt_int(fld_id, id).Exec_update();
}
public void Delete_all() {conn.Stmt_delete(tbl_name, Db_meta_fld.Ary_empty).Exec_delete();;}
public Xowd_category_itm Select(int id) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_id);
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_id, id).Exec_select__rls_manual();
try {return rdr.Move_next() ? new_itm(rdr) : Xowd_category_itm.Null;} finally {rdr.Rls();}
}
public void Select_by_cat_id_in(Cancelable cancelable, Ordered_hash rv, int bgn, int end) {
in_wkr.Init(rv);
in_wkr.Select_in(cancelable, conn, bgn, end);
}
public Xowd_category_itm new_itm(Db_rdr rdr) {
return Xowd_category_itm.load_
( rdr.Read_int(fld_id)
, rdr.Read_int(fld_link_db_id)
, rdr.Read_bool_by_byte(fld_hidden)
, rdr.Read_int(fld_subcats)
, rdr.Read_int(fld_files)
, rdr.Read_int(fld_pages)
);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_update = Db_stmt_.Rls(stmt_update);
stmt_select = Db_stmt_.Rls(stmt_select);
}
}

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.utls.*;
class Xowd_cat_core_tbl__in_wkr extends Db_in_wkr__base {
private Xowd_cat_core_tbl tbl;
private String tbl_name, fld_cat_id; private Db_meta_fld_list flds; private Ordered_hash hash;
public void Ctor(Xowd_cat_core_tbl tbl, String tbl_name, Db_meta_fld_list flds, String fld_cat_id) {
this.tbl = tbl; this.tbl_name = tbl_name; this.flds = flds; this.fld_cat_id = fld_cat_id;
}
public void Init(Ordered_hash hash) {this.hash = hash;}
@Override protected Db_qry Make_qry(int bgn, int end) {
Object[] part_ary = In_ary(end - bgn);
return Db_qry_.select_cols_(tbl_name, Db_crt_.in_(fld_cat_id, part_ary), flds.To_str_ary());
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xowd_page_itm itm = (Xowd_page_itm)hash.Get_at(i);
stmt.Crt_int(fld_cat_id, itm.Id());
}
}
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
Xowd_category_itm ctg_data = tbl.new_itm(rdr);
Xowd_page_itm page = (Xowd_page_itm)hash.Get_by(ctg_data.Id_val());
page.Xtn_(ctg_data);
}
}
}

View 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.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.*;
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;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_in;
public Db_conn Conn() {return conn;}
public Xowd_cat_link_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.tbl_name = schema_is_1 ? "categorylinks" : "cat_link";
fld_from = flds.Add_int ("cl_from");
fld_to_id = flds.Add_int ("cl_to_id");
fld_type_id = flds.Add_byte ("cl_type_id");
fld_sortkey = flds.Add_str ("cl_sortkey", 230);
fld_timestamp = flds.Add_str ("cl_timestamp", 14);
conn.Rls_reg(this);
}
public Xowd_cat_link_tbl Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds)); return this;}
public void Create_idx() {
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
, Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_to_id, fld_type_id, fld_sortkey, fld_from)
, Db_meta_idx.new_normal_by_tbl(tbl_name, "from", fld_from)
);
}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, int ctg_page_id, byte ctg_tid, byte[] sortkey, int timestamp) {
stmt_insert.Clear()
.Val_int(fld_from , page_id)
.Val_int(fld_to_id , ctg_page_id)
.Val_byte(fld_type_id , ctg_tid)
.Val_bry_as_str(fld_sortkey , sortkey)
.Val_int(fld_timestamp , timestamp)
.Exec_insert();
}
public void Delete_all() {conn.Stmt_delete(tbl_name, Db_meta_fld.Ary_empty).Exec_delete();}
public int Select_by_type(List_adp list, int cat_page_id, byte arg_tid, byte[] arg_sortkey, boolean arg_is_from, int limit) {
String arg_sortkey_str = arg_sortkey == null ? "" : String_.new_u8(arg_sortkey);
gplx.core.criterias.Criteria comp_crt = !arg_is_from
? Db_crt_.mte_(fld_sortkey, arg_sortkey_str) // from: sortkey >= 'val'
: Db_crt_.lte_(fld_sortkey, arg_sortkey_str); // until: sortkey <= 'val'
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_from, fld_sortkey).From_(tbl_name)
.Where_(gplx.core.criterias.Criteria_.And_many(Db_crt_.eq_(fld_to_id, -1), Db_crt_.eq_(fld_type_id, arg_tid), comp_crt))
.OrderBy_(fld_sortkey, !arg_is_from)
.Limit_(limit + 1); // + 1 to get last_plus_one for next page / previous page
Db_rdr rdr = conn.Stmt_new(qry).Crt_int(fld_to_id, cat_page_id).Crt_byte(fld_type_id, arg_tid).Crt_str(fld_sortkey, arg_sortkey_str).Exec_select__rls_auto();
int count = 0;
try {
while (rdr.Move_next()) {
int itm_page_id = rdr.Read_int(fld_from);
byte[] itm_sortkey = rdr.Read_bry_by_str(fld_sortkey);
Xowd_page_itm itm = new Xowd_page_itm().Id_(itm_page_id).Xtn_(new Xoctg_page_xtn(arg_tid, itm_sortkey));
list.Add(itm);
++count;
}
} finally {rdr.Rls();}
list.Sort_by(Xowd_page_itm_sorter.Ctg_tid_sortkey_asc);
return count;
}
public void Select_in(List_adp rv, int cat_id) {
if (stmt_select_in == null) stmt_select_in = conn.Stmt_select(tbl_name, flds, fld_to_id);
Db_rdr rdr = stmt_select_in.Clear().Crt_int(fld_to_id, cat_id).Exec_select__rls_manual();
try {
while (rdr.Move_next())
rv.Add(new Xowd_page_itm().Id_(rdr.Read_int(fld_from)));
} finally {rdr.Rls();}
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*; import gplx.xowa.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;
public int File_idx() {return file_idx;} private int file_idx;
public boolean Hidden() {return hidden;} private boolean hidden;
public int Count_all() {return count_subcs + count_files + count_pages;}
public int Count_subcs() {return count_subcs;} private int count_subcs;
public int Count_files() {return count_files;} private int count_files;
public int Count_pages() {return count_pages;} private int count_pages;
public int Count_by_tid(byte tid) {
switch (tid) {
case Xoa_ctg_mgr.Tid_subc: return count_subcs;
case Xoa_ctg_mgr.Tid_page: return count_pages;
case Xoa_ctg_mgr.Tid_file: return count_files;
default: throw Exc_.new_unhandled(tid);
}
}
public static Xowd_category_itm load_(int id, int file_idx, boolean hidden, int count_subcs, int count_files, int count_pages) {
Xowd_category_itm rv = new Xowd_category_itm();
rv.id = id; rv.file_idx = file_idx; rv.hidden = hidden;
rv.count_subcs = count_subcs; rv.count_files = count_files; rv.count_pages = count_pages;
return rv;
}
public static final Xowd_category_itm Null = new Xowd_category_itm(); Xowd_category_itm() {}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_css_core_itm {
public Xowd_css_core_itm(int id, String key, DateAdp updated_on) {
this.id = id; this.key = key; this.updated_on = updated_on;
}
public int Id() {return id;} private final int id;
public String Key() {return key;} private final String key;
public DateAdp Updated_on() {return updated_on;} private final DateAdp updated_on;
}

View File

@@ -0,0 +1,73 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_css_core_tbl implements RlsAble {
private final String tbl_name = "css_core"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_id, fld_key, fld_updated_on;
public Xowd_css_core_tbl(Db_conn conn) {
this.conn = conn;
this.fld_id = flds.Add_int_pkey_autonum("css_id");
this.fld_key = flds.Add_str("css_key", 255);
this.fld_updated_on = flds.Add_str("css_updated_on", 20);
conn.Rls_reg(this);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public String Tbl_name() {return tbl_name;}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_key)));}
public void Rls() {}
public int Insert(String key, DateAdp updated_on) {
Db_stmt stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Val_str(fld_key, key).Val_str(fld_updated_on, updated_on.XtoStr_fmt_yyyyMMdd_HHmmss()).Exec_insert();
return Select_id_by_key(key);
}
public void Update(int id, String key, DateAdp updated_on) {
Db_stmt stmt_update = conn.Stmt_update_exclude(tbl_name, flds, fld_id);
stmt_update.Val_str(fld_key, key).Val_str(fld_updated_on, updated_on.XtoStr_fmt_yyyyMMdd_HHmmss()).Crt_int(fld_id, id).Exec_update();
}
public Xowd_css_core_itm Select_by_key(String key) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_key).Crt_str(fld_key, key).Exec_select__rls_auto();
try {return rdr.Move_next() ? new_itm(rdr) : null;}
finally {rdr.Rls();}
}
public int Select_id_by_key(String key) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_key).Crt_str(fld_key, key).Exec_select__rls_auto();
try {return rdr.Move_next() ? rdr.Read_int(fld_id) : Id_null;}
finally {rdr.Rls();}
}
public Xowd_css_core_itm[] Select_all() { // TEST:
Db_stmt stmt = conn.Stmt_select(tbl_name, flds);
return Select_by_stmt(stmt);
}
private Xowd_css_core_itm[] Select_by_stmt(Db_stmt stmt) {
List_adp rv = List_adp_.new_();
Db_rdr rdr = stmt.Exec_select__rls_auto();
try {
while (rdr.Move_next())
rv.Add(new_itm(rdr));
} finally {rdr.Rls();}
return (Xowd_css_core_itm[])rv.To_ary_and_clear(Xowd_css_core_itm.class);
}
public void Delete_all() {
conn.Stmt_delete(tbl_name).Exec_delete();
}
private Xowd_css_core_itm new_itm(Db_rdr rdr) {
return new Xowd_css_core_itm(rdr.Read_int(fld_id), rdr.Read_str(fld_key), rdr.Read_date_by_str(fld_updated_on));
}
public static final int Id_null = -1;
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_css_file_itm {
public Xowd_css_file_itm(int css_id, String path, byte[] data) {this.css_id = css_id; this.path = path; this.data = data;}
public int Css_id() {return css_id;} private final int css_id;
public String Path() {return path;} private final String path;
public byte[] Data() {return data;} private final byte[] data;
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_css_file_tbl implements RlsAble {
private final String tbl_name = "css_file"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_css_id, fld_path, fld_data;
private final Db_conn conn; private Db_stmt stmt_insert;
public Xowd_css_file_tbl(Db_conn conn) {
this.conn = conn;
fld_css_id = flds.Add_int("css_id");
fld_path = flds.Add_str("file_path", 255);
fld_data = flds.Add_bry("file_data");
conn.Rls_reg(this);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Insert(int css_id, String path, byte[] data) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
stmt_insert.Clear().Val_int(fld_css_id, css_id).Val_str(fld_path, path).Val_bry(fld_data, data).Exec_insert();
}
public void Delete(int css_id) {
conn.Stmt_delete(tbl_name, fld_css_id).Crt_int(fld_css_id, css_id).Exec_delete();
}
public Xowd_css_file_itm[] Select_by_owner(int css_id) {
Db_stmt stmt = conn.Stmt_select(tbl_name, flds, fld_css_id).Crt_int(fld_css_id, css_id);
return Select_by_stmt(stmt);
}
public Xowd_css_file_itm[] Select_all() { // TEST:
Db_stmt stmt = conn.Stmt_select(tbl_name, flds);
return Select_by_stmt(stmt);
}
private Xowd_css_file_itm[] Select_by_stmt(Db_stmt stmt) {
List_adp rv = List_adp_.new_();
Db_rdr rdr = stmt.Exec_select__rls_auto();
try {
while (rdr.Move_next())
rv.Add(new_itm(rdr));
} finally {rdr.Rls();}
return (Xowd_css_file_itm[])rv.To_ary_and_clear(Xowd_css_file_itm.class);
}
public void Delete_all() {
conn.Stmt_delete(tbl_name).Exec_delete();
}
private Xowd_css_file_itm new_itm(Db_rdr rdr) {return new Xowd_css_file_itm(rdr.Read_int(fld_css_id), rdr.Read_str(fld_path), rdr.Read_bry(fld_data));}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_html_row {
public Xowd_html_row(int page_id, int tid, byte[] data) {this.page_id = page_id; this.tid = tid; this.data = data;}
public int Page_id() {return page_id;} private final int page_id;
public int Tid() {return tid;} private final int tid;
public byte[] Data() {return data;} private final byte[] data;
public static final int // SERIALIZED
Tid_html = 0
, Tid_img = 1
, Tid_redlink = 2
;
}

View File

@@ -0,0 +1,71 @@
/*
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.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.*;
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;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert, stmt_delete;
private final Io_stream_zip_mgr zip_mgr = Xoa_app_.Utl__zip_mgr(); private final byte zip_tid;
public Xowd_html_tbl(Db_conn conn, byte zip_tid) {
this.conn = conn; this.zip_tid = zip_tid;
fld_page_id = flds.Add_int("page_id");
fld_html_tid = flds.Add_int("html_tid");
fld_html_data = flds.Add_bry("html_data");
conn.Rls_reg(this);
}
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 Insert_bgn() {conn.Txn_bgn(); 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) {
if (stmt_insert == null) stmt_insert = conn.Stmt_insert(tbl_name, flds);
data = zip_mgr.Zip(zip_tid, data);
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_int(fld_html_tid, tid).Val_bry(fld_html_data, data).Exec_insert();
return data.length;
}
public void Delete(int page_id) {
if (stmt_delete == null) stmt_delete = conn.Stmt_delete(tbl_name, String_.Ary(fld_page_id));
stmt_delete.Clear().Crt_int(fld_page_id, page_id).Exec_delete();
}
public void Select_by_page(List_adp rv, int page_id) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_page_id));
Db_rdr rdr = stmt_select.Clear().Crt_int(fld_page_id, page_id).Exec_select__rls_manual();
try {
while (rdr.Move_next()) {
Xowd_html_row row = new Xowd_html_row(rdr.Read_int(fld_page_id), rdr.Read_int(fld_html_tid), zip_mgr.Unzip(zip_tid, rdr.Read_bry(fld_html_data)));
rv.Add(row);
}
}
finally {rdr.Rls();}
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_delete = Db_stmt_.Rls(stmt_delete);
stmt_select = Db_stmt_.Rls(stmt_select);
}
public static void Assert_col__page_html_db_id(Xowd_db_mgr db_mgr) {
Xowd_page_tbl page_tbl = db_mgr.Tbl__page(); Db_conn page_conn = page_tbl.Conn();
boolean html_flds_exists = page_conn.Meta_fld_exists(page_tbl.Tbl_name(), page_tbl.Fld_html_db_id());
if (html_flds_exists) return;
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Db_meta_fld.new_int(page_tbl.Fld_html_db_id()).Default_(-1));
page_conn.Ddl_append_fld(page_tbl.Tbl_name(), Db_meta_fld.new_int(page_tbl.Fld_redirect_id()).Default_(-1));
page_tbl.Hdump_enabled_(Bool_.Y);
}
}

View File

@@ -0,0 +1,126 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*;
public class Xowd_page_itm implements Xobl_data_itm {
public Xowd_page_itm() {this.Clear();}
public int Id() {return id;} public Xowd_page_itm Id_(int v) {id = v; id_val = null; return this;} private int id;
public Int_obj_val Id_val() {if (id_val == null) id_val = Int_obj_val.new_(id); return id_val;} private Int_obj_val id_val;
public int Ns_id() {return ns_id;} public Xowd_page_itm Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
public byte[] Ttl_page_db() {return ttl_page_db;} public Xowd_page_itm Ttl_page_db_(byte[] v) {ttl_page_db = v; return this;} private byte[] ttl_page_db; // EX: Category1
public byte[] Ttl_full_db() {return ttl_full_db;} private byte[] ttl_full_db; // EX: Category:Category1
public boolean Redirected() {return redirected;} public Xowd_page_itm Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
public int Text_len() {return text_len;} public Xowd_page_itm Text_len_(int v) {text_len = v; return this;} private int text_len;
public int Text_db_id() {return text_db_id;} public Xowd_page_itm Text_db_id_(int v) {text_db_id = v; return this;} private int text_db_id;
public byte[] Text() {return text;} public Xowd_page_itm Text_(byte[] v) {text = v; if (v != null) text_len = v.length; return this;} private byte[] text;
public int Html_db_id() {return html_db_id;} private int html_db_id;
public int Redirect_id() {return redirect_id;} private int redirect_id;
public DateAdp Modified_on() {return modified_on;} public Xowd_page_itm Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on;
public boolean Exists() {return exists;} public Xowd_page_itm Exists_(boolean v) {exists = v; return this;} private boolean exists;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public Object Xtn() {return xtn;} public Xowd_page_itm Xtn_(Object v) {this.xtn = v; return this;} private Object xtn;
public int Tdb_row_idx() {return tdb_row_idx;} public void Tdb_row_idx_(int v) {tdb_row_idx = v;} private int tdb_row_idx;
public Xowd_page_itm Init(int id, byte[] ttl_page_db, boolean redirected, int text_len, int text_db_id, int tdb_row_idx) {
this.id = id; this.ttl_page_db = ttl_page_db; this.redirected = redirected;
this.text_len = text_len; this.text_db_id = text_db_id; this.tdb_row_idx = tdb_row_idx;
id_val = null;
return this;
}
public void Init_by_sql(int id, int ns_id, byte[] ttl_page_db, DateAdp modified_on, boolean redirected, int text_len, int text_db_id, int html_db_id, int redirect_id) {
this.id = id;
this.ns_id = ns_id;
this.ttl_page_db = ttl_page_db;
this.modified_on = modified_on;
this.redirected = redirected;
this.text_len = text_len;
this.text_db_id = text_db_id;
this.html_db_id = html_db_id;
this.redirect_id = redirect_id;
}
public void Init_by_tdb(int id, int text_db_id, int tdb_row_idx, boolean redirected, int text_len, int ns_id, byte[] ttl_page_db) {
this.id = id;
this.text_db_id = text_db_id;
this.tdb_row_idx = tdb_row_idx;
this.redirected = redirected;
this.text_len = text_len;
this.ns_id = ns_id;
this.ttl_page_db = ttl_page_db;
}
public Xowd_page_itm Ttl_(Xow_ns ns, byte[] ttl_page_db) {
this.ns = ns;
ns_id = ns.Id();
this.ttl_page_db = ttl_page_db;
this.ttl_full_db = ns.Gen_ttl(ttl_page_db);
return this;
}
public Xowd_page_itm Ttl_(Xoa_ttl ttl) {
ttl_full_db = ttl.Full_txt();
ttl_page_db = ttl.Page_db();
ns = ttl.Ns();
ns_id = ns.Id();
return this;
}
public Xowd_page_itm Ttl_(byte[] v, Xow_ns_mgr ns_mgr) {
ttl_full_db = v;
Object o = ns_mgr.Names_get_w_colon(v, 0, v.length);
if (o == null) {
ns = ns_mgr.Ns_main();
ttl_page_db = v;
}
else {
ns = (Xow_ns)o;
ttl_page_db = Bry_.Mid(v, ns.Name_txt_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
}
ns_id = ns.Id();
return this;
}
public void Clear() {
id = Id_null; text_len = 0; // text_len should be 0 b/c text defaults to 0;
text_db_id = tdb_row_idx = 0; // default to 0, b/c some tests do not set and will fail at -1
ns_id = Int_.MinValue;
ttl_full_db = ttl_page_db = null; text = Bry_.Empty; // default to Ary_empty for entries that have <text />
ns = null;
redirected = exists = false;
modified_on = DateAdp_.MinValue;
id_val = null;
html_db_id = -1;
redirect_id = -1;
}
public void Copy(Xowd_page_itm orig) {
this.id = orig.id;
this.text_len = orig.text_len;
this.text_db_id = orig.text_db_id;
this.tdb_row_idx = orig.tdb_row_idx;
this.ns_id = orig.ns_id;
this.ttl_full_db = orig.ttl_full_db;
this.ttl_page_db = orig.ttl_page_db;
this.text = orig.text;
this.ns = orig.ns;
this.redirected = orig.redirected;
this.exists = orig.exists;
this.modified_on = orig.modified_on;
this.id_val = null;
this.html_db_id = orig.html_db_id;
}
public void Srl_save(Bry_bfr bfr) {gplx.xowa.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;
public static Xowd_page_itm new_tmp() {return new Xowd_page_itm();}
public static Xowd_page_itm new_srch(int id, int text_len) {return new Xowd_page_itm().Id_(id).Text_len_(text_len);}
}

View File

@@ -0,0 +1,53 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.lists.*; /*ComparerAble*/ import gplx.xowa.wikis.data.tbls.*;
public class Xowd_page_itm_sorter implements ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xowd_page_itm lhs = (Xowd_page_itm)lhsObj, rhs = (Xowd_page_itm)rhsObj;
return order * Compare_rows(compareType, lhs, rhs);
}
private static int Compare_rows(byte compareType, Xowd_page_itm lhs, Xowd_page_itm rhs) {
switch (compareType) {
case Tid_ns_ttl: {
int rv = Int_.Compare(lhs.Ns_id(), rhs.Ns_id());
return rv == CompareAble_.Same ? Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db()) : rv;
}
case Tid_itm_len: return Int_.Compare(lhs.Text_len(), rhs.Text_len());
case Tid_id: return Int_.Compare(lhs.Id(), rhs.Id());
case Tid_ttl: return Bry_.Compare(lhs.Ttl_page_db(), rhs.Ttl_page_db());
case Tid_ctg_tid_sortkey:
gplx.xowa.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();
if (lhs_xtn == null || rhs_xtn == null) return CompareAble_.Same;
int tid_comparable = Byte_.Compare(lhs_xtn.Tid(), rhs_xtn.Tid());
if (tid_comparable != CompareAble_.Same) return tid_comparable;
return Bry_.Compare(lhs_xtn.Sortkey(), rhs_xtn.Sortkey());
default: throw Exc_.new_unhandled(compareType);
}
}
Xowd_page_itm_sorter(byte compareType, int order) {this.compareType = compareType; this.order = order;}
byte compareType; int order;
static final byte Tid_ns_ttl = 0, Tid_itm_len = 2, Tid_id = 3, Tid_ttl = 4, Tid_ctg_tid_sortkey = 5;
static final int Asc = 1, Dsc = -1;
public static final Xowd_page_itm_sorter TitleAsc = new Xowd_page_itm_sorter(Tid_ttl , Asc);
public static final Xowd_page_itm_sorter EnyLenDsc = new Xowd_page_itm_sorter(Tid_itm_len , Dsc);
public static final Xowd_page_itm_sorter IdAsc = new Xowd_page_itm_sorter(Tid_id , Asc);
public static final Xowd_page_itm_sorter Ns_id_TtlAsc = new Xowd_page_itm_sorter(Tid_ns_ttl , Asc);
public static final Xowd_page_itm_sorter Ctg_tid_sortkey_asc = new Xowd_page_itm_sorter(Tid_ctg_tid_sortkey , Asc);
}

View 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.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.*;
public class Xowd_page_itm_tst {
@Before public void init() {fxt.Init();} private Xowd_page_itm_fxt fxt = new Xowd_page_itm_fxt();
@Test public void Ttl_() {
fxt.Test_ttl_("User_talk:A", Xow_ns_.Id_user_talk, "A");
fxt.Test_ttl_("User talk:A", Xow_ns_.Id_user_talk, "A");
}
}
class Xowd_page_itm_fxt {
public void Init() {
if (ns_mgr == null) {
ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.Ascii());
ns_mgr.Add_new(Xow_ns_.Id_main, "");
ns_mgr.Add_new(Xow_ns_.Id_user_talk, "User talk");
ns_mgr.Init_w_defaults();
tmp_page = new Xowd_page_itm();
}
} private Xow_ns_mgr ns_mgr; Xowd_page_itm tmp_page;
public void Test_ttl_(String ttl, int expd_ns, String expd_ttl) {
tmp_page.Ttl_(Bry_.new_a7(ttl), ns_mgr);
Tfds.Eq(expd_ns, tmp_page.Ns_id());
Tfds.Eq(expd_ttl, String_.new_a7(tmp_page.Ttl_page_db()));
}
}

View File

@@ -0,0 +1,323 @@
/*
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.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.*;
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;
private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final Db_conn conn; private Db_stmt stmt_select_all_by_ttl, stmt_select_all_by_id, stmt_select_id_by_ttl, stmt_insert; private boolean hdump_enabled;
private final String[] flds_select_all, flds_select_idx;
public String Tbl_name() {return tbl_name;}
public String Fld_page_id() {return fld_id;}
public String Fld_page_ns() {return fld_ns;}
public String Fld_page_title() {return fld_title;}
public String Fld_page_len() {return fld_len;}
public String Fld_html_db_id() {return fld_html_db_id;}
public String Fld_redirect_id() {return fld_redirect_id;}
public String[] Flds_select_idx() {return flds_select_idx;}
public String[] Flds_select_all() {return flds_select_all;}
public Db_conn Conn() {return conn;}
public Xowd_page_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_text_db_id_name = "";
if (schema_is_1) {fld_text_db_id_name = "page_file_idx";}
else {fld_text_db_id_name = "page_text_db_id";}
fld_id = flds.Add_int_pkey("page_id"); // int(10); unsigned -- MW:same
fld_ns = flds.Add_int("page_namespace"); // int(11); -- MW:same
fld_title = flds.Add_str("page_title", 255); // varbinary(255); -- MW:blob
fld_is_redirect = flds.Add_int("page_is_redirect"); // tinyint(3); -- MW:same
fld_touched = flds.Add_str("page_touched", 14); // binary(14); -- MW:blob; NOTE: should be revision!rev_timestamp, but needs extra join
fld_len = flds.Add_int("page_len"); // int(10); unsigned -- MW:same except NULL REF: WikiPage.php!updateRevisionOn;"
fld_random_int = flds.Add_int("page_random_int"); // MW:XOWA
fld_text_db_id = flds.Add_int(fld_text_db_id_name); // MW:XOWA
Hdump_enabled_(!schema_is_1);
flds_select_all = String_.Ary_wo_null(fld_id, fld_ns, fld_title, fld_touched, fld_is_redirect, fld_len, fld_text_db_id, fld_html_db_id, fld_redirect_id);
flds_select_idx = String_.Ary(fld_ns, fld_title, fld_id, fld_len);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds.To_fld_ary()));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, int ns_id, byte[] ttl_wo_ns, boolean page_is_redirect, DateAdp modified_on, int page_len, int random_int, int text_db_id, int html_db_id) {
stmt_insert.Clear()
.Val_int(fld_id, page_id)
.Val_int(fld_ns, ns_id)
.Val_bry_as_str(fld_title, ttl_wo_ns)
.Val_bool_as_byte(fld_is_redirect, page_is_redirect)
.Val_str(fld_touched, modified_on.XtoStr_fmt(Page_touched_fmt))
.Val_int(fld_len, page_len)
.Val_int(fld_random_int, random_int)
.Val_int(fld_text_db_id, text_db_id)
.Val_int(fld_html_db_id, html_db_id)
.Val_int(fld_redirect_id, -1)
.Exec_insert();
}
public void Hdump_enabled_(boolean v) {
this.hdump_enabled = v;
if (v) {
fld_html_db_id = flds.Add_int_dflt("page_html_db_id", -1); // MW:XOWA
fld_redirect_id = flds.Add_int_dflt("page_redirect_id", -1); // MW:XOWA
}
else {
fld_html_db_id = Db_meta_fld.Key_null;
fld_redirect_id = Db_meta_fld.Key_null;
}
}
public boolean Select_by_ttl(Xowd_page_itm rv, Xow_ns ns, byte[] ttl) {
if (stmt_select_all_by_ttl == null) stmt_select_all_by_ttl = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_ns, fld_title));
Db_rdr rdr = stmt_select_all_by_ttl.Clear().Crt_int(fld_ns, ns.Id()).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
Read_page__all(rv, rdr);
return true;
}
}
finally {rdr.Rls();}
return false;
}
public boolean Select_by_id(Xowd_page_itm rv, int page_id) {
if (stmt_select_all_by_id == null) stmt_select_all_by_id = conn.Stmt_select(tbl_name, flds_select_all, fld_id);
Db_rdr rdr = stmt_select_all_by_id.Clear().Crt_int(fld_id, page_id).Exec_select__rls_manual();
try {
if (rdr.Move_next()) {
Read_page__all(rv, rdr);
return true;
}
}
finally {rdr.Rls();}
return false;
}
public Db_rdr Select_all() {
Db_qry__select_cmd qry = Db_qry__select_cmd.new_().From_(tbl_name).Cols_(fld_id, fld_title).OrderBy_asc_(fld_id);
return conn.Stmt_new(qry).Exec_select__rls_auto();
}
public int Select_id(int ns_id, byte[] ttl) {
if (stmt_select_id_by_ttl == null) stmt_select_id_by_ttl = conn.Stmt_select(tbl_name, flds_select_all, fld_ns, fld_title);
Db_rdr rdr = stmt_select_id_by_ttl.Clear().Crt_int(fld_ns, ns_id).Crt_bry_as_str(fld_title, ttl).Exec_select__rls_manual();
try {
return rdr.Move_next() ? rdr.Read_int(fld_id) : Xowd_page_itm.Id_null;
} finally {rdr.Rls();}
}
public void Select_in__ttl(Cancelable cancelable, Ordered_hash rv, int ns_id, int bgn, int end) {
Xowd_page_tbl__ttl wkr = new Xowd_page_tbl__ttl();
wkr.Ctor(this, tbl_name, fld_title);
wkr.Init(rv, ns_id);
wkr.Select_in(cancelable, conn, bgn, end);
}
public void Select_in__ns_ttl(Cancelable cancelable, Ordered_hash rv, Xow_ns_mgr ns_mgr, boolean fill_idx_fields_only, int bgn, int end) {
Xowd_page_tbl__ttl_ns wkr = new Xowd_page_tbl__ttl_ns();
wkr.Fill_idx_fields_only_(fill_idx_fields_only);
wkr.Ctor(this, tbl_name, fld_title);
wkr.Init(ns_mgr, rv);
wkr.Select_in(cancelable, conn, bgn, end);
}
public boolean Select_in__id(Cancelable cancelable, List_adp rv) {return Select_in__id(cancelable, false, rv, 0, rv.Count());}
public boolean Select_in__id(Cancelable cancelable, boolean skip_table_read, List_adp rv) {return Select_in__id(cancelable, skip_table_read, rv, 0, rv.Count());}
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_();
for (int i = 0; i < len; i++) {
if (cancelable.Canceled()) return false;
Xowd_page_itm p = page_ary[i];
if (!hash.Has(p.Id_val())) // NOTE: must check if file already exists b/c dynamicPageList currently allows dupes; DATE:2013-07-22
hash.Add(p.Id_val(), p);
}
hash.Sort_by(Xowd_page_itm_sorter.IdAsc); // sort by ID to reduce disk thrashing; DATE:2015-03-31
conn.Txn_bgn();
try {
Xowd_page_tbl__id wkr = new Xowd_page_tbl__id();
wkr.Ctor(this, tbl_name, fld_id);
wkr.Init(rv, hash);
wkr.Select_in(cancelable, conn, bgn, end);
} finally {conn.Txn_end();}
return true;
}
public byte[] Select_random(Xow_ns ns) {// ns should be ns_main
int random_int = RandomAdp_.new_().Next(ns.Count());
Db_rdr rdr = conn.Stmt_select(tbl_name, String_.Ary(fld_title), fld_ns, fld_random_int)
.Crt_int(fld_ns, ns.Id()).Crt_int(fld_random_int, random_int)
.Exec_select__rls_auto();
try {
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_title) : null;
} finally {rdr.Rls();}
}
public void Select_by_search(Cancelable cancelable, List_adp rv, byte[] search, int results_max) {
if (Bry_.Len_eq_0(search)) return; // do not allow empty search
Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, Xow_ns_.Id_main), Db_crt_.like_(fld_title, ""));
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).Cols_(fld_id, fld_len, fld_ns, fld_title).Where_(crt); // NOTE: use fields from main index only
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Id_main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
Xowd_page_itm page = new Xowd_page_itm();
page.Id_ (rdr.Read_int(fld_id));
page.Ns_id_ (rdr.Read_int(fld_ns));
page.Ttl_page_db_ (rdr.Read_bry_by_str(fld_title));
page.Text_len_ (rdr.Read_int(fld_len));
rv.Add(page);
}
} finally {rdr.Rls();}
}
public void Select_for_search_suggest(Cancelable cancelable, List_adp rslt_list, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
String search_bgn = String_.new_u8(key);
String search_end = String_.new_u8(gplx.intl.Utf8_.Increment_char_at_last_pos(key));
String sql = String_.Format
( "SELECT {0}, {1}, {2}, {3} FROM {4} INDEXED BY {4}__title WHERE {1} = {5} AND {2} BETWEEN '{6}' AND '{7}' ORDER BY {3} DESC LIMIT {8};"
, fld_id, fld_ns, fld_title, fld_len
, tbl_name
, Int_.Xto_str(ns.Id()), search_bgn, search_end, Int_.Xto_str(max_results)
);
Db_qry qry = Db_qry_sql.rdr_(sql);
Db_rdr rdr = conn.Stmt_new(qry).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
Xowd_page_itm page = new Xowd_page_itm();
Read_page__idx(page, rdr);
rslt_list.Add(page);
}
rslt_list.Sort_by(Xowd_page_itm_sorter.TitleAsc);
}
finally {rdr.Rls();}
}
private Db_rdr Load_ttls_starting_with_rdr(int ns_id, byte[] ttl_frag, boolean include_redirects, int max_results, int min_page_len, int browse_len, boolean fwd, boolean search_suggest) {
String ttl_frag_str = String_.new_u8(ttl_frag);
Criteria crt_ttl = fwd ? Db_crt_.mte_(fld_title, ttl_frag_str) : Db_crt_.lt_(fld_title, ttl_frag_str);
Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, ns_id), crt_ttl, Db_crt_.mte_(fld_len, min_page_len));
if (!include_redirects)
crt = Criteria_.And(crt, Db_crt_.eq_(fld_is_redirect, Byte_.Zero));
String[] cols = search_suggest
? flds_select_idx
: flds_select_all
;
int limit = fwd ? max_results + 1 : max_results; // + 1 to get next item
Db_qry__select_cmd qry = Db_qry_.select_cols_(tbl_name, crt, cols).Limit_(limit).OrderBy_(fld_title, fwd);
Db_stmt stmt = conn.Stmt_new(qry).Crt_int(fld_ns, ns_id).Crt_str(fld_title, ttl_frag_str).Crt_int(fld_len, min_page_len);
if (!include_redirects)
stmt.Crt_bool_as_byte(fld_is_redirect, include_redirects);
return stmt.Exec_select__rls_auto();
}
public void Select_for_special_all_pages(Cancelable cancelable, List_adp rslt_list, Xowd_page_itm rslt_nxt, Xowd_page_itm rslt_prv, Int_obj_ref rslt_count, Xow_ns ns, byte[] key, int max_results, int min_page_len, int browse_len, boolean include_redirects, boolean fetch_prv_item) {
Xowd_page_itm nxt_itm = null;
int rslt_idx = 0;
boolean max_val_check = max_results == Int_.MaxValue;
Db_rdr rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, true, true);
try {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
Xowd_page_itm page = new Xowd_page_itm();
Read_page__idx(page, rdr);
if (max_val_check && !Bry_.Has_at_bgn(page.Ttl_page_db(), key)) break;
nxt_itm = page;
if (rslt_idx == max_results) {} // last item which is not meant for rslts, but only for nxt itm
else {
rslt_list.Add(page);
++rslt_idx;
}
}
if (rslt_nxt != null && nxt_itm != null) // occurs when range is empty; EX: "Module:A" in simplewikibooks
rslt_nxt.Copy(nxt_itm);
if (fetch_prv_item) { // NOTE: Special:AllPages passes in true, but Search_suggest passes in false
if (cancelable.Canceled()) return;
rdr = Load_ttls_starting_with_rdr(ns.Id(), key, include_redirects, max_results, min_page_len, browse_len, false, false);
Xowd_page_itm prv_itm = new Xowd_page_itm();
boolean found = false;
while (rdr.Move_next()) {
Read_page__all(prv_itm, rdr);
found = true;
}
if (found)
rslt_prv.Copy(prv_itm);
else { // at beginning of range, so no items found; EX: "Module:A" is search, but 1st Module is "Module:B"
if (rslt_list.Count() > 0) // use 1st item
rslt_prv.Copy((Xowd_page_itm)rslt_list.Get_at(0));
}
}
}
finally {rdr.Rls();}
rslt_count.Val_(rslt_idx);
}
public void Read_page__idx(Xowd_page_itm page, Db_rdr rdr) {
page.Id_ (rdr.Read_int(fld_id));
page.Ns_id_ (rdr.Read_int(fld_ns));
page.Ttl_page_db_ (rdr.Read_bry_by_str(fld_title));
page.Text_len_ (rdr.Read_int(fld_len));
}
public void Read_page__all(Xowd_page_itm page, Db_rdr rdr) {
int html_db_id = -1, redirected_id = -1;
if (hdump_enabled) {
html_db_id = rdr.Read_int(fld_html_db_id);
redirected_id = rdr.Read_int(fld_redirect_id);
}
page.Init_by_sql
( rdr.Read_int(fld_id)
, rdr.Read_int(fld_ns)
, rdr.Read_bry_by_str(fld_title)
, DateAdp_.parse_fmt(rdr.Read_str(fld_touched), Page_touched_fmt)
, rdr.Read_bool_by_byte(fld_is_redirect)
, rdr.Read_int(fld_len)
, rdr.Read_int(fld_text_db_id)
, html_db_id
, redirected_id
);
}
public void Update__html_db_id(int page_id, int html_db_id) {
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_html_db_id);
stmt.Val_int(fld_html_db_id, html_db_id).Crt_int(fld_id, page_id).Exec_update();
}
public void Update__ns__ttl(int page_id, int trg_ns, byte[] trg_ttl) {
for (int i = 0; i < 2; ++i) {
try {
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_ns, fld_title)
.Val_int(fld_ns, trg_ns).Val_bry_as_str(fld_title, trg_ttl)
.Crt_int(fld_id, page_id)
.Exec_update();
break;
} catch (Exception exc) {
if (String_.Has(Err_.Message_gplx_brief(exc), "columns page_namespace, page_random_int are not unique")) { // HACK: terrible hack, but moving pages across ns will break UNIQUE index
conn.Exec_sql_args("DROP INDEX {0}__name_random;", tbl_name); // is UNIQUE by default
conn.Exec_sql_args("CREATE INDEX {0}__name_random ON {0} ({1}, {2});", tbl_name, fld_ns, fld_random_int);
}
}
}
}
public void Update__redirect__modified(int page_id, boolean redirect, DateAdp modified) {
conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_is_redirect, fld_touched)
.Crt_int(fld_id, page_id)
.Val_int(fld_is_redirect, redirect ? 1 : 0).Val_str(fld_touched, modified.XtoStr_fmt(Page_touched_fmt))
.Exec_update()
;
}
public void Create_index() {
conn.Ddl_create_idx(Xoa_app_.Usr_dlg()
, Db_meta_idx.new_normal_by_tbl(tbl_name, "title" , fld_ns, fld_title, fld_id, fld_len, fld_is_redirect)
, Db_meta_idx.new_normal_by_tbl(tbl_name, "random" , fld_ns, fld_random_int)
);
}
public void Rls() {
stmt_select_all_by_ttl = Db_stmt_.Rls(stmt_select_all_by_ttl);
stmt_select_all_by_id = Db_stmt_.Rls(stmt_select_all_by_id);
stmt_select_id_by_ttl = Db_stmt_.Rls(stmt_select_id_by_ttl);
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
private static final String Page_touched_fmt = "yyyyMMddHHmmss";
}

View File

@@ -0,0 +1,116 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.criterias.*;
import gplx.dbs.*; import gplx.dbs.utls.*;
class Xowd_page_tbl__ttl_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
public void Init(Xow_ns_mgr ns_mgr, Ordered_hash hash) {this.ns_mgr = ns_mgr; this.hash = hash;}
@Override protected Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(fld_ns, 0), Db_crt_.eq_(fld_ttl, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
stmt.Val_int(page.Ns_id());
stmt.Val_bry_as_str(page.Ttl_page_db());
}
}
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {
Xow_ns ns = ns_mgr.Ids_get_or_null(rdr_page.Ns_id());
if (ns == null) return null; // NOTE: ns seems to "randomly" be null when threading during redlinks; guard against null; DATE:2014-01-03
byte[] ttl_wo_ns = rdr_page.Ttl_page_db();
rdr_page.Ttl_(ns, ttl_wo_ns);
return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_full_db());
}
}
class Xowd_page_tbl__ttl extends Xowd_page_tbl__in_wkr__base {
private Ordered_hash hash; private int in_ns;
@Override protected int Interval() {return 64;} // NOTE: 96+ overflows; EX: w:Space_Liability_Convention; DATE:2013-10-24
public void Init(Ordered_hash hash, int in_ns) {this.hash = hash; this.in_ns = in_ns;}
@Override protected Criteria In_filter(Object[] part_ary) {
int len = part_ary.length;
Criteria[] crt_ary = new Criteria[len];
String fld_ns = tbl.Fld_page_ns(); String fld_ttl = tbl.Fld_page_title();
for (int i = 0; i < len; i++)
crt_ary[i] = Criteria_.And(Db_crt_.eq_(fld_ns, in_ns), Db_crt_.eq_(fld_ttl, Bry_.Empty));
return Criteria_.Or_many(crt_ary);
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
stmt.Val_int(in_ns);
stmt.Val_bry_as_str(page.Ttl_page_db());
}
}
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Ttl_page_db());}
}
class Xowd_page_tbl__id extends Xowd_page_tbl__in_wkr__base {
private List_adp list; // list is original list of ids which may have dupes; needed to fill statement (which takes range of bgn - end); DATE:2013-12-08
private Ordered_hash hash; // hash is unique list of ids; needed for fetch from rdr (which indexes by id)
public void Init(List_adp list, Ordered_hash hash) {this.list = list; this.hash = hash; this.Fill_idx_fields_only_(true);}
@Override protected boolean Show_progress() {return true;}
@Override protected Criteria In_filter(Object[] part_ary) {
return Db_crt_.in_(this.In_fld_name(), part_ary);
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Xowd_page_itm page = (Xowd_page_itm)list.Get_at(i);
stmt.Val_int(page.Id());
}
}
@Override public Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page) {return (Xowd_page_itm)hash.Get_by(rdr_page.Id_val());}
}
abstract class Xowd_page_tbl__in_wkr__base extends Db_in_wkr__base {
protected Xowd_page_tbl tbl; private String tbl_name, fld_in_name;
public String Tbl_name() {return tbl_name;}
public void Ctor(Xowd_page_tbl tbl, String tbl_name, String fld_in_name) {this.tbl = tbl; this.tbl_name = tbl_name; this.fld_in_name = fld_in_name;}
public String In_fld_name() {return fld_in_name;}
protected abstract Criteria In_filter(Object[] part_ary);
public abstract Xowd_page_itm Read_data_to_page(Xowd_page_itm rdr_page);
public boolean Fill_idx_fields_only() {return fill_idx_fields_only;} public void Fill_idx_fields_only_(boolean v) {fill_idx_fields_only = v;} private boolean fill_idx_fields_only;
@Override protected Db_qry Make_qry(int bgn, int end) {
Object[] part_ary = In_ary(end - bgn);
return Db_qry_.select_cols_
( this.Tbl_name()
, In_filter(part_ary)
, fill_idx_fields_only ? tbl.Flds_select_idx() : tbl.Flds_select_all()
)
;
}
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
Xowd_page_itm temp = new Xowd_page_itm();
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
if (fill_idx_fields_only)
tbl.Read_page__idx(temp, rdr);
else
tbl.Read_page__all(temp, rdr);
Xowd_page_itm page = Read_data_to_page(temp);
if (page == null) continue; // page not found
temp.Exists_(true);
page.Copy(temp);
}
}
}

View 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.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.*;
public class Xowd_page_tbl_tst {
private Xowd_page_tbl_fxt fxt = new Xowd_page_tbl_fxt();
@Test public void Find_search_end() {
fxt.Test_find_search_end("ab", "ac");
fxt.Test_find_search_end("ab%", "ac%");
}
}
class Xowd_page_tbl_fxt {
public void Test_find_search_end(String val, String expd) {Tfds.Eq(expd, String_.new_u8(Find_search_end(Bry_.new_u8(val))));}
private static byte[] Find_search_end(byte[] orig) { // NOTE: moved from old Xowd_page_tbl; is probably obsolete
byte[] rv = Bry_.Copy(orig);
int rv_len = rv.length;
int increment_pos = rv[rv_len - 1] == Byte_ascii.Percent ? rv_len - 2 : rv_len - 1; // increment last char, unless it is %; if %, increment one before it
return Bry_.Increment_last(rv, increment_pos);
}
}

View File

@@ -0,0 +1,75 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*;
import gplx.dbs.*; import gplx.dbs.utls.*;
public class Xowd_search_link_tbl {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_word_id, fld_page_id;
private final Db_conn conn; private Db_stmt stmt_insert; private final Xowd_search_page_tbl__in_wkr in_wkr = new Xowd_search_page_tbl__in_wkr();
public Xowd_search_link_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "search_title_page"; fld_prefix = "stp_";}
else {tbl_name = "search_link";}
fld_word_id = flds.Add_int(fld_prefix + "word_id");
fld_page_id = flds.Add_int(fld_prefix + "page_id");
in_wkr.Ctor(tbl_name, flds, fld_page_id, fld_word_id);
}
public String Tbl_name() {return tbl_name;}
public String Fld_word_id() {return fld_word_id;}
public String Fld_page_id() {return fld_page_id;}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Create_idx_unique() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
public void Create_idx_normal() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "main", fld_word_id, fld_page_id));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int word_id, int page_id) {
stmt_insert.Clear().Val_int(fld_word_id, word_id).Val_int(fld_page_id, page_id).Exec_insert();
}
public void Select_in(Cancelable cancelable, List_adp rv, List_adp words) {
in_wkr.Init(words, rv);
in_wkr.Select_in(cancelable, conn, 0, words.Count());
}
}
class Xowd_search_page_tbl__in_wkr extends Db_in_wkr__base {
private String tbl_name; private Db_meta_fld_list flds; private String fld_page_id, fld_word_id;
private List_adp words, pages;
public void Ctor(String tbl_name, Db_meta_fld_list flds, String fld_page_id, String fld_word_id) {
this.tbl_name = tbl_name; this.flds = flds; this.fld_page_id = fld_page_id; this.fld_word_id = fld_word_id;
}
public void Init(List_adp words, List_adp pages) {this.words = words; this.pages = pages;}
@Override protected Db_qry Make_qry(int bgn, int end) {
Object[] part_ary = In_ary(end - bgn);
return Db_qry_.select_cols_(tbl_name, Db_crt_.in_(fld_word_id, part_ary), flds.To_str_ary());
}
@Override protected void Fill_stmt(Db_stmt stmt, int bgn, int end) {
for (int i = bgn; i < end; i++) {
Int_obj_val word_id = (Int_obj_val)words.Get_at(i);
stmt.Crt_int(fld_word_id, word_id.Val());
}
}
@Override protected void Read_data(Cancelable cancelable, Db_rdr rdr) {
while (rdr.Move_next()) {
if (cancelable.Canceled()) return;
int page_id = rdr.Read_int(fld_page_id);
Xowd_page_itm page = new Xowd_page_itm().Id_(page_id);
pages.Add(page);
}
}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.engines.sqlite.*;
public class Xowd_search_temp_tbl {
private final String tbl_name = "search_temp"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_page_id, fld_word_text;
private final Db_conn conn; private Db_stmt stmt_insert;
private final String sql_create_word, sql_create_link;
public Xowd_search_temp_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
if (schema_is_1) {sql_create_word = Sql_create_word_v1; sql_create_link = Sql_create_link_v1;}
else {sql_create_word = Sql_create_word_v2; sql_create_link = Sql_create_link_v2;}
flds.Add_int_pkey_autonum("word_id");
fld_page_id = flds.Add_int("page_id");
fld_word_text = flds.Add_str("word_text", 255);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, byte[] word) {
stmt_insert.Clear()
.Val_int(fld_page_id, page_id).Val_bry_as_str(fld_word_text, word)
.Exec_insert();
}
public void Make_data(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
conn.Ddl_create_idx(usr_dlg, Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_word_text, fld_page_id));
conn.Exec_sql_plog_txn("search_temp.create_word", sql_create_word);
conn.Exec_sql_plog_txn("search_temp.create_link", sql_create_link);
Create_idx(usr_dlg, search_link_tbl, search_word_tbl);
conn.Env_vacuum();
}
public void Create_idx(Gfo_usr_dlg usr_dlg, Xowd_search_link_tbl search_link_tbl, Xowd_search_word_tbl search_word_tbl) {
conn.Ddl_delete_tbl(tbl_name);
try {search_word_tbl.Create_idx();}
catch (Exception e) {usr_dlg.Warn_many("", "", "bldr.search_word.unique_search_failed: err=~{0}", Err_.Message_gplx_brief(e));}
try {search_link_tbl.Create_idx_unique();}
catch (Exception e) {
usr_dlg.Warn_many("", "", "bldr.search_page.unique_search_failed: err=~{0}", Err_.Message_gplx_brief(e));
search_link_tbl.Create_idx_normal();;
}
}
private static final String Sql_create_word_v1 = String_.Concat_lines_nl
( "INSERT INTO search_title_word (stw_word_id, stw_word)"
, "SELECT word_id"
, ", word_text"
, "FROM search_temp"
, "GROUP BY "
, " word_text"
, ";"
);
private static final String Sql_create_link_v1 = String_.Concat_lines_nl
( "INSERT INTO search_title_page (stp_word_id, stp_page_id)"
, "SELECT w.stw_word_id"
, ", t.page_id"
, "FROM search_temp t"
, " JOIN search_title_word w ON t.word_text = w.stw_word"
, ";"
);
private static final String Sql_create_word_v2 = String_.Concat_lines_nl
( "INSERT INTO search_word (word_id, word_text, word_page_count)"
, "SELECT word_id"
, ", word_text"
, ", Count(DISTINCT page_id)"
, "FROM search_temp"
, "GROUP BY "
, " word_text"
, ";"
);
private static final String Sql_create_link_v2 = String_.Concat_lines_nl
( "INSERT INTO search_link (word_id, page_id)"
, "SELECT w.word_id"
, ", t.page_id"
, "FROM search_temp t"
, " JOIN search_word w ON t.word_text = w.word_text"
, ";"
);
}

View File

@@ -0,0 +1,25 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
public class Xowd_search_word_row {
public Xowd_search_word_row(int id, byte[] text, int page_count) {this.id = id; this.text = text; this.page_count = page_count;}
public int Id() {return id;} private final int id;
public byte[] Text() {return text;} private final byte[] text;
public int Page_count() {return page_count;} private final int page_count;
public static final Xowd_search_word_row Null = null;
}

View File

@@ -0,0 +1,129 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.core.primitives.*; import gplx.dbs.*; import gplx.dbs.cfgs.*; import gplx.dbs.qrys.*;
public class Xowd_search_word_tbl implements RlsAble {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_id, fld_text; private String fld_page_count; private boolean page_count_exists;
private final Db_conn conn; private Db_stmt stmt_insert, stmt_select_by, stmt_select_in;
public Xowd_search_word_tbl(Db_conn conn, boolean schema_is_1, boolean page_count_exists) {
this.conn = conn; this.page_count_exists = page_count_exists;
String fld_prefix = "", fld_text_name = "word_text";
if (schema_is_1) {tbl_name = "search_title_word"; fld_prefix = "stw_"; fld_text_name = "stw_word";}
else {tbl_name = "search_word";}
this.fld_id = flds.Add_int_pkey(fld_prefix + "word_id");
this.fld_text = flds.Add_str(fld_text_name, 255);
this.fld_page_count = page_count_exists ? flds.Add_int_dflt("word_page_count", 0) : Db_meta_fld.Key_null;
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_unique_by_tbl(tbl_name, "main", fld_text, fld_id, fld_page_count));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int id, byte[] word, int page_count) {
stmt_insert.Clear().Val_int(fld_id, id).Val_bry_as_str(fld_text, word).Val_int(fld_page_count, page_count).Exec_insert();
}
public Xowd_search_word_row Select_by_or_null(byte[] word) {
if (stmt_select_by == null) stmt_select_by = conn.Stmt_select(tbl_name, flds, fld_text);
Db_rdr rdr = stmt_select_by.Clear().Crt_bry_as_str(fld_text, word).Exec_select__rls_manual();
try {
return rdr.Move_next() ? new_row(rdr) : Xowd_search_word_row.Null;
}
finally {rdr.Rls();}
}
private Xowd_search_word_row new_row(Db_rdr rdr) {
int page_count = fld_page_count == Db_meta_fld.Key_null ? 0 : rdr.Read_int(fld_page_count);
return new Xowd_search_word_row(rdr.Read_int(fld_id), rdr.Read_bry_by_str(fld_text), page_count);
}
public Xowd_search_word_row[] Select_in(Cancelable cxl, byte[] word) {
if (stmt_select_in == null) {
Db_qry__select_cmd qry = Db_qry_.select_().From_(tbl_name).OrderBy_(fld_page_count, Bool_.N).Where_(Db_crt_.like_(fld_text, "")); // order by highest page count to look at most common words
stmt_select_in = conn.Stmt_new(qry);
}
List_adp list = List_adp_.new_();
Db_rdr rdr = stmt_select_in.Clear().Crt_bry_as_str(fld_text, Bry_.Replace(word, Byte_ascii.Star, Byte_ascii.Percent)).Exec_select__rls_manual();
try {
int row_count = 0;
while (rdr.Move_next()) {
if (cxl.Canceled()) break;
Xowd_search_word_row word_row = new_row(rdr);
if (++row_count % 10 == 0)
Xoa_app_.Usr_dlg().Prog_many("", "", "search; reading pages for word: word=~{0} pages=~{1}", word_row.Text(), word_row.Page_count());
list.Add(word_row);
}
}
finally {rdr.Rls();}
return (Xowd_search_word_row[])list.To_ary_and_clear(Xowd_search_word_row.class);
}
public void Select_by_word(Cancelable cancelable, Xowd_search_link_tbl search_page_tbl, List_adp rv, byte[] search, int results_max) {
gplx.core.criterias.Criteria crt = null;
if (Bry_.Has(search, Byte_ascii.Star)) {
search = Bry_.Replace(search, Byte_ascii.Star, Byte_ascii.Percent);
crt = Db_crt_.like_ (fld_text, String_.new_u8(search));
}
else
crt = Db_crt_.eq_ (fld_text, String_.new_u8(search));
Db_qry__select_cmd qry = Db_qry_.select_().Cols_(fld_id).From_(tbl_name).Where_(crt);
List_adp words = List_adp_.new_();
Db_rdr rdr = conn.Stmt_new(qry).Crt_bry_as_str(fld_text, search).Exec_select__rls_auto();
try {
while (rdr.Move_next())
words.Add(Int_obj_val.new_(rdr.Read_int(fld_id)));
}
finally {rdr.Rls();}
search_page_tbl.Select_in(cancelable, rv, words);
}
public boolean Ddl__page_count() {return page_count_exists;}
public void Ddl__page_count_y_() { // needed for search_cmd;
page_count_exists = true;
if (!flds.Has("word_page_count"))
flds.Add_int_dflt("word_page_count", 0);
}
public void Ddl__page_count__add(Xowd_search_link_tbl link_tbl, Db_cfg_tbl cfg_tbl) {
Db_meta_fld page_count_fld = Db_meta_fld.new_int("word_page_count").Default_(0);
conn.Txn_bgn();
conn.Ddl_append_fld(tbl_name, page_count_fld); // SQL: ALTER TABLE search_word ADD word_page_count integer NOT NULL DEFAULT 0;
String sql = String_.Format(String_.Concat_lines_nl_skip_last
( "REPLACE INTO {0} ({1}, {2}, word_page_count)"
, "SELECT w.{1}"
, ", w.{2}"
, ", Count(l.{4})"
, "FROM {0} w"
, " JOIN {3} l ON w.{1} = l.{4}"
, "GROUP BY w.{1}"
, ", w.{2};"
), tbl_name, fld_id, fld_text
, link_tbl.Tbl_name(), link_tbl.Fld_word_id()
);
conn.Exec_sql_plog_ntx("calculating page count per word (please wait)", sql);
Ddl__page_count__cfg(cfg_tbl);
fld_page_count = page_count_fld.Name(); flds.Add(page_count_fld); this.Rls();
conn.Txn_end();
}
public void Ddl__page_count__cfg(Db_cfg_tbl cfg_tbl) {
cfg_tbl.Insert_yn(Xowd_db_file_schema_props.Grp, Xowd_db_file_schema_props.Key__col_search_word_page_count, Bool_.Y);
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select_by = Db_stmt_.Rls(stmt_select_by);
stmt_select_in = Db_stmt_.Rls(stmt_select_in);
}
public static final int Id_null = -1;
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
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;
private final Db_conn conn;
public Xowd_site_ns_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
this.tbl_name = schema_is_1 ? "xowa_ns" : "site_ns";
fld_id = flds.Add_int_pkey ("ns_id");
fld_name = flds.Add_str ("ns_name", 255);
fld_case = flds.Add_byte ("ns_case");
fld_is_alias = flds.Add_bool ("ns_is_alias");
fld_count = flds.Add_int ("ns_count");
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Insert(Xow_ns_mgr ns_mgr) {
Db_stmt stmt = conn.Stmt_insert(tbl_name, flds);
int len = ns_mgr.Ids_len();
for (int i = 0; i < len; i++) {
Xow_ns ns = ns_mgr.Ids_get_at(i);
stmt.Clear()
.Val_int(fld_id, ns.Id())
.Val_str(fld_name, ns.Name_str())
.Val_byte(fld_case, ns.Case_match())
.Val_bool_as_byte(fld_is_alias, ns.Is_alias())
.Val_int(fld_count, ns.Count())
.Exec_insert();
;
}
}
public void Select_all(Xow_ns_mgr ns_mgr) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
try {
ns_mgr.Clear();
while (rdr.Move_next()) {
int ns_id = rdr.Read_int(fld_id);
byte[] ns_name = rdr.Read_bry_by_str(fld_name);
byte ns_case_match = rdr.Read_byte(fld_case);
int ns_count = rdr.Read_int(fld_count);
boolean ns_is_alias = rdr.Read_byte(fld_is_alias) == Bool_.Y_byte;
ns_mgr.Add_new(ns_id, ns_name, ns_case_match, ns_is_alias);
if (ns_id < 0) continue; // don't load counts for Special / Media
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
ns.Count_(ns_count);
if (ns_count > 0) ns.Exists_(true); // ns has article; mark it as exists, else Talk tab won't show; DATE:2013-12-04
}
ns_mgr.Init();
} finally {rdr.Rls();}
}
public int Select_ns_count(int ns_id) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, String_.Ary(fld_id))
.Crt_int(fld_id, ns_id)
.Exec_select__rls_auto();
try {
return rdr.Move_next() ? Int_.cast_(rdr.Read_int(fld_count)) : 0;
} finally {rdr.Rls();}
}
public void Update_ns_count(int ns_id, int ns_count) {
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_id), fld_count);
stmt.Clear()
.Val_int(fld_count, ns_count)
.Crt_int(fld_id, ns_id)
.Exec_update();
}
}

View File

@@ -0,0 +1,52 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_site_stats_tbl {
private final String tbl_name = "site_stats";
private final String fld_row_id, fld_good_articles, fld_total_pages, fld_images;
private final Db_conn conn; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
public Xowd_site_stats_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
fld_row_id = flds.Add_int_pkey("ss_row_id");
fld_good_articles = flds.Add_long("ss_good_articles");
fld_total_pages = flds.Add_long("ss_total_pages");
fld_images = flds.Add_int("ss_images");
}
public void Create_tbl() {
conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));
conn.Stmt_insert(tbl_name, flds).Val_int(fld_row_id, Site_stats_row_id).Val_long(fld_good_articles, 0).Val_long(fld_total_pages, 0).Val_int(fld_images, 0).Exec_insert();
}
public void Update(int num_articles, int num_pages, int num_files) {
Db_stmt stmt = conn.Stmt_update(tbl_name, String_.Ary(fld_row_id), fld_good_articles, fld_total_pages, fld_images);
stmt.Val_long(fld_good_articles, num_articles).Val_long(fld_total_pages, num_pages).Val_int(fld_images, num_files)
.Crt_int(fld_row_id, Site_stats_row_id)
.Exec_update();
}
public void Select(Xow_wiki_stats stats) {
Db_rdr rdr = conn.Stmt_select(tbl_name, flds, fld_row_id).Crt_int(fld_row_id, Site_stats_row_id).Exec_select__rls_auto();
try {
if (rdr.Move_next()) {
stats.NumArticles_ ((int)rdr.Read_long(fld_good_articles)); // #<>(int)rdr.Read_long~rdr.Read_int
stats.NumPages_ ((int)rdr.Read_long(fld_total_pages)); // #<>(int)rdr.Read_long~rdr.Read_int
stats.NumFiles_ (rdr.Read_int(fld_images));
}
} finally {rdr.Rls();}
}
private static final int Site_stats_row_id = 1;
}

View File

@@ -0,0 +1,59 @@
/*
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.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.utls.*;
public class Xowd_text_tbl implements RlsAble {
private final String tbl_name = "text"; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_page_id, fld_text_data;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private final Io_stream_zip_mgr zip_mgr = Xoa_app_.Utl__zip_mgr(); private final byte zip_tid;
public String Fld_text_data() {return fld_text_data;}
public Xowd_text_tbl(Db_conn conn, boolean schema_is_1, byte zip_tid) {
this.conn = conn; this.zip_tid = zip_tid;
String fld_text_data_name = "";
fld_text_data_name = schema_is_1 ? "old_text" : "text_data";
fld_page_id = flds.Add_int_pkey("page_id");
fld_text_data = flds.Add_bry(fld_text_data_name);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(int page_id, byte[] text_data) {
stmt_insert.Clear().Val_int(fld_page_id, page_id).Val_bry(fld_text_data, text_data).Exec_insert();
}
public void Update(int page_id, byte[] text) {
Db_stmt stmt = conn.Stmt_update_exclude(tbl_name, flds, fld_page_id);
text = zip_mgr.Zip(zip_tid, text);
stmt.Clear().Val_bry(fld_text_data, text).Crt_int(fld_page_id, page_id).Exec_update();
}
public byte[] Select(int page_id) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_page_id);
Db_rdr rdr = stmt_select.Clear().Val_int(fld_page_id, page_id).Exec_select__rls_manual();
try {
byte[] rv = (byte[])rdr.Read_bry(fld_text_data);
rv = zip_mgr.Unzip(zip_tid, rv);
return rv;
} finally {rdr.Rls();}
}
public byte[] Zip(byte[] data) {return zip_mgr.Zip(zip_tid, data);}
public void Rls() {
stmt_select = Db_stmt_.Rls(stmt_select);
stmt_insert = Db_stmt_.Rls(stmt_insert);
}
}

View File

@@ -0,0 +1,58 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.xowa.xtns.wdatas.*;
public class Xowd_wbase_pid_tbl implements RlsAble {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_src_lang, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
public Xowd_wbase_pid_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "wdata_pids"; fld_prefix = "wp_";}
else {tbl_name = "wbase_pid";}
fld_src_lang = flds.Add_str(fld_prefix + "src_lang", 255);
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "src", fld_src_lang, fld_src_ttl));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(byte[] src_lang, byte[] src_ttl, byte[] trg_ttl) {
stmt_insert.Clear()
.Val_bry_as_str(fld_src_lang, src_lang).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl, trg_ttl)
.Exec_insert();
}
public int Select_pid(byte[] src_lang, byte[] src_ttl) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_lang, fld_src_ttl);
Db_rdr rdr = stmt_select.Clear()
.Crt_bry_as_str(fld_src_lang, src_lang).Crt_bry_as_str(fld_src_ttl, src_ttl)
.Exec_select__rls_manual();
try {
if (!rdr.Move_next()) return Wdata_wiki_mgr.Pid_null; // occurs when pid exists, but does not have entry for language; see hu.w:Marco Polo argali; DATE: 2014-02-01
byte[] pid_bry = rdr.Read_bry_by_str(fld_trg_ttl);
return pid_bry == null ? Wdata_wiki_mgr.Pid_null : Bry_.Xto_int_or(pid_bry, 1, pid_bry.length, Wdata_wiki_mgr.Pid_null);
} finally {rdr.Rls();}
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select = Db_stmt_.Rls(stmt_select);
}
}

View File

@@ -0,0 +1,59 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*;
public class Xowd_wbase_qid_tbl implements RlsAble {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_src_wiki, fld_src_ns, fld_src_ttl, fld_trg_ttl;
private final Db_conn conn; private Db_stmt stmt_select, stmt_insert;
private boolean src_ttl_has_spaces;
public Xowd_wbase_qid_tbl(Db_conn conn, boolean schema_is_1, boolean src_ttl_has_spaces) {
this.conn = conn; this.src_ttl_has_spaces = src_ttl_has_spaces;
String fld_prefix = "";
if (schema_is_1) {tbl_name = "wdata_qids"; fld_prefix = "wq_";}
else {tbl_name = "wbase_qid";}
fld_src_wiki = flds.Add_str(fld_prefix + "src_wiki", 255);
fld_src_ns = flds.Add_int(fld_prefix + "src_ns");
fld_src_ttl = flds.Add_str(fld_prefix + "src_ttl", 512);
fld_trg_ttl = flds.Add_str(fld_prefix + "trg_ttl", 512);
conn.Rls_reg(this);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public void Create_idx() {conn.Ddl_create_idx(Xoa_app_.Usr_dlg(), Db_meta_idx.new_normal_by_tbl(tbl_name, "src", fld_src_wiki, fld_src_ns, fld_src_ttl));}
public void Insert_bgn() {conn.Txn_bgn(); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
public void Insert_cmd_by_batch(byte[] src_wiki, int src_ns, byte[] src_ttl, byte[] trg_ttl) {
stmt_insert.Clear()
.Val_bry_as_str(fld_src_wiki, src_wiki).Val_int(fld_src_ns, src_ns).Val_bry_as_str(fld_src_ttl, src_ttl).Val_bry_as_str(fld_trg_ttl,trg_ttl)
.Exec_insert();
}
public byte[] Select_qid(byte[] src_wiki, byte[] src_ns, byte[] src_ttl) {
if (stmt_select == null) stmt_select = conn.Stmt_select(tbl_name, flds, fld_src_wiki, fld_src_ns, fld_src_ttl);
if (src_ttl_has_spaces) src_ttl = Xoa_ttl.Replace_unders(src_ttl); // NOTE: v2.4.2.1-v2.4.3.2 stores ttl in spaces ("A B"), while xowa will use under form ("A_B"); DATE:2015-04-21
Db_rdr rdr = stmt_select.Clear()
.Crt_bry_as_str(fld_src_wiki, src_wiki).Crt_int(fld_src_ns, Bry_.Xto_int(src_ns)).Crt_bry_as_str(fld_src_ttl, src_ttl)
.Exec_select__rls_manual();
try {
return rdr.Move_next() ? rdr.Read_bry_by_str(fld_trg_ttl) : null;
} finally {rdr.Rls();}
}
public void Rls() {
stmt_insert = Db_stmt_.Rls(stmt_insert);
stmt_select = Db_stmt_.Rls(stmt_select);
}
}

View File

@@ -0,0 +1,47 @@
/*
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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import org.junit.*; import gplx.dbs.*;
public class Xowd_wbase_qid_tbl_tst {
private final Xowd_wbase_qid_tbl_fxt fxt = new Xowd_wbase_qid_tbl_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Space() {
fxt.Exec_insert("enwiki", Xow_ns_.Id_main, "A B", "q1");
fxt.Test_select("enwiki", Xow_ns_.Id_main, "A B", "q1");
fxt.Test_select("enwiki", Xow_ns_.Id_main, "A_B", "q1");
}
}
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"));
this.qid_tbl = new Xowd_wbase_qid_tbl(conn, Bool_.N, Bool_.Y); // simulate v2.4.2 with bad "spaces"
qid_tbl.Create_tbl();
}
public void Exec_insert(String src_wiki, int src_ns, String src_ttl, String trg_ttl) {
qid_tbl.Insert_bgn();
qid_tbl.Insert_cmd_by_batch(Bry_.new_u8(src_wiki), src_ns, Bry_.new_u8(src_ttl), Bry_.new_u8(trg_ttl));
qid_tbl.Insert_end();
}
public void Test_select(String src_wiki, int src_ns, String src_ttl, String expd) {
byte[] actl = qid_tbl.Select_qid(Bry_.new_u8(src_wiki), Bry_.new_a7(Int_.Xto_str(src_ns)), Bry_.new_u8(src_ttl));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View 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.data.tbls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.data.*;
import gplx.dbs.*; import gplx.dbs.qrys.*;
import gplx.xowa.wikis.data.*;
public class Xowd_xowa_db_tbl {
private final String tbl_name; private final Db_meta_fld_list flds = Db_meta_fld_list.new_();
private final String fld_id, fld_type, fld_url, fld_ns_ids, fld_part_id, fld_guid; private boolean schema_is_1;
private final Db_conn conn; private final Db_stmt_bldr stmt_bldr = new Db_stmt_bldr();
public Xowd_xowa_db_tbl(Db_conn conn, boolean schema_is_1) {
this.conn = conn; this.schema_is_1 = schema_is_1;
this.tbl_name = "xowa_db";
fld_id = flds.Add_int_pkey ("db_id");
fld_type = flds.Add_byte ("db_type");
fld_url = flds.Add_str ("db_url", 512);
if (schema_is_1) {
fld_ns_ids = fld_part_id = fld_guid = Db_meta_fld.Key_null;
}
else {
fld_ns_ids = flds.Add_str ("db_ns_ids", 255);
fld_part_id = flds.Add_int ("db_part_id");
fld_guid = flds.Add_str ("db_guid", 36);
}
stmt_bldr.Conn_(conn, tbl_name, flds, fld_id);
}
public void Create_tbl() {conn.Ddl_create_tbl(Db_meta_tbl.new_(tbl_name, flds));}
public Xowd_db_file[] Select_all(Xowd_core_db_props props, Io_url wiki_root_dir) {
List_adp list = List_adp_.new_();
Db_rdr rdr = conn.Stmt_select(tbl_name, flds).Exec_select__rls_auto();
try {
while (rdr.Move_next()) {
String ns_ids = ""; int part_id = -1; Guid_adp guid = Guid_adp_.Empty;
if (!schema_is_1) {
ns_ids = rdr.Read_str(fld_ns_ids);
part_id = rdr.Read_int(fld_part_id);
guid = Guid_adp_.parse_(rdr.Read_str(fld_guid));
}
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);
return (Xowd_db_file[])list.To_ary(Xowd_db_file.class);
}
public void Commit_all(Xowd_db_mgr core_data_mgr) {
stmt_bldr.Batch_bgn();
try {
int len = core_data_mgr.Dbs__len();
for (int i = 0; i < len; i++)
Commit_itm(core_data_mgr.Dbs__get_at(i));
} finally {stmt_bldr.Batch_end();}
}
private void Commit_itm(Xowd_db_file itm) {
Db_stmt stmt = stmt_bldr.Get(itm.Cmd_mode());
switch (itm.Cmd_mode()) {
case Db_cmd_mode.Tid_create: stmt.Clear().Val_int(fld_id, itm.Id()); Commit_itm_vals(stmt, itm); stmt.Exec_insert(); break;
case Db_cmd_mode.Tid_update: stmt.Clear(); Commit_itm_vals(stmt, itm); stmt.Crt_int(fld_id, itm.Id()).Exec_update(); break;
case Db_cmd_mode.Tid_delete: stmt.Clear().Crt_int(fld_id, itm.Id()).Exec_delete(); break;
case Db_cmd_mode.Tid_ignore: break;
default: throw Exc_.new_unhandled(itm.Cmd_mode());
}
itm.Cmd_mode_(Db_cmd_mode.Tid_ignore);
}
private void Commit_itm_vals(Db_stmt stmt, Xowd_db_file itm) {
stmt.Val_byte(fld_type, itm.Tid()).Val_str(fld_url, itm.Url_rel()).Val_str(fld_ns_ids, itm.Ns_ids()).Val_int(fld_part_id, itm.Part_id()).Val_str(fld_guid, itm.Guid().XtoStr());
}
}
class Xowd_db_file_sorter__id implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {
Xowd_db_file lhs = (Xowd_db_file)lhsObj;
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() {}
}

View 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.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
public class Xow_domain_abrv_xo_ {
public static byte[] To_bry(byte[] domain_bry, Xol_lang_itm lang, Xow_domain_type type) { // en.wikipedia.org -> en.w
byte[] type_abrv = type.Abrv();
if (type.Multi_lang()) // wikipedia,wiktionary,etc..
return Bry_.Add(lang.Key(), Byte_ascii.Dot_bry, type_abrv);
else if (type_abrv.length > 0) // commons,wbase,species,etc..
return type_abrv;
else // home;wikia;others
return domain_bry;
}
public static Xow_domain 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;
int dot_pos = Bry_finder.Find_fwd(src, Byte_ascii.Dot);
if (dot_pos != Bry_finder.Not_found) { // dot found; EX: "en.w"
type = Xow_domain_type_.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);
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);
if (type != null) { // type found; EX: "c"
domain_bry = type.Domain_bry();
}
}
return Xow_domain_.parse(domain_bry); // for consolidation's sake, parse abrv to domain_bry and pass to Xow_domain_.parse_()
}
}

View 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.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_domain_abrv_xo__tst {
@Before public void init() {fxt.Clear();} private final Xow_domain_abrv_xo__fxt fxt = new Xow_domain_abrv_xo__fxt();
@Test public void Basic() {
fxt.Test("en.wikipedia.org" , "en.w"); // multi.enwiki
fxt.Test("fr.wiktionary.org" , "fr.d"); // multi.frwiktionary
fxt.Test("commons.wikimedia.org" , "c"); // important.unique.commons
fxt.Test("www.wikidata.org" , "wd"); // important.unique.wikidata
fxt.Test("home" , "home"); // important.unique.xowa
fxt.Test("meta.wikimedia.org" , "meta"); // wikimedia.unique
fxt.Test("pl.wikimedia.org" , "pl.m"); // wikimedia.multi
fxt.Test("a.b.c" , "a.b.c"); // unkonwn
}
}
class Xow_domain_abrv_xo__fxt {
public void Clear() {}
public void Test(String domain_str, String expd_abrv) {
Xow_domain domain = Xow_domain_.parse(Bry_.new_u8(domain_str));
byte[] actl_abrv = Xow_domain_abrv_xo_.To_bry(domain.Domain_bry(), domain.Lang_itm(), domain.Domain_type());
Tfds.Eq(expd_abrv, String_.new_u8(actl_abrv), "To_bry");
domain = Xow_domain_abrv_xo_.To_itm(actl_abrv);
Tfds.Eq(domain_str, domain.Domain_str(), "To_itm");
}
}

View 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.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
public class Xow_domain_uid_ {
public static final int
Tid_null = 0
, Tid_xowa = 1
, Tid_commons = 2
, Tid_wikidata = 3
, Tid_mediawiki = 20
, Tid_meta = 21
, Tid_incubator = 22
, Tid_wmfblog = 23
, Tid_species = 24
;
private static final int
Tid_sub_wikipedia = 0
, Tid_sub_wiktionary = 1
, Tid_sub_wikisource = 2
, Tid_sub_wikivoyage = 3
, Tid_sub_wikiquote = 4
, Tid_sub_wikibooks = 5
, Tid_sub_wikiversity = 6
, Tid_sub_wikinews = 7
, Tid_sub_wikimedia = 8
;
private static final int Const_system_reserved = 100, Const_lang_reserved = 20;
public static int To_int(Xow_domain domain) {
int domain_tid = 0;
switch (domain.Domain_tid()) {
case Xow_domain_type_.Tid_home: return Tid_xowa;
case Xow_domain_type_.Tid_commons: return Tid_commons;
case Xow_domain_type_.Tid_wikidata: return Tid_wikidata;
case Xow_domain_type_.Tid_mediawiki: return Tid_mediawiki;
case Xow_domain_type_.Tid_meta: return Tid_meta;
case Xow_domain_type_.Tid_incubator: return Tid_incubator;
case Xow_domain_type_.Tid_wmfblog: return Tid_wmfblog;
case Xow_domain_type_.Tid_species: return Tid_species;
case Xow_domain_type_.Tid_wikipedia: domain_tid = Tid_sub_wikipedia; break;
case Xow_domain_type_.Tid_wiktionary: domain_tid = Tid_sub_wiktionary; break;
case Xow_domain_type_.Tid_wikisource: domain_tid = Tid_sub_wikisource; break;
case Xow_domain_type_.Tid_wikivoyage: domain_tid = Tid_sub_wikivoyage; break;
case Xow_domain_type_.Tid_wikiquote: domain_tid = Tid_sub_wikiquote; break;
case Xow_domain_type_.Tid_wikibooks: domain_tid = Tid_sub_wikibooks; break;
case Xow_domain_type_.Tid_wikiversity: domain_tid = Tid_sub_wikiversity; break;
case Xow_domain_type_.Tid_wikinews: domain_tid = Tid_sub_wikinews; break;
case Xow_domain_type_.Tid_wikimedia: domain_tid = Tid_sub_wikimedia; break;
default: throw Exc_.new_unhandled(domain.Domain_tid());
}
return Const_system_reserved // reserve first 100 slots
+ domain_tid // domain_tid assigned above
+ (domain.Lang_uid() * Const_lang_reserved) // reserve 20 wikis per lang
;
}
public static Xow_domain To_domain(int tid) {
switch (tid) {
case Tid_xowa: return Xow_domain.new_(Xow_domain_.Domain_bry_home, Xow_domain_type_.Tid_home, Xol_lang_itm_.Key__unknown);
case Tid_commons: return Xow_domain.new_(Xow_domain_.Domain_bry_commons, Xow_domain_type_.Tid_commons, Xol_lang_itm_.Key__unknown);
case Tid_wikidata: return Xow_domain.new_(Xow_domain_.Domain_bry_wikidata, Xow_domain_type_.Tid_commons, Xol_lang_itm_.Key__unknown);
case Tid_mediawiki: return Xow_domain.new_(Xow_domain_.Domain_bry_mediawiki, Xow_domain_type_.Tid_mediawiki, Xol_lang_itm_.Key__unknown);
case Tid_meta: return Xow_domain.new_(Xow_domain_.Domain_bry_meta, Xow_domain_type_.Tid_meta, Xol_lang_itm_.Key__unknown);
case Tid_incubator: return Xow_domain.new_(Xow_domain_.Domain_bry_incubator, Xow_domain_type_.Tid_incubator, Xol_lang_itm_.Key__unknown);
case Tid_wmfblog: return Xow_domain.new_(Xow_domain_.Domain_bry_wmforg, Xow_domain_type_.Tid_wmfblog, Xol_lang_itm_.Key__unknown);
case Tid_species: return Xow_domain.new_(Xow_domain_.Domain_bry_species, Xow_domain_type_.Tid_species, Xol_lang_itm_.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_.Tid_wikipedia; tid_bry = Xow_domain_type_.Key_bry_wikipedia; break;
case Tid_sub_wiktionary: tid_int = Xow_domain_type_.Tid_wiktionary; tid_bry = Xow_domain_type_.Key_bry_wiktionary; break;
case Tid_sub_wikisource: tid_int = Xow_domain_type_.Tid_wikisource; tid_bry = Xow_domain_type_.Key_bry_wikisource; break;
case Tid_sub_wikivoyage: tid_int = Xow_domain_type_.Tid_wikivoyage; tid_bry = Xow_domain_type_.Key_bry_wikivoyage; break;
case Tid_sub_wikiquote: tid_int = Xow_domain_type_.Tid_wikiquote; tid_bry = Xow_domain_type_.Key_bry_wikiquote; break;
case Tid_sub_wikibooks: tid_int = Xow_domain_type_.Tid_wikibooks; tid_bry = Xow_domain_type_.Key_bry_wikibooks; break;
case Tid_sub_wikiversity: tid_int = Xow_domain_type_.Tid_wikiversity; tid_bry = Xow_domain_type_.Key_bry_wikiversity; break;
case Tid_sub_wikinews: tid_int = Xow_domain_type_.Tid_wikinews; tid_bry = Xow_domain_type_.Key_bry_wikinews; break;
case Tid_sub_wikimedia: tid_int = Xow_domain_type_.Tid_wikimedia; tid_bry = Xow_domain_type_.Key_bry_wikimedia; break;
default: throw Exc_.new_unhandled(type_id);
}
Xol_lang_itm lang = Xol_lang_itm_.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_.Seg_bry_org);
byte[] domain_bry = bfr.Xto_bry_and_clear();
bfr.Mkr_rls();
return Xow_domain.new_(domain_bry, tid_int, lang);
}
}

View File

@@ -0,0 +1,37 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.domains; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_domain_uid__tst {
@Before public void init() {fxt.Clear();} private final Xow_domain_uid__fxt fxt = new Xow_domain_uid__fxt();
@Test public void Basic() {
fxt.Test(Xow_domain_uid_.Tid_commons , "commons.wikimedia.org" , "", Xow_domain_type_.Tid_commons);
fxt.Test(100 , "en.wikipedia.org" , "en", Xow_domain_type_.Tid_wikipedia);
}
}
class Xow_domain_uid__fxt {
public void Clear() {}
public void Test(int tid, String domain_str, String expd_lang, int expd_tid) {
byte[] domain_bry = Bry_.new_a7(domain_str);
Xow_domain actl_domain = Xow_domain_uid_.To_domain(tid);
Tfds.Eq_bry(domain_bry , actl_domain.Domain_bry());
Tfds.Eq_bry(Bry_.new_a7(expd_lang) , actl_domain.Lang_key());
Tfds.Eq(expd_tid , actl_domain.Domain_tid());
Tfds.Eq(tid, Xow_domain_uid_.To_int(actl_domain));
}
}

View File

@@ -0,0 +1,22 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
import gplx.core.primitives.*;
public interface Xow_domain_crt_itm {
boolean Matches(Xow_domain cur, Xow_domain comp);
}

View File

@@ -0,0 +1,84 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
class Xow_domain_crt_itm_ {
public static final Xow_domain_crt_itm Null = null;
}
class Xow_domain_crt_itm__any_wiki implements Xow_domain_crt_itm {
public boolean Matches(Xow_domain cur, Xow_domain comp) {return true;}
public static final Xow_domain_crt_itm__any_wiki I = new Xow_domain_crt_itm__any_wiki(); Xow_domain_crt_itm__any_wiki() {}
}
class Xow_domain_crt_itm__in implements Xow_domain_crt_itm {
private final Xow_domain_crt_itm[] ary;
public Xow_domain_crt_itm__in(Xow_domain_crt_itm[] ary) {this.ary = ary;}
public boolean Matches(Xow_domain cur, Xow_domain comp) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
Xow_domain_crt_itm itm = ary[i];
if (itm.Matches(cur, comp)) return true;
}
return false;
}
}
class Xow_domain_crt_itm__any_standard implements Xow_domain_crt_itm {
public boolean Matches(Xow_domain cur, Xow_domain comp) {
switch (comp.Domain_tid()) {
case Xow_domain_type_.Tid_wikipedia:
case Xow_domain_type_.Tid_wiktionary:
case Xow_domain_type_.Tid_wikisource:
case Xow_domain_type_.Tid_wikivoyage:
case Xow_domain_type_.Tid_wikiquote:
case Xow_domain_type_.Tid_wikibooks:
case Xow_domain_type_.Tid_wikiversity:
case Xow_domain_type_.Tid_wikinews: return true;
default: return false;
}
}
public static final Xow_domain_crt_itm__any_standard I = new Xow_domain_crt_itm__any_standard(); Xow_domain_crt_itm__any_standard() {}
}
class Xow_domain_crt_itm__none implements Xow_domain_crt_itm {
public boolean Matches(Xow_domain cur, Xow_domain comp) {return false;}
public static final Xow_domain_crt_itm__none I = 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 cur, Xow_domain comp) {return Bry_.Eq(cur.Domain_bry(), comp.Domain_bry());}
public static final Xow_domain_crt_itm__self I = new Xow_domain_crt_itm__self(); Xow_domain_crt_itm__self() {}
}
class Xow_domain_crt_itm__same_lang implements Xow_domain_crt_itm {
public boolean Matches(Xow_domain cur, Xow_domain comp) {return 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() {}
}
class Xow_domain_crt_itm__same_type implements Xow_domain_crt_itm {
public boolean Matches(Xow_domain cur, Xow_domain comp) {return cur.Domain_tid() == comp.Domain_tid();}
public static final Xow_domain_crt_itm__same_type I = new Xow_domain_crt_itm__same_type(); Xow_domain_crt_itm__same_type() {}
}
class Xow_domain_crt_itm__lang implements Xow_domain_crt_itm {
private final int lang_uid;
public Xow_domain_crt_itm__lang(int lang_uid) {this.lang_uid = lang_uid;}
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Lang_orig_uid() == lang_uid;}
}
class Xow_domain_crt_itm__type implements Xow_domain_crt_itm {
private final int wiki_tid;
public Xow_domain_crt_itm__type(int wiki_tid) {this.wiki_tid = wiki_tid;}
public boolean Matches(Xow_domain cur, Xow_domain comp) {return comp.Domain_tid() == wiki_tid;}
}
class Xow_domain_crt_itm__wiki implements Xow_domain_crt_itm {
private final byte[] domain;
public Xow_domain_crt_itm__wiki(byte[] domain) {this.domain = domain;}
public boolean Matches(Xow_domain cur, Xow_domain comp) {return Bry_.Eq(comp.Domain_bry(), domain);}
}

View File

@@ -0,0 +1,91 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
import gplx.xowa.langs.*;
class Xow_domain_crt_itm_parser {
public Xow_domain_crt_kv_itm[] Parse_as_kv_itms_or_null(byte[] raw) {
List_adp rv = Parse_as_obj_or_null(raw, Bool_.N);
return rv == null ? null : (Xow_domain_crt_kv_itm[])rv.To_ary_and_clear(Xow_domain_crt_kv_itm.class);
}
public Xow_domain_crt_kv_ary[] Parse_as_kv_arys_or_null(byte[] raw) {
List_adp rv = Parse_as_obj_or_null(raw, Bool_.Y);
return rv == null ? null : (Xow_domain_crt_kv_ary[])rv.To_ary_and_clear(Xow_domain_crt_kv_ary.class);
}
public List_adp Parse_as_obj_or_null(byte[] raw, boolean is_ary) {
List_adp rv = List_adp_.new_();
byte[][] line_ary = Bry_.Split_lines(raw);
int line_len = line_ary.length;
for (int i = 0; i < line_len; ++i) {
byte[] line = line_ary[i];
if (line.length == 0) continue; // ignore blank lines
byte[][] word_ary = Bry_.Split(line, Byte_ascii.Pipe);
int word_len = word_ary.length;
if (word_len != 2) return null; // not A|B; exit now;
Xow_domain_crt_itm key_itm = Xow_domain_crt_itm_parser.I.Parse_as_in(word_ary[0]);
if (key_itm == Xow_domain_crt_itm_.Null) 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]);
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]);
if (val_itm == Xow_domain_crt_itm_.Null) return null; // invalid val; exit;
rv.Add(new Xow_domain_crt_kv_itm(key_itm, val_itm));
}
}
return rv;
}
public Xow_domain_crt_itm Parse_as_in(byte[] raw) {
Xow_domain_crt_itm[] in_ary = Parse_as_ary(raw);
return in_ary == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__in(in_ary);
}
public Xow_domain_crt_itm[] Parse_as_ary(byte[] raw) {
byte[][] terms = Bry_.Split(raw, Byte_ascii.Comma, Bool_.Y);
int len = terms.length;
Xow_domain_crt_itm[] rv_ary = new Xow_domain_crt_itm[len];
for (int i = 0; i < len; ++i) {
Xow_domain_crt_itm itm = Parse_itm(terms[i]);
if (itm == Xow_domain_crt_itm_.Null) return null; // invalid val; exit;
rv_ary[i] = itm;
}
return rv_ary;
}
public Xow_domain_crt_itm Parse_itm(byte[] raw) {
Xow_domain_crt_itm rv = (Xow_domain_crt_itm)itm_hash.Get_by_bry(raw); if (rv != null) return rv; // singleton; EX: <self>, <same_type>, etc..
int raw_len = raw.length;
if (Bry_.Has_at_bgn(raw, Wild_lang)) { // EX: *.wikipedia
int wiki_tid = Xow_domain_type_.Get_type_as_tid(raw, Wild_lang.length, raw_len);
return wiki_tid == Xow_domain_type_.Tid_null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__type(wiki_tid);
}
else if (Bry_.Has_at_end(raw, Wild_type)) { // EX: en.*
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(raw, 0, raw_len - Wild_type.length);
return lang_itm == null ? Xow_domain_crt_itm_.Null : new Xow_domain_crt_itm__lang(lang_itm.Id());
}
else
return new Xow_domain_crt_itm__wiki(raw); // EX: en.wikipedia.org
}
private static final Hash_adp_bry itm_hash = Hash_adp_bry.cs_()
.Add_str_obj("<self>" , Xow_domain_crt_itm__self.I)
.Add_str_obj("<same_type>" , Xow_domain_crt_itm__same_type.I)
.Add_str_obj("<same_lang>" , Xow_domain_crt_itm__same_lang.I)
.Add_str_obj("<any>" , Xow_domain_crt_itm__any_wiki.I)
;
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() {}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.domains.crts; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*;
public class Xow_domain_crt_kv_itm_mgr {
private final List_adp list = List_adp_.new_();
public void Clear() {list.Clear();}
@gplx.Internal protected void Add(Xow_domain_crt_kv_itm itm) {list.Add(itm);}
public boolean Parse_as_itms(byte[] raw) {
this.Clear();
Xow_domain_crt_kv_itm[] ary = Xow_domain_crt_itm_parser.I.Parse_as_kv_itms_or_null(raw);
if (ary == null) return false; // invalid parse; leave current value as is and exit;
int len = ary.length;
for (int i = 0; i < len; ++i)
this.Add(ary[i]);
return true;
}
public boolean Parse_as_arys(byte[] raw) {
this.Clear();
Xow_domain_crt_kv_ary[] ary = Xow_domain_crt_itm_parser.I.Parse_as_kv_arys_or_null(raw);
if (ary == null) return false; // invalid parse; leave current value as is and exit;
int len = ary.length;
for (int i = 0; i < len; ++i)
list.Add(ary[i]);
return true;
}
public Xow_domain_crt_itm Find_itm(Xow_domain cur, Xow_domain comp) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Xow_domain_crt_kv_itm kv = (Xow_domain_crt_kv_itm)list.Get_at(i);
if (kv.Key().Matches(cur, comp)) return kv.Val();
}
return Xow_domain_crt_itm__none.I;
}
public Xow_domain_crt_itm[] Find_ary(Xow_domain cur, Xow_domain comp) {
int len = list.Count();
for (int i = 0; i < len; ++i) {
Xow_domain_crt_kv_ary kv = (Xow_domain_crt_kv_ary)list.Get_at(i);
if (kv.Key().Matches(cur, comp)) return kv.Val();
}
return null;
}
}
class Xow_domain_crt_kv_itm {
public Xow_domain_crt_kv_itm(Xow_domain_crt_itm key, Xow_domain_crt_itm val) {this.key = key; this.val = val;}
public Xow_domain_crt_itm Key() {return key;} private final Xow_domain_crt_itm key;
public Xow_domain_crt_itm Val() {return val;} private final Xow_domain_crt_itm val;
}
class Xow_domain_crt_kv_ary {
public Xow_domain_crt_kv_ary(Xow_domain_crt_itm key, Xow_domain_crt_itm[] val) {this.key = key; this.val = val;}
public Xow_domain_crt_itm Key() {return key;} private final Xow_domain_crt_itm key;
public Xow_domain_crt_itm[] Val() {return val;} private final Xow_domain_crt_itm[] val;
}

View 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.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_module_base implements GfoInvkAble {
public byte Enabled() {return enabled;} private byte enabled = Bool_.__byte;
public boolean Enabled_y() {return enabled == Bool_.Y_byte;}
public boolean Enabled_n() {return enabled == Bool_.N_byte;}
@gplx.Virtual public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_enabled)) return Yn.Xto_nullable_str(enabled);
else if (ctx.Match(k, Invk_enabled_)) enabled = Yn.Xto_nullable_byte(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String Invk_enabled = "enabled", Invk_enabled_ = "enabled_";
}

View 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.modules; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.html.modules.*; import gplx.xowa.html.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) {
this.popup_mgr = new Xow_popup_mgr(wiki);
regy.Add_bry_obj(Xoh_module_itm_.Key_top_icon , itm__top_icon);
regy.Add_bry_obj(Xoh_module_itm_.Key_navframe , itm__navframe);
regy.Add_bry_obj(Xoh_module_itm_.Key_title_rewrite , itm__title_rewrite);
}
public void Init_by_wiki(Xowe_wiki wiki) {
popup_mgr.Init_by_wiki(wiki);
}
public Xow_module_base Itm__top_icon() {return itm__top_icon;} private Xow_module_base itm__top_icon = new Xow_module_base();
public Xow_module_base Itm__navframe() {return itm__navframe;} private Xow_module_base itm__navframe = new Xow_module_base();
public Xow_module_base Itm__title_rewrite() {return itm__title_rewrite;} private Xow_module_base itm__title_rewrite = new Xow_module_base();
public Xow_popup_mgr Popup_mgr() {return popup_mgr;} private Xow_popup_mgr popup_mgr;
public Xow_module_base Get(byte[] key) {return (Xow_module_base)regy.Get_by_bry(key);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Get(m.ReadBry("v"));
else return GfoInvkAble_.Rv_unhandled;
} private static final String Invk_get = "get";
}

View 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__anchor_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Anch_y() {fxt.Init_ttl("a#b") .Expd_full_txt("A").Expd_page_txt("A").Expd_anch_txt("b").Test();}
@Test public void Anch_only() {fxt.Init_ttl("#a") .Expd_full_txt("").Expd_page_txt("").Expd_anch_txt("a").Test();}
@Test public void Anchor_fails() { // PURPOSE: :#batch:Main Page causes ttl to fail b/c # is treated as anchor; DATE:2013-01-02
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_a7("#batch"), Bry_.new_a7("none"));
fxt.Init_ttl(":#batch:Main Page").Expd_full_txt("Main Page").Test();
}
@Test public void Anchor_angles() {// PURPOSE: angles in anchor should be encoded; DATE: 2013-01-23
fxt.Init_ttl("A#b<c>d").Expd_full_txt("A").Expd_anch_txt("b.3Cc.3Ed").Test();
}
@Test public void Anchor_arg_in_non_main_ns() {
fxt.Init_ttl("Help:A#B").Expd_full_txt("Help:A").Expd_anch_txt("B").Test();
}
@Test public void Anchor_and_slash() { // PURPOSE: slash in anchor was being treated as a subpage; DATE:2014-01-14
fxt.Init_ttl("A#b/c").Expd_full_txt("A").Expd_anch_txt("b/c").Expd_leaf_txt("A").Test(); // NOTE: Leaf_txt should be Page_txt; used to fail
}
@Test public void Decode_ncr() { // PURPOSE: convert &#x23; to #; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
fxt.Init_ttl("A&#x23;b").Expd_full_txt("A").Expd_page_txt("A").Expd_anch_txt("b").Test();
fxt.Init_ttl("A&#35;b").Expd_full_txt("A").Expd_page_txt("A").Expd_anch_txt("b").Test();
fxt.Init_ttl("A&#36;b").Expd_full_txt("A$b").Expd_page_txt("A$b").Expd_anch_txt("").Test();
}
}

View 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__basic_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Ns() {fxt.Init_ttl("Help:Test") .Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Test();}
@Test public void Ns_false() {fxt.Init_ttl("Helpx:Test") .Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Helpx:Test").Test();}
@Test public void Ns_multiple() {fxt.Init_ttl("Help:Talk:test") .Expd_page_txt("Talk:test").Test();}
@Test public void Full_txt() {fxt.Init_ttl("Help:a & b") .Expd_full_txt("Help:A & b").Test();} // preserve
@Test public void Full_url() {fxt.Init_ttl("Help:a & b") .Expd_full_url("Help:A_%26_b").Test();} // escape
@Test public void Page_txt() {fxt.Init_ttl("a & b") .Expd_page_txt("A & b").Test();} // preserve;
@Test public void Page_txt_underline() {fxt.Init_ttl("a_b") .Expd_page_txt("A b").Expd_page_url("A_b").Test();} // NOTE: raw is "a_b" but txt is "a b"
@Test public void Page_url() {fxt.Init_ttl("a & b") .Expd_page_url("A_%26_b").Test();} // escape
@Test public void Page_url_w_ns() {fxt.Init_ttl("Help:a & b") .Expd_page_url("A_%26_b").Test();} // remove ns
@Test public void Page_url_symbols() {fxt.Init_ttl(";:@&=$ -_.+!*'(),/").Expd_page_url(";:@%26%3D$_-_.%2B!*%27(),/").Test();}// symbols + space
@Test public void Leaf_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_leaf_txt("leaf").Test();}
@Test public void Leaf_txt_slash_is_last() {fxt.Init_ttl("root/mid/leaf/") .Expd_leaf_txt("").Test();}
@Test public void Leaf_txt_no_slash() {fxt.Init_ttl("root") .Expd_leaf_txt("Root").Test();}
@Test public void Leaf_url() {fxt.Init_ttl("root/mid/a & b") .Expd_leaf_url("a_%26_b").Test();} // NOTE: a not capitalized ("root" would be)
@Test public void Base_txt() {fxt.Init_ttl("a & b/mid/leaf") .Expd_base_txt("A & b/mid").Test();}
@Test public void Base_url() {fxt.Init_ttl("a & b/mid/leaf") .Expd_base_url("A_%26_b/mid").Test();}
@Test public void Root_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_root_txt("Root").Test();}
@Test public void Rest_txt() {fxt.Init_ttl("root/mid/leaf") .Expd_rest_txt("mid/leaf").Test();}
@Test public void Talk_txt() {fxt.Init_ttl("Help:test") .Expd_talk_txt("Help talk:Test").Test();}
@Test public void Talk_txt_identity() {fxt.Init_ttl("Help talk:test") .Expd_talk_txt("Help talk:Test").Test();}
@Test public void Talk_url() {fxt.Init_ttl("Help:a & b") .Expd_talk_url("Help_talk:A_%26_b").Test();}
@Test public void Talk_txt_main() {fxt.Init_ttl("test") .Expd_talk_txt("Talk:Test").Test();}
@Test public void Subj_txt() {fxt.Init_ttl("Help talk:test") .Expd_subj_txt("Help:Test").Test();}
@Test public void Subj_txt_identity() {fxt.Init_ttl("Help:test") .Expd_subj_txt("Help:Test").Test();}
@Test public void Subj_url() {fxt.Init_ttl("Help talk:a & b").Expd_subj_url("Help:A_%26_b").Test();}
@Test public void Subj_txt_main() {fxt.Init_ttl("Talk:test") .Expd_subj_txt("Test").Test();}
@Test public void Force_literal_link_y() {fxt.Init_ttl(":Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();}
@Test public void Force_literal_link_n() {fxt.Init_ttl( "Help:test") .Expd_force_literal_link(0).Expd_page_txt("Test").Test();}
@Test public void Force_literal_link_y_2() {fxt.Init_ttl("::Help:test") .Expd_force_literal_link(1).Expd_page_txt("Test").Test();} // PURPOSE: 2nd initial colon should be ignored; EX:mw:MediaWiki; [[::MediaWiki]]; DATE:2013-12-14
@Test public void All_page() {fxt.Init_ttl("test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();}
@Test public void All_ns() {fxt.Init_ttl("Help:test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_help).Expd_page_txt("Test").Expd_leaf_txt("Test").Expd_anch_txt("").Test();}
@Test public void Special() {fxt.Init_ttl("Special:Random").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Random").Test();}
@Test public void Special_xowa() {fxt.Init_ttl("Special:xowa/Search/Ttl").Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt("Xowa/Search/Ttl").Test();}
@Test public void Comment() {fxt.Init_ttl("Ab<!--b-->").Expd_page_txt("Ab").Test();}
@Test public void Comment_eos() {fxt.Init_ttl("Ab<!--b--").Expd_page_txt(null).Test();}
@Test public void Ns_case() {// PURPOSE: lowercase ns should be converted to proper case; EX: fr.w:Project:Sandbox (redirect link); en.w:Periclimenes imperator; [[commons:category:Periclimenes imperator|''Periclimenes imperator'']]; DATE: 2013-01-27
fxt.Init_ttl("help:A").Expd_full_txt("Help:A").Test();
fxt.Init_ttl("help talk:A").Expd_full_txt("Help talk:A").Test();
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__err_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Invalid() {fxt.Init_ttl("<!--A").Expd_err(Xop_ttl_log.Comment_eos).Test();}
@Test public void Invalid_brace() {fxt.Init_ttl("[[a]]").Expd_err(Xop_ttl_log.Invalid_char).Test();}
@Test public void Invalid_curly() {fxt.Init_ttl("{{a}}").Expd_err(Xop_ttl_log.Invalid_char).Test();}
@Test public void Len_0() {
fxt.Init_ttl("").Expd_err(Xop_ttl_log.Len_0).Test();
fxt.Init_ttl(" ").Expd_err(Xop_ttl_log.Len_0).Test();
fxt.Init_ttl("_").Expd_err(Xop_ttl_log.Len_0).Test();
fxt.Init_ttl("_ _").Expd_err(Xop_ttl_log.Len_0).Test();
}
@Test public void Len_max() {
fxt.Init_ttl(String_.Repeat("A", 512)).Expd_page_txt(String_.Repeat("A", 512)).Test();
// fxt.Init_ttl("File:" + String_.Repeat("A", 255)).Expd_page_txt(String_.Repeat("A", 255)).Test(); // DELETE: removing multi-byte check; DATE:2013-02-02
// fxt.Init_ttl(String_.Repeat("A", 256)).Expd_err(Xop_ttl_log.Len_max).Test();
// fxt.Init_ttl("Special:" + String_.Repeat("A", 255)).Expd_ns_id(Xow_ns_.Id_special).Expd_page_txt(String_.Repeat("A", 255)).Test();
// fxt.Init_ttl("Special:" + String_.Repeat("A", 512 + 8)).Expd_err(Xop_ttl_log.Len_max).Test(); // 8="Special:".length
}
@Test public void Colon_is_last_ns() {fxt.Init_ttl("Help:").Expd_err(Xop_ttl_log.Ttl_is_ns_only).Test();}
}

View 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__html_entity_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Eacute() {fxt.Init_ttl("&eacute;").Expd_page_txt("é").Test();} //É
@Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();}
@Test public void Ncr_dec() {fxt.Init_ttl("A&#98;").Expd_page_txt("Ab").Test();}
@Test public void Ncr_hex() {fxt.Init_ttl("A&#x62;").Expd_page_txt("Ab").Test();}
@Test public void Nbsp() {fxt.Init_ttl("A&nbsp;b").Expd_page_txt("A b").Test();} // NOTE: &nbsp must convert to space; EX:w:United States [[Image:Dust Bowl&nbsp;- Dallas, South Dakota 1936.jpg|220px|alt=]]
@Test public void Amp() {fxt.Init_ttl("A&amp;b").Expd_page_txt("A&b").Test();} // PURPOSE: A&amp;B -> A&B; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23
}

View File

@@ -0,0 +1,43 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
import gplx.xowa.langs.cases.*;
public class Xow_ttl__i18n_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Bidi() {
fxt.Init_ttl("A" + String_.new_u8(Bry_.ints_(226, 128, 142)) + "B").Expd_page_txt("AB").Test();
fxt.Init_ttl("A" + String_.new_u8(Bry_.ints_(226, 128, 97)) + "B").Expd_page_txt("A" + String_.new_u8(Bry_.ints_(226, 128, 97)) + "B").Test();
}
@Test public void Multi_byte_char2() { // PURPOSE: multi-byte HTML entity causes array out of index error; EX: w:List_of_Unicode_characters; DATE:2013-12-25
fxt.Init_ttl("&#x2c65;").Expd_full_txt("").Test();
}
@Test public void First_char_is_multi_byte() { // PURPOSE: if multi-byte, uppercasing is complicated; EX: µ -> Μ; DATE:2013-11-27
fxt.Wiki().Lang().Case_mgr_utf8_();
fxt.Init_ttl("µ").Expd_full_txt("Μ").Test(); // NOTE: this is not an ASCII "Μ"
fxt.Init_ttl("µab").Expd_full_txt("Μab").Test(); // check that rest of title works fine
fxt.Init_ttl("Help:µab").Expd_full_txt("Help:Μab").Test(); // check ns
fxt.Init_ttl("Ι").Expd_full_txt("Ι").Test(); // check that Ι is not upper-cased to COMBINING GREEK YPOGEGRAMMENI; DATE:2014-02-24
}
@Test public void First_char_is_multi_byte_assymetrical() { // PURPOSE: test multi-byte asymmetry (lc is 3 bytes; uc is 2 bytes)
fxt.Wiki().Lang().Case_mgr_utf8_();
fxt.Init_ttl("").Expd_full_txt("Ⱥ").Test();
fxt.Init_ttl("ⱥab").Expd_full_txt("Ⱥab").Test(); // check that rest of title works fine
fxt.Init_ttl("Help:ⱥab").Expd_full_txt("Help:Ⱥab").Test(); // check ns
}
}

View File

@@ -0,0 +1,31 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__qarg_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Base_txt_wo_qarg() {
fxt.Init_ttl("Special:Search/A?b=c").Expd_base_txt_wo_qarg("Search").Expd_qarg_txt("b=c").Test();
}
@Test public void Leaf_txt_wo_qarg() {
fxt.Init_ttl("Special:Search/A?b=c").Expd_leaf_txt_wo_qarg("A").Expd_qarg_txt("b=c").Test();
}
@Test public void Ttl_has_question_mark() { // PURPOSE: handle titles that have both question mark and leaf; PAGE:en.w:Portal:Organized_Labour/Did_You_Know?/1 DATE:2014-06-08
fxt.Init_ttl("A/B?/1").Expd_page_txt("A/B?/1").Expd_base_txt("A/B?").Expd_leaf_txt("1").Expd_leaf_txt_wo_qarg("1").Expd_qarg_txt(null).Test();
}
}

View 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__ws_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Space() {fxt.Init_ttl(" a b ") .Expd_page_url("A_b").Expd_page_txt("A b").Test();}
@Test public void Space_w_ns() {fxt.Init_ttl(" Help : a b ") .Expd_page_url("A_b").Expd_page_txt("A b").Test();}
@Test public void Nl() {fxt.Init_ttl("\n\na\n\n") .Expd_page_txt("A").Test();}
@Test public void Nl_end() {fxt.Init_ttl("a\nb") .Expd_page_txt("A b").Test();}
@Test public void Tab() {fxt.Init_ttl("\ta\t") .Expd_page_txt("A").Test();}
@Test public void Nbsp() {fxt.Init_ttl("A&nbsp;bc") .Expd_page_url("A_bc").Expd_page_txt("A bc").Test();} // PURPOSE:convert "&nbsp;" to " "; DATE:2014-09-25
@Test public void Nbsp_mix() {fxt.Init_ttl("A &nbsp; bc") .Expd_page_url("A_bc").Expd_page_txt("A bc").Test();} // PURPOSE:convert multiple "&nbsp;" to " "; PAGE:en.w:Greek_government-debt_crisis; DATE:2014-09-25
}

View 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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_ttl__xwik_tst {
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
@Test public void Known() {fxt.Init_ttl("fr:a") .Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("a").Test();}
@Test public void Known_ns() {fxt.Init_ttl("fr:Help:a") .Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_full_txt("Help:a").Expd_page_txt("Help:a").Test();} // NOTE: Page is "Help:a" b/c ns are unknowable in foreign wiki
@Test public void Unknown() {fxt.Init_ttl("frx:a") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Frx:a").Test();}
@Test public void Unknown_ns() {fxt.Init_ttl("frx:Help:a") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Frx:Help:a").Test();}
@Test public void Known_ns_leaf_anch() {fxt.Init_ttl("fr:Help:a/b/c#d").Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Id_main).Expd_page_txt("Help:a/b/c").Expd_leaf_txt("c").Expd_anch_txt("d").Expd_full_txt("Help:a/b/c").Test();}
@Test public void Colon_is_last() {
fxt.Init_ttl("fr:Help:").Expd_xwik_txt("fr").Expd_page_txt("Help:").Test();
fxt.Init_ttl("fr:_ _").Expd_xwik_txt("fr").Expd_page_txt("").Test(); // NOTE: fr:_ _ is invalid (resolves to "fr:");
fxt.Init_ttl("fr:Help:_ _").Expd_xwik_txt("fr").Expd_page_txt("Help:").Test();
}
@Test public void Colon_multiple() {
fxt.Init_ttl("fr::Help:Test").Expd_xwik_txt("fr").Expd_page_txt(":Help:Test").Test();
fxt.Init_ttl("fr::Test").Expd_xwik_txt("fr").Expd_page_txt(":Test").Test();
fxt.Init_ttl(":fr:Test").Expd_xwik_txt("fr").Expd_page_txt("Test").Expd_force_literal_link(1).Test();
fxt.Init_ttl(":::fr:Test").Expd_xwik_txt("").Expd_page_txt(":fr:Test").Expd_force_literal_link(1).Test();
}
@Test public void Ns_should_precede_xwiki() {// PURPOSE: the "Wikipedia" in "Wikipedia:Main page" should be interpreted as namespace, not an alias
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_a7("Wikipedia"), Bry_.new_a7("en.wikipedia.org"));
fxt.Init_ttl("Wikipedia:Test").Expd_xwik_txt("").Expd_full_txt("Wikipedia:Test").Test();
}
}

View File

@@ -0,0 +1,86 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
class Xow_ttl_fxt {
private Xop_fxt fxt = new Xop_fxt();
public Xow_ttl_fxt Init_ttl(String raw) {test_raw = raw; return this;} private String test_raw = "";
public Xow_ttl_fxt Expd_ns_id(int v) {expd_ns_id = v; return this;} private int expd_ns_id = Int_.MinValue;
public Xow_ttl_fxt Expd_page_txt(String v) {expd_page_txt = v; return this;} private String expd_page_txt;
public Xow_ttl_fxt Expd_page_url(String v) {expd_page_url = v; return this;} private String expd_page_url;
public Xow_ttl_fxt Expd_full_txt(String v) {expd_full_txt = v; return this;} private String expd_full_txt;
public Xow_ttl_fxt Expd_full_url(String v) {expd_full_url = v; return this;} private String expd_full_url;
public Xow_ttl_fxt Expd_leaf_txt(String v) {expd_leaf_txt = v; return this;} private String expd_leaf_txt;
public Xow_ttl_fxt Expd_leaf_url(String v) {expd_leaf_url = v; return this;} private String expd_leaf_url;
public Xow_ttl_fxt Expd_base_txt(String v) {expd_base_txt = v; return this;} private String expd_base_txt;
public Xow_ttl_fxt Expd_base_url(String v) {expd_base_url = v; return this;} private String expd_base_url;
public Xow_ttl_fxt Expd_root_txt(String v) {expd_root_txt = v; return this;} private String expd_root_txt;
public Xow_ttl_fxt Expd_rest_txt(String v) {expd_rest_txt = v; return this;} private String expd_rest_txt;
public Xow_ttl_fxt Expd_talk_txt(String v) {expd_talk_txt = v; return this;} private String expd_talk_txt;
public Xow_ttl_fxt Expd_talk_url(String v) {expd_talk_url = v; return this;} private String expd_talk_url;
public Xow_ttl_fxt Expd_subj_txt(String v) {expd_subj_txt = v; return this;} private String expd_subj_txt;
public Xow_ttl_fxt Expd_subj_url(String v) {expd_subj_url = v; return this;} private String expd_subj_url;
public Xow_ttl_fxt Expd_qarg_txt(String v) {expd_qarg_txt = v; return this;} private String expd_qarg_txt;
public Xow_ttl_fxt Expd_xwik_txt(String v) {expd_xwik_txt = v; return this;} private String expd_xwik_txt;
public Xow_ttl_fxt Expd_anch_txt(String v) {expd_anch_txt = v; return this;} private String expd_anch_txt;
public Xow_ttl_fxt Expd_base_txt_wo_qarg(String v) {expd_base_txt_wo_qarg = v; return this;} private String expd_base_txt_wo_qarg;
public Xow_ttl_fxt Expd_leaf_txt_wo_qarg(String v) {expd_leaf_txt_wo_qarg = v; return this;} private String expd_leaf_txt_wo_qarg;
public Xow_ttl_fxt Expd_force_literal_link(int v) {expd_force_literal_link = v; return this;} private int expd_force_literal_link = -1;
public Xow_ttl_fxt Expd_err(Gfo_msg_itm v) {expd_err = v; return this;} private Gfo_msg_itm expd_err;
public Xowe_wiki Wiki() {return fxt.Wiki();}
public void Reset() {
fxt.Reset();
fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_u8("fr"), Bry_.new_u8("fr.wikipedia.org"));
test_raw = "Test page";
expd_ns_id = Int_.MinValue;
expd_xwik_txt = expd_full_txt = expd_full_url = expd_page_txt = expd_page_url = expd_leaf_txt = expd_leaf_url = expd_base_txt = expd_base_url
= expd_root_txt = expd_rest_txt = expd_talk_txt = expd_talk_url = expd_subj_txt = expd_subj_url = expd_anch_txt
= expd_base_txt_wo_qarg = expd_leaf_txt_wo_qarg = expd_qarg_txt = null;
expd_err = null;
expd_force_literal_link = -1;
fxt.Log_clear();
}
public void Test() {
Xoa_ttl actl = Xoa_ttl.parse_(fxt.Wiki(), Bry_.new_u8(test_raw));
if (expd_err == null) {
if (expd_ns_id != Int_.MinValue) Tfds.Eq(expd_ns_id, actl.Ns().Id(), "ns");
if (expd_xwik_txt != null) Tfds.Eq(expd_xwik_txt, String_.new_u8(actl.Wik_txt()), "Wiki");
if (expd_page_txt != null) Tfds.Eq(expd_page_txt, String_.new_u8(actl.Page_txt()), "Page_txt");
if (expd_page_url != null) Tfds.Eq(expd_page_url, String_.new_u8(actl.Page_url()), "Page_url");
if (expd_full_txt != null) Tfds.Eq(expd_full_txt, String_.new_u8(actl.Full_txt()), "Full_txt");
if (expd_full_url != null) Tfds.Eq(expd_full_url, String_.new_u8(actl.Full_url()), "Full_url");
if (expd_leaf_txt != null) Tfds.Eq(expd_leaf_txt, String_.new_u8(actl.Leaf_txt()), "Leaf_txt");
if (expd_leaf_url != null) Tfds.Eq(expd_leaf_url, String_.new_u8(actl.Leaf_url()), "Leaf_url");
if (expd_base_txt != null) Tfds.Eq(expd_base_txt, String_.new_u8(actl.Base_txt()), "Base_txt");
if (expd_base_url != null) Tfds.Eq(expd_base_url, String_.new_u8(actl.Base_url()), "Base_url");
if (expd_root_txt != null) Tfds.Eq(expd_root_txt, String_.new_u8(actl.Root_txt()), "Root_txt");
if (expd_rest_txt != null) Tfds.Eq(expd_rest_txt, String_.new_u8(actl.Rest_txt()), "Rest_txt");
if (expd_talk_txt != null) Tfds.Eq(expd_talk_txt, String_.new_u8(actl.Talk_txt()), "Talk_txt");
if (expd_talk_url != null) Tfds.Eq(expd_talk_url, String_.new_u8(actl.Talk_url()), "Talk_url");
if (expd_subj_txt != null) Tfds.Eq(expd_subj_txt, String_.new_u8(actl.Subj_txt()), "Subj_txt");
if (expd_subj_url != null) Tfds.Eq(expd_subj_url, String_.new_u8(actl.Subj_url()), "Subj_url");
if (expd_anch_txt != null) Tfds.Eq(expd_anch_txt, String_.new_u8(actl.Anch_txt()), "Anch_txt");
if (expd_qarg_txt != null) Tfds.Eq(expd_qarg_txt, String_.new_u8(actl.Qarg_txt()), "Qarg_txt");
if (expd_base_txt_wo_qarg != null) Tfds.Eq(expd_base_txt_wo_qarg, String_.new_u8(actl.Base_txt_wo_qarg()), "Expd_base_txt_wo_qarg");
if (expd_leaf_txt_wo_qarg != null) Tfds.Eq(expd_leaf_txt_wo_qarg, String_.new_u8(actl.Leaf_txt_wo_qarg()), "Expd_leaf_txt_wo_qarg");
if (expd_force_literal_link != -1) Tfds.Eq(expd_force_literal_link == 1, actl.ForceLiteralLink(), "ForceLiteralLink");
}
else {
Tfds.Eq_ary(String_.Ary(String_.new_u8(expd_err.Owner().Path()) + "." + String_.new_u8(expd_err.Key_bry())), fxt.Log_xtoAry());
}
}
}

View File

@@ -0,0 +1,23 @@
/*
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.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public interface Xow_ttl_parser {
Xoa_ttl Ttl_parse(byte[] ttl);
Xoa_ttl Ttl_parse(int ns_id, byte[] ttl);
Xow_ns_mgr Ns_mgr();
}

View File

@@ -0,0 +1,85 @@
/*
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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_lang_grp implements GfoInvkAble {
public int Id() {return id;} private int id;
public byte[] Key() {return key;} private byte[] key;
public byte[] Name() {return name;} public Xow_lang_grp Name_(byte[] v) {name = v; return this;} private byte[] name;
public int Sort_idx() {return sort_idx;} public Xow_lang_grp Sort_idx_(int v) {sort_idx = v; return this;} private int sort_idx = 0;
public byte Sort_mode() {return sort_mode;} public Xow_lang_grp Sort_mode_(byte v) {sort_mode = v; return this;} private byte sort_mode = Sort_mode_page_name;
public Xow_lang_itm[] Itms() {if (itms == null) itms = (Xow_lang_itm[])itm_list.To_ary(Xow_lang_itm.class); return itms;} private Xow_lang_itm[] itms;
public int Itms_len() {return this.Itms().length;}
public Xow_lang_itm Itms_get(int i) {return this.Itms()[i];}
public void Itms_add(Xow_lang_itm itm) {itms = null; itm_list.Add(itm);} List_adp itm_list = List_adp_.new_();
public void Itms_active_len_add_one_() {++itms_active_len;}
public int Itms_active_len() {return itms_active_len;} private int itms_active_len;
public void Itms_reset() {
Xow_lang_itm[] itms_ary = this.Itms();
int itms_len = itms_ary.length;
for (int i = 0; i < itms_len; i++)
itms_ary[i].Atrs_set(null, false, null); // clear out pre-existing page names; needed b/c this struct is a singleton for entire wiki
itms_active_len = 0;
}
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all; public Xow_lang_grp Html_all_(String s) {html_all = Bry_fmtr.new_(s, "all_name", "grps"); return this;}
public byte[] Html_grp_bgn() {return html_grp_bgn;} private byte[] html_grp_bgn = Bry_.new_a7("\n <tr>");
public byte[] Html_grp_end() {return html_grp_end;} private byte[] html_grp_end = Bry_.new_a7("\n </tr>");
public Bry_fmtr Html_itm() {return html_itm;} Bry_fmtr html_itm; public Xow_lang_grp Html_itm_(String s) {html_itm = Bry_fmtr.new_(s, "lang_code", "lang_domain", "lang_name", "lang_href", "pagename_translation", "page_badge"); return this;}
public void Html_bld(Bry_bfr bfr, Xowe_wiki wiki) {
Xow_lang_itm[] itms_ary = this.Itms();
if (sort_mode == Xow_lang_grp.Sort_mode_page_name)
Array_.Sort(itms_ary, Xow_lang_itm_sorter_page_name._);
int itms_ary_len = itms_ary.length;
for (int i = 0; i < itms_ary_len; i++)
itms_ary[i].Html_bld(bfr, wiki);
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_owner)) return lang_mgr;
else if (ctx.Match(k, Invk_name_)) name = m.ReadBry("v");
else if (ctx.Match(k, Invk_sort_idx_)) sort_idx = m.ReadInt("v");
else if (ctx.Match(k, Invk_sort_mode_)) sort_mode = (byte)m.ReadInt("v");
else if (ctx.Match(k, Invk_html_all_)) Html_all_(m.ReadStr("v"));
else if (ctx.Match(k, Invk_html_itm_)) Html_itm_(m.ReadStr("v"));
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_owner = "owner", Invk_name_ = "name_", Invk_sort_mode_ = "sort_mode_", Invk_sort_idx_ = "sort_idx_", Invk_html_all_ = "html_all_", Invk_html_itm_ = "html_itm_";
public static final byte Sort_mode_lang_idx = 0, Sort_mode_lang_name = 1, Sort_mode_page_name = 2;
public static Xow_lang_grp dflt_(Xow_lang_mgr lang_mgr, int id, byte[] key) {
Xow_lang_grp rv = new Xow_lang_grp();
rv.lang_mgr = lang_mgr; rv.id = id; rv.key = key; rv.name = key;
rv.Html_all_(String_.Concat_lines_nl_skip_last
( ""
, " <h4>~{all_name}</h4>"
, " <table style='width: 100%;'>~{grps}"
, " </table>"
));
rv.Html_itm_(String_.Concat_lines_nl_skip_last
( ""
, " <td style='width: 10%; padding-bottom: 5px;'>~{lang_name}</td><td style='width: 20%; padding-bottom: 5px;'><li~{page_badge}><a hreflang=\"~{lang_code}\" title=\"~{pagename_translation}\" href=\"~{lang_href}\">~{pagename_translation}</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
));
return rv;
} private Xow_lang_grp() {}
Xow_lang_mgr lang_mgr;
}
class Xow_lang_itm_sorter_page_name implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {return Bry_.Compare(((Xow_lang_itm)lhsObj).Page_name(), ((Xow_lang_itm)rhsObj).Page_name());}
public static final Xow_lang_itm_sorter_page_name _ = new Xow_lang_itm_sorter_page_name(); Xow_lang_itm_sorter_page_name() {}
}
class Xow_lang_grp_sorter_sort_idx implements gplx.lists.ComparerAble {
public int compare(Object lhsObj, Object rhsObj) {return Int_.Compare(((Xow_lang_grp)lhsObj).Sort_idx(), ((Xow_lang_grp)rhsObj).Sort_idx());}
public static final Xow_lang_grp_sorter_sort_idx _ = new Xow_lang_grp_sorter_sort_idx(); Xow_lang_grp_sorter_sort_idx() {}
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
public class Xow_lang_itm {
private final Xow_lang_grp html_grp; private final Xow_xwiki_itm xwiki; private final Xoac_lang_itm lang;
public Xow_lang_itm(Xow_lang_grp html_grp, Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
this.html_grp = html_grp; this.xwiki = xwiki; this.lang = lang;
}
public byte[] Lang_key() {return lang.Key_bry();}
public byte[] Lang_domain() {return xwiki.Domain_bry();}
public byte[] Lang_name() {return lang.Local_name_bry();}
public byte[] Page_name() {return page_name;} private byte[] page_name;
public boolean Page_name_has() {return Bry_.Len_gt_0(page_name);}
public boolean Empty_xwiki() {return empty_xwiki;} private boolean empty_xwiki;
public byte[][] Page_badges() {return page_badges;} private byte[][] page_badges;
public void Html_bld(Bry_bfr bfr, Xowe_wiki wiki) {
html_grp.Html_itm().Bld_bfr(bfr, lang.Key_bry(), xwiki.Domain_bry(), lang.Local_name_bry(), page_name);
}
public void Atrs_set(byte[] page_name, boolean empty_xwiki, byte[][] page_badges) {
this.page_name = page_name; this.empty_xwiki = empty_xwiki; this.page_badges = page_badges;
html_grp.Itms_active_len_add_one_();
}
}

View File

@@ -0,0 +1,193 @@
/*
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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*; import gplx.xowa.wikis.xwikis.*; import gplx.xowa.apis.xowa.html.*; import gplx.xowa.xtns.wdatas.core.*;
import gplx.xowa.html.hrefs.*;
public class Xow_lang_mgr {
Xow_lang_mgr() {
int len = Xol_lang_itm_.Id__max;
itms = new Xow_lang_itm[len];
}
public Bry_fmtr Html_div() {return html_div;} private final Bry_fmtr html_div = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5>~{toggle_btn}~{wikidata_link}</h5>"
, " <div~{toggle_hdr}>~{grps}"
, " </div>"
, "</div>"
), "wikidata_link", "toggle_btn", "toggle_hdr", "grps");
public Bry_fmtr Html_wikidata_link() {return html_wikidata_link;} private final Bry_fmtr html_wikidata_link = Bry_fmtr.new_(" (<a href=\"/site/www.wikidata.org/wiki/~{qid}\">wikidata</a>)", "qid");
public void Clear() {hash.Clear();}
public void Itms_reg(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
int lang_id = xwiki.Lang_id();
Xoac_lang_grp ini_grp = lang.Grp();
Xow_lang_grp grp = (Xow_lang_grp)hash.Get_by(ini_grp.Key_bry());
if (grp == null) {
grp = Grps_get_or_new(ini_grp.Key_bry());
grp.Name_(ini_grp.Name_bry());
grp.Sort_idx_(ini_grp.Sort_idx());
}
Xow_lang_itm itm = itms[lang_id];
if (itm == null) {
itm = new Xow_lang_itm(grp, xwiki, lang);
itms[lang_id] = itm;
}
grp.Itms_add(itm);
}
public int Grps_len() {return hash.Count();}
public Xow_lang_grp Grps_get_at(int i) {return (Xow_lang_grp)hash.Get_at(i);}
Xow_lang_grp Grps_get_or_new(byte[] key) {
Xow_lang_grp rv = (Xow_lang_grp)hash.Get_by(key);
if (rv == null) {
int id = hash.Count();
rv = Xow_lang_grp.dflt_(this, id, key);
rv.Sort_idx_(id);
hash.Add(key, rv);
rv.Name_(key);
}
return rv;
} private Ordered_hash hash = Ordered_hash_.new_bry_();
public void Grps_sort() {hash.Sort_by(Xow_lang_grp_sorter_sort_idx._);}
public void Html_bld(Bry_bfr bfr, Xowe_wiki wiki, List_adp slink_list, byte[] qid) {
int grp_len = hash.Count();
for (int i = 0; i < grp_len; i++) {
Xow_lang_grp grp = (Xow_lang_grp)hash.Get_at(i);
grp.Itms_reset();
}
int slink_len = slink_list.Count();
for (int i = 0; i < slink_len; i++) {
Wdata_sitelink_itm slink = (Wdata_sitelink_itm)slink_list.Get_at(i);
Xoa_ttl ttl = slink.Page_ttl();
Xow_xwiki_itm xwiki = ttl.Wik_itm();
int lang_id = xwiki.Lang_id();
Xow_lang_itm itm = itms[lang_id]; // NOTE: handles ttls like [[fr:]] and [[:fr;]] which have an empty Page_txt, but a valued Full_txt_raw
byte[] ttl_bry = ttl.Page_txt_w_anchor();
boolean empty_xwiki = false;
if (Bry_.Len_eq_0(ttl_bry)) {
ttl_bry = wiki.Ctx().Cur_page().Ttl().Page_txt();
empty_xwiki = true;
}
itm.Atrs_set(ttl_bry, empty_xwiki, slink.Badges());
}
html_bldr.Init(this, wiki, slink_list, slink_len, qid);
html_bldr.XferAry(bfr, -1);
} private Xow_lang_itm[] itms = null; Xow_lang_html html_bldr = new Xow_lang_html();
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_get)) return Grps_get_or_new(m.ReadBry("v"));
else if (ctx.Match(k, Invk_sort)) Grps_sort();
else return GfoInvkAble_.Rv_unhandled;
return this;
} private static final String Invk_get = "get", Invk_sort = "sort";
public static Xow_lang_mgr dflt_() {return new Xow_lang_mgr();}
}
class Xow_lang_html implements Bry_fmtr_arg {
private Xow_lang_mgr lang_mgr; Xowe_wiki wiki; List_adp ttl_list; private byte[] qid;
private Xoapi_toggle_itm toggle_itm;
private int stage = 0;
public Xow_lang_html Init(Xow_lang_mgr lang_mgr, Xowe_wiki wiki, List_adp ttl_list, int ttl_list_len, byte[] qid) {
this.lang_mgr = lang_mgr; this.wiki = wiki; this.ttl_list = ttl_list; this.qid = qid;
toggle_itm = wiki.Appe().Api_root().Html().Page().Toggle_mgr().Get_or_new("wikidata-langs");
return this;
}
public void XferAry(Bry_bfr bfr, int idx) {
switch (stage) {
case 0: {
stage = 1;
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b128().Mkr_rls();
byte[] msg_lang = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_page_lang_header);
byte[] wikidata_link = Bry_.Len_eq_0(qid) ? Bry_.Empty : lang_mgr.Html_wikidata_link().Bld_bry_many(tmp_bfr, qid);
toggle_itm.Init(wiki, msg_lang);
lang_mgr.Html_div().Bld_bfr_many(bfr, wikidata_link, toggle_itm.Html_toggle_btn(), toggle_itm.Html_toggle_hdr(), this);
stage = 0;
break;
}
case 1:
stage = 2;
int grps_len = lang_mgr.Grps_len();
for (int i = 0; i < grps_len; i++) {
grp = lang_mgr.Grps_get_at(i);
if (grp.Itms_active_len() == 0) continue; // skip grps with no items
grp.Html_all().Bld_bfr_many(bfr, grp.Name(), this);
}
stage = 1;
break;
case 2:
int itms_len = grp.Itms_len();
int grp_counter = 0; boolean row_opened = false;
for (int i = 0; i < itms_len; i++) {
Xow_lang_itm itm = grp.Itms_get(i);
if (!itm.Page_name_has()) continue;
if (grp_counter == 0) {
bfr.Add(grp.Html_grp_bgn());
row_opened = true;
}
byte[] lang_key = itm.Lang_key();
byte[] domain = itm.Lang_domain();
byte[] page_name = itm.Page_name();
byte[] local_name = itm.Lang_name();
byte[] badge_cls = Badge_cls(tmp_bfr, itm.Page_badges());
if (wiki.Appe().Usere().Wiki().Xwiki_mgr().Get_by_key(domain) == null)
tmp_bfr.Add(Xoh_href_parser.Href_https_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
else
tmp_bfr.Add(Xoh_href_parser.Href_site_bry).Add(domain).Add(Xoh_href_parser.Href_wiki_bry);
if (!itm.Empty_xwiki()) tmp_bfr.Add(page_name);
grp.Html_itm().Bld_bfr_many(bfr, lang_key, domain, local_name, tmp_bfr.Xto_bry_and_clear(), page_name, badge_cls);
++grp_counter;
if (grp_counter == 3) {
row_opened = false;
bfr.Add(grp.Html_grp_end());
grp_counter = 0;
}
}
if (row_opened) {
bfr.Add(grp.Html_grp_end());
grp_counter = 0;
}
stage = 2;
break;
}
} private Xow_lang_grp grp; Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
private static byte[] Badge_cls(Bry_bfr bfr, byte[][] badges) {
if (badges == null) badges = Bry_.Ary_empty;
int badges_len = badges.length;
bfr.Add(Cls_bgn);
if (badges_len == 0)
bfr.Add(Badge_none_cls);
else {
for (int i = 0; i < badges_len; ++i) {
if (i != 0) bfr.Add_byte_comma();
byte[] badge = badges[i];
byte[] badge_cls = (byte[])badges_hash.Get_by_bry(badge);
if (badge_cls == null) Gfo_usr_dlg_.I.Warn_many("", "", "unknown badge: badge=~{0}", String_.new_u8(badge));
else bfr.Add(badge_cls);
}
}
bfr.Add_byte_apos();
return bfr.Xto_bry_and_clear();
}
private static final byte[]
Badge_none_cls = Bry_.new_a7("badge-none")
, Cls_bgn = Bry_.new_a7(" class='")
;
private static Hash_adp_bry badges_hash = Hash_adp_bry.ci_ascii_()
.Add_str_obj("Q17437798", Bry_.new_a7("badge-goodarticle"))
.Add_str_obj("Q17437796", Bry_.new_a7("badge-featuredarticle"))
.Add_str_obj("Q17559452", Bry_.new_a7("badge-recommendedarticle"))
.Add_str_obj("Q17506997", Bry_.new_a7("badge-featuredlist"))
.Add_str_obj("Q17580674", Bry_.new_a7("badge-featuredportal"))
;
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
public class Xow_lang_mgr_fxt {
public void Clear() {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
Init_langs(wiki);
}
public static void Init_langs(Xowe_wiki wiki) {
Xoae_app app = wiki.Appe();
Xoa_lang_mgr lang_mgr = app.Lang_mgr();
lang_mgr.Groups().Set_bulk(Bry_.new_a7(String_.Concat_lines_nl
( "+||grp|wiki"
, "+|wiki|grp|grp1"
, "+|wiki|grp|grp2"
, "+|grp1|itm|simple|Simple"
, "+|grp2|itm|fr|French"
, "+|grp1|itm|es|Spanish"
, "+|grp2|itm|de|German"
, "+|grp1|itm|it|Italian"
, "+|grp1|itm|zh|Chinese"
)));
wiki.Xwiki_mgr().Add_bulk_langs(Bry_.new_a7("wiki"));
String bulk = String_.Concat_lines_nl
( "simple.wikipedia.org|simple.wikipedia.org"
, "fr.wikipedia.org|fr.wikipedia.org"
, "es.wikipedia.org|es.wikipedia.org"
, "de.wikipedia.org|de.wikipedia.org"
, "it.wikipedia.org|it.wikipedia.org"
);
wiki.Appe().Usere().Wiki().Xwiki_mgr().Add_bulk(Bry_.new_a7(bulk));
}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
Xoae_app app;
public void tst(String raw, String expd) {
Xop_ctx ctx = wiki.Ctx();
ctx.Cur_page().Ttl_(Xoa_ttl.parse_(wiki, Bry_.new_a7("test_page")));
byte[] raw_bry = Bry_.new_u8(raw);
Bry_bfr bfr = Bry_bfr.new_();
Xop_root_tkn root = ctx.Tkn_mkr().Root(raw_bry);
wiki.Parser().Parse_page_all_clear(root, ctx, ctx.Tkn_mkr(), raw_bry);
wiki.Html_mgr().Html_wtr().Write_all(bfr, ctx, raw_bry, root);
Bry_bfr html_bfr = Bry_bfr.new_();
wiki.Xwiki_mgr().Lang_mgr().Html_bld(html_bfr, wiki, ctx.Cur_page().Slink_list(), gplx.xowa.xtns.wdatas.Wdata_xwiki_link_wtr.Qid_null);
Tfds.Eq_str_lines(expd, html_bfr.Xto_str_and_clear());
}
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*;
public class Xow_lang_mgr_tst {
private Xow_lang_mgr_fxt fxt = new Xow_lang_mgr_fxt();
@Before public void init() {fxt.Clear();}
@Test public void Basic() {
fxt.tst("[[simple:Earth]] [[fr:Terre]] [[es:Tierra]] [[de:Erde]] [[it:Terre]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Earth\" href=\"/site/simple.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Spanish</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"es\" title=\"Tierra\" href=\"/site/es.wikipedia.org/wiki/Tierra\">Tierra</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>Italian</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"it\" title=\"Terre\" href=\"/site/it.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " <h4>grp2</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>French</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"fr\" title=\"Terre\" href=\"/site/fr.wikipedia.org/wiki/Terre\">Terre</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " <td style='width: 10%; padding-bottom: 5px;'>German</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"de\" title=\"Erde\" href=\"/site/de.wikipedia.org/wiki/Erde\">Erde</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Empty() {
fxt.tst("[[simple:]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"Test page\" href=\"/site/simple.wikipedia.org/wiki/\">Test page</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Unregistered() {
// fxt.Wiki().Xwiki_mgr().Add_full(Bry_.new_u8("zh"), Bry_.new_u8("zh.wikipedia.org"), Bry_.new_u8("http://zh.wikipedia.org/~{0}"));
fxt.tst("[[zh:Earth]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Chinese</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"zh\" title=\"Earth\" href=\"https://zh.wikipedia.org/wiki/Earth\">Earth</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Anchor() {// PURPOSE: A#b was not showing anchor "#b"; DATE:2013-10-23
fxt.tst("[[simple:A#b]]", String_.Concat_lines_nl_skip_last
( "<div id=\"xowa-lang\">"
, " <h5><a href='javascript:xowa_toggle_visible(\"wikidata-langs\");' style='text-decoration: none !important;'>In other languages<img id='wikidata-langs-toggle-icon' src='file:///mem/xowa/user/test_user/app/img/window/portal/twisty_right.png' title='' /></a></h5>"
, " <div id='wikidata-langs-toggle-elem' style='display:none;'>"
, " <h4>grp1</h4>"
, " <table style='width: 100%;'>"
, " <tr>"
, " <td style='width: 10%; padding-bottom: 5px;'>Simple</td><td style='width: 20%; padding-bottom: 5px;'><li class='badge-none'><a hreflang=\"simple\" title=\"A#b\" href=\"/site/simple.wikipedia.org/wiki/A#b\">A#b</a></li></td><td style='width: 3%; padding-bottom: 5px;'></td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
public class Xow_xwiki_itm implements gplx.CompareAble {
public Xow_xwiki_itm(byte[] key_bry, byte[] url_fmt, int lang_id, int domain_tid, byte[] domain_bry, byte[] domain_name) {
this.key_bry = key_bry; this.key_str = String_.new_u8(key_bry);
this.url_fmt = url_fmt; this.lang_id = lang_id;
this.url_fmtr = Bry_.Len_eq_0(url_fmt) ? null : Bry_fmtr.new_(url_fmt, "0");
this.domain_tid = domain_tid; this.domain_bry = domain_bry; this.domain_name = domain_name;
}
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry; // EX: commons
public String Key_str() {return key_str;} private final String key_str;
public byte[] Url_fmt() {return url_fmt;} private final byte[] url_fmt; // EX: //commons.wikimedia.org/wiki/Category:$1
public Bry_fmtr Url_fmtr(){return url_fmtr;} private final Bry_fmtr url_fmtr;
public int Lang_id() {return lang_id;} private final int lang_id; // EX: Id__unknown
public int Domain_tid() {return domain_tid;} private final int domain_tid; // EX: Tid_int_commons
public byte[] Domain_bry() {return domain_bry;} private final byte[] domain_bry; // EX: commons.wikimedia.org
public byte[] Domain_name() {return domain_name;} private final byte[] domain_name; // EX: Wikimedia Commons
public boolean Offline() {return offline;} public Xow_xwiki_itm Offline_(boolean v) {offline = v; return this;} private boolean offline;
public int compareTo(Object obj) {Xow_xwiki_itm comp = (Xow_xwiki_itm)obj; return Bry_.Compare(key_bry, comp.key_bry);}
public boolean Type_is_xwiki_lang(int cur_lang_id) {
return lang_id != Xol_lang_itm_.Id__unknown // valid lang code
&& domain_tid != Xow_domain_type_.Tid_commons // commons should never be considered an xwiki_lang; EX:[[commons:A]] PAGE:species:Scarabaeidae; DATE:2014-09-10
&& lang_id != cur_lang_id // lang is different than current; EX: [[en:A]] in en.wikipedia.org shouldn't link back to self
&& Bry_.Len_gt_0(url_fmt) // url_fmt exists
;
}
public static Xow_xwiki_itm new_(byte[] key_bry, byte[] url_fmt, int lang_id, int domain_tid, byte[] domain_bry) {
return new Xow_xwiki_itm(key_bry, url_fmt, lang_id, domain_tid, domain_bry, domain_bry);
}
public static Xow_xwiki_itm new_by_mw(Bry_bfr bfr, Gfo_url_parser url_parser, Gfo_url url, byte[] key, byte[] mw_url, byte[] domain_name) {// EX: "commons|//commons.wikimedia.org/wiki/Category:$1|Wikimedia Commons" "DMOZ|http://www.dmoz.org/Regional/Europe/$1/"|DMOZ"
byte[] gfs_url = gplx.xowa.apps.Xoa_gfs_php_mgr.Xto_gfs(bfr, mw_url); // EX: "//commons.wikimedia.org/wiki/Category:$1" -> "//commons.wikimedia.org/wiki/Category:~{0}"
url_parser.Parse(url, gfs_url, 0, gfs_url.length);
byte[] domain_bry = url.Site(); // extract "commons.wikimedia.org"
Xow_domain domain = Xow_domain_.parse(domain_bry);
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_key());
int lang_id = lang_itm == null ? Xol_lang_itm_.Id__unknown : lang_itm.Id();
return new Xow_xwiki_itm(key, gfs_url, lang_id, domain.Domain_tid(), domain_bry, domain_name);
}
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
public class Xow_xwiki_itm_tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_itm_fxt fxt = new Xow_xwiki_itm_fxt();
@Test public void Commons() {fxt.Test_new_by_mw("commons.wikimedia.org/wiki/$1" , "commons.wikimedia.org" , "commons.wikimedia.org/wiki/~{0}" , Xow_domain_type_.Tid_commons , Xol_lang_itm_.Id__unknown);}
@Test public void Wiktionary() {fxt.Test_new_by_mw("fr.wiktionary.org/wiki/$1" , "fr.wiktionary.org" , "fr.wiktionary.org/wiki/~{0}" , Xow_domain_type_.Tid_wiktionary , Xol_lang_itm_.Id_fr);}
@Test public void Lang() {fxt.Test_new_by_mw("fr.wikipedia.org/wiki/$1" , "fr.wikipedia.org" , "fr.wikipedia.org/wiki/~{0}" , Xow_domain_type_.Tid_wikipedia , Xol_lang_itm_.Id_fr);}
}
class Xow_xwiki_itm_fxt {
private Bry_bfr tmp_bfr;
private Gfo_url_parser url_parser;
private Gfo_url tmp_url;
private byte[] key;
public void Clear() {
tmp_bfr = Bry_bfr.new_(255);
url_parser = new Gfo_url_parser();
tmp_url = new Gfo_url();
key = Bry_.new_a7("test");
}
public void Test_new_by_mw(String url_php, String expd_domain, String expd_url_fmt, int expd_wiki_tid, int expd_lang_tid) {
Xow_xwiki_itm itm = Xow_xwiki_itm.new_by_mw(tmp_bfr, url_parser, tmp_url, key, Bry_.new_u8(url_php), key);
Tfds.Eq(expd_domain , String_.new_u8(itm.Domain_bry()));
Tfds.Eq(expd_url_fmt , String_.new_u8(itm.Url_fmt()));
Tfds.Eq(expd_wiki_tid , itm.Domain_tid(), "wiki");
Tfds.Eq(expd_lang_tid , itm.Lang_id(), "lang");
}
}

View File

@@ -0,0 +1,215 @@
/*
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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.xowa.langs.*;
import gplx.xowa.html.hrefs.*;
public class Xow_xwiki_mgr implements GfoInvkAble {
private Xowe_wiki wiki; private Xow_xwiki_mgr_srl srl;
public Xow_xwiki_mgr() {} // FIXME: current placeholder for viewer
public Xow_xwiki_mgr(Xowe_wiki wiki, Gfo_url_parser url_parser) {
this.wiki = wiki;
srl = new Xow_xwiki_mgr_srl(this, url_parser);
}
public Xow_lang_mgr Lang_mgr() {return lang_mgr;} private final Xow_lang_mgr lang_mgr = Xow_lang_mgr.dflt_();
public int Len() {return list.Count();} private Ordered_hash list = Ordered_hash_.new_bry_(); private Hash_adp_bry hash = Hash_adp_bry.ci_ascii_(); // ASCII:lang_code
public void Clear() {hash.Clear(); list.Clear();}
public Xow_xwiki_itm Get_at(int i) {return (Xow_xwiki_itm)list.Get_at(i);}
public Xow_xwiki_itm Get_by_key(byte[] key) {return (Xow_xwiki_itm)hash.Get_by_bry(key);}
public Xow_xwiki_itm Get_by_mid(byte[] src, int bgn, int end) {return (Xow_xwiki_itm)hash.Get_by_mid(src, bgn, end);}
public Xow_xwiki_itm Add_full(String alias, String domain) {return Add_full(Bry_.new_a7(alias), Bry_.new_a7(domain), null);}
public Xow_xwiki_itm Add_full(byte[] alias, byte[] domain) {return Add_full(alias, domain, null);}
public Xow_xwiki_itm Add_full(byte[] alias, byte[] domain_bry, byte[] url_fmt) {
int domain_tid = Byte_.Zero;
int lang_id = -1;
Xow_domain wiki_type = Xow_domain_.parse(domain_bry);
domain_tid = wiki_type.Domain_tid();
if (Bry_.Len_gt_0(wiki_type.Lang_key())) { // domain_bry has lang (EX: "en.")
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(wiki_type.Lang_key());
if (lang_itm == null) return null; // unknown lang: do not add to wiki collection; EX: en1.wikipedia.org
lang_id = lang_itm.Id();
}
Xow_xwiki_itm itm = Xow_xwiki_itm.new_(alias, url_fmt, lang_id, domain_tid, domain_bry);
Add_itm(itm, null);
return itm;
}
public void Sort_by_key() {
list.Sort();
}
public Xow_domain[] Get_by_crt(Xow_domain cur, gplx.xowa.wikis.domains.crts.Xow_domain_crt_itm crt) {
List_adp rv = List_adp_.new_();
int len = this.Len();
for (int i = 0; i < len; ++i) {
Xow_xwiki_itm wiki = this.Get_at(i);
if (!wiki.Offline()) continue;
Xow_domain domain_itm = Xow_domain_.parse(wiki.Domain_bry());
if (crt.Matches(cur, domain_itm)) rv.Add(domain_itm);
}
return (Xow_domain[])rv.To_ary_and_clear(Xow_domain.class);
}
public void Add_bulk(byte[] raw) {
byte[][] rows = Bry_.Split(raw, Byte_ascii.Nl);
int rows_len = rows.length;
Hash_adp_bry lang_regy = Xol_lang_itm_.Regy();
for (int i = 0; i < rows_len; i++) {
byte[] row = rows[i]; if (Bry_.Len_eq_0(row)) continue; // ignore blank rows
Xow_xwiki_itm itm = Add_bulk_row(lang_regy, row);
Add_itm(itm, null);
}
}
public Xow_xwiki_itm Add_bulk_row(Hash_adp_bry lang_regy, byte[] row) {
byte[][] flds = Bry_.Split(row, Byte_ascii.Pipe); int flds_len = flds.length;
byte[] alias = Bry_.Empty, domain_bry = Bry_.Empty;
for (int j = 0; j < flds_len; j++) {
byte[] fld = flds[j];
switch (j) {
case 0: alias = fld; break;
case 1: domain_bry = fld; break;
case 2: break; // reserved for 0,1 (0=custom; 1=wmf)
default: throw Exc_.new_unhandled(j);
}
}
Xow_domain domain = Xow_domain_.parse(domain_bry);
int lang_id = Xol_lang_itm_.Id__unknown;
if (Bry_.Len_gt_0(domain.Lang_key())) {
Xol_lang_itm lang_itm = Xol_lang_itm_.Get_by_key(domain.Lang_key());
if (lang_itm != null // lang exists
&& Bry_.Eq(alias, lang_itm.Key())) // alias == lang.key; only assign langs to aliases that have lang key; EX: w|en.wikipedia.org; "w" alias should not be registered for "en"; DATE:2013-07-25
lang_id = lang_itm.Id();
}
byte[] url_fmt = Bry_.Add(Xoh_href_parser.Href_https_bry, domain_bry, Xoh_href_parser.Href_wiki_bry, Arg_0);
return Xow_xwiki_itm.new_(alias, url_fmt, lang_id, domain.Domain_tid(), domain_bry);
} static final byte[] Arg_0 = Bry_.new_a7("~{0}");
String Exec_itms_print(byte[] raw) {
Bry_fmtr fmtr = Bry_fmtr.new_bry_(raw, "wiki_key");//, "wiki_type_url", "wiki_lang", "wiki_name", "wiki_logo_url");
Bry_bfr tmp_bfr = Xoa_app_.Utl__bfr_mkr().Get_k004();
Hash_adp_bry seen = Hash_adp_bry.ci_ascii_(); // ASCII:url_domain; EX:en.wikipedia.org
int wikis_len = list.Count();
for (int i = 0; i < wikis_len; i++) {
Xow_xwiki_itm itm = (Xow_xwiki_itm)list.Get_at(i);
byte[] key = itm.Key_bry();
if (Bry_.Eq(key, Xow_domain_type_.Key_bry_home)) continue; // skip home
byte[] domain = itm.Domain_bry();
if (seen.Has(domain)) continue;
seen.Add_as_key_and_val(domain);
fmtr.Bld_bfr_many(tmp_bfr, key);
}
return tmp_bfr.To_str_and_rls();
}
public void Add_bulk_peers(byte[] raw) {
byte[][] keys = Bry_.Split(raw, Byte_ascii.Tilde);
int len = keys.length;
Ordered_hash peers = Ordered_hash_.new_();
Cfg_nde_root peer_root = wiki.Appe().Wiki_mgr().Groups();
for (int i = 0; i < len; i++) {
byte[] key = keys[i];
Cfg_nde_obj peer_grp = peer_root.Grps_get(key);
if (peer_grp == null)
throw Exc_.new_("unknown peer group", "key", String_.new_u8(key));
else
Cfg_nde_obj_.Fill_recurse(peers, peer_grp);
}
len = peers.Count();
byte[] lang_key_bry = wiki.Lang().Key_bry();
if (lang_key_bry == Xol_lang_itm_.Key__unknown) lang_key_bry = Xol_lang_.Key_en; // default non-lang wikis to english
String lang_key_str = String_.new_u8(lang_key_bry);
int lang_id = Xol_lang_itm_.Get_by_key(lang_key_bry).Id();
for (int i = 0; i < len; i++) {
Xoac_wiki_itm wiki_itm = (Xoac_wiki_itm)peers.Get_at(i);
byte[] wiki_name_bry = wiki_itm.Key_bry();
String wiki_name = String_.new_u8(wiki_name_bry);
String domain_str = null;
int domain_tid = Xow_domain_type_.Get_type_as_tid(wiki_name_bry);
switch (domain_tid) {
case Xow_domain_type_.Tid_commons:
case Xow_domain_type_.Tid_species:
case Xow_domain_type_.Tid_meta:
case Xow_domain_type_.Tid_incubator: domain_str = String_.Format("{0}.wikimedia.org", wiki_name); break; // EX: commons.wikimedia.org
case Xow_domain_type_.Tid_wikidata: domain_str = String_.Format("www.wikidata.org", wiki_name); break; // EX: www.wikidata.org
case Xow_domain_type_.Tid_mediawiki: domain_str = String_.Format("www.mediawiki.org", wiki_name); break;
case Xow_domain_type_.Tid_wmfblog: domain_str = String_.Format("wikimediafoundation.org", wiki_name); break;
default: domain_str = String_.Format("{0}.{1}.org", lang_key_str, wiki_name); break; // EX: en.wiktionary.org
}
byte[] domain_bry = Bry_.new_u8(domain_str);
Xowe_wiki lang_wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_null(domain_bry);
boolean offline_exists = lang_wiki != null;
String fmt = String_.Format("http://" + domain_str + "/wiki/~{0}");
int aliases_len = wiki_itm.Aliases().length;
for (int j = 0; j < aliases_len; j++) {
byte[] alias = wiki_itm.Aliases()[j];
if (wiki.Ns_mgr().Names_get_or_null(alias, 0, alias.length) != null) continue; // NOTE: do not add xwiki if alias matches namespace; EX: en.wiktionary.org has ns of "Wiktionary"; do not add alias of "wiktionary"; note that wikipedia does have an alias to wiktionary
Xow_xwiki_itm xwiki = Xow_xwiki_itm.new_(alias, Bry_.new_u8(fmt), lang_id, domain_tid, domain_bry).Offline_(offline_exists); // NOTE: domain_tid must be used, not wiki.Domain_tid; DATE:2014-09-14
Add_itm(xwiki, null);
}
}
}
public void Add_bulk_langs(GfoMsg m) {
byte[] grp_key = m.ReadBry("grp_key");
byte[] wiki_type_name = m.ReadBryOr("wiki_type_name", null);
int wiki_tid = wiki_type_name == null ? wiki.Domain_tid() : Xow_domain_type_.Get_type_as_tid(wiki_type_name);
Add_bulk_langs(grp_key, wiki_tid);
}
public void Add_bulk_langs(byte[] grp_key) {Add_bulk_langs(grp_key, wiki.Domain_tid());}
public void Add_bulk_langs(byte[] grp_key, int domain_tid) {
Ordered_hash langs = wiki.Appe().Lang_mgr().Xto_hash(grp_key);
int len = langs.Count();
byte[] wiki_tid_name = Xow_domain_type_.Get_type_as_bry(domain_tid);
String wiki_tid_name_str = String_.new_u8(wiki_tid_name);
for (int i = 0; i < len; i++) {
Xoac_lang_itm lang = (Xoac_lang_itm)langs.Get_at(i);
String domain_str = String_.Format("{0}.{1}.org", String_.new_u8(lang.Key_bry()), wiki_tid_name_str); // EX: fr.wikipedia.org
byte[] domain_bry = Bry_.new_u8(domain_str);
Xowe_wiki lang_wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_null(domain_bry);
boolean offline_exists = lang_wiki != null;
String url_fmt = String_.Format("http://" + domain_str + "/wiki/~{0}");
int lang_id = Xol_lang_itm_.Get_by_key(lang.Key_bry()).Id();
Xow_xwiki_itm xwiki = Xow_xwiki_itm.new_(lang.Key_bry(), Bry_.new_u8(url_fmt), lang_id, domain_tid, domain_bry).Offline_(offline_exists);
Add_itm(xwiki, lang);
}
lang_mgr.Grps_sort();
}
public void Add_itm(Xow_xwiki_itm itm) {Add_itm(itm, null);}
private void Add_itm(Xow_xwiki_itm xwiki, Xoac_lang_itm lang) {
byte[] xwiki_key = xwiki.Key_bry();
if ( !hash.Has(xwiki.Key_bry()) // only register xwiki / lang pair once
&& lang != null) // null lang should not be registered
lang_mgr.Itms_reg(xwiki, lang);
byte[] xwiki_domain = xwiki.Domain_bry();
if (!domain_hash.Has(xwiki_domain)) { // domain is new
domain_hash.Add(xwiki_domain, xwiki_key);
list.Add_if_dupe_use_nth(xwiki_key, xwiki); // only add to list if domain is new; some wikis like commons will be added multiple times under different aliases (commons, c, commons.wikimedia.org); need to check domain and add only once DATE:2014-11-07
}
hash.Add_if_dupe_use_nth(xwiki_key, xwiki);
} private final Hash_adp_bry domain_hash = Hash_adp_bry.ci_ascii_();
public void Add_many(byte[] v) {srl.Load_by_bry(v);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_count)) return list.Count();
else if (ctx.Match(k, Invk_add_bulk)) Add_bulk(m.ReadBry("v"));
else if (ctx.Match(k, Invk_add_bulk_langs)) Add_bulk_langs(m);
else if (ctx.Match(k, Invk_add_bulk_peers)) Add_bulk_peers(m.ReadBry("v"));
else if (ctx.Match(k, Invk_add_many)) Add_many(m.ReadBry("v"));
else if (ctx.Match(k, Invk_itms_print)) return Exec_itms_print(m.ReadBry("v"));
else if (ctx.Match(k, Invk_clear)) this.Clear();
else return GfoInvkAble_.Rv_unhandled;
return this;
}
private static final String
Invk_add_bulk = "add_bulk", Invk_add_bulk_langs = "add_bulk_langs", Invk_add_bulk_peers = "add_bulk_peers", Invk_add_many = "add_many"
, Invk_itms_print = "itms_print", Invk_count = "count", Invk_clear = "clear"
;
}

View 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.srls.dsvs.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.xwikis.*;
class Xow_xwiki_mgr_srl extends Dsv_wkr_base {
private byte[] key, url_fmt, name;
private final Xow_xwiki_mgr mgr;
private final Gfo_url_parser url_parser; private final Gfo_url tmp_url = new Gfo_url(); private final Bry_bfr tmp_bfr = Bry_bfr.reset_(255);
public Xow_xwiki_mgr_srl(Xow_xwiki_mgr mgr, Gfo_url_parser url_parser) {
this.mgr = mgr; this.url_parser = url_parser;
}
@Override public Dsv_fld_parser[] Fld_parsers() {return new Dsv_fld_parser[] {Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser, Dsv_fld_parser_.Bry_parser};}
@Override public boolean Write_bry(Dsv_tbl_parser parser, int fld_idx, byte[] src, int bgn, int end) {
switch (fld_idx) {
case 0: key = Bry_.Mid(src, bgn, end); return true;
case 1: url_fmt = Bry_.Mid(src, bgn, end); return true;
case 2: name = Bry_.Mid(src, bgn, end); return true;
default: return false;
}
}
@Override public void Commit_itm(Dsv_tbl_parser parser, int pos) {
Xow_xwiki_itm itm = Xow_xwiki_itm.new_by_mw(tmp_bfr, url_parser, tmp_url, key, url_fmt, name);
mgr.Add_itm(itm);
}
}

View File

@@ -0,0 +1,140 @@
/*
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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import org.junit.*; import gplx.core.strings.*; import gplx.xowa.wikis.*; import gplx.xowa.langs.*;
public class Xow_xwiki_mgr_tst {
@Before public void init() {fxt.Clear();} private Xow_xwiki_mgr_fxt fxt = new Xow_xwiki_mgr_fxt();
@Test public void Add_bulk_wiki_en() {fxt.Test_add_bulk("w|en.wikipedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_wikipedia , "w" , "https://en.wikipedia.org/wiki/~{0}", "en.wikipedia.org");}
@Test public void Add_bulk_wiki_fr() {fxt.Test_add_bulk("fr|fr.wikipedia.org" , Xol_lang_itm_.Id_fr , Xow_domain_type_.Tid_wikipedia , "fr" , "https://fr.wikipedia.org/wiki/~{0}", "fr.wikipedia.org");}
@Test public void Add_bulk_wikt_en() {fxt.Test_add_bulk("wikt|en.wiktionary.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_wiktionary , "wikt" , "https://en.wiktionary.org/wiki/~{0}", "en.wiktionary.org");}
@Test public void Add_bulk_commons() {fxt.Test_add_bulk("commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_commons , "commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_commons_cap() {fxt.Test_add_bulk("Commons|commons.wikimedia.org" , Xol_lang_itm_.Id__unknown , Xow_domain_type_.Tid_commons , "Commons" , "https://commons.wikimedia.org/wiki/~{0}", "commons.wikimedia.org");}
@Test public void Add_bulk_langs_wiki() {fxt.Init_langs().Test_add_bulk_langs("wiki", fxt.xwiki_("en", "en.wikipedia.org", "http://en.wikipedia.org/wiki/~{0}"), fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grps() {fxt.Init_langs().Test_add_bulk_langs("europe_west~asia_east", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grp_itm() {fxt.Init_langs().Test_add_bulk_langs("europe_west~ja", fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"), fxt.xwiki_("ja", "ja.wikipedia.org", "http://ja.wikipedia.org/wiki/~{0}"));}
@Test public void Add_bulk_langs_grp_commons() {
fxt.Init_langs();
fxt.Wiki().Xwiki_mgr().Add_bulk_langs(Bry_.new_a7("europe_west"), Xow_domain_type_.Tid_wikipedia);
fxt.Tst_itms(fxt.xwiki_("de", "de.wikipedia.org", "http://de.wikipedia.org/wiki/~{0}"), fxt.xwiki_("fr", "fr.wikipedia.org", "http://fr.wikipedia.org/wiki/~{0}"));
}
@Test public void Add_bulk_peers() {fxt.Init_peers().Test_add_bulk_peers("peer", fxt.xwiki_null_("commons"), fxt.xwiki_null_("m"), fxt.xwiki_("wikt", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("wiktionary", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"), fxt.xwiki_("s", "en.wikisource.org", "http://en.wikisource.org/wiki/~{0}"));}
@Test public void Add_bulk_peers_skip_self() {fxt.Init_peers().Test_add_bulk_peers("peer", fxt.xwiki_null_("wikipedia"), fxt.xwiki_("w", "en.wikipedia.org", "http://en.wikipedia.org/wiki/~{0}"));} // PURPOSE: skip "wikipedia" as alias since "Wikipedia" is namespace; needed for titles of "Wikipedia:Main page" (which would otherwise try to go to page "Main Page" in the main names of xwiki "Wikipedia"
@Test public void Add_bulk_core_wikidata() {fxt.Init_peers().Test_add_bulk_peers("core", fxt.xwiki_("d", "www.wikidata.org", "http://www.wikidata.org/wiki/~{0}"));}
@Test public void Add_bulk_peers_tid() { // PURPOSE:wikt should generate wiki_tid of wiktionary, not wikipedia; PAGE:en.s:Main_Page DATE:2014-09-14
fxt.Init_wikt ().Test_add_bulk_peers("peer", fxt.xwiki_("wikt", "en.wiktionary.org", "http://en.wiktionary.org/wiki/~{0}"));
}
@Test public void Multiple_aliases_should_only_add_once() { // PURPOSE.FIX: multiple aliases for same domain should only be added once to Get_at's list; DATE:2014-11-07
fxt.Exec_add_bulk("a1|a.org\na2|a.org").Test_len(1);
}
}
class Xow_xwiki_mgr_fxt {
Xow_xwiki_mgr xwiki_mgr; Xoa_lang_mgr lang_mgr; String_bldr sb = String_bldr_.new_(); Xoae_app app; Xowe_wiki wiki;
public void Clear() {
if (xwiki_mgr == null) {
app = Xoa_app_fxt.app_();
wiki = Xoa_app_fxt.wiki_tst_(app);
xwiki_mgr = wiki.Xwiki_mgr();
lang_mgr = app.Lang_mgr();
}
xwiki_mgr.Clear();
lang_mgr.Clear();
}
public Xowe_wiki Wiki() {return wiki;}
public Xow_xwiki_itm xwiki_null_(String key) {return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.Empty, Xol_lang_itm_.Id__unknown, Xow_domain_type_.Tid_other, Bry_.Empty);}
public Xow_xwiki_itm xwiki_(String key, String domain_str, String url_fmt) {
Xow_domain domain = Xow_domain_.parse(Bry_.new_u8(domain_str));
return Xow_xwiki_itm.new_(Bry_.new_u8(key), Bry_.new_u8(url_fmt), domain.Lang_itm().Id(), domain.Domain_tid(), domain.Domain_bry());
}
public Xow_xwiki_mgr_fxt Test_add_bulk(String raw, int lang_tid, int wiki_tid, String alias, String fmt, String domain) {
Xow_xwiki_itm itm = xwiki_mgr.Add_bulk_row(Xol_lang_itm_.Regy(), Bry_.new_a7(raw));
Tfds.Eq(alias, String_.new_a7(itm.Key_bry()));
Tfds.Eq(fmt, String_.new_a7(itm.Url_fmt()));
Tfds.Eq(wiki_tid, itm.Domain_tid(), "wiki_tid");
Tfds.Eq(lang_tid, itm.Lang_id(), "lang_id");
return this;
}
public Xow_xwiki_mgr_fxt Init_langs() {
lang_mgr.Groups().Set_bulk(Bry_.new_u8(String_.Concat_lines_nl
( "+||grp|wiki"
, "+|wiki|grp|english"
, "+|wiki|grp|europe_west"
, "+|wiki|grp|asia_east"
, "+|english|itm|en|English"
, "+|europe_west|itm|fr|French"
, "+|europe_west|itm|de|German"
, "+|asia_east|itm|ja|Japanese"
)));
return this;
}
public Xow_xwiki_mgr_fxt Init_peers() {
app.Wiki_mgr().Groups().Set_bulk(Bry_.new_u8(String_.Concat_lines_nl
( "+|core|itm|commons|commons"
, "+|core|itm|meta|meta;m"
, "+|core|itm|wikidata|d"
, "+|peer|itm|wiktionary|wikt;wiktionary"
, "+|peer|itm|wikisource|s"
, "+|peer|itm|wikipedia|w;wikipedia"
)));
return this;
}
public Xow_xwiki_mgr_fxt Init_wikt() {
app.Wiki_mgr().Groups().Set_bulk(Bry_.new_u8(String_.Concat_lines_nl
( "+|peer|itm|wiktionary|wikt;wiktionary"
)));
return this;
}
public Xow_xwiki_mgr_fxt Test_add_bulk_langs(String langs, Xow_xwiki_itm... itms) {
xwiki_mgr.Add_bulk_langs(Bry_.new_u8(langs));
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(To_ary(itms)));
return this;
}
public Xow_xwiki_mgr_fxt Test_add_bulk_peers(String peers, Xow_xwiki_itm... itms) {
xwiki_mgr.Add_bulk_peers(Bry_.new_u8(peers));
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(To_ary(itms)));
return this;
}
public Xow_xwiki_mgr_fxt Tst_itms(Xow_xwiki_itm... itms) {
Tfds.Eq_str_lines(Xto_str(itms), Xto_str(To_ary(itms)));
return this;
}
public Xow_xwiki_mgr_fxt Exec_add_bulk(String raw) {xwiki_mgr.Add_bulk(Bry_.new_u8(raw)); return this;}
public Xow_xwiki_mgr_fxt Test_len(int expd) {Tfds.Eq(expd, xwiki_mgr.Len()); return this;}
Xow_xwiki_itm[] To_ary(Xow_xwiki_itm[] itms) {
int len = itms.length;
List_adp rv = List_adp_.new_();
for (int i = 0; i < len; i++) {
byte[] alias = itms[i].Key_bry();
Xow_xwiki_itm itm = xwiki_mgr.Get_by_key(alias);
if (itm == null) itm = xwiki_null_(String_.new_u8(alias)); // "null", ignore
rv.Add(itm);
}
return (Xow_xwiki_itm[])rv.To_ary(Xow_xwiki_itm.class);
}
String Xto_str(Xow_xwiki_itm[] itms) {
int len = itms.length;
for (int i = 0; i < len; i++) {
Xow_xwiki_itm itm = itms[i];
if (Bry_.Len_eq_0(itm.Domain_bry())) // "null", ignore
sb.Add(itm.Key_bry()).Add_char_nl();
else {
sb.Add(itm.Key_bry()).Add_char_pipe().Add(itm.Domain_bry()).Add_char_pipe().Add(itm.Url_fmt()).Add_char_pipe().Add(itm.Domain_tid()).Add_char_nl();
}
}
return sb.Xto_str_and_clear();
}
}