1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2014-09-07 22:38:50 -04:00
parent be63adc5af
commit a022d7f26c
293 changed files with 2546 additions and 1942 deletions

View File

@@ -125,39 +125,41 @@ public class Xop_lnki_arg_parser {
}
public static final byte[] Bry_upright = Bry_.new_utf8_("upright"), Bry_thumbtime = Bry_.new_utf8_("thumbtime");
public static final byte
Tid_unknown = 0, Tid_thumb = 1, Tid_left = 2, Tid_right = 3, Tid_none = 4, Tid_center = 5, Tid_frame = 6, Tid_frameless = 7, Tid_upright = 8, Tid_border = 9
, Tid_alt = 10, Tid_link = 11, Tid_baseline = 12, Tid_sub = 13, Tid_super = 14, Tid_top = 15, Tid_text_top = 16, Tid_middle = 17, Tid_bottom = 18, Tid_text_bottom = 19
, Tid_dim = 20
, Tid_trg = 21, Tid_caption = 22
, Tid_page = 23
, Tid_noplayer = 24, Tid_noicon = 25, Tid_thumbtime = 26
Tid_unknown = 0, Tid_thumb = 1, Tid_left = 2, Tid_right = 3, Tid_none = 4, Tid_center = 5, Tid_frame = 6, Tid_frameless = 7, Tid_upright = 8, Tid_border = 9
, Tid_alt = 10, Tid_link = 11, Tid_baseline = 12, Tid_sub = 13, Tid_super = 14, Tid_top = 15, Tid_text_top = 16, Tid_middle = 17, Tid_bottom = 18, Tid_text_bottom = 19
, Tid_dim = 20
, Tid_trg = 21, Tid_caption = 22
, Tid_page = 23
, Tid_noplayer = 24, Tid_noicon = 25, Tid_thumbtime = 26
, Tid_class = 27
;
private static final byte[] X_bry = Bry_.new_utf8_("x");
private static final byte Key_dim_num = 0, Key_dim_x = 1, Key_dim_px = 2, Key_space = 3;
private static final int[][] Keys_ids = new int[][]
{ new int[] {Xol_kwd_grp_.Id_img_thumbnail , Tid_thumb}
, new int[] {Xol_kwd_grp_.Id_img_manualthumb , Tid_thumb} // RESEARCH: what is manualthumb? 'thumb=$1' vs 'thumb'
, new int[] {Xol_kwd_grp_.Id_img_right , Tid_right}
, new int[] {Xol_kwd_grp_.Id_img_left , Tid_left}
, new int[] {Xol_kwd_grp_.Id_img_none , Tid_none}
, new int[] {Xol_kwd_grp_.Id_img_center , Tid_center}
, new int[] {Xol_kwd_grp_.Id_img_framed , Tid_frame}
, new int[] {Xol_kwd_grp_.Id_img_frameless , Tid_frameless}
, new int[] {Xol_kwd_grp_.Id_img_page , Tid_page} // for pdf
, new int[] {Xol_kwd_grp_.Id_img_upright , Tid_upright}
, new int[] {Xol_kwd_grp_.Id_img_border , Tid_border}
, new int[] {Xol_kwd_grp_.Id_img_baseline , Tid_baseline}
, new int[] {Xol_kwd_grp_.Id_img_sub , Tid_sub}
, new int[] {Xol_kwd_grp_.Id_img_super , Tid_super}
, new int[] {Xol_kwd_grp_.Id_img_top , Tid_top}
, new int[] {Xol_kwd_grp_.Id_img_text_top , Tid_text_top}
, new int[] {Xol_kwd_grp_.Id_img_middle , Tid_middle}
, new int[] {Xol_kwd_grp_.Id_img_bottom , Tid_bottom}
, new int[] {Xol_kwd_grp_.Id_img_text_bottom , Tid_text_bottom}
, new int[] {Xol_kwd_grp_.Id_img_link , Tid_link}
, new int[] {Xol_kwd_grp_.Id_img_alt , Tid_alt}
, new int[] {Xol_kwd_grp_.Id_ogg_noplayer , Tid_noplayer} // RESEARCH: what does noplayer do?; find example
, new int[] {Xol_kwd_grp_.Id_ogg_noicon , Tid_noicon}
, new int[] {Xol_kwd_grp_.Id_ogg_thumbtime , Tid_thumbtime}
{ new int[] {Xol_kwd_grp_.Id_img_thumbnail , Tid_thumb}
, new int[] {Xol_kwd_grp_.Id_img_manualthumb , Tid_thumb} // RESEARCH: what is manualthumb? 'thumb=$1' vs 'thumb'
, new int[] {Xol_kwd_grp_.Id_img_right , Tid_right}
, new int[] {Xol_kwd_grp_.Id_img_left , Tid_left}
, new int[] {Xol_kwd_grp_.Id_img_none , Tid_none}
, new int[] {Xol_kwd_grp_.Id_img_center , Tid_center}
, new int[] {Xol_kwd_grp_.Id_img_framed , Tid_frame}
, new int[] {Xol_kwd_grp_.Id_img_frameless , Tid_frameless}
, new int[] {Xol_kwd_grp_.Id_img_page , Tid_page} // for pdf
, new int[] {Xol_kwd_grp_.Id_img_upright , Tid_upright}
, new int[] {Xol_kwd_grp_.Id_img_border , Tid_border}
, new int[] {Xol_kwd_grp_.Id_img_baseline , Tid_baseline}
, new int[] {Xol_kwd_grp_.Id_img_sub , Tid_sub}
, new int[] {Xol_kwd_grp_.Id_img_super , Tid_super}
, new int[] {Xol_kwd_grp_.Id_img_top , Tid_top}
, new int[] {Xol_kwd_grp_.Id_img_text_top , Tid_text_top}
, new int[] {Xol_kwd_grp_.Id_img_middle , Tid_middle}
, new int[] {Xol_kwd_grp_.Id_img_bottom , Tid_bottom}
, new int[] {Xol_kwd_grp_.Id_img_text_bottom , Tid_text_bottom}
, new int[] {Xol_kwd_grp_.Id_img_link , Tid_link}
, new int[] {Xol_kwd_grp_.Id_img_alt , Tid_alt}
, new int[] {Xol_kwd_grp_.Id_img_class , Tid_class}
, new int[] {Xol_kwd_grp_.Id_ogg_noplayer , Tid_noplayer} // RESEARCH: what does noplayer do?; find example
, new int[] {Xol_kwd_grp_.Id_ogg_noicon , Tid_noicon}
, new int[] {Xol_kwd_grp_.Id_ogg_thumbtime , Tid_thumbtime}
};
}

View File

@@ -29,6 +29,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
public byte Align_v() {return align_v;} public Xop_lnki_tkn Align_v_(byte v) {align_v = v; return this;} private byte align_v = Byte_.MaxValue_127;
public int Lnki_w() {return lnki_w;} public Xop_lnki_tkn Lnki_w_(int v) {lnki_w = v; return this;} int lnki_w = Width_null;
public int Lnki_h() {return lnki_h;} public Xop_lnki_tkn Lnki_h_(int v) {lnki_h = v; return this;} int lnki_h = Height_null;
public byte[] Lnki_cls() {return lnki_cls;} public void Lnki_cls_(byte[] v) {lnki_cls = v;} private byte[] lnki_cls;
public boolean Media_icon() {return media_icon;} public Xop_lnki_tkn Media_icon_n_() {media_icon = false; return this;} private boolean media_icon = true;
public double Upright() {return upright;} public Xop_lnki_tkn Upright_(double v) {upright = v; return this;} double upright = Upright_null;
public double Thumbtime() {return thumbtime;} public Xop_lnki_tkn Thumbtime_(double v) {thumbtime = v; return this;} private double thumbtime = Xof_doc_thumb.Null;

View File

@@ -111,6 +111,7 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
case Xop_lnki_arg_parser.Tid_text_top: lnki.Align_v_(Xop_lnki_align_v.TextTop); break;
case Xop_lnki_arg_parser.Tid_text_bottom: lnki.Align_v_(Xop_lnki_align_v.TextBottom); break;
case Xop_lnki_arg_parser.Tid_baseline: lnki.Align_v_(Xop_lnki_align_v.Baseline); break;
case Xop_lnki_arg_parser.Tid_class: lnki.Lnki_cls_(Xop_lnki_wkr_.Val_extract(src, arg)); break;
case Xop_lnki_arg_parser.Tid_alt: lnki.Alt_tkn_(arg);
lnki.Alt_tkn().Tkn_ini_pos(false, arg.Src_bgn(), arg.Src_end());
break;
@@ -155,7 +156,7 @@ public class Xop_lnki_wkr implements Xop_ctx_wkr, Xop_arg_wkr {
if (number_parser.HasErr())
ctx.Msg_log().Add_itm_none(Xop_lnki_log.Upright_val_is_invalid, src, valTknBgn, valTknEnd);
else
lnki.Upright_(number_parser.AsDec().XtoDouble());
lnki.Upright_(number_parser.AsDec().Xto_double());
}
else // no =; EX: [[Image:a|upright]]
lnki.Upright_(gplx.xowa.files.Xof_img_size.Upright_default_marker);// NOTE: was incorrectly hardcoded as 1; DATE:2014-07-23
@@ -253,6 +254,10 @@ class Xop_lnki_wkr_ {
else
lnki.Page_(number_parser.AsInt());
}
public static byte[] Val_extract(byte[] src, Arg_nde_tkn arg) {
int val_tkn_bgn = arg.Val_tkn().Src_bgn(), val_tkn_end = arg.Val_tkn().Src_end();
return Bry_.Trim(src, val_tkn_bgn, val_tkn_end); // trim trailing space
}
public static void Thumbtime_parse(Xop_ctx ctx, byte[] src, NumberParser number_parser, Xop_lnki_tkn lnki, Arg_nde_tkn arg) {
int val_tkn_bgn = arg.Val_tkn().Src_bgn(), val_tkn_end = arg.Val_tkn().Src_end();
long fracs = TimeSpanAdp_.parse_to_fracs(src, val_tkn_bgn, val_tkn_end, false);

View File

@@ -261,52 +261,6 @@ public class Xop_lnki_wkr__basic_tst {
, ""
));
}
// @Test public void Subpage_parent() { // DISABLED: MW does not allow ../ to go past root; DATE:2014-01-02
// fxt.Page_ttl_("A");
// fxt.Test_parse_page_wiki_str
// ( "[[b/../c]]"
// , "<a href=\"/wiki/C\">c</a>"
// );
// }
@Test public void Subpage_disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]]
fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(false);
fxt.Test_parse_page_all_str("[[/dev/null]]", "<a href=\"/wiki//dev/null\">/dev/null</a>");
fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true);
}
@Test public void Subpage_false_match() {// PAGE:en.w:en.wiktionary.org/wiki/Wiktionary:Requests for cleanup/archive/2006
fxt.Test_parse_page_wiki_str
( "[[.../compare ...]]"
, "<a href=\"/wiki/.../compare_...\">.../compare ...</a>"
);
}
@Test public void Subpage_owner() { // PURPOSE: ../c does "A/c", not "c"; DATE:2014-01-02
fxt.Page_ttl_("A/b");
fxt.Test_parse_page_wiki_str
( "[[../c]]"
, "<a href=\"/wiki/A/c\">A/c</a>"
);
}
@Test public void Subpage_owner_w_slash() { // PURPOSE: ../c/ does "c", not "A/c"; DATE:2014-01-02
fxt.Page_ttl_("A/b");
fxt.Test_parse_page_wiki_str
( "[[../c/]]"
, "<a href=\"/wiki/A/c\">c</a>"
);
}
@Test public void Subpage_slash() { // PURPOSE: /B should show /B, not A/B; DATE:2014-01-02
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/B\">/B</a>"
));
}
@Test public void Subpage_slash_w_slash() { // PURPOSE: /B/ should show B, not /B; DATE:2014-01-02
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B/]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/B\">B</a>"
));
}
@Test public void Xwiki_file() { // PURPOSE: if xwiki and File, ignore xwiki (hackish); DATE:2013-12-22
Reg_xwiki_alias("test", "test.wikimedia.org"); // must register xwiki, else ttl will not parse it
fxt.Wiki().Cfg_parser().Lnki_cfg().Xwiki_repo_mgr().Add_or_mod(Bry_.new_ascii_("test")); // must add to xwiki_repo_mgr

View File

@@ -0,0 +1,68 @@
/*
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; import gplx.*;
import org.junit.*;
public class Xop_lnki_wkr__subpage_tst {
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private Xop_fxt fxt = new Xop_fxt();
@Test public void Disabled() { // PURPOSE: slash being interpreted as subpage; PAGE:en.w:[[/dev/null]]
fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(false);
fxt.Test_parse_page_all_str("[[/dev/null]]", "<a href=\"/wiki//dev/null\">/dev/null</a>");
fxt.Wiki().Ns_mgr().Ids_get_or_null(Xow_ns_.Id_main).Subpages_enabled_(true);
}
@Test public void False_match() {// PAGE:en.w:en.wiktionary.org/wiki/Wiktionary:Requests for cleanup/archive/2006
fxt.Test_parse_page_wiki_str
( "[[.../compare ...]]"
, "<a href=\"/wiki/.../compare_...\">.../compare ...</a>"
);
}
@Test public void Owner() { // PURPOSE: ../c does "A/c", not "c"; DATE:2014-01-02
fxt.Page_ttl_("A/b");
fxt.Test_parse_page_wiki_str
( "[[../c]]"
, "<a href=\"/wiki/A/c\">A/c</a>"
);
}
@Test public void Owner_w_slash() { // PURPOSE: ../c/ does "c", not "A/c"; DATE:2014-01-02
fxt.Page_ttl_("A/b");
fxt.Test_parse_page_wiki_str
( "[[../c/]]"
, "<a href=\"/wiki/A/c\">c</a>"
);
}
@Test public void Slash() { // PURPOSE: /B should show /B, not A/B; DATE:2014-01-02
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/B\">/B</a>"
));
}
@Test public void Slash_w_slash() { // PURPOSE: /B/ should show B, not /B; DATE:2014-01-02
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B/]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/B\">B</a>"
));
}
@Test public void Leaf_w_ncr() { // PURPOSE: /B&#x63; should not encode &#x63; PAGE:en.s:The_English_Constitution_(1894) DATE:2014-09-07
fxt.Page_ttl_("A");
fxt.Test_parse_page_wiki_str
( "[[/B&#x63;|B]]", String_.Concat_lines_nl_skip_last
( "<a href=\"/wiki/A/Bc\">B</a>"
));
}
}