1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.9.2.1'

This commit is contained in:
gnosygnu
2016-09-11 21:49:20 -04:00
parent 232838c732
commit 35d78f6106
310 changed files with 4358 additions and 5116 deletions

View File

@@ -0,0 +1,65 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
import gplx.xowa.addons.wikis.ctgs.htmls.*;
public class Xoa_ctg_mgr implements Gfo_invk {
public void Init_by_app(Xoae_app app) {}
public boolean Pagecats_grouping_enabled() {return pagecats_grouping_enabled;} private boolean pagecats_grouping_enabled = false;
public byte Missing_ctg_cls_tid() {return missing_ctg_cls_tid;} private byte missing_ctg_cls_tid = Missing_ctg_cls_red_tid;
public byte[] Missing_ctg_cls_css() {
switch (missing_ctg_cls_tid) {
case Missing_ctg_cls_normal_tid: return Missing_ctg_cls_normal_css;
case Missing_ctg_cls_hide_tid: return Missing_ctg_cls_hide_css;
case Missing_ctg_cls_red_tid: return Missing_ctg_cls_red_css;
default: throw Err_.new_unhandled(missing_ctg_cls_tid);
}
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk_missing_ctg_cls)) return Missing_ctg_cls_tid_print(missing_ctg_cls_tid);
else if (ctx.Match(k, Invk_missing_ctg_cls_)) missing_ctg_cls_tid = Missing_ctg_cls_tid_parse(m.ReadStr("v"));
else if (ctx.Match(k, Invk_missing_ctg_cls_list)) return Options_missing_ctg_cls_list;
else if (ctx.Match(k, Invk_pagecats_grouping_enabled)) return Yn.To_str(pagecats_grouping_enabled);
else if (ctx.Match(k, Invk_pagecats_grouping_enabled_)) pagecats_grouping_enabled = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Invk_missing_ctg_cls = "missing_ctg_cls", Invk_missing_ctg_cls_ = "missing_ctg_cls_", Invk_missing_ctg_cls_list = "missing_ctg_cls_list", Invk_pagecats_grouping_enabled = "pagecats_grouping_enabled", Invk_pagecats_grouping_enabled_ = "pagecats_grouping_enabled_";
private static final byte Missing_ctg_cls_normal_tid = 0, Missing_ctg_cls_hide_tid = 1, Missing_ctg_cls_red_tid = 2;
private static final String Missing_ctg_cls_normal_str = "normal", Missing_ctg_cls_hide_str = "hide", Missing_ctg_cls_red_str = "red_link";
private static final byte[] Missing_ctg_cls_normal_css = Bry_.new_a7(".xowa-missing-category-entry {}"), Missing_ctg_cls_hide_css = Bry_.new_a7(".xowa-missing-category-entry {display: none;}"), Missing_ctg_cls_red_css = Bry_.new_a7(".xowa-missing-category-entry {color: red;}");
private static Keyval[] Options_missing_ctg_cls_list = Keyval_.Ary(Keyval_.new_(Missing_ctg_cls_normal_str), Keyval_.new_(Missing_ctg_cls_hide_str), Keyval_.new_(Missing_ctg_cls_red_str));
private static byte Missing_ctg_cls_tid_parse(String v) {
if (String_.Eq(v, Missing_ctg_cls_normal_str)) return Missing_ctg_cls_normal_tid;
else if (String_.Eq(v, Missing_ctg_cls_hide_str)) return Missing_ctg_cls_hide_tid;
else if (String_.Eq(v, Missing_ctg_cls_red_str)) return Missing_ctg_cls_red_tid;
else throw Err_.new_unhandled(v);
}
private static String Missing_ctg_cls_tid_print(byte v) {
switch (v) {
case Missing_ctg_cls_normal_tid: return Missing_ctg_cls_normal_str;
case Missing_ctg_cls_hide_tid: return Missing_ctg_cls_hide_str;
case Missing_ctg_cls_red_tid: return Missing_ctg_cls_red_str;
default: throw Err_.new_unhandled(v);
}
}
public static final byte Version_null = Byte_.Zero, Version_1 = 1, Version_2 = 2;
public static final byte Tid_null = Byte_.Max_value_127, Tid_subc = 0, Tid_file = 1, Tid_page = 2, Tid__max = 3; // SERIALIZED
public static final byte Hidden_n = Byte_.Zero, Hidden_y = (byte)1;
public static final String Html__cls__str = "CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory";
public static final byte[] Html__cls__bry = Bry_.new_a7(Html__cls__str);
}

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.wikis.ctgs.dbs.*;
public class Xoax_ctg_addon implements Xoax_addon_itm { // TODO_OLD:mem_mgr
private final Xow_wiki wiki;
private final Hash_adp_bry hash = Hash_adp_bry.cs();
@@ -25,7 +26,7 @@ public class Xoax_ctg_addon implements Xoax_addon_itm { // TODO_OLD:mem_mgr
public Xoctg_ctg_itm Itms__load(byte[] key) {
Xowd_page_itm tmp_page = new Xowd_page_itm();
wiki.Data__core_mgr().Tbl__page().Select_by_ttl(tmp_page, wiki.Ns_mgr().Ns_category(), key);
gplx.xowa.wikis.data.tbls.Xowd_category_itm itm = wiki.Data__core_mgr().Db__cat_core().Tbl__cat_core().Select(tmp_page.Id());
gplx.xowa.wikis.data.tbls.Xowd_category_itm itm = Xodb_cat_db_.Get_cat_core_or_fail(wiki.Data__core_mgr()).Select(tmp_page.Id());
return Itms__add(key, itm.Count_pages(), itm.Count_subcs(), itm.Count_files());
}
public Xoctg_ctg_itm Itms__add(byte[] key, int pages, int subcs, int files) { // TEST:

View File

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

View File

@@ -0,0 +1,29 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.wkrs.*;
public class Xoax_ctg_bldr_addon implements Xoax_addon_itm, Xoax_addon_itm__bldr {
public Xob_cmd[] Bldr_cmds() {
return new Xob_cmd[]
{ gplx.xowa.addons.wikis.ctgs.bldrs.Xob_pageprop_cmd.Prototype
, gplx.xowa.addons.wikis.ctgs.bldrs.Xob_catlink_cmd.Prototype
};
}
public String Addon__key() {return "xowa.builds.ctgs";}
}

View File

@@ -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);}
}

View File

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

View File

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

View File

@@ -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");
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.bldrs.ucas; 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.bldrs.*;
import org.junit.*; import gplx.xowa.bldrs.*;
public class Uca_trie_tst {
@Before public void init() {fxt.Clear();} private Xob_base_fxt fxt = new Xob_base_fxt();
@Test public void Basic() {
Uca_trie_fxt fxt = new Uca_trie_fxt();
fxt.Clear();
fxt.Init_trie_itm("a", Bry_.New_by_ints(10, 11));
fxt.Init_trie_itm("b", Bry_.New_by_ints(20, 21));
fxt.Init_trie_itm("c", Bry_.New_by_ints(30, 31));
fxt.Test_decode(Bry_.New_by_ints(10, 11), "a");
fxt.Test_decode(Bry_.New_by_ints(10, 11, 20, 21, 30, 31), "abc");
}
}
class Uca_trie_fxt {
public void Clear() {
if (trie == null) {
trie = new Uca_trie();
bfr = Bry_bfr_.New();
}
trie.Clear();
} Uca_trie trie; Bry_bfr bfr;
public void Init_trie_itm(String charAsStr, byte[] uca) {trie.Init_itm(gplx.core.intls.Utf16_.Decode_to_int(Bry_.new_u8(charAsStr), 0), uca);}
public void Test_decode(byte[] bry, String expd) {
trie.Decode(bfr, bry, 0, bry.length);
Tfds.Eq(expd, bfr.To_str_and_clear());
}
}

View File

@@ -0,0 +1,26 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.wikis.data.*; import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.wikis.dbs.*;
public class Xodb_cat_db_ {
public static Xowd_cat_core_tbl Get_cat_core_or_fail(Xow_db_mgr db_mgr) {
Xow_db_file cat_core_db = db_mgr.Dbs__get_by_tid_or_core(Xow_db_file_.Tid__cat_core);
Xowd_cat_core_tbl cat_core_tbl = new Xowd_cat_core_tbl(cat_core_db.Conn(), db_mgr.Props().Schema_is_1());
return cat_core_tbl;
}
}

View File

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

View File

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

View File

@@ -0,0 +1,31 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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_db {
private final Io_url url;
public Xodb_tmp_cat_db(Xowe_wiki wiki) {
this.url = wiki.Fsys_mgr().Root_dir().GenSubFil("xowa.temp.category.sqlite3");
this.conn = Db_conn_bldr.Instance.Get_or_autocreate(true, url);
}
public Db_conn Conn() {return conn;} private final Db_conn conn;
public void Delete() {
conn.Rls_conn();
Io_mgr.Instance.DeleteFil(url);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -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)
);
}
}

View File

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

View File

@@ -0,0 +1,301 @@
/*
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 org.junit.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoh_ctg_page_fxt fxt = new Xoh_ctg_page_fxt();
@Test public void Page_itm() {
fxt .Init_itms__pages("A1")
.Test_html_page(Xoa_ctg_mgr.Tid_page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>");
}
@Test public void Page_itm_missing() {
fxt .Init_itms__pages("A1");
fxt .Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid_page).Itms()[0].Missing_y_();
fxt .Test_html_page(Xoa_ctg_mgr.Tid_page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">A1 (missing)</li>");
}
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
byte[] page_bry = Bry_.new_a7("A 1");
Xoa_url url = Xoa_url.New(Bry_.new_a7("en.wikipedia.org"), page_bry);
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry);
fxt.Wiki().Appe().Usere().History_mgr().Add(url, ttl, page_bry);
fxt .Init_itms__pages("A_1").Init_grp__pages(0, 1)
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A_1\" class=\"xowa-visited\" title=\"A 1\">A 1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all() {
fxt .Init_itms__pages("A1").Init_grp__pages(0, 1)
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void File_all() {
fxt .Init_itms__files("File:A1.png").Init_grp__files(0, 1)
.Test_html_all(Xoa_ctg_mgr.Tid_file, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-category-media\">"
, " <h2>Media in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following file.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/File:A1.png\" title=\"File:A1.png\">File:A1.png</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
// , " <ul id=\"xowa_gallery_ul_0\" class=\"gallery\">"
// , " <li class=\"gallerybox\" style=\"width:155px;\">"
// , " <div style=\"width:155px;\">"
// , " <div class=\"thumb\" style=\"width:155px;\">"
// , " <div id=\"xowa_gallery_div3_-1\" style=\"margin:15px auto;\">"
// , " <a href=\"/wiki/File:A1.png\" class=\"image\">"
// , " <img id=\"xoimg_-1\" alt=\"A1.png\" src=\"\" width=\"-1\" height=\"-1\" />"
// , " </a>"
// , " </div>"
// , " </div>"
// , " <div class=\"gallerytext\">A1.png"
// , " </div>"
// , " </div>"
// , " </li>"
// , ""
// , " </ul>"
}
@Test public void Subc_all() {
fxt .Init_itms__subcs("Category:Subc_1").Init_grp__files(0, 1)
.Test_html_all(Xoa_ctg_mgr.Tid_subc, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-subcategories\">"
, " <h2>Subcategories</h2>"
, " <p>This category has only the following subcategory.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>S</h3>"
, " <ul>"
, " <li>"
, " <div class=\"CategoryTreeSection\">"
, " <div class=\"CategoryTreeItem\">"
, " <span class=\"CategoryTreeBullet\">"
, " <span class=\"CategoryTreeToggle\" style=\"display: none;\" data-ct-title=\"Subc_1\" title=\"Subc 1\" data-ct-state=\"collapsed\">"
, " </span> "
, " </span>"
, " <a href=\"/wiki/Category:Subc_1\" class=\"CategoryTreeLabel CategoryTreeLabelNs14 CategoryTreeLabelCategory\">Subc 1"
, " </a>"
, " <span title=\"contains 0 subcategories, 0 pages, and 0 files\" dir=\"ltr\">"
, " </span>"
, " </div>"
, " <div class=\"CategoryTreeChildren\" style=\"display:none\"></div>"
, " </div>"
, " </li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Page_all_cols() {
fxt .Init_itms__pages("A1", "A2", "A3", "B1", "C1").Init_grp__pages(0, 5)
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>The following 5 pages are in this category, out of 5 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>"
, " <li><a href=\"/wiki/A2\" title=\"A2\">A2</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>A cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A3\" title=\"A3\">A3</a></li>"
, " </ul>"
, " <h3>B</h3>"
, " <ul>"
, " <li><a href=\"/wiki/B1\" title=\"B1\">B1</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>C</h3>"
, " <ul>"
, " <li><a href=\"/wiki/C1\" title=\"C1\">C1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28
fxt .Init_itms__pages("A\"1").Init_grp__pages(0, 1)
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
, " <h2>Pages in category \"Ctg_1\"</h2>"
, " <p>This category contains only the following page.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
, " <td style=\"width: 33%;\">"
, " <h3>A</h3>"
, " <ul>"
, " <li><a href=\"/wiki/A%221\" title=\"A&quot;1\">A&quot;1</a></li>"
, " </ul>"
, " </td>"
, " </tr>"
, " </table>"
, " </div>"
, "</div>"
));
}
@Test public void Bld_rslts_lnk() {
fxt .Init_itms__pages("A1").Init_grp__pages(1, 1)
.Test_bld_rslts_lnk(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, " (<a href=\"/wiki/Category:Ctg_1?pageuntil=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 0</a>)"
, " (<a href=\"/wiki/Category:Ctg_1?pagefrom=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 0</a>)"
));
}
@Test public void Bld_rslts_lnk__encoded() { // escape quotes and spaces; DATE:2016-01-11
fxt .Init_itms__pages("A\" b").Init_grp__pages(1, 1)
.Test_bld_rslts_lnk(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, " (<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+b#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 0</a>)"
, " (<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+b#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 0</a>)"
));
}
@Test public void Calc_col_len() {
fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items
fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items
fxt.Test__calc_col_len(10, 2, 3); // for 10 items, col 2 has 3 items
fxt.Test__calc_col_len(11, 0, 4);
fxt.Test__calc_col_len(11, 1, 4);
fxt.Test__calc_col_len(11, 2, 3);
fxt.Test__calc_col_len(12, 0, 4);
fxt.Test__calc_col_len(12, 1, 4);
fxt.Test__calc_col_len(12, 2, 4);
}
}
class Xoh_ctg_page_fxt {
public Xoh_ctg_page_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
ctg_html = wiki.Html_mgr().Ns_ctg();
}
ctg = new Xoctg_catpage_ctg(Bry_.new_a7("Ctg_1"));
return this;
} private Xoae_app app; private Xoctg_catpage_mgr ctg_html;
public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));}
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg;
public void Test_bld_rslts_lnk(boolean next, String ctg_str, String expd) {
Xoctg_fmt_grp.Grp__max = 0;
byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid_page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid_page));
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
Xoctg_fmt_grp.Grp__max = 200;
}
public Xoh_ctg_page_fxt Init_grp__pages(int bgn, int count) {ctg.Pages().Init(bgn, count); return this;}
public Xoh_ctg_page_fxt Init_grp__files(int bgn, int count) {ctg.Files().Init(bgn, count); return this;}
public Xoh_ctg_page_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_page, titles);}
public Xoh_ctg_page_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_file, titles);}
public Xoh_ctg_page_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_subc, titles);}
private Xoh_ctg_page_fxt Init_itms(byte tid, String[] ttls) {
int len = ttls.length;
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
for (int i = 0; i < len; ++i) {
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, Bry_.new_u8(ttls[i]));
grp.Itms__add(new Xoctg_catpage_itm(i, ttl, ttl.Page_txt()));
}
grp.Itms__make();
return this;
}
public void Test_html_page(byte tid, byte grp_char_0, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_itm_base itm_fmt = list_mgr.Itm_fmt();
Xoctg_catpage_grp list = ctg.Grp_by_tid(tid);
itm_fmt.Init_from_ltr(wiki, list);
itm_fmt.Set_ltr_and_bgn(new byte[] {grp_char_0}, 0);
itm_fmt.Col_end_(0, 0);
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
itm_fmt.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test_html_grp(byte tid, String expd) {
Xoctg_fmt_grp list_mgr = ctg_html.Fmt(tid);
Xoctg_fmt_ltr fmtr_grp = new Xoctg_fmt_ltr(list_mgr.Itm_fmt());
fmtr_grp.Init_from_grp(wiki, ctg.Grp_by_tid(tid));
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
fmtr_grp.Bfr_arg__add(bfr);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
public void Test_html_all(byte tid, String expd) {
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ctg);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
}

View File

@@ -0,0 +1,83 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_url {
public byte[][] Grp_idxs() {return grp_idxs;} private byte[][] grp_idxs = new byte[3][];
public byte[] Grp_fwds() {return grp_fwds;} private byte[] grp_fwds = new byte[3];
private void Clear() {
for (int i = 0; i < 3; i++) {
grp_fwds[i] = Bool_.__byte;
grp_idxs[i] = null;
}
}
public Xoctg_catpage_url Parse(Gfo_usr_dlg usr_dlg, Xoa_url url) {
this.Clear();
Gfo_qarg_itm[] args = url.Qargs_ary();
int len = args.length;
for (int i = 0; i < len; i++) {
Gfo_qarg_itm arg = args[i];
byte[] arg_key = arg.Key_bry();
Object tid_obj = Arg_keys.Get_by_bry(arg_key);
if (tid_obj == null) {usr_dlg.Warn_many("", "", "unknown arg_key: ~{0}", String_.new_u8(arg_key)); continue;} // ignore invalid args
byte[] arg_val = arg.Val_bry();
byte tid = ((Byte_obj_val)tid_obj).Val();
switch (tid) {
case Tid_all_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break; // if "from", default all grps to val; DATE:2014-02-05
case Tid_all_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break;
case Tid_subc_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc); break;
case Tid_subc_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc); break;
case Tid_file_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_file); break;
case Tid_file_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_file); break;
case Tid_page_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_page); break;
case Tid_page_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_page); break;
}
}
return this;
}
private void Set_grp(byte[] val, byte fwd, byte... tids) {
int tids_len = tids.length;
for (int i = 0; i < tids_len; i++) {
byte tid = tids[i];
grp_fwds[tid] = fwd;
grp_idxs[tid] = val;
}
}
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
public static final byte[]
Url_arg_from = Bry_.new_a7("from")
, Url_arg_until = Bry_.new_a7("until")
, Url_arg_subc_bgn = Bry_.new_a7("subcatfrom")
, Url_arg_subc_end = Bry_.new_a7("subcatuntil")
, Url_arg_page_bgn = Bry_.new_a7("pagefrom")
, Url_arg_page_end = Bry_.new_a7("pageuntil")
, Url_arg_file_bgn = Bry_.new_a7("filefrom")
, Url_arg_file_end = Bry_.new_a7("fileuntil")
;
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_a7()
.Add_bry_byte(Url_arg_from , Tid_all_bgn)
.Add_bry_byte(Url_arg_until , Tid_all_end)
.Add_bry_byte(Url_arg_subc_bgn , Tid_subc_bgn)
.Add_bry_byte(Url_arg_subc_end , Tid_subc_end)
.Add_bry_byte(Url_arg_file_bgn , Tid_file_bgn)
.Add_bry_byte(Url_arg_file_end , Tid_file_end)
.Add_bry_byte(Url_arg_page_bgn , Tid_page_bgn)
.Add_bry_byte(Url_arg_page_end , Tid_page_end)
;
}

View File

@@ -0,0 +1,72 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 org.junit.*; import gplx.xowa.apps.urls.*;
public class Xoctg_catpage_url_tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url_fxt fxt = new Xoctg_catpage_url_fxt();
@Test public void Basic() {
fxt.Test_parse("A?subcatfrom=B&filefrom=C&pagefrom=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
fxt.Test_parse("A?subcatuntil=B&fileuntil=C&pageuntil=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
fxt.Test_parse("A?from=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
fxt.Test_parse("A?until=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
}
}
class Xoctg_catpage_url_fxt {
public Xoctg_catpage_url_chkr url() {return expd.Clear();} private Xoctg_catpage_url_chkr expd;
public void Clear() {
if (parser == null) {
Xoa_app app = Xoa_app_fxt.Make__app__edit();
parser = app.User().Wikii().Utl__url_parser();
page_url = Xoa_url.blank();
ctg_url = new Xoctg_catpage_url();
expd = new Xoctg_catpage_url_chkr();
}
} private Xow_url_parser parser; Xoa_url page_url; Xoctg_catpage_url ctg_url;
public void Test_parse(String url_str, Xoctg_catpage_url_chkr expd) {
page_url = parser.Parse(Bry_.new_u8(url_str));
ctg_url.Parse(Gfo_usr_dlg_.Test(), page_url);
expd.Chk(ctg_url);
expd.Clear();
}
}
class Xoctg_catpage_url_chkr {
public Xoctg_catpage_url_chkr Grp_idxs_(String subc, String file, String page) {
grp_idxs[Xoa_ctg_mgr.Tid_subc] = Bry_.new_a7(subc);
grp_idxs[Xoa_ctg_mgr.Tid_file] = Bry_.new_a7(file);
grp_idxs[Xoa_ctg_mgr.Tid_page] = Bry_.new_a7(page);
return this;
} byte[][] grp_idxs = new byte[Xoa_ctg_mgr.Tid__max][];
public Xoctg_catpage_url_chkr Grp_fwds_(byte subc, byte file, byte page) {
grp_fwds[Xoa_ctg_mgr.Tid_subc] = subc;
grp_fwds[Xoa_ctg_mgr.Tid_file] = file;
grp_fwds[Xoa_ctg_mgr.Tid_page] = page;
return this;
} byte[] grp_fwds = new byte[Xoa_ctg_mgr.Tid__max];
public void Chk(Xoctg_catpage_url actl) {
Tfds.Eq_ary_str(String_.Ary(grp_idxs), String_.Ary(actl.Grp_idxs()));
Tfds.Eq_ary(grp_fwds, actl.Grp_fwds());
}
public Xoctg_catpage_url_chkr Clear() {
int len = Xoa_ctg_mgr.Tid__max;
for (int i = 0; i < len; i++) {
grp_idxs[i] = null;
grp_fwds[i] = Bool_.__byte;
}
return this;
}
}

View File

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

View File

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

View File

@@ -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];
}

View File

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

View File

@@ -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"));}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,42 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.*;
class Xoctg_fmt_itm_page extends Xoctg_fmt_itm_base {}
class Xoctg_fmt_itm_file extends Xoctg_fmt_itm_base {
// public void Bfr_arg__add(Bry_bfr bfr) {
// html_itm = wiki.Html_mgr().Gallery_xtn_mgr().Html_gallery_itm_img();
// for (int i = list.Bgn(); i < len; i++) {
// Xoctg_catpage_itm itm = list.Itms()[i];
// Xoa_ttl ttl = itm.Ttl();
// byte[] ttl_page = ttl.Page_txt();
// byte[] itm_href = href_parser.Build_to_bry(ttl, wiki);
// html_itm.Bld_bfr_many(bfr
// , 155 // "itm_box_width"
// , 155 // "itm_div_width"
// , 15 // "itm_margin"
// , -1 // "img_id"
// , ttl_page // "img_ttl"
// , itm_href // "img_href"
// , Bry_.Empty // "html_src"
// , -1 // "img_width"
// , -1 // "img_height"
// , ttl_page // "itm_caption"
// );
// }
// }
}

View File

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

View File

@@ -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>");
}

View File

@@ -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() {}
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,85 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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 org.junit.*;
import gplx.xowa.wikis.data.tbls.*;
public class Xoctg_double_box__tst {
@Before public void init() {fxt.Clear();} private Xoctg_double_box__fxt fxt = new Xoctg_double_box__fxt();
@Test public void Basic() {
fxt.Init_ctg_hidden("Category:A", "Category:B", "Category:C");
fxt.Init_ctg_normal("Category:D", "Category:E", "Category:F");
fxt.Test_print_hidden(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "<a href=\"/wiki/Special:Categories\" title=\"Special:Categories\">Categories</a>:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:D\" title=\"Category:D\">D</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:E\" title=\"Category:E\">E</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:F\" title=\"Category:F\">F</a>"
, "</li>"
, "</ul>"
, "</div>"
, "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks mw-hidden-cats-user-shown\">Hidden categories:"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" title=\"Category:A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" title=\"Category:B\">B</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:C\" title=\"Category:C\">C</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoctg_double_box__fxt {
private Xop_fxt fxt; private Xoctg_double_box hidden_wtr;
private final List_adp init_ctgs = List_adp_.New();
public void Clear() {
fxt = new Xop_fxt();
hidden_wtr = new Xoctg_double_box();
hidden_wtr.Init_by_wiki(fxt.Wiki());
init_ctgs.Clear();
}
public void Init_ctg_normal(String... ary) {Init_ctg(Bool_.N, ary);}
public void Init_ctg_hidden(String... ary) {Init_ctg(Bool_.Y, ary);}
public void Init_ctg(boolean hidden, String[] ary) {
int len = ary.length;
for (int i = 0; i < len; i++) {
Xoa_ttl ttl = fxt.Wiki().Ttl_parse(Bry_.new_u8(ary[i]));
Xoctg_pagebox_itm itm = Xoctg_pagebox_itm.New_by_ttl(ttl);
itm.Load_by_cat_core(hidden, 0, 0, 0);
init_ctgs.Add_many(itm);
}
}
public void Test_print_hidden(String expd) {
Bry_bfr bfr = Bry_bfr_.New();
Xoctg_pagebox_itm[] ary = (Xoctg_pagebox_itm[])init_ctgs.To_ary_and_clear(Xoctg_pagebox_itm.class);
hidden_wtr.Write_pagebox(bfr, ary);
Tfds.Eq_str_lines(expd, bfr.To_str_and_clear());
}
}

View File

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

View File

@@ -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>"
);
}

View File

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

View File

@@ -0,0 +1,62 @@
/*
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 org.junit.*;
import gplx.xowa.htmls.core.htmls.*;
public class Xoctg_single_box__tst {
@Before public void init() {fxt.Clear();} private final Xoh_ctg_mgr_fxt fxt = new Xoh_ctg_mgr_fxt();
@Test public void Basic() {
fxt.Init__ctgs("Category:A", "Category:B").Test_html(String_.Concat_lines_nl
( "<div id=\"catlinks\" class=\"catlinks\">"
, "<div id=\"mw-normal-catlinks\" class=\"mw-normal-catlinks\">"
, "Categories"
, "<ul>"
, "<li>"
, "<a href=\"/wiki/Category:A\" class=\"internal\" title=\"A\">A</a>"
, "</li>"
, "<li>"
, "<a href=\"/wiki/Category:B\" class=\"internal\" title=\"B\">B</a>"
, "</li>"
, "</ul>"
, "</div>"
, "</div>"
));
}
}
class Xoh_ctg_mgr_fxt {
private Xoctg_single_box ctg_grp_mgr; Xoae_app app; Xowe_wiki wiki; Bry_bfr tmp_bfr = Bry_bfr_.New();
private Xoae_page page;
public void Clear() {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
page = wiki.Parser_mgr().Ctx().Page();
ctg_grp_mgr = new Xoctg_single_box();
ctg_grp_mgr.Init_by_wiki(wiki);
}
public Xoh_ctg_mgr_fxt Init__ctgs(String... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
page.Wtxt().Ctgs__add(wiki.Ttl_parse(Bry_.new_u8(ary[i])));
}
return this;
}
public void Test_html(String expd) {
ctg_grp_mgr.Write_pagebox(tmp_bfr, Xoctg_pagebox_itm.New_ary(page));
Tfds.Eq_str_lines(expd, tmp_bfr.To_str_and_clear());
}
}

View File

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