If multiple caption arguments, take last, not all of them

v3.3.4
gnosygnu 8 years ago
parent 7fc776aee9
commit 62ff87350b

@ -21,7 +21,7 @@ public class Gfo_script_engine_ {
if (String_.Eq(key, "javascript.java")) return new Gfo_script_engine__javascript();
else if (String_.Eq(key, "lua.luaj")) return new Gfo_script_engine__luaj();
else if (String_.Eq(key, "noop")) return new Gfo_script_engine__noop();
else throw Err_.new_unhandled(key);
else throw Err_.new_unhandled(key);
}
public static Gfo_script_engine New_by_ext(String ext) {
if (String_.Eq(ext, ".js")) return new Gfo_script_engine__javascript();

@ -32,7 +32,7 @@ public class Xoa_app_ {
}
}
public static final String Name = "xowa";
public static final String Version = "3.10.3.1";
public static final String Version = "3.10.3.2";
public static String Build_date = "2012-12-30 00:00:00";
public static String Op_sys_str;
public static String User_agent = "";

@ -36,7 +36,6 @@ public abstract class Xoscript_doc_sect_base {
public void add_html(String pos_str, byte[] html) {
doc.html_by_marker(get_marker_by_pos(Bry_.new_u8(pos_str)), html);
}
// public void add_tag_by_objs(String pos_str, String tag_str, String body, params String[] head_atrs) {
public void add_tag(String pos_str, String tag_str, String body, Object... head_atrs) {
// build tag.bgn; EX: '<tag k1="v1">'
tmp_bfr.Add_byte(Byte_ascii.Angle_bgn);

@ -21,7 +21,7 @@ import gplx.xowa.langs.*; import gplx.xowa.langs.kwds.*;
import gplx.xowa.wikis.nss.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.lnkis.files.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.files.*;
public class Gallery_parser {
public class Gallery_parser {
private Xowe_wiki wiki; private Btrie_slim_mgr trie = Btrie_slim_mgr.ci_u8();
private Gallery_itm cur_itm;
private byte[] src; private int end_pos;
@ -47,13 +47,14 @@ public class Gallery_parser {
this.src = src;
this.cur_pos = content_bgn; this.end_pos = content_end;
cur_itm = new Gallery_itm();
while (cur_pos < end_pos) {
cur_itm.Reset();
caption_bfr.Clear();
byte cur_mode = Parse_itm();
if (cur_itm.Ttl() != null) {
if (caption_bfr.Len() > 0)
cur_itm.Caption_bry_(caption_bfr.To_bry_and_clear_and_trim());
cur_itm.Caption_bry_(Make_caption_bry(caption_bfr, wiki, ctx, caption_bfr.To_bry_and_clear()));
Make_lnki_tkn(mgr, xnde, src);
rv.Add(cur_itm);
cur_itm = new Gallery_itm();
@ -238,6 +239,24 @@ public class Gallery_parser {
trie.Add_obj(itm_bry, trie_ref);
}
}
// MW changed behavior from chaining multiple args to keeping last one; EX: "File:A.png|a|b" -> "b" x> "a|b" PAGE:fr.w:Belgique DATE:2016-10-17 REF: https://github.com/wikimedia/mediawiki/commit/63aeabeff1e098e872cc46f3698c61457e44ba15
private static byte[] Make_caption_bry(Bry_bfr tmp_bfr, Xowe_wiki wiki, Xop_ctx ctx, byte[] src) {
// parse caption to tkns
Xop_root_tkn root = wiki.Parser_mgr().Main().Parse_text_to_wdom(Xop_ctx.New__top(wiki), src, false);
// loop tkns
int subs_len = root.Subs_len();
for (int i = 0; i < subs_len; ++i) {
Xop_tkn_itm sub = root.Subs_get(i);
// pipe resets caption; EX: "a|b" -> "b"
if (sub.Tkn_tid() == Xop_tkn_itm_.Tid_pipe)
tmp_bfr.Clear();
// else, add tkn to caption; note that loop does not recurse through tkn's subtkns; EX: "a|[[b|c]]" -> "text_tkn,lnki_tkn" -> "[[b|c]]"
else
tmp_bfr.Add_mid(root.Data_mid(), sub.Src_bgn(), sub.Src_end());
}
return tmp_bfr.To_bry_and_clear_and_trim();
}
}
/*
SEE:non_ws_pos;

@ -23,7 +23,9 @@ public class Gallery_parser_tst {
@Test public void Ttl_only() {fxt.Test_parse("File:A.png" , fxt.Expd("File:A.png", null, null, null));}
@Test public void Ttl_url_encoded() {fxt.Test_parse("File:A%28b%29.png" , fxt.Expd("File:A(b).png"));} // PURPOSE: handle url-encoded sequences; DATE:2014-01-01
@Test public void Caption_only() {fxt.Test_parse("File:A.png|a" , fxt.Expd("File:A.png", "a" , null, null));}
@Test public void Caption_many() {fxt.Test_parse("File:A.png|a|b" , fxt.Expd("File:A.png", "a|b"));} // NOTE: pipe becomes part of caption (i.e.: doesn't separate into caption / alt)
@Test public void Caption_many() {fxt.Test_parse("File:A.png|a|b" , fxt.Expd("File:A.png", "b"));} // NOTE: keep last pipe
@Test public void Caption_many_lnki1(){fxt.Test_parse("File:A.png|a|[[b|c]]" , fxt.Expd("File:A.png", "[[b|c]]"));} // NOTE: ignore pipe in lnki
@Test public void Caption_many_lnki2(){fxt.Test_parse("File:A.png|[[b|c]]|d" , fxt.Expd("File:A.png", "d"));} // NOTE: ignore pipe in lnki
@Test public void Alt_only() {fxt.Test_parse("File:A.png|alt=a" , fxt.Expd("File:A.png", null, "a" , null));}
@Test public void Link_only() {fxt.Test_parse("File:A.png|link=a" , fxt.Expd("File:A.png", null, null, "a"));}
@Test public void Caption_alt() {fxt.Test_parse("File:A.png|a|alt=b" , fxt.Expd("File:A.png", "a" , "b"));}
@ -31,7 +33,7 @@ public class Gallery_parser_tst {
@Test public void Alt_blank() {fxt.Test_parse("File:A.png|alt=|b" , fxt.Expd("File:A.png", "b" , ""));}
@Test public void Alt_invalid() {fxt.Test_parse("File:A.png|alta=b" , fxt.Expd("File:A.png", "alta=b"));} // NOTE: invalid alt becomes caption
@Test public void Ws() {fxt.Test_parse("File:A.png| alt = b | c" , fxt.Expd("File:A.png", "c" , "b"));}
@Test public void Ws_caption_many() {fxt.Test_parse("File:A.png| a | b | c " , fxt.Expd("File:A.png", "a | b | c"));}
@Test public void Ws_caption_many() {fxt.Test_parse("File:A.png| a | b | c " , fxt.Expd("File:A.png", "c"));}
@Test public void Page_pdf() {fxt.Test_parse("File:A.pdf|page=1 " , fxt.Expd("File:A.pdf", null, null, null, 1));} // pdf parses page=1
@Test public void Page_png() {fxt.Test_parse("File:A.png|page=1 " , fxt.Expd("File:A.png", "page=1", null, null));} // non-pdf treats page=1 as caption
@Test public void Page_invalid() {fxt.Test_parse("|page=1");} // check that null title doesn't fail; DATE:2014-03-21

Loading…
Cancel
Save