mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Xomw: Add minor changes to XomwMessage / XomwLanguage
This commit is contained in:
parent
ea46354cf8
commit
be0d09aaff
@ -17,7 +17,7 @@ package gplx.xowa.parsers.lnkis; import gplx.*; import gplx.xowa.*; import gplx.
|
||||
import org.junit.*;
|
||||
import gplx.xowa.langs.cases.*;
|
||||
public class Xop_lnki_wkr__pre_tst {
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@Before public void init() {fxt.Reset(); fxt.Init_para_y_();} private final Xop_fxt fxt = new Xop_fxt();
|
||||
@After public void term() {fxt.Init_para_n_();}
|
||||
@Test public void Previous_pre() { // PURPOSE: if pre is already in effect, end it; EX: en.b:Knowing_Knoppix/Other_applications
|
||||
fxt.Test_parse_page_all_str(String_.Concat_lines_nl_skip_last
|
||||
@ -88,7 +88,7 @@ public class Xop_lnki_wkr__pre_tst {
|
||||
, ""
|
||||
));
|
||||
}
|
||||
private static final String Html_A_png = String_.Concat_lines_nl_skip_last
|
||||
private static final String Html_A_png = String_.Concat_lines_nl_skip_last
|
||||
( "<div class=\"thumb tright\">"
|
||||
, " <div id=\"xowa_file_div_0\" class=\"thumbinner\" style=\"width:220px;\">"
|
||||
, " <a href=\"/wiki/File:A.png\" class=\"image\" xowa_title=\"A.png\"><img id=\"xoimg_0\" alt=\"\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/220px.png\" width=\"0\" height=\"0\" /></a>"
|
||||
|
@ -29,13 +29,14 @@ public class XomwEnv {
|
||||
public int[] Global__wgThumbLimits = new int[] {120, 150, 180, 200, 250, 300};
|
||||
|
||||
public XomwEnv(Xol_lang_itm xoLang) {
|
||||
XomwLanguage language = new XomwLanguage(xoLang);
|
||||
this.language = new XomwLanguage(xoLang);
|
||||
XomwSiteLookup siteLookup = new XomwXowaSiteLookup();
|
||||
XomwInterwikiLookup interwikiLookup = new XomwInterwikiLookupAdapter(siteLookup);
|
||||
byte[][] localInterwikis = new byte[0][]; // TODO.XO: pass in to XomwEnv or retrieve from datastore
|
||||
this.mediaWikiServices = new XomwMediaWikiServices(this, interwikiLookup, language, localInterwikis);
|
||||
}
|
||||
|
||||
public XomwLanguage Language() {return language;} private final XomwLanguage language;
|
||||
public XomwMagicWordMgr Magic_word_mgr() {return magic_word_mgr;} private final XomwMagicWordMgr magic_word_mgr = new XomwMagicWordMgr();
|
||||
public XomwMessageMgr Message_mgr() {return message_mgr;} private final XomwMessageMgr message_mgr = new XomwMessageMgr();
|
||||
public XomwFileFinder File_finder() {return file_finder;} private XomwFileFinder file_finder = new XomwFileFinderNoop();
|
||||
|
@ -237,13 +237,14 @@ public class XomwMessage {
|
||||
private byte[] message;
|
||||
|
||||
public void CompilerAppeasement() {
|
||||
this.language = null; this.key = null; this.keysToTry = null; this.message = null;
|
||||
this.key = null; this.keysToTry = null; this.message = null;
|
||||
Tfds.Write(interfaceIsUserLang, language, key, keysToTry, format, useDatabase, title, message, listTypeMap, parameters);
|
||||
Tfds.Write(FORMAT_BLOCK_PARSE, FORMAT_ESCAPED, FORMAT_PARSE, FORMAT_PLAIN, FORMAT_TEXT);
|
||||
this.extractParam(null, null, 0);
|
||||
}
|
||||
public XomwMessage(byte[] textBry) {
|
||||
public XomwMessage(byte[] textBry, XomwLanguage language) {
|
||||
this.textBry = textBry;
|
||||
this.language = language;
|
||||
}
|
||||
public byte[] text() {return textBry;} private byte[] textBry;
|
||||
public byte[] escaped() {throw Err_.new_unimplemented();}
|
||||
@ -379,19 +380,19 @@ public class XomwMessage {
|
||||
// wfDeprecated(__METHOD__, '1.29');
|
||||
// return this.format;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the Language of the Message.
|
||||
// *
|
||||
// * @since 1.23
|
||||
// *
|
||||
// * @return Language
|
||||
// */
|
||||
// public function getLanguage() {
|
||||
// // Defaults to false which means current user language
|
||||
// return this.language ?: RequestContext::getMain()->getLanguage();
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the Language of the Message.
|
||||
*
|
||||
* @since 1.23
|
||||
*
|
||||
* @return Language
|
||||
*/
|
||||
public XomwLanguage getLanguage() {
|
||||
// Defaults to false which means current user language
|
||||
return this.language;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Factory function that is just wrapper for the real constructor. It is
|
||||
// * intended to be used instead of the real constructor, because it allows
|
||||
@ -1133,35 +1134,43 @@ public class XomwMessage {
|
||||
private void extractParam(XomwMessageVal rv, Object param, int format) {
|
||||
if (Type_adp_.Implements_intf_obj(param, XomwMessagePrm.class)) {
|
||||
XomwMessagePrm prm = (XomwMessagePrm)param;
|
||||
if (prm.Tid() == XomwMessagePrm.Tid__raw) {
|
||||
rv.Set(PRM_TID_AFTER, ((XomwMessagePrm_raw)prm).raw);
|
||||
}
|
||||
else if (prm.Tid() == XomwMessagePrm.Tid__num) {
|
||||
// Replace number prmsVar always in before step for now.
|
||||
// No support for combined raw and num prmsVar
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatNum($param['num']) ];
|
||||
}
|
||||
// elseif (isset($param['duration'])) {
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatDuration($param['duration']) ];
|
||||
// } elseif (isset($param['expiry'])) {
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatExpiry($param['expiry']) ];
|
||||
// } elseif (isset($param['period'])) {
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatTimePeriod($param['period']) ];
|
||||
// } elseif (isset($param['size'])) {
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatSize($param['size']) ];
|
||||
// } elseif (isset($param['bitrate'])) {
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatBitrate($param['bitrate']) ];
|
||||
// } elseif (isset($param['plaintext'])) {
|
||||
// return [PRM_TID_AFTER, this.formatPlaintext($param['plaintext'], $format) ];
|
||||
// } elseif (isset($param['list'])) {
|
||||
// return this.formatListParam($param['list'], $param['type'], $format);
|
||||
// }
|
||||
else {
|
||||
String warning = "Invalid parameter for message '" + this.getKey() + "': " +
|
||||
prm.toString();
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", warning);
|
||||
switch (prm.Tid()) {
|
||||
case XomwMessagePrm.Tid__raw:
|
||||
rv.Set(PRM_TID_AFTER, ((XomwMessagePrm_raw)prm).raw);
|
||||
break;
|
||||
case XomwMessagePrm.Tid__num:
|
||||
// Replace number prmsVar always in before step for now.
|
||||
// No support for combined raw and num prmsVar
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatNum($param['num']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__duration:
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatDuration($param['duration']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__expiry:
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatExpiry($param['expiry']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__period:
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatTimePeriod($param['period']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__size:
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatSize($param['size']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__bitrate:
|
||||
// return [PRM_TID_BEFORE, this.getLanguage()->formatBitrate($param['bitrate']) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__plaintext:
|
||||
// return [PRM_TID_AFTER, this.formatPlaintext($param['plaintext'], $format) ];
|
||||
break;
|
||||
case XomwMessagePrm.Tid__list:
|
||||
// return this.formatListParam($param['list'], $param['type'], $format);
|
||||
break;
|
||||
default:
|
||||
String warning = "Invalid parameter for message '" + this.getKey() + "': " +
|
||||
prm.toString();
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", warning);
|
||||
|
||||
rv.Set(PRM_TID_BEFORE, Bry_.new_a7("[INVALID]"));
|
||||
rv.Set(PRM_TID_BEFORE, Bry_.new_a7("[INVALID]"));
|
||||
break;
|
||||
}
|
||||
// }
|
||||
// else if ($param instanceof Message) {
|
||||
|
@ -14,10 +14,11 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.xowa.mediawiki.languages.*;
|
||||
public class XomwMessageMgr {
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
public void Add(String key, String val) {
|
||||
hash.Add(key, new XomwMessage(Bry_.new_u8(val)));
|
||||
public void Add(String key, String val, XomwLanguage language) {
|
||||
hash.Add(key, new XomwMessage(Bry_.new_u8(val), language));
|
||||
}
|
||||
public XomwMessage Get_by_str(String key) {return (XomwMessage)hash.Get_by(key);}
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ class Xomw_lnki_wkr__fxt {
|
||||
// env
|
||||
file_finder = new XomwFileFinderMock(parser.Env());
|
||||
env = parser.Env();
|
||||
parser.Env().File_finder_(file_finder);
|
||||
parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_thumbnail"), Bool_.Y, Bry_.Ary("thumb"));
|
||||
parser.Env().Magic_word_mgr().Add(Bry_.new_u8("img_width"), Bool_.Y, Bry_.Ary("$1px"));
|
||||
parser.Env().Message_mgr().Add("thumbnail-more", "enlarge");
|
||||
env.File_finder_(file_finder);
|
||||
env.Magic_word_mgr().Add(Bry_.new_u8("img_thumbnail"), Bool_.Y, Bry_.Ary("thumb"));
|
||||
env.Magic_word_mgr().Add(Bry_.new_u8("img_width"), Bool_.Y, Bry_.Ary("$1px"));
|
||||
env.Message_mgr().Add("thumbnail-more", "enlarge", env.Language());
|
||||
parser.Init_by_wiki(wiki);
|
||||
|
||||
// ctx
|
||||
|
Loading…
Reference in New Issue
Block a user