mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.2.1
This commit is contained in:
@@ -21,10 +21,10 @@ 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:
|
||||
case Xow_ns_.Tid__mediawiki:
|
||||
case Xow_ns_.Tid__user:
|
||||
return Identify_by_ttl(ttl);
|
||||
case gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module:
|
||||
case Xow_ns_.Tid__module:
|
||||
return (Bry_.Has_at_end(ttl, Ext_doc))
|
||||
? Tid_wikitext : Tid_lua;
|
||||
default:
|
||||
|
||||
@@ -98,7 +98,7 @@ public class Xowv_wiki implements Xow_wiki, Xow_ttl_parser, GfoInvkAble {
|
||||
}
|
||||
public void Pages_get(Xoh_page rv, Gfo_url url, Xoa_ttl ttl) {
|
||||
if (init_needed) Init_by_wiki();
|
||||
if (ttl.Ns().Id_special())
|
||||
if (ttl.Ns().Id_is_special())
|
||||
special_mgr.Get_by_ttl(rv, url, ttl);
|
||||
else
|
||||
html__hdump_mgr.Load_mgr().Load(rv, ttl);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class Xoctg_html_mgr implements GfoInvkAble {
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] all_label = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_label(), view_ctg.Name());
|
||||
byte[] all_stats = msg_mgr.Val_by_id_args(fmtr_all.Msg_id_stats(), view_grp.Len(), view_grp.Total());
|
||||
Xoa_ttl ctg_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, view_ctg.Name());
|
||||
Xoa_ttl ctg_ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__category, view_ctg.Name());
|
||||
byte[] all_navs = fmtr_all.Bld_bwd_fwd(wiki, ctg_ttl, view_grp);
|
||||
fmtr_grp.Init_from_all(wiki, lang, view_ctg, fmtr_all, view_grp);
|
||||
fmtr_all.Html_all().Bld_bfr_many(bfr, fmtr_all.Div_id(), all_label, all_stats, all_navs, lang.Key_bry(), lang.Dir_ltr_bry(), fmtr_grp);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Xoctg_pagelist_itms implements Bry_fmtr_arg {
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)itms.Get_at(i);
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Id_category, page.Ttl_page_db());
|
||||
Xoa_ttl ttl = Xoa_ttl.parse(wiki, Xow_ns_.Tid__category, page.Ttl_page_db());
|
||||
byte[] lnki_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
byte[] lnki_href = href_wtr.Build_to_bry(wiki, ttl);
|
||||
byte[] lnki_ttl = ttl.Full_txt();
|
||||
|
||||
@@ -39,10 +39,10 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
rv.Url_(url); // NOTE: must update page.Url(); should combine with Xoae_page.new_()
|
||||
Xow_ns ns = ttl.Ns();
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Id_special:
|
||||
case Xow_ns_.Tid__special:
|
||||
wiki.Special_mgr().Special_gen(wiki, rv, url, ttl);
|
||||
return rv;
|
||||
case Xow_ns_.Id_mediawiki:
|
||||
case Xow_ns_.Tid__mediawiki:
|
||||
if ( !called_from_msg // if called from msg, fall through to actual data retrieval below, else infinite loop; DATE:2014-05-09
|
||||
&& Xow_page_tid.Identify_by_ttl(ttl.Page_db()) == Xow_page_tid.Tid_wikitext // skip ".js" and ".css" pages in MediaWiki; DATE:2014-06-13
|
||||
) {
|
||||
@@ -57,7 +57,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
}
|
||||
break;
|
||||
}
|
||||
return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect,Xoa_url_.Qarg__redirect__yes));
|
||||
return Get_page(rv, ns, ttl, called_from_tmpl, url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
|
||||
}
|
||||
public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) {
|
||||
int redirects = 0;
|
||||
@@ -71,7 +71,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
byte[] bry = db_page.Text();
|
||||
rv.Data_raw_(bry).Revision_data().Modified_on_(db_page.Modified_on()).Id_(db_page.Id()).Html_db_id_(db_page.Html_db_id());
|
||||
if (redirect_force) return rv;
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry, bry.length);
|
||||
Xoa_ttl redirect_ttl = redirect_mgr.Extract_redirect(bry);
|
||||
if ( redirect_ttl == null // not a redirect
|
||||
|| redirects++ > 4) // too many redirects; something went wrong
|
||||
break;
|
||||
@@ -101,7 +101,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
}
|
||||
}
|
||||
if (vnt_missing) {
|
||||
if (ttl.Ns().Id_file()) {
|
||||
if (ttl.Ns().Id_is_file()) {
|
||||
Xowe_wiki commons_wiki = wiki.Appe().Wiki_mgr().Get_by_key_or_null(wiki.Commons_wiki_key());
|
||||
if (commons_wiki != null) { // commons exists
|
||||
if (!Bry_.Eq(wiki.Domain_bry(), commons_wiki.Domain_bry())) { // !Bry_.Eq is recursion guard
|
||||
@@ -133,7 +133,7 @@ public class Xow_data_mgr implements GfoInvkAble {
|
||||
Xoa_ttl trg_ttl = Xoa_ttl.parse(wiki, page_bry);
|
||||
Xoa_url trg_url = Xoa_url.new_(wiki.Domain_bry(), page_bry);
|
||||
page.Ttl_(trg_ttl).Url_(trg_url).Redirected_(true);
|
||||
return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__yes));
|
||||
return wiki.Data_mgr().Get_page(page, trg_ttl.Ns(), trg_ttl, false, trg_url.Qargs_mgr().Match(Xoa_url_.Qarg__redirect, Xoa_url_.Qarg__redirect__no));
|
||||
}
|
||||
public static final int File_idx_unknown = -1;
|
||||
static final String GRP_KEY = "xowa.wiki.data";
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Xow_data_mgr_tst {
|
||||
;
|
||||
}
|
||||
@Test public void Update_zip() {
|
||||
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Id_main].Ext_tid_(gplx.core.ios.Io_stream_.Tid_zip);
|
||||
// fxt.Wiki().Fsys_mgr().Dir_regy()[Xow_ns_.Tid__main].Ext_tid_(gplx.core.ios.Io_stream_.Tid_zip);
|
||||
// fxt.Wiki().Data_mgr().Zip_mgr_(new Io_zip_mgr_mok());
|
||||
// fxt .Create("A1", "A1 data")
|
||||
// .Create("B12", "B12 data")
|
||||
@@ -154,8 +154,8 @@ class Xow_data_mgr_fxt {
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(file_orig));
|
||||
return this;
|
||||
}
|
||||
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Id_main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Id_main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_page(String expd) {return Tst_data(Xotdb_dir_info_.Tid_page , Xow_ns_.Tid__main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data_title(String expd) {return Tst_data(Xotdb_dir_info_.Tid_ttl, Xow_ns_.Tid__main, 0, expd);}
|
||||
public Xow_data_mgr_fxt Tst_data(byte dir_tid, int ns_id, int fil, String expd) {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(dir_tid, ns_id, fil);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
|
||||
@@ -85,7 +85,7 @@ public class Xowd_page_itm {
|
||||
}
|
||||
else {
|
||||
ns = (Xow_ns)o;
|
||||
ttl_page_db = Bry_.Mid(v, ns.Name_txt_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
|
||||
ttl_page_db = Bry_.Mid(v, ns.Name_ui_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
|
||||
}
|
||||
ns_id = ns.Id();
|
||||
return this;
|
||||
|
||||
@@ -20,16 +20,16 @@ import org.junit.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.n
|
||||
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");
|
||||
fxt.Test_ttl_("User_talk:A", Xow_ns_.Tid__user_talk, "A");
|
||||
fxt.Test_ttl_("User talk:A", Xow_ns_.Tid__user_talk, "A");
|
||||
}
|
||||
}
|
||||
class Xowd_page_itm_fxt {
|
||||
public void Init() {
|
||||
if (ns_mgr == null) {
|
||||
ns_mgr = new Xow_ns_mgr(gplx.xowa.langs.cases.Xol_case_mgr_.A7());
|
||||
ns_mgr.Add_new(Xow_ns_.Id_main, "");
|
||||
ns_mgr.Add_new(Xow_ns_.Id_user_talk, "User talk");
|
||||
ns_mgr.Add_new(Xow_ns_.Tid__main, "");
|
||||
ns_mgr.Add_new(Xow_ns_.Tid__user_talk, "User talk");
|
||||
ns_mgr.Init_w_defaults();
|
||||
tmp_page = new Xowd_page_itm();
|
||||
}
|
||||
|
||||
@@ -167,10 +167,10 @@ public class Xowd_page_tbl implements RlsAble {
|
||||
}
|
||||
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, ""));
|
||||
Criteria crt = Criteria_.And_many(Db_crt_.eq_(fld_ns, Xow_ns_.Tid__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();
|
||||
Db_rdr rdr = conn.Stmt_new(qry).Clear().Crt_int(fld_ns, Xow_ns_.Tid__main).Val_bry_as_str(fld_title, search).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
if (cancelable.Canceled()) return;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class Xowd_site_ns_tbl {
|
||||
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_str(fld_name, ns.Name_db_str())
|
||||
.Val_byte(fld_case, ns.Case_match())
|
||||
.Val_bool_as_byte(fld_is_alias, ns.Is_alias())
|
||||
.Val_int(fld_count, ns.Count())
|
||||
|
||||
@@ -47,6 +47,7 @@ public class Xowd_text_tbl implements RlsAble {
|
||||
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);
|
||||
if (rv == null) rv = Bry_.Empty; // NOTE: defect wherein blank page inserts null not ""; for now always convert nul to empty String; DATE:2015-11-08
|
||||
rv = zip_mgr.Unzip(zip_tid, rv);
|
||||
return rv;
|
||||
} finally {rdr.Rls();}
|
||||
|
||||
@@ -22,9 +22,9 @@ 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");
|
||||
fxt.Exec_insert("enwiki", Xow_ns_.Tid__main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A B", "q1");
|
||||
fxt.Test_select("enwiki", Xow_ns_.Tid__main, "A_B", "q1");
|
||||
}
|
||||
}
|
||||
class Xowd_wbase_qid_tbl_fxt {
|
||||
|
||||
@@ -64,13 +64,13 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
public boolean Load_by_id (Xowd_page_itm rv, int id) {return db_mgr.Core_data_mgr().Tbl__page().Select_by_id(rv, id);}
|
||||
public void Load_by_ids(Cancelable cancelable, List_adp rv, int bgn, int end) {db_mgr.Core_data_mgr().Tbl__page().Select_in__id(cancelable, false, rv, bgn, end);}
|
||||
public boolean Load_ctg_v1(Xoctg_view_ctg rv, byte[] ctg_bry) {
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false;
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ctg_bry); if (cat_page_id == Xowd_page_itm.Id_null) return false;
|
||||
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return false;
|
||||
return Ctg_select_v1(db_mgr.Wiki(), db_mgr.Core_data_mgr(), rv, ctg.File_idx(), ctg);
|
||||
}
|
||||
public boolean Load_ctg_v2(Xoctg_data_ctg rv, byte[] ctg_bry) {throw Err_.new_unimplemented();}
|
||||
public void Load_ctg_v2a(Xoctg_view_ctg rv, Xoctg_url ctg_url, byte[] ctg_ttl, int load_max) {
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return;
|
||||
int cat_page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ctg_ttl); if (cat_page_id == Xowd_page_itm.Id_null) return;
|
||||
Xowd_category_itm ctg = fsys_mgr.Db__cat_core().Tbl__cat_core().Select(cat_page_id); if (ctg == Xowd_category_itm.Null) return;
|
||||
List_adp list = List_adp_.new_();
|
||||
Load_ctg_v2a_db_retrieve(rv, ctg_url, cat_page_id, load_max, ctg.File_idx(), list);
|
||||
@@ -143,7 +143,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
}
|
||||
public int Load_ctg_count(byte[] ttl) {
|
||||
if (db_mgr.Core_data_mgr().Db__cat_core() == null) return 0;
|
||||
int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Id_category, ttl);
|
||||
int page_id = db_mgr.Core_data_mgr().Tbl__page().Select_id(Xow_ns_.Tid__category, ttl);
|
||||
if (page_id == Xowd_page_itm.Id_null) return 0; // title not found; return 0;
|
||||
return db_mgr.Core_data_mgr().Db__cat_core().Tbl__cat_core().Select(page_id).Count_all();
|
||||
}
|
||||
@@ -164,7 +164,7 @@ public class Xodb_load_mgr_sql implements Xodb_load_mgr {
|
||||
hash.Add(ttl, page);
|
||||
}
|
||||
len = hash.Count(); // must update len (!hash.Has() may have skipped titles)
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Id_category, 0, len);
|
||||
db_mgr.Core_data_mgr().Tbl__page().Select_in__ttl(Cancelable_.Never, hash, Xow_ns_.Tid__category, 0, len);
|
||||
Ordered_hash hash2 = Ordered_hash_.New();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xowd_page_itm page = (Xowd_page_itm)hash.Get_at(i);
|
||||
|
||||
@@ -53,7 +53,7 @@ class Xodb_load_mgr_sql_fxt {
|
||||
public void Rls() {fxt.Rls();}
|
||||
public Xowd_page_itm[] pages_(Xowd_page_itm... ary) {return ary;}
|
||||
public Xowd_page_itm ctg_(int id, String ttl, boolean hidden, int count_subcs, int count_files, int count_pages) {
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Id_category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl));
|
||||
Xowd_page_itm rv = new Xowd_page_itm().Ns_id_(Xow_ns_.Tid__category).Id_(id).Ttl_page_db_(Bry_.new_a7(ttl));
|
||||
Xowd_category_itm ctg = Xowd_category_itm.load_(id, 0, hidden, count_subcs, count_files, count_pages);
|
||||
rv.Xtn_(ctg);
|
||||
return rv;
|
||||
@@ -157,7 +157,7 @@ class Xoctg_mok_ctg {
|
||||
public Xoctg_mok_ctg Grp_pages_(int bgn, int end, String last_itm_plus_one_sortkey) {
|
||||
Xoctg_mok_grp grp = Grps_get_or_new(Xoa_ctg_mgr.Tid_page);
|
||||
byte[] ttl_prefix = Bry_.new_a7("Page_");
|
||||
int ns_id = Xow_ns_.Id_main;
|
||||
int ns_id = Xow_ns_.Tid__main;
|
||||
byte ctg_tid = Xoa_ctg_mgr.Tid_page;
|
||||
for (int i = bgn; i < end; i++) {
|
||||
byte[] ttl = Bry_.Add(ttl_prefix, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 3)));
|
||||
|
||||
@@ -344,8 +344,8 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
}
|
||||
public static byte Load_ctg_v1_tid(int ns_id) {
|
||||
switch (ns_id) {
|
||||
case Xow_ns_.Id_category: return Xoa_ctg_mgr.Tid_subc;
|
||||
case Xow_ns_.Id_file: return Xoa_ctg_mgr.Tid_file;
|
||||
case Xow_ns_.Tid__category: return Xoa_ctg_mgr.Tid_subc;
|
||||
case Xow_ns_.Tid__file: return Xoa_ctg_mgr.Tid_file;
|
||||
default: return Xoa_ctg_mgr.Tid_page;
|
||||
}
|
||||
}
|
||||
@@ -363,7 +363,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
byte[] ttl = Bry_.Mid (src, bgn + 12 , ttl_end);
|
||||
byte[] text = Bry_.Mid (src, ttl_end + 1 , itm_end - 1);
|
||||
page.Init_by_tdb(-1, -1, xdat.Itm_idx(), Bool_.N, text.length, ns_id, ttl);
|
||||
page.Modified_on_(Bit_.Xto_date_short(timestamp));
|
||||
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
|
||||
page.Text_(text);
|
||||
return true;
|
||||
}
|
||||
@@ -372,7 +372,7 @@ public class Xodb_load_mgr_txt implements Xodb_load_mgr {
|
||||
int timestamp_end = timestamp_bgn + 5;
|
||||
if (timestamp_enabled) {
|
||||
int timestamp = Base85_.To_int_by_bry(src, timestamp_bgn, timestamp_end - 1);
|
||||
page.Modified_on_(Bit_.Xto_date_short(timestamp));
|
||||
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
|
||||
}
|
||||
int name_bgn = timestamp_end + 1;
|
||||
int name_end = Bry_find_.Find_fwd(src, Xotdb_page_itm_.Txt_page_dlm, name_bgn, src_len);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class Xodb_mgr_txt implements Xodb_mgr {
|
||||
public Xodb_load_mgr Load_mgr() {return load_mgr;} private Xodb_load_mgr_txt load_mgr;
|
||||
public Xodb_save_mgr Save_mgr() {return save_mgr;} private Xodb_save_mgr_txt save_mgr;
|
||||
public DateAdp Dump_date_query() {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 0);
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 0);
|
||||
return Io_mgr.Instance.QueryFil(url).ModifiedTime();
|
||||
}
|
||||
public byte Category_version() {
|
||||
|
||||
@@ -17,68 +17,69 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.bldrs.cmds.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xow_ns implements GfoInvkAble {
|
||||
public class Xow_ns implements GfoInvkAble {
|
||||
public Xow_ns(int id, byte case_match, byte[] name, boolean is_alias) {
|
||||
this.id = id; this.case_match = case_match; this.is_alias = is_alias;
|
||||
Name_bry_(name);
|
||||
}
|
||||
public void Name_bry_(byte[] v) {
|
||||
if (id == Xow_ns_.Id_main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test"
|
||||
this.name_str = "";
|
||||
this.name_bry = Bry_.Empty;
|
||||
if (id == Xow_ns_.Tid__main) { // NOTE: Main will never prefix titles; EX: "Test" vs "Category:Test"
|
||||
this.name_db_str = "";
|
||||
this.name_db = Bry_.Empty;
|
||||
this.name_db_w_colon = Bry_.Empty;
|
||||
}
|
||||
else {
|
||||
this.name_bry = v;
|
||||
this.name_db = v;
|
||||
this.name_db_w_colon = Bry_.Add(v, Byte_ascii.Colon);
|
||||
this.name_str = String_.new_u8(v);
|
||||
this.name_db_str = String_.new_u8(v);
|
||||
}
|
||||
this.num_str = Int_.To_str_pad_bgn_zero(id, 3);
|
||||
this.num_bry = Bry_.new_a7(num_str);
|
||||
this.name_enc = Xoa_url_encoder.Instance.Encode(name_bry);
|
||||
this.name_txt = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
this.name_txt_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
this.name_enc = Xoa_url_encoder.Instance.Encode(name_db);
|
||||
this.name_ui = Bry_.Replace(name_enc, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
this.name_ui_w_colon = Bry_.Replace(name_db_w_colon, Byte_ascii.Underline, Byte_ascii.Space);
|
||||
}
|
||||
public byte[] Name_bry() {return name_bry;} private byte[] name_bry;
|
||||
public String Name_str() {return name_str;} private String name_str;
|
||||
public byte[] Name_txt() {return name_txt;} private byte[] name_txt;
|
||||
public byte[] Name_enc() {return name_enc;} private byte[] name_enc;
|
||||
public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
|
||||
public byte[] Name_db() {return name_db;} private byte[] name_db;
|
||||
public byte[] Name_db_w_colon() {return name_db_w_colon;} private byte[] name_db_w_colon;
|
||||
public byte[] Name_txt_w_colon() {return name_txt_w_colon;} private byte[] name_txt_w_colon; // PERF: for Xoa_ttl
|
||||
public byte[] Name_ui() {return id == Xow_ns_.Id_main ? Xow_ns_.Name_ui_main : name_txt;}
|
||||
public String Name_db_str() {return name_db_str;} private String name_db_str;
|
||||
public byte[] Name_ui() {return name_ui;} private byte[] name_ui;
|
||||
public byte[] Name_ui_w_colon() {return name_ui_w_colon;} private byte[] name_ui_w_colon; // PERF: for Xoa_ttl
|
||||
public byte[] Name_enc() {return name_enc;} private byte[] name_enc;
|
||||
public byte[] Name_combo() {return id == Xow_ns_.Tid__main ? Xow_ns_.Bry__main: name_ui;} // for combo boxes; namely "(Main)"
|
||||
public String Num_str() {return num_str;} private String num_str;
|
||||
public byte[] Num_bry() {return num_bry;} private byte[] num_bry;
|
||||
public int Id() {return id;} private int id;
|
||||
public int Id_subj_id() {if (id < 0) return id; return Id_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject
|
||||
public int Id_talk_id() {if (id < 0) return id; return Id_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk
|
||||
public int Id_alt_id() {if (id < 0) return id; return Id_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk
|
||||
public boolean Id_subj() {return !Id_talk();} // REF.MW: Namespace.php|isMain
|
||||
public boolean Id_talk() {return id > Xow_ns_.Id_main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk
|
||||
public boolean Id_file() {return id == Xow_ns_.Id_file;}
|
||||
public boolean Id_file_or_media() {return id == Xow_ns_.Id_file || id == Xow_ns_.Id_media;}
|
||||
public boolean Id_tmpl() {return id == Xow_ns_.Id_template;}
|
||||
public boolean Id_ctg() {return id == Xow_ns_.Id_category;}
|
||||
public boolean Id_main() {return id == Xow_ns_.Id_main;}
|
||||
public boolean Id_media() {return id == Xow_ns_.Id_media;}
|
||||
public boolean Id_special() {return id == Xow_ns_.Id_special;}
|
||||
public boolean Id_module() {return id == gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module;}
|
||||
public int Id_subj_id() {if (id < 0) return id; return Id_is_talk() ? id - 1 : id;} // id< 0: special/media return themself; REF.MW: Namespace.php|getSubject
|
||||
public int Id_talk_id() {if (id < 0) return id; return Id_is_talk() ? id : id + 1;} // REF.MW: Namespace.php|getTalk
|
||||
public int Id_alt_id() {if (id < 0) return id; return Id_is_talk() ? Id_subj_id() : Id_talk_id();} // REF.MW: Namespace.php|getTalk
|
||||
public boolean Id_is_subj() {return !Id_is_talk();} // REF.MW: Namespace.php|isMain
|
||||
public boolean Id_is_talk() {return id > Xow_ns_.Tid__main && id % 2 == 1;} // REF.MW: Namespace.php|isTalk
|
||||
public boolean Id_is_media() {return id == Xow_ns_.Tid__media;}
|
||||
public boolean Id_is_special() {return id == Xow_ns_.Tid__special;}
|
||||
public boolean Id_is_main() {return id == Xow_ns_.Tid__main;}
|
||||
public boolean Id_is_file() {return id == Xow_ns_.Tid__file;}
|
||||
public boolean Id_is_file_or_media() {return id == Xow_ns_.Tid__file || id == Xow_ns_.Tid__media;}
|
||||
public boolean Id_is_tmpl() {return id == Xow_ns_.Tid__template;}
|
||||
public boolean Id_is_ctg() {return id == Xow_ns_.Tid__category;}
|
||||
public boolean Id_is_module() {return id == Xow_ns_.Tid__module;}
|
||||
public int Ord() {return ord;} public void Ord_(int v) {this.ord = v;} private int ord;
|
||||
public int Ord_subj_id() {if (id < 0) return ord; return Id_talk() ? ord - 1 : ord;} // id< 0: special/media returns self
|
||||
public int Ord_talk_id() {if (id < 0) return ord; return Id_talk() ? ord : ord + 1;}
|
||||
public int Ord_subj_id() {if (id < 0) return ord; return Id_is_talk() ? ord - 1 : ord;} // id< 0: special/media returns self
|
||||
public int Ord_talk_id() {if (id < 0) return ord; return Id_is_talk() ? ord : ord + 1;}
|
||||
public byte Case_match() {return case_match;} public void Case_match_(byte v) {case_match = v;} private byte case_match;
|
||||
public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Id_special; only Special, Media does not have subpages; DATE:2013-10-07
|
||||
public boolean Subpages_enabled() {return subpages_enabled;} private boolean subpages_enabled = false;// CHANGED: id > Xow_ns_.Tid__special; only Special, Media does not have subpages; DATE:2013-10-07
|
||||
public Xow_ns Subpages_enabled_(boolean v) {subpages_enabled = v; return this;}
|
||||
public boolean Is_gender_aware() {return id == Xow_ns_.Id_user || id == Xow_ns_.Id_user_talk;} // ASSUME: only User, User_talk are gender aware
|
||||
public boolean Is_capitalized() {return false;} // ASSUME: always false (?)
|
||||
public boolean Is_content() {return id == Xow_ns_.Id_main;} // ASSUME: only Main
|
||||
public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?)
|
||||
public boolean Is_movable() {return id > Xow_ns_.Id_special;} // ASSUME: only Special, Media cannot move (be renamed?)
|
||||
public boolean Is_meta() {return id < Xow_ns_.Id_main;} // ASSUME: only Special, Media
|
||||
public boolean Is_gender_aware() {return id == Xow_ns_.Tid__user || id == Xow_ns_.Tid__user_talk;} // ASSUME: only User, User_talk are gender aware
|
||||
public boolean Is_capitalized() {return false;} // ASSUME: always false (?)
|
||||
public boolean Is_content() {return id == Xow_ns_.Tid__main;} // ASSUME: only Main
|
||||
public boolean Is_includable() {return true;} // ASSUME: always true (be transcluded?)
|
||||
public boolean Is_movable() {return id > Xow_ns_.Tid__special;} // ASSUME: only Special, Media cannot move (be renamed?)
|
||||
public boolean Is_meta() {return id < Xow_ns_.Tid__main;} // ASSUME: only Special, Media
|
||||
public boolean Is_alias() {return is_alias;} private boolean is_alias;
|
||||
public int Count() {return count;} public Xow_ns Count_(int v) {count = v; return this;} private int count;
|
||||
public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Id_main ? page : Bry_.Add(name_db_w_colon, page);}
|
||||
public byte[] Gen_ttl(byte[] page) {return id == Xow_ns_.Tid__main ? page : Bry_.Add(name_db_w_colon, page);}
|
||||
public void Aliases_add(String alias) {
|
||||
if (String_.Eq(alias, name_str)) return;
|
||||
if (String_.Eq(alias, name_db_str)) return;
|
||||
if (aliases == null) aliases = Ordered_hash_.New();
|
||||
aliases.Add_if_dupe_use_1st(alias, alias);
|
||||
} private Ordered_hash aliases;
|
||||
@@ -92,13 +93,12 @@ public class Xow_ns implements GfoInvkAble {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public boolean Exists() {return exists;} public Xow_ns Exists_(boolean v) {exists = v; return this;} private boolean exists;
|
||||
public Xob_ns_file_itm Bldr_data() {return bldr_data;} public void Bldr_data_(Xob_ns_file_itm v) {bldr_data = v;} private Xob_ns_file_itm bldr_data;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_subpages_enabled_)) this.subpages_enabled = m.ReadYn("v");
|
||||
else if (ctx.Match(k, Invk_id)) return id;
|
||||
else if (ctx.Match(k, Invk_name_txt)) return name_txt;
|
||||
else if (ctx.Match(k, Invk_name_ui)) return Name_ui();
|
||||
else if (ctx.Match(k, Invk_name_txt)) return name_ui;
|
||||
else if (ctx.Match(k, Invk_name_ui)) return Name_combo();
|
||||
else return GfoInvkAble_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_subpages_enabled_ = "subpages_enabled_", Invk_id = "id", Invk_name_txt = "name_txt", Invk_name_ui = "name_ui";
|
||||
|
||||
@@ -16,74 +16,44 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xow_ns_ {
|
||||
public class Xow_ns_ {
|
||||
public static final int // PAGE:en.w:http://www.mediawiki.org/wiki/Help:Namespaces
|
||||
Id_media = -2
|
||||
, Id_special = -1
|
||||
, Id_main = 0 , Id_talk = 1
|
||||
, Id_user = 2 , Id_user_talk = 3
|
||||
, Id_project = 4 , Id_project_talk = 5
|
||||
, Id_file = 6 , Id_file_talk = 7
|
||||
, Id_mediawiki = 8 , Id_mediaWiki_talk = 9
|
||||
, Id_template = 10 , Id_template_talk = 11
|
||||
, Id_help = 12 , Id_help_talk = 13
|
||||
, Id_category = 14 , Id_category_talk = 15
|
||||
, Id_portal = 100 , Id_portal_talk = 101
|
||||
, Id_null = Int_.Min_value
|
||||
;
|
||||
Tid__media = -2
|
||||
, Tid__special = -1
|
||||
, Tid__main = 0 , Tid__talk = 1
|
||||
, Tid__user = 2 , Tid__user_talk = 3
|
||||
, Tid__project = 4 , Tid__project_talk = 5
|
||||
, Tid__file = 6 , Tid__file_talk = 7
|
||||
, Tid__mediawiki = 8 , Tid__mediawiki_talk = 9
|
||||
, Tid__template = 10 , Tid__template_talk = 11
|
||||
, Tid__help = 12 , Tid__help_talk = 13
|
||||
, Tid__category = 14 , Tid__category_talk = 15
|
||||
, Tid__portal = 100 , Tid__portal_talk = 101
|
||||
, Tid__module = 828 , Tid__module_talk = 829
|
||||
, Tid__null = Int_.Min_value
|
||||
;
|
||||
public static final String
|
||||
Key_media = "Media"
|
||||
, Key_special = "Special"
|
||||
, Key_main = "(Main)" , Key_talk = "Talk"
|
||||
, Key_user = "User" , Key_user_talk = "User talk"
|
||||
, Key_project = "Project" , Key_project_talk = "Project talk"
|
||||
, Key_file = "File" , Key_file_talk = "File talk"
|
||||
, Key_mediaWiki = "MediaWiki" , Key_mediaWiki_talk = "MediaWiki talk"
|
||||
, Key_template = "Template" , Key_template_talk = "Template talk"
|
||||
, Key_help = "Help" , Key_help_talk = "Help talk"
|
||||
, Key_category = "Category" , Key_category_talk = "Category talk"
|
||||
, Key_portal = "Portal" , Key_portal_talk = "Portal talk"
|
||||
, Key_module = "Module" , Key_module_talk = "Module talk"
|
||||
, Key_null = "null"
|
||||
;
|
||||
public static final byte[] Bry_template = Bry_.new_a7(Key_template);
|
||||
public static final byte[] Name_ui_main = Bry_.new_a7(Key_main);
|
||||
public static int Canonical_id(byte[] canonical_name) {
|
||||
if (canonical_hash == null) {
|
||||
Xow_ns[] ary = Canonical;
|
||||
int len = ary.length;
|
||||
canonical_hash = Ordered_hash_.New_bry();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xow_ns ns = ary[i];
|
||||
canonical_hash.Add(ns.Name_bry(), Int_obj_val.new_(ns.Id()));
|
||||
}
|
||||
}
|
||||
Object rv_obj = canonical_hash.Get_by(canonical_name);
|
||||
return rv_obj == null ? Xow_ns_.Id_null : ((Int_obj_val)rv_obj).Val();
|
||||
} private static Ordered_hash canonical_hash;
|
||||
public static int Canonical_idx_media = 0;
|
||||
public static final Xow_ns[] Canonical = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames
|
||||
{ Canonical_new_(Id_media, Key_media)
|
||||
, Canonical_new_(Id_special, Key_special)
|
||||
, Canonical_new_(Id_talk, Key_talk)
|
||||
, Canonical_new_(Id_user, Key_user)
|
||||
, Canonical_new_(Id_user_talk, Key_user_talk)
|
||||
, Canonical_new_(Id_project, Key_project)
|
||||
, Canonical_new_(Id_project_talk, Key_project_talk)
|
||||
, Canonical_new_(Id_file, Key_file)
|
||||
, Canonical_new_(Id_file_talk, Key_file_talk)
|
||||
, Canonical_new_(Id_mediawiki, Key_mediaWiki)
|
||||
, Canonical_new_(Id_mediaWiki_talk, Key_mediaWiki_talk)
|
||||
, Canonical_new_(Id_template, Key_template)
|
||||
, Canonical_new_(Id_template_talk, Key_template_talk)
|
||||
, Canonical_new_(Id_help, Key_help)
|
||||
, Canonical_new_(Id_help_talk, Key_help_talk)
|
||||
, Canonical_new_(Id_category, Key_category)
|
||||
, Canonical_new_(Id_category_talk, Key_category_talk)
|
||||
};
|
||||
public static final String Ns_name_wikipedia = "Wikipedia";
|
||||
public static final byte[] Ns_name_main_bry = Bry_.new_a7(Key_main);
|
||||
public static final byte[] Ns_prefix_main = Bry_.new_a7("Main:");
|
||||
private static Xow_ns Canonical_new_(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
|
||||
Key__media = "Media"
|
||||
, Key__special = "Special"
|
||||
, Key__main = "(Main)" , Key__talk = "Talk"
|
||||
, Key__user = "User" , Key__user_talk = "User talk"
|
||||
, Key__project = "Project" , Key__project_talk = "Project talk"
|
||||
, Key__file = "File" , Key__file_talk = "File talk"
|
||||
, Key__mediawiki = "MediaWiki" , Key__mediawiki_talk = "MediaWiki talk"
|
||||
, Key__template = "Template" , Key__template_talk = "Template talk"
|
||||
, Key__help = "Help" , Key__help_talk = "Help talk"
|
||||
, Key__category = "Category" , Key__category_talk = "Category talk"
|
||||
, Key__portal = "Portal" , Key__portal_talk = "Portal talk"
|
||||
, Key__module = "Module" , Key__module_talk = "Module talk"
|
||||
, Key__null = "null"
|
||||
, Key__wikipedia = "Wikipedia"
|
||||
;
|
||||
public static final String
|
||||
Alias__wikipedia = "Wikipedia"
|
||||
;
|
||||
public static final byte[]
|
||||
Bry__main = Bry_.new_a7(Key__main)
|
||||
, Bry__file = Bry_.new_a7(Key__file)
|
||||
, Bry__template = Bry_.new_a7(Key__template)
|
||||
;
|
||||
}
|
||||
|
||||
80
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java
Normal file
80
400_xowa/src/gplx/xowa/wikis/nss/Xow_ns_canonical_.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.wikis.nss; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import gplx.core.primitives.*;
|
||||
public class Xow_ns_canonical_ {
|
||||
public static final Xow_ns[] Ary = new Xow_ns[] // REF.MW: Namespace.php|$wgCanonicalNamespaceNames
|
||||
{ New_itm(Xow_ns_.Tid__media , Xow_ns_.Key__media)
|
||||
, New_itm(Xow_ns_.Tid__special , Xow_ns_.Key__special)
|
||||
, New_itm(Xow_ns_.Tid__talk , Xow_ns_.Key__talk)
|
||||
, New_itm(Xow_ns_.Tid__user , Xow_ns_.Key__user)
|
||||
, New_itm(Xow_ns_.Tid__user_talk , Xow_ns_.Key__user_talk)
|
||||
, New_itm(Xow_ns_.Tid__project , Xow_ns_.Key__project)
|
||||
, New_itm(Xow_ns_.Tid__project_talk , Xow_ns_.Key__project_talk)
|
||||
, New_itm(Xow_ns_.Tid__file , Xow_ns_.Key__file)
|
||||
, New_itm(Xow_ns_.Tid__file_talk , Xow_ns_.Key__file_talk)
|
||||
, New_itm(Xow_ns_.Tid__mediawiki , Xow_ns_.Key__mediawiki)
|
||||
, New_itm(Xow_ns_.Tid__mediawiki_talk , Xow_ns_.Key__mediawiki_talk)
|
||||
, New_itm(Xow_ns_.Tid__template , Xow_ns_.Key__template)
|
||||
, New_itm(Xow_ns_.Tid__template_talk , Xow_ns_.Key__template_talk)
|
||||
, New_itm(Xow_ns_.Tid__help , Xow_ns_.Key__help)
|
||||
, New_itm(Xow_ns_.Tid__help_talk , Xow_ns_.Key__help_talk)
|
||||
, New_itm(Xow_ns_.Tid__category , Xow_ns_.Key__category)
|
||||
, New_itm(Xow_ns_.Tid__category_talk , Xow_ns_.Key__category_talk)
|
||||
, New_itm(Xow_ns_.Tid__module , Xow_ns_.Key__module)
|
||||
, New_itm(Xow_ns_.Tid__module_talk , Xow_ns_.Key__module_talk)
|
||||
};
|
||||
private static Xow_ns New_itm(int id, String name) {return new Xow_ns(id, Xow_ns_case_.Tid__1st, Bry_.new_a7(name), false);} // NOTE: for id/name reference only; case_match and alias does not matter;
|
||||
private static Ordered_hash id_hash;
|
||||
public static int To_id(byte[] key) {
|
||||
if (id_hash == null) {
|
||||
id_hash = Ordered_hash_.New_bry();
|
||||
int len = Ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_ns ns = Ary[i];
|
||||
id_hash.Add(ns.Name_db(), Int_obj_val.new_(ns.Id()));
|
||||
}
|
||||
}
|
||||
Object rv_obj = id_hash.Get_by(key);
|
||||
return rv_obj == null ? Xow_ns_.Tid__null : ((Int_obj_val)rv_obj).Val();
|
||||
}
|
||||
public static String To_canonical_or_local(Xow_ns ns) { // NOTE: prefer canonical names if they exist; otherwise use local; PAGE:sh.w:Koprno; DATE:2015-11-08
|
||||
switch (ns.Id()) {
|
||||
case Xow_ns_.Tid__media: return Xow_ns_.Key__media;
|
||||
case Xow_ns_.Tid__special: return Xow_ns_.Key__special;
|
||||
case Xow_ns_.Tid__talk: return Xow_ns_.Key__talk;
|
||||
case Xow_ns_.Tid__user: return Xow_ns_.Key__user;
|
||||
case Xow_ns_.Tid__user_talk: return Xow_ns_.Key__user_talk;
|
||||
case Xow_ns_.Tid__project: return Xow_ns_.Key__project;
|
||||
case Xow_ns_.Tid__project_talk: return Xow_ns_.Key__project_talk;
|
||||
case Xow_ns_.Tid__file: return Xow_ns_.Key__file;
|
||||
case Xow_ns_.Tid__file_talk: return Xow_ns_.Key__file_talk;
|
||||
case Xow_ns_.Tid__mediawiki: return Xow_ns_.Key__mediawiki;
|
||||
case Xow_ns_.Tid__mediawiki_talk: return Xow_ns_.Key__mediawiki_talk;
|
||||
case Xow_ns_.Tid__template: return Xow_ns_.Key__template;
|
||||
case Xow_ns_.Tid__template_talk: return Xow_ns_.Key__template_talk;
|
||||
case Xow_ns_.Tid__help: return Xow_ns_.Key__help;
|
||||
case Xow_ns_.Tid__help_talk: return Xow_ns_.Key__help_talk;
|
||||
case Xow_ns_.Tid__category: return Xow_ns_.Key__category;
|
||||
case Xow_ns_.Tid__category_talk: return Xow_ns_.Key__category_talk;
|
||||
case Xow_ns_.Tid__module: return Xow_ns_.Key__module;
|
||||
case Xow_ns_.Tid__module_talk: return Xow_ns_.Key__module_talk;
|
||||
default: return String_.new_u8(ns.Name_ui());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,9 +101,9 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
for (int i = 0; i < ords_len; i++) {
|
||||
Xow_ns ns = ords[i];
|
||||
if (ns == null) continue; // TEST: allow gaps in ns numbers; see Talk_skip test and related
|
||||
if (ns.Id() == Xow_ns_.Id_project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort
|
||||
Rebuild_hashes__add(name_hash, ns, ns.Name_bry());
|
||||
if (ns.Id_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon());
|
||||
if (ns.Id() == Xow_ns_.Tid__project_talk) Fix_project_talk(ns); // NOTE: handle $1 talk as per Language.php!fixVariableInNamespace; placement is important as it must go before key registration but after ord sort
|
||||
Rebuild_hashes__add(name_hash, ns, ns.Name_db());
|
||||
if (ns.Id_is_tmpl()) tmpl_hash.Add(ns.Name_db_w_colon(), ns.Name_db_w_colon());
|
||||
}
|
||||
int aliases_len = aliases.Count();
|
||||
for (int i = 0; i < aliases_len; i++) {
|
||||
@@ -113,7 +113,7 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
ns.Aliases_add(kv.Key()); // register alias with official ns; EX: "Image" will be placed in "File"'s .Aliases
|
||||
byte[] alias_bry = Bry_.new_u8(kv.Key());
|
||||
Rebuild_hashes__add(name_hash, ns, alias_bry);
|
||||
if (ns.Id_tmpl()) {
|
||||
if (ns.Id_is_tmpl()) {
|
||||
byte[] alias_name = Bry_.new_u8(kv.Key());
|
||||
alias_name = Bry_.Add(alias_name, Byte_ascii.Colon);
|
||||
tmpl_hash.Add_if_dupe_use_nth(alias_name, alias_name);
|
||||
@@ -121,11 +121,11 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
}
|
||||
}
|
||||
private void Fix_project_talk(Xow_ns ns) {
|
||||
byte[] ns_name = ns.Name_bry();
|
||||
if (Bry_find_.Find_fwd(ns.Name_bry(), Project_talk_fmt_arg)== Bry_find_.Not_found) return; // no $1 found; exit
|
||||
byte[] ns_name = ns.Name_db();
|
||||
if (Bry_find_.Find_fwd(ns.Name_db(), Project_talk_fmt_arg)== Bry_find_.Not_found) return; // no $1 found; exit
|
||||
Xow_ns project_ns = ords[ns.Ord_subj_id()];
|
||||
if (project_ns == null) return; // should warn or throw error; for now just exit
|
||||
ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_bry()));
|
||||
ns.Name_bry_(Bry_.Replace(ns_name, Project_talk_fmt_arg, project_ns.Name_db()));
|
||||
} private static final byte[] Project_talk_fmt_arg = Bry_.new_a7("$1");
|
||||
private void Rebuild_hashes__add(Hash_adp_bry hash, Xow_ns ns, byte[] key) {
|
||||
Xow_ns_mgr_name_itm ns_itm = new Xow_ns_mgr_name_itm(key, ns);
|
||||
@@ -134,10 +134,10 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
hash.Add_if_dupe_use_nth(Bry_.Replace(key, Byte_ascii.Underline, Byte_ascii.Space), ns_itm);
|
||||
}
|
||||
public Xow_ns_mgr Add_defaults() { // NOTE: needs to happen after File ns is added; i.e.: cannot be put in Xow_ns_mgr() {} ctor
|
||||
Aliases_add(Xow_ns_.Id_file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well
|
||||
Aliases_add(Xow_ns_.Id_file_talk, "Image_talk");
|
||||
Aliases_add(Xow_ns_.Id_project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages
|
||||
Aliases_add(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module
|
||||
Aliases_add(Xow_ns_.Tid__file , "Image"); // REF.MW: Setup.php; add "Image", "Image talk" for backward compatibility; note that MW hardcodes Image ns as well
|
||||
Aliases_add(Xow_ns_.Tid__file_talk , "Image_talk");
|
||||
Aliases_add(Xow_ns_.Tid__project , "Project"); // always add "Project" ns (EX: Wikipedia is name for en.wikipedia.org; not sure if MW hardcodes, but it is in messages
|
||||
Aliases_add(Xow_ns_.Tid__module , "Module"); // always add "Module" ns; de.wikipedia.org has "Modul" defined in siteinfo.xml, but also uses Module
|
||||
return this;
|
||||
}
|
||||
public Xow_ns_mgr Add_new(int nsId, String name) {return Add_new(nsId, Bry_.new_u8(name), Xow_ns_case_.Tid__1st, false);} // for tst_ constructor
|
||||
@@ -145,24 +145,24 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
Bry_.Replace_all_direct(name, Byte_ascii.Space, Byte_ascii.Underline); // standardize on _; EX: User talk -> User_talk; DATE:2013-04-21
|
||||
Xow_ns ns = new Xow_ns(ns_id, caseMatchId, name, alias);
|
||||
switch (ns_id) {
|
||||
case Xow_ns_.Id_main: ns_main = ns; break;
|
||||
case Xow_ns_.Id_template: ns_template = ns; break;
|
||||
case Xow_ns_.Id_portal: ns_portal = ns; break;
|
||||
case Xow_ns_.Id_project: ns_project = ns; break;
|
||||
case Xow_ns_.Id_mediawiki: ns_mediawiki = ns; break;
|
||||
case Scrib_xtn_mgr.Ns_id_module: ns_module = ns; break;
|
||||
case Xow_ns_.Id_file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file
|
||||
case Xow_ns_.Id_category:
|
||||
case Xow_ns_.Tid__main: ns_main = ns; break;
|
||||
case Xow_ns_.Tid__template: ns_template = ns; break;
|
||||
case Xow_ns_.Tid__portal: ns_portal = ns; break;
|
||||
case Xow_ns_.Tid__project: ns_project = ns; break;
|
||||
case Xow_ns_.Tid__mediawiki: ns_mediawiki = ns; break;
|
||||
case Xow_ns_.Tid__module: ns_module = ns; break;
|
||||
case Xow_ns_.Tid__file: if (ns_file == null) ns_file = ns; break; // NOTE: if needed, else Image will become the official ns_file
|
||||
case Xow_ns_.Tid__category:
|
||||
ns_category = ns;
|
||||
if (category_trie == null)
|
||||
category_trie = Btrie_slim_mgr.new_(ns.Case_match() == Xow_ns_case_.Tid__all);
|
||||
category_trie.Add_obj(ns.Name_bry(), this);
|
||||
category_trie.Add_obj(ns.Name_db(), this);
|
||||
break;
|
||||
}
|
||||
++ns_count;
|
||||
if (!id_hash.Has(ns_hash_lkp.Val_(ns_id))) // NOTE: do not add if already exists; avoids alias
|
||||
id_hash.Add(Int_obj_ref.new_(ns.Id()), ns);
|
||||
name_hash.Add_if_dupe_use_nth(ns.Name_bry(), new Xow_ns_mgr_name_itm(ns.Name_bry(), ns));
|
||||
name_hash.Add_if_dupe_use_nth(ns.Name_db(), new Xow_ns_mgr_name_itm(ns.Name_db(), ns));
|
||||
return this;
|
||||
}
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
@@ -226,10 +226,10 @@ public class Xow_ns_mgr implements GfoInvkAble, gplx.lists.ComparerAble {
|
||||
this.Add_new(ns_id, Int_.To_bry(ns_id), Xow_ns_case_.Tid__1st, false); // NOTE: name and case_match are mostly useless defaults; note that in theory this proc should not be called (all siteInfos should be well-formed) but just in case, create items now so that Get_by_ord() does not fail
|
||||
}
|
||||
public byte[] Bld_ttl_w_ns(Bry_bfr bfr, boolean text_form, boolean literalize, int ns_id, byte[] ttl) {
|
||||
if (ns_id == Xow_ns_.Id_main) return ttl;
|
||||
if (ns_id == Xow_ns_.Tid__main) return ttl;
|
||||
Xow_ns ns = Ids_get_or_null(ns_id); if (ns == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "ns_mgr:uknown ns_id; ns_id=~{0} ttl=~{1}", ns_id, ttl); return ttl;}
|
||||
if (literalize) bfr.Add_byte(Byte_ascii.Colon); // NOTE: add : to literalize ns; EX: [[Category:A]] will get thrown into category list; [[:Category:A]] will print
|
||||
bfr.Add(text_form ? ns.Name_txt_w_colon() : ns.Name_db_w_colon());
|
||||
bfr.Add(text_form ? ns.Name_ui_w_colon() : ns.Name_db_w_colon());
|
||||
bfr.Add(ttl);
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Xow_ns_mgr_ {
|
||||
rv = rv.Add_new(-2, "Media").Add_new(-1, "Special").Add_new(0, "").Add_new(1, "Talk").Add_new(2, "User").Add_new(3, "User_talk").Add_new(4, "Wikipedia").Add_new(5, "Wikipedia_talk")
|
||||
.Add_new(6, "File").Add_new(7, "File_talk").Add_new(8, "MediaWiki").Add_new(9, "MediaWiki_talk").Add_new(10, "Template").Add_new(11, "Template_talk")
|
||||
.Add_new(12, "Help").Add_new(13, "Help_talk").Add_new(14, "Category").Add_new(15, "Category_talk").Add_new(100, "Portal").Add_new(101, "Portal_talk").Add_new(108, "Book").Add_new(109, "Book_talk")
|
||||
.Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module).Add_new(gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_id_module_talk, gplx.xowa.xtns.scribunto.Scrib_xtn_mgr.Ns_name_module_talk)
|
||||
.Add_new(Xow_ns_.Tid__module, Xow_ns_.Key__module).Add_new(Xow_ns_.Tid__module_talk, Xow_ns_.Key__module_talk)
|
||||
.Add_defaults()
|
||||
;
|
||||
rv.Init();
|
||||
@@ -37,14 +37,14 @@ public class Xow_ns_mgr_ {
|
||||
Xow_ns ns_name = ns_names.Get_at(i);
|
||||
int ns_id = ns_name.Id();
|
||||
Xow_ns ns = ns_mgr.Ids_get_or_null(ns_id);
|
||||
ns.Name_bry_(ns_name.Name_bry());
|
||||
ns.Name_bry_(ns_name.Name_db());
|
||||
}
|
||||
ns_names = lang.Ns_aliases();
|
||||
ns_names_len = ns_names.Len();
|
||||
for (int i = 0; i < ns_names_len; i++) {
|
||||
Xow_ns ns_name = ns_names.Get_at(i);
|
||||
int ns_id = ns_name.Id();
|
||||
ns_mgr.Aliases_add(ns_id, ns_name.Name_str());
|
||||
ns_mgr.Aliases_add(ns_id, ns_name.Name_db_str());
|
||||
}
|
||||
ns_mgr.Init();
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class Xow_ns_mgr_tst {
|
||||
@Test public void Skip_even() {fxt.ini_ns_(-2, 2, 4).run_Ords_sort().tst_Ords(-2, -100, 2, 3, 4, 5);}
|
||||
@Test public void Ns_alias() {
|
||||
fxt.Ns_mgr().Aliases_clear();
|
||||
fxt.Ns_mgr().Add_new(Xow_ns_.Id_template, "Template");
|
||||
fxt.Ns_mgr().Aliases_add(Xow_ns_.Id_template, "Templatex");
|
||||
fxt.Ns_mgr().Add_new(Xow_ns_.Tid__template, "Template");
|
||||
fxt.Ns_mgr().Aliases_add(Xow_ns_.Tid__template, "Templatex");
|
||||
fxt.Ns_mgr().Init();
|
||||
byte[] name = Bry_.new_a7("Templatex:Abc");
|
||||
Tfds.Eq(10, fxt.Ns_mgr().Tmpls_get_w_colon(name, 0, name.length));
|
||||
|
||||
@@ -20,27 +20,27 @@ import org.junit.*;
|
||||
public class Xow_ns_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xow_ns_fxt fxt = new Xow_ns_fxt();
|
||||
@Test public void Category() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Tid__category)
|
||||
.Expd_id_talkId_(Xow_ns_.Tid__category_talk)
|
||||
.Expd_id_subj_(Bool_.Y)
|
||||
.Expd_id_talk_(Bool_.N)
|
||||
.Test(Xow_ns_.Id_category)
|
||||
.Test(Xow_ns_.Tid__category)
|
||||
;
|
||||
}
|
||||
@Test public void Category_talk() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_category)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_category_talk)
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Tid__category)
|
||||
.Expd_id_talkId_(Xow_ns_.Tid__category_talk)
|
||||
.Expd_id_subj_(Bool_.N)
|
||||
.Expd_id_talk_(Bool_.Y)
|
||||
.Test(Xow_ns_.Id_category_talk)
|
||||
.Test(Xow_ns_.Tid__category_talk)
|
||||
;
|
||||
}
|
||||
@Test public void Special() {
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Id_special)
|
||||
.Expd_id_talkId_(Xow_ns_.Id_special)
|
||||
fxt .Expd_id_subjId_(Xow_ns_.Tid__special)
|
||||
.Expd_id_talkId_(Xow_ns_.Tid__special)
|
||||
.Expd_id_subj_(Bool_.Y)
|
||||
.Expd_id_talk_(Bool_.N)
|
||||
.Test(Xow_ns_.Id_special)
|
||||
.Test(Xow_ns_.Tid__special)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class Xow_ns_fxt {
|
||||
Xow_ns actl = new Xow_ns(nsId, Xow_ns_case_.Tid__1st, Bry_.Empty, false);
|
||||
Tfds.Eq(expd_id_subjId, actl.Id_subj_id());
|
||||
Tfds.Eq(expd_id_talkId, actl.Id_talk_id());
|
||||
Tfds.Eq(expd_id_subj, actl.Id_subj());
|
||||
Tfds.Eq(expd_id_talk, actl.Id_talk());
|
||||
Tfds.Eq(expd_id_subj, actl.Id_is_subj());
|
||||
Tfds.Eq(expd_id_talk, actl.Id_is_talk());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import gplx.xowa.wikis.nss.*;
|
||||
public class Xotdb_fsys_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xow_fsys_mgr_fxt fxt = new Xow_fsys_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat");
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip");
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.N).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page/00/00/00/01/0000000123.xdat");
|
||||
fxt.Zip_(Xotdb_dir_info_.Tid_page, Bool_.Y).Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, 123, "mem/xowa/wiki/en.wikipedia.org/ns/000/page_zip/00/00/00/01/0000000123.zip");
|
||||
}
|
||||
}
|
||||
class Xow_fsys_mgr_fxt {
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Xotdb_page_itm_ {
|
||||
.Add(page.Ttl_page_db()) .Add_byte_nl();
|
||||
}
|
||||
public static void Txt_page_save(Bry_bfr bfr, int id, DateAdp modified_on, byte[] title, byte[] text, boolean add_nl) {
|
||||
int ts = Bit_.Xto_int_date_short(modified_on.XtoSegAry());
|
||||
int ts = Int_flag_bldr_.To_int_date_short(modified_on.XtoSegAry());
|
||||
bfr .Add_base85(id , Base85_.Len_int) .Add_byte(Txt_page_dlm) // needed for mass template load
|
||||
.Add_base85(ts , Base85_.Len_int) .Add_byte(Txt_page_dlm)
|
||||
.Add(title) .Add_byte(Txt_page_dlm) // needed for rebuilding ttl files
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Xotdb_page_raw_parser {
|
||||
page.Id_(id);
|
||||
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read timestamp");
|
||||
int timestamp = Base85_.To_int_by_bry(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
|
||||
page.Modified_on_(Bit_.Xto_date_short(timestamp));
|
||||
page.Modified_on_(Int_flag_bldr_.To_date_short(timestamp));
|
||||
read = rdr.Read_next(); if (!read) throw Err_.new_wo_type("could not read ttl");
|
||||
byte[] ttl = Bry_.Mid(rdr.Bfr(), rdr.Key_pos_bgn(), rdr.Key_pos_end() - 1);
|
||||
page.Ttl_(ttl, ns_mgr);
|
||||
|
||||
@@ -75,7 +75,7 @@ class Xowd_hive_mgr_fxt {
|
||||
return this;
|
||||
}
|
||||
public Xowd_hive_mgr_fxt Tst_fil(int fil, String expd) {
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Id_main, fil);
|
||||
Io_url url = wiki.Tdb_fsys_mgr().Url_ns_fil(Xotdb_dir_info_.Tid_page, Xow_ns_.Tid__main, fil);
|
||||
Tfds.Eq_str_lines(expd, Io_mgr.Instance.LoadFilStr(url));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xow
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
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() {fxt.Init_ttl("Help:Test") .Expd_ns_id(Xow_ns_.Tid__help).Expd_page_txt("Test").Test();}
|
||||
@Test public void Ns_false() {fxt.Init_ttl("Helpx:Test") .Expd_ns_id(Xow_ns_.Tid__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
|
||||
@@ -48,10 +48,10 @@ public class Xow_ttl__basic_tst {
|
||||
@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 All_page() {fxt.Init_ttl("test") .Expd_xwik_txt("").Expd_ns_id(Xow_ns_.Tid__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_.Tid__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_.Tid__special).Expd_page_txt("Random").Test();}
|
||||
@Test public void Special_xowa() {fxt.Init_ttl("Special:xowa/Search/Ttl").Expd_ns_id(Xow_ns_.Tid__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
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Xow_ttl__err_tst {
|
||||
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", 255)).Expd_ns_id(Xow_ns_.Tid__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();}
|
||||
|
||||
@@ -19,11 +19,11 @@ package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xow
|
||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||
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 Known() {fxt.Init_ttl("fr:a") .Expd_xwik_txt("fr").Expd_ns_id(Xow_ns_.Tid__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_.Tid__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_.Tid__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_.Tid__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_.Tid__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:");
|
||||
|
||||
@@ -17,14 +17,21 @@ 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.core.net.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xow_xwiki_itm implements gplx.CompareAble {
|
||||
private final boolean show_in_sitelangs_base;
|
||||
public Xow_xwiki_itm(byte[] key_bry, byte[] url_fmt, int lang_id, int domain_tid, byte[] domain_bry, byte[] domain_name, byte[] abrv_wm) {
|
||||
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; this.abrv_wm = abrv_wm;
|
||||
int key_bry_len = key_bry.length;
|
||||
this.show_in_sitelangs_base
|
||||
= lang_id != Xol_lang_stub_.Id__unknown // valid lang code
|
||||
&& domain_tid != Xow_domain_tid_.Int__commons // commons should never be considered an xwiki_lang; EX:[[commons:A]] PAGE:species:Scarabaeidae; DATE:2014-09-10
|
||||
&& Bry_.Len_gt_0(url_fmt) // url_fmt exists
|
||||
&& Bry_.Match(domain_bry, 0, key_bry_len, key_bry) && key_bry_len + 1 < domain_bry.length && domain_bry[key_bry_len] == Byte_ascii.Dot // key + . matches start of domain; EX: "en" and "en.wikipedia.org"
|
||||
;
|
||||
}
|
||||
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;
|
||||
@@ -37,11 +44,9 @@ public class Xow_xwiki_itm implements gplx.CompareAble {
|
||||
public byte[] Abrv_wm() {return abrv_wm;} private final byte[] abrv_wm; // EX: enwiki; needed for sitelinks
|
||||
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(byte[] cur_lang_key) {
|
||||
return lang_id != Xol_lang_stub_.Id__unknown // valid lang code
|
||||
&& domain_tid != Xow_domain_tid_.Int__commons // commons should never be considered an xwiki_lang; EX:[[commons:A]] PAGE:species:Scarabaeidae; DATE:2014-09-10
|
||||
public boolean Show_in_sitelangs(byte[] cur_lang_key) {
|
||||
return show_in_sitelangs_base
|
||||
&& !Bry_.Eq(key_bry, cur_lang_key) // 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, byte[] abrv_wm) {
|
||||
|
||||
45
400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_tst.java
Normal file
45
400_xowa/src/gplx/xowa/wikis/xwikis/Xow_xwiki_itm_tst.java
Normal 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.xwikis; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||
import org.junit.*; import gplx.xowa.langs.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xow_xwiki_itm_tst {
|
||||
private final Xow_xwiki_itm_fxt fxt = new Xow_xwiki_itm_fxt();
|
||||
@Test public void Show_in_sitelangs__basic() { // PURPOSE: basic test for show in "In other languages"; DATE:2015-11-06
|
||||
fxt.Test__type_is_xwiki_lang(Bool_.Y, fxt.Make_xwiki("en", "en.wikipedia.org/wiki/{0}", Xol_lang_stub_.Id_en, Xow_domain_tid_.Int__wikipedia, "en.wikipedia.org", "enwiki"), "simple");
|
||||
}
|
||||
@Test public void Show_in_sitelangs__lang_like() { // PURPOSE: only consider xwikis with key similar to domain; EX: [[w:A]] in simplewiki; PAGE:Main_Page; DATE:2015-11-06
|
||||
fxt.Test__type_is_xwiki_lang(Bool_.N, fxt.Make_xwiki("e", "en.wikipedia.org/wiki/{0}", Xol_lang_stub_.Id_en, Xow_domain_tid_.Int__wikipedia, "en.wikipedia.org", "enwiki"), "simple");
|
||||
}
|
||||
@Test public void Show_in_sitelangs__same() { // PURPOSE: same wiki should not appear in "In other languages"; DATE:2015-11-06
|
||||
fxt.Test__type_is_xwiki_lang(Bool_.N, fxt.Make_xwiki("en", "en.wikipedia.org/wiki/{0}", Xol_lang_stub_.Id_en, Xow_domain_tid_.Int__wikipedia, "en.wikipedia.org", "enwiki"), "en");
|
||||
}
|
||||
@Test public void Show_in_sitelangs__no_url_fmt() { // PURPOSE: xwikis with no format should not appear in "In other languages"; DATE:2015-11-06
|
||||
fxt.Test__type_is_xwiki_lang(Bool_.N, fxt.Make_xwiki("en", "", Xol_lang_stub_.Id_en, Xow_domain_tid_.Int__wikipedia, "en.wikipedia.org", "enwiki"), "simple");
|
||||
}
|
||||
@Test public void Show_in_sitelangs__commons() { // PURPOSE: commons should not appear in "In other languages"; DATE:2015-11-06
|
||||
fxt.Test__type_is_xwiki_lang(Bool_.N, fxt.Make_xwiki("c", "commons.wikimedia.org/wiki/{0}", Xol_lang_stub_.Id__intl, Xow_domain_tid_.Int__commons, "commons.wikimedia.org", "commonswiki"), "en");
|
||||
}
|
||||
}
|
||||
class Xow_xwiki_itm_fxt {
|
||||
public Xow_xwiki_itm Make_xwiki(String key_bry, String url_fmt, int lang_id, int domain_tid, String domain_bry, String abrv_wm) {
|
||||
return Xow_xwiki_itm.new_(Bry_.new_u8(key_bry), Bry_.new_u8(url_fmt), lang_id, domain_tid, Bry_.new_u8(domain_bry), Bry_.new_u8(abrv_wm));
|
||||
}
|
||||
public void Test__type_is_xwiki_lang(boolean expd, Xow_xwiki_itm xwiki_itm, String cur_lang_key) {
|
||||
Tfds.Eq_bool(expd, xwiki_itm.Show_in_sitelangs(Bry_.new_u8(cur_lang_key)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user