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-03-08 21:27:59 -04:00
parent d279c70606
commit 80b9928b5c
259 changed files with 2841 additions and 2060 deletions

View File

@@ -53,7 +53,7 @@ public class Xob_hive_mgr {
for (; row_idx < rows_len; row_idx++) {
xdat_file.GetAt(xdat_itm, row_idx);
Xodb_page ttl_itm = Xodb_page_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Type_redirect()) continue;
if (!include_redirects && ttl_itm.Redirected()) continue;
++count;
nxt_itm = ttl_itm;
if (count == total) {
@@ -88,7 +88,7 @@ public class Xob_hive_mgr {
for (; row_idx > -1; row_idx--) {
xdat_file.GetAt(xdat_itm, row_idx);
Xodb_page ttl_itm = Xodb_page_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Type_redirect()) continue;
if (!include_redirects && ttl_itm.Redirected()) continue;
// list.Add(ttl_itm);
++count;
prv_itm = ttl_itm;
@@ -158,7 +158,7 @@ public class Xob_hive_mgr {
for (; row_idx < rows_len; row_idx++) {
xdat.GetAt(xdat_itm, row_idx);
Xodb_page ttl_itm = Xodb_page_.Txt_ttl_load(Bry_.Mid(xdat_itm.Src(), xdat_itm.Itm_bgn(), xdat_itm.Itm_end()));
if (!include_redirects && ttl_itm.Type_redirect()) continue;
if (!include_redirects && ttl_itm.Redirected()) continue;
list.Add(ttl_itm);
if (++count == total) {loop = false; break;}
}

View File

@@ -22,54 +22,80 @@ public class Xodb_page implements Xobl_data_itm {
public int Id() {return id;} public Xodb_page 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 Xodb_page Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
public byte[] Ttl_wo_ns() {return ttl_wo_ns;} public Xodb_page Ttl_wo_ns_(byte[] v) {ttl_wo_ns = v; return this;} private byte[] ttl_wo_ns;
public boolean Type_redirect() {return type_redirect;} public Xodb_page Type_redirect_(boolean v) {type_redirect = v; return this;} private boolean type_redirect;
public DateAdp Modified_on() {return modified_on;} public Xodb_page Modified_on_(DateAdp v) {modified_on = v; return this;} DateAdp modified_on;
public int Text_len() {return text_len;} public Xodb_page Text_len_(int v) {text_len = v; return this;} private int text_len;
public int Text_db_id() {return text_db_id;} public Xodb_page Text_db_id_(int v) {text_db_id = v; return this;} private int text_db_id;
public int Html_db_id() {return html_db_id;} public Xodb_page Html_db_id_(int v) {html_db_id = v; return this;} private int html_db_id;
public int Redirect_id() {return redirect_id;} public void Redirect_id_(int v) {redirect_id = v;} private int redirect_id;
public byte[] Text() {return text;} public Xodb_page Text_(byte[] v) {text = v; if (v != null) text_len = v.length; return this;} private byte[] text;
public byte[] Ttl_page_db() {return ttl_page_db;} public Xodb_page 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 Xodb_page Redirected_(boolean v) {redirected = v; return this;} private boolean redirected;
public int Wtxt_len() {return wtxt_len;} public Xodb_page Wtxt_len_(int v) {wtxt_len = v; return this;} private int wtxt_len;
public int Wtxt_db_id() {return wtxt_db_id;} public Xodb_page Wtxt_db_id_(int v) {wtxt_db_id = v; return this;} private int wtxt_db_id;
public byte[] Wtxt() {return wtxt;} public Xodb_page Wtxt_(byte[] v) {wtxt = v; if (v != null) wtxt_len = v.length; return this;} private byte[] wtxt;
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 Xodb_page Modified_on_(DateAdp v) {modified_on = v; return this;} private DateAdp modified_on;
public boolean Exists() {return exists;} public Xodb_page Exists_(boolean v) {exists = v; return this;} private boolean exists;
public int Db_row_idx() {return db_row_idx;} public Xodb_page Db_row_idx_(int v) {db_row_idx = v; return this;} private int db_row_idx;
public Xow_ns Ns() {return ns;} private Xow_ns ns;
public Object Xtn() {return xtn;} public Xodb_page Xtn_(Object v) {this.xtn = v; return this;} Object xtn;
public byte[] Ttl_w_ns() {return ttl_w_ns;} private byte[] ttl_w_ns;
public Xodb_page Ttl_(Xow_ns ns, byte[] ttl_wo_ns) {
public Object Xtn() {return xtn;} public Xodb_page 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 Xodb_page Init(int id, byte[] ttl_page_db, boolean redirected, int wtxt_len, int wtxt_db_id, int tdb_row_idx) {
this.id = id; this.ttl_page_db = ttl_page_db; this.redirected = redirected;
this.wtxt_len = wtxt_len; this.wtxt_db_id = wtxt_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 wtxt_len, int wtxt_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.wtxt_len = wtxt_len;
this.wtxt_db_id = wtxt_db_id;
this.html_db_id = html_db_id;
this.redirect_id = redirect_id;
}
public void Init_by_tdb(int id, int wtxt_db_id, int tdb_row_idx, boolean redirected, int wtxt_len, int ns_id, byte[] ttl_page_db) {
this.id = id;
this.wtxt_db_id = wtxt_db_id;
this.tdb_row_idx = tdb_row_idx;
this.redirected = redirected;
this.wtxt_len = wtxt_len;
this.ns_id = ns_id;
this.ttl_page_db = ttl_page_db;
}
public Xodb_page Ttl_(Xow_ns ns, byte[] ttl_page_db) {
this.ns = ns;
ns_id = ns.Id();
this.ttl_wo_ns = ttl_wo_ns;
this.ttl_w_ns = ns.Gen_ttl(ttl_wo_ns);
this.ttl_page_db = ttl_page_db;
this.ttl_full_db = ns.Gen_ttl(ttl_page_db);
return this;
}
public Xodb_page Ttl_(Xoa_ttl ttl) {
ttl_w_ns = ttl.Full_txt();
ttl_wo_ns = ttl.Page_db();
ttl_full_db = ttl.Full_txt();
ttl_page_db = ttl.Page_db();
ns = ttl.Ns();
ns_id = ns.Id();
return this;
}
public Xodb_page Ttl_(byte[] v, Xow_ns_mgr ns_mgr) {
ttl_w_ns = v;
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_wo_ns = v;
ttl_page_db = v;
}
else {
ns = (Xow_ns)o;
ttl_wo_ns = Bry_.Mid(v, ns.Name_txt_w_colon().length, v.length); // EX: "Template:A" -> "Template:" + "A"
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 = db_row_idx = 0; // default to 0, b/c some tests do not set and will fail at -1
id = Id_null; wtxt_len = 0; // wtxt_len should be 0 b/c wtxt defaults to 0;
wtxt_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_w_ns = ttl_wo_ns = null; text = Bry_.Empty; // default to Ary_empty for entries that have <text />
ttl_full_db = ttl_page_db = null; wtxt = Bry_.Empty; // default to Ary_empty for entries that have <wtxt />
ns = null;
type_redirect = exists = false;
redirected = exists = false;
modified_on = DateAdp_.MinValue;
id_val = null;
html_db_id = -1;
@@ -77,30 +103,24 @@ public class Xodb_page implements Xobl_data_itm {
}
public void Copy(Xodb_page orig) {
this.id = orig.id;
this.text_len = orig.text_len;
this.text_db_id = orig.text_db_id;
this.db_row_idx = orig.db_row_idx;
this.wtxt_len = orig.wtxt_len;
this.wtxt_db_id = orig.wtxt_db_id;
this.tdb_row_idx = orig.tdb_row_idx;
this.ns_id = orig.ns_id;
this.ttl_w_ns = orig.ttl_w_ns;
this.ttl_wo_ns = orig.ttl_wo_ns;
this.text = orig.text;
this.ttl_full_db = orig.ttl_full_db;
this.ttl_page_db = orig.ttl_page_db;
this.wtxt = orig.wtxt;
this.ns = orig.ns;
this.type_redirect = orig.type_redirect;
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 Xodb_page Set_all_(int id, int text_db_id, int db_row_idx, boolean redirect, int text_len, byte[] ttl_wo_ns) {
this.id = id; this.text_db_id = text_db_id; this.db_row_idx = db_row_idx; this.type_redirect = redirect; this.text_len = text_len; this.ttl_wo_ns = ttl_wo_ns;
id_val = null;
return this;
}
public void Srl_save(Bry_bfr bfr) {Xodb_page_.Txt_id_save(bfr, this);}
public static Xodb_page tmp_() {return new Xodb_page();}
public static Xodb_page srch_(int id, int text_len) {return new Xodb_page().Id_(id).Text_len_(text_len);}
public static final int Id_null = -1, Modified_on_null_int = 0;
public static final Xodb_page[] Ary_empty = new Xodb_page[0];
public static final int Timestamp_null = 0;
public static final int Id_null = -1;
public static final Xodb_page Null = null;
public static Xodb_page new_tmp() {return new Xodb_page();}
public static Xodb_page new_srch(int id, int wtxt_len) {return new Xodb_page().Id_(id).Wtxt_len_(wtxt_len);}
}

View File

@@ -29,15 +29,18 @@ public class Xodb_page_ {
public static void Txt_ttl_load(Xodb_page page, byte[] bry) {Txt_ttl_load(page, bry, 0, bry.length);}
private static void Txt_ttl_load(Xodb_page page, byte[] bry, int bgn, int end) {
try {
page.Id_ (Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4));
page.Text_db_id_ (Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10));
page.Db_row_idx_ (Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16));
page.Type_redirect_ (bry[18] == Byte_ascii.Num_1);
page.Text_len_ (Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24));
page.Ttl_wo_ns_ (Bry_.Mid (bry, bgn + 26, end));
page.Init_by_tdb
( Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4)
, Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10)
, Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16)
, bry[18] == Byte_ascii.Num_1
, Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24)
, page.Ns_id()
, Bry_.Mid (bry, bgn + 26, end)
);
} catch (Exception e) {throw Err_.err_(e, "parse_by_ttl failed: {0}", String_.new_utf8_(bry, bgn, end));}
}
public static void Txt_ttl_save(Bry_bfr bfr, Xodb_page page) {Txt_ttl_save(bfr, page.Id(), page.Text_db_id(), page.Db_row_idx(), page.Type_redirect(), page.Text_len(), page.Ttl_wo_ns());}
public static void Txt_ttl_save(Bry_bfr bfr, Xodb_page page) {Txt_ttl_save(bfr, page.Id(), page.Wtxt_db_id(), page.Tdb_row_idx(), page.Redirected(), page.Wtxt_len(), page.Ttl_page_db());}
public static void Txt_ttl_save(Bry_bfr bfr, int id, int file_idx, int row_idx, boolean redirect, int text_len, byte[] ttl_wo_ns) {
bfr .Add_base85_len_5(id) .Add_byte_pipe()
.Add_base85_len_5(file_idx) .Add_byte_pipe()
@@ -51,23 +54,25 @@ public class Xodb_page_ {
private static void Txt_id_load(Xodb_page page, byte[] bry, int bgn, int end) {
try {
page.Clear();
page.Id_ (Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4));
page.Text_db_id_ (Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10));
page.Db_row_idx_ (Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16));
page.Type_redirect_ (bry[18] == Byte_ascii.Num_1);
page.Text_len_ (Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24));
page.Ns_id_ (Base85_utl.XtoIntByAry (bry, bgn + 26, bgn + 30));
page.Ttl_wo_ns_ (Bry_.Mid (bry, bgn + 32, end));
page.Init_by_tdb
( Base85_utl.XtoIntByAry (bry, bgn + 0, bgn + 4)
, Base85_utl.XtoIntByAry (bry, bgn + 6, bgn + 10)
, Base85_utl.XtoIntByAry (bry, bgn + 12, bgn + 16)
, bry[18] == Byte_ascii.Num_1
, Base85_utl.XtoIntByAry (bry, bgn + 20, bgn + 24)
, Base85_utl.XtoIntByAry (bry, bgn + 26, bgn + 30)
, Bry_.Mid (bry, bgn + 32, end)
);
} catch (Exception e) {throw Err_.err_(e, "parse_by_id failed: {0}", String_.new_utf8_(bry, bgn, end));}
}
public static void Txt_id_save(Bry_bfr bfr, Xodb_page page) {
bfr .Add_base85_len_5(page.Id()) .Add_byte_pipe()
.Add_base85_len_5(page.Text_db_id()) .Add_byte_pipe()
.Add_base85_len_5(page.Db_row_idx()) .Add_byte_pipe()
.Add_byte(page.Type_redirect() ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe()
.Add_base85_len_5(page.Text_len()) .Add_byte_pipe()
.Add_base85_len_5(page.Wtxt_db_id()) .Add_byte_pipe()
.Add_base85_len_5(page.Tdb_row_idx()) .Add_byte_pipe()
.Add_byte(page.Redirected() ? Byte_ascii.Num_1 : Byte_ascii.Num_0).Add_byte_pipe()
.Add_base85_len_5(page.Wtxt_len()) .Add_byte_pipe()
.Add_base85_len_5(page.Ns_id()) .Add_byte_pipe()
.Add(page.Ttl_wo_ns()) .Add_byte_nl();
.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());

View File

@@ -26,11 +26,11 @@ public class Xodb_page_sorter implements ComparerAble {
switch (compareType) {
case Tid_ns_ttl: {
int rv = Int_.Compare(lhs.Ns_id(), rhs.Ns_id());
return rv == CompareAble_.Same ? Bry_.Compare(lhs.Ttl_wo_ns(), rhs.Ttl_wo_ns()) : rv;
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_itm_len: return Int_.Compare(lhs.Wtxt_len(), rhs.Wtxt_len());
case Tid_id: return Int_.Compare(lhs.Id(), rhs.Id());
case Tid_ttl: return Bry_.Compare(lhs.Ttl_wo_ns(), rhs.Ttl_wo_ns());
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();

View File

@@ -37,6 +37,6 @@ class Xodb_page_fxt {
public void Test_ttl_(String ttl, int expd_ns, String expd_ttl) {
tmp_page.Ttl_(Bry_.new_ascii_(ttl), ns_mgr);
Tfds.Eq(expd_ns, tmp_page.Ns_id());
Tfds.Eq(expd_ttl, String_.new_ascii_(tmp_page.Ttl_wo_ns()));
Tfds.Eq(expd_ttl, String_.new_ascii_(tmp_page.Ttl_page_db()));
}
}

View File

@@ -52,14 +52,14 @@ public class Xow_data_mgr implements GfoInvkAble {
}
public Xoae_page Get_page(Xoae_page rv, Xow_ns ns, Xoa_ttl ttl, boolean called_from_tmpl, boolean redirect_force) {
int redirects = 0;
Xodb_page db_page = Xodb_page.tmp_();
Xodb_page db_page = Xodb_page.new_tmp();
while (true) {
boolean exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(db_page, ns, ttl.Page_db());
if (!exists) return rv.Missing_();
if (wiki.Appe().Mode() == Xoa_app_.Mode_gui) // NOTE: must check if gui, else will write during mass build; DATE:2014-05-03
wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "file_load", "loading page for ~{0}", String_.new_utf8_(ttl.Raw()));
wiki.Db_mgr().Load_mgr().Load_page(db_page, ns, !called_from_tmpl);
byte[] bry = db_page.Text();
byte[] bry = db_page.Wtxt();
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);

View File

@@ -35,7 +35,7 @@ public class Xow_hive_mgr_fxt {
String[] actl = new String[actl_len];
for (int i = 0; i < actl_len; i++) {
Xodb_page itm = (Xodb_page)list.FetchAt(i);
actl[i] = String_.new_ascii_(itm.Ttl_wo_ns());
actl[i] = String_.new_ascii_(itm.Ttl_page_db());
}
Tfds.Eq_ary_str(expd, actl);
}