1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

XOMW: Start XomwMessage [#632]

This commit is contained in:
gnosygnu 2020-05-04 08:29:37 -04:00
parent 0d917bccc7
commit f9cf49c160
13 changed files with 2946 additions and 1470 deletions

View File

@ -196,6 +196,7 @@ public class XophpArray implements Bry_bfr_able {
itm += v;
this.Set(idx, itm);
}
public XophpArray Clone() {
XophpArray rv = new XophpArray();
int len = hash.Len();
@ -240,5 +241,23 @@ public class XophpArray implements Bry_bfr_able {
rv.Add(val);
return rv;
}
// REF.PHP:https://www.php.net/manual/en/function.reset.php
private int internalPointerIndex = 0;
private Object internalPointerAdd(int v) {
internalPointerIndex += v;
return internalPointerGetOrNull();
}
private Object internalPointerReset() {
internalPointerIndex = 0;
return internalPointerGetOrNull();
}
private Object internalPointerGetOrNull() {return hash.Len() == 0 ? null : this.Get_at(internalPointerIndex);}
public static Object reset(XophpArray array) {return array.internalPointerReset();}
public static Object current(XophpArray array) {return array.internalPointerGetOrNull();}
public static Object next(XophpArray array) {
return array.internalPointerAdd(1);
}
public static final XophpArray False = null; // handles code like "if ($var === false)" where var is an Object;
}

View File

@ -129,6 +129,16 @@ public class XophpArray_ {
return rv;
}
public static XophpArray array_values(XophpArray array) {
XophpArray rv = XophpArray.New();
int len = array.count();
for (int i = 0; i < len; i++) {
XophpArrayItm itm = array.Get_at_itm(i);
rv.Add(itm.Val());
}
return rv;
}
// DEPRECATE:use XophpArray
public static boolean popBoolOrN(List_adp list) {return Bool_.Cast(List_adp_.Pop_or(list, false));}
public static byte[] popBryOrNull(List_adp list) {return (byte[])List_adp_.Pop_or(list, null);}
@ -151,7 +161,10 @@ public class XophpArray_ {
public static boolean array_key_exists(int key, Ordered_hash array) {return array.Has(key);}
public static boolean array_key_exists(String key, Ordered_hash array) {return array.Has(key);}
public static boolean array_key_exists(byte[] key, Ordered_hash array) {return array.Has(key);}
public static boolean array_is_empty(Ordered_hash array) {
public static boolean empty(Ordered_hash array) {
return array.Len() == 0;
}
public static boolean empty(XophpArray array) {
return array.Len() == 0;
}

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
@ -13,6 +13,9 @@ The terms of each license can be found in the source code repository:
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; import gplx.*; import gplx.xowa.*;
public class XophpInvalidArgumentException extends Err { public XophpInvalidArgumentException(String text) {super(false, "", text, text);}
}
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
public class XophpInvalidArgumentException extends Err {
public XophpInvalidArgumentException(String fmt, Object... args) {
super(true, "", "", String_.Format(fmt, args));
}
}

View File

@ -17,6 +17,7 @@ package gplx.xowa.mediawiki.includes;
import gplx.Gfo_log_;
import gplx.xowa.mediawiki.XomwEnv;
import gplx.xowa.mediawiki.XophpObject_;
import gplx.xowa.mediawiki.XophpString_;
// MW.SRC:1.33.1
@ -1283,7 +1284,7 @@ public class XomwGlobalFunctions {
*
* @see Message::__construct
*/
public static XomwMessage wfMessage(XomwEnv env, String key, String... params) {
public static XomwMessageOld wfMessageOld(XomwEnv env, String key, String... params) {
// $message = new Message($key);
//
// // We call Message::params() to reduce code duplication
@ -1292,7 +1293,17 @@ public class XomwGlobalFunctions {
// }
//
// return $message;
return env.Message_mgr().Get_by_str(key);
return env.Message_mgr().Old_get_by_str(key);
}
public static XomwMessage wfMessage(XomwEnv env, String key, String... params) {
XomwMessage message = new XomwMessage(key);
// We call Message::params() to reduce code duplication
if (XophpObject_.is_true(params)) {
// message.params(...$params);
}
return message;
}
// /**

View File

@ -13,7 +13,8 @@ The terms of each license can be found in the source code repository:
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.*;
package gplx.xowa.mediawiki.includes; import gplx.*;
import gplx.xowa.mediawiki.*;
import gplx.core.btries.*;
import gplx.langs.htmls.*;
import gplx.xowa.mediawiki.includes.xohtml.*; import gplx.xowa.mediawiki.includes.linkers.*; import gplx.xowa.mediawiki.includes.parsers.*;
@ -650,7 +651,7 @@ public class XomwLinker {
, tmp_attribs.Clear()
.Add(Gfh_atr_.Bry__href , url)
.Add(Gfh_atr_.Bry__class, Class__internal)
.Add(Gfh_atr_.Bry__title, XomwGlobalFunctions.wfMessage(env, "thumbnail-more").text())
.Add(Gfh_atr_.Bry__title, XomwGlobalFunctions.wfMessageOld(env, "thumbnail-more").text())
, Bry_.Empty);
byte[] zoom_anch = tmp.To_bry_and_clear();
XomwHtml.rawElement(tmp, htmlTemp, Gfh_tag_.Bry__div, tmp_attribs.Clear().Add(Gfh_atr_.Bry__class, Class__magnify), zoom_anch);

File diff suppressed because it is too large Load Diff

View File

@ -13,12 +13,12 @@ The terms of each license can be found in the source code repository:
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, 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);}
}
package gplx.xowa.mediawiki.includes; import gplx.*;
import gplx.xowa.mediawiki.languages.*;
public class XomwMessageMgr {
private final Hash_adp hash = Hash_adp_.New();
public void Old_add(String key, String val, XomwLanguage language) {
hash.Add(key, new XomwMessageOld(Bry_.new_u8(val), language));
}
public XomwMessageOld Old_get_by_str(String key) {return (XomwMessageOld)hash.Get_by(key);}
}

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,6 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.mediawiki.includes; import gplx.*;
import gplx.xowa.mediawiki.*;
import gplx.xowa.mediawiki.includes.linkers.XomwLinkTarget;
import gplx.xowa.mediawiki.includes.title.*;
/**
* Represents a title within MediaWiki.
@ -558,7 +557,7 @@ public class XomwTitleOld { // implements XomwLinkTarget
* @return Title The new Object
*/
public static XomwTitleOld newMainPage(XomwEnv env) {
XomwTitleOld title = XomwTitleOld.newFromText(env, XomwGlobalFunctions.wfMessage(env, "mainpage").inContentLanguage().text());
XomwTitleOld title = XomwTitleOld.newFromText(env, XomwGlobalFunctions.wfMessageOld(env, "mainpage").inContentLanguage().text());
// Don't give fatal errors if the message is broken
if (title == null) {
title = XomwTitleOld.newFromText(env, Bry_.new_a7("Main Page"));

View File

@ -13,7 +13,11 @@ The terms of each license can be found in the source code repository:
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.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
package gplx.xowa.mediawiki.includes.parsers; import gplx.*;
import gplx.core.primitives.Bool_obj_ref;
import gplx.core.primitives.Int_obj_ref;
import gplx.core.primitives.String_obj_ref;
import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
import gplx.core.btries.*;
import gplx.core.net.*;
import gplx.xowa.mediawiki.includes.content.XomwContent;
@ -4507,20 +4511,20 @@ Tfds.Write(nowiki, isHTML, forceRawInterwiki, isChildObj, isLocalObj, titleText,
* @return array
*/
public static XophpArray statelessFetchTemplate(XomwTitle title, XomwParser parser) { // $parser = false
String text = XophpString_.False;
boolean skip = false;
String_obj_ref text = String_obj_ref.new_(XophpString_.False);
Bool_obj_ref skip = Bool_obj_ref.n_();
XomwTitle finalTitle = title;
XophpArray deps = XophpArray.New();
// Loop to fetch the article, with up to 1 redirect
for (int i = 0; i < 2 && XophpObject_.is_object(title); i++) {
// Give extensions a chance to select the revision instead
int id = XophpInt_.False; // Assume current
// Hooks::run('BeforeParserFetchTemplateAndtitle',
// [ parser, title, &skip, &id ]);
Int_obj_ref id = Int_obj_ref.New(XophpInt_.False); // Assume current
XomwHooks.run("BeforeParserFetchTemplateAndtitle",
XophpArray.New(parser, title, skip, id));
if (skip) {
text = XophpString_.False;
if (skip.Val()) {
text = text.Val_(XophpString_.False);
deps.Add(XophpArray.New()
.Add("title", title)
.Add("page_id", title.getArticleID())
@ -4530,8 +4534,8 @@ Tfds.Write(nowiki, isHTML, forceRawInterwiki, isChildObj, isLocalObj, titleText,
}
// Get the revision
XomwRevision rev = null;
if (XophpInt_.is_true(id)) {
rev = XomwRevision.newFromId(id);
if (XophpInt_.is_true(id.Val())) {
rev = XomwRevision.newFromId(id.Val());
} else if (XophpObject_.is_true(parser)) {
// rev = parser.fetchCurrentRevisionOfTitle(title);
} else {
@ -4539,7 +4543,7 @@ Tfds.Write(nowiki, isHTML, forceRawInterwiki, isChildObj, isLocalObj, titleText,
}
int rev_id = XophpObject_.is_true(rev) ? rev.getId() : 0;
// If there is no current revision, there is no page
if (XophpInt_.is_false(id) && !XophpObject_.is_true(rev)) {
if (XophpInt_.is_false(id.Val()) && !XophpObject_.is_true(rev)) {
// linkCache = MediaWikiServices::getInstance().getLinkCache();
// linkCache.addBadLinkObj(title);
}
@ -4559,12 +4563,12 @@ Tfds.Write(nowiki, isHTML, forceRawInterwiki, isChildObj, isLocalObj, titleText,
XomwContent content;
if (XophpObject_.is_true(rev)) {
content = rev.getContent();
text = XophpObject_.is_true(content) ? content.getWikitextForTransclusion() : null;
text = text.Val_(XophpObject_.is_true(content) ? content.getWikitextForTransclusion() : null);
// Hooks::run('ParserFetchTemplate',
// [ parser, title, rev, &text, &deps ]);
if (XophpString_.is_false(text) || XophpString_.is_null(text)) {
text = XophpString_.False;
XomwHooks.run("ParserFetchTemplate",
XophpArray.New(parser, title, rev, text, deps)); // NOTE: was &deps
if (XophpString_.is_false(text.Val()) || XophpString_.is_null(text.Val())) {
text = text.Val_(XophpString_.False);
break;
}
} else if (title.getNamespace() == XomwDefines.NS_MEDIAWIKI) {

View File

@ -91,7 +91,7 @@ class Xomw_lnki_wkr__fxt {
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());
env.Message_mgr().Old_add("thumbnail-more", "enlarge", env.Language());
parser.Init_by_wiki(wiki);
// ctx

View File

@ -1,19 +1,20 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
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.site; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
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.site; import gplx.*;
import gplx.xowa.mediawiki.*;
import gplx.xowa.mediawiki.includes.libs.*;
/**
* Collection of Site objects.
@ -174,7 +175,7 @@ public class XomwSiteList extends XomwGenericArrayObject { public int Len() {ret
* @return boolean
*/
@Override public boolean isEmpty() {
return XophpArray_.array_is_empty(this.byGlobalId);
return XophpArray_.empty(this.byGlobalId);
}
/**

View File

@ -371,6 +371,24 @@ public class XophpArray__tst {
, XophpArray_.array_filter(array, callbackOwner.NewCallback("array_filter_both"), XophpArray_.ARRAY_FILTER_USE_BOTH)
);
}
@Test public void reset() {
// PHP examples
// Example #1 reset() example
XophpArray array;
array = XophpArray.New("step one", "step two", "step three", "step four");
// by default, the pointer is on the first element
Gftest.Eq__str("step one", (String)XophpArray.current(array));
// skip two steps
XophpArray.next(array);
XophpArray.next(array);
Gftest.Eq__str("step three", (String)XophpArray.current(array));
// reset pointer, start again on step one
XophpArray.reset(array);
Gftest.Eq__str("step one", (String)XophpArray.current(array));
}
}
class XophpArray__fxt {
public XophpArray Make() {return new XophpArray();}