Category: Group category members under same upper-cased letter [#637]

staging
gnosygnu 5 years ago
parent e0de779e1d
commit 5f1d9c6f15

@ -26,7 +26,7 @@ public class Xoctg_catpage_mgr__basic__tst {
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);
itm.Sortkey_handle_make(Bry_bfr_.New(), fxt.Wiki(), 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
@ -137,7 +137,7 @@ public class Xoctg_catpage_mgr__basic__tst {
}
@Test public void Page_all_cols() {
fxt.Init_itms__pages("A1", "A2", "A3", "B1", "C1");
fxt.Init__grp_max_(6);
fxt.Init__grp_max_(6); // SEE:FOOTNOTE:LT_NOT_LTE DATE:2019-12-14
fxt.Test__html__all(Xoa_ctg_mgr.Tid__page, String_.Concat_lines_nl_skip_last
( ""
, "<div id=\"mw-pages\">"
@ -175,14 +175,14 @@ public class Xoctg_catpage_mgr__basic__tst {
, "</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);
@Test public void Page__numeric() { // PURPOSE: check numeric sorting; 0, 2, 3, 10; not 0, 10, 2, 3; DATE:2016-10-09
fxt.Init_itms__pages("0", "2", "3", "10");
fxt.Init__grp_max_(5); // SEE:FOOTNOTE:LT_NOT_LTE DATE:2019-12-14
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>"
, " <p>The following 4 pages are in this category, out of 4 total.</p>"
, " <div lang=\"en\" dir=\"ltr\" class=\"mw-content-ltr\">"
, " <table style=\"width: 100%;\">"
, " <tr style=\"vertical-align: top;\">"
@ -190,12 +190,13 @@ public class Xoctg_catpage_mgr__basic__tst {
, " <h3>0-9</h3>"
, " <ul>"
, " <li><a href=\"/wiki/0\" title=\"0\">0</a></li>"
, " <li><a href=\"/wiki/2\" title=\"2\">2</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>0-9 cont.</h3>"
, " <ul>"
, " <li><a href=\"/wiki/9\" title=\"9\">9</a></li>"
, " <li><a href=\"/wiki/3\" title=\"3\">3</a></li>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
@ -232,6 +233,39 @@ public class Xoctg_catpage_mgr__basic__tst {
, "</div>"
));
}
@Test public void Mixed_case_titles() {// PURPOSE: titles in mixed-case should sort under same upper-case letter; ISSUE#:637 DATE:2019-12-14
// init main ns to be case-sensitive, so that "A1" and "a2" get sorted into different groups (fr.wikisource)
fxt.Wiki().Ns_mgr().Ns_main().Case_match_(gplx.xowa.wikis.nss.Xow_ns_case_.Tid__all);
// init pages
fxt.Init_itms__pages("A1", "a2");
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 2 pages are in this category, out of 2 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>"
, " </ul>"
, " </td>"
, " <td style=\"width: 33%;\">"
, " <h3>A cont.</h3>" // fails if "a" instead of "A. cont"
, " <ul>"
, " <li><a href=\"/wiki/a2\" title=\"a2\">a2</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
@ -254,7 +288,7 @@ class Xoctg_catpage_mgr_fxt {
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
grp_max = 3; // default to 3 per 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));}
@ -267,7 +301,9 @@ class Xoctg_catpage_mgr_fxt {
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__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) {
@ -281,7 +317,7 @@ class Xoctg_catpage_mgr_fxt {
Xoctg_catpage_itm itm = Xoctg_catpage_itm.New_by_ttl(tid, i, ttl);
tmp.Add(itm);
}
tmp.Make_by_grp(grp);
tmp.Make_by_grp(wiki, grp);
return this;
}
public void Test__html__page(byte tid, byte grp_char_0, String expd) {

@ -55,7 +55,7 @@ class Xoctg_catlink_loader {
// load ns / ttl for each catlink
Xoctg_catpage_grp grp = rv.Grp_by_tid(grp_tid);
grp.Itms_((Xoctg_catpage_itm[])catlink_hash.To_ary_and_clear(Xoctg_catpage_itm.class));
grp.Itms_(wiki, (Xoctg_catpage_itm[])catlink_hash.To_ary_and_clear(Xoctg_catpage_itm.class));
// get zth_itm (for "Next 200" / "Previous 200")
if (catlink_list_len > limit) {
@ -138,7 +138,7 @@ class Xoctg_catlink_loader {
// 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);
zth_itm.Sortkey_handle_make(Bry_bfr_.New(), wiki, 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

@ -28,7 +28,7 @@ public class Xoctg_catpage_grp {
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) {
public void Itms_(Xow_wiki wiki, 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
@ -38,7 +38,7 @@ public class Xoctg_catpage_grp {
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);
prv_sortkey_handle = itm.Sortkey_handle_make(tmp_bfr, wiki, prv_sortkey_handle);
}
}

@ -42,7 +42,7 @@ public class Xoctg_catpage_itm {
// 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) {
public byte[] Sortkey_handle_make(Bry_bfr tmp_bfr, Xow_wiki wiki, 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}}
@ -67,6 +67,7 @@ public class Xoctg_catpage_itm {
}
else {
byte[] sortkey_normalized = Bry_.Replace(sortkey_prefix, Sortkey_prefix_replace__src, Sortkey_prefix_replace__trg);
sortkey_normalized = wiki.Lang().Case_mgr().Case_reuse_1st_upper(sortkey_normalized); // ISSUE#:637
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();

@ -20,15 +20,15 @@ public class Xoctg_catpage_tmp {
List_adp list = Get_by_tid(itm.Grp_tid());
list.Add(itm);
}
public void Make_by_ctg(Xoctg_catpage_ctg ctg) { // TEST:
public void Make_by_ctg(Xow_wiki wiki, Xoctg_catpage_ctg ctg) { // TEST:
for (byte tid = 0; tid < Xoa_ctg_mgr.Tid___max; ++tid)
Make_by_grp(ctg.Grp_by_tid(tid));
Make_by_grp(wiki, ctg.Grp_by_tid(tid));
}
public void Make_by_grp(Xoctg_catpage_grp grp) {
public void Make_by_grp(Xow_wiki wiki, 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));
grp.Itms_(wiki, (Xoctg_catpage_itm[])list.To_ary_and_clear(Xoctg_catpage_itm.class));
}
private List_adp Get_by_tid(byte tid) {
switch (tid) {

@ -48,7 +48,7 @@ public class Xoctg_fmt_grp { // subc|page|file
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;
if (view_grp.Count_all() < grp_max) return Bry_.Empty; // NOTE: must be "<", not "<="; FOOTNOTE:LT_NOT_LTE; DATE:2019-12-14
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);
@ -105,3 +105,21 @@ public class Xoctg_fmt_grp { // subc|page|file
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"));}
}
/*
== LT_NOT_LTE ==
DATE:2019-12-14
Must be <, not <=.
* Intuitively, it seems like it should be <=. For example, 200 <= 200
* However, when there are exactly 200 categories, MediaWiki shows "(previous 200) (next 200)" headers but with no links
* If changed to <=, then the "(previous 200) (next 200)" disappears. This has no meaningful effect, but might as well imitate MW
Tested with following
* en.wikipedia.org/wiki/Category:1603_births
* Also, SQL to find other categories
<pre>
ATTACH 'en.wikipedia.org-core.xowa' AS page_db;
SELECT c.cat_id, c.cat_pages, p.page_title FROM cat_core c JOIN page_db.page p ON c.cat_id = p.page_id WHERE c.cat_pages = 200 LIMIT 10;
</pre>
*/

@ -336,7 +336,7 @@ class Dpl_xnde_fxt {
Xoctg_catpage_itm catpage_itm = Xoctg_catpage_itm.New_by_ttl(tid, page.Id(), ttl);
tmp.Add(catpage_itm);
}
tmp.Make_by_ctg(ctg);
tmp.Make_by_ctg(fxt.Wiki(), ctg);
Xoctg_catpage_mgr catpage_mgr = fxt.Wiki().Ctg__catpage_mgr();
catpage_mgr.Cache__add(Bry_.new_u8("Category:" + ctg_ttl), ctg);
}

Loading…
Cancel
Save