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

Source: Restore broken commit

This commit is contained in:
gnosygnu
2017-02-06 22:14:55 -05:00
parent 938beac9f9
commit 3bfeb94b43
4380 changed files with 328018 additions and 0 deletions

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; 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 {
public static final byte Version_null = Byte_.Zero, Version_1 = 1, Version_2 = 2;
public static final byte Tid__subc = 0, Tid__file = 1, Tid__page = 2, Tid___max = 3; // SERIALIZED; cat_link.cl_type_id
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

@@ -0,0 +1,57 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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();
public Xoax_ctg_addon(Xow_wiki wiki) {this.wiki = wiki;}
public Xoctg_ctg_itm Itms__get_or_null(byte[] key) {return (Xoctg_ctg_itm)hash.Get_by_bry(key);}
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 = 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:
Xoctg_ctg_itm rv = new Xoctg_ctg_itm(key, pages, subcs, files);
hash.Add(key, rv);
return rv;
}
/*
public long Mem__size__max() {return mem__size__max;} private long mem__size__max;
public long Mem__size__reduce() {return mem__size__reduce;} private long mem__size__reduce;
public void Mem__free__all() {hash.Clear();}
public void Mem__free__reduce() {Mem_mgr_.Free__reduce(hash);}
public void Mem__free__unused() {Mem_mgr_.Free__unused(hash);}
public long Mem__stat__size() {return mem__stat__size;} private long mem__stat__size;
public long Mem__stat__last() {return mem__stat__last;} private long mem__stat__last;
public int Mem__stat__count() {return mem__stat__count;} private int mem__stat__count;
*/
public static Xoax_ctg_addon Get(Xow_wiki wiki) {
Xoax_ctg_addon rv = (Xoax_ctg_addon)wiki.Addon_mgr().Itms__get_or_null(ADDON_KEY);
if (rv == null) {
rv = new Xoax_ctg_addon(wiki);
wiki.Addon_mgr().Itms__add(rv);
}
return rv;
}
public String Addon__key() {return ADDON_KEY;} private static final String ADDON_KEY = "xowa.apps.category";
}

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; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*;
public class Xoctg_ctg_itm {
public Xoctg_ctg_itm(byte[] ttl_wo_ns, int pages, int subcs, int files) {
this.Ttl_wo_ns = ttl_wo_ns;
this.Pages = pages;
this.Subcs = subcs;
this.Files = files;
this.All = pages + subcs + files;
}
public final byte[] Ttl_wo_ns;
public final int Pages;
public final int Subcs;
public final int Files;
public final int All;
}

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,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.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.sql_dumps.*;
public class Xob_catlink_cmd extends Xob_sql_dump_base implements Xosql_dump_cbk {
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 protected Xosql_dump_parser New_parser() {return new Xosql_dump_parser(this, "cl_from", "cl_to", "cl_sortkey", "cl_timestamp", "cl_sortkey_prefix", "cl_collation", "cl_type");}
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Xosql_dump_parser parser) {
wiki.Init_assert();
mgr.On_cmd_bgn(wiki);
}
@Override public void Cmd_end() {
if (fail) return;
mgr.On_cmd_end();
this.Cmd_cleanup_sql();
}
public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) {
switch (fld_idx) {
case Fld__cl_from: this.tmp_page_id = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld__cl_to: this.tmp_ctg_ttl = Bry_.Mid(src, val_bgn, val_end); break;
case Fld__cl_sortkey: this.tmp_sortkey = Bry_.Mid(src, val_bgn, val_end); break;
case Fld__cl_timestamp: this.tmp_timestamp = Bry_.Mid(src, val_bgn, val_end); break;
case Fld__cl_sortkey_prefix: this.tmp_sortkey_prefix = Bry_.Mid(src, val_bgn, val_end); break;
case Fld__cl_collation: this.tmp_collation = Bry_.Mid(src, val_bgn, val_end); break;
case Fld__cl_type: this.tmp_type = Bry_.Mid(src, val_bgn, val_end); break;
}
}
public void On_row_done() {
mgr.On_cmd_row(tmp_page_id, tmp_ctg_ttl, tmp_sortkey, tmp_timestamp, tmp_sortkey_prefix, tmp_collation, tmp_type);
}
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,97 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.*;
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 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
String timestamp_str = String_.new_u8(timestamp_bry);
long timestamp = String_.Len_eq_0(timestamp_str) ? 0 : DateAdp_.parse_fmt(timestamp_str, "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
byte[] sortkey_actl = sortkey_orig;
if (collation_id != Xoctg_collation_enum.Tid__uca) {
// sortkey; handle \n
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
}
// 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();
// get cat_core conn
tmp_link_tbl.Create_idx__sortkey(); // index should make SELECT DISTINCT faster
Db_conn cat_core_conn = wiki.Data__core_mgr().Db__core().Conn();
if (wiki.Data__core_mgr().Props().Layout_text().Tid_is_lot()) {
Xow_db_file cat_core_db = wiki.Data__core_mgr().Dbs__get_by_tid_or_null(Xow_db_file_.Tid__cat_core);
if (cat_core_db == null)
cat_core_db = wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__cat_core);
cat_core_conn = cat_core_db.Conn();
}
// create tbl
// 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(); // 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();
try {
wkr.Make_catlink_dbs(wiki, tmp_conn, page_conn, cat_core_conn);
} catch (Exception e) {
Gfo_usr_dlg_.Instance.Log_many("", "", "error while generating catlink dbs; ~{0}", Err_.Message_gplx_log(e));
throw Err_.new_wo_type("error while generating catlink dbs", "err", Err_.Message_gplx_log(e));
}
// 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,145 @@
/*
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"
, ", tcl.cl_timestamp"
, ", tcl.cl_sortkey"
, ", tcl.cl_sortkey_prefix"
, "FROM <temp_db>tmp_cat_link tcl"
, " JOIN page p ON tcl.cl_to_ttl = p.page_title AND p.page_namespace = 14"
, "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 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");
byte[] sortkey = rdr.Read_bry("cl_sortkey");
if (sortkey == null) sortkey = Bry_.Empty; // WORKAROUND: sortkey should never be null; however, sqlite.jdbc sometimes returns as null; EX:ru.s and cl_from = 1324; DATE:2016-11-19
byte[] sortkey_prefix = rdr.Read_bry_by_str("cl_sortkey_prefix");
long db_size_new = db_size_cur + 48 + (sortkey.length * 2) + sortkey_prefix.length;// 46 = 3 ints (12) + 1 long (8) + 1 byte (2?) + 2 index (24?) + 11 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_long("cl_timestamp"), sortkey, sortkey_prefix);
if (++rows % 100000 == 0) {
Gfo_usr_dlg_.Instance.Plog_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__catbox();
cat_link_tbl.Create_idx__catpage();
}
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 <page_db>page p"
, " JOIN <temp_db>tmp_cat_link tcl ON tcl.cl_to_ttl = p.page_title"
, " LEFT JOIN <temp_db>tmp_cat_hidden h ON h.cat_id = p.page_id"
, "WHERE p.page_namespace = 14"
, "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,61 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.sql_dumps.*;
import gplx.dbs.*; import gplx.xowa.addons.wikis.ctgs.dbs.*;
public class Xob_pageprop_cmd extends Xob_sql_dump_base implements Xosql_dump_cbk {
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 protected Xosql_dump_parser New_parser() {return new Xosql_dump_parser(this, "pp_page", "pp_propname", "pp_value");} // NOTE: 4 b/c MW added fld_3:pp_sortkey; DATE:2014-04-28
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Xosql_dump_parser parser) {
wiki.Init_assert();
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() {
if (fail) return;
tbl.Insert_end();
this.Cmd_cleanup_sql();
}
public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) {
switch (fld_idx) {
case Fld__pp_page: this.tmp_id = Bry_.To_int_or(src, val_bgn, val_end, -1); break;
case Fld__pp_propname: this.tmp_key_is_hiddencat = Bry_.Eq(src, val_bgn, val_end, Key_hiddencat); break;
}
}
public void On_row_done() {
if (tmp_key_is_hiddencat)
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"));
}
private static final byte Fld__pp_page = 0, Fld__pp_propname = 1;
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");
}

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,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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__timestamp_unix, fld__sortkey, fld__sortkey_prefix;
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__timestamp_unix = flds.Add_long ("cl_timestamp_unix");
this.fld__sortkey = flds.Add_bry ("cl_sortkey");
this.fld__sortkey_prefix = flds.Add_str ("cl_sortkey_prefix", 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__catbox() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "catbox", fld__from));}
public void Create_idx__catpage() {conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, "catpage", fld__to_id, fld__type_id, fld__sortkey));}
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, long timestamp_unix, byte[] sortkey, byte[] sortkey_prefix) {
stmt_insert.Clear()
.Val_int(fld__from , from)
.Val_int(fld__to_id , to_id)
.Val_byte(fld__type_id , type_id)
.Val_long(fld__timestamp_unix , timestamp_unix)
.Val_bry(fld__sortkey , sortkey)
.Val_bry_as_str(fld__sortkey_prefix , sortkey_prefix)
.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,61 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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_bry ("cl_sortkey");
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(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() {
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_from, fld_from));
conn.Meta_idx_create(Dbmeta_idx_itm.new_normal_by_tbl(tbl_name, fld_to_ttl + "__" + fld_type_id, fld_to_ttl, fld_type_id));
}
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,105 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.core.intls.ucas.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
public class Xoctg_catpage_mgr implements Gfo_invk {
private final Xow_wiki wiki;
private final Hash_adp_bry cache = Hash_adp_bry.cs();
private final Xoctg_catpage_loader loader = new Xoctg_catpage_loader();
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();
private final Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true);
private String missing_cls = Str__missing_cls__red;
public int Grp_max() {return grp_max;} private int grp_max = Grp_max_dflt;
public Xoctg_catpage_mgr(Xow_wiki wiki) {
this.wiki = wiki;
this.collation_mgr = new Xoctg_collation_mgr(wiki);
}
public Xoctg_collation_mgr Collation_mgr() {return collation_mgr;} private Xoctg_collation_mgr collation_mgr;
public Xoctg_fmt_grp Fmt(byte tid) {
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 byte[] Missing_ctg_cls_css() {
if (String_.Eq(missing_cls, Str__missing_cls__normal)) return Css__missing_cls__normal;
else if (String_.Eq(missing_cls, Str__missing_cls__hide)) return Css__missing_cls__hide;
else if (String_.Eq(missing_cls, Str__missing_cls__red)) return Css__missing_cls__red;
else return Bry_.Empty; // NOTE: do not throw error, else fatal error when regen'ing cfg db; DATE:2016-12-27
}
public void Init_by_wiki(Xow_wiki wiki) {
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__missing_class);
}
public void Free_mem_all() {cache.Clear();}
public Xoctg_catpage_ctg Get_or_load_or_null(byte[] page_ttl, Xoctg_catpage_url catpage_url, Xoa_ttl cat_ttl, int limit) {
// load categories from cat dbs; exit if not found
Xoctg_catpage_ctg ctg = (Xoctg_catpage_ctg)cache.Get_by(cat_ttl.Full_db());
if (ctg == null) {
if (gplx.core.envs.Env_.Mode_testing()) return null; // needed for dpl test
synchronized (thread_lock) { // LOCK:used by multiple wrks; DATE:2016-09-12
ctg = loader.Load_ctg_or_null(wiki, page_ttl, this, catpage_url, cat_ttl, limit);
}
if (ctg == null) return null; // not in cache or db; exit
if (limit == Int_.Max_value) // only add to cache if Max_val (DynamicPageList); for regular catpages, always retrieve on demand
cache.Add(cat_ttl.Full_db(), ctg);
}
return ctg;
}
public void Write_catpage(Bry_bfr bfr, Xoa_page page) {
try {
// get catpage_url
Xoctg_catpage_url catpage_url = Xoctg_catpage_url_parser.Parse(page.Url());
// load categories from cat dbs; exit if not found
Xoctg_catpage_ctg ctg = Get_or_load_or_null(page.Ttl().Page_db(), catpage_url, page.Ttl(), grp_max);
if (ctg == null) return;
// write html
Xol_lang_itm lang = page.Lang();
fmt_subcs.Write_catpage_grp(bfr, wiki, lang, ltr_extractor, ctg, grp_max);
fmt_pages.Write_catpage_grp(bfr, wiki, lang, ltr_extractor, ctg, grp_max);
fmt_files.Write_catpage_grp(bfr, wiki, lang, ltr_extractor, ctg, grp_max);
}
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));
}
}
public void Cache__add(byte[] ttl, Xoctg_catpage_ctg ctg) {
cache.Del(ttl);
cache.Add(ttl, ctg);
}
public void Grp_max_(int v) {grp_max = v;} // TEST:
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Invk__collation_)) collation_mgr.Collation_name_(m.ReadStr("v"));
else if (ctx.Match(k, Cfg__missing_class)) missing_cls = m.ReadStr("v");
else return Gfo_invk_.Rv_unhandled;
return this;
} private static final String Invk__collation_ = "collation_";
public static int Grp_max_dflt = 200;
private static final Object thread_lock = new Object();
private static final String Cfg__missing_class = "xowa.addon.category.catpage.missing_class";
private static final String Str__missing_cls__normal = "normal", Str__missing_cls__hide = "hide", Str__missing_cls__red = "red_link";
private static final byte[] Css__missing_cls__normal = Bry_.new_a7(".xowa-missing-category-entry {}"), Css__missing_cls__hide = Bry_.new_a7(".xowa-missing-category-entry {display: none;}"), Css__missing_cls__red = Bry_.new_a7(".xowa-missing-category-entry {color: red;}");
}

View File

@@ -0,0 +1,313 @@
/*
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.core.intls.ucas.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
public class Xoctg_catpage_mgr__basic__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_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");
Xoctg_catpage_itm itm = fxt.Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0);
itm.Page_ttl_(Xoa_ttl.Null);
itm.Sortkey_handle_make(Bry_bfr_.New(), Bry_.Empty);
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\">missing page (0)</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(fxt.Wiki().App(), url, ttl, page_bry);
fxt .Init_itms__pages("A_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")
.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")
.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>"
));
}
@Test public void Subc_all() {
fxt .Init_itms__subcs("Category:Subc_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");
fxt.Init__grp_max_(6);
fxt.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 Page__numeric() { // PURPOSE: check numeric sorting; 0, 9, 10; not 0, 10, 9; DATE:2016-10-09
fxt.Init_itms__pages("0", "9", "10");
fxt.Init__grp_max_(6);
fxt.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 3 pages are in this category, out of 3 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>0-9</h3>"
, " <ul>"
, " <li><a href=\"/wiki/0\" title=\"0\">0</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/9\" title=\"9\">9</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/10\" title=\"10\">10</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")
.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 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 Xoctg_catpage_mgr_fxt {
private int grp_max;
private Uca_ltr_extractor ltr_extractor = new Uca_ltr_extractor(true);
public Xoctg_catpage_mgr_fxt Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
ctg_html = wiki.Ctg__catpage_mgr();
}
ctg = new Xoctg_catpage_ctg(1, Bry_.new_a7("Ctg_1"));
grp_max = 3; // default to 3 paer page
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 Init__grp_max_(int v) {this.grp_max = v;}
public void Init__prev_hide_y_(byte tid) {ctg.Grp_by_tid(tid).Prev_disable_(true);}
public void Init__next_sortkey_(byte tid, String v) {ctg.Grp_by_tid(tid).Next_sortkey_(Bry_.new_u8(v));}
public void Test__navlink(boolean next, String ctg_str, String expd) {
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), grp_max);
Tfds.Eq_str_lines(expd, String_.new_u8(actl));
}
public Xoctg_catpage_mgr_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__page, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__file, titles);}
public Xoctg_catpage_mgr_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid__subc, titles);}
private Xoctg_catpage_mgr_fxt Init_itms(byte tid, String[] ttls) {
int len = ttls.length;
Xoctg_catpage_tmp tmp = new Xoctg_catpage_tmp();
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
grp.Count_all_(len);
for (int i = 0; i < len; ++i) {
byte[] page_ttl_bry = Bry_.new_u8(ttls[i]);
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, page_ttl_bry);
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl);
tmp.Add(itm);
}
tmp.Make_by_grp(grp);
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, ltr_extractor);
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), ltr_extractor);
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(), ltr_extractor, ctg, grp_max);
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
}
}

View File

@@ -0,0 +1,59 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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__navlink__tst {
@Before public void init() {fxt.Clear();} private Xoctg_catpage_mgr_fxt fxt = new Xoctg_catpage_mgr_fxt();
@Test public void Navlink__basic() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
fxt.Init_itms__pages("A\" 2", "A\" 3", "A\" 4");
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A\" 5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2%0AA%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__bos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Init__prev_hide_y_(Xoa_ctg_mgr.Tid__page);
fxt.Init__next_sortkey_(Xoa_ctg_mgr.Tid__page, "A5");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(previous 3)"
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A5#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 3</a>)"
));
}
@Test public void Navlink__eos() {
fxt.Init_itms__pages("A2", "A3", "A4");
fxt.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
( ""
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2%0AA2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 3</a>)"
, "(next 3)"
));
}
}

View File

@@ -0,0 +1,193 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; 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.dbs.*; import gplx.xowa.wikis.data.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
class Xoctg_catlink_loader {
private byte version;
private int link_dbs_len;
private Db_attach_mgr attach_mgr;
private final Bry_bfr sortkey_val_bfr = Bry_bfr_.New();
public void Run(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xoctg_catpage_mgr catpage_mgr, Xowd_page_tbl page_tbl, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int limit) {
String sql = Bld_sql(catpage_mgr, cat_id, grp_tid, url_is_from, url_sortkey, limit);
Load_catlinks(rv, wiki, page_tbl, rv.Grp_by_tid(grp_tid), sql, url_is_from, limit);
}
public void Make_attach_mgr__v2(Xow_db_mgr db_mgr, int cat_link_db_idx) {
this.version = 2;
this.link_dbs_len = 1;
Xow_db_file cat_link_db = db_mgr.Dbs__get_by_id_or_fail(cat_link_db_idx);
this.attach_mgr = new Db_attach_mgr(cat_link_db.Conn(), new Db_attach_itm("link_db_1", cat_link_db.Conn()));
}
public void Make_attach_mgr__v3_v4(Xow_db_mgr db_mgr, Db_conn cat_core_conn) {
// init db vars
List_adp db_list = List_adp_.New();
Db_conn db_1st = null;
int db_idx = 0;
// fill db_list by looping over each db unless (a) cat_link_db or (b) core_db (if all or few)
int len = db_mgr.Dbs__len();
for (int i = 0; i < len; ++i) {
Xow_db_file cl_db = db_mgr.Dbs__get_at(i);
switch (cl_db.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: // skip all other files
continue;
}
// add to db_list
if (db_1st == null) db_1st = cl_db.Conn();
db_list.Add(new Db_attach_itm("link_db_" + ++db_idx, cl_db.Conn()));
}
// make attach_mgr
this.version = 4;
this.link_dbs_len = db_list.Len();
if (cat_core_conn.Meta_tbl_exists("cat_sort")) {
version = 3;
db_1st = cat_core_conn;
}
this.attach_mgr = new Db_attach_mgr(db_1st, (Db_attach_itm[])db_list.To_ary_and_clear(Db_attach_itm.class));
}
private String Bld_sql (Xoctg_catpage_mgr catpage_mgr, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int limit) {
Bry_bfr bfr = Bry_bfr_.New();
for (int i = 0; i < link_dbs_len; ++i)
Bld_sql_by_db(catpage_mgr, cat_id, grp_tid, url_is_from, url_sortkey, i + List_adp_.Base1, bfr);
bfr.Add_str_u8_fmt
( "\nORDER BY cl_to_id, cl_type_id, cl_sortkey {0}"
+ "\nLIMIT {1}"
, url_is_from ? "ASC" : "DESC", limit + 1);
return bfr.To_str_and_clear();
}
private void Bld_sql_by_db (Xoctg_catpage_mgr catpage_mgr, int cat_id, byte grp_tid, boolean url_is_from, byte[] url_sortkey, int link_db_id, Bry_bfr bfr) {
if (link_db_id != List_adp_.Base1) bfr.Add_str_a7("\nUNION\n");
// change sortkey vars per version; note that v3 differs from v2 and v4 b/c of cat_sort tbl
String sortkey_col = "cl_sortkey";
String sortkey_join = "";
if (version == 3) { // NOTE: version 3 takes sortkey from cat_sort
sortkey_col = "cs.cs_key";
sortkey_join = "\n JOIN cat_sort cs ON cl.cl_sortkey_id = cs.cs_id";
}
// sortkey_val
byte[] sortkey_val = null;
String sortkey_prefix_fld = version == 4 ? "cl_sortkey_prefix" : "''";
sortkey_val = Build_sortkey_val(sortkey_val_bfr, version, catpage_mgr.Collation_mgr(), url_sortkey);
// bld sql; NOTE: building sql with args embedded b/c (a) UNION requires multiple Crt_arg for each ?; (EX: 4 unions, 3 ? require 12 .Crt_arg); (b) easier to debug
String sql = Db_sql_.Make_by_fmt(String_.Ary
( "SELECT cl_to_id"
, ", cl_from"
, ", cl_type_id"
, ", {3} AS cl_sortkey"
, ", {7} AS cl_sortkey_prefix"
, "FROM <link_db_{0}>cat_link cl{6}"
, "WHERE cl_to_id = {1}"
, "AND cl_type_id = {2}"
, "AND {3} {4} {5}"
), link_db_id, cat_id, grp_tid, sortkey_col, url_is_from ? ">=" : "<", sortkey_val, sortkey_join, sortkey_prefix_fld);
bfr.Add_str_u8(sql);
}
private void Load_catlinks(Xoctg_catpage_ctg rv, Xow_wiki wiki, Xowd_page_tbl page_tbl, Xoctg_catpage_grp grp, String sql, boolean url_is_from, int limit) {
// init; prep sql
Xoctg_page_loader catlink_loader = new Xoctg_page_loader(wiki);
Ordered_hash hash = catlink_loader.Hash();
sql = attach_mgr.Resolve_sql(sql);
// run sql and create itms based on cat_link
Xoctg_catpage_itm zth_itm = null;
Db_rdr rdr = Db_rdr_.Empty;
int row_idx = 0;
try {
attach_mgr.Attach();
rdr = attach_mgr.Conn_main().Stmt_sql(sql).Exec_select__rls_auto();
while (rdr.Move_next()) {
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_rdr(rdr, version);
if (row_idx++ < limit) // row_idx >= limit for last row; EX: 200 < 200
hash.Add(itm.Page_id(), itm);
else { // last row; EX: 201
if (url_is_from) // from=some_key; 201st row is sort_key for "(Next 200)"
zth_itm = itm;
else // until=some_key; 201st row means that 200th row is not 1st row; show prev link
grp.Prev_disable_(false);
}
}
}
finally {
rdr.Rls();
attach_mgr.Detach();
}
// load ns / ttl from page
page_tbl.Select_in__id(catlink_loader);
grp.Itms_((Xoctg_catpage_itm[])hash.To_ary_and_clear(Xoctg_catpage_itm.class));
// set data for Next 200 / Previous 200
if (zth_itm != null) {
if (version == 4) {
Load_sortkey(wiki, grp, zth_itm);
grp.Next_sortkey_(zth_itm.Sortkey_handle());
}
else
grp.Next_sortkey_(zth_itm.Sortkey_handle());
}
}
private static void Load_sortkey(Xow_wiki wiki, Xoctg_catpage_grp grp, Xoctg_catpage_itm zth_itm) {
// load page_ttl from db
Xowd_page_itm tmp_pg = new Xowd_page_itm();
wiki.Data__core_mgr().Tbl__page().Select_by_id(tmp_pg, zth_itm.Page_id());
// set ttl; skip if page is missing (Talk: ns) else null-ref; PAGE:en.wCategory:Disambig-Class_Comics_articles_of_NA-importance DATE:2016-10-12
if (tmp_pg.Exists()) {
Xoa_ttl zth_ttl = wiki.Ttl_parse(tmp_pg.Ns_id(), tmp_pg.Ttl_page_db());
zth_itm.Page_ttl_(zth_ttl);
}
// make sortkey
byte[] prv_sortkey = grp.Itms__len() == 0 ? Bry_.Empty : grp.Itms__get_at(grp.Itms__len() - 1).Sortkey_handle();
zth_itm.Sortkey_handle_make(Bry_bfr_.New(), prv_sortkey);
}
public static byte[] Build_sortkey_val(Bry_bfr sortkey_val_bfr, byte version, Xoctg_collation_mgr collation_mgr, byte[] url_sortkey) {
// find \n and ignore everything after it; needed else "< 'A\nA'" will pull up "A"; NOTE: can't find logic in MediaWiki CategoryViewer.php; DATE:2016-10-11
// ALSO: needed for v2 else SQL will literally have WHERE cl_sortkey = 'A\nA';
byte[] tmp_sortkey = url_sortkey;
int nl_pos = Bry_find_.Find_fwd(tmp_sortkey, Byte_ascii.Nl);
if (nl_pos != Bry_find_.Not_found)
tmp_sortkey = Bry_.Mid(tmp_sortkey, 0, nl_pos);
if (version == 4) {
if (Bry_.Len_gt_0(url_sortkey)) {
// make sortkey_val
sortkey_val_bfr.Add_byte(Byte_ascii.Ltr_x).Add_byte_apos();
gplx.core.encoders.Hex_utl_.Encode_bfr(sortkey_val_bfr, collation_mgr.Get_sortkey(tmp_sortkey));
sortkey_val_bfr.Add_byte_apos();
}
else
sortkey_val_bfr.Add_byte_apos().Add_byte_apos();
}
else
sortkey_val_bfr.Add_byte_apos().Add(Db_sql_.Escape_arg(tmp_sortkey)).Add_byte_apos();
return sortkey_val_bfr.To_bry_and_clear();
}
}

View File

@@ -0,0 +1,39 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; 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 org.junit.*; import gplx.core.tests.*; import gplx.xowa.apps.urls.*;
import gplx.xowa.langs.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs.*;
public class Xoctg_catlink_loader__tst {
private final Xoctg_catlink_loader__fxt fxt = new Xoctg_catlink_loader__fxt();
@Test public void Build_sortkey_val__v4() { // PURPOSE: remove "\n" and afterwards else will omit 1 record
fxt.Test__build_sortkey_sql(4, "A\nA", "x'41'"); // fails if "x'410a41'"
}
@Test public void Build_sortkey_val__v2() { // PURPOSE: remove "\n" and afterwards else SQL will be malformed
fxt.Test__build_sortkey_sql(2, "A\nA", "'A'"); // fails if "'A\nA'"
}
}
class Xoctg_catlink_loader__fxt {
public void Test__build_sortkey_sql(int version, String sortkey, String expd) {
Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app, "de.wikipedia.org"); // use "de.wikipedia.org" for simple "uppercase" collation
Xoctg_collation_mgr collation_mgr = new Xoctg_collation_mgr(wiki);
Bry_bfr bfr = Bry_bfr_.New();
Gftest.Eq__str(expd, Xoctg_catlink_loader.Build_sortkey_val(bfr, Byte_.By_int(version), collation_mgr, Bry_.new_u8(sortkey)));
}
}

View File

@@ -0,0 +1,71 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs; 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.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.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.dbs.*;
public class Xoctg_catpage_loader {
public Xoctg_catpage_ctg Load_ctg_or_null(Xow_wiki wiki, byte[] page_ttl_bry, Xoctg_catpage_mgr catpage_mgr, Xoctg_catpage_url cat_url, Xoa_ttl cat_ttl, int limit) {
// get cat_id 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.Log_many("", "", "category does not exist in page table; wiki=~{0} page=~{1} ttl=~{2}", wiki.Domain_str(), page_ttl_bry, cat_ttl.Full_db()); // Log instead of Warn b/c happens many times in en.d, en.b, en.u; DATE:2016-10-22
return null;
}
int cat_id = page_itm.Id();
// get cat_core_itm from cat_core_tbl
Xowd_cat_core_tbl cat_core_tbl = Xodb_cat_db_.Get_cat_core_or_fail(db_mgr);
Xowd_category_itm cat_core_itm = cat_core_tbl.Select(cat_id);
if (cat_core_itm == Xowd_category_itm.Null) {
Gfo_usr_dlg_.Instance.Log_many("", "", "category does not exist in cat_core table; ttl=~{0}", cat_ttl.Full_db()); // NOTE: this is not rare as Category pages can be created as deliberately empty, or as redirects; fr.w:Catégorie:Utilisateur_hess-4; DATE:2016-09-12
return null;
}
// load itms from cat_link_db for each grp_tid
Xoctg_catpage_ctg rv = new Xoctg_catpage_ctg(cat_id, cat_ttl.Page_txt());
for (byte grp_tid = Xoa_ctg_mgr.Tid__subc; grp_tid < Xoa_ctg_mgr.Tid___max; ++grp_tid) {
Xoctg_catpage_grp grp = rv.Grp_by_tid(grp_tid);
grp.Count_all_(cat_core_itm.Count_by_tid(grp_tid)); // set total counts per grp based on cat_core_itm;
// init url_vars
boolean url_is_from = cat_url.Grp_fwds()[grp_tid]; // EX: "pagefrom=A"; "pageuntil=B"
byte[] url_sortkey = cat_url.Grp_keys()[grp_tid];
// set prev / next props to dflt values
if (url_is_from) { // url is from; EX: from=A
if (Bry_.Len_eq_0(url_sortkey)) // no sortkey specified for group, so group always starts with 1st itm -> disable previous link
grp.Prev_disable_(true);
}
else { // url is until; EX: until=A
grp.Prev_disable_(true); // default prev link to disabled; loader will load 201 items and set to false if 201st found
grp.Next_sortkey_(url_sortkey); // next sortkey is always sortkey of until url arg;
}
// load links
Xoctg_catlink_loader loader = new Xoctg_catlink_loader();
if (cat_core_itm.File_idx() == -1) // v3 or v4: loop over all cat_link dbs {
loader.Make_attach_mgr__v3_v4 (db_mgr, cat_core_tbl.Conn());
else // v2: use cat_link_db
loader.Make_attach_mgr__v2 (db_mgr, cat_core_itm.File_idx());
loader.Run(rv, wiki, catpage_mgr, page_tbl, cat_id, grp_tid, url_is_from, url_sortkey, limit);
}
return rv;
}
}

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.dbs; 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.dbs.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
public class Xoctg_page_loader implements Select_in_cbk {
private final Xow_wiki wiki;
private final Ordered_hash hash = Ordered_hash_.New();
public Xoctg_page_loader(Xow_wiki wiki) {this.wiki = wiki;}
public Ordered_hash Hash() {return hash;}
public int Hash_max() {return hash.Len();}
public void Write_sql(Bry_bfr bfr, int idx) {
Xoctg_catpage_itm itm = (Xoctg_catpage_itm)hash.Get_at(idx);
bfr.Add_int_variable(itm.Page_id());
}
public void Read_data(Db_rdr rdr) {
// read values from page_tbl
int page_id = rdr.Read_int("page_id");
int page_ns = rdr.Read_int("page_namespace");
byte[] page_ttl = rdr.Read_bry_by_str("page_title");
// get itm and set data
Xoctg_catpage_itm itm = (Xoctg_catpage_itm)hash.Get_by(page_id);
if (itm == null) return; // NOTE: itms can exist in cat_links_tbl, but not in page_tbl; EX:User:Any_page
itm.Page_ttl_(wiki.Ttl_parse(page_ns, page_ttl));
}
}

View File

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

View File

@@ -0,0 +1,54 @@
/*
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 {
private Xoctg_catpage_itm[] itms = Xoctg_catpage_itm.Ary_empty;
private byte[] next_sortkey = Bry_.Empty;
public Xoctg_catpage_grp(byte tid) {this.tid = tid;}
public byte Tid() {return tid;} private byte tid; // subc|page|file
public int Count_all() {return count_all;} private int count_all; // count of items in entire category; EX: 456
public boolean Prev_disable() {return prev_disable;} private boolean prev_disable; // prev_link: disable link
public byte[] Next_sortkey() {return next_sortkey;} // next_link: set sortkey
public int Itms__len() {return itms.length;}
public Xoctg_catpage_itm Itms__get_at(int i) {return itms[i];}
public void Count_all_(int v) {this.count_all = v;}
public void Prev_disable_(boolean v) {this.prev_disable = v;}
public void Next_sortkey_(byte[] v) {this.next_sortkey = v;}
public void Itms_(Xoctg_catpage_itm[] v) {
this.itms = v;
Array_.Sort(itms, new Xoctg_catpage_itm_sorter()); // NOTE: need to reorder for page_until b/c ORDER BY DESC
// make sortkey_handle
Bry_bfr tmp_bfr = Bry_bfr_.New();
int itms_len = itms.length;
byte[] prv_sortkey_handle = Bry_.Empty;
for (int i = 0; i < itms_len; ++i) {
Xoctg_catpage_itm itm = itms[i];
prv_sortkey_handle = itm.Sortkey_handle_make(tmp_bfr, prv_sortkey_handle);
}
}
}
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.Sortkey_binary(), rhs.Sortkey_binary());
}
}

View File

@@ -0,0 +1,101 @@
/*
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.*;
import gplx.dbs.*; import gplx.xowa.wikis.nss.*;
public class Xoctg_catpage_itm {
private byte version;
Xoctg_catpage_itm(byte version, byte grp_tid, int page_id, byte[] sortkey_prefix, byte[] sortkey_binary) {
this.version = version;
this.grp_tid = grp_tid;
this.page_id = page_id;
this.page_ttl = Xoa_ttl.Null;
this.sortkey_prefix = sortkey_prefix;
this.sortkey_handle = sortkey_prefix; // default handle to sortkey_prefix;
this.sortkey_binary = sortkey_binary;
}
public byte Grp_tid() {return grp_tid;} private final byte grp_tid; // v2-v4:cl_type_id; subc,page,file
public int Page_id() {return page_id;} private final int page_id; // v2-v4:cl_from
public byte[] Sortkey_prefix() {return sortkey_prefix;} private byte[] sortkey_prefix; // v2-v3:cl_sortkey; v4:cl_sortkey_prefix
public byte[] Sortkey_handle() {return sortkey_handle;} private byte[] sortkey_handle; // v2-v3:cl_sortkey; v4:cl_sortkey_prefix\nttl_txt; never "cl_sortkey" which is binary ICU value;
public byte[] Sortkey_binary() {return sortkey_binary;} private byte[] sortkey_binary; // v2-v4:cl_sortkey; note that v4 is binary icu value
public Xoa_ttl Page_ttl() {return page_ttl;} private Xoa_ttl page_ttl;
public void Page_ttl_(Xoa_ttl ttl) {
this.page_ttl = ttl;
// sortkey_prefix will be blank for v2; use page_ttl; PAGE:s.w:Category:Computer_science DATE:2015-11-22
if (version == Version__2 && Bry_.Len_eq_0(sortkey_prefix))
sortkey_prefix = page_ttl.Page_txt();
// sortkey_binary will be blank for v2,v3; use page_ttl; PAGE:fr.w:Article_contenant_un_appel_à_traduction_en_anglais; DATE:2016-10-11
if (version != Version__4 && Bry_.Len_eq_0(sortkey_binary)) sortkey_binary = page_ttl.Page_txt();
}
public byte[] Sortkey_handle_make(Bry_bfr tmp_bfr, byte[] prv_sortkey_handle) {
// page.tbl missing even though in cat_link.tbl; happens for "User:" namespace pages;
if (page_ttl == Xoa_ttl.Null) {
// sortkey_prefix exists; happens for [[Category:A]] as opposed to [[Category:A|some_sortkey_prefix]]; also, {{DEFAULTSORTKEY:some_sortkey_prefix}}
if (Bry_.Len_gt_0(sortkey_prefix)) {
sortkey_handle = sortkey_prefix;
return sortkey_handle; // set sortkey_prefix as new prv_sortkey_handle;
}
else {
// set sortkey_handle to "prv_sortkey" + "page_id"; needed for multiple "missing" catlinks which span 200 page boundaries
tmp_bfr.Add(prv_sortkey_handle);
tmp_bfr.Add_byte_nl();
tmp_bfr.Add_int_variable(page_id);
sortkey_handle = tmp_bfr.To_bry_and_clear();
return prv_sortkey_handle;
}
}
// page.tbl exists
else {
// "In UCA, tab is the only character that can sort above LF so we strip both of them from the original prefix."; Title.php|getCategorySortKey
if (sortkey_prefix.length == 0) {
sortkey_handle = page_ttl.Page_txt();
}
else {
byte[] sortkey_normalized = Bry_.Replace(sortkey_prefix, Sortkey_prefix_replace__src, Sortkey_prefix_replace__trg);
tmp_bfr.Add(sortkey_normalized);
tmp_bfr.Add_byte_nl().Add(page_ttl.Page_txt()); // "$prefix\n$unprefixed";
sortkey_handle = tmp_bfr.To_bry_and_clear();
}
return sortkey_handle;
}
}
public static final Xoctg_catpage_itm[] Ary_empty = new Xoctg_catpage_itm[0];
public static Xoctg_catpage_itm New_by_rdr(Db_rdr rdr, byte version) {
byte[] sortkey_binary = Bry_.Empty;
byte[] sortkey_prefix = Bry_.Empty;
if (version == Version__4) {
sortkey_binary = rdr.Read_bry("cl_sortkey");
sortkey_prefix = rdr.Read_bry_by_str("cl_sortkey_prefix");
}
else {
sortkey_binary = Bry_.Empty;
sortkey_prefix = rdr.Read_bry_by_str("cl_sortkey");
}
return new Xoctg_catpage_itm(version, rdr.Read_byte("cl_type_id"), rdr.Read_int("cl_from"), sortkey_prefix, sortkey_binary);
}
public static Xoctg_catpage_itm New_by_ttl(byte grp_tid, int page_id, Xoa_ttl ttl) { // TEST
Xoctg_catpage_itm rv = new Xoctg_catpage_itm(Version__4, grp_tid, page_id, ttl.Page_txt(), Bry_.Empty);
rv.Page_ttl_(ttl);
return rv;
}
private static final byte Version__2 = 2, Version__4 = 4;
private static final byte[] Sortkey_prefix_replace__src = Bry_.new_a7("\n\t"), Sortkey_prefix_replace__trg = Bry_.new_a7(" ");
}

View File

@@ -0,0 +1,43 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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_tmp {
private final List_adp subc_list = List_adp_.New(), page_list = List_adp_.New(), file_list = List_adp_.New();
public void Add(Xoctg_catpage_itm itm) {
List_adp list = Get_by_tid(itm.Grp_tid());
list.Add(itm);
}
public void Make_by_ctg(Xoctg_catpage_ctg ctg) { // TEST:
for (byte tid = 0; tid < Xoa_ctg_mgr.Tid___max; ++tid)
Make_by_grp(ctg.Grp_by_tid(tid));
}
public void Make_by_grp(Xoctg_catpage_grp grp) {
byte tid = grp.Tid();
List_adp list = Get_by_tid(tid);
if (list.Len() == 0) return;
grp.Itms_((Xoctg_catpage_itm[])list.To_ary_and_clear(Xoctg_catpage_itm.class));
}
private List_adp Get_by_tid(byte tid) {
switch (tid) {
case Xoa_ctg_mgr.Tid__subc: return subc_list;
case Xoa_ctg_mgr.Tid__page: return page_list;
case Xoa_ctg_mgr.Tid__file: return file_list;
default: throw Err_.new_unhandled_default(tid);
}
}
}

View File

@@ -0,0 +1,109 @@
/*
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.core.intls.ucas.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
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, Uca_ltr_extractor ltr_extractor, Xoctg_catpage_ctg dom_ctg, int grp_max) { // TEST:
Xoctg_catpage_grp dom_grp = dom_ctg.Grp_by_tid(tid);
if (dom_grp.Count_all() == 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.Itms__len(), dom_grp.Count_all());
// 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, grp_max);
// init grp; write
itms_fmt.Init_from_grp(wiki, dom_grp, ltr_extractor);
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, int grp_max) { // TEST:
if (view_grp.Count_all() < grp_max) return Bry_.Empty; // < 200; never show;
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
Html_nav_bry(bfr, wiki, ttl, view_grp, grp_max, Bool_.N);
Html_nav_bry(bfr, wiki, ttl, view_grp, grp_max, 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 grp, int grp_max, boolean url_is_from) {
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 (url_is_from) {
arg_idx_lbl = url_arg_bgn;
arg_sortkey = grp.Next_sortkey();
}
else {
arg_idx_lbl = url_arg_end;
arg_sortkey = grp.Itms__get_at(0).Sortkey_handle(); // use 1st item as sortkey for "until" args
}
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 = url_is_from ? 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
// print text if 1st / zth page; else, print html
if ( ( url_is_from && Bry_.Len_eq_0(grp.Next_sortkey()))
|| (!url_is_from && grp.Prev_disable())
)
Fmt__nav__text.Bld_many(bfr, nav_text);
else
Fmt__nav__href.Bld_many(bfr, nav_href, ttl.Full_url(), nav_text);
}
private static final Bry_fmt
Fmt__nav__href = Bry_fmt.New("\n(<a href=\"~{nav_href}\" class=\"xowa_nav\" title=\"~{nav_title}\">~{nav_text}</a>)")
, Fmt__nav__text = Bry_fmt.New("\n(~{nav_text})")
, 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_parser.Bry__arg_subc_bgn, Xoctg_catpage_url_parser.Bry__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_parser.Bry__arg_page_bgn, Xoctg_catpage_url_parser.Bry__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_parser.Bry__arg_file_bgn, Xoctg_catpage_url_parser.Bry__arg_file_end, Bry_.new_a7("mw-category-media"));}
}

View File

@@ -0,0 +1,101 @@
/*
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.core.intls.ucas.*;
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 Uca_ltr_extractor ltr_extractor;
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.Itms__len(), col_idx, Cols_max);
}
public void Init_from_ltr(Xow_wiki wiki, Xoctg_catpage_grp grp, Uca_ltr_extractor ltr_extractor) {
this.wiki = wiki;
this.grp = grp;
this.ltr_extractor = ltr_extractor;
}
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 grp_end = grp.Itms__len();
// loop over itms;
for (int i = loop_bgn; i < grp_end; 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__get_at(i);
byte[] itm_sortkey = itm.Sortkey_handle();
// reached end of ltr; exit
byte[] ltr_1st = ltr_extractor.Get_1st_ltr(itm_sortkey);
if (!Bry_.Has_at_bgn(ltr_1st, ltr_cur, 0, ltr_1st.length)) {
loop_end_idx = i;
loop_ends_at_col = i == col_end;
return;
}
Xoa_ttl itm_ttl = itm.Page_ttl();
if (itm_ttl == Xoa_ttl.Null)
Fmt__missing.Bld_many(bfr, itm.Page_id());
else
Bld_html(bfr, wiki, history_mgr, href_parser, itm, itm_ttl);
}
loop_end_idx = grp_end;
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"
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, gplx.core.encoders.Hex_utl_.Encode_bry(itm.Sortkey_binary()));
}
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\">missing page (~{itm_id})</li>"
)
, Fmt__exists = Bry_fmt.Auto_nl_skip_last
( ""
, " <li><a href=\"~{itm_href}\"~{itm_atr_cls} title=\"~{itm_title}\">~{itm_text}</a></li>" // <!--~{itm_sortkey}-->
)
;
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__subc.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__subc = 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,86 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.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.core.intls.ucas.*;
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;
private Uca_ltr_extractor ltr_extractor;
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, Uca_ltr_extractor ltr_extractor) {
this.grp = grp;
this.msg__list_continues = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_list_continues);
this.ltr_extractor = ltr_extractor;
itm_fmt.Init_from_ltr(wiki, grp, ltr_extractor);
}
public void Bfr_arg__add(Bry_bfr bfr) {
int itm_idx = 0;
int itm_end = grp.Itms__len();
int itms_len = itm_end - itm_idx; if (itms_len == 0) return; // no items; exit
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 < itm_end) {
Xoctg_catpage_itm itm = grp.Itms__get_at(itm_idx);
// get ltr_head; EX: "C" or "C cont."
byte[] itm_sortkey = itm.Sortkey_handle();
// byte[] ltr_cur = gplx.core.intls.Utf8_.Get_char_at_pos_as_bry(itm_sortkey, 0);
byte[] ltr_cur = ltr_extractor.Get_1st_ltr(itm_sortkey);
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,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.langs; 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.core.intls.ucas.*;
public class Xoctg_collation_mgr {
private final Xow_wiki wiki;
private Xoctg_collation_wkr wkr;
public Xoctg_collation_mgr(Xow_wiki wiki) {
this.wiki = wiki;
this.wkr = new Xoctg_collation_wkr__uppercase(wiki); // REF:https://noc.wikimedia.org/conf/InitialiseSettings.php.txt|wgCategoryCollation|default
}
public void Collation_name_(String v) {
this.wkr = Xoctg_collation_wkr_.Make(wiki, v);
}
public byte[] Get_sortkey(byte[] src) {
return wkr.Get_sortkey(src);
}
}

View File

@@ -0,0 +1,67 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.langs; 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 interface Xoctg_collation_wkr {
String Type_name();
String Wm_name();
byte[] Get_sortkey(byte[] src);
}
class Xoctg_collation_wkr__uppercase implements Xoctg_collation_wkr {
private final Xow_wiki wiki;
public Xoctg_collation_wkr__uppercase(Xow_wiki wiki) {this.wiki = wiki;}
public String Type_name() {return "uppercase";}
public String Wm_name() {return this.Type_name();}
public byte[] Get_sortkey(byte[] src) {
return wiki.Lang().Case_mgr().Case_build_upper(src);
}
}
class Xoctg_collation_wkr__identity implements Xoctg_collation_wkr {
public String Type_name() {return "identity";}
public String Wm_name() {return this.Type_name();}
public byte[] Get_sortkey(byte[] src) {
return src;
}
}
class Xoctg_collation_wkr__uca implements Xoctg_collation_wkr {
private gplx.core.intls.ucas.Uca_collator collator;
public Xoctg_collation_wkr__uca(String wm_name, String icu_locale) {
// REF:"includes/collation/Collation.php|factory" "includes/collation/IcuCollation.php|__construct"
this.wm_name = wm_name;
// remove anything after "@"; EX: 'svwikisource' => 'uca-sv@collation=standard', // T48058
int at_pos = String_.FindFwd(icu_locale, "@");
if (at_pos != String_.Find_none)
icu_locale = String_.Mid(icu_locale, 0, at_pos);
// handle "default-u-kn"
if (String_.Eq(icu_locale, "default-u-kn"))
this.icu_locale = "en";
else if (String_.Eq(icu_locale, "root"))
this.icu_locale = "en";
else
this.icu_locale = icu_locale;
this.numeric_sorting = String_.Has_at_end(icu_locale, "-u-kn");
}
public String Type_name() {return wm_name;} private final String wm_name;
public String Wm_name() {return this.Type_name();}
public String Icu_locale() {return icu_locale;} private final String icu_locale;
public boolean Numeric_sorting() {return numeric_sorting;} private final boolean numeric_sorting;
public byte[] Get_sortkey(byte[] src) {
if (collator == null) collator = gplx.core.intls.ucas.Uca_collator_.New(icu_locale, numeric_sorting);
return collator.Get_sortkey(String_.new_u8(src));
}
}

View File

@@ -0,0 +1,36 @@
/*
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.langs; 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_collation_wkr_ {
public static Xoctg_collation_wkr Make(Xow_wiki wiki, String wm_name) {
// REF:"includes/collation/Collation.php|factory"
if (String_.Eq(wm_name, "uppercase")) return new Xoctg_collation_wkr__uppercase(wiki);
else if (String_.Eq(wm_name, "identity")) return new Xoctg_collation_wkr__identity();
else if (String_.Eq(wm_name, "uca-default")) return new Xoctg_collation_wkr__uca(wm_name, "root");
else if (String_.Eq(wm_name, "xx-uca-ckb")) return new Xoctg_collation_wkr__uca(wm_name, "fa"); // FUTURE:should create custom collation class to do extra logic
else if (String_.Eq(wm_name, "xx-uca-et")) return new Xoctg_collation_wkr__uca(wm_name, "et"); // FUTURE:should create custom collation class to do extra logic
else {
if (String_.Has_at_bgn(wm_name, "uca-"))
return new Xoctg_collation_wkr__uca(wm_name, String_.Replace(wm_name, "uca-", ""));
else { // unknown collation code; log and exit
Gfo_usr_dlg_.Instance.Warn_many("", "", "unknown collation; collation=~{0}", wm_name);
return new Xoctg_collation_wkr__uppercase(wiki);
}
}
}
}

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.catpages.langs; 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 org.junit.*; import gplx.core.tests.*;
public class Xoctg_collation_wkr___tst {
private final Xoctg_collation_wkr___fxt fxt = new Xoctg_collation_wkr___fxt();
@Test public void Uppercase() {fxt.Test__make("uppercase" , "uppercase");}
@Test public void Identity() {fxt.Test__make("identity" , "identity");}
@Test public void Unknown() {fxt.Test__make("unknown" , "uppercase");}
@Test public void Uca__uca_default() {fxt.Test__make__uca("uca-default" , "en", false);}
@Test public void Uca__xx_uca_ckb() {fxt.Test__make__uca("xx-uca-ckb" , "fa", false);}
@Test public void Uca__xx_uca_et() {fxt.Test__make__uca("xx-uca-et" , "et", false);}
@Test public void Uca__uca_default_u_kn() {fxt.Test__make__uca("uca-default-u-kn" , "en", true);}
@Test public void Uca__uca_at_logic() {fxt.Test__make__uca("uca-sv@collation=standard" , "sv", false);}
}
class Xoctg_collation_wkr___fxt {
public void Test__make(String wm_name, String expd_type) {
Xoctg_collation_wkr actl = Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_type, actl.Type_name());
}
public void Test__make__uca(String wm_name, String expd_locale, boolean expd_numeric_sorting) {
Xoctg_collation_wkr__uca actl = (Xoctg_collation_wkr__uca)Xoctg_collation_wkr_.Make(null, wm_name);
Gftest.Eq__str(expd_locale, actl.Icu_locale());
Gftest.Eq__bool(expd_numeric_sorting, actl.Numeric_sorting());
}
}

View File

@@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; 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_url {
public Xoctg_catpage_url(byte[][] keys, boolean[] fwds) {this.keys = keys; this.fwds = fwds;}
public byte[][] Grp_keys() {return keys;} private final byte[][] keys;
public boolean[] Grp_fwds() {return fwds;} private final boolean[] fwds;
public static Xoctg_catpage_url New__blank() {
byte[][] keys = new byte[Xoa_ctg_mgr.Tid___max][];
boolean[] fwds = new boolean[Xoa_ctg_mgr.Tid___max];
// for blank url, all fwds are true; EX: "Category:A" -> keys {"", "", ""}, fwds {true, true, true}
for (int i = 0; i < Xoa_ctg_mgr.Tid___max; ++i) {
fwds[i] = Bool_.Y;
keys[i] = Bry_.Empty;
}
return new Xoctg_catpage_url(keys, fwds);
}
}

View File

@@ -0,0 +1,47 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls; 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 org.junit.*; import gplx.core.tests.*; 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 Specific() {
fxt.Exec__parse("A?subcatfrom=B&filefrom=C&pagefrom=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?subcatuntil=B&fileuntil=C&pageuntil=D" ).Test__keys("B", "C", "D").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void General() {
fxt.Exec__parse("A?from=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
fxt.Exec__parse("A?until=B" ).Test__keys("B", "B", "B").Test__fwds(Bool_.N, Bool_.N, Bool_.N);
}
@Test public void Url_encoded() {
fxt.Exec__parse("A?from=B+C").Test__keys("B C", "B C", "B C").Test__fwds(Bool_.Y, Bool_.Y, Bool_.Y);
}
}
class Xoctg_catpage_url__fxt {
private Xow_url_parser xo_url_parser; private Xoctg_catpage_url ctg_url;
public void Clear() {
Xoa_app app = Xoa_app_fxt.Make__app__edit();
this.xo_url_parser = app.User().Wikii().Utl__url_parser();
}
public Xoctg_catpage_url__fxt Exec__parse(String url_str) {
Xoa_url page_url = xo_url_parser.Parse(Bry_.new_u8(url_str));
this.ctg_url = Xoctg_catpage_url_parser.Parse(page_url);
return this;
}
public Xoctg_catpage_url__fxt Test__keys(String... expd) {Gftest.Eq__ary(Bry_.Ary(expd), ctg_url.Grp_keys(), "keys"); return this;}
public Xoctg_catpage_url__fxt Test__fwds(boolean... expd) {Gftest.Eq__ary(expd, ctg_url.Grp_fwds(), "fwds"); return this;}
}

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.urls; 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.core.net.*; import gplx.core.net.qargs.*;
import gplx.langs.htmls.encoders.*;
public class Xoctg_catpage_url_parser {
public static Xoctg_catpage_url Parse(Xoa_url url) {
Gfo_qarg_itm[] args = url.Qargs_ary();
if (args == null) return Xoctg_catpage_url.New__blank();
int len = args.length;
if (len == 0) return Xoctg_catpage_url.New__blank();
// init caturl structs
byte[][] keys = new byte[Xoa_ctg_mgr.Tid___max][];
boolean[] fwds = new boolean[Xoa_ctg_mgr.Tid___max];
for (int i = 0; i < Xoa_ctg_mgr.Tid___max; ++i) {
fwds[i] = Bool_.Y;
keys[i] = Bry_.Empty;
}
Bry_bfr tmp_bfr = Bry_bfr_.New();
// loop qargs; EX: "?subcatfrom=B&filefrom=C&pagefrom=D"
for (int i = 0; i < len; ++i) {
Gfo_qarg_itm arg = args[i];
// get tid from arg; EX: "pagefrom" -> Tid__page_bgn
byte[] key = arg.Key_bry();
byte tid = Key_hash.Get_as_byte_or(key, Byte_ascii.Max_7_bit);
if (tid == Byte_ascii.Max_7_bit) { // if invalid, warn and skip
Gfo_usr_dlg_.Instance.Warn_many("", "", "catpage:unknown url arg: raw~={0} key=~{1}", url.To_bry(true, true), key);
continue;
}
// set val
byte[] val = arg.Val_bry();
Gfo_url_encoder_.Http_url.Decode(tmp_bfr, Bool_.N, val, 0, val.length);
val = tmp_bfr.To_bry_and_clear();
// set struct
switch (tid) {
case Tid__each_bgn: Set_grp(keys, fwds, val, Bool_.Y, 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__each_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__subc, Xoa_ctg_mgr.Tid__file, Xoa_ctg_mgr.Tid__page); break;
case Tid__subc_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__subc); break;
case Tid__subc_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__subc); break;
case Tid__file_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__file); break;
case Tid__file_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__file); break;
case Tid__page_bgn: Set_grp(keys, fwds, val, Bool_.Y, Xoa_ctg_mgr.Tid__page); break;
case Tid__page_end: Set_grp(keys, fwds, val, Bool_.N, Xoa_ctg_mgr.Tid__page); break;
}
}
return new Xoctg_catpage_url(keys, fwds);
}
private static void Set_grp(byte[][] keys, boolean[] fwds, byte[] key, boolean fwd, byte... tids) {
int len = tids.length;
for (int i = 0; i < len; ++i) {
byte tid = tids[i];
keys[tid] = key;
fwds[tid] = fwd;
}
}
private static final byte
Tid__each_bgn = 0, Tid__each_end = 1
, Tid__subc_bgn = 2, Tid__subc_end = 3
, Tid__file_bgn = 4, Tid__file_end = 5
, Tid__page_bgn = 6, Tid__page_end = 7
;
public static final byte[]
Bry__arg_each_bgn = Bry_.new_a7("from") , Bry__arg_each_end = Bry_.new_a7("until")
, Bry__arg_subc_bgn = Bry_.new_a7("subcatfrom") , Bry__arg_subc_end = Bry_.new_a7("subcatuntil")
, Bry__arg_page_bgn = Bry_.new_a7("pagefrom") , Bry__arg_page_end = Bry_.new_a7("pageuntil")
, Bry__arg_file_bgn = Bry_.new_a7("filefrom") , Bry__arg_file_end = Bry_.new_a7("fileuntil")
;
private static final Hash_adp_bry Key_hash = Hash_adp_bry.ci_a7()
.Add_bry_byte(Bry__arg_each_bgn , Tid__each_bgn) .Add_bry_byte(Bry__arg_each_end , Tid__each_end)
.Add_bry_byte(Bry__arg_subc_bgn , Tid__subc_bgn) .Add_bry_byte(Bry__arg_subc_end , Tid__subc_end)
.Add_bry_byte(Bry__arg_page_bgn , Tid__page_bgn) .Add_bry_byte(Bry__arg_page_end , Tid__page_end)
.Add_bry_byte(Bry__arg_file_bgn , Tid__file_bgn) .Add_bry_byte(Bry__arg_file_end , Tid__file_end)
;
}

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_or_fail(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=~{1}", 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,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.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 implements Gfo_invk {
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 boolean Grouping_enabled() {return grouping_enabled;} private boolean grouping_enabled;
public void Init_by_wiki(Xow_wiki wiki) {
single_box.Init_by_wiki(wiki);
double_box.Init_by_wiki(wiki);
wiki.App().Cfg().Bind_many_wiki(this, wiki, Cfg__grouping_enabled);
}
public void Write_pagebox(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xoctg_pagebox_itm[] pagebox_itms) {
try {
if (grouping_enabled)
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) {
// NOTE: db load is necessary b/c page.Wtxt().Ctgs__len() is insufficient
// html_dbs will always be 0 since they do not parse ctgs;
// wtxt_dbs may have page.Wtxt().Ctgs__len() > 0 but these items don't have Id / Hidden
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_db());
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);
}
return hash.To_ary_and_clear();
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Cfg__grouping_enabled)) this.grouping_enabled = m.ReadYn("v");
else return Gfo_invk_.Rv_unhandled;
return this;
}
private static final String Cfg__grouping_enabled = "xowa.addon.category.pagebox.grouping_enabled";
}

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 itm = ary[i];
Xoctg_double_grp list = itm.Hidden() ? grp_hidden : grp_normal;
list.Itms().Itms__add(itm);
}
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>"
);
}