Mw_parse: Implement plain image link

pull/620/head
gnosygnu 7 years ago
parent 911be09aef
commit 42c7bc61fb

@ -27,7 +27,7 @@ import gplx.langs.phps.utls.*;
* P7: $html = HtmlArmor::getHtml($text);
*/
public class Xomw_linker {
private final Bry_bfr tmp = Bry_bfr_.New();
private final Bry_bfr tmp = Bry_bfr_.New(), tmp_2 = Bry_bfr_.New();
private final Linker_rel_splitter splitter = new Linker_rel_splitter();
private final Xomw_html_utl html_utl = new Xomw_html_utl();
private byte[] wg_title = null;
@ -35,8 +35,9 @@ public class Xomw_linker {
private final byte[][] split_trail_rv = new byte[2][];
private Btrie_slim_mgr split_trail_trie;
private final Xomw_atr_mgr tmp_attribs = new Xomw_atr_mgr();
private final Xomw_img_prms params_list = new Xomw_img_prms();
private final Xomw_mto_params params_list = new Xomw_mto_params();
private final Xomw_mto_params mto_params = new Xomw_mto_params();
private static final byte[] Atr__class = Bry_.new_a7("class"), Atr__rel = Bry_.new_a7("rel"), Atr__href = Bry_.new_a7("href"), Rel__nofollow = Bry_.new_a7("nofollow");
public static final byte[]
Align__frame__center = Bry_.new_a7("center")
@ -190,16 +191,17 @@ public class Xomw_linker {
}
}
boolean thumb = false;
Xomw_mto thumb = new Xomw_mto(file.url);
if (file != null && handler_params.width != -1) {
// Create a resized image, without the additional thumbnail features
// $thumb = $file->transform(handler_params);
}
else {
thumb = false;
thumb = null;
}
if (!thumb) {
byte[] s = null;
if (thumb == null) {
// $s = self::makeBrokenImageLinkObj($title, frame_params['title'], '', '', '', $time == true);
}
else {
@ -213,17 +215,22 @@ public class Xomw_linker {
params_list.img_cls = Xomw_img_prms.Cls_add(params_list.img_cls, Img_class__thumbborder);
}
// $params = self::getImageLinkMTOParams(frame_params, $query, $parser) + $params;
//
// $s = $thumb->toHtml($params);
thumb.To_html(tmp, tmp_2, params_list);
s = tmp.To_bry_and_clear();
}
if (frame_params.align != Bry_.Empty) {
tmp.Add_str_a7("<div class=\"float").Add(frame_params.align).Add_str_a7("\">{$s}</div>");
tmp.Add_str_a7("<div class=\"float").Add(frame_params.align);
tmp.Add(s);
tmp.Add_str_a7("\">");
tmp.Add_str_a7("</div>");
s = tmp.To_bry_and_clear();
}
// XO.MW: "str_replace("\n", ' ', prefix . $s . postfix);"
int rv_bgn = bfr.Len();
bfr.Add(prefix);
bfr.Add_bfr_and_clear(tmp);
bfr.Add(s);
bfr.Add(postfix);
Bry_.Replace_all_direct(bfr.Bfr(), Byte_ascii.Nl, Byte_ascii.Space, rv_bgn, bfr.Len());
}
@ -281,10 +288,10 @@ public class Xomw_linker {
// Reduce width for upright images when parameter 'upright' is used
handler_params.width = frame_params.upright != -1 ? 130 : 180;
}
Xomw_mto thumb = null;
boolean no_scale = false;
boolean manual_thumb = false;
Xomw_mto thumb = null;
int outer_width = 0;
if (!exists) {
outer_width = handler_params.width + 2;
@ -305,8 +312,8 @@ public class Xomw_linker {
}
else if (frame_params.framed != null) {
// Use image dimensions, don't scale
thumb = new Xomw_mto();
// thumb = $file->getUnscaledThumb(handler_params);
thumb = new Xomw_mto(file.url);
no_scale = true;
}
else {

@ -23,7 +23,7 @@ public class Xomw_xml {
// characters (<, >, &) are escaped but illegals are not touched.
// ARGS: contents defaults to ""
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Element(Bry_bfr bfr, byte[] element, Ordered_hash attribs, byte[] contents, boolean allow_short_tag) {
public static void Element(Bry_bfr bfr, byte[] element, List_adp attribs, byte[] contents, boolean allow_short_tag) {
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(element);
if (attribs.Len() > 0) {
Expand_attributes(bfr, attribs);
@ -48,7 +48,7 @@ public class Xomw_xml {
// Return null if no attributes given.
// @param array $attribs Array of attributes for an XML element
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Expand_attributes(Bry_bfr bfr, Ordered_hash attribs) {
public static void Expand_attributes(Bry_bfr bfr, List_adp attribs) {
int attribs_len = attribs.Len();
for (int i = 0; i < attribs_len; i += 2) {
// XO.MW: $out .= " {$name}=\"" . Sanitizer::encodeAttribute( $val ) . '"';
@ -62,7 +62,7 @@ public class Xomw_xml {
// This opens an XML element
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Open_element(Bry_bfr bfr, byte[] element, Ordered_hash attribs) {
public static void Open_element(Bry_bfr bfr, byte[] element, List_adp attribs) {
bfr.Add_byte(Byte_ascii.Angle_bgn).Add(element);
Expand_attributes(bfr, attribs);
bfr.Add_byte(Byte_ascii.Angle_end);
@ -77,7 +77,7 @@ public class Xomw_xml {
// Same as Xml::element(), but does not escape contents. Handy when the
// content you have is already valid xml.
// XO.MW:SYNC:1.29; DATE:2017-02-03
public static void Tags(Bry_bfr bfr, byte[] element, Ordered_hash attribs, byte[] contents) {
public static void Tags(Bry_bfr bfr, byte[] element, List_adp attribs, byte[] contents) {
Open_element(bfr, element, attribs);
bfr.Add(contents);
bfr.Add_byte(Byte_ascii.Angle_bgn).Add_byte(Byte_ascii.Slash).Add(element).Add_byte(Byte_ascii.Angle_end);

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.filerepos.files; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.filerepos.*;
public class Xomw_file {
public byte[] url;
public boolean Allow_inline_display() {
return true;
}

@ -20,8 +20,11 @@ import gplx.langs.htmls.*;
import gplx.langs.phps.utls.*;
public class Xomw_mto {
private int width = -1, height = -1;
private byte[] url = null;
private final Ordered_hash attribs = Ordered_hash_.New_bry(), link_attribs = Ordered_hash_.New_bry();
public byte[] url;
private final List_adp attribs = List_adp_.New(), link_attribs = List_adp_.New();
public Xomw_mto(byte[] url) {
this.url = url;
}
// Return HTML <img ... /> tag for the thumbnail, will include
// width and height attributes and a blank alt text (as required).
@ -57,31 +60,31 @@ public class Xomw_mto {
// byte[] query = options.desc_query;
attribs.Clear();
attribs.Add(Gfh_atr_.Bry__alt, alt);
attribs.Add(Gfh_atr_.Bry__src, url);
attribs.Add_many(Gfh_atr_.Bry__alt, alt);
attribs.Add_many(Gfh_atr_.Bry__src, url);
boolean link_attribs_is_null = false;
if (!Php_utl_.Empty(options.custom_url_link)) {
link_attribs.Clear();
link_attribs.Add(Gfh_atr_.Bry__href, options.custom_url_link);
link_attribs.Add_many(Gfh_atr_.Bry__href, options.custom_url_link);
if (!Php_utl_.Empty(options.title)) {
link_attribs.Add(Gfh_atr_.Bry__title, options.title);
link_attribs.Add_many(Gfh_atr_.Bry__title, options.title);
}
if (Php_utl_.Empty(options.custom_target_link)) {
link_attribs.Add(Gfh_atr_.Bry__target, options.custom_target_link);
link_attribs.Add_many(Gfh_atr_.Bry__target, options.custom_target_link);
}
else if (Php_utl_.Empty(options.parser_extlink_target)) {
link_attribs.Add(Gfh_atr_.Bry__target, options.parser_extlink_target);
link_attribs.Add_many(Gfh_atr_.Bry__target, options.parser_extlink_target);
}
if (Php_utl_.Empty(options.parser_extlink_rel)) {
link_attribs.Add(Gfh_atr_.Bry__rel, options.parser_extlink_rel);
link_attribs.Add_many(Gfh_atr_.Bry__rel, options.parser_extlink_rel);
}
}
else if (!Php_utl_.Empty(options.custom_title_link)) {
// byte[] title = options.custom_title_link;
link_attribs.Clear();
// link_attribs.Add(Gfh_atr_.Bry__href, title.Get_link_url());
// link_attribs.Add_many(Gfh_atr_.Bry__href, title.Get_link_url());
// byte[] options_title = options.title;
// link_attribs.Add(Gfh_atr_.Bry__title, Php_utl_.Empty(options_title) ? title.Get_full_text : options_title;
// link_attribs.Add_many(Gfh_atr_.Bry__title, Php_utl_.Empty(options_title) ? title.Get_full_text : options_title;
}
else if (!Php_utl_.Empty(options.desc_link)) {
// link_attribs = $this->getDescLinkAttribs(
@ -91,30 +94,30 @@ public class Xomw_mto {
}
else if (!Php_utl_.Empty(options.file_link)) {
link_attribs.Clear();
// link_attribs.Add(Gfh_atr_.Bry__href, file.Get_url());
// link_attribs.Add_many(Gfh_atr_.Bry__href, file.Get_url());
}
else {
link_attribs_is_null = true;
if (!Php_utl_.Empty(options.title)) {
attribs.Add(Gfh_atr_.Bry__title, options.title);
attribs.Add_many(Gfh_atr_.Bry__title, options.title);
}
}
if (!Php_utl_.Empty(options.no_dimensions)) {
attribs.Add(Gfh_atr_.Bry__width, Int_.To_bry(width));
attribs.Add(Gfh_atr_.Bry__height, Int_.To_bry(height));
attribs.Add_many(Gfh_atr_.Bry__width, Int_.To_bry(width));
attribs.Add_many(Gfh_atr_.Bry__height, Int_.To_bry(height));
}
if (!Php_utl_.Empty(options.valign)) {
attribs.Add(Gfh_atr_.Bry__style, Bry_.Add(Bry__vertical_align, options.valign));
attribs.Add_many(Gfh_atr_.Bry__style, Bry_.Add(Bry__vertical_align, options.valign));
}
if (!Php_utl_.Empty(options.img_cls)) {
attribs.Add(Gfh_atr_.Bry__class, options.img_cls);
attribs.Add_many(Gfh_atr_.Bry__class, options.img_cls);
}
if (Php_utl_.Is_set(options.override_height)) {
attribs.Add(Gfh_atr_.Bry__class, options.override_height);
attribs.Add_many(Gfh_atr_.Bry__class, options.override_height);
}
if (Php_utl_.Is_set(options.override_width)) {
attribs.Add(Gfh_atr_.Bry__width, options.override_height);
attribs.Add_many(Gfh_atr_.Bry__width, options.override_height);
}
// Additional densities for responsive images, if specified.
@ -130,7 +133,7 @@ public class Xomw_mto {
}
// Wrap some XHTML text in an anchor tag with the given attributes
// XO.MW:SYNC:1.29; DATE:2017-02-03
private void Link_wrap(Bry_bfr bfr, Ordered_hash link_attribs, byte[] contents) {
private void Link_wrap(Bry_bfr bfr, List_adp link_attribs, byte[] contents) {
if (link_attribs != null) {
Xomw_xml.Tags(bfr, Gfh_tag_.Bry__a, link_attribs, contents);
}

@ -353,25 +353,30 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// }
//
if (ns.Id_is_file()) {
// if (!wfIsBadImage(nt->getDBkey(), this->mTitle)) {
// if (wasblank) {
// // if no parameters were passed, text
// // becomes something like "File:Foo.png",
// // which we don't want to pass on to the
// // image generator
// text = '';
// } else {
// // recursively parse links inside the image caption
// // actually, this will parse them in any other parameters, too,
// // but it might be hard to fix that, and it doesn't matter ATM
// boolean is_good_image = !wfIsBadImage(nt->getDBkey(), this->mTitle)
boolean is_good_image = true;
if (is_good_image) {
if (was_blank) {
// if no parameters were passed, text
// becomes something like "File:Foo.png",
// which we don't want to pass on to the
// image generator
text = Bry_.Empty;
}
else {
// recursively parse links inside the image caption
// actually, this will parse them in any other parameters, too,
// but it might be hard to fix that, and it doesn't matter ATM
// text = this->replaceExternalLinks(text);
// holders->merge(this->replaceInternalLinks2(text));
// }
// // cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
// s .= prefix . this->armorLinks(
// this->makeImage(nt, text, holders)) . trail;
// continue;
// }
}
// cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
bfr.Add(prefix);
// Armor_links(Make_image(bfr, nt, text, holders))
Make_image(bfr, nt, text, holders);
bfr.Add(trail);
continue;
}
}
else if (ns.Id_is_ctg()) {
bfr.Trim_end_ws(); // s = rtrim(s . "\n"); // T2087
@ -434,7 +439,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
}
}
}
public void Make_image(Bry_bfr bfr, Xoa_ttl title, byte[] link_args, boolean holders) {
public void Make_image(Bry_bfr bfr, Xoa_ttl title, byte[] link_args, Xomw_link_holders holders) {
// Check if the options text is of the form "options|alt text"
// Options are:
// * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
@ -471,6 +476,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// Fetch and register the file (file title may be different via hooks)
Xomw_file file = new Xomw_file();
file.url = Bry_.new_a7("A.png");
// list($file, $title) = $this->fetchFileAndTitle($title, $options);
// Get parameter map

@ -0,0 +1,26 @@
/*
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.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
import org.junit.*;
public class Xomw_lnki_wkr__file__tst {
private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Plain() {
fxt.Test__to_html("[[File:A.png]]", "<img alt='A.png' src='A.png' />");
}
}

@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.mws.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*; import gplx.xowa.mws.parsers.*;
import org.junit.*;
public class Xomw_lnki_wkr__tst {
public class Xomw_lnki_wkr__text__tst {
private final Xomw_lnki_wkr__fxt fxt = new Xomw_lnki_wkr__fxt();
@Before public void init() {fxt.Clear();}
@Test public void Text() {fxt.Test__parse("a [[A]] z" , "a <!--LINK 0--> z");}
@ -26,7 +26,6 @@ public class Xomw_lnki_wkr__tst {
@Test public void Html__self() {fxt.Test__to_html("[[Page_1]]" , "<strong class='selflink'>Page_1</strong>");}
@Test public void Html__text() {fxt.Test__to_html("[[A]]" , "<a href='/wiki/A' title='A'>A</a>");}
@Test public void Html__capt() {fxt.Test__to_html("[[A|a]]" , "<a href='/wiki/A' title='A'>a</a>");}
// @Test public void Html__file() {fxt.Test__to_html("[[File:A.png|thumb|abc]]" , "<strong class='selflink'>Page_1</strong>");}
}
class Xomw_lnki_wkr__fxt {
private final Xomw_lnki_wkr wkr;
Loading…
Cancel
Save