mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.9.4.1'
This commit is contained in:
@@ -58,7 +58,7 @@ public class Xoa_ctg_mgr implements Gfo_invk {
|
||||
}
|
||||
}
|
||||
public static final byte Version_null = Byte_.Zero, Version_1 = 1, Version_2 = 2;
|
||||
public static final byte Tid_null = Byte_.Max_value_127, Tid_subc = 0, Tid_file = 1, Tid_page = 2, Tid__max = 3; // SERIALIZED
|
||||
public static final byte 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);
|
||||
|
||||
@@ -16,33 +16,33 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
public class Xob_catlink_cmd extends Xob_sql_dump_base implements Sql_file_parser_cmd {
|
||||
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, Sql_file_parser parser) {
|
||||
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Xosql_dump_parser parser) {
|
||||
wiki.Init_assert();
|
||||
parser.Save_csv_n_().Fld_cmd_(this).Flds_req_idx_(7, 0, 1, 2, 3, 4, 5, 6);
|
||||
mgr.On_cmd_bgn(wiki);
|
||||
}
|
||||
@Override public void Cmd_end() {
|
||||
mgr.On_cmd_end();
|
||||
this.Cmd_cleanup_sql();
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
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, fld_bgn, fld_end, -1); break;
|
||||
case Fld__cl_to: this.tmp_ctg_ttl = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_sortkey: this.tmp_sortkey = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_timestamp: this.tmp_timestamp = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_sortkey_prefix: this.tmp_sortkey_prefix = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_collation: this.tmp_collation = Bry_.Mid(src, fld_bgn, fld_end); break;
|
||||
case Fld__cl_type: this.tmp_type = Bry_.Mid(src, fld_bgn, fld_end);
|
||||
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);
|
||||
mgr.On_cmd_row(tmp_page_id, tmp_ctg_ttl, tmp_sortkey, tmp_timestamp, tmp_sortkey_prefix, tmp_collation, tmp_type);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ class Xob_catlink_mgr {
|
||||
}
|
||||
public void On_cmd_row(int page_id, byte[] ctg_ttl, byte[] sortkey_orig, byte[] timestamp_bry, byte[] sortkey_prefix, byte[] collation_bry, byte[] type_bry) {
|
||||
// convert strings to numbers
|
||||
long timestamp = DateAdp_.parse_fmt(String_.new_u8(timestamp_bry), "YYYY-MM-dd HH:mm:ss").Timestamp_unix();
|
||||
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);
|
||||
|
||||
@@ -64,11 +65,17 @@ class Xob_catlink_mgr {
|
||||
public void On_cmd_end() {
|
||||
tmp_link_tbl.Insert_end();
|
||||
|
||||
// create cat_sort
|
||||
// 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().Props().Layout_text().Tid_is_lot()
|
||||
? wiki.Data__core_mgr().Dbs__make_by_tid(Xow_db_file_.Tid__cat_core).Conn()
|
||||
: wiki.Data__core_mgr().Db__core().Conn();
|
||||
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);
|
||||
|
||||
@@ -16,9 +16,9 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.bldrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*;
|
||||
import gplx.xowa.bldrs.*; import gplx.xowa.bldrs.wkrs.*; import gplx.xowa.bldrs.sqls.*;
|
||||
import gplx.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 Sql_file_parser_cmd {
|
||||
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;
|
||||
@@ -26,10 +26,10 @@ public class Xob_pageprop_cmd extends Xob_sql_dump_base implements Sql_file_pars
|
||||
|
||||
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, Sql_file_parser parser) {
|
||||
@Override public void Cmd_bgn_hook(Xob_bldr bldr, Xosql_dump_parser parser) {
|
||||
wiki.Init_assert();
|
||||
parser.Save_csv_n_().Fld_cmd_(this).Flds_req_idx_(4, 0, 1, 2); // NOTE: 4 b/c MW added fld_3:pp_sortkey; DATE:2014-04-28
|
||||
Xodb_tmp_cat_db tmp_db = new Xodb_tmp_cat_db(wiki);
|
||||
tbl = new Xodb_tmp_cat_hidden_tbl(tmp_db.Conn());
|
||||
tbl.Insert_bgn();
|
||||
@@ -38,18 +38,18 @@ public class Xob_pageprop_cmd extends Xob_sql_dump_base implements Sql_file_pars
|
||||
tbl.Insert_end();
|
||||
this.Cmd_cleanup_sql();
|
||||
}
|
||||
public void Exec(byte[] src, byte[] fld_key, int fld_idx, int fld_bgn, int fld_end, Bry_bfr file_bfr, Sql_file_parser_data data) {
|
||||
public void On_fld_done(int fld_idx, byte[] src, int val_bgn, int val_end) {
|
||||
switch (fld_idx) {
|
||||
case Fld__id: this.tmp_id = Bry_.To_int_or(src, fld_bgn, fld_end, -1); break;
|
||||
case Fld__key: this.tmp_key_is_hiddencat = Bry_.Eq(src, fld_bgn, fld_end, Key_hiddencat); break;
|
||||
case Fld__val:
|
||||
if (!tmp_key_is_hiddencat) {data.Cancel_row_y_(); return;}
|
||||
tbl.Insert_cmd_by_batch(tmp_id);
|
||||
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;
|
||||
case Fld__pp_value:
|
||||
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"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
private static final byte Fld__id = 0, Fld__key = 1, Fld__val = 2;
|
||||
private static final byte Fld__pp_page = 0, Fld__pp_propname = 1, Fld__pp_value = 2;
|
||||
|
||||
public static final String BLDR_CMD_KEY = "wiki.page_props";
|
||||
@Override public String Cmd_key() {return BLDR_CMD_KEY;}
|
||||
|
||||
@@ -19,34 +19,56 @@ package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.x
|
||||
import gplx.xowa.wikis.dbs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
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.utls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_mgr {
|
||||
private final Hash_adp_bry cache = Hash_adp_bry.cs();
|
||||
private final Xoctg_catpage_loader loader = new Xoctg_catpage_loader();
|
||||
private final Xoctg_catpage_url tmp_catpage_url = new Xoctg_catpage_url();
|
||||
private final Xoctg_fmt_grp fmt_subcs = Xoctg_fmt_grp.New__subc(), fmt_pages = Xoctg_fmt_grp.New__page(), fmt_files = Xoctg_fmt_grp.New__file();
|
||||
public Xoctg_fmt_grp Fmt(byte tid) { // TEST:
|
||||
public int Grp_max() {return grp_max;} private int grp_max = Grp_max_dflt;
|
||||
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;
|
||||
case Xoa_ctg_mgr.Tid__subc: return fmt_subcs;
|
||||
case Xoa_ctg_mgr.Tid__page: return fmt_pages;
|
||||
case Xoa_ctg_mgr.Tid__file: return fmt_files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Free_mem_all() {cache.Clear();}
|
||||
public Xoctg_catpage_ctg Get_or_load_or_null(Xow_wiki wiki, Xoa_ttl cat_ttl) {
|
||||
// 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
|
||||
ctg = loader.Load_by_ttl_or_null(wiki, cat_ttl);
|
||||
if (ctg == null) return null; // not in cache or db; exit
|
||||
cache.Add(cat_ttl.Full_db(), ctg);
|
||||
}
|
||||
return ctg;
|
||||
}
|
||||
public void Write_catpage(Bry_bfr bfr, Xow_wiki wiki, Xoa_page page, Xoh_wtr_ctx hctx) {
|
||||
try {
|
||||
// load categories from cat dbs; exit if not found
|
||||
tmp_catpage_url.Parse(wiki.App().Usr_dlg(), page.Url());
|
||||
Xoctg_catpage_ctg dom_ctg = loader.Load_by_ttl_or_null(wiki, page.Ttl());
|
||||
if (dom_ctg == null) return;
|
||||
Xoctg_catpage_ctg ctg = Get_or_load_or_null(wiki, page.Ttl());
|
||||
if (ctg == null) return;
|
||||
|
||||
// filter subs; need for large categories like de.w:Category:Mann
|
||||
Xoctg_catpage_url catpage_url = Xoctg_catpage_url_parser.Parse(page.Url());
|
||||
Xoctg_catpage_filter.Filter(grp_max, catpage_url, ctg);
|
||||
|
||||
// write html
|
||||
Xol_lang_itm lang = page.Lang();
|
||||
fmt_subcs.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
fmt_pages.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
fmt_files.Write_catpage_grp(bfr, wiki, lang, dom_ctg);
|
||||
fmt_subcs.Write_catpage_grp(bfr, wiki, lang, ctg, grp_max);
|
||||
fmt_pages.Write_catpage_grp(bfr, wiki, lang, ctg, grp_max);
|
||||
fmt_files.Write_catpage_grp(bfr, wiki, lang, 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 static int Grp_max_dflt = 200;
|
||||
}
|
||||
|
||||
@@ -18,16 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.htmls.core.htmls.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoh_ctg_page_fxt fxt = new Xoh_ctg_page_fxt();
|
||||
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__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li><a href=\"/wiki/A1\" title=\"A1\">A1</a></li>");
|
||||
}
|
||||
@Test public void Page_itm_missing() {
|
||||
fxt .Init_itms__pages("A1");
|
||||
fxt .Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid_page).Itms()[0].Missing_y_();
|
||||
fxt .Test_html_page(Xoa_ctg_mgr.Tid_page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">A1 (missing)</li>");
|
||||
fxt .Ctg().Grp_by_tid(Xoa_ctg_mgr.Tid__page).Itms__get_at(0).Missing_y_();
|
||||
fxt .Test__html__page(Xoa_ctg_mgr.Tid__page, Byte_ascii.Ltr_A, "\n <li class=\"xowa-missing-category-entry\"><span title=\"id not found: #0 might be talk/user page\">A1 (missing)</li>");
|
||||
}
|
||||
@Test public void Visited_doesnt_work_for_space() {// PURPOSE: xowa-visited not inserted for pages with space
|
||||
byte[] page_bry = Bry_.new_a7("A 1");
|
||||
@@ -35,7 +35,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
Xoa_ttl ttl = Xoa_ttl.Parse(fxt.Wiki(), page_bry);
|
||||
fxt.Wiki().Appe().Usere().History_mgr().Add(url, ttl, page_bry);
|
||||
fxt .Init_itms__pages("A_1").Init_grp__pages(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
.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>"
|
||||
@@ -57,7 +57,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
}
|
||||
@Test public void Page_all() {
|
||||
fxt .Init_itms__pages("A1").Init_grp__pages(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
.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>"
|
||||
@@ -79,7 +79,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
}
|
||||
@Test public void File_all() {
|
||||
fxt .Init_itms__files("File:A1.png").Init_grp__files(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_file, String_.Concat_lines_nl_skip_last
|
||||
.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>"
|
||||
@@ -117,7 +117,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
}
|
||||
@Test public void Subc_all() {
|
||||
fxt .Init_itms__subcs("Category:Subc_1").Init_grp__files(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_subc, String_.Concat_lines_nl_skip_last
|
||||
.Test__html__all(Xoa_ctg_mgr.Tid__subc, String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, "<div id=\"mw-subcategories\">"
|
||||
, " <h2>Subcategories</h2>"
|
||||
@@ -153,7 +153,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
}
|
||||
@Test public void Page_all_cols() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3", "B1", "C1").Init_grp__pages(0, 5)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
.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>"
|
||||
@@ -192,7 +192,7 @@ public class Xoctg_catpage_mgr_tst {
|
||||
}
|
||||
@Test public void Title__escape_quotes() {// PURPOSE: quotes in title should be escaped; DATE:2015-12-28
|
||||
fxt .Init_itms__pages("A\"1").Init_grp__pages(0, 1)
|
||||
.Test_html_all(Xoa_ctg_mgr.Tid_page, String_.Concat_lines_nl_skip_last
|
||||
.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>"
|
||||
@@ -212,22 +212,6 @@ public class Xoctg_catpage_mgr_tst {
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Bld_rslts_lnk() {
|
||||
fxt .Init_itms__pages("A1").Init_grp__pages(1, 1)
|
||||
.Test_bld_rslts_lnk(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pageuntil=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 0</a>)"
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pagefrom=A1#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 0</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Bld_rslts_lnk__encoded() { // escape quotes and spaces; DATE:2016-01-11
|
||||
fxt .Init_itms__pages("A\" b").Init_grp__pages(1, 1)
|
||||
.Test_bld_rslts_lnk(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+b#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 0</a>)"
|
||||
, " (<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+b#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 0</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Calc_col_len() {
|
||||
fxt.Test__calc_col_len(10, 0, 4); // for 10 items, col 0 has 4 items
|
||||
fxt.Test__calc_col_len(10, 1, 3); // for 10 items, col 1 has 3 items
|
||||
@@ -240,31 +224,32 @@ public class Xoctg_catpage_mgr_tst {
|
||||
fxt.Test__calc_col_len(12, 2, 4);
|
||||
}
|
||||
}
|
||||
class Xoh_ctg_page_fxt {
|
||||
public Xoh_ctg_page_fxt Clear() {
|
||||
class Xoctg_catpage_mgr_fxt {
|
||||
private int grp_max;
|
||||
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.Html_mgr().Ns_ctg();
|
||||
ctg_html = wiki.Html_mgr().Catpage_mgr();
|
||||
}
|
||||
ctg = new Xoctg_catpage_ctg(Bry_.new_a7("Ctg_1"));
|
||||
grp_max = Xoctg_catpage_mgr.Grp_max_dflt;
|
||||
return this;
|
||||
} private Xoae_app app; private Xoctg_catpage_mgr ctg_html;
|
||||
public void Test__calc_col_len(int grp_len, int col_idx, int expd) {Tfds.Eq(expd, Xoctg_fmt_itm_base.Calc_col_len(grp_len, col_idx, 3));}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Xoctg_catpage_ctg Ctg() {return ctg;} private Xoctg_catpage_ctg ctg;
|
||||
public void Test_bld_rslts_lnk(boolean next, String ctg_str, String expd) {
|
||||
Xoctg_fmt_grp.Grp__max = 0;
|
||||
byte[] actl = ctg_html.Fmt(Xoa_ctg_mgr.Tid_page).Bld_bwd_fwd(wiki, Xoa_ttl.Parse(wiki, Bry_.new_a7(ctg_str)), ctg.Grp_by_tid(Xoa_ctg_mgr.Tid_page));
|
||||
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));
|
||||
Xoctg_fmt_grp.Grp__max = 200;
|
||||
}
|
||||
public Xoh_ctg_page_fxt Init_grp__pages(int bgn, int count) {ctg.Pages().Init(bgn, count); return this;}
|
||||
public Xoh_ctg_page_fxt Init_grp__files(int bgn, int count) {ctg.Files().Init(bgn, count); return this;}
|
||||
public Xoh_ctg_page_fxt Init_itms__pages(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_page, titles);}
|
||||
public Xoh_ctg_page_fxt Init_itms__files(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_file, titles);}
|
||||
public Xoh_ctg_page_fxt Init_itms__subcs(String... titles) {return Init_itms(Xoa_ctg_mgr.Tid_subc, titles);}
|
||||
private Xoh_ctg_page_fxt Init_itms(byte tid, String[] ttls) {
|
||||
public Xoctg_catpage_mgr_fxt Init_grp_max(int v) {this.grp_max = v; return this;}
|
||||
public Xoctg_catpage_mgr_fxt Init_grp__pages(int bgn, int count) {ctg.Pages().Rng_(bgn, count); return this;}
|
||||
public Xoctg_catpage_mgr_fxt Init_grp__files(int bgn, int count) {ctg.Files().Rng_(bgn, count); return this;}
|
||||
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_grp grp = ctg.Grp_by_tid(tid);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
@@ -274,7 +259,7 @@ class Xoh_ctg_page_fxt {
|
||||
grp.Itms__make();
|
||||
return this;
|
||||
}
|
||||
public void Test_html_page(byte tid, byte grp_char_0, String expd) {
|
||||
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);
|
||||
@@ -285,7 +270,7 @@ class Xoh_ctg_page_fxt {
|
||||
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) {
|
||||
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));
|
||||
@@ -293,9 +278,9 @@ class Xoh_ctg_page_fxt {
|
||||
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) {
|
||||
public void Test__html__all(byte tid, String expd) {
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ctg);
|
||||
ctg_html.Fmt(tid).Write_catpage_grp(bfr, wiki, wiki.Lang(), ctg, grp_max);
|
||||
Tfds.Eq_str_lines(expd, bfr.To_str_and_rls());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
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("A1", "A2", "A3").Init_grp_max(1).Init_grp__pages(1, 2)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 1</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__encoded() { // escape quotes and spaces; DATE:2016-01-11
|
||||
fxt .Init_itms__pages("A\" 1", "A\" 2", "A\" 3").Init_grp_max(1).Init_grp__pages(1, 2)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A%22+2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 1</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A%22+3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__bos() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3").Init_grp_max(1).Init_grp__pages(0, 1)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(previous 1)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A2#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 1</a>)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__eos() {
|
||||
fxt .Init_itms__pages("A1", "A2", "A3").Init_grp_max(2).Init_grp__pages(2, 3)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 2</a>)"
|
||||
, "(next 2)"
|
||||
));
|
||||
}
|
||||
@Test public void Navlink__eos__2() { // PURPOSE.fix: do not suppress next page on penultimate page; DATE:2016-09-25
|
||||
fxt .Init_itms__pages("A1", "A2", "A3", "A4").Init_grp_max(2).Init_grp__pages(2, 3)
|
||||
.Test__navlink(Bool_.Y, "Category:Ctg_1", String_.Concat_lines_nl
|
||||
( ""
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pageuntil=A3#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">previous 2</a>)"
|
||||
, "(<a href=\"/wiki/Category:Ctg_1?pagefrom=A4#mw-pages\" class=\"xowa_nav\" title=\"Category:Ctg_1\">next 2</a>)"
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts.*;
|
||||
public class Xoctg_catpage_url {
|
||||
public byte[][] Grp_idxs() {return grp_idxs;} private byte[][] grp_idxs = new byte[3][];
|
||||
public byte[] Grp_fwds() {return grp_fwds;} private byte[] grp_fwds = new byte[3];
|
||||
private void Clear() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
grp_idxs[i] = null;
|
||||
}
|
||||
}
|
||||
public Xoctg_catpage_url Parse(Gfo_usr_dlg usr_dlg, Xoa_url url) {
|
||||
this.Clear();
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
int len = args.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
byte[] arg_key = arg.Key_bry();
|
||||
Object tid_obj = Arg_keys.Get_by_bry(arg_key);
|
||||
if (tid_obj == null) {usr_dlg.Warn_many("", "", "unknown arg_key: ~{0}", String_.new_u8(arg_key)); continue;} // ignore invalid args
|
||||
byte[] arg_val = arg.Val_bry();
|
||||
byte tid = ((Byte_obj_val)tid_obj).Val();
|
||||
switch (tid) {
|
||||
case Tid_all_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break; // if "from", default all grps to val; DATE:2014-02-05
|
||||
case Tid_all_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc, Xoa_ctg_mgr.Tid_file, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_subc_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_subc_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_subc); break;
|
||||
case Tid_file_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_file_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_file); break;
|
||||
case Tid_page_bgn: Set_grp(arg_val, Bool_.Y_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
case Tid_page_end: Set_grp(arg_val, Bool_.N_byte, Xoa_ctg_mgr.Tid_page); break;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void Set_grp(byte[] val, byte fwd, byte... tids) {
|
||||
int tids_len = tids.length;
|
||||
for (int i = 0; i < tids_len; i++) {
|
||||
byte tid = tids[i];
|
||||
grp_fwds[tid] = fwd;
|
||||
grp_idxs[tid] = val;
|
||||
}
|
||||
}
|
||||
public static final byte Tid_all_bgn = 0, Tid_subc_bgn = 1, Tid_subc_end = 2, Tid_file_bgn = 3, Tid_file_end = 4, Tid_page_bgn = 5, Tid_page_end = 6, Tid_all_end = 8;
|
||||
public static final byte[]
|
||||
Url_arg_from = Bry_.new_a7("from")
|
||||
, Url_arg_until = Bry_.new_a7("until")
|
||||
, Url_arg_subc_bgn = Bry_.new_a7("subcatfrom")
|
||||
, Url_arg_subc_end = Bry_.new_a7("subcatuntil")
|
||||
, Url_arg_page_bgn = Bry_.new_a7("pagefrom")
|
||||
, Url_arg_page_end = Bry_.new_a7("pageuntil")
|
||||
, Url_arg_file_bgn = Bry_.new_a7("filefrom")
|
||||
, Url_arg_file_end = Bry_.new_a7("fileuntil")
|
||||
;
|
||||
public static final Hash_adp_bry Arg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_bry_byte(Url_arg_from , Tid_all_bgn)
|
||||
.Add_bry_byte(Url_arg_until , Tid_all_end)
|
||||
.Add_bry_byte(Url_arg_subc_bgn , Tid_subc_bgn)
|
||||
.Add_bry_byte(Url_arg_subc_end , Tid_subc_end)
|
||||
.Add_bry_byte(Url_arg_file_bgn , Tid_file_bgn)
|
||||
.Add_bry_byte(Url_arg_file_end , Tid_file_end)
|
||||
.Add_bry_byte(Url_arg_page_bgn , Tid_page_bgn)
|
||||
.Add_bry_byte(Url_arg_page_end , Tid_page_end)
|
||||
;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*;
|
||||
import org.junit.*; import gplx.xowa.apps.urls.*;
|
||||
public class Xoctg_catpage_url_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xoctg_catpage_url_fxt fxt = new Xoctg_catpage_url_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_parse("A?subcatfrom=B&filefrom=C&pagefrom=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?subcatuntil=B&fileuntil=C&pageuntil=D", fxt.url().Grp_idxs_("B", "C", "D").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
fxt.Test_parse("A?from=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.Y_byte, Bool_.Y_byte, Bool_.Y_byte));
|
||||
fxt.Test_parse("A?until=B", fxt.url().Grp_idxs_("B", "B", "B").Grp_fwds_(Bool_.N_byte, Bool_.N_byte, Bool_.N_byte));
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url_fxt {
|
||||
public Xoctg_catpage_url_chkr url() {return expd.Clear();} private Xoctg_catpage_url_chkr expd;
|
||||
public void Clear() {
|
||||
if (parser == null) {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
parser = app.User().Wikii().Utl__url_parser();
|
||||
page_url = Xoa_url.blank();
|
||||
ctg_url = new Xoctg_catpage_url();
|
||||
expd = new Xoctg_catpage_url_chkr();
|
||||
}
|
||||
} private Xow_url_parser parser; Xoa_url page_url; Xoctg_catpage_url ctg_url;
|
||||
public void Test_parse(String url_str, Xoctg_catpage_url_chkr expd) {
|
||||
page_url = parser.Parse(Bry_.new_u8(url_str));
|
||||
ctg_url.Parse(Gfo_usr_dlg_.Test(), page_url);
|
||||
expd.Chk(ctg_url);
|
||||
expd.Clear();
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_url_chkr {
|
||||
public Xoctg_catpage_url_chkr Grp_idxs_(String subc, String file, String page) {
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_subc] = Bry_.new_a7(subc);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_file] = Bry_.new_a7(file);
|
||||
grp_idxs[Xoa_ctg_mgr.Tid_page] = Bry_.new_a7(page);
|
||||
return this;
|
||||
} byte[][] grp_idxs = new byte[Xoa_ctg_mgr.Tid__max][];
|
||||
public Xoctg_catpage_url_chkr Grp_fwds_(byte subc, byte file, byte page) {
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_subc] = subc;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_file] = file;
|
||||
grp_fwds[Xoa_ctg_mgr.Tid_page] = page;
|
||||
return this;
|
||||
} byte[] grp_fwds = new byte[Xoa_ctg_mgr.Tid__max];
|
||||
public void Chk(Xoctg_catpage_url actl) {
|
||||
Tfds.Eq_ary_str(String_.Ary(grp_idxs), String_.Ary(actl.Grp_idxs()));
|
||||
Tfds.Eq_ary(grp_fwds, actl.Grp_fwds());
|
||||
}
|
||||
public Xoctg_catpage_url_chkr Clear() {
|
||||
int len = Xoa_ctg_mgr.Tid__max;
|
||||
for (int i = 0; i < len; i++) {
|
||||
grp_idxs[i] = null;
|
||||
grp_fwds[i] = Bool_.__byte;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -19,20 +19,20 @@ package gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import g
|
||||
public class Xoctg_catpage_ctg {
|
||||
public Xoctg_catpage_ctg(byte[] name) {this.name = name;}
|
||||
public byte[] Name() {return name;} private final byte[] name;
|
||||
public Xoctg_catpage_grp Subcs() {return subcs;} private final Xoctg_catpage_grp subcs = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_subc);
|
||||
public Xoctg_catpage_grp Pages() {return pages;} private final Xoctg_catpage_grp pages = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_page);
|
||||
public Xoctg_catpage_grp Files() {return files;} private final Xoctg_catpage_grp files = new Xoctg_catpage_grp(Xoa_ctg_mgr.Tid_file);
|
||||
public int Total() {return subcs.Total() + pages.Total() + files.Total();}
|
||||
public Xoctg_catpage_grp 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.Itms__len() + pages.Itms__len() + files.Itms__len();}
|
||||
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;
|
||||
case Xoa_ctg_mgr.Tid__subc: return subcs;
|
||||
case Xoa_ctg_mgr.Tid__page: return pages;
|
||||
case Xoa_ctg_mgr.Tid__file: return files;
|
||||
default: throw Err_.new_unhandled(tid);
|
||||
}
|
||||
}
|
||||
public void Make_itms() {
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid__max; ++i) {
|
||||
for (byte i = 0; i < Xoa_ctg_mgr.Tid___max; ++i) {
|
||||
Xoctg_catpage_grp grp = Grp_by_tid(i);
|
||||
grp.Itms__make();
|
||||
}
|
||||
|
||||
@@ -17,28 +17,27 @@ 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 final List_adp tmp_list = List_adp_.New();
|
||||
public Xoctg_catpage_grp(byte tid) {this.tid = tid;}
|
||||
public byte Tid() {return tid;} private byte tid; // subc|page|file
|
||||
public int Bgn() {return bgn;} private int bgn;
|
||||
public int End() {return end;} private int end;
|
||||
public int Len() {return end - bgn;}
|
||||
public int Total() {return total;} private int total;
|
||||
public byte Tid() {return tid;} private byte tid; // subc|page|file
|
||||
public int Bgn() {return bgn;} private int bgn; // idx of 1st item; EX: 200
|
||||
public int End() {return end;} private int end; // idx of nth item + 1; EX: 399
|
||||
public int Count_by_page() {return end - bgn;} // count of items on page; EX: 200
|
||||
public int Itms__len() {return itms_len;} private int itms_len; // count of items in entire category; EX: 456
|
||||
public Xoctg_catpage_itm[] Itms() {return itms;} private Xoctg_catpage_itm[] itms = Xoctg_catpage_itm.Ary_empty;
|
||||
public byte[] Itms__nth_sortkey() {return itms__nth_sortkey;}
|
||||
public Xoctg_catpage_itm Itms__get_at_0th() {return Itms__get_at(0);}
|
||||
public Xoctg_catpage_itm Itms__get_at_nth() {return Itms__get_at(itms.length - 1);}
|
||||
private Xoctg_catpage_itm Itms__get_at(int i) {
|
||||
if (i < 0 || i >= itms.length) throw Err_.new_wo_type("ctg.view: i is out of bounds", "i", i, "len", itms.length, "tid", tid);
|
||||
public Xoctg_catpage_itm Itms__get_at(int i) {
|
||||
if (i < 0 || i >= itms.length) throw Err_.new_wo_type("catpage: i is out of bounds", "i", i, "len", itms.length, "tid", tid);
|
||||
Xoctg_catpage_itm rv = itms[i]; if (rv == null) throw Err_.new_wo_type("ctg.view: itm is null", "i", i, "len", itms.length, "tid", tid);
|
||||
return rv;
|
||||
}
|
||||
public void Itms__add(Xoctg_catpage_itm sub) {tmp_list.Add(sub);}
|
||||
public void Itms__make() {
|
||||
itms = (Xoctg_catpage_itm[])tmp_list.To_ary(Xoctg_catpage_itm.class);
|
||||
total = end = itms.length;
|
||||
tmp_list.Sort_by(Xoctg_catpage_itm_sorter__sort_key.Sorter);
|
||||
itms = (Xoctg_catpage_itm[])tmp_list.To_ary_and_clear(Xoctg_catpage_itm.class);
|
||||
bgn = 0;
|
||||
end = itms_len = itms.length;
|
||||
}
|
||||
public void Rng_(int bgn, int end) {
|
||||
this.bgn = bgn; this.end = end;
|
||||
}
|
||||
public Xoctg_catpage_grp Itms__nth_sortkey_(byte[] v) {itms__nth_sortkey = v; return this;} private byte[] itms__nth_sortkey;
|
||||
|
||||
public void Init(int bgn, int end) {this.bgn = bgn; this.end = end;} // TEST:
|
||||
public List_adp Itms_list() {return tmp_list;} private final List_adp tmp_list = List_adp_.New(); // TEST
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_itm implements gplx.CompareAble {
|
||||
public class Xoctg_catpage_itm {
|
||||
public Xoctg_catpage_itm(int page_id, Xoa_ttl page_ttl, byte[] sort_key) {
|
||||
this.page_id = page_id;
|
||||
this.page_ttl = page_ttl;
|
||||
@@ -28,6 +28,5 @@ public class Xoctg_catpage_itm implements gplx.CompareAble {
|
||||
public boolean Missing() {return missing;} private boolean missing; // not used; remove?;
|
||||
public void Missing_y_() {missing = true;}
|
||||
|
||||
public int compareTo(Object obj) {Xoctg_catpage_itm comp = (Xoctg_catpage_itm)obj; return Int_.Compare(page_id, comp.Page_id());}
|
||||
public static final Xoctg_catpage_itm[] Ary_empty = new Xoctg_catpage_itm[0];
|
||||
}
|
||||
|
||||
@@ -15,13 +15,16 @@ GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
class Xoctg_catpage_itm_sorter implements gplx.core.lists.ComparerAble {
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
public class Xoctg_catpage_itm_sorter__sort_key implements gplx.core.lists.ComparerAble, gplx.core.lists.binary_searches.Binary_comparer {
|
||||
public int compare(Object lhsObj, Object rhsObj) {
|
||||
Xoctg_catpage_itm lhs = (Xoctg_catpage_itm)lhsObj;
|
||||
Xoctg_catpage_itm rhs = (Xoctg_catpage_itm)rhsObj;
|
||||
return Bry_.Compare(lhs.Sort_key(), rhs.Sort_key());
|
||||
}
|
||||
public static final Xoctg_catpage_itm_sorter Sorter = new Xoctg_catpage_itm_sorter();
|
||||
public int Compare_val_to_obj(Object val, Object obj) {
|
||||
Xoctg_catpage_itm itm = (Xoctg_catpage_itm)obj;
|
||||
return Bry_.Compare((byte[])val, itm.Sort_key());
|
||||
}
|
||||
public static final Xoctg_catpage_itm_sorter__sort_key Sorter = new Xoctg_catpage_itm_sorter__sort_key();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.fmts; import gplx.*; import gplx.xowa.*; import gplx.xowa.addons.*; import gplx.xowa.addons.wikis.*; import gplx.xowa.addons.wikis.ctgs.*; import gplx.xowa.addons.wikis.ctgs.htmls.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.htmls.core.htmls.*; import gplx.langs.htmls.encoders.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*;
|
||||
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;
|
||||
@@ -32,45 +32,47 @@ public class Xoctg_fmt_grp { // subc|page|file
|
||||
this.url_arg_bgn = url_arg_bgn; this.url_arg_end = url_arg_end; this.div_id = div_id;
|
||||
}
|
||||
public Xoctg_fmt_itm_base Itm_fmt() {return itm_fmt;} private final Xoctg_fmt_itm_base itm_fmt;
|
||||
public void Write_catpage_grp(Bry_bfr bfr, Xow_wiki wiki, Xol_lang_itm lang, Xoctg_catpage_ctg dom_ctg) { // TEST:
|
||||
public void Write_catpage_grp(Bry_bfr bfr, Xow_wiki wiki, Xol_lang_itm lang, Xoctg_catpage_ctg dom_ctg, int grp_max) { // TEST:
|
||||
Xoctg_catpage_grp dom_grp = dom_ctg.Grp_by_tid(tid);
|
||||
if (dom_grp.Itms().length == 0) return; // no items in grp; EX: 0 items in File
|
||||
if (dom_grp.Itms__len() == 0) return; // no items in grp; EX: 0 items in File
|
||||
|
||||
// get msgs
|
||||
Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
byte[] msg_label_bry = msg_mgr.Val_by_id_args(msg_label_id, dom_ctg.Name());
|
||||
byte[] msg_stats_bry = msg_mgr.Val_by_id_args(msg_stats_id, dom_grp.Len(), dom_grp.Total());
|
||||
byte[] msg_stats_bry = msg_mgr.Val_by_id_args(msg_stats_id, dom_grp.Count_by_page(), dom_grp.Itms__len());
|
||||
|
||||
// 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);
|
||||
byte[] nav_html = this.Bld_bwd_fwd(wiki, ctg_ttl, dom_grp, grp_max);
|
||||
|
||||
// sort; init grp; write
|
||||
Array_.Sort(dom_grp.Itms(), Xoctg_catpage_itm_sorter.Sorter); // NOTE: must assert sorted for v1; PAGE:s.w:Category:Computer_science; DATE:2015-11-22
|
||||
// init grp; write
|
||||
itms_fmt.Init_from_grp(wiki, dom_grp);
|
||||
Fmt__ctg.Bld_many(bfr, div_id, msg_label_bry, msg_stats_bry, nav_html, lang.Key_bry(), lang.Dir_ltr_bry(), itms_fmt);
|
||||
}
|
||||
public byte[] Bld_bwd_fwd(Xow_wiki wiki, Xoa_ttl ttl, Xoctg_catpage_grp view_grp) { // TEST:
|
||||
if (view_grp.Total() < Grp__max) return Bry_.Empty;
|
||||
public byte[] Bld_bwd_fwd(Xow_wiki wiki, Xoa_ttl ttl, Xoctg_catpage_grp view_grp, int grp_max) { // TEST:
|
||||
if (view_grp.Itms__len() < 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, Bool_.N);
|
||||
Html_nav_bry(bfr, wiki, ttl, view_grp, Bool_.Y);
|
||||
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 view_grp, boolean type_is_bgn) {
|
||||
private void Html_nav_bry(Bry_bfr bfr, Xow_wiki wiki, Xoa_ttl ttl, Xoctg_catpage_grp grp, int grp_max, boolean type_is_next) {
|
||||
Bry_bfr href_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
|
||||
// get nav_href; EX:href="/wiki/Category:Ctg_1?pageuntil=A1#mw-pages"
|
||||
wiki.Html__href_wtr().Build_to_bfr(href_bfr, wiki.App(), Xoh_wtr_ctx.Basic, wiki.Domain_bry(), ttl);
|
||||
byte[] arg_idx_lbl = null; byte[] arg_sortkey = null;
|
||||
if (type_is_bgn) {
|
||||
if (type_is_next) {
|
||||
arg_idx_lbl = url_arg_bgn;
|
||||
arg_sortkey = view_grp.Itms__nth_sortkey();
|
||||
if (arg_sortkey == null) arg_sortkey = view_grp.Itms__get_at_nth().Sort_key();
|
||||
|
||||
// get next category after last one on page; needed for "Next 200 (href=Cat_201)"
|
||||
int nxt_idx = grp.End();
|
||||
if (nxt_idx == grp.Itms__len()) --nxt_idx; // if last item, then grp.End() does not exist; just use last one
|
||||
arg_sortkey = grp.Itms__get_at(nxt_idx).Sort_key();
|
||||
}
|
||||
else {
|
||||
arg_idx_lbl = url_arg_end;
|
||||
arg_sortkey = view_grp.Itms__get_at_0th().Sort_key();
|
||||
arg_sortkey = grp.Itms__get_at(grp.Bgn()).Sort_key(); // 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
|
||||
@@ -78,19 +80,20 @@ public class Xoctg_fmt_grp { // subc|page|file
|
||||
byte[] nav_href = href_bfr.To_bry_and_rls();
|
||||
|
||||
// get nav_text
|
||||
int nav_text_id = type_is_bgn ? Xol_msg_itm_.Id_next_results : Xol_msg_itm_.Id_prev_results;
|
||||
byte[] nav_text = wiki.Msg_mgr().Val_by_id_args(nav_text_id, Grp__max); // next 200 / previous 200
|
||||
int nav_text_id = type_is_next ? Xol_msg_itm_.Id_next_results : Xol_msg_itm_.Id_prev_results;
|
||||
byte[] nav_text = wiki.Msg_mgr().Val_by_id_args(nav_text_id, grp_max); // next 200 / previous 200
|
||||
|
||||
// fmt
|
||||
Fmt__nav.Bld_many(bfr, nav_href, ttl.Full_url(), nav_text);
|
||||
// print text if 1st / zth page; else, print html
|
||||
if ( ( type_is_next && grp.Bgn() + grp_max > grp.Itms__len())
|
||||
|| (!type_is_next && grp.Bgn() - grp_max < 0)
|
||||
)
|
||||
Fmt__nav__text.Bld_many(bfr, nav_text);
|
||||
else
|
||||
Fmt__nav__href.Bld_many(bfr, nav_href, ttl.Full_url(), nav_text);
|
||||
}
|
||||
|
||||
public static int Grp__max = 200;
|
||||
private static final Bry_fmt
|
||||
Fmt__nav = Bry_fmt.Auto_nl_skip_last
|
||||
( ""
|
||||
, " (<a href=\"~{nav_href}\" class=\"xowa_nav\" title=\"~{nav_title}\">~{nav_text}</a>)"
|
||||
)
|
||||
Fmt__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}\">"
|
||||
@@ -104,7 +107,7 @@ public class Xoctg_fmt_grp { // subc|page|file
|
||||
, " </div>~{nav_html}"
|
||||
, "</div>"
|
||||
);
|
||||
public static Xoctg_fmt_grp New__subc() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_subc, new Xoctg_fmt_itm_subc(), Xol_msg_itm_.Id_ctg_subc_header, Xol_msg_itm_.Id_ctg_subc_count, Xoctg_catpage_url.Url_arg_subc_bgn, Xoctg_catpage_url.Url_arg_subc_end, Bry_.new_a7("mw-subcategories"));}
|
||||
public static Xoctg_fmt_grp New__page() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_page, new Xoctg_fmt_itm_page(), Xol_msg_itm_.Id_ctg_page_header, Xol_msg_itm_.Id_ctg_page_count, Xoctg_catpage_url.Url_arg_page_bgn, Xoctg_catpage_url.Url_arg_page_end, Bry_.new_a7("mw-pages"));}
|
||||
public static Xoctg_fmt_grp New__file() {return new Xoctg_fmt_grp(Xoa_ctg_mgr.Tid_file, new Xoctg_fmt_itm_file(), Xol_msg_itm_.Id_ctg_file_header, Xol_msg_itm_.Id_ctg_file_count, Xoctg_catpage_url.Url_arg_file_bgn, Xoctg_catpage_url.Url_arg_file_end, Bry_.new_a7("mw-category-media"));}
|
||||
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"));}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract class Xoctg_fmt_itm_base implements gplx.core.brys.Bfr_arg {
|
||||
public int Loop_end_idx() {return loop_end_idx;} private int loop_end_idx;
|
||||
public boolean Loop_ends_at_col() {return loop_ends_at_col;} private boolean loop_ends_at_col;
|
||||
public void Col_end_(int col_bgn, int col_idx) {
|
||||
this.col_end = col_bgn + Calc_col_len(grp.Len(), col_idx, Cols_max);
|
||||
this.col_end = col_bgn + Calc_col_len(grp.Count_by_page(), col_idx, Cols_max);
|
||||
}
|
||||
public void Init_from_ltr(Xow_wiki wiki, Xoctg_catpage_grp grp) {this.wiki = wiki; this.grp = grp;}
|
||||
public void Set_ltr_and_bgn(byte[] ltr_cur, int loop_bgn) {this.ltr_cur = ltr_cur; this.loop_bgn = loop_bgn;}
|
||||
@@ -37,10 +37,10 @@ public abstract class Xoctg_fmt_itm_base implements gplx.core.brys.Bfr_arg {
|
||||
// init vars
|
||||
Xoh_href_parser href_parser = wiki.App().Html__href_parser();
|
||||
Xou_history_mgr history_mgr = wiki.App().User().History_mgr();
|
||||
int len = grp.Len();
|
||||
int grp_end = grp.End();
|
||||
|
||||
// loop over itms;
|
||||
for (int i = loop_bgn; i < len; i++) {
|
||||
for (int i = loop_bgn; i < grp_end; i++) {
|
||||
// reached end of col; exit
|
||||
if (i == col_end) {
|
||||
loop_end_idx = i;
|
||||
@@ -49,7 +49,7 @@ public abstract class Xoctg_fmt_itm_base implements gplx.core.brys.Bfr_arg {
|
||||
}
|
||||
|
||||
// get sortkey
|
||||
Xoctg_catpage_itm itm = grp.Itms()[i];
|
||||
Xoctg_catpage_itm itm = grp.Itms__get_at(i);
|
||||
byte[] itm_sortkey = itm.Sort_key();
|
||||
|
||||
// reached end of ltr; exit
|
||||
@@ -61,7 +61,7 @@ public abstract class Xoctg_fmt_itm_base implements gplx.core.brys.Bfr_arg {
|
||||
|
||||
Bld_html(bfr, wiki, history_mgr, href_parser, itm, itm.Page_ttl());
|
||||
}
|
||||
loop_end_idx = len;
|
||||
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) {
|
||||
|
||||
@@ -32,16 +32,17 @@ public class Xoctg_fmt_ltr implements gplx.core.brys.Bfr_arg { // "A", "B", "C c
|
||||
itm_fmt.Init_from_ltr(wiki, grp);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int itms_len = grp.Len(); if (itms_len == 0) return; // no items; exit
|
||||
|
||||
int itm_idx = grp.Bgn(); // itm idx; EX: idx=201 in len=500
|
||||
int itm_end = grp.End();
|
||||
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 < itms_len) {
|
||||
Xoctg_catpage_itm itm = grp.Itms()[itm_idx];
|
||||
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.Sort_key();
|
||||
|
||||
@@ -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.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;
|
||||
}
|
||||
@@ -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;}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 null;
|
||||
|
||||
// init caturl structs
|
||||
byte[][] keys = new byte[Xoa_ctg_mgr.Tid___max][];
|
||||
boolean[] fwds = new boolean[Xoa_ctg_mgr.Tid___max];
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
|
||||
// loop qargs; EX: "?subcatfrom=B&filefrom=C&pagefrom=D"
|
||||
int len = args.length;
|
||||
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)
|
||||
;
|
||||
}
|
||||
@@ -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.catpages.utls; 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.lists.binary_searches.*;
|
||||
import gplx.xowa.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter {
|
||||
public static void Filter(int limit, Xoctg_catpage_url cat_url, Xoctg_catpage_ctg ctg) {
|
||||
int len = Xoa_ctg_mgr.Tid___max;
|
||||
for (byte i = 0; i < len; ++i) {
|
||||
Filter_by_grp(limit, cat_url, ctg.Grp_by_tid(i));
|
||||
}
|
||||
}
|
||||
private static void Filter_by_grp(int grp_len, Xoctg_catpage_url cat_url, Xoctg_catpage_grp grp) {
|
||||
byte grp_tid = grp.Tid();
|
||||
byte[] grp_key = cat_url.Grp_keys()[grp_tid];
|
||||
|
||||
// dflt to bos; EX: grp_bgn=0 grp_end=200
|
||||
int grp_bgn = 0;
|
||||
int grp_end = grp_bgn + grp_len;
|
||||
|
||||
// key specified; calc new grp_bgn, grp_end
|
||||
if (grp_key != null) {
|
||||
// get idx of key
|
||||
int key_idx = Binary_search_.Search(grp.Itms(), Xoctg_catpage_itm_sorter__sort_key.Sorter, grp_key);
|
||||
|
||||
// if fwd, set grp_bgn to key_idx, and add grp_len
|
||||
if (cat_url.Grp_fwds()[grp_tid]) {
|
||||
grp_bgn = key_idx;
|
||||
grp_end = grp_bgn + grp_len;
|
||||
}
|
||||
// if bwd, set grp_end to key_idx, and subtract grp_len
|
||||
else {
|
||||
grp_end = key_idx;
|
||||
grp_bgn = grp_end - grp_len;
|
||||
|
||||
// assert new grp_bgn is not negative
|
||||
if (grp_bgn < 0) grp_bgn = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// assert new grp_end is not > grp_max; note that this needs to be specified for when grp_key is null and not null
|
||||
int grp_max = grp.Itms__len();
|
||||
if (grp_end > grp_max)
|
||||
grp_end = grp_max;
|
||||
grp.Rng_(grp_bgn, grp_end);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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.utls; 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.addons.wikis.ctgs.htmls.catpages.doms.*; import gplx.xowa.addons.wikis.ctgs.htmls.catpages.urls.*;
|
||||
public class Xoctg_catpage_filter__tst {
|
||||
private final Xoctg_catpage_filter__fxt fxt = new Xoctg_catpage_filter__fxt();
|
||||
private Xoctg_catpage_ctg ctg;
|
||||
@Before public void init() {
|
||||
this.ctg = fxt.Make__ctg(25, 25, 25);
|
||||
}
|
||||
@Test public void Initial() {
|
||||
fxt.Exec__filter(5, "A", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__05() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=05", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 5, 10);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__10() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=10", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 10, 15);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__page__23() {
|
||||
fxt.Exec__filter(5, "A?pagefrom=23", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 23, 25);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Fwd__full__06() {
|
||||
fxt.Exec__filter(5, "A?from=06", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
@Test public void Bwd__page__20() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=20", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 15, 20);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__page__2() {
|
||||
fxt.Exec__filter(5, "A?pageuntil=01", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 0, 1);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 0, 5);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 0, 5);
|
||||
}
|
||||
@Test public void Bwd__full__11() {
|
||||
fxt.Exec__filter(5, "A?until=11", ctg);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__page, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__subc, 6, 11);
|
||||
fxt.Test__cat_grp(ctg, Xoa_ctg_mgr.Tid__file, 6, 11);
|
||||
}
|
||||
}
|
||||
class Xoctg_catpage_filter__fxt {
|
||||
private Xow_url_parser url_parser;
|
||||
public Xoctg_catpage_filter__fxt() {
|
||||
Xoa_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.url_parser = app.User().Wikii().Utl__url_parser();
|
||||
}
|
||||
public Xoctg_catpage_ctg Make__ctg(int subc, int page, int file) {
|
||||
Xoctg_catpage_ctg ctg = new Xoctg_catpage_ctg(Bry_.new_a7("A"));
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__subc, subc);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__page, page);
|
||||
Make__ctg_grp(ctg, Xoa_ctg_mgr.Tid__file, file);
|
||||
return ctg;
|
||||
}
|
||||
private void Make__ctg_grp(Xoctg_catpage_ctg ctg, byte tid, int count) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(i * tid, Xoa_ttl.Null, Bry_.new_a7(Int_.To_str_pad_bgn_zero(i, 2)));
|
||||
grp.Itms__add(itm);
|
||||
}
|
||||
grp.Itms__make();
|
||||
}
|
||||
public void Exec__filter(int limit, String cat_url_str, Xoctg_catpage_ctg ctg) {
|
||||
Xoctg_catpage_url cat_url = Xoctg_catpage_url_parser.Parse(url_parser.Parse(Bry_.new_a7(cat_url_str)));
|
||||
Xoctg_catpage_filter.Filter(limit, cat_url, ctg);
|
||||
}
|
||||
public void Test__cat_grp(Xoctg_catpage_ctg ctg, byte tid, int expd_bgn, int expd_end) {
|
||||
Xoctg_catpage_grp grp = ctg.Grp_by_tid(tid);
|
||||
Gftest.Eq__int(expd_bgn, grp.Bgn(), "bgn failed; tid={0}", tid);
|
||||
Gftest.Eq__int(expd_end, grp.End(), "end failed; tid={0}", tid);
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,11 @@ 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.*;
|
||||
package gplx.xowa.addons.wikis.ctgs.htmls.catpages.utls; 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.*;
|
||||
class Xoctg_catpage_loader {
|
||||
public class Xoctg_catpage_loader {
|
||||
private static final Object thread_lock = new Object();
|
||||
public Xoctg_catpage_ctg Load_by_ttl_or_null(Xow_wiki wiki, Xoa_ttl cat_ttl) {
|
||||
// get cat_id for cat_ttl from page_tbl
|
||||
Xow_db_mgr db_mgr = wiki.Data__core_mgr();
|
||||
@@ -34,7 +35,7 @@ class Xoctg_catpage_loader {
|
||||
int cat_id = page_itm.Id();
|
||||
Xowd_category_itm cat_core_itm = cat_core_tbl.Select(cat_id);
|
||||
if (cat_core_itm == Xowd_category_itm.Null) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "category does not exist in cat_core table; ttl=~{0}", cat_ttl.Full_db());
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -72,21 +73,23 @@ class Xoctg_catpage_loader {
|
||||
// prep sql
|
||||
Db_attach_mgr attach_mgr = new Db_attach_mgr(cat_link_conn, new Db_attach_itm("page_db", page_conn), new Db_attach_itm("cat_core_db", cat_core_conn));
|
||||
sql = attach_mgr.Resolve_sql(sql);
|
||||
attach_mgr.Attach();
|
||||
|
||||
// run sql and create itms based on cat_link
|
||||
Db_rdr rdr = Db_rdr_.Empty;
|
||||
try {
|
||||
rdr = cat_link_conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(rdr.Read_int("cl_from"), page_ttl, Bry_.new_u8(rdr.Read_str("cl_sortkey")));
|
||||
rv.Grp_by_tid(rdr.Read_byte("cl_type_id")).Itms__add(itm);
|
||||
synchronized (thread_lock) { // LOCK:used by multiple wrks; DATE:2016-09-12
|
||||
try {
|
||||
attach_mgr.Attach();
|
||||
rdr = cat_link_conn.Stmt_sql(sql).Exec_select__rls_auto();
|
||||
while (rdr.Move_next()) {
|
||||
Xoa_ttl page_ttl = wiki.Ttl_parse(rdr.Read_int("page_namespace"), rdr.Read_bry_by_str("page_title"));
|
||||
Xoctg_catpage_itm itm = new Xoctg_catpage_itm(rdr.Read_int("cl_from"), page_ttl, Bry_.new_u8(rdr.Read_str("cl_sortkey")));
|
||||
rv.Grp_by_tid(rdr.Read_byte("cl_type_id")).Itms__add(itm);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
attach_mgr.Detach();
|
||||
}
|
||||
}
|
||||
private static String Sql_for_v3(int cat_id) {
|
||||
@@ -23,7 +23,7 @@ class Xoctg_pagebox_hash {
|
||||
public int Len() {return hash_by_ttl.Len();}
|
||||
public Xoctg_pagebox_itm Get_at(int i) {return (Xoctg_pagebox_itm)hash_by_ttl.Get_at(i);}
|
||||
public Xoctg_pagebox_itm Get_by_ttl(byte[] full_db) {return (Xoctg_pagebox_itm)hash_by_ttl.Get_by(full_db);}
|
||||
public Xoctg_pagebox_itm Get_by_id(int page_id) {return (Xoctg_pagebox_itm)hash_by_id.Get_by(page_id);}
|
||||
public Xoctg_pagebox_itm 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);
|
||||
|
||||
Reference in New Issue
Block a user