mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v2.11.1.1
This commit is contained in:
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.net.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xop_link_parser {
|
||||
public byte[] Html_xowa_ttl() {return html_xowa_ttl;} private byte[] html_xowa_ttl;
|
||||
public byte Html_anchor_cls() {return html_anchor_cls;} private byte html_anchor_cls;
|
||||
@@ -52,7 +52,7 @@ public class Xop_link_parser {
|
||||
int proto_len = tmp_url.Protocol_bry().length;
|
||||
if (proto_len + 1 < raw_len && raw[proto_len + 1] == Byte_ascii.Slash) { // next char is slash, assume xfer_itm refers to protocol; EX: file:///C/A.png
|
||||
int slash_pos = Bry_find_.Find_bwd(raw, Byte_ascii.Slash);
|
||||
if (slash_pos != Bry_.NotFound) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
|
||||
if (slash_pos != Bry_find_.Not_found) // set xowa_title to file_name; TODO: call Xoa_url.build; note that this will fail sometimes when (a) xfer_itm is very long (File:ReallyLongName will be shortened to 128 chars) or (b) xfer_itm has invalid windows characters (EX:File:a"b"c.jpg)
|
||||
html_xowa_ttl = Bry_.Mid(raw, slash_pos + Int_.Const_dlm_len, raw.length);
|
||||
}
|
||||
else // next char is not slash; assume xfer_itm refers to ns; EX:File:A.png
|
||||
|
||||
@@ -16,6 +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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.core.log_msgs.*;
|
||||
public class Xop_lnki_log {
|
||||
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "lnki");
|
||||
public static final Gfo_msg_itm
|
||||
|
||||
@@ -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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.lnkis.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
import gplx.xowa.files.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*; import gplx.xowa.xtns.pfuncs.ttls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
@@ -24,7 +24,7 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
public void Tkn_tid_to_txt() {tkn_tid = Xop_tkn_itm_.Tid_txt;}
|
||||
public int Ns_id() {return ns_id;} public Xop_lnki_tkn Ns_id_(int v) {ns_id = v; return this;} private int ns_id;
|
||||
public Xoa_ttl Ttl() {return ttl;} public Xop_lnki_tkn Ttl_(Xoa_ttl v) {ttl = v; return this;} private Xoa_ttl ttl;
|
||||
public byte Lnki_type() {return lnki_type;} public Xop_lnki_tkn Lnki_type_(byte v) {lnki_type = (byte)Bitmask_.Add_int(lnki_type, v); return this;} private byte lnki_type = Xop_lnki_type.Id_null;
|
||||
public byte Lnki_type() {return lnki_type;} private byte lnki_type = Xop_lnki_type.Id_null;
|
||||
public int Tail_bgn() {return tail_bgn;} public Xop_lnki_tkn Tail_bgn_(int v) {tail_bgn = v; return this;} private int tail_bgn = -1;
|
||||
public int Tail_end() {return tail_end;} public Xop_lnki_tkn Tail_end_(int v) {tail_end = v; return this;} private int tail_end = -1;
|
||||
public byte Border() {return border;} public Xop_lnki_tkn Border_(byte v) {border = v; return this;} private byte border = Bool_.__byte;
|
||||
@@ -61,6 +61,11 @@ public class Xop_lnki_tkn extends Xop_tkn_itm_base {
|
||||
|| (ns_id == Xow_ns_.Id_category // a Category only has a target; any caption is ignored; EX: [[Category:a|b], b is ignored
|
||||
&& !ttl.ForceLiteralLink()));
|
||||
}
|
||||
public Xop_lnki_tkn Lnki_type_(byte v) {
|
||||
if (lnki_type == Xop_lnki_type.Id_null) // NOTE:per MW:1.25.2, only use 1st argument of thumb|frame|frameless;/includes/parser/Parser.php; // use first appearing option, discard others.; DATE:2015-11-01
|
||||
lnki_type = v;
|
||||
return this;
|
||||
}
|
||||
public static final double Upright_null = -1;
|
||||
public static final int Width_null = -1, Height_null = -1;
|
||||
}
|
||||
|
||||
@@ -29,27 +29,27 @@ public class Xop_lnki_type {
|
||||
)
|
||||
return true;
|
||||
else if ( Bitmask_.Has_int(id, Id_frame) // [[File:A.png|frame]] -> 400,200 (frame is always default size)
|
||||
|| id == Id_null // [[File:A.png]] -> 400,200 (default to original size)
|
||||
|| id == Id_null // [[File:A.png]] -> 400,200 (default to original size)
|
||||
|| Bitmask_.Has_int(id, Id_none) // TODO: deprecate; NOTE: still used by one test; DATE:2015-08-03
|
||||
)
|
||||
return false;
|
||||
else // should not happen
|
||||
else // should not happen
|
||||
throw Err_.new_unhandled(id);
|
||||
}
|
||||
public static boolean Id_limits_large_size(byte id) {// Linker.php|makeThumbLink2|Do not present an image bigger than the source, for bitmap-style images; assuming original of 400,200
|
||||
public static boolean Id_limits_large_size(byte id) { // Linker.php|makeThumbLink2|Do not present an image bigger than the source, for bitmap-style images; assuming original of 400,200
|
||||
if ( Bitmask_.Has_int(id, Id_thumb) // [[File:A.png|600px|thumb]] -> 400,200
|
||||
|| Bitmask_.Has_int(id, Id_frameless) // [[File:A.png|600px|frameless]] -> 400,200
|
||||
|| Bitmask_.Has_int(id, Id_frame) // [[File:A.png|600px|frame]] -> 400,200 (frame is always default size)
|
||||
)
|
||||
return true;
|
||||
else if ( id == Id_null // [[File:A.png|600px]] -> 600,400; uses orig file of 400,200, but <img> tag src_width / src_height set to 600,400
|
||||
else if ( id == Id_null // [[File:A.png|600px]] -> 600,400; uses orig file of 400,200, but <img> tag src_width / src_height set to 600,400
|
||||
|| Bitmask_.Has_int(id, Id_none) // TODO: deprecate; NOTE: leaving in b/c of above failed-deprecate; DATE:2015-08-03
|
||||
)
|
||||
return false;
|
||||
else // should not happen;
|
||||
else // should not happen;
|
||||
throw Err_.new_unhandled(id);
|
||||
}
|
||||
public static boolean Id_supports_upright(byte id) {// REF:Linker.php|makeImageLink;if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) DATE:2014-05-22
|
||||
public static boolean Id_supports_upright(byte id) { // REF:Linker.php|makeImageLink;if ( isset( $fp['thumbnail'] ) || isset( $fp['manualthumb'] ) || isset( $fp['framed'] ) || isset( $fp['frameless'] ) || !$hp['width'] ) DATE:2014-05-22
|
||||
if ( Bitmask_.Has_int(id, Id_thumb)
|
||||
|| Bitmask_.Has_int(id, Id_frameless)
|
||||
|| Bitmask_.Has_int(id, Id_frame)
|
||||
@@ -59,7 +59,7 @@ public class Xop_lnki_type {
|
||||
|| Bitmask_.Has_int(id, Id_none)
|
||||
)
|
||||
return false;
|
||||
else // should not happen;
|
||||
else // should not happen;
|
||||
throw Err_.new_unhandled(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Xop_lnki_wkr__basic_tst {
|
||||
@Test public void Image() {
|
||||
fxt.Test_parse_page_wiki("[[Image:a]]" , fxt.tkn_lnki_().Ns_id_(Xow_ns_.Id_file).Trg_tkn_(fxt.tkn_arg_val_(fxt.tkn_txt_(2, 7), fxt.tkn_colon_(7), fxt.tkn_txt_(8, 9))));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|border]]" , fxt.tkn_lnki_().Border_(Bool_.Y_byte));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|thumb]]" , fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|left]]" , fxt.tkn_lnki_().HAlign_(Xop_lnki_align_h.Left));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|top]]" , fxt.tkn_lnki_().VAlign_(Xop_lnki_align_v.Top));
|
||||
fxt.Test_parse_page_wiki("[[Image:a|10px]]" , fxt.tkn_lnki_().Width_(10).Height_(-1));
|
||||
|
||||
@@ -69,7 +69,7 @@ public class Xop_lnki_wkr__ctg_tst {
|
||||
, "[[Category:B]]" // category should not show below
|
||||
), String_.Concat_lines_nl_skip_last
|
||||
( "<ul>"
|
||||
, " <li> <a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>"
|
||||
, " <li> <a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>"
|
||||
, " </li>"
|
||||
, "</ul>"
|
||||
, ""
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
|
||||
import org.junit.*;
|
||||
public class Xop_lnki_wkr__frame_tst {
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_n_();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
// PURPOSE:use 1st imgtype param; changed between mw1.22.2 and mw1.25.2 PAGE:he.w:מספן_המודיעין EX: [[File:Osa-I class Project205 DN-SN-84-01770.jpg|thumb|frame|abcde]]
|
||||
@Test public void Use_1st__thumb() {fxt.Test_parse_page_wiki("[[File:A.png|thumb|frame]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_thumb));}
|
||||
@Test public void Use_1st__frame() {fxt.Test_parse_page_wiki("[[File:A.png|frame|thumb]]", fxt.tkn_lnki_().ImgType_(Xop_lnki_type.Id_frame));}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class Xop_lnki_wkr__uncommon_tst {
|
||||
}
|
||||
@Test public void Triple_bracket_with_lnke_lnki() { // PURPOSE: handle [http://a.org [[File:A.png|123px]]]; PAGE:ar.w:محمد DATE:2014-08-20
|
||||
fxt.Test_parse_page_all_str("[http://a.org [[File:A.png|123px]]]"
|
||||
, "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
|
||||
, "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\"><a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xowa_file_img_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/123px.png\" width=\"123\" height=\"0\" /></a></a>"
|
||||
);
|
||||
}
|
||||
@Test public void Multiple_captions() { // PURPOSE: multiple captions should be concatenated (used to only take first); EX:zh.d:维基词典:Unicode字符索引/0000–0FFF; DATE:2014-05-05
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.hdumps.core.*;
|
||||
import gplx.xowa.langs.vnts.*; import gplx.xowa.guis.views.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.htmls.core.makes.imgs.*;
|
||||
import gplx.xowa.parsers.tmpls.*;
|
||||
public class Xog_redlink_mgr implements GfoInvkAble {
|
||||
private Xog_win_itm win; private Xog_html_itm html_itm; private Xowe_wiki wiki; private Xoae_page page;
|
||||
|
||||
@@ -19,7 +19,7 @@ package gplx.xowa.parsers.lnkis.redlinks; import gplx.*; import gplx.xowa.*; imp
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.data.tbls.*; import gplx.xowa.users.*;
|
||||
public class Xopg_redlink_lnki_list {
|
||||
private int lnki_idx = gplx.xowa.htmls.lnkis.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
|
||||
private int lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // NOTE: default to 1, not 0, b/c 0 is ignored by wtr; DATE:2014-10-09
|
||||
public Xopg_redlink_lnki_list(boolean ttl_is_module) { // never redlink in Module ns; particularly since Lua has multi-line comments for [[ ]]
|
||||
this.disabled = ttl_is_module;
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class Xopg_redlink_lnki_list {
|
||||
public int Thread_id() {return thread_id;} private int thread_id = 1;
|
||||
public void Clear() {
|
||||
if (disabled) return;
|
||||
lnki_idx = 0; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0
|
||||
lnki_idx = gplx.xowa.htmls.core.wkrs.lnkis.htmls.Xoh_lnki_wtr.Lnki_id_min; // NOTE: must start at 0, so that ++lnki_idx is > 0; html_wtr checks for > 0
|
||||
lnki_list.Clear();
|
||||
thread_id++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user