mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Mw_parse: Add code for imageParams
This commit is contained in:
parent
909c96a1ff
commit
352238a9c5
22
400_xowa/src/gplx/xowa/mws/Xomw_Message.java
Normal file
22
400_xowa/src/gplx/xowa/mws/Xomw_Message.java
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
public class Xomw_Message {
|
||||
public byte[] text() {return null;}
|
||||
public byte[] escaped() {return null;}
|
||||
}
|
@ -27,6 +27,7 @@ import gplx.langs.phps.utls.*;
|
||||
* P7: $html = HtmlArmor::getHtml($text);
|
||||
*/
|
||||
public class Xomw_linker {
|
||||
// private Xomw_parser_env env;
|
||||
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();
|
||||
@ -53,7 +54,8 @@ public class Xomw_linker {
|
||||
public Xomw_linker(Xomw_link_renderer link_renderer) {
|
||||
this.link_renderer = link_renderer;
|
||||
}
|
||||
public void Init_by_wiki(Btrie_slim_mgr trie) {
|
||||
public void Init_by_wiki(Xomw_parser_env env, Btrie_slim_mgr trie) {
|
||||
// this.env = env;
|
||||
this.split_trail_trie = trie;
|
||||
}
|
||||
// Given parameters derived from [[Image:Foo|options...]], generate the
|
||||
@ -360,6 +362,7 @@ public class Xomw_linker {
|
||||
zoom_icon = Bry_.Empty;
|
||||
}
|
||||
else if (thumb == null) {
|
||||
// env.Msg_mgr().Get_by_id().Escaped();
|
||||
// $s .= wfMessage('thumbnail_error', '')->escaped();
|
||||
zoom_icon = Bry_.Empty;
|
||||
}
|
||||
@ -383,6 +386,7 @@ public class Xomw_linker {
|
||||
.Add(Gfh_atr_.Bry__class, Class__internal)
|
||||
// .Add(Gfh_atr_.Bry__title, wfMessage('thumbnail-more')->text())
|
||||
, Bry_.Empty);
|
||||
// env.Message_mgr().Get_by_str("thumbnail-more").text();
|
||||
byte[] zoom_anch = tmp.To_bry_and_clear();
|
||||
html_utl.Raw_element(bfr, Gfh_tag_.Bry__div, tmp_attribs.Clear().Add(Gfh_atr_.Bry__class, Class__magnify), zoom_anch);
|
||||
}
|
||||
@ -635,46 +639,6 @@ public class Xomw_linker {
|
||||
}
|
||||
return split_trail_rv;
|
||||
}
|
||||
// public function getImageParams($handler) {
|
||||
// if ($handler) {
|
||||
// $handlerClass = get_class($handler);
|
||||
// }
|
||||
// else {
|
||||
// $handlerClass = '';
|
||||
// }
|
||||
// if (!isset($this->mImageParams[$handlerClass])) {
|
||||
// Initialise static lists
|
||||
// static $internalParamNames = [
|
||||
// 'horizAlign' => [ 'left', 'right', 'center', 'none' ],
|
||||
// 'vertAlign' => [ 'baseline', 'sub', 'super', 'top', 'text-top', 'middle',
|
||||
// 'bottom', 'text-bottom' ],
|
||||
// 'frame' => [ 'thumbnail', 'manual_thumb', 'framed', 'frameless',
|
||||
// 'upright', 'border', 'link', 'alt', 'class' ],
|
||||
// ];
|
||||
// static $internalParamMap;
|
||||
// if (!$internalParamMap) {
|
||||
// $internalParamMap = [];
|
||||
// foreach ($internalParamNames as $type => $names) {
|
||||
// foreach ($names as $name) {
|
||||
// $magicName = str_replace('-', '_', "img_$name");
|
||||
// $internalParamMap[$magicName] = [ $type, $name ];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Add handler params
|
||||
// $paramMap = $internalParamMap;
|
||||
// if ($handler) {
|
||||
// $handlerParamMap = $handler->getParamMap();
|
||||
// foreach ($handlerParamMap as $magic => $paramName) {
|
||||
// $paramMap[$magic] = [ 'handler', $paramName ];
|
||||
// }
|
||||
// }
|
||||
// $this->mImageParams[$handlerClass] = $paramMap;
|
||||
// $this->mImageParamsMagicArray[$handlerClass] = new MagicWordArray(array_keys($paramMap));
|
||||
// }
|
||||
// return [ $this->mImageParams[$handlerClass], $this->mImageParamsMagicArray[$handlerClass] ];
|
||||
// }
|
||||
// // Make HTML for a thumbnail including image, border and caption
|
||||
// public static function makeThumbLinkObj(Title $title, $file, $label = '', $alt,
|
||||
// $align = 'right', $params = [], $framed = false, $manual_thumb = ""
|
||||
|
@ -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.mws; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.btries.*;
|
||||
import org.junit.*; import gplx.core.tests.*; import gplx.core.btries.*; import gplx.xowa.mws.parsers.*;
|
||||
public class Xomw_linker__split_trail__tst {
|
||||
private final Xomw_linker__split_trail__fxt fxt = new Xomw_linker__split_trail__fxt();
|
||||
@Test public void Basic() {fxt.Test__split_trail("abc def" , "abc" , " def");}
|
||||
@ -29,7 +29,7 @@ class Xomw_linker__split_trail__fxt {
|
||||
String[] ary = new String[] {"a", "b", "c", "d", "e", "f"};
|
||||
for (String itm : ary)
|
||||
trie.Add_str_str(itm, itm);
|
||||
linker.Init_by_wiki(trie);
|
||||
linker.Init_by_wiki(new Xomw_parser_env(), trie);
|
||||
}
|
||||
public void Test__split_trail(String trail_str, String expd_inside, String expd_trail) {
|
||||
byte[][] split_trail = linker.Split_trail(Bry_.new_u8(trail_str));
|
||||
|
22
400_xowa/src/gplx/xowa/mws/Xomw_message_mgr.java
Normal file
22
400_xowa/src/gplx/xowa/mws/Xomw_message_mgr.java
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
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; import gplx.*; import gplx.xowa.*;
|
||||
public class Xomw_message_mgr {
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
public Xomw_Message Get_by_str(String key) {return (Xomw_Message)hash.Get_by(key);}
|
||||
}
|
@ -17,7 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
|
||||
import gplx.xowa.mws.filerepo.file.*;
|
||||
public class Xomw_ImageHandler extends Xomw_MediaHandler { /**
|
||||
public class Xomw_ImageHandler extends Xomw_MediaHandler { public Xomw_ImageHandler(byte[] key) {super(key);}
|
||||
/**
|
||||
* @param File file
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -18,6 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.mws.media; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
|
||||
import gplx.xowa.mws.filerepo.file.*;
|
||||
public class Xomw_MediaHandler {
|
||||
public byte[] Key() {return key;} private byte[] key;
|
||||
public Xomw_MediaHandler(byte[] key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
// static final TRANSFORM_LATER = 1;
|
||||
// static final METADATA_GOOD = true;
|
||||
// static final METADATA_BAD = false;
|
||||
|
@ -74,7 +74,7 @@ public class Xomw_parser {
|
||||
this.magiclinks_wkr = new Xomw_magiclinks_wkr(this, sanitizer, linker, regex_boundary, regex_url);
|
||||
}
|
||||
public void Init_by_wiki(Xowe_wiki wiki) {
|
||||
linker.Init_by_wiki(wiki.Lang().Lnki_trail_mgr().Trie());
|
||||
linker.Init_by_wiki(env, wiki.Lang().Lnki_trail_mgr().Trie());
|
||||
lnke_wkr.Init_by_wiki(protocols_trie, regex_url, regex_space);
|
||||
lnki_wkr.Init_by_wiki(env, wiki);
|
||||
doubleunder_wkr.Init_by_wiki(doubleunder_data, wiki.Lang());
|
||||
|
@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.mws.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mws.*;
|
||||
import gplx.xowa.mws.filerepo.file.*;
|
||||
public class Xomw_parser_env {
|
||||
public Xomw_message_mgr Message_mgr() {return message_mgr;} private final Xomw_message_mgr message_mgr = new Xomw_message_mgr();
|
||||
public Xomw_file_finder File_finder() {return file_finder;} private Xomw_file_finder file_finder = new Xomw_file_finder__noop();
|
||||
|
||||
public Xomw_parser_env File_finder_(Xomw_file_finder v) {file_finder = v; return this;}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.xwikis.*;
|
||||
import gplx.xowa.mws.parsers.*; import gplx.xowa.mws.parsers.quotes.*;
|
||||
import gplx.xowa.mws.htmls.*; import gplx.xowa.mws.linkers.*;
|
||||
import gplx.xowa.mws.utls.*; import gplx.xowa.mws.libs.*;
|
||||
import gplx.xowa.mws.filerepo.file.*;
|
||||
import gplx.xowa.mws.media.*; import gplx.xowa.mws.filerepo.file.*;
|
||||
import gplx.xowa.parsers.uniqs.*;
|
||||
/* TODO.XO
|
||||
* P7: multi-line links; // look at the next 'line' to see if we can close it there
|
||||
@ -53,6 +53,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
private final Xomw_qry_mgr query = new Xomw_qry_mgr();
|
||||
private final Btrie_rv trv = new Btrie_rv();
|
||||
private final List_adp tmp_list = List_adp_.New();
|
||||
// private final Hash_adp mImageParams = Hash_adp_.New();
|
||||
public Xomw_lnki_wkr(Xomw_parser parser, Xomw_link_holders holders, Xomw_link_renderer link_renderer, Btrie_slim_mgr protocols_trie) {
|
||||
this.parser = parser;
|
||||
this.holders = holders;
|
||||
@ -88,10 +89,10 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
|
||||
this.page_title = pctx.Page_title();
|
||||
|
||||
Replace_internal_links(bfr, src, src_bgn, src_end);
|
||||
Replace_internal_links(pctx, bfr, src, src_bgn, src_end);
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-02-02
|
||||
public void Replace_internal_links(Bry_bfr bfr, byte[] src, int src_bgn, int src_end) {
|
||||
public void Replace_internal_links(Xomw_parser_ctx pctx, Bry_bfr bfr, byte[] src, int src_bgn, int src_end) {
|
||||
// XO.MW: regex for tc move to header; e1 and e1_img moved to code
|
||||
// the % is needed to support urlencoded titles as well
|
||||
|
||||
@ -308,7 +309,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// we couldn't find the end of this imageLink, so output it raw
|
||||
// but don't ignore what might be perfectly normal links in the text we've examined
|
||||
Bry_bfr nested = wiki.Utl__bfr_mkr().Get_b128();
|
||||
this.Replace_internal_links(nested, text, 0, text.length);
|
||||
this.Replace_internal_links(pctx, nested, text, 0, text.length);
|
||||
nested.Mkr_rls();
|
||||
bfr.Add(prefix).Add(Bry__wtxt__lnki__bgn).Add(link).Add_byte_pipe().Add(text); // s .= "{prefix}[[link|text";
|
||||
// note: no trail, because without an end, there *is* no trail
|
||||
@ -375,7 +376,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// 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);
|
||||
Make_image(pctx, bfr, nt, text, holders);
|
||||
bfr.Add(trail);
|
||||
continue;
|
||||
}
|
||||
@ -441,7 +442,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, Xomw_link_holders holders) {
|
||||
public void Make_image(Xomw_parser_ctx pctx, 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
|
||||
@ -484,10 +485,14 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// $handler = $file ? $file->getHandler() : false;
|
||||
|
||||
// list($paramMap, $mwArray) = $this->getImageParams($handler);
|
||||
// Xomw_image_params tmp_img_params = new Xomw_image_params();
|
||||
// this.getImageParams(tmp_img_params, handler);
|
||||
// Xomw_param_map paramMap = tmp_img_params.param_map;
|
||||
|
||||
// if (!$file) {
|
||||
// $this->addTrackingCategory('broken-file-category');
|
||||
// }
|
||||
// XO.MW.UNSUPPORTED.TrackingCategory:
|
||||
//if (!$file) {
|
||||
// $this->addTrackingCategory('broken-file-category');
|
||||
//}
|
||||
|
||||
// Process the input parameters
|
||||
byte[] caption = Bry_.Empty;
|
||||
@ -684,6 +689,52 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// $tooltip = Sanitizer::stripAllTags( $tooltip );
|
||||
//
|
||||
// return $tooltip;
|
||||
// }
|
||||
|
||||
// static Xomw_param_list[] internalParamNames;
|
||||
// static Xomw_param_map internalParamMap;
|
||||
// private void getImageParams(Xomw_image_params rv, Xomw_MediaHandler handler) {
|
||||
// byte[] handlerClass = handler.Key();
|
||||
// //XO.MW.SKIP:handled by handler.Key()
|
||||
// //if ($handler) {
|
||||
// // $handlerClass = get_class($handler);
|
||||
// //}
|
||||
// //else {
|
||||
// // $handlerClass = '';
|
||||
// //}
|
||||
// Xomw_param_map rv_map = (Xomw_param_map)mImageParams.Get_by(handler.Key());
|
||||
// if (rv == null) {
|
||||
// // Initialise static lists
|
||||
// if (internalParamNames == null) {
|
||||
// internalParamNames = new Xomw_param_list[]
|
||||
// { Xomw_param_list.New("horizAlign", "left", "right", "center", "none")
|
||||
// , Xomw_param_list.New("vertAlign", "baseline", "sub", "super", "top", "text-top", "middle", "bottom", "text-bottom")
|
||||
// , Xomw_param_list.New("thumbnail", "manual_thumb", "framed", "frameless", "upright", "border", "link", "alt", "class")
|
||||
// };
|
||||
//
|
||||
// internalParamMap = new Xomw_param_map();
|
||||
// byte[] bry_img = Bry_.new_a7("img_");
|
||||
// foreach (Xomw_param_list param_list in internalParamNames) {
|
||||
// byte[] type = param_list.type;
|
||||
// foreach (byte[] name in param_list.names) {
|
||||
// byte[] magic_name = Bry_.Add(bry_img, Bry_.Replace(name, Byte_ascii.Dash, Byte_ascii.Underline));
|
||||
// internalParamMap.Add(magic_name, type, name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Add handler params
|
||||
// Xomw_param_map paramMap = internalParamMap.Clone();
|
||||
// if (handler != null) {
|
||||
//// $handlerParamMap = $handler->getParamMap();
|
||||
//// foreach ($handlerParamMap as $magic => $paramName) {
|
||||
//// $paramMap[$magic] = [ 'handler', $paramName ];
|
||||
//// }
|
||||
// }
|
||||
// this.mImageParams.Add(handlerClass, paramMap);
|
||||
//// $this->mImageParamsMagicArray[$handlerClass] = new MagicWordArray(array_keys($paramMap));
|
||||
// }
|
||||
// rv.param_map = rv_map;
|
||||
// }
|
||||
|
||||
/**
|
||||
@ -773,3 +824,30 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// pipe -> \\|
|
||||
// other chars... -> (.*)
|
||||
}
|
||||
class Xomw_image_params {
|
||||
public Xomw_param_map param_map = null;
|
||||
public Object magicArray = null;
|
||||
}
|
||||
class Xomw_param_map {
|
||||
public void Add(byte[] magic, byte[] type, byte[] name) {
|
||||
}
|
||||
public Xomw_param_map Clone() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class Xomw_param_itm {
|
||||
public byte[] magicName = null;
|
||||
public byte[] type = null;
|
||||
public byte[] name = null;
|
||||
}
|
||||
class Xomw_param_list {
|
||||
public byte[] type;
|
||||
public byte[][] names;
|
||||
|
||||
public static Xomw_param_list New(String type, String... names) {
|
||||
Xomw_param_list rv = new Xomw_param_list();
|
||||
rv.type = Bry_.new_u8(type);
|
||||
rv.names = Bry_.Ary(names);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user