mirror of https://github.com/gnosygnu/xowa
parent
232838c732
commit
35d78f6106
@ -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.dbs.utls; import gplx.*; import gplx.dbs.*;
|
||||
import gplx.dbs.stmts.*;
|
||||
public class Db_tbl__crud_ {
|
||||
public static void Upsert(Db_conn conn, String tbl_name, Dbmeta_fld_list flds, String[] crt_cols, Object... objs) {
|
||||
// init
|
||||
int crt_cols_len = crt_cols.length;
|
||||
String[] val_cols = Find_excepts(flds, crt_cols);
|
||||
|
||||
// check if exists
|
||||
Db_stmt select_stmt = conn.Stmt_select(tbl_name, crt_cols, crt_cols);
|
||||
Add_arg(select_stmt, flds, crt_cols, objs, Bool_.Y, 0);
|
||||
Db_rdr rdr = select_stmt.Exec_select__rls_auto();
|
||||
boolean exists = rdr.Move_next();
|
||||
rdr.Rls();
|
||||
|
||||
// do update / insert; NOTE: 0-index and crt_cols_len assumes that objs starts with crts; EX: (id) -> (1, 'abc') x> ('abc', 1)
|
||||
// update
|
||||
if (exists) {
|
||||
Db_stmt update_stmt = conn.Stmt_update(tbl_name, crt_cols, crt_cols);
|
||||
Add_arg(update_stmt, flds, crt_cols, objs, Bool_.Y, 0);
|
||||
Add_arg(update_stmt, flds, val_cols, objs, Bool_.N, crt_cols_len);
|
||||
update_stmt.Exec_update();
|
||||
update_stmt.Rls();
|
||||
}
|
||||
// insert
|
||||
else {
|
||||
Db_stmt insert_stmt = conn.Stmt_insert(tbl_name, flds);
|
||||
Add_arg(insert_stmt, flds, crt_cols, objs, Bool_.N, 0);
|
||||
Add_arg(insert_stmt, flds, val_cols, objs, Bool_.N, crt_cols_len);
|
||||
insert_stmt.Exec_insert();
|
||||
insert_stmt.Rls();
|
||||
}
|
||||
}
|
||||
private static String[] Find_excepts(Dbmeta_fld_list flds, String[] cols) {
|
||||
// hash cols
|
||||
Hash_adp hash = Hash_adp_.New();
|
||||
int cols_len = cols.length;
|
||||
for (int i = 0; i < cols_len; ++i)
|
||||
hash.Add_as_key_and_val(cols[i]);
|
||||
|
||||
// loop flds and get excepts
|
||||
List_adp list = List_adp_.New();
|
||||
int flds_len = flds.Len();
|
||||
for (int i = 0; i < flds_len; ++i) {
|
||||
Dbmeta_fld_itm fld = flds.Get_at(i);
|
||||
if (!hash.Has(fld.Name()))
|
||||
list.Add(fld.Name());
|
||||
}
|
||||
return list.To_str_ary_and_clear();
|
||||
}
|
||||
private static void Add_arg(Db_stmt stmt, Dbmeta_fld_list flds, String[] cols, Object[] objs, boolean mode_is_crt, int objs_bgn) {
|
||||
int cols_len = cols.length;
|
||||
for (int i = 0; i < cols_len; ++i) {
|
||||
String col = cols[i];
|
||||
Dbmeta_fld_itm fld = flds.Get_by(col);
|
||||
Object obj = objs[i + objs_bgn];
|
||||
if (mode_is_crt)
|
||||
Db_stmt_arg_list.Fill_crt(stmt, fld.Type().Tid_ansi(), col, obj);
|
||||
else
|
||||
Db_stmt_arg_list.Fill_val(stmt, fld.Type().Tid_ansi(), col, obj);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
//namespace gplx.xowa.addons.apps.cfgs.dbs {
|
||||
// using gplx.dbs; using gplx.dbs.utls;
|
||||
// class Xocfg_data_itm : Db_tbl {
|
||||
// private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
// private final String fld_itm_id, fld_itm_val, fld_itm_date;
|
||||
// private final Db_conn conn;
|
||||
// public Xocfg_data_itm(Db_conn conn) {
|
||||
// this.conn = conn;
|
||||
// this.tbl_name = "cfg_data_itm";
|
||||
// this.fld_itm_id = flds.Add_int("itm_id"); // EX: '1'
|
||||
// // ctx_id; app,wiki,ns
|
||||
// this.fld_itm_date = flds.Add_str("itm_date", 32); // EX: '20160901_010203'
|
||||
// this.fld_itm_val = flds.Add_str("itm_val", 4096); // EX: 'abc'
|
||||
// conn.Rls_reg(this);
|
||||
// }
|
||||
// public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
// public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
// public void Upsert(int itm_id, String itm_date, String itm_val) {
|
||||
// Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_itm_id), itm_id, itm_date, itm_val);
|
||||
// }
|
||||
// public void Rls() {}
|
||||
// }
|
||||
// class Xocfg_meta_itm : Db_tbl {
|
||||
// private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
// private final String fld_grp_id, fld_itm_id, fld_itm_sort, fld_itm_key, fld_scope_id, fld_type_id, fld_itm_dflt;
|
||||
// private final Db_conn conn;
|
||||
// public Xocfg_meta_itm(Db_conn conn) {
|
||||
// this.conn = conn;
|
||||
// this.tbl_name = "cfg_meta_itm";
|
||||
// this.fld_grp_id = flds.Add_int("grp_id"); // EX: '1'
|
||||
// this.fld_itm_id = flds.Add_int("itm_id"); // EX: '2'
|
||||
// this.fld_itm_sort = flds.Add_int("itm_sort"); // EX: '3'
|
||||
// this.fld_scope_id = flds.Add_int("itm_scope_id"); // EX: '1'; REF: cfg_meta_scope; ENUM: app-only, wiki-only, ...
|
||||
// this.fld_type_id = flds.Add_int("itm_type_id"); // EX: '1'; REF: cfg_meta_type; ENUM: int, String, ...
|
||||
// this.fld_itm_key = flds.Add_str("itm_key", 255); // EX: 'cfg_1'
|
||||
// this.fld_itm_dflt = flds.Add_str("itm_dflt", 4096); // EX: 'abc'
|
||||
// // display_name
|
||||
// // help_text
|
||||
// // locale
|
||||
// conn.Rls_reg(this);
|
||||
// }
|
||||
// public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
// public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
// public void Upsert(int grp_id, int itm_id, int itm_sort, int scope_id, int type_id, String itm_key, String itm_dflt) {
|
||||
// Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_grp_id, fld_itm_id), grp_id, itm_id, itm_sort, scope_id, type_id, itm_key, itm_dflt);
|
||||
// }
|
||||
// public void Rls() {}
|
||||
// }
|
||||
// class Xocfg_meta_grp : Db_tbl {
|
||||
// private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
// private final String fld_grp_id, fld_grp_key;
|
||||
// private final Db_conn conn;
|
||||
// public Xocfg_meta_grp(Db_conn conn) {
|
||||
// this.conn = conn;
|
||||
// this.tbl_name = "cfg_meta_grp";
|
||||
// this.fld_grp_id = flds.Add_int("grp_id");
|
||||
// this.fld_grp_key = flds.Add_str("grp_key", 255);
|
||||
// // display
|
||||
// conn.Rls_reg(this);
|
||||
// }
|
||||
// public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
// public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
// public void Upsert(int grp_id, String grp_key) {
|
||||
// Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_grp_id), grp_id, grp_key);
|
||||
// }
|
||||
// public void Rls() {}
|
||||
// }
|
||||
// class Xocfg_meta_grp_map : Db_tbl {
|
||||
// private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
// private final String fld_map_src, fld_map_trg, fld_map_sort;
|
||||
// private final Db_conn conn;
|
||||
// public Xocfg_meta_grp_map(Db_conn conn) {
|
||||
// this.conn = conn;
|
||||
// this.tbl_name = "cfg_meta_grp_map";
|
||||
// this.fld_map_src = flds.Add_int("map_src");
|
||||
// this.fld_map_trg = flds.Add_int("map_trg");
|
||||
// this.fld_map_sort = flds.Add_int("map_sort");
|
||||
// conn.Rls_reg(this);
|
||||
// }
|
||||
// public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
// public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
// public void Upsert(int map_src, int map_trg, int map_sort) {
|
||||
// Db_tbl__crud_.Upsert(conn, tbl_name, flds, String_.Ary(fld_map_src), map_src, map_trg, map_sort);
|
||||
// }
|
||||
// public void Rls() {}
|
||||
// }
|
||||
///*
|
||||
//EXEC cfg_select 'xowa.wiki.page.sync', 'scope'
|
||||
//
|
||||
//SELECT @grp_id = grp_id FROM grp WHERE key = 'xowa.wiki.page.sync';
|
||||
//@aboe = SELECT * FROM grp_map WHERE owner_id = @grp_id ORDER BY sort
|
||||
//SELECT * FROM meta_itm WHERE grp_id IN (@above)
|
||||
//
|
||||
//{{#grp}}
|
||||
// {{#itm_key}}
|
||||
// Coalesce({{#itm_val}}, {{#itm_dflt}})
|
||||
// {{#itm_dirty}}
|
||||
// {{#itm_notes}}
|
||||
//{{#grp}}
|
||||
//
|
||||
//grp_0 -> Name of page
|
||||
//grp_1 -> H2
|
||||
//grp_2 -> H3
|
||||
//...
|
||||
//*/
|
||||
//}
|
@ -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.addons.bldrs.infos; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.bldrs.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.wikis.domains.*;
|
||||
public class Xobc_info_html__tst {
|
||||
private final Xobc_info_html__fxt fxt = new Xobc_info_html__fxt();
|
||||
@Test public void Torrent__en_w() {fxt.Test__torrent_link("en.wikipedia.org" , "https://archive.org/download/Xowa_enwiki_latest_archive.torrent");}
|
||||
@Test public void Torrent__fr_d() {fxt.Test__torrent_link("fr.wiktionary.org" , "https://archive.org/download/Xowa_frwiki_latest_archive.torrent");}
|
||||
}
|
||||
class Xobc_info_html__fxt {
|
||||
public void Test__torrent_link(String domain_str, String expd) {
|
||||
Gftest.Eq__str(expd, Xobc_info_html.Make_torrent_fil("https://archive.org/download/", Xow_domain_itm_.parse(Bry_.new_u8(domain_str))));
|
||||
}
|
||||
}
|
@ -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.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
||||
class Xoh_sidebar_htmlr {
|
||||
public static byte[] To_html(Bry_bfr bfr, Xowe_wiki wiki, List_adp grps) {
|
||||
Xoh_sidebar_itms_fmtr itms_fmtr = new Xoh_sidebar_itms_fmtr();
|
||||
int len = grps.Count();
|
||||
boolean popups_enabled = wiki.Appe().Api_root().Html().Modules().Popups().Enabled();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_sidebar_itm grp = (Xoh_sidebar_itm)grps.Get_at(i);
|
||||
itms_fmtr.Init_by_grp(popups_enabled, grp);
|
||||
fmt.Bld_many(bfr, grp.Id(), grp.Text(), itms_fmtr);
|
||||
}
|
||||
return bfr.To_bry_and_clear();
|
||||
}
|
||||
private static final Bry_fmt fmt = Bry_fmt.Auto_nl_skip_last
|
||||
( "<div class=\"portal\" id=\"~{grp_id}\">"
|
||||
, " <h3>~{grp_text}</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, ""
|
||||
);
|
||||
}
|
||||
class Xoh_sidebar_itms_fmtr implements Bfr_arg {
|
||||
private boolean popups_enabled; private Xoh_sidebar_itm grp;
|
||||
public void Init_by_grp(boolean popups_enabled, Xoh_sidebar_itm grp) {this.popups_enabled = popups_enabled; this.grp = grp;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
String itm_cls = popups_enabled ? " class='xowa-hover-off'" : "";
|
||||
int len = grp.Subs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoh_sidebar_itm itm = grp.Subs__get_at(i);
|
||||
fmt.Bld_many(bfr, itm.Id(), itm.Href(), itm_cls, itm.Atr_accesskey_and_title(), itm.Text());
|
||||
}
|
||||
}
|
||||
private final Bry_fmt fmt = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " <li id=\"~{itm_id}\"><a href=\"~{itm_href}\"~{itm_cls}~{itm_accesskey_and_title}>~{itm_text}</a></li>"
|
||||
);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
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.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
public class Xoh_sidebar_itm {
|
||||
public Xoh_sidebar_itm(boolean tid_is_itm, byte[] text_key, byte[] text_val, byte[] href) {
|
||||
this.tid_is_itm = tid_is_itm;
|
||||
this.id = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(Bry_.Add(CONST_id_prefix, text_key)); // build id; EX:"n-encoded_id"
|
||||
this.text = text_val;
|
||||
this.href = href;
|
||||
}
|
||||
public boolean Tid_is_itm() {return tid_is_itm;} private final boolean tid_is_itm;
|
||||
public byte[] Id() {return id;} private final byte[] id;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public byte[] Href() {return href;} private final byte[] href;
|
||||
public byte[] Title() {return title;} private byte[] title;
|
||||
public byte[] Accesskey() {return accesskey;} private byte[] accesskey;
|
||||
public byte[] Atr_accesskey_and_title() {return atr_accesskey_and_title;} private byte[] atr_accesskey_and_title;
|
||||
public int Subs__len() {return subs.Count();} private final List_adp subs = List_adp_.New();
|
||||
public Xoh_sidebar_itm Subs__get_at(int i) {return (Xoh_sidebar_itm)subs.Get_at(i);}
|
||||
public Xoh_sidebar_itm Subs__add(Xoh_sidebar_itm... ary) {
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i)
|
||||
subs.Add(ary[i]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Init_by_title_and_accesskey(byte[] title, byte[] accesskey, byte[] atr_accesskey_and_title) {
|
||||
this.title = title;
|
||||
this.accesskey = accesskey;
|
||||
this.atr_accesskey_and_title = atr_accesskey_and_title;
|
||||
}
|
||||
|
||||
private static final byte[] CONST_id_prefix = Bry_.new_a7("n-");
|
||||
}
|
@ -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.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.nss.*;
|
||||
public class Xoh_sidebar_mgr {
|
||||
public Xoh_sidebar_mgr(Xowe_wiki wiki) {this.wiki = wiki;} private final Xowe_wiki wiki;
|
||||
public List_adp Grps() {return grps;} private final List_adp grps = List_adp_.New(); // TEST:
|
||||
public byte[] Html_bry() {return html_bry;} private byte[] html_bry;
|
||||
public void Init_by_wiki() {
|
||||
try {
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
byte[] sidebar = Get_sidebar_or_null(tmp_bfr, wiki);
|
||||
if (sidebar != null) Make(tmp_bfr, sidebar);
|
||||
} catch (Exception e) {
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "sidebar failed: wiki=~{0} err=~{1}", wiki.Domain_str(), Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
private byte[] Get_sidebar_or_null(Bry_bfr tmp_bfr, Xowe_wiki wiki) {
|
||||
// if home, always return null
|
||||
if (wiki.Domain_tid() == Xow_domain_tid_.Tid__home) return null;
|
||||
|
||||
// check msg_mgr; note that this checks (a) en.wikipedia.org/wiki/MediaWiki:Sidebar; (b) "sidebar" in en.gfs
|
||||
Xol_msg_itm rv_msg = Xol_msg_mgr_.Get_msg_itm(tmp_bfr, wiki, wiki.Lang(), Ttl__sidebar);
|
||||
|
||||
// if found in MediaWiki:Sidebar, always return it
|
||||
byte[] rv = rv_msg.Val();
|
||||
if (rv_msg.Defined_in() == Xol_msg_itm.Defined_in__wiki && Bry_.Len_gt_0(rv)) return rv;
|
||||
|
||||
// sidebar is either (a) in lang.gfs (wikia; wmf wikis without MediaWiki:Sidebar), or (b) not even in lang.gfs (wmf wikis in lang.gfs without "lang.gfs"; EX:de.gfs)
|
||||
return null;
|
||||
}
|
||||
public void Make(Bry_bfr tmp_bfr, byte[] src) { // TEST:
|
||||
Xoh_sidebar_parser.Parse(tmp_bfr, wiki, grps, src);
|
||||
html_bry = Xoh_sidebar_htmlr.To_html(tmp_bfr, wiki, grps);
|
||||
}
|
||||
private static final byte[] Ttl__sidebar = Bry_.new_a7("Sidebar"); // MediaWiki:Sidebar
|
||||
}
|
@ -0,0 +1,234 @@
|
||||
/*
|
||||
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.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
public class Xoh_sidebar_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private final Xoh_sidebar_mgr_fxt fxt = new Xoh_sidebar_mgr_fxt();
|
||||
@Test public void Grp() {
|
||||
fxt.Init__msg__grp("key", "text", "title");
|
||||
fxt.Exec__make("* key");
|
||||
fxt.Test__objs(fxt.Make__grp("text", "title"));
|
||||
}
|
||||
@Test public void Grp_missing_msg() {
|
||||
fxt.Exec__make("* key");
|
||||
fxt.Test__objs(fxt.Make__grp("key", Null_str));
|
||||
}
|
||||
@Test public void Itm() {
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
||||
}
|
||||
@Test public void Itm_missing_msg() {
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Href_key"));
|
||||
}
|
||||
@Test public void Itm_text() { // PURPOSE: only text msg exists; EX: ** Portal:Contents|contents; no href, accesskey, title
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", Null_str, Null_str, Null_str); // only define msg for text
|
||||
fxt.Exec__make("** href_key|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("text", Null_str, Null_str, "/wiki/Href_key"));
|
||||
}
|
||||
@Test public void Itm_href_absolute() {
|
||||
fxt.Exec__make("** http://a.org|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "http://a.org"));
|
||||
}
|
||||
@Test public void Itm_href_manual() {
|
||||
fxt.Exec__make("** Help:Contents|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/wiki/Help:Contents"));
|
||||
}
|
||||
@Test public void Itm_href_xwiki() {
|
||||
Xop_fxt.Reg_xwiki_alias(fxt.Wiki(), "c", "commons.wikimedia.org");
|
||||
fxt.Exec__make("** c:Help:Contents|main_key");
|
||||
fxt.Test__objs(fxt.Make__itm("main_key", Null_str, Null_str, "/site/commons.wikimedia.org/wiki/Help:Contents"));
|
||||
}
|
||||
@Test public void Itm_err_missing_key() {
|
||||
fxt.Exec__make("** no_main_key");
|
||||
fxt.Test__objs();
|
||||
}
|
||||
@Test public void Itm_ignore() { // PURPOSE: ignore SEARCH, TOOLBOX, LANGUAGES
|
||||
fxt.Exec__make
|
||||
( "** SEARCH"
|
||||
, "** TOOLBOX"
|
||||
, "** LANGUAGES"
|
||||
);
|
||||
fxt.Test__objs();
|
||||
}
|
||||
@Test public void Itm_comment() { // PURPOSE: ignore comment; EX:de.v:MediaWiki:Sidebar; DATE:2014-03-08
|
||||
fxt.Init__msg__itm("href_key", "main_key", "text", "title", "accesskey", "href");
|
||||
fxt.Exec__make("** href_key<!--a-->|main_key<!--b-->");
|
||||
fxt.Test__objs(fxt.Make__itm("text", "title", "accesskey", "/wiki/Href"));
|
||||
}
|
||||
@Test public void Smoke() {
|
||||
fxt.Init__msg__grp("navigation", "Grp_0_text", "Grp_0_title");
|
||||
fxt.Init__msg__itm("mainpage", "mainpage-description", "Itm_0_text", "Itm_0_title [a]", "a", "Itm_0_href");
|
||||
fxt.Init__msg__itm("Portal:Contents", "contents", "Itm_1_text", Null_str, Null_str, Null_str);
|
||||
fxt.Exec__make
|
||||
( "* navigation"
|
||||
, "** mainpage|mainpage-description"
|
||||
, "** Portal:Contents|contents"
|
||||
, "* SEARCH"
|
||||
, "* interaction"
|
||||
, "** helppage|help"
|
||||
, "* TOOLBOX"
|
||||
, "** TOOLBOXEND"
|
||||
, "* LANGUAGES"
|
||||
);
|
||||
fxt.Test__objs
|
||||
( fxt.Make__grp("Grp_0_text", "Grp_0_title").Subs__add
|
||||
( fxt.Make__itm("Itm_0_text", "Itm_0_title [a]", "a", "/wiki/Itm_0_href")
|
||||
, fxt.Make__itm("Itm_1_text", Null_str, Null_str, "/wiki/Portal:Contents")
|
||||
)
|
||||
, fxt.Make__grp("interaction", Null_str).Subs__add
|
||||
( fxt.Make__itm("help", Null_str, Null_str, "/wiki/Helppage")
|
||||
));
|
||||
fxt.Test__html
|
||||
( "<div class=\"portal\" id=\"n-navigation\">"
|
||||
, " <h3>Grp_0_text</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Itm_0_href\" accesskey=\"a\" title=\"Itm_0_title [a] [a]\">Itm_0_text</a></li>"
|
||||
, " <li id=\"n-contents\"><a href=\"/wiki/Portal:Contents\" title=\"\">Itm_1_text</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
, "<div class=\"portal\" id=\"n-interaction\">"
|
||||
, " <h3>interaction</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-help\"><a href=\"/wiki/Helppage\" title=\"\">help</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
||||
@Test public void Itm_template_msg() {
|
||||
fxt.Init__msg__itm("href", "main", null, null, null, "{{ns:Special}}:Random");
|
||||
fxt.Exec__make("** href|main");
|
||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||
}
|
||||
@Test public void Itm_template_key() {
|
||||
fxt.Exec__make("** {{ns:Special}}:Random|main");
|
||||
fxt.Test__objs(fxt.Make__itm("main", Null_str, Null_str, "/wiki/Special:Random"));
|
||||
}
|
||||
@Test public void Popups() {
|
||||
fxt.Init__popups_enabled(true);
|
||||
fxt.Exec__make
|
||||
( "* navigation"
|
||||
, "** mainpage|mainpage-description"
|
||||
);
|
||||
fxt.Test__objs
|
||||
( fxt.Make__grp("navigation", "").Subs__add
|
||||
( fxt.Make__itm("mainpage-description", Null_str, Null_str, "/wiki/Mainpage")
|
||||
));
|
||||
fxt.Test__html
|
||||
( "<div class=\"portal\" id=\"n-navigation\">"
|
||||
, " <h3>navigation</h3>"
|
||||
, " <div class=\"body\">"
|
||||
, " <ul>"
|
||||
, " <li id=\"n-mainpage-description\"><a href=\"/wiki/Mainpage\" class='xowa-hover-off' title=\"\">mainpage-description</a></li>"
|
||||
, " </ul>"
|
||||
, " </div>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
||||
private static final String Null_str = "";
|
||||
}
|
||||
class Xoh_sidebar_mgr_fxt {
|
||||
private Xoae_app app; private Xowe_wiki wiki; private Xoh_sidebar_mgr sidebar_mgr; private Bry_bfr bfr;
|
||||
public Xoh_sidebar_mgr_fxt Clear() {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
sidebar_mgr = wiki.Html_mgr().Portal_mgr().Sidebar_mgr();
|
||||
bfr = Bry_bfr_.Reset(Io_mgr.Len_kb);
|
||||
Init__popups_enabled(false);
|
||||
return this;
|
||||
}
|
||||
public Xowe_wiki Wiki() {return wiki;}
|
||||
public Xoh_sidebar_itm Make__grp(String text, String title, Xoh_sidebar_itm... itms) {
|
||||
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.N, Bry_.new_a7(text), Bry_.new_a7(text), null);
|
||||
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), null, null);
|
||||
return rv;
|
||||
}
|
||||
public Xoh_sidebar_itm Make__itm(String text, String title, String accesskey, String href) {
|
||||
Xoh_sidebar_itm rv = new Xoh_sidebar_itm(Bool_.Y, Bry_.new_a7(text), Bry_.new_a7(text), Bry_.new_a7(href));
|
||||
rv.Init_by_title_and_accesskey(Bry_.new_a7(title), Bry_.new_a7(accesskey), null);
|
||||
return rv;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init__popups_enabled(boolean v) {app.Api_root().Html().Modules().Popups().Enabled_(v); return this;}
|
||||
public Xoh_sidebar_mgr_fxt Init__msg__grp(String key, String text, String title) {
|
||||
Init_msg(key, text);
|
||||
Init_msg("tooltip-n-" + key, title);
|
||||
return this;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init__msg__itm(String href_key, String main_key, String text, String title, String accesskey, String href) {
|
||||
if (text != null) Init_msg(main_key, text);
|
||||
if (href != null) Init_msg(href_key, href);
|
||||
if (title != null) Init_msg("tooltip-n-" + main_key, title);
|
||||
if (accesskey != null) Init_msg("accesskey-n-" + main_key, accesskey);
|
||||
return this;
|
||||
}
|
||||
public Xoh_sidebar_mgr_fxt Init_msg(String key, String val) {
|
||||
Xol_msg_mgr msg_mgr = wiki.Lang().Msg_mgr();
|
||||
Xol_msg_itm msg_itm = msg_mgr.Itm_by_key_or_new(Bry_.new_a7(key));
|
||||
msg_itm.Atrs_set(Bry_.new_a7(val), false, String_.Has(val, "{{"));
|
||||
return this;
|
||||
}
|
||||
public void Exec__make(String... raw) {
|
||||
sidebar_mgr.Make(bfr, Bry_.new_u8(String_.Concat_lines_nl_skip_last(raw)));
|
||||
}
|
||||
public void Test__objs(Xoh_sidebar_itm... expd) {
|
||||
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
|
||||
}
|
||||
public void Test__objs(String raw, Xoh_sidebar_itm... expd) {
|
||||
Tfds.Eq_str_lines(To_str_by_itms(expd), To_str_by_mgr(sidebar_mgr));
|
||||
}
|
||||
public void Test__html(String... expd) {
|
||||
Tfds.Eq_str_lines(String_.Concat_lines_nl_skip_last(expd), String_.new_u8(sidebar_mgr.Html_bry()));
|
||||
}
|
||||
private static String To_str_by_mgr(Xoh_sidebar_mgr mgr) {
|
||||
List_adp grps = mgr.Grps();
|
||||
int len = grps.Len();
|
||||
Xoh_sidebar_itm[] ary = new Xoh_sidebar_itm[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
ary[i] = (Xoh_sidebar_itm)grps.Get_at(i);
|
||||
return To_str_by_itms(ary);
|
||||
}
|
||||
|
||||
private static String To_str_by_itms(Xoh_sidebar_itm[] ary) {
|
||||
Bry_bfr bfr = Bry_bfr_.New();
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
To_str_by_itm(bfr, ary[i]);
|
||||
return bfr.To_str_and_clear();
|
||||
}
|
||||
private static void To_str_by_itm(Bry_bfr bfr, Xoh_sidebar_itm cur) {
|
||||
boolean tid_is_itm = cur.Tid_is_itm();
|
||||
bfr.Add_str_a7(tid_is_itm ? "itm|" : "grp|");
|
||||
bfr.Add(cur.Text()).Add_byte_pipe();
|
||||
bfr.Add(cur.Title()).Add_byte_pipe();
|
||||
if (tid_is_itm) {
|
||||
bfr.Add(cur.Accesskey()).Add_byte_pipe();
|
||||
bfr.Add(cur.Href()).Add_byte_pipe();
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
|
||||
int len = cur.Subs__len();
|
||||
for (int i = 0; i< len; ++i)
|
||||
To_str_by_itm(bfr, cur.Subs__get_at(i));
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
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.addons.htmls.sidebars; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.htmls.*;
|
||||
import gplx.core.btries.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.parsers.lnkis.*;
|
||||
class Xoh_sidebar_parser { // TS:
|
||||
public static void Parse(Bry_bfr tmp_bfr, Xowe_wiki wiki, List_adp grps, byte[] src) {
|
||||
// split MediaWiki:Sidebar into lines
|
||||
byte[][] lines = Bry_split_.Split(src, Byte_ascii.Nl);
|
||||
|
||||
// init
|
||||
Xop_link_parser link_parser = new Xop_link_parser();
|
||||
Xoa_url tmp_url = Xoa_url.blank();
|
||||
Xoh_sidebar_itm cur_grp = null;
|
||||
|
||||
// loop lines
|
||||
int lines_len = lines.length;
|
||||
for (int i = 0; i < lines_len; i++) {
|
||||
byte[] line = lines[i];
|
||||
int line_len = line.length;
|
||||
if (line_len == 0) continue; // skip blank lines
|
||||
if (line[0] != Byte_ascii.Star) continue; // skip non-list items; note that all items must begin with "*"
|
||||
|
||||
// if **, then itm; else * is grp
|
||||
boolean tid_is_itm = line[1] == Byte_ascii.Star;
|
||||
|
||||
// trim ws; note that tid indicates # of asterisks; EX: '** a' -> 'a'
|
||||
byte[] raw = Bry_.Trim(line, tid_is_itm ? 2 : 1, line_len);
|
||||
|
||||
// strip comments; DATE:2014-03-08
|
||||
raw = gplx.langs.htmls.Gfh_utl.Del_comments(tmp_bfr, raw);
|
||||
|
||||
Xoh_sidebar_itm cur_itm = null;
|
||||
// parse itm
|
||||
if (tid_is_itm) {
|
||||
cur_itm = Parse_itm_or_null(wiki, raw, link_parser, tmp_url, tmp_bfr); if (cur_itm == null) continue;
|
||||
if (cur_grp == null) // handle null_ref; should only occur for tests
|
||||
grps.Add(cur_itm);
|
||||
else
|
||||
cur_grp.Subs__add(cur_itm);
|
||||
}
|
||||
// parse grp
|
||||
else {
|
||||
cur_itm = Parse_grp_or_null(wiki, raw); if (cur_itm == null) continue;
|
||||
cur_grp = cur_itm;
|
||||
grps.Add(cur_grp);
|
||||
}
|
||||
wiki.Msg_mgr().Val_html_accesskey_and_title(cur_itm.Id(), tmp_bfr, cur_itm);
|
||||
}
|
||||
}
|
||||
private static Xoh_sidebar_itm Parse_grp_or_null(Xowe_wiki wiki, byte[] raw) {
|
||||
// ignore SEARCH, TOOLBOX, LANGUAGES
|
||||
if (ignore_trie.Match_bgn(raw, 0, raw.length) != null) return null;
|
||||
|
||||
byte[] text_key = raw;
|
||||
byte[] text_val = Resolve_key(wiki, text_key);
|
||||
return new Xoh_sidebar_itm(Bool_.N, text_key, text_val, null);
|
||||
}
|
||||
private static Xoh_sidebar_itm Parse_itm_or_null(Xowe_wiki wiki, byte[] raw, Xop_link_parser link_parser, Xoa_url tmp_url, Bry_bfr bfr) {
|
||||
// separate into key|val; note that grp uses entire raw for key while itm uses raw after "|"
|
||||
int pipe_pos = Bry_find_.Find_fwd(raw, Byte_ascii.Pipe);
|
||||
|
||||
// if no pipe, warn and return; EX: should be "href|main", but only "href"
|
||||
if (pipe_pos == Bry_find_.Not_found) {
|
||||
// don't bother warning if es.wikisource.org and special:Random/Pagina; occurs in 2014-02-03 dump and still present as of 2016-09; note this sidebar item does not show on WMF either
|
||||
if (Bry_.Eq(wiki.Domain_bry(), Ignore_wiki_ess) && Bry_.Eq(raw, Ignore_item_ess_random)) {}
|
||||
else
|
||||
wiki.Appe().Usr_dlg().Warn_many("", "", "sidebar item is missing pipe; only href is available; item will be hidden: item=~{0}", String_.new_u8(raw));
|
||||
return null;
|
||||
}
|
||||
|
||||
// get text
|
||||
byte[] text_key = Bry_.Mid(raw, pipe_pos + 1, raw.length);
|
||||
byte[] text_val = Resolve_key(wiki, text_key);
|
||||
|
||||
// get href
|
||||
byte[] href_key = Bry_.Mid(raw, 0, pipe_pos);
|
||||
byte[] href_val = Resolve_key(wiki, href_key);
|
||||
href_val = link_parser.Parse(bfr, tmp_url, wiki, href_val, Bry_.Empty);
|
||||
|
||||
return new Xoh_sidebar_itm(Bool_.Y, text_key, text_val, href_val);
|
||||
}
|
||||
private static byte[] Resolve_key(Xowe_wiki wiki, byte[] key) {
|
||||
byte[] val = wiki.Msg_mgr().Val_by_key_obj(key);
|
||||
if (Bry_.Len_eq_0(val)) val = key; // if key is not found, default to val
|
||||
return wiki.Parser_mgr().Main().Expand_tmpl(val);
|
||||
}
|
||||
|
||||
private static byte[] Ignore_wiki_ess = Bry_.new_a7("es.wikisource.org"), Ignore_item_ess_random = Bry_.new_u8("special:Random/Página djvu");
|
||||
private static final byte Ignore__search = 1, Ignore__toolbox = 2, Ignore__toolbox_end = 3, Ignore__languages = 4;
|
||||
private static final Btrie_slim_mgr ignore_trie = Btrie_slim_mgr.ci_a7()
|
||||
.Add_str_byte("SEARCH" , Ignore__search)
|
||||
.Add_str_byte("TOOLBOX" , Ignore__toolbox)
|
||||
.Add_str_byte("TOOLBOXEND" , Ignore__toolbox_end)
|
||||
.Add_str_byte("LANGUAGES" , Ignore__languages)
|
||||
;
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xob_catlink_cmd extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
private final Xob_catlink_mgr mgr = new Xob_catlink_mgr();
|
||||
private int tmp_page_id;
|
||||
private byte[] tmp_ctg_ttl, tmp_sortkey, tmp_timestamp, tmp_sortkey_prefix, tmp_collation, tmp_type;
|
||||
|
||||
public Xob_catlink_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
@Override public String Sql_file_name() {return Dump_file_name;} public static final String Dump_file_name = "categorylinks";
|
||||
|
||||
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Sql_file_parser parser) {
|
||||
wiki.Init_assert();
|
||||
parser.Save_csv_n_().Fld_cmd_(this).Flds_req_idx_(7, 0, 1, 2, 3, 4, 5, 6);
|
||||
mgr.On_cmd_bgn(wiki);
|
||||
}
|
||||
@Override public void Cmd_end() {
|
||||
mgr.On_cmd_end();
|
||||
this.Cmd_cleanup_sql();
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
switch (fld_idx) {
|
||||
case Fld__cl_from: this.tmp_page_id = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld__cl_to: this.tmp_ctg_ttl = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_sortkey: this.tmp_sortkey = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_timestamp: this.tmp_timestamp = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_sortkey_prefix: this.tmp_sortkey_prefix = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_collation: this.tmp_collation = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_type: this.tmp_type = Bry_.Mid(src, fld_bgn, fld_end);
|
||||
mgr.On_cmd_row(tmp_page_id, tmp_ctg_ttl, tmp_sortkey, tmp_timestamp, tmp_sortkey_prefix, tmp_collation, tmp_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
private static final byte Fld__cl_from = 0, Fld__cl_to = 1, Fld__cl_sortkey = 2, Fld__cl_timestamp = 3, Fld__cl_sortkey_prefix = 4, Fld__cl_collation = 5, Fld__cl_type = 6;
|
||||
|
||||
public static final String BLDR_CMD_KEY = "wiki.categorylinks";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xob_catlink_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xob_catlink_cmd(bldr, wiki);}
|
||||
}
|
@ -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.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.enums.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.bldrs.ucas.*;
|
||||
class Xob_catlink_mgr {
|
||||
private Xowe_wiki wiki;
|
||||
private Xodb_tmp_cat_db tmp_db; private Db_conn tmp_conn; private Xodb_tmp_cat_link_tbl tmp_link_tbl;
|
||||
private final Xoctg_collation_enum collation_enum = new Xoctg_collation_enum(); private final Xoctg_type_enum type_enum = new Xoctg_type_enum();
|
||||
private Uca_trie trie; private final Bry_bfr uca_bfr = Bry_bfr_.New();
|
||||
private int rows = 0;
|
||||
public void On_cmd_bgn(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
|
||||
// init tmp_db, tmp_link_tbl
|
||||
this.tmp_db = new Xodb_tmp_cat_db(wiki);
|
||||
this.tmp_conn = tmp_db.Conn();
|
||||
this.tmp_link_tbl = new Xodb_tmp_cat_link_tbl(tmp_conn);
|
||||
tmp_link_tbl.Insert_bgn();
|
||||
}
|
||||
public void On_cmd_row(int page_id, byte[] ctg_ttl, byte[] sortkey_orig, byte[] timestamp_bry, byte[] sortkey_prefix, byte[] collation_bry, byte[] type_bry) {
|
||||
// convert strings to numbers
|
||||
long timestamp = DateAdp_.parse_fmt(String_.new_u8(timestamp_bry), "YYYY-MM-dd HH:mm:ss").Timestamp_unix();
|
||||
byte collation_id = collation_enum.To_tid_or_fail(collation_bry);
|
||||
byte type_id = type_enum.To_tid_or_fail(type_bry);
|
||||
|
||||
// sortkey; handle \n
|
||||
byte[] sortkey_actl = sortkey_orig;
|
||||
int nl_pos = Bry_find_.Find_fwd(sortkey_actl, Byte_ascii.Nl);
|
||||
if (nl_pos != Bry_find_.Not_found) // some sortkeys have format of "sortkey\ntitle"; discard 2nd to conserve hard-disk space; EX: "WALES, JIMMY\nJIMMY WALES"
|
||||
sortkey_actl = Bry_.Mid(sortkey_actl, 0, nl_pos); // NOTE: some sortkeys have space which will sort under " "; EX: ' \nART' -> " "; SEE: s.w:Category:Art
|
||||
|
||||
// sortkey; handle uca
|
||||
if (collation_id == Xoctg_collation_enum.Tid__uca) {
|
||||
if (trie == null) trie = new Uca_trie();
|
||||
trie.Decode(uca_bfr, sortkey_actl, 0, sortkey_actl.length);
|
||||
sortkey_actl = uca_bfr.Len() == 0 ? Byte_ascii.Space_bry : uca_bfr.To_bry_and_clear();
|
||||
}
|
||||
|
||||
// insert to tmp; notify; commit
|
||||
tmp_link_tbl.Insert_cmd_by_batch(page_id, ctg_ttl, sortkey_actl, timestamp, sortkey_prefix, collation_id, type_id);
|
||||
if (++rows % 100000 == 0) {
|
||||
Gfo_usr_dlg_.Instance.Prog_many("", "", "parsing categorylinks sql: ~{0}", Int_.To_str_fmt(rows, "#,##0"));
|
||||
tmp_conn.Txn_sav();
|
||||
}
|
||||
}
|
||||
public void On_cmd_end() {
|
||||
tmp_link_tbl.Insert_end();
|
||||
|
||||
// create cat_sort
|
||||
tmp_link_tbl.Create_idx__sortkey(); // index should make SELECT DISTINCT faster
|
||||
Db_conn cat_core_conn = wiki.Data__core_mgr().Props().Layout_text().Tid_is_lot()
|
||||
? wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__cat_core).Conn()
|
||||
: wiki.Data__core_mgr().Db__core().Conn();
|
||||
Xodb_cat_sort_tbl cat_sort_tbl = new Xodb_cat_sort_tbl(cat_core_conn);
|
||||
cat_core_conn.Meta_tbl_remake(cat_sort_tbl);
|
||||
cat_sort_tbl.Insert_by_select(tmp_conn);
|
||||
|
||||
// make catlink_dbs
|
||||
cat_sort_tbl.Create_idx__key(); // index will be needed for join
|
||||
tmp_link_tbl.Create_idx__to_ttl(); // index will be needed for join
|
||||
Db_conn page_conn = wiki.Data__core_mgr().Db__core().Conn();
|
||||
Xob_catlink_wkr wkr = new Xob_catlink_wkr();
|
||||
wkr.Make_catlink_dbs(wiki, tmp_conn, page_conn, cat_core_conn);
|
||||
|
||||
// make catcore_tbl; update page!cat_db_id
|
||||
wkr.Make_catcore_tbl(wiki, tmp_conn, page_conn, cat_core_conn);
|
||||
wkr.Update_page_cat_db_id(wiki, page_conn);
|
||||
|
||||
// cleanup
|
||||
cat_sort_tbl.Delete_idx__key(); // remove idx
|
||||
tmp_db.Delete();
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
class Xob_catlink_wkr {
|
||||
public void Make_catlink_dbs(Xowe_wiki wiki, Db_conn tmp_conn, Db_conn page_conn, Db_conn cat_core_conn) {
|
||||
// init select
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(page_conn, new Db_attach_itm("temp_db", tmp_conn), new Db_attach_itm("cat_db", cat_core_conn)); // NOTE: main_conn must be page_conn, else sqlite will be very slow when doing insert
|
||||
String sql = attach_mgr.Resolve_sql(String_.Concat_lines_nl_skip_last
|
||||
( "SELECT tcl.cl_from"
|
||||
, ", p.page_id"
|
||||
, ", tcl.cl_type_id"
|
||||
, ", cs.cs_id"
|
||||
, ", tcl.cl_timestamp"
|
||||
, "FROM <temp_db>tmp_cat_link tcl"
|
||||
, " JOIN <cat_db>cat_sort cs ON tcl.cl_sortkey = cs.cs_key"
|
||||
, " JOIN page p ON p.page_namespace = 14 AND tcl.cl_to_ttl = p.page_title"
|
||||
, "ORDER BY 1" // NOTE: must sort by page_id to keep all cats for page in one db
|
||||
));
|
||||
attach_mgr.Attach();
|
||||
|
||||
// select from tmp_db and insert insert into cat_link
|
||||
Xodb_cat_link_tbl cat_link_tbl = Make_cat_link_tbl(wiki, null);
|
||||
Db_rdr rdr = attach_mgr.Conn_main().Stmt_sql(sql).Exec_select__rls_auto();
|
||||
try {
|
||||
// misc row vals
|
||||
long db_size_cur = 0, db_size_max = wiki.Appe().Api_root().Bldr().Wiki().Import().Cat_link_db_max();
|
||||
int page_id_prv = -1;
|
||||
int rows = 0;
|
||||
while (rdr.Move_next()) {
|
||||
// check if row can fit in db; else update db_size
|
||||
int page_id_cur = rdr.Read_int("cl_from");
|
||||
long db_size_new = db_size_cur + 46;// 46 = 3 ints (12) + 1 long (8) + 1 byte (2?) + 2 index (24?) + 9 fudge factor (?); DATE:2016-09-06
|
||||
if ( db_size_cur > db_size_max // size exceeded
|
||||
&& page_id_cur != page_id_prv) { // and page_id is diff; keeps all page_ids in one db
|
||||
cat_link_tbl = Make_cat_link_tbl(wiki, cat_link_tbl);
|
||||
db_size_new = 0;
|
||||
}
|
||||
db_size_cur = db_size_new;
|
||||
page_id_prv = page_id_cur;
|
||||
|
||||
// insert; notify;
|
||||
cat_link_tbl.Insert_cmd_by_batch(page_id_prv, rdr.Read_int("page_id"), rdr.Read_byte("cl_type_id"), rdr.Read_int("cs_id"), rdr.Read_long("cl_timestamp"));
|
||||
if (++rows % 100000 == 0)
|
||||
Gfo_usr_dlg_.Instance.Prog_many("", "", "inserting cat_link row: ~{0}", Int_.To_str_fmt(rows, "#,##0"));
|
||||
}
|
||||
}
|
||||
finally {rdr.Rls();}
|
||||
Term_cat_link_tbl(cat_link_tbl);
|
||||
attach_mgr.Detach(); // NOTE: must detach after txn
|
||||
}
|
||||
private static Xodb_cat_link_tbl Make_cat_link_tbl(Xowe_wiki wiki, Xodb_cat_link_tbl cat_link_tbl) {
|
||||
Term_cat_link_tbl(cat_link_tbl);
|
||||
|
||||
// get cat_link_conn
|
||||
Db_conn cat_link_conn = wiki.Data__core_mgr().Props().Layout_text().Tid_is_lot()
|
||||
? wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__cat_link).Conn()
|
||||
: wiki.Data__core_mgr().Db__core().Conn();
|
||||
|
||||
// make tbl
|
||||
Xodb_cat_link_tbl rv = new Xodb_cat_link_tbl(cat_link_conn);
|
||||
cat_link_conn.Meta_tbl_remake(rv);
|
||||
rv.Insert_bgn();
|
||||
return rv;
|
||||
}
|
||||
private static void Term_cat_link_tbl(Xodb_cat_link_tbl cat_link_tbl) {
|
||||
if (cat_link_tbl == null) return;
|
||||
cat_link_tbl.Insert_end();
|
||||
cat_link_tbl.Create_idx__from();
|
||||
cat_link_tbl.Create_idx__to_id();
|
||||
}
|
||||
public void Make_catcore_tbl(Xowe_wiki wiki, Db_conn tmp_conn, Db_conn page_conn, Db_conn cat_core_conn) {
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(cat_core_conn, new Db_attach_itm("temp_db", tmp_conn), new Db_attach_itm("page_db", page_conn));
|
||||
Xowd_cat_core_tbl cat_core_tbl = new Xowd_cat_core_tbl(cat_core_conn, Bool_.N);
|
||||
cat_core_conn.Meta_tbl_remake(cat_core_tbl);
|
||||
String sql = String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "INSERT INTO cat_core (cat_id, cat_pages, cat_subcats, cat_files, cat_hidden, cat_link_db_id)"
|
||||
, "SELECT p.page_id"
|
||||
, ", Sum(CASE WHEN tcl.cl_type_id = 2 THEN 1 ELSE 0 END)"
|
||||
, ", Sum(CASE WHEN tcl.cl_type_id = 0 THEN 1 ELSE 0 END)"
|
||||
, ", Sum(CASE WHEN tcl.cl_type_id = 1 THEN 1 ELSE 0 END)"
|
||||
, ", CASE WHEN h.cat_id IS NULL THEN 0 ELSE 1 END"
|
||||
, ", -1"
|
||||
, "FROM <temp_db>tmp_cat_link tcl"
|
||||
, " JOIN <page_db>page p ON p.page_namespace = 14 AND tcl.cl_to_ttl = p.page_title"
|
||||
, " LEFT JOIN <temp_db>tmp_cat_hidden h ON h.cat_id = p.page_id"
|
||||
, "GROUP BY p.page_id"
|
||||
);
|
||||
attach_mgr.Exec_sql(sql);
|
||||
}
|
||||
public void Update_page_cat_db_id(Xowe_wiki wiki, Db_conn page_conn) {
|
||||
// assert page_cat_db_id exists
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Xowd_page_tbl page_tbl = db_mgr.Db__core().Tbl__page();
|
||||
page_conn.Meta_fld_append_if_missing(page_tbl.Tbl_name(), page_tbl.Flds__all(), Dbmeta_fld_itm.new_int("page_cat_db_id").Default_(-1));
|
||||
|
||||
// prep sql
|
||||
String sql = String_.Concat_lines_nl_skip_last
|
||||
( "UPDATE page"
|
||||
, "SET page_cat_db_id = {0}"
|
||||
, "WHERE page_id IN (SELECT cl_from FROM <link_db>cat_link WHERE cl_from = page.page_id);"
|
||||
);
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(page_conn);
|
||||
|
||||
// loop cat_link dbs and update page_id
|
||||
boolean layout_is_lot = wiki.Data__core_mgr().Props().Layout_text().Tid_is_lot();
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_db_file link_db = db_mgr.Dbs__get_at(i);
|
||||
switch (link_db.Tid()) {
|
||||
case Xow_db_file_.Tid__core:
|
||||
if (layout_is_lot) continue; // use core_db is all or few; skip if lot;
|
||||
break;
|
||||
case Xow_db_file_.Tid__cat_link:
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
attach_mgr.Conn_links_(new Db_attach_itm("link_db", link_db.Conn()));
|
||||
Gfo_usr_dlg_.Instance.Prog_many("", "", "updating page.cat_db_id; db=~{0}", link_db.Id());
|
||||
attach_mgr.Exec_sql(sql, link_db.Id());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
public class Xob_pageprop_cmd extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
private int tmp_id;
|
||||
private boolean tmp_key_is_hiddencat;
|
||||
private int rows;
|
||||
private Xodb_tmp_cat_hidden_tbl tbl;
|
||||
|
||||
public Xob_pageprop_cmd(Xob_bldr bldr, Xowe_wiki wiki) {this.Cmd_ctor(bldr, wiki);}
|
||||
@Override public String Sql_file_name() {return Dump_file_name;} public static final String Dump_file_name = "page_props";
|
||||
|
||||
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Sql_file_parser parser) {
|
||||
wiki.Init_assert();
|
||||
parser.Save_csv_n_().Fld_cmd_(this).Flds_req_idx_(4, 0, 1, 2); // NOTE: 4 b/c MW added fld_3:pp_sortkey; DATE:2014-04-28
|
||||
Xodb_tmp_cat_db tmp_db = new Xodb_tmp_cat_db(wiki);
|
||||
tbl = new Xodb_tmp_cat_hidden_tbl(tmp_db.Conn());
|
||||
tbl.Insert_bgn();
|
||||
}
|
||||
@Override public void Cmd_end() {
|
||||
tbl.Insert_end();
|
||||
this.Cmd_cleanup_sql();
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
switch (fld_idx) {
|
||||
case Fld__id: this.tmp_id = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld__key: this.tmp_key_is_hiddencat = Bry_.Eq(src, fld_bgn, fld_end, Key_hiddencat); break;
|
||||
case Fld__val:
|
||||
if (!tmp_key_is_hiddencat) {data.Cancel_row_y_(); return;}
|
||||
tbl.Insert_cmd_by_batch(tmp_id);
|
||||
if (++rows % 10000 == 0) usr_dlg.Prog_many("", "", "parsing pageprops sql: row=~{0}", Int_.To_str_fmt(rows, "#,##0"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
private static final byte Fld__id = 0, Fld__key = 1, Fld__val = 2;
|
||||
|
||||
public static final String BLDR_CMD_KEY = "wiki.page_props";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
public static final Xob_cmd Prototype = new Xob_pageprop_cmd(null, null);
|
||||
@Override public Xob_cmd Cmd_clone(Xob_bldr bldr, Xowe_wiki wiki) {return new Xob_pageprop_cmd(bldr, wiki);}
|
||||
|
||||
private static final byte[] Key_hiddencat = Bry_.new_a7("hiddencat");
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
public class Xodb_cat_link_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_from, fld_to_id, fld_type_id, fld_sortkey_id, fld_timestamp_unix;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xodb_cat_link_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cat_link";
|
||||
this.fld_from = flds.Add_int ("cl_from");
|
||||
this.fld_to_id = flds.Add_int ("cl_to_id");
|
||||
this.fld_type_id = flds.Add_byte ("cl_type_id");
|
||||
this.fld_sortkey_id = flds.Add_int ("cl_sortkey_id");
|
||||
this.fld_timestamp_unix = flds.Add_long ("cl_timestamp_unix");
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx__from() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_from, fld_from));}
|
||||
public void Create_idx__to_id() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_to_id, fld_to_id));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("cl__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int from, int to_id, byte type_id, int sortkey_id, long timestamp_unix) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_from , from)
|
||||
.Val_int(fld_to_id , to_id)
|
||||
.Val_byte(fld_type_id , type_id)
|
||||
.Val_int(fld_sortkey_id , sortkey_id)
|
||||
.Val_long(fld_timestamp_unix , timestamp_unix)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
||||
/*
|
||||
NOTE_1: categorylinks row size: 34 + 20 + 12 + (cat_sortkey.length * 2)
|
||||
row length (data) : 34=8+4+4+14+4 ROWID, cl_from, cl_to_id, cl_timestamp, cl_type_id
|
||||
cl_main length (idx) : 20=8+4+4+4 ROWID, cl_from, cl_to_id, cl_type_id
|
||||
cl_from length (idx) : 12=8+4 ROWID, cl_from
|
||||
variable_data length : cat_sortkey.length * 2 sortkey is used for row and cl_main
|
||||
|
||||
Note the following
|
||||
. ints are 4 bytes
|
||||
. tinyint is assumed to be 4 bytes (should be 1, but sqlite only has one numeric datatype, so import all 4?)
|
||||
. varchar(14) is assumed to be 14 bytes (should be 15? +1 for length of varchar?)
|
||||
. calculations work out "too well". comparing 4 databases gets +/- .25 bytes per row. however
|
||||
.. - bytes should not be possible
|
||||
.. +.25 bytes is too low (18 MB out of 5.5 GB).*; there must be other bytes used for page breaks / fragmentation
|
||||
*/
|
@ -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.addons.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
public class Xodb_cat_sort_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_key;
|
||||
public Xodb_cat_sort_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "cat_sort";
|
||||
flds.Add_int_pkey_autonum("cs_id");
|
||||
this.fld_key = flds.Add_str ("cs_key", 255);
|
||||
conn.Rls_reg(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Create_idx__key() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_key, fld_key));}
|
||||
public void Delete_idx__key() {conn.Meta_idx_delete(tbl_name, fld_key);}
|
||||
public void Insert_by_select(Db_conn tmp_conn) {
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(conn, new Db_attach_itm("temp_db", tmp_conn));
|
||||
attach_mgr.Exec_sql(String_.Concat_lines_nl
|
||||
( "INSERT INTO cat_sort (cs_key)"
|
||||
, "SELECT DISTINCT cl_sortkey"
|
||||
, "FROM <temp_db>tmp_cat_link"
|
||||
));
|
||||
}
|
||||
public void Rls() {}
|
||||
}
|
@ -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.addons.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*;
|
||||
public class Xodb_tmp_cat_hidden_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_cat_id;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xodb_tmp_cat_hidden_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "tmp_cat_hidden";
|
||||
this.fld_cat_id = flds.Add_int_pkey ("cat_id");
|
||||
conn.Rls_reg(this);
|
||||
conn.Meta_tbl_remake(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("tch__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_cat_id , page_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.dbs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.dbs.*; import gplx.dbs.qrys.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
public class Xodb_tmp_cat_link_tbl implements Db_tbl {
|
||||
private final Dbmeta_fld_list flds = new Dbmeta_fld_list();
|
||||
private final String fld_from, fld_to_ttl, fld_sortkey, fld_timestamp, fld_sortkey_prefix, fld_collation_id, fld_type_id;
|
||||
private Db_stmt stmt_insert;
|
||||
public Xodb_tmp_cat_link_tbl(Db_conn conn) {
|
||||
this.conn = conn;
|
||||
this.tbl_name = "tmp_cat_link";
|
||||
this.fld_from = flds.Add_int ("cl_from");
|
||||
this.fld_to_ttl = flds.Add_str ("cl_to_ttl", 255);
|
||||
this.fld_sortkey = flds.Add_str ("cl_sortkey", 230);
|
||||
this.fld_timestamp = flds.Add_long ("cl_timestamp");
|
||||
this.fld_sortkey_prefix = flds.Add_str ("cl_sortkey_prefix", 230);
|
||||
this.fld_collation_id = flds.Add_byte ("cl_collation_id");
|
||||
this.fld_type_id = flds.Add_byte ("cl_type_id");
|
||||
conn.Rls_reg(this);
|
||||
conn.Meta_tbl_remake(this);
|
||||
}
|
||||
public Db_conn Conn() {return conn;} private final Db_conn conn;
|
||||
public String Tbl_name() {return tbl_name;} private final String tbl_name;
|
||||
public void Create_tbl() {conn.Meta_tbl_create(Dbmeta_tbl_itm.New(tbl_name, flds));}
|
||||
public void Insert_bgn() {conn.Txn_bgn("tcl__insert"); stmt_insert = conn.Stmt_insert(tbl_name, flds);}
|
||||
public void Insert_end() {conn.Txn_end(); stmt_insert = Db_stmt_.Rls(stmt_insert);}
|
||||
public void Insert_cmd_by_batch(int page_id, byte[] ctg_ttl, byte[] sortkey, long timestamp, byte[] sortkey_prefix, byte collation_id, byte type_id) {
|
||||
stmt_insert.Clear()
|
||||
.Val_int(fld_from , page_id)
|
||||
.Val_bry_as_str(fld_to_ttl , ctg_ttl)
|
||||
.Val_bry_as_str(fld_sortkey , sortkey)
|
||||
.Val_long(fld_timestamp , timestamp)
|
||||
.Val_bry_as_str(fld_sortkey_prefix , sortkey_prefix)
|
||||
.Val_byte(fld_collation_id , collation_id)
|
||||
.Val_byte(fld_type_id , type_id)
|
||||
.Exec_insert();
|
||||
}
|
||||
public void Create_idx__sortkey() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_sortkey, fld_sortkey));}
|
||||
public void Create_idx__to_ttl() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_to_ttl, fld_to_ttl));}
|
||||
public void Rls() {
|
||||
stmt_insert = Db_stmt_.Rls(stmt_insert);
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xoctg_collation_enum {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs()
|
||||
.Add_str_byte("uppercase" , Tid__uppercase)
|
||||
.Add_str_byte("uca" , Tid__uca);
|
||||
public byte To_tid_or_fail(byte[] raw) {
|
||||
byte tid = trie.Match_byte_or(trv, raw, 0, raw.length, Byte_.Max_value_127);
|
||||
if (tid == Byte_.Max_value_127) throw Err_.new_unhandled_default(raw);
|
||||
return tid;
|
||||
}
|
||||
public static final byte Tid__uppercase = 1, Tid__uca = 3;
|
||||
}
|
@ -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.addons.wikis.ctgs.enums; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.core.btries.*;
|
||||
public class Xoctg_type_enum {
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private final Btrie_slim_mgr trie = Btrie_slim_mgr.cs()
|
||||
.Add_str_byte("subcat" , Tid__subc)
|
||||
.Add_str_byte("file" , Tid__file)
|
||||
.Add_str_byte("page" , Tid__page);
|
||||
public byte To_tid_or_fail(byte[] raw) {
|
||||
byte tid = trie.Match_byte_or(trv, raw, 0, raw.length, Byte_.Max_value_127);
|
||||
if (tid == Byte_.Max_value_127) throw Err_.new_unhandled_default(raw);
|
||||
return tid;
|
||||
}
|
||||
public static final byte Tid__subc = 0, Tid__file = 1, Tid__page = 2, Tid_max = 3;
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
class Xoctg_catpage_loader {
|
||||
public Xoctg_catpage_ctg Load_by_ttl_or_null(Xow_wiki wiki, Xoa_ttl cat_ttl) {
|
||||
// get cat_id for cat_ttl from page_tbl
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
Xowd_page_tbl page_tbl = db_mgr.Db__core().Tbl__page();
|
||||
Xowd_page_itm page_itm = page_tbl.Select_by_ttl_as_itm_or_null(cat_ttl);
|
||||
if (page_itm == null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "category does not exist in page table; ttl=~{0}", cat_ttl.Full_db());
|
||||
return null;
|
||||
}
|
||||
|
||||
// get cat_link db from cat_core_tbl
|
||||
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(db_mgr);
|
||||
int cat_id = page_itm.Id();
|
||||
Xowd_category_itm cat_core_itm = cat_core_tbl.Select(cat_id);
|
||||
if (cat_core_itm == Xowd_category_itm.Null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "category does not exist in cat_core table; ttl=~{0}", cat_ttl.Full_db());
|
||||
return null;
|
||||
}
|
||||
|
||||
// load itms from cat_link_db
|
||||
Xoctg_catpage_ctg rv = new Xoctg_catpage_ctg(cat_ttl.Page_txt());
|
||||
if (cat_core_itm.File_idx() == -1) // new v3: loop over all cat_link dbs
|
||||
Search_cat_core_tbls_for_cat_id(rv, wiki, db_mgr, page_tbl.Conn(), cat_core_tbl.Conn(), cat_id);
|
||||
else { // old v2: use cat_link_db
|
||||
Xow_db_file cat_link_db = db_mgr.Dbs__get_by_id_or_fail(cat_core_itm.File_idx());
|
||||
Select_by_cat_id(rv, wiki, page_tbl.Conn(), cat_core_tbl.Conn(), cat_link_db.Conn(), cat_id, Sql_for_v2(cat_id));
|
||||
}
|
||||
rv.Make_itms();
|
||||
return rv;
|
||||
}
|
||||
private static void Search_cat_core_tbls_for_cat_id(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xow_db_mgr db_mgr, Db_conn page_conn, Db_conn cat_core_conn, int cat_id) {
|
||||
// loop over each db unless (a) cat_link_db; (b) core_db (if all or few)
|
||||
int len = db_mgr.Dbs__len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_db_file db_file = db_mgr.Dbs__get_at(i);
|
||||
switch (db_file.Tid()) {
|
||||
case Xow_db_file_.Tid__cat_link: // always use cat_link db
|
||||
break;
|
||||
case Xow_db_file_.Tid__core: // only use core if all or few
|
||||
if (db_mgr.Props().Layout_text().Tid_is_lot())
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
default: // else ignore all other files
|
||||
continue;
|
||||
}
|
||||
Select_by_cat_id(rv, wiki, page_conn, cat_core_conn, db_file.Conn(), cat_id, Sql_for_v3(cat_id));
|
||||
}
|
||||
}
|
||||
private static void Select_by_cat_id(Xoctg_catpage_ctg rv, Xow_wiki wiki, Db_conn page_conn, Db_conn cat_core_conn, Db_conn cat_link_conn, int cat_id, String sql) {
|
||||
// prep sql
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(cat_link_conn, new Db_attach_itm("page_db", page_conn), new Db_attach_itm("cat_core_db", cat_core_conn));
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
attach_mgr.Attach();
|
||||
|
||||
// run sql and create itms based on cat_link
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
try {
|
||||
rdr = cat_link_conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(rdr.Read_int("cl_from"), page_ttl, Bry_.new_u8(rdr.Read_str("cl_sortkey")));
|
||||
rv.Grp_by_tid(rdr.Read_byte("cl_type_id")).Itms__add(itm);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
}
|
||||
private static String Sql_for_v3(int cat_id) {
|
||||
return String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "SELECT cl.cl_from"
|
||||
, ", cl.cl_type_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", cs.cs_key AS cl_sortkey"
|
||||
, "FROM cat_link cl"
|
||||
, " JOIN <page_db>page p ON cl.cl_from = p.page_id"
|
||||
, " JOIN <cat_core_db>cat_sort cs ON cl.cl_sortkey_id = cs.cs_id"
|
||||
, "WHERE cl.cl_to_id = " + Int_.To_str(cat_id)
|
||||
);
|
||||
}
|
||||
private static String Sql_for_v2(int cat_id) { // NOTE: main difference is cl_sortkey is on cat_link, not in cat_sort
|
||||
return String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "SELECT cl.cl_from"
|
||||
, ", cl.cl_type_id"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, ", cl.cl_sortkey"
|
||||
, "FROM cat_link cl"
|
||||
, " JOIN <page_db>page p ON cl.cl_from = p.page_id"
|
||||
, "WHERE cl.cl_to_id = " + Int_.To_str(cat_id)
|
||||
);
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_mgr {
|
||||
private final Xoctg_catpage_loader loader = new Xoctg_catpage_loader();
|
||||
private final Xoctg_catpage_url tmp_catpage_url = new Xoctg_catpage_url();
|
||||
private final Xoctg_fmt_grp fmt_subcs = Xoctg_fmt_grp.New__subc(), fmt_pages = Xoctg_fmt_grp.New__page(), fmt_files = Xoctg_fmt_grp.New__file();
|
||||
public Xoctg_fmt_grp Fmt(byte tid) { // TEST:
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: return fmt_subcs;
|
||||
case Xoa_ctg_mgr.Tid_page: return fmt_pages;
|
||||
case Xoa_ctg_mgr.Tid_file: return fmt_files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Write_catpage(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xoh_wtr_ctx hctx) {
|
||||
try {
|
||||
// load categories from cat dbs; exit if not found
|
||||
tmp_catpage_url.Parse(wiki.App().Usr_dlg(), page.Url());
|
||||
Xoctg_catpage_ctg dom_ctg = loader.Load_by_ttl_or_null(wiki, page.Ttl());
|
||||
if (dom_ctg == null) return;
|
||||
|
||||
// write html
|
||||
Xol_lang_itm lang = page.Lang();
|
||||
fmt_subcs.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
fmt_pages.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
fmt_files.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Xoa_app_.Usr_dlg().Warn_many("", "", "failed to generate category: title=~{0} err=~{1}", page.Url_bry_safe(), Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_ctg {
|
||||
public Xoctg_catpage_ctg(byte[] name) {this.name = name;}
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public Xoctg_catpage_grp Subcs() {return subcs;} private final Xoctg_catpage_grp subcs = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_subc);
|
||||
public Xoctg_catpage_grp Pages() {return pages;} private final Xoctg_catpage_grp pages = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_page);
|
||||
public Xoctg_catpage_grp Files() {return files;} private final Xoctg_catpage_grp files = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_file);
|
||||
public int Total() {return subcs.Total() + pages.Total() + files.Total();}
|
||||
public Xoctg_catpage_grp Grp_by_tid(byte tid) {
|
||||
switch (tid) {
|
||||
case Xoa_ctg_mgr.Tid_subc: return subcs;
|
||||
case Xoa_ctg_mgr.Tid_page: return pages;
|
||||
case Xoa_ctg_mgr.Tid_file: return files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Make_itms() {
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; ++i) {
|
||||
Xoctg_catpage_grp grp = Grp_by_tid(i);
|
||||
grp.Itms__make();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_grp {
|
||||
public Xoctg_catpage_grp(byte tid) {this.tid = tid;}
|
||||
public byte Tid() {return tid;} private byte tid; // subc|page|file
|
||||
public int Bgn() {return bgn;} private int bgn;
|
||||
public int End() {return end;} private int end;
|
||||
public int Len() {return end - bgn;}
|
||||
public int Total() {return total;} private int total;
|
||||
public Xoctg_catpage_itm[] Itms() {return itms;} private Xoctg_catpage_itm[] itms = Xoctg_catpage_itm.Ary_empty;
|
||||
public byte[] Itms__nth_sortkey() {return itms__nth_sortkey;}
|
||||
public Xoctg_catpage_itm Itms__get_at_0th() {return Itms__get_at(0);}
|
||||
public Xoctg_catpage_itm Itms__get_at_nth() {return Itms__get_at(itms.length - 1);}
|
||||
private Xoctg_catpage_itm Itms__get_at(int i) {
|
||||
if (i < 0 || i >= itms.length) throw Err_.new_wo_type("ctg.view: i is out of bounds", "i", i, "len", itms.length, "tid", tid);
|
||||
Xoctg_catpage_itm rv = itms[i]; if (rv == null) throw Err_.new_wo_type("ctg.view: itm is null", "i", i, "len", itms.length, "tid", tid);
|
||||
return rv;
|
||||
}
|
||||
public void Itms__add(Xoctg_catpage_itm sub) {tmp_list.Add(sub);}
|
||||
public void Itms__make() {
|
||||
itms = (Xoctg_catpage_itm[])tmp_list.To_ary(Xoctg_catpage_itm.class);
|
||||
total = end = itms.length;
|
||||
}
|
||||
public Xoctg_catpage_grp Itms__nth_sortkey_(byte[] v) {itms__nth_sortkey = v; return this;} private byte[] itms__nth_sortkey;
|
||||
|
||||
public void Init(int bgn, int end) {this.bgn = bgn; this.end = end;} // TEST:
|
||||
public List_adp Itms_list() {return tmp_list;} private final List_adp tmp_list = List_adp_.New(); // TEST
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_itm implements gplx.CompareAble {
|
||||
public Xoctg_catpage_itm(int page_id, Xoa_ttl page_ttl, byte[] sort_key) {
|
||||
this.page_id = page_id;
|
||||
this.page_ttl = page_ttl;
|
||||
this.sort_key = sort_key.length == 0 ? page_ttl.Page_db() : sort_key; // v1 will not have sortkey data; PAGE:s.w:Category:Computer_science DATE:2015-11-22
|
||||
}
|
||||
public int Page_id() {return page_id;} private int page_id;
|
||||
public Xoa_ttl Page_ttl() {return page_ttl;} private Xoa_ttl page_ttl;
|
||||
public byte[] Sort_key() {return sort_key;} private byte[] sort_key;
|
||||
public boolean Missing() {return missing;} private boolean missing; // not used; remove?;
|
||||
public void Missing_y_() {missing = true;}
|
||||
|
||||
public int compareTo(Object obj) {Xoctg_catpage_itm comp = (Xoctg_catpage_itm)obj; return Int_.Compare(page_id, comp.Page_id());}
|
||||
public static final Xoctg_catpage_itm[] Ary_empty = new Xoctg_catpage_itm[0];
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
class Xoctg_catpage_itm_sorter implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_catpage_itm lhs = (Xoctg_catpage_itm)lhsObj;
|
||||
Xoctg_catpage_itm rhs = (Xoctg_catpage_itm)rhsObj;
|
||||
return Bry_.Compare(lhs.Sort_key(), rhs.Sort_key());
|
||||
}
|
||||
public static final Xoctg_catpage_itm_sorter Sorter = new Xoctg_catpage_itm_sorter();
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Xoctg_fmt_grp { // subc|page|file
|
||||
private final byte tid;
|
||||
private final byte[] div_id, url_arg_bgn, url_arg_end;
|
||||
private final int msg_label_id, msg_stats_id;
|
||||
private final Xoctg_fmt_ltr itms_fmt;
|
||||
Xoctg_fmt_grp(byte tid, Xoctg_fmt_itm_base itm_fmt, int msg_label_id, int msg_stats_id, byte[] url_arg_bgn, byte[] url_arg_end, byte[] div_id) {
|
||||
this.tid = tid;
|
||||
this.itm_fmt = itm_fmt;
|
||||
this.itms_fmt = new Xoctg_fmt_ltr(itm_fmt);
|
||||
this.msg_label_id = msg_label_id; this.msg_stats_id = msg_stats_id;
|
||||
this.url_arg_bgn = url_arg_bgn; this.url_arg_end = url_arg_end; this.div_id = div_id;
|
||||
}
|
||||
public Xoctg_fmt_itm_base Itm_fmt() {return itm_fmt;} private final Xoctg_fmt_itm_base itm_fmt;
|
||||
public void Write_catpage_grp(Bry_bfr bfr, Xow_wiki wiki, Xol_lang_itm lang, Xoctg_catpage_ctg dom_ctg) { // TEST:
|
||||
Xoctg_catpage_grp dom_grp = dom_ctg.Grp_by_tid(tid);
|
||||
if (dom_grp.Itms().length == 0) return; // no items in grp; EX: 0 items in File
|
||||
|
||||
// get msgs
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] msg_label_bry = msg_mgr.Val_by_id_args(msg_label_id, dom_ctg.Name());
|
||||
byte[] msg_stats_bry = msg_mgr.Val_by_id_args(msg_stats_id, dom_grp.Len(), dom_grp.Total());
|
||||
|
||||
// get nav html; next / previous 200
|
||||
Xoa_ttl ctg_ttl = wiki.Ttl_parse(Xow_ns_.Tid__category, dom_ctg.Name());
|
||||
byte[] nav_html = this.Bld_bwd_fwd(wiki, ctg_ttl, dom_grp);
|
||||
|
||||
// sort; init grp; write
|
||||
Array_.Sort(dom_grp.Itms(), Xoctg_catpage_itm_sorter.Sorter); // NOTE: must assert sorted for v1; PAGE:s.w:Category:Computer_science; DATE:2015-11-22
|
||||
itms_fmt.Init_from_grp(wiki, dom_grp);
|
||||
Fmt__ctg.Bld_many(bfr, div_id, msg_label_bry, msg_stats_bry, nav_html, lang.Key_bry(), lang.Dir_ltr_bry(), itms_fmt);
|
||||
}
|
||||
public byte[] Bld_bwd_fwd(Xow_wiki wiki, Xoa_ttl ttl, Xoctg_catpage_grp view_grp) { // TEST:
|
||||
if (view_grp.Total() < Grp__max) return Bry_.Empty;
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
Html_nav_bry(bfr, wiki, ttl, view_grp, Bool_.N);
|
||||
Html_nav_bry(bfr, wiki, ttl, view_grp, Bool_.Y);
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
private void Html_nav_bry(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl, Xoctg_catpage_grp view_grp, boolean type_is_bgn) {
|
||||
Bry_bfr href_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
|
||||
// get nav_href; EX:href="/wiki/Category:Ctg_1?pageuntil=A1#mw-pages"
|
||||
wiki.Html__href_wtr().Build_to_bfr(href_bfr, wiki.App(), Xoh_wtr_ctx.Basic, wiki.Domain_bry(), ttl);
|
||||
byte[] arg_idx_lbl = null; byte[] arg_sortkey = null;
|
||||
if (type_is_bgn) {
|
||||
arg_idx_lbl = url_arg_bgn;
|
||||
arg_sortkey = view_grp.Itms__nth_sortkey();
|
||||
if (arg_sortkey == null) arg_sortkey = view_grp.Itms__get_at_nth().Sort_key();
|
||||
}
|
||||
else {
|
||||
arg_idx_lbl = url_arg_end;
|
||||
arg_sortkey = view_grp.Itms__get_at_0th().Sort_key();
|
||||
}
|
||||
href_bfr.Add_byte(Byte_ascii.Question).Add(arg_idx_lbl).Add_byte(Byte_ascii.Eq); // filefrom=
|
||||
Gfo_url_encoder_.Http_url.Encode(href_bfr, arg_sortkey); // Abc
|
||||
href_bfr.Add_byte(Byte_ascii.Hash).Add(div_id); // #mw-subcategories
|
||||
byte[] nav_href = href_bfr.To_bry_and_rls();
|
||||
|
||||
// get nav_text
|
||||
int nav_text_id = type_is_bgn ? Xol_msg_itm_.Id_next_results : Xol_msg_itm_.Id_prev_results;
|
||||
byte[] nav_text = wiki.Msg_mgr().Val_by_id_args(nav_text_id, Grp__max); // next 200 / previous 200
|
||||
|
||||
// fmt
|
||||
Fmt__nav.Bld_many(bfr, nav_href, ttl.Full_url(), nav_text);
|
||||
}
|
||||
|
||||
public static int Grp__max = 200;
|
||||
private static final Bry_fmt
|
||||
Fmt__nav = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " (<a href=\"~{nav_href}\" class=\"xowa_nav\" title=\"~{nav_title}\">~{nav_text}</a>)"
|
||||
)
|
||||
, Fmt__ctg = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"~{div_id}\">"
|
||||
, " <h2>~{msg_label_bry}</h2>"
|
||||
, " <p>~{msg_stats_bry}</p>~{nav_html}"
|
||||
, " <div lang=\"~{lang_key}\" dir=\"~{lang_ltr}\" class=\"mw-content-~{lang_ltr}\">"
|
||||
, " <table style=\"width: 100%;\">"
|
||||
, " <tr style=\"vertical-align: top;\">~{grps}"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </div>~{nav_html}"
|
||||
, "</div>"
|
||||
);
|
||||
public static Xoctg_fmt_grp New__subc() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_subc, new Xoctg_fmt_itm_subc(), Xol_msg_itm_.Id_ctg_subc_header, Xol_msg_itm_.Id_ctg_subc_count, Xoctg_catpage_url.Url_arg_subc_bgn, Xoctg_catpage_url.Url_arg_subc_end, Bry_.new_a7("mw-subcategories"));}
|
||||
public static Xoctg_fmt_grp New__page() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_page, new Xoctg_fmt_itm_page(), Xol_msg_itm_.Id_ctg_page_header, Xol_msg_itm_.Id_ctg_page_count, Xoctg_catpage_url.Url_arg_page_bgn, Xoctg_catpage_url.Url_arg_page_end, Bry_.new_a7("mw-pages"));}
|
||||
public static Xoctg_fmt_grp New__file() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_file, new Xoctg_fmt_itm_file(), Xol_msg_itm_.Id_ctg_file_header, Xol_msg_itm_.Id_ctg_file_count, Xoctg_catpage_url.Url_arg_file_bgn, Xoctg_catpage_url.Url_arg_file_end, Bry_.new_a7("mw-category-media"));}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public abstract class Xoctg_fmt_itm_base implements gplx.core.brys.Bfr_arg {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private Xow_wiki wiki;
|
||||
private Xoctg_catpage_grp grp;
|
||||
private byte[] ltr_cur; private int loop_bgn; private int col_end;
|
||||
|
||||
public int Loop_end_idx() {return loop_end_idx;} private int loop_end_idx;
|
||||
public boolean Loop_ends_at_col() {return loop_ends_at_col;} private boolean loop_ends_at_col;
|
||||
public void Col_end_(int col_bgn, int col_idx) {
|
||||
this.col_end = col_bgn + Calc_col_len(grp.Len(), col_idx, Cols_max);
|
||||
}
|
||||
public void Init_from_ltr(Xow_wiki wiki, Xoctg_catpage_grp grp) {this.wiki = wiki; this.grp = grp;}
|
||||
public void Set_ltr_and_bgn(byte[] ltr_cur, int loop_bgn) {this.ltr_cur = ltr_cur; this.loop_bgn = loop_bgn;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
// init vars
|
||||
Xoh_href_parser href_parser = wiki.App().Html__href_parser();
|
||||
Xou_history_mgr history_mgr = wiki.App().User().History_mgr();
|
||||
int len = grp.Len();
|
||||
|
||||
// loop over itms;
|
||||
for (int i = loop_bgn; i < len; i++) {
|
||||
// reached end of col; exit
|
||||
if (i == col_end) {
|
||||
loop_end_idx = i;
|
||||
loop_ends_at_col = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// get sortkey
|
||||
Xoctg_catpage_itm itm = grp.Itms()[i];
|
||||
byte[] itm_sortkey = itm.Sort_key();
|
||||
|
||||
// reached end of ltr; exit
|
||||
if (!Bry_.Has_at_bgn(itm_sortkey, ltr_cur, 0, itm_sortkey.length)) {
|
||||
loop_end_idx = i;
|
||||
loop_ends_at_col = i == col_end;
|
||||
return;
|
||||
}
|
||||
|
||||
Bld_html(bfr, wiki, history_mgr, href_parser, itm, itm.Page_ttl());
|
||||
}
|
||||
loop_end_idx = len;
|
||||
loop_ends_at_col = true;
|
||||
}
|
||||
@gplx.Virtual public void Bld_html(Bry_bfr bfr, Xow_wiki wiki, Xou_history_mgr history_mgr, Xoh_href_parser href_parser, Xoctg_catpage_itm itm, Xoa_ttl ttl) {
|
||||
byte[] itm_full_ttl = Gfh_utl.Escape_html_as_bry(tmp_bfr, ttl.Full_txt_w_ttl_case());// NOTE: ttl.Full_txt() to get full ns; EX: Template:A instead of just "A"
|
||||
if (itm.Missing())
|
||||
fmt_missing.Bld_many(bfr, itm.Page_id(), itm_full_ttl);
|
||||
else {
|
||||
byte[] itm_href = wiki.Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
byte[] itm_atr_cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki.Domain_bry(), ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
fmt_exists.Bld_many(bfr, itm_href, itm_atr_cls, itm_full_ttl, itm_full_ttl);
|
||||
}
|
||||
}
|
||||
private static final Bry_fmt
|
||||
fmt_missing = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #~{itm_id} might be talk/user page\">~{itm_text} (missing)</li>"
|
||||
)
|
||||
, fmt_exists = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " <li><a href=\"~{itm_href}\"~{itm_atr_cls} title=\"~{itm_title}\">~{itm_text}</a></li>"
|
||||
)
|
||||
;
|
||||
public static final int Cols_max = 3;
|
||||
public static int Calc_col_len(int grp_len, int col_idx, int max_cols) { // TEST
|
||||
if (grp_len == 0) return 0; // 0 items in group; return 0;
|
||||
int max_itms_in_col = ((grp_len - 1) / max_cols) + 1; // EX: grp with 4, 5, 6 items should have max of 2 items in 1 col, so (a) subtract 1; (b) divide by 3; (c) add 1
|
||||
return col_idx <= ((grp_len - 1) % max_cols) // complicated formula but works; rely on example and note that only 2 or 1 can be returned; EX: 4=2,1,1; 5=2,2,1; 6=2,2,2
|
||||
? max_itms_in_col
|
||||
: max_itms_in_col - 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
class Xoctg_fmt_itm_subc extends Xoctg_fmt_itm_base {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
@Override public void Bld_html(Bry_bfr bfr, Xow_wiki wiki, Xou_history_mgr history_mgr, Xoh_href_parser href_parser, Xoctg_catpage_itm itm, Xoa_ttl ttl) {
|
||||
byte[] itm_href = wiki.Html__href_wtr().Build_to_bry(wiki, ttl);
|
||||
int count_subcs = 0;
|
||||
int count_pages = 0;
|
||||
int count_files = 0;
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] contains_title = wiki.Msg_mgr().Val_by_id_args(Xol_msg_itm_.Id_ctgtree_subc_counts, count_subcs, count_pages, count_files);
|
||||
byte[] contains_text = Bld_contains_text(msg_mgr, count_subcs, count_pages, count_files);
|
||||
byte[] ttl_page = ttl.Page_txt();
|
||||
fmt_exists.Bld_many(bfr, ttl.Page_db(), ttl_page, itm_href, ttl_page, contains_title, contains_text);
|
||||
}
|
||||
private byte[] Bld_contains_text(Xow_msg_mgr msg_mgr, int count_subcs, int count_pages, int count_files) {
|
||||
if (count_subcs == 0 && count_pages == 0 && count_files == 0) return Bry_.Empty;
|
||||
tmp_bfr.Add_byte(Byte_ascii.Paren_bgn);
|
||||
Bld_contains_text_itm(tmp_bfr, msg_mgr, Xol_msg_itm_.Id_ctgtree_subc_counts_ctg, count_subcs);
|
||||
Bld_contains_text_itm(tmp_bfr, msg_mgr, Xol_msg_itm_.Id_ctgtree_subc_counts_page, count_pages);
|
||||
Bld_contains_text_itm(tmp_bfr, msg_mgr, Xol_msg_itm_.Id_ctgtree_subc_counts_file, count_files);
|
||||
tmp_bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
private void Bld_contains_text_itm(Bry_bfr bfr, Xow_msg_mgr msg_mgr, int msg_id, int val) {
|
||||
if (val == 0) return;
|
||||
if (bfr.Len() > 1) bfr.Add(Bld_contains_text_itm_dlm); // NOTE: 1 b/c Paren_bgn is always added
|
||||
bfr.Add(msg_mgr.Val_by_id_args(msg_id, val));
|
||||
} private static final byte[] Bld_contains_text_itm_dlm = Bry_.new_a7(", ");
|
||||
private static final Bry_fmt
|
||||
fmt_exists = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " <li>"
|
||||
, " <div class=\"CategoryTreeSection\">"
|
||||
, " <div class=\"CategoryTreeItem\">"
|
||||
, " <span class=\"CategoryTreeBullet\">"
|
||||
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"~{itm_data_title}\" title=\"~{itm_title}\" data-ct-state=\"collapsed\">"
|
||||
, " </span> "
|
||||
, " </span>"
|
||||
, " <a href=\"~{itm_href}\" class=\"" + Xoa_ctg_mgr.Html__cls__str + "\">~{itm_text}"
|
||||
, " </a>"
|
||||
, " <span title=\"~{itm_contains_title}\" dir=\"ltr\">~{itm_contains_text}"
|
||||
, " </span>"
|
||||
, " </div>"
|
||||
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
|
||||
, " </div>"
|
||||
, " </li>"
|
||||
);
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
public class Xoctg_fmt_ltr implements gplx.core.brys.Bfr_arg { // "A", "B", "C cont."
|
||||
private final Xoctg_fmt_itm_base itm_fmt;
|
||||
private Xoctg_catpage_grp grp;
|
||||
private byte[] msg__list_continues;
|
||||
public Xoctg_fmt_ltr(Xoctg_fmt_itm_base itm_fmt) {
|
||||
this.itm_fmt = itm_fmt;
|
||||
}
|
||||
public void Init_from_grp(Xow_wiki wiki, Xoctg_catpage_grp grp) {
|
||||
this.grp = grp;
|
||||
this.msg__list_continues = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_list_continues);
|
||||
itm_fmt.Init_from_ltr(wiki, grp);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int itms_len = grp.Len(); if (itms_len == 0) return; // no items; exit
|
||||
|
||||
int itm_idx = grp.Bgn(); // itm idx; EX: idx=201 in len=500
|
||||
int col_idx = 0; // col idx; EX: 3 cols; idx = 0, 1, 2
|
||||
boolean start_new_col = true;
|
||||
byte[] ltr_prv = Bry_.Empty;
|
||||
|
||||
// loop itms until no more itms
|
||||
while (itm_idx < itms_len) {
|
||||
Xoctg_catpage_itm itm = grp.Itms()[itm_idx];
|
||||
|
||||
// get ltr_head; EX: "C" or "C cont."
|
||||
byte[] itm_sortkey = itm.Sort_key();
|
||||
byte[] ltr_cur = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(itm_sortkey, 0);
|
||||
byte[] ltr_head = Bry_.Eq(ltr_prv, ltr_cur)
|
||||
? Bry_.Add(ltr_prv, Byte_ascii.Space_bry, msg__list_continues) // new col uses same ltr as last itm in old col; add "cont."; EX: "C cont."
|
||||
: ltr_cur; // else, just use ltr; EX: "C"
|
||||
ltr_prv = ltr_cur;
|
||||
|
||||
// start new column if needed
|
||||
if (start_new_col) {
|
||||
itm_fmt.Col_end_(itm_idx, col_idx++); // set col_end; note col starts at itm_idx
|
||||
Fmt__col_bgn.Bld_many(bfr, 100 / Xoctg_fmt_itm_base.Cols_max); // width:33%
|
||||
}
|
||||
|
||||
// set ltr and idx
|
||||
itm_fmt.Set_ltr_and_bgn(ltr_prv, itm_idx);
|
||||
|
||||
// loop until (a) end of ltr or (b) end of col
|
||||
Fmt__tbl.Bld_many(bfr, ltr_head, itm_fmt);
|
||||
itm_idx = itm_fmt.Loop_end_idx();
|
||||
start_new_col = itm_fmt.Loop_ends_at_col();
|
||||
|
||||
// end column if needed
|
||||
if (start_new_col)
|
||||
Fmt__col_end.Bld_many(bfr);
|
||||
}
|
||||
}
|
||||
private static final Bry_fmt
|
||||
Fmt__tbl = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " <h3>~{ltr_head}</h3>" // EX: "A", "A cont."
|
||||
, " <ul>~{itms}"
|
||||
, " </ul>"
|
||||
)
|
||||
, Fmt__col_bgn = Bry_fmt.New("\n <td style=\"width: ~{width}%;\">")
|
||||
, Fmt__col_end = Bry_fmt.New("\n </td>");
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.pageboxs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.core.lists.hashs.*;
|
||||
class Xoctg_pagebox_hash {
|
||||
private final Ordered_hash hash_by_ttl = Ordered_hash_.New_bry();
|
||||
private final Hash_adp__int hash_by_id = new Hash_adp__int();
|
||||
public int Len() {return hash_by_ttl.Len();}
|
||||
public Xoctg_pagebox_itm Get_at(int i) {return (Xoctg_pagebox_itm)hash_by_ttl.Get_at(i);}
|
||||
public Xoctg_pagebox_itm Get_by_ttl(byte[] full_db) {return (Xoctg_pagebox_itm)hash_by_ttl.Get_by(full_db);}
|
||||
public Xoctg_pagebox_itm Get_by_id(int page_id) {return (Xoctg_pagebox_itm)hash_by_id.Get_by(page_id);}
|
||||
public Xoctg_pagebox_itm[] To_ary_and_clear() {
|
||||
hash_by_id.Clear();
|
||||
return (Xoctg_pagebox_itm[])hash_by_ttl.To_ary_and_clear(Xoctg_pagebox_itm.class);
|
||||
}
|
||||
public Xoctg_pagebox_itm Add_by_ttl(Xoa_ttl ttl) {
|
||||
Xoctg_pagebox_itm rv = Xoctg_pagebox_itm.New_by_ttl(ttl);
|
||||
hash_by_ttl.Add(ttl.Full_db(), rv);
|
||||
return rv;
|
||||
}
|
||||
public void Sort_and_fill_ids() {
|
||||
// sort
|
||||
hash_by_ttl.Sort_by(Xoctg_pagebox_hash_sorter.Sorter);
|
||||
|
||||
// fill ids_hash
|
||||
hash_by_id.Clear();
|
||||
int len = hash_by_ttl.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoctg_pagebox_itm itm = (Xoctg_pagebox_itm)hash_by_ttl.Get_at(i);
|
||||
hash_by_id.Add(itm.Id(), itm);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Xoctg_pagebox_hash_sorter implements gplx.core.lists.ComparerAble {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_pagebox_itm lhs = (Xoctg_pagebox_itm)lhsObj;
|
||||
Xoctg_pagebox_itm rhs = (Xoctg_pagebox_itm)rhsObj;
|
||||
return -Int_.Compare(lhs.Count__all(), rhs.Count__all());
|
||||
}
|
||||
public static final Xoctg_pagebox_hash_sorter Sorter = new Xoctg_pagebox_hash_sorter(); Xoctg_pagebox_hash_sorter() {}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.xowa.wikis.pages.wtxts.*;
|
||||
public class Xoctg_pagebox_itm {
|
||||
public Xoctg_pagebox_itm(Xoa_ttl ttl) {
|
||||
this.ttl = ttl;
|
||||
}
|
||||
public Xoa_ttl Ttl() {return ttl;} private final Xoa_ttl ttl;
|
||||
public int Id() {return id;} private int id;
|
||||
public DateAdp Timestamp() {return timestamp;} private DateAdp timestamp;
|
||||
public boolean Hidden() {return hidden;} private boolean hidden;
|
||||
public int Count__subcs() {return count__subcs;} private int count__subcs;
|
||||
public int Count__pages() {return count__pages;} private int count__pages;
|
||||
public int Count__files() {return count__files;} private int count__files;
|
||||
public int Count__all() {return count__all;} private int count__all;
|
||||
|
||||
public void Load_by_db(int id, DateAdp timestamp) {
|
||||
this.id = id; this.timestamp = timestamp;
|
||||
}
|
||||
public void Load_by_cat_core(boolean hidden, int count__subcs, int count__pages, int count__files) {
|
||||
this.hidden = hidden;
|
||||
this.count__subcs = count__subcs; this.count__pages = count__pages; this.count__files = count__files;
|
||||
this.count__all = count__subcs + count__pages + count__files;
|
||||
}
|
||||
|
||||
public static Xoctg_pagebox_itm New_by_ttl(Xoa_ttl ttl) {return new Xoctg_pagebox_itm(ttl);}
|
||||
public static Xoctg_pagebox_itm[] New_ary(Xoa_page pg) {
|
||||
int len = pg.Wtxt().Ctgs__len();
|
||||
Xoctg_pagebox_itm[] rv = new Xoctg_pagebox_itm[len];
|
||||
for (int i = 0; i < len; ++i)
|
||||
rv[i] = New_by_ttl(pg.Wtxt().Ctgs__get_at(i));
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.dbs.*; import gplx.xowa.addons.wikis.ctgs.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
class Xoctg_pagebox_loader implements Select_in_cbk {
|
||||
private final Xoctg_pagebox_hash hash; private final byte[] page_url;
|
||||
public Xoctg_pagebox_loader(Xoctg_pagebox_hash hash, byte[] page_url) {
|
||||
this.hash = hash; this.page_url = page_url;
|
||||
}
|
||||
public int Hash_max() {return hash.Len();}
|
||||
public void Write_sql(Bry_bfr bfr, int idx) {
|
||||
Xoctg_pagebox_itm page = (Xoctg_pagebox_itm)hash.Get_at(idx);
|
||||
bfr.Add_int_variable(page.Id());
|
||||
}
|
||||
public void Read_data(Db_rdr rdr) {
|
||||
int cat_id = rdr.Read_int("cat_id");
|
||||
Xoctg_pagebox_itm page = (Xoctg_pagebox_itm)hash.Get_by_id(cat_id);
|
||||
if (page == null) {// unlikely, but possible for itms to exist in cat_links, but not in cat_core; log and return;
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "cat_id in cat_link but not in cat_core; page=~{0} cat_id=~{0}", page_url, cat_id);
|
||||
}
|
||||
page.Load_by_cat_core(rdr.Read_bool_by_byte("cat_hidden"), rdr.Read_int("cat_pages"), rdr.Read_int("cat_subcats"), rdr.Read_int("cat_files"));
|
||||
}
|
||||
public void Select_catlinks_by_page(Xow_wiki wiki, Db_conn cat_link_conn, Xoctg_pagebox_hash hash, int page_id) {
|
||||
// init
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(cat_link_conn, new Db_attach_itm("page_db", wiki.Data__core_mgr().Db__core().Conn()));
|
||||
String sql = String_.Concat_lines_nl_skip_last // ANSI.Y
|
||||
( "SELECT cl.cl_to_id"
|
||||
, ", cl.cl_timestamp_unix"
|
||||
, ", p.page_namespace"
|
||||
, ", p.page_title"
|
||||
, "FROM cat_link cl"
|
||||
, " JOIN <page_db>page p ON cl.cl_to_id = p.page_id"
|
||||
, "WHERE cl.cl_from = " + Int_.To_str(page_id)
|
||||
);
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
|
||||
// select
|
||||
attach_mgr.Attach();
|
||||
Db_rdr rdr = cat_link_conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
try {
|
||||
while (rdr.Move_next()) {
|
||||
Xoa_ttl ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
|
||||
// check if ttl exists already in hash; add it if not; check is not needed now b/c html_dbs will never put itms in hash, but may need in future if merging "wtxt" and "ctgs_dbs"
|
||||
Xoctg_pagebox_itm itm = (Xoctg_pagebox_itm)hash.Get_by_ttl(ttl.Full_db());
|
||||
if (itm == null)
|
||||
itm = hash.Add_by_ttl(ttl);
|
||||
itm.Load_by_db(rdr.Read_int("cl_to_id"), DateAdp_.unixtime_utc_ms_(rdr.Read_long("cl_timestamp_unix")));
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
|
||||
// hash items by id
|
||||
hash.Sort_and_fill_ids();
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.singles.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.doubles.*;
|
||||
import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
|
||||
public class Xoctg_pagebox_wtr {
|
||||
private final Xoctg_single_box single_box = new Xoctg_single_box();
|
||||
private final Xoctg_double_box double_box = new Xoctg_double_box();
|
||||
private final Xoctg_pagebox_hash hash = new Xoctg_pagebox_hash();
|
||||
private final Xowd_page_itm tmp_page_itm = new Xowd_page_itm();
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
single_box.Init_by_wiki(wiki);
|
||||
double_box.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Write_pagebox(boolean double_mode, Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xoctg_pagebox_itm[] pagebox_itms) {
|
||||
try {
|
||||
if (double_mode)
|
||||
double_box.Write_pagebox(bfr, pagebox_itms);
|
||||
else
|
||||
single_box.Write_pagebox(bfr, pagebox_itms);
|
||||
} catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "failed to write pagebox categories; page=~{0} err=~{1}", page.Url_bry_safe(), Err_.Message_gplx_log(e));
|
||||
}
|
||||
}
|
||||
public Xoctg_pagebox_itm[] Get_catlinks_by_page(Xow_wiki wiki, Xoa_page page) {
|
||||
int wtxt_ctgs_len = page.Wtxt().Ctgs__len();
|
||||
// html_dbs will always be 0 since they do not parse ctgs; note that wtxt_dbs can also have 0 if no ctgs
|
||||
if (wtxt_ctgs_len == 0) {
|
||||
// init
|
||||
Xoctg_pagebox_loader select_cbk = new Xoctg_pagebox_loader(hash, page.Url_bry_safe());
|
||||
|
||||
// get cat_db_id from page
|
||||
boolean exists = wiki.Data__core_mgr().Tbl__page().Select_by_ttl(tmp_page_itm, page.Ttl().Ns(), page.Ttl().Page_txt());
|
||||
int cat_db_id = tmp_page_itm.Cat_db_id();
|
||||
if (exists && cat_db_id != -1) {// note that wtxt_dbs can have 0 ctgs but will have cat_db_id == -1
|
||||
Xow_db_file cat_link_db = wiki.Data__core_mgr().Dbs__get_by_id_or_null(cat_db_id);
|
||||
if (cat_link_db != null && Io_mgr.Instance.ExistsFil(cat_link_db.Url())) { // make sure cat_db_id exists
|
||||
select_cbk.Select_catlinks_by_page(wiki, cat_link_db.Conn(), hash, tmp_page_itm.Id());
|
||||
}
|
||||
}
|
||||
|
||||
// get hidden
|
||||
int hash_len = hash.Len();
|
||||
if (hash_len > 0) { // note that html_dbs may have 0 ctgs in cat_db; don't bother checking cat_core
|
||||
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(wiki.Data__core_mgr());
|
||||
cat_core_tbl.Select_by_cat_id_many(select_cbk);
|
||||
}
|
||||
}
|
||||
// wtxt_dbs will always have itms;
|
||||
else {
|
||||
for (int i = 0; i < wtxt_ctgs_len; ++i) {
|
||||
Xoa_ttl ttl = page.Wtxt().Ctgs__get_at(i);
|
||||
hash.Add_by_ttl(ttl);
|
||||
}
|
||||
}
|
||||
|
||||
return hash.To_ary_and_clear();
|
||||
}
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
public class Xoctg_double_box implements Bfr_arg {
|
||||
public Xoctg_double_grp Grp_normal() {return grp_normal;} private final Xoctg_double_grp grp_normal = new Xoctg_double_grp();
|
||||
public Xoctg_double_grp Grp_hidden() {return grp_hidden;} private final Xoctg_double_grp grp_hidden = new Xoctg_double_grp();
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
Xou_history_mgr history_mgr = wiki.App().User().History_mgr();
|
||||
grp_normal.Init_by_wiki(wiki, history_mgr, Bool_.Y);
|
||||
grp_hidden.Init_by_wiki(wiki, history_mgr, Bool_.N);
|
||||
}
|
||||
public void Write_pagebox(Bry_bfr bfr, Xoctg_pagebox_itm[] ary) {
|
||||
grp_normal.Itms().Itms__clear();
|
||||
grp_hidden.Itms().Itms__clear();
|
||||
|
||||
int len = ary.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoctg_pagebox_itm ctg = ary[i];
|
||||
Xoctg_double_grp list = ctg.Hidden() ? grp_hidden : grp_normal;
|
||||
list.Itms().Itms__add(ctg);
|
||||
}
|
||||
this.Bfr_arg__add(bfr);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Fmt__all.Bld_many(bfr, grp_normal, grp_hidden);
|
||||
}
|
||||
private static final Bry_fmt
|
||||
Fmt__all = Bry_fmt.Auto_nl_skip_last
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">~{grp_normal}~{grp_hidden}"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
public class Xoctg_double_grp implements Bfr_arg {
|
||||
private byte[] lbl_ctg_help, lbl_ctg_text, lbl_hidden;
|
||||
public boolean Type_is_normal() {return type_is_normal;} private boolean type_is_normal;
|
||||
public Xoctg_double_itm Itms() {return itms;} private final Xoctg_double_itm itms = new Xoctg_double_itm();
|
||||
public void Init_by_wiki(Xow_wiki wiki, Xou_history_mgr history_mgr, boolean type_is_normal) {
|
||||
this.type_is_normal = type_is_normal;
|
||||
lbl_ctg_text = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hdr);
|
||||
lbl_ctg_help = Xol_msg_mgr_.Get_msg_val(wiki, wiki.Lang(), Key_pagecategorieslink, Bry_.Ary_empty);
|
||||
lbl_hidden = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hidden);
|
||||
itms.Init_by_wiki(wiki, history_mgr);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
if (type_is_normal)
|
||||
Fmt__normal.Bld_many(bfr, lbl_ctg_help, lbl_ctg_text, itms);
|
||||
else
|
||||
Fmt__hidden.Bld_many(bfr, lbl_hidden, itms);
|
||||
}
|
||||
|
||||
private static final byte[] Key_pagecategorieslink = Bry_.new_a7("pagecategorieslink");
|
||||
private static final Bry_fmt
|
||||
Fmt__normal = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "<a href=\"/wiki/~{ctg_help_page}\" title=\"~{ctg_help_page}\">~{ctg_text}</a>:"
|
||||
, "<ul>~{grp_itms}"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
)
|
||||
, Fmt__hidden = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">~{hidden_ctg_txt}:"
|
||||
, "<ul>~{grp_itms}"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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.addons.wikis.ctgs.htmls.pageboxs.doubles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.core.brys.fmts.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
public class Xoctg_double_itm implements gplx.core.brys.Bfr_arg {
|
||||
private final List_adp itms = List_adp_.New();
|
||||
private Xow_wiki wiki; private Xoh_href_wtr href_wtr; private Xou_history_mgr history_mgr;
|
||||
public void Init_by_wiki(Xow_wiki wiki, Xou_history_mgr history_mgr) {
|
||||
this.wiki = wiki;
|
||||
this.href_wtr = wiki.Html__href_wtr();
|
||||
this.history_mgr = history_mgr;
|
||||
}
|
||||
public void Itms__clear() {itms.Clear();}
|
||||
public void Itms__add(Xoctg_pagebox_itm page) {itms.Add(page);}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = itms.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoctg_pagebox_itm itm = (Xoctg_pagebox_itm)itms.Get_at(i);
|
||||
Xoa_ttl ttl = itm.Ttl();
|
||||
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_text = ttl.Page_txt();
|
||||
byte[] lnki_ttl = ttl.Full_txt_w_ttl_case();
|
||||
|
||||
// build title
|
||||
// tmp_bfr.Add(ttl.Full_txt_w_ttl_case());
|
||||
// tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Paren_bgn) .Add_byte(Byte_ascii.Ltr_S).Add_byte_colon().Add_int_variable(itm.Count__subcs());
|
||||
// tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Comma) .Add_byte(Byte_ascii.Ltr_P).Add_byte_colon().Add_int_variable(itm.Count__pages());
|
||||
// tmp_bfr.Add_byte_space().Add_byte(Byte_ascii.Comma) .Add_byte(Byte_ascii.Ltr_F).Add_byte_colon().Add_int_variable(itm.Count__files());
|
||||
// tmp_bfr.Add_byte(Byte_ascii.Paren_end);
|
||||
// byte[] lnki_ttl = tmp_bfr.To_bry_and_clear();
|
||||
|
||||
Fmt__itm.Bld_many(bfr, lnki_cls, lnki_href, lnki_ttl, lnki_text);
|
||||
}
|
||||
}
|
||||
private static final Bry_fmt Fmt__itm = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, "<li>"
|
||||
, "<a~{lnki_cls} href=\"~{lnki_href}\" title=\"~{lnki_ttl}\">~{lnki_text}</a>"
|
||||
, "</li>"
|
||||
);
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.htmls.core.htmls.*;
|
||||
public class Xoctg_single_box {
|
||||
private final Xoctg_single_itm itms_fmtr = new Xoctg_single_itm();
|
||||
private byte[] lbl_categories;
|
||||
public void Init_by_wiki(Xow_wiki wiki) {
|
||||
this.lbl_categories = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ctg_tbl_hdr);
|
||||
itms_fmtr.Init_by_wiki(wiki);
|
||||
}
|
||||
public void Write_pagebox(Bry_bfr bfr, Xoctg_pagebox_itm[] itms) {
|
||||
itms_fmtr.Init_by_page(itms);
|
||||
Fmt__grp.Bld_many(bfr, lbl_categories, itms_fmtr);
|
||||
}
|
||||
private static final Bry_fmt Fmt__grp = Bry_fmt.Auto_nl_skip_last
|
||||
( "<div id=\"catlinks\" class=\"catlinks\">"
|
||||
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
|
||||
, "~{grp_lbl}"
|
||||
, "<ul>~{grp_itms}"
|
||||
, "</ul>"
|
||||
, "</div>"
|
||||
, "</div>"
|
||||
);
|
||||
}
|
@ -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.addons.wikis.ctgs.htmls.pageboxs.singles; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
|
||||
import gplx.core.brys.*; import gplx.core.brys.fmts.*;
|
||||
class Xoctg_single_itm implements Bfr_arg {
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
private Xow_wiki wiki;
|
||||
private Xoctg_pagebox_itm[] itms;
|
||||
public void Init_by_wiki(Xow_wiki wiki) {this.wiki = wiki;}
|
||||
public void Init_by_page(Xoctg_pagebox_itm[] itms) {this.itms = itms;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = itms.length;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xoa_ttl ctg_ttl = itms[i].Ttl();
|
||||
wiki.Html__href_wtr().Build_to_bfr(tmp_bfr, wiki.App(), wiki.Domain_bry(), ctg_ttl);
|
||||
byte[] ctg_page_txt = ctg_ttl.Page_txt();
|
||||
Fmt__itm.Bld_many(bfr, tmp_bfr.To_bry_and_clear(), ctg_page_txt, ctg_page_txt);
|
||||
}
|
||||
}
|
||||
private static final Bry_fmt Fmt__itm = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, "<li>"
|
||||
, "<a href=\"~{itm_href}\" class=\"internal\" title=\"~{itm_title}\">~{itm_text}</a>"
|
||||
, "</li>"
|
||||
);
|
||||
}
|
@ -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.addons.wikis.pages.syncs.core; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.addons.wikis.pages.syncs.dbs.*;
|
||||
import gplx.xowa.apps.apis.xowa.addons.bldrs.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xosync_read_mgr {
|
||||
private final Xowd_page_itm tmp_dbpg = new Xowd_page_itm();
|
||||
private Db_conn sync_conn; private Xosync_sync_tbl sync_tbl;
|
||||
private final Xosync_update_mgr update_mgr = new Xosync_update_mgr();
|
||||
public void Auto_update(Xow_wiki wiki, Xoa_page page, Xoa_ttl page_ttl) {
|
||||
if (wiki.Domain_itm().Domain_type_id() == gplx.xowa.wikis.domains.Xow_domain_tid_.Tid__home) return;
|
||||
if (page_ttl.Ns().Id_is_special()) return;
|
||||
|
||||
Xoapi_sync_api sync_api = wiki.App().Api_root().Addon().Bldr().Sync();
|
||||
if (!sync_api.Auto_enabled()) return;
|
||||
if (!sync_api.Auto_page_matcher().Match(page_ttl.Full_db())) return;
|
||||
|
||||
wiki.Data__core_mgr().Db__core().Tbl__page().Select_by_ttl(tmp_dbpg, page_ttl.Ns(), page_ttl.Page_db());
|
||||
|
||||
if (sync_conn == null) {
|
||||
Io_url sync_db_url = wiki.Fsys_mgr().Root_dir().GenSubFil(wiki.Domain_str() + "-sync.xowa");
|
||||
sync_conn = Db_conn_bldr.Instance.Get_or_autocreate(true, sync_db_url);
|
||||
sync_tbl = new Xosync_sync_tbl(sync_conn);
|
||||
sync_conn.Meta_tbl_assert(sync_tbl);
|
||||
}
|
||||
DateAdp sync_date = sync_tbl.Select_sync_date_or_min(tmp_dbpg.Id());
|
||||
if (Datetime_now.Get().Diff(sync_date).Total_mins().To_int() < sync_api.Auto_interval()) return;
|
||||
|
||||
Xoa_app app = wiki.App();
|
||||
Xoh_page hpg = new Xoh_page();
|
||||
update_mgr.Init_by_app(app);
|
||||
update_mgr.Init_by_page(wiki, hpg);
|
||||
update_mgr.Update(app.Wmf_mgr().Download_wkr(), wiki, page_ttl);
|
||||
|
||||
sync_tbl.Upsert(tmp_dbpg.Id(), Datetime_now.Get());
|
||||
}
|
||||
}
|
@ -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.addons.wikis.pages.syncs.core.loaders; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.pages.*; import gplx.xowa.addons.wikis.pages.syncs.*; import gplx.xowa.addons.wikis.pages.syncs.core.*;
|
||||
import gplx.core.brys.*;
|
||||
import gplx.langs.htmls.*; import gplx.xowa.htmls.*; import gplx.langs.htmls.docs.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.imgs.atrs.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.files.repos.*;
|
||||
import gplx.xowa.wikis.domains.*;
|
||||
import gplx.xowa.addons.wikis.pages.syncs.core.parsers.*;
|
||||
public class Xosync_page_loader {
|
||||
private final Xoh_hdoc_ctx hctx = new Xoh_hdoc_ctx();
|
||||
private final Gfh_tag_rdr tag_rdr = Gfh_tag_rdr.New__html();
|
||||
private final Bry_err_wkr err_wkr = new Bry_err_wkr();
|
||||
private final Xoh_img_src_data img_src_parser = new Xoh_img_src_data();
|
||||
private final Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public byte[] Parse(Xow_wiki wiki, Xoh_page hpg, byte[] src) {
|
||||
// init hctx, tag_rdr, err_wkr
|
||||
int src_len = src.length;
|
||||
hctx.Init_by_page(wiki, hpg);
|
||||
tag_rdr.Init(hpg.Url_bry_safe(), src, 0, src_len);
|
||||
err_wkr.Init_by_page(String_.new_u8(hpg.Url_bry_safe()), src);
|
||||
|
||||
// loop for all <img>
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
// get next "<img>"
|
||||
Gfh_tag img_tag = tag_rdr.Tag__find_fwd_head(pos, src_len, Gfh_tag_.Id__img);
|
||||
|
||||
// none found; add and exit
|
||||
if (img_tag.Name_id() == Gfh_tag_.Id__eos) {
|
||||
tmp_bfr.Add_mid(src, pos, src_len); // add bytes between img_end and prv_pos
|
||||
break;
|
||||
}
|
||||
|
||||
// add bytes between prv_pos and img_bgn
|
||||
tmp_bfr.Add_mid(src, pos, img_tag.Src_bgn());
|
||||
|
||||
// do simple replace for @src
|
||||
Gfh_atr img_src_atr = img_tag.Atrs__get_by_or_fail(Gfh_atr_.Bry__src);
|
||||
byte[] img_src_val = img_src_atr.Val();
|
||||
img_src_val = Bry_.Replace(img_src_val, Xosync_img_src_parser.Bry__xowa_src_bgn, wiki.App().Fsys_mgr().File_dir().To_http_file_bry());
|
||||
|
||||
// parse other atrs for fsdb
|
||||
img_src_parser.Parse(err_wkr, hctx, wiki.Domain_bry(), img_src_atr.Val_bgn(), img_src_atr.Val_end());
|
||||
if (img_src_parser.File_ttl_bry() != null) { // NOTE: need to skip images that don't follow MW image format ("commons.wikimedia.org/thumb/7/70/A.png"); for example, math images
|
||||
Xof_fsdb_itm img = hpg.Img_mgr().Make_img(false);
|
||||
byte[] file_ttl_bry = gplx.langs.htmls.encoders.Gfo_url_encoder_.Http_url.Decode(img_src_parser.File_ttl_bry());
|
||||
img.Init_by_wm_parse(hctx.Wiki__domain_itm().Abrv_xo(), img_src_parser.Repo_is_commons(), img_src_parser.File_is_orig(), file_ttl_bry, img_src_parser.File_w(), img_src_parser.File_time(), img_src_parser.File_page());
|
||||
hctx.File__url_bldr().Init_by_root(img_src_parser.Repo_is_commons() ? hctx.Fsys__file__comm() : hctx.Fsys__file__wiki(), Bool_.N, Byte_ascii.Slash, Bool_.N, Bool_.N, 4);
|
||||
hctx.File__url_bldr().Init_by_itm(img_src_parser.File_is_orig() ? Xof_repo_itm_.Mode_orig : Xof_repo_itm_.Mode_thumb, file_ttl_bry, Xof_file_wkr_.Md5(file_ttl_bry), Xof_ext_.new_by_ttl_(file_ttl_bry), img_src_parser.File_w(), img_src_parser.File_time(), img_src_parser.File_page());
|
||||
img.Orig_repo_name_(img_src_parser.Repo_is_commons() ? Xow_domain_itm_.Bry__commons : wiki.Domain_bry());
|
||||
Io_url html_view_url = hctx.File__url_bldr().Xto_url_by_http();
|
||||
img.Init_at_gallery_end(img_tag.Atrs__get_as_int(Gfh_atr_.Bry__width), img_tag.Atrs__get_as_int(Gfh_atr_.Bry__height), html_view_url, html_view_url);
|
||||
|
||||
Xosync_hdoc_parser.Write_img_tag(tmp_bfr, img_tag, img_src_val, img.Html_uid());
|
||||
}
|
||||
pos = img_tag.Src_end();
|
||||
}
|
||||
|
||||
// overwrite html
|
||||
src = tmp_bfr.To_bry_and_clear();
|
||||
hpg.Db().Html().Html_bry_(src);
|
||||
return src;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue