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

Xomw: Add XomwMediaWikiServices to XomwEnv; Add XomwNamespaceHash

This commit is contained in:
gnosygnu 2017-02-26 09:55:57 -05:00
parent a661f90ede
commit 5a6ac3a335
26 changed files with 264 additions and 177 deletions

View File

@ -24,6 +24,10 @@ public class HashByInt {
public int Len() { public int Len() {
return hash.Len(); return hash.Len();
} }
public Object Get_at_or_null(int idx) {
HashByIntItem item = (HashByIntItem)hash.Get_at(idx);
return item.val;
}
public Object Get_by_or_fail(int key) { public Object Get_by_or_fail(int key) {
synchronized (tmp_key) { synchronized (tmp_key) {
HashByIntItem item = (HashByIntItem)hash.Get_by_or_fail(tmp_key.Val_(key)); HashByIntItem item = (HashByIntItem)hash.Get_by_or_fail(tmp_key.Val_(key));

View File

@ -13,9 +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 GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.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; import gplx.*; import gplx.xowa.*;
import gplx.xowa.mediawiki.includes.*;
import gplx.xowa.mediawiki.includes.filerepo.file.*; import gplx.xowa.mediawiki.includes.media.*; import gplx.xowa.mediawiki.includes.filerepo.file.*; import gplx.xowa.mediawiki.includes.media.*;
public class XomwParserEnv { import gplx.xowa.mediawiki.languages.*;
import gplx.xowa.langs.*;
public class XomwEnv {
public byte[] Lang__align_end = Bry_.new_a7("right"); public byte[] Lang__align_end = Bry_.new_a7("right");
public int User__default__thumbsize = 220; public int User__default__thumbsize = 220;
@ -23,10 +26,21 @@ public class XomwParserEnv {
public double Global__wgThumbUpright = .75d; public double Global__wgThumbUpright = .75d;
public int[] Global__wgThumbLimits = new int[] {120, 150, 180, 200, 250, 300}; public int[] Global__wgThumbLimits = new int[] {120, 150, 180, 200, 250, 300};
public XomwEnv(Xol_lang_itm xoLang) {
XomwLanguage language = new XomwLanguage(xoLang);
this.mediaWikiServices = new XomwMediaWikiServices(language);
}
public XomwMagicWordMgr Magic_word_mgr() {return magic_word_mgr;} private final XomwMagicWordMgr magic_word_mgr = new XomwMagicWordMgr(); 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 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(); public XomwFileFinder File_finder() {return file_finder;} private XomwFileFinder file_finder = new XomwFileFinderNoop();
public XomwMediaHandlerFactory MediaHandlerFactory() {return mediaHandlerFactory;} private final XomwMediaHandlerFactory mediaHandlerFactory = new XomwMediaHandlerFactory(); public XomwMediaHandlerFactory MediaHandlerFactory() {return mediaHandlerFactory;} private final XomwMediaHandlerFactory mediaHandlerFactory = new XomwMediaHandlerFactory();
public XomwMediaWikiServices MediaWikiServices() {return mediaWikiServices;} private final XomwMediaWikiServices mediaWikiServices;
public XomwParserEnv File_finder_(XomwFileFinder v) {file_finder = v; return this;} public XomwEnv File_finder_(XomwFileFinder v) {file_finder = v; return this;}
public static XomwEnv NewTest() {return NewTestByApp(Xoa_app_fxt.Make__app__edit());}
public static XomwEnv NewTestByApp(Xoae_app app) {
return new XomwEnv(Xol_lang_itm_.Lang_en_make(app.Lang_mgr()));
}
} }

View File

@ -1375,7 +1375,7 @@ public class XomwGlobalFunctions {
* *
* @see Message::__construct * @see Message::__construct
*/ */
public static XomwMessage wfMessage(XomwParserEnv env, String key) { public static XomwMessage wfMessage(XomwEnv env, String key) {
// function wfMessage($key /*...*/) { // function wfMessage($key /*...*/) {
// $message = new Message($key); // $message = new Message($key);

View File

@ -26,7 +26,7 @@ import gplx.xowa.mediawiki.includes.parsers.lnkis.*;
* P7: $html = HtmlArmor::getHtml($text); * P7: $html = HtmlArmor::getHtml($text);
*/ */
public class XomwLinker { public class XomwLinker {
// private XomwParserEnv env; // private XomwEnv env;
private final Bry_bfr tmp = Bry_bfr_.New(), tmp_2 = 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 Linker_rel_splitter splitter = new Linker_rel_splitter();
private byte[] wg_title = null; private byte[] wg_title = null;
@ -51,7 +51,7 @@ public class XomwLinker {
public XomwLinker(XomwLinkRenderer link_renderer) { public XomwLinker(XomwLinkRenderer link_renderer) {
this.link_renderer = link_renderer; this.link_renderer = link_renderer;
} }
public void Init_by_wiki(XomwParserEnv env, Btrie_slim_mgr trie) { public void Init_by_wiki(XomwEnv env, Btrie_slim_mgr trie) {
// this.env = env; // this.env = env;
this.split_trail_trie = trie; this.split_trail_trie = trie;
} }
@ -331,7 +331,7 @@ public class XomwLinker {
// @since 1.20 // @since 1.20
// @return String HTML for an image, with links, wrappers, etc. // @return String HTML for an image, with links, wrappers, etc.
// XO.MW:SYNC:1.29; DATE:2017-02-08 // XO.MW:SYNC:1.29; DATE:2017-02-08
public void makeImageLink(Bry_bfr bfr, XomwParserEnv env, XomwParserCtx pctx, XomwParserIface parser, XomwTitle title, XomwFile file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query, int widthOption) { public void makeImageLink(Bry_bfr bfr, XomwEnv env, XomwParserCtx pctx, XomwParserIface parser, XomwTitle title, XomwFile file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query, int widthOption) {
// XO.MW.HOOK:ImageBeforeProduceHTML // XO.MW.HOOK:ImageBeforeProduceHTML
if (file != null && !file.allowInlineDisplay()) { if (file != null && !file.allowInlineDisplay()) {
@ -534,7 +534,7 @@ public class XomwLinker {
* @return String * @return String
*/ */
// XO.MW:SYNC:1.29; DATE:2017-02-08 // XO.MW:SYNC:1.29; DATE:2017-02-08
private void makeThumbLink2(Bry_bfr bfr, XomwParserEnv env, XomwParserCtx pctx, XomwTitle title, XomwFile file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query) { private void makeThumbLink2(Bry_bfr bfr, XomwEnv env, XomwParserCtx pctx, XomwTitle title, XomwFile file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query) {
boolean exists = file != null && file.exists(); boolean exists = file != null && file.exists();
int page = handlerParams.page; int page = handlerParams.page;

View File

@ -26,10 +26,14 @@ public class XomwLinker_NormalizeSubpageLinkTest {
@Test public void Dot2__trailing() {fxt.Test__normalize_subpage_link("A/B/C" , "../../Z/" , "" , "A/Z" , "Z");} @Test public void Dot2__trailing() {fxt.Test__normalize_subpage_link("A/B/C" , "../../Z/" , "" , "A/Z" , "Z");}
} }
class XomwLinker_NormalizeSubpageLinkFxt { class XomwLinker_NormalizeSubpageLinkFxt {
private final XomwEnv env;
private final XomwLinker mgr = new XomwLinker(new gplx.xowa.mediawiki.includes.linkers.XomwLinkRenderer(new XomwSanitizer())); private final XomwLinker mgr = new XomwLinker(new gplx.xowa.mediawiki.includes.linkers.XomwLinkRenderer(new XomwSanitizer()));
private final XomwLinker_NormalizeSubpageLink normalize_subpage_link = new XomwLinker_NormalizeSubpageLink(); private final XomwLinker_NormalizeSubpageLink normalize_subpage_link = new XomwLinker_NormalizeSubpageLink();
public XomwLinker_NormalizeSubpageLinkFxt() {
this.env = XomwEnv.NewTest();
}
public void Test__normalize_subpage_link(String page_title_str, String link, String text, String expd_link, String expd_text) { public void Test__normalize_subpage_link(String page_title_str, String link, String text, String expd_link, String expd_text) {
mgr.normalizeSubpageLink(normalize_subpage_link, XomwTitle.newFromText(Bry_.new_u8(page_title_str)), Bry_.new_u8(link), Bry_.new_u8(text)); mgr.normalizeSubpageLink(normalize_subpage_link, XomwTitle.newFromText(env, Bry_.new_u8(page_title_str)), Bry_.new_u8(link), Bry_.new_u8(text));
Gftest.Eq__str(expd_link, String_.new_u8(normalize_subpage_link.link)); Gftest.Eq__str(expd_link, String_.new_u8(normalize_subpage_link.link));
Gftest.Eq__str(expd_text, String_.new_u8(normalize_subpage_link.text)); Gftest.Eq__str(expd_text, String_.new_u8(normalize_subpage_link.text));
} }

View File

@ -27,7 +27,7 @@ class XomwLinker_SplitTrailFxt {
String[] ary = new String[] {"a", "b", "c", "d", "e", "f"}; String[] ary = new String[] {"a", "b", "c", "d", "e", "f"};
for (String itm : ary) for (String itm : ary)
trie.Add_str_str(itm, itm); trie.Add_str_str(itm, itm);
linker.Init_by_wiki(new XomwParserEnv(), trie); linker.Init_by_wiki(XomwEnv.NewTest(), trie);
} }
public void Test__split_trail(String trail_str, String expd_inside, String expd_trail) { public void Test__split_trail(String trail_str, String expd_inside, String expd_trail) {
byte[][] split_trail = linker.splitTrail(Bry_.new_u8(trail_str)); byte[][] split_trail = linker.splitTrail(Bry_.new_u8(trail_str));

View File

@ -30,37 +30,11 @@ import gplx.xowa.mediawiki.includes.title.*;
* MediaWiki code super. * MediaWiki code super.
*/ */
public class XomwMediaWikiServices { public class XomwMediaWikiServices {
/** // XO.MW.SKIP:remove global getInstance(). See XomwEnv
* @var MediaWikiServices|null private final XomwMediaWikiTitleCodec titleParser;
*/
private static XomwMediaWikiServices instance = null;
/** public XomwMediaWikiServices(XomwLanguage language) {
* Returns the global default instance of the top level service locator. this.titleParser = new XomwMediaWikiTitleCodec(language);
*
* @since 1.27
*
* The default instance is initialized using the service instantiator functions
* defined in ServiceWiring.php.
*
* @note This should only be called by static functions! The instance returned here
* should not be passed around! Objects that need access to a service should have
* that service injected into the constructor, never a service locator!
*
* @return MediaWikiServices
*/
public static XomwMediaWikiServices getInstance() {
if (instance == null) {
// NOTE: constructing GlobalVarConfig here is not particularly pretty,
// but some information from the global scope has to be injected here,
// even if it's just a file name or database credentials to load
// configuration from.
// $bootstrapConfig = new GlobalVarConfig();
// self::$instance = self::newInstance($bootstrapConfig, 'load');
instance = new XomwMediaWikiServices();
}
return instance;
} }
// /** // /**
@ -581,7 +555,6 @@ public class XomwMediaWikiServices {
// return $this->getService( 'TitleParser' ); // return $this->getService( 'TitleParser' );
return titleParser; return titleParser;
} }
private XomwMediaWikiTitleCodec titleParser = new XomwMediaWikiTitleCodec(new XomwLanguage());
// /** // /**
// * @since 1.28 // * @since 1.28

View File

@ -14,7 +14,6 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.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.*; import gplx.xowa.mediawiki.*;
import gplx.core.lists.*;
public class XomwNamespace { public class XomwNamespace {
// /** // /**
// * These namespaces should always be first-letter capitalized, now and // * These namespaces should always be first-letter capitalized, now and
@ -189,13 +188,13 @@ public class XomwNamespace {
* @return array * @return array
* @since 1.17 * @since 1.17
*/ */
private static HashByInt namespaces = null; private static XomwNamespaceHash namespaces = null;
public static HashByInt getCanonicalNamespaces() {return getCanonicalNamespaces(false);} public static XomwNamespaceHash getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
public static HashByInt getCanonicalNamespaces(boolean rebuild) { public static XomwNamespaceHash getCanonicalNamespaces(boolean rebuild) {
if (namespaces == null || rebuild) { if (namespaces == null || rebuild) {
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames; // global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone(); namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
namespaces.Add_as_bry(XomwDefines.NS_MAIN, ""); namespaces.Add(XomwDefines.NS_MAIN, "");
// // Add extension namespaces // // Add extension namespaces
// $namespaces += ExtensionRegistry::getInstance()->getAttribute('ExtensionNamespaces'); // $namespaces += ExtensionRegistry::getInstance()->getAttribute('ExtensionNamespaces');
@ -221,29 +220,32 @@ public class XomwNamespace {
// return false; // return false;
// } // }
// } // }
//
// /** /**
// * Returns the index for a given canonical name, or NULL * Returns the index for a given canonical name, or NULL
// * The input *must* be converted to lower case first * The input *must* be converted to lower case first
// * *
// * @param String $name Namespace name * @param String $name Namespace name
// * @return int * @return int
// */ */
// public static function getCanonicalIndex($name) { private static Hash_adp xNamespaces = null;
// static $xNamespaces = false; public static int getCanonicalIndex(byte[] name) {
// if ($xNamespaces == false) { if (xNamespaces == null) {
// $xNamespaces = []; xNamespaces = Hash_adp_bry.cs();
// foreach (self::getCanonicalNamespaces() as $i => $text) { int len = namespaces.Len();
// $xNamespaces[strtolower($text)] = $i; for (int i = 0; i < len; i++) {
// } XomwNamespaceItem item = (XomwNamespaceItem)namespaces.GetItemOrNull(i);
// } xNamespaces.Add(Bry_.Lcase__all(item.text), item); // NOTE: MW does "strtolower($text)"; canonical namespaces are always ascii
}
}
// if (array_key_exists($name, $xNamespaces)) { // if (array_key_exists($name, $xNamespaces)) {
// return $xNamespaces[$name]; // return $xNamespaces[$name];
// } else { // } else {
// return null; // return null;
// } // }
// } return XomwNamespace.NULL_NS_ID;
// }
// /** // /**
// * Returns an array of the namespaces (by integer id) that exist on the // * Returns an array of the namespaces (by integer id) that exist on the
// * wiki. Used primarily by the api in help documentation. // * wiki. Used primarily by the api in help documentation.
@ -496,4 +498,5 @@ public class XomwNamespace {
// //
// return $usableLevels; // return $usableLevels;
// } // }
public static final int NULL_NS_ID = XophpUtility.Null_int;
} }

View File

@ -0,0 +1,37 @@
/*
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
import gplx.core.lists.*;
public class XomwNamespaceHash {
private HashByInt hash = new HashByInt();
public int Len() {return hash.Len();}
public byte[] GetTextOrNull(int id) {
XomwNamespaceItem item = (XomwNamespaceItem)hash.Get_by_or_null(id);
return item == null ? null : item.text;
}
public XomwNamespaceItem GetItemOrNull(int idx) {
return (XomwNamespaceItem)hash.Get_at_or_null(idx);
}
public XomwNamespaceHash Add(int id, String text) {
hash.Add(id, new XomwNamespaceItem(id, Bry_.new_u8(text)));
return this;
}
public XomwNamespaceHash Clone() {
XomwNamespaceHash rv = new XomwNamespaceHash();
rv.hash = hash.Clone();
return rv;
}
}

View File

@ -0,0 +1,24 @@
/*
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; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
public class XomwNamespaceItem {
public final int id;
public final byte[] text;
public XomwNamespaceItem(int id, byte[] text) {
this.id = id;
this.text = text;
}
}

View File

@ -14,7 +14,6 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.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.*; import gplx.xowa.mediawiki.*;
import gplx.core.lists.*;
/** /**
* Include most things that are needed to make MediaWiki work. * Include most things that are needed to make MediaWiki work.
* *
@ -393,24 +392,24 @@ public class XomwSetup {
* Definitions of the NS_ constants are in Defines.php * Definitions of the NS_ constants are in Defines.php
* @private * @private
*/ */
public static HashByInt wgCanonicalNamespaceNames = new HashByInt() public static XomwNamespaceHash wgCanonicalNamespaceNames = new XomwNamespaceHash()
.Add_as_bry(XomwDefines.NS_MEDIA , "Media") .Add(XomwDefines.NS_MEDIA , "Media")
.Add_as_bry(XomwDefines.NS_SPECIAL , "Special") .Add(XomwDefines.NS_SPECIAL , "Special")
.Add_as_bry(XomwDefines.NS_TALK , "Talk") .Add(XomwDefines.NS_TALK , "Talk")
.Add_as_bry(XomwDefines.NS_USER , "User") .Add(XomwDefines.NS_USER , "User")
.Add_as_bry(XomwDefines.NS_USER_TALK , "User_talk") .Add(XomwDefines.NS_USER_TALK , "User_talk")
.Add_as_bry(XomwDefines.NS_PROJECT , "Project") .Add(XomwDefines.NS_PROJECT , "Project")
.Add_as_bry(XomwDefines.NS_PROJECT_TALK , "Project_talk") .Add(XomwDefines.NS_PROJECT_TALK , "Project_talk")
.Add_as_bry(XomwDefines.NS_FILE , "File") .Add(XomwDefines.NS_FILE , "File")
.Add_as_bry(XomwDefines.NS_FILE_TALK , "File_talk") .Add(XomwDefines.NS_FILE_TALK , "File_talk")
.Add_as_bry(XomwDefines.NS_MEDIAWIKI , "MediaWiki") .Add(XomwDefines.NS_MEDIAWIKI , "MediaWiki")
.Add_as_bry(XomwDefines.NS_MEDIAWIKI_TALK , "MediaWiki_talk") .Add(XomwDefines.NS_MEDIAWIKI_TALK , "MediaWiki_talk")
.Add_as_bry(XomwDefines.NS_TEMPLATE , "Template") .Add(XomwDefines.NS_TEMPLATE , "Template")
.Add_as_bry(XomwDefines.NS_TEMPLATE_TALK , "Template_talk") .Add(XomwDefines.NS_TEMPLATE_TALK , "Template_talk")
.Add_as_bry(XomwDefines.NS_HELP , "Help") .Add(XomwDefines.NS_HELP , "Help")
.Add_as_bry(XomwDefines.NS_HELP_TALK , "Help_talk") .Add(XomwDefines.NS_HELP_TALK , "Help_talk")
.Add_as_bry(XomwDefines.NS_CATEGORY , "Category") .Add(XomwDefines.NS_CATEGORY , "Category")
.Add_as_bry(XomwDefines.NS_CATEGORY_TALK , "Category_talk") .Add(XomwDefines.NS_CATEGORY_TALK , "Category_talk")
; ;
// /// @todo UGLY UGLY // /// @todo UGLY UGLY

View File

@ -156,6 +156,7 @@ public class XomwTitle {
// private $mIsBigDeletion = null; // private $mIsBigDeletion = null;
// // @} // // @}
private final XomwEnv env;
/** /**
* B/C kludge: provide a TitleParser for use by Title. * B/C kludge: provide a TitleParser for use by Title.
* Ideally, Title would have no methods that need this. * Ideally, Title would have no methods that need this.
@ -164,9 +165,9 @@ public class XomwTitle {
* *
* @return TitleFormatter * @return TitleFormatter
*/ */
private static XomwMediaWikiTitleCodec getTitleFormatter() { // private static XomwMediaWikiTitleCodec getTitleFormatter() {
return XomwMediaWikiServices.getInstance().getTitleFormatter(); // return XomwMediaWikiServices.getInstance().getTitleFormatter();
} // }
// /** // /**
// * B/C kludge: provide an InterwikiLookup for use by Title. // * B/C kludge: provide an InterwikiLookup for use by Title.
@ -179,13 +180,14 @@ public class XomwTitle {
// private static function getInterwikiLookup() { // private static function getInterwikiLookup() {
// return MediaWikiServices::getInstance().getInterwikiLookup(); // return MediaWikiServices::getInstance().getInterwikiLookup();
// } // }
//
// /** /**
// * @access protected * @access protected
// */ */
// function __construct() { XomwTitle(XomwEnv env) {
// } this.env = env;
// }
// /** // /**
// * Create a new Title from a prefixed DB key // * Create a new Title from a prefixed DB key
// * // *
@ -250,8 +252,8 @@ public class XomwTitle {
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @return Title|null Title or null on an error. * @return Title|null Title or null on an error.
*/ */
public static XomwTitle newFromText(byte[] text) {return newFromText(text, XomwDefines.NS_MAIN);} public static XomwTitle newFromText(XomwEnv env, byte[] text) {return newFromText(env, text, XomwDefines.NS_MAIN);}
public static XomwTitle newFromText(byte[] text, int defaultNamespace) { private static XomwTitle newFromText(XomwEnv env, byte[] text, int defaultNamespace) {
// DWIM: Integers can be passed in here when page titles are used as array keys. // DWIM: Integers can be passed in here when page titles are used as array keys.
// XO.MW.SKIP:STRONGCAST // XO.MW.SKIP:STRONGCAST
// if ($text != null && !is_string($text) && !is_int($text)) { // if ($text != null && !is_string($text) && !is_int($text)) {
@ -262,7 +264,7 @@ public class XomwTitle {
} }
try { try {
return XomwTitle.newFromTextThrow(text, defaultNamespace); return XomwTitle.newFromTextThrow(env, text, defaultNamespace);
} catch (XomwMalformedTitleException ex) { } catch (XomwMalformedTitleException ex) {
Err_.Noop(ex); Err_.Noop(ex);
return null; return null;
@ -283,7 +285,7 @@ public class XomwTitle {
* @throws XomwMalformedTitleException If the title is invalid * @throws XomwMalformedTitleException If the title is invalid
* @return Title * @return Title
*/ */
public static XomwTitle newFromTextThrow(byte[] text, int defaultNamespace) { private static XomwTitle newFromTextThrow(XomwEnv env, byte[] text, int defaultNamespace) {
// if (is_object($text)) { // if (is_object($text)) {
// throw new MWException('$text must be a String, given an Object'); // throw new MWException('$text must be a String, given an Object');
// } // }
@ -306,11 +308,11 @@ public class XomwTitle {
// $filteredText = Sanitizer::decodeCharReferencesAndNormalize($text); // $filteredText = Sanitizer::decodeCharReferencesAndNormalize($text);
byte[] filteredText = text; byte[] filteredText = text;
XomwTitle t = new XomwTitle(); XomwTitle t = new XomwTitle(env);
t.mDbkeyform = XophpString.strtr(filteredText, Byte_ascii.Space, Byte_ascii.Underline); t.mDbkeyform = XophpString.strtr(filteredText, Byte_ascii.Space, Byte_ascii.Underline);
t.mDefaultNamespace = defaultNamespace; t.mDefaultNamespace = defaultNamespace;
t.secureAndSplit(); t.secureAndSplit(env);
// XO.MW.SKIP:CACHE // XO.MW.SKIP:CACHE
// if ($defaultNamespace == NS_MAIN) { // if ($defaultNamespace == NS_MAIN) {
// $titleCache.set($text, t); // $titleCache.set($text, t);
@ -985,7 +987,7 @@ public class XomwTitle {
} }
// try { // try {
XomwTitleFormatter formatter = getTitleFormatter(); XomwTitleFormatter formatter = env.MediaWikiServices().getTitleFormatter();
return formatter.getNamespaceName(this.mNamespace, this.mDbkeyform); return formatter.getNamespaceName(this.mNamespace, this.mDbkeyform);
// } catch (InvalidArgumentException $ex) { // } catch (InvalidArgumentException $ex) {
// wfDebug(__METHOD__ . ': ' . $ex.getMessage() . "\n"); // wfDebug(__METHOD__ . ': ' . $ex.getMessage() . "\n");
@ -3351,7 +3353,7 @@ public class XomwTitle {
* @throws XomwMalformedTitleException On invalid titles * @throws XomwMalformedTitleException On invalid titles
* @return boolean True on success * @return boolean True on success
*/ */
private boolean secureAndSplit() { private boolean secureAndSplit(XomwEnv env) {
// Initialisation // Initialisation
this.mInterwiki = Bry_.Empty; this.mInterwiki = Bry_.Empty;
this.mFragment = Bry_.Empty; this.mFragment = Bry_.Empty;
@ -3364,7 +3366,7 @@ public class XomwTitle {
// @todo: get rid of secureAndSplit, refactor parsing code. // @todo: get rid of secureAndSplit, refactor parsing code.
// @note: getTitleParser() returns a TitleParser implementation which does not have a // @note: getTitleParser() returns a TitleParser implementation which does not have a
// splitTitleString method, but the only implementation (MediaWikiTitleCodec) does // splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
XomwMediaWikiTitleCodec titleCodec = XomwMediaWikiServices.getInstance().getTitleParser(); XomwMediaWikiTitleCodec titleCodec = env.MediaWikiServices().getTitleParser();
// XomwMalformedTitleException can be thrown here // XomwMalformedTitleException can be thrown here
XomwMediaWikiTitleCodecParts parts = titleCodec.splitTitleString(dbkey, this.getDefaultNamespace()); XomwMediaWikiTitleCodecParts parts = titleCodec.splitTitleString(dbkey, this.getDefaultNamespace());

View File

@ -21,7 +21,7 @@ public class XomwFile {
* P8: normalizeExtension * P8: normalizeExtension
* P8: normalizeTitle * P8: normalizeTitle
*/ */
private final XomwParserEnv env; private final XomwEnv env;
// // Bitfield values akin to the Revision deletion constants // // Bitfield values akin to the Revision deletion constants
// static final DELETED_FILE = 1; // static final DELETED_FILE = 1;
// static final DELETED_COMMENT = 2; // static final DELETED_COMMENT = 2;
@ -265,7 +265,7 @@ public class XomwFile {
// return strcmp(a.getName(), b.getName()); // return strcmp(a.getName(), b.getName());
// } // }
public XomwFile(XomwParserEnv env, XomwTitle title, XomwFileRepo repo) { public XomwFile(XomwEnv env, XomwTitle title, XomwFileRepo repo) {
this.env = env; this.env = env;
this.title = title; this.title = title;
// change title.getDBKey to normalizeTitle // change title.getDBKey to normalizeTitle

View File

@ -16,8 +16,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.mediawiki.includes.filerepo.file; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.filerepo.*; package gplx.xowa.mediawiki.includes.filerepo.file; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.filerepo.*;
import gplx.xowa.mediawiki.includes.parsers.*; import gplx.xowa.mediawiki.includes.parsers.*;
public class XomwFileFinderMock implements XomwFileFinder { public class XomwFileFinderMock implements XomwFileFinder {
private final XomwParserEnv env; private final XomwEnv env;
public XomwFileFinderMock(XomwParserEnv env) {this.env = env;} public XomwFileFinderMock(XomwEnv env) {this.env = env;}
private final Hash_adp_bry hash = Hash_adp_bry.cs(); private final Hash_adp_bry hash = Hash_adp_bry.cs();
public void Clear() {hash.Clear();} public void Clear() {hash.Clear();}
public XomwFile Find_file(XomwTitle ttl) { public XomwFile Find_file(XomwTitle ttl) {
@ -25,7 +25,7 @@ public class XomwFileFinderMock implements XomwFileFinder {
} }
public void Add(String title, XomwFileRepo repo, int w, int h, byte[] mime) { public void Add(String title, XomwFileRepo repo, int w, int h, byte[] mime) {
byte[] title_bry = Bry_.new_u8(title); byte[] title_bry = Bry_.new_u8(title);
XomwLocalFile file = new XomwLocalFile(env, XomwTitle.newFromText(title_bry), repo, w, h, mime); XomwLocalFile file = new XomwLocalFile(env, XomwTitle.newFromText(env, title_bry), repo, w, h, mime);
hash.Add_if_dupe_use_nth(title_bry, file); hash.Add_if_dupe_use_nth(title_bry, file);
} }
} }

View File

@ -186,7 +186,7 @@ public class XomwLocalFile extends XomwFile {// static final VERSION = 10; // c
// ]; // ];
// } // }
public XomwLocalFile(XomwParserEnv env, XomwTitle title, XomwFileRepo repo, int w, int h, byte[] mime) {super(env, title, repo); public XomwLocalFile(XomwEnv env, XomwTitle title, XomwFileRepo repo, int w, int h, byte[] mime) {super(env, title, repo);
this.width = w; this.width = w;
this.height = h; this.height = h;
this.mime = mime; this.mime = mime;

View File

@ -17,6 +17,7 @@ package gplx.xowa.mediawiki.includes.media; import gplx.*; import gplx.xowa.*; i
import org.junit.*; import gplx.core.tests.*; import org.junit.*; import gplx.core.tests.*;
import gplx.xowa.mediawiki.includes.parsers.*; import gplx.xowa.mediawiki.includes.parsers.lnkis.*; import gplx.xowa.mediawiki.includes.parsers.*; import gplx.xowa.mediawiki.includes.parsers.lnkis.*;
import gplx.xowa.mediawiki.includes.filerepo.*; import gplx.xowa.mediawiki.includes.filerepo.file.*; import gplx.xowa.mediawiki.includes.filerepo.*; import gplx.xowa.mediawiki.includes.filerepo.file.*;
import gplx.xowa.mediawiki.languages.*;
public class XomwImageHandlerTest { public class XomwImageHandlerTest {
private final XomwImageHandler_fxt fxt = new XomwImageHandler_fxt(); private final XomwImageHandler_fxt fxt = new XomwImageHandler_fxt();
@Before public void init() { @Before public void init() {
@ -30,10 +31,10 @@ public class XomwImageHandlerTest {
class XomwImageHandler_fxt { class XomwImageHandler_fxt {
private final XomwImageHandler handler; private final XomwImageHandler handler;
private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb")); private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb"));
private final XomwParserEnv env = new XomwParserEnv(); private final XomwEnv env = XomwEnv.NewTest();
private XomwFile file; private XomwFile file;
public XomwImageHandler_fxt() { public XomwImageHandler_fxt() {
handler = new XomwTransformationalImageHandler(Bry_.new_a7("test_handler")); this.handler = new XomwTransformationalImageHandler(Bry_.new_a7("test_handler"));
} }
public Xomw_params_handler Make__handlerParams(int w) {return Make__handlerParams(w, XophpUtility.Null_int, XophpUtility.Null_int, XophpUtility.Null_int);} public Xomw_params_handler Make__handlerParams(int w) {return Make__handlerParams(w, XophpUtility.Null_int, XophpUtility.Null_int, XophpUtility.Null_int);}
public Xomw_params_handler Make__handlerParams(int w, int h, int phys_w, int phys_h) { public Xomw_params_handler Make__handlerParams(int w, int h, int phys_w, int phys_h) {
@ -45,7 +46,7 @@ class XomwImageHandler_fxt {
return rv; return rv;
} }
public void Init__file(String title, int w, int h) { public void Init__file(String title, int w, int h) {
this.file = new XomwLocalFile(env, XomwTitle.newFromText(Bry_.new_u8(title)), repo, w, h, XomwMediaHandlerFactory.Mime__image__png); this.file = new XomwLocalFile(env, XomwTitle.newFromText(env, Bry_.new_u8(title)), repo, w, h, XomwMediaHandlerFactory.Mime__image__png);
} }
public void Test__normaliseParams(Xomw_params_handler prms, Xomw_params_handler expd) { public void Test__normaliseParams(Xomw_params_handler prms, Xomw_params_handler expd) {
// exec // exec

View File

@ -24,13 +24,17 @@ public class XomwLinkHolderArrayTest {
} }
} }
class XomwLinkHolderArrayFxt { class XomwLinkHolderArrayFxt {
private final XomwLinkHolderArray holders = new XomwLinkHolderArray(new XomwParser()); private final XomwEnv env;
private final XomwLinkHolderArray holders;
private final XomwParserBfr pbfr = new XomwParserBfr(); private final XomwParserBfr pbfr = new XomwParserBfr();
private boolean apos = true; private boolean apos = true;
public XomwLinkHolderArrayFxt() { public XomwLinkHolderArrayFxt() {
XomwParser parser = new XomwParser(XomwEnv.NewTest());
this.env = parser.Env();
this.holders = new XomwLinkHolderArray(parser);
} }
public void Init__add(String ttl, String capt) { public void Init__add(String ttl, String capt) {
holders.Test__add(XomwTitle.newFromText(Bry_.new_u8(ttl)), Bry_.new_u8(capt)); holders.Test__add(XomwTitle.newFromText(env, Bry_.new_u8(ttl)), Bry_.new_u8(capt));
} }
public void Test__replace(String src, String expd) { public void Test__replace(String src, String expd) {
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd); if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);

View File

@ -259,7 +259,7 @@ public class XomwParser implements XomwParserIface {
// XOWA // XOWA
private final Bry_bfr tmp_bfr = Bry_bfr_.New(); private final Bry_bfr tmp_bfr = Bry_bfr_.New();
private final XomwParserEnv env = new XomwParserEnv(); private final XomwEnv env;
private final XomwSanitizer sanitizer = new XomwSanitizer(); private final XomwSanitizer sanitizer = new XomwSanitizer();
private final Xomw_table_wkr tableWkr; private final Xomw_table_wkr tableWkr;
private final Xomw_hr_wkr hrWkr = new Xomw_hr_wkr(); private final Xomw_hr_wkr hrWkr = new Xomw_hr_wkr();
@ -308,12 +308,12 @@ public class XomwParser implements XomwParserIface {
// wfDebug(__CLASS__ . ": using preprocessor: {this.mPreprocessorClass}\n"); // wfDebug(__CLASS__ . ": using preprocessor: {this.mPreprocessorClass}\n");
// } // }
private final Btrie_slim_mgr protocols_trie; private final Btrie_slim_mgr protocols_trie;
public XomwParserEnv Env() {return env;} public XomwEnv Env() {return env;}
public Xomw_lnki_wkr Lnki_wkr() {return lnkiWkr;} public Xomw_lnki_wkr Lnki_wkr() {return lnkiWkr;}
public XomwLinker Linker() {return linker;} private final XomwLinker linker; public XomwLinker Linker() {return linker;} private final XomwLinker linker;
public byte[] Get_external_link_rel; public byte[] Get_external_link_rel;
private static byte[] Atr__rel; private static byte[] Atr__rel;
public XomwParser() { public XomwParser(XomwEnv env) {
if (regex_space == null) { if (regex_space == null) {
synchronized (Type_adp_.ClassOf_obj(this)) { synchronized (Type_adp_.ClassOf_obj(this)) {
regex_space = new Xomw_regex_space(); regex_space = new Xomw_regex_space();
@ -324,6 +324,7 @@ public class XomwParser implements XomwParserIface {
} }
} }
this.env = env;
this.mLinkRenderer = new XomwLinkRenderer(sanitizer); this.mLinkRenderer = new XomwLinkRenderer(sanitizer);
this.linker = new XomwLinker(mLinkRenderer); this.linker = new XomwLinker(mLinkRenderer);
this.protocols_trie = XomwParser.Protocols__dflt(); this.protocols_trie = XomwParser.Protocols__dflt();

View File

@ -58,15 +58,16 @@ public class XomwParserTest {
} }
} }
class XomwParserFxt { class XomwParserFxt {
private final XomwParser parser = new XomwParser(); private final XomwParser parser;
private final XomwParserCtx pctx = new XomwParserCtx(); private final XomwParserCtx pctx = new XomwParserCtx();
private final XomwParserBfr pbfr = new XomwParserBfr(); private final XomwParserBfr pbfr = new XomwParserBfr();
public XomwParserFxt() { public XomwParserFxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit(); Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
this.parser = new XomwParser(XomwEnv.NewTestByApp(app));
parser.Init_by_wiki(wiki); parser.Init_by_wiki(wiki);
parser.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1"))); parser.Init_by_page(XomwTitle.newFromText(parser.Env(), Bry_.new_a7("Page_1")));
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1"))); pctx.Init_by_page(XomwTitle.newFromText(parser.Env(), Bry_.new_a7("Page_1")));
} }
public void Test__parse(String src_str, String expd) { public void Test__parse(String src_str, String expd) {
byte[] src_bry = Bry_.new_u8(src_str); byte[] src_bry = Bry_.new_u8(src_str);

View File

@ -57,7 +57,7 @@ class Xomw_lnke_wkr__fxt {
private final XomwParserBfr pbfr = new XomwParserBfr(); private final XomwParserBfr pbfr = new XomwParserBfr();
private boolean apos = true; private boolean apos = true;
public Xomw_lnke_wkr__fxt() { public Xomw_lnke_wkr__fxt() {
XomwParser parser = new XomwParser(); XomwParser parser = new XomwParser(XomwEnv.NewTest());
this.wkr = new Xomw_lnke_wkr(parser, Bry_bfr_.New(), parser.Linker(), parser.Sanitizer()); this.wkr = new Xomw_lnke_wkr(parser, Bry_bfr_.New(), parser.Linker(), parser.Sanitizer());
Xomw_regex_space regex_space = new Xomw_regex_space(); Xomw_regex_space regex_space = new Xomw_regex_space();
wkr.Init_by_wiki(XomwParser.Protocols__dflt(), new Xomw_regex_url(regex_space), regex_space); wkr.Init_by_wiki(XomwParser.Protocols__dflt(), new Xomw_regex_url(regex_space), regex_space);

View File

@ -40,7 +40,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
// private final Btrie_slim_mgr protocols_trie; // private final Btrie_slim_mgr protocols_trie;
private final Xomw_quote_wkr quote_wkr; private final Xomw_quote_wkr quote_wkr;
private final XomwStripState strip_state; private final XomwStripState strip_state;
private XomwParserEnv env; private XomwEnv env;
private Xow_wiki wiki; private Xow_wiki wiki;
private XomwTitle mPageTitle; private XomwTitle mPageTitle;
// private final XomwLinker_NormalizeSubpageLink normalize_subpage_link = new XomwLinker_NormalizeSubpageLink(); // private final XomwLinker_NormalizeSubpageLink normalize_subpage_link = new XomwLinker_NormalizeSubpageLink();
@ -65,7 +65,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
this.tmp = tmp; this.tmp = tmp;
this.strip_state = strip_state; this.strip_state = strip_state;
} }
public void Init_by_wiki(XomwParserEnv env, Xow_wiki wiki) { public void Init_by_wiki(XomwEnv env, Xow_wiki wiki) {
this.env = env; this.env = env;
this.wiki = wiki; this.wiki = wiki;
if (title_chars_for_lnki == null) { if (title_chars_for_lnki == null) {
@ -78,7 +78,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
public void Clear_state() { public void Clear_state() {
holders.clear(); holders.clear();
} }
public void replaceInternalLinks(XomwParserBfr pbfr, XomwParserEnv env, XomwParserCtx pctx) { public void replaceInternalLinks(XomwParserBfr pbfr, XomwEnv env, XomwParserCtx pctx) {
// XO.PBFR // XO.PBFR
Bry_bfr src_bfr = pbfr.Src(); Bry_bfr src_bfr = pbfr.Src();
byte[] src = src_bfr.Bfr(); byte[] src = src_bfr.Bfr();
@ -92,7 +92,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
replaceInternalLinks(env, pctx, bfr, src, src_bgn, src_end); replaceInternalLinks(env, pctx, bfr, src, src_bgn, src_end);
} }
// XO.MW:SYNC:1.29; DATE:2017-02-02 // XO.MW:SYNC:1.29; DATE:2017-02-02
public void replaceInternalLinks(XomwParserEnv env, XomwParserCtx pctx, Bry_bfr bfr, byte[] src, int src_bgn, int src_end) { public void replaceInternalLinks(XomwEnv env, XomwParserCtx 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 // XO.MW: regex for tc move to header; e1 and e1_img moved to code
// the % is needed to support urlencoded titles as well // the % is needed to support urlencoded titles as well
@ -253,7 +253,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
link = Bry_.Mid(link, 1); link = Bry_.Mid(link, 1);
} }
// $nt = is_string( $unstrip ) ? Title::newFromText( $unstrip ) : null; // $nt = is_string( $unstrip ) ? Title::newFromText( $unstrip ) : null;
XomwTitle nt = XomwTitle.newFromText(link); XomwTitle nt = XomwTitle.newFromText(env, link);
// Make subpage if necessary // Make subpage if necessary
// boolean useSubpages = nt.Ns().Subpages_enabled(); // boolean useSubpages = nt.Ns().Subpages_enabled();
@ -270,7 +270,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
byte[] unstrip = strip_state.unstripNoWiki(link); byte[] unstrip = strip_state.unstripNoWiki(link);
if (!Bry_.Eq(unstrip, link)) if (!Bry_.Eq(unstrip, link))
nt = XomwTitle.newFromText(unstrip); nt = XomwTitle.newFromText(env, unstrip);
if (nt == null) { if (nt == null) {
bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line; bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line;
prv = cur = lnki_bgn + 2; prv = cur = lnki_bgn + 2;
@ -443,7 +443,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
} }
} }
} }
public void makeImage(XomwParserEnv env, XomwParserCtx pctx, Bry_bfr bfr, XomwTitle title, byte[] options_at_link, XomwLinkHolderArray holders) { public void makeImage(XomwEnv env, XomwParserCtx pctx, Bry_bfr bfr, XomwTitle title, byte[] options_at_link, XomwLinkHolderArray holders) {
// Check if the options text is of the form "options|alt text" // Check if the options text is of the form "options|alt text"
// Options are: // Options are:
// * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang // * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang

View File

@ -74,14 +74,15 @@ class Xomw_lnki_wkr__fxt {
private final Xomw_lnki_wkr wkr; private final Xomw_lnki_wkr wkr;
private final XomwParserCtx pctx; private final XomwParserCtx pctx;
private final XomwParserBfr pbfr = new XomwParserBfr(); private final XomwParserBfr pbfr = new XomwParserBfr();
private final XomwParserEnv env; private final XomwEnv env;
private final XomwFileFinderMock file_finder; private final XomwFileFinderMock file_finder;
private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb")); private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb"));
private boolean apos = true; private boolean apos = true;
public Xomw_lnki_wkr__fxt() { public Xomw_lnki_wkr__fxt() {
Xoae_app app = Xoa_app_fxt.Make__app__edit(); Xoae_app app = Xoa_app_fxt.Make__app__edit();
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app); Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
XomwParser parser = new XomwParser();
XomwParser parser = new XomwParser(XomwEnv.NewTestByApp(app));
wkr = parser.Lnki_wkr(); wkr = parser.Lnki_wkr();
// env // env
@ -95,7 +96,7 @@ class Xomw_lnki_wkr__fxt {
// ctx // ctx
pctx = new XomwParserCtx(); pctx = new XomwParserCtx();
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1"))); pctx.Init_by_page(XomwTitle.newFromText(env, Bry_.new_a7("Page_1")));
} }
public void Clear() { public void Clear() {
wkr.Clear_state(); wkr.Clear_state();

View File

@ -70,8 +70,8 @@ class Xomw_magiclinks_wkr__fxt {
private final XomwParserBfr pbfr = new XomwParserBfr(); private final XomwParserBfr pbfr = new XomwParserBfr();
public Xomw_magiclinks_wkr__fxt() { public Xomw_magiclinks_wkr__fxt() {
Xomw_regex_space regex_space = new Xomw_regex_space(); Xomw_regex_space regex_space = new Xomw_regex_space();
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1"))); XomwParser parser = new XomwParser(XomwEnv.NewTest());
XomwParser parser = new XomwParser(); pctx.Init_by_page(XomwTitle.newFromText(parser.Env(), Bry_.new_a7("Page_1")));
this.wkr = new Xomw_magiclinks_wkr(parser, parser.Sanitizer(), parser.Linker(), new Xomw_regex_boundary(regex_space), new Xomw_regex_url(regex_space)); this.wkr = new Xomw_magiclinks_wkr(parser, parser.Sanitizer(), parser.Linker(), new Xomw_regex_boundary(regex_space), new Xomw_regex_url(regex_space));
wkr.Init_by_wiki(); wkr.Init_by_wiki();
} }

View File

@ -119,7 +119,7 @@ class Xomw_table_wkr__fxt {
private final XomwParserCtx pctx = new XomwParserCtx(); private final XomwParserCtx pctx = new XomwParserCtx();
private final Xomw_table_wkr wkr; private final Xomw_table_wkr wkr;
public Xomw_table_wkr__fxt() { public Xomw_table_wkr__fxt() {
XomwParser parser = new XomwParser(); XomwParser parser = new XomwParser(XomwEnv.NewTest());
this.wkr = new Xomw_table_wkr(Bry_bfr_.New(), parser.Sanitizer(), parser.Strip_state()); this.wkr = new Xomw_table_wkr(Bry_bfr_.New(), parser.Sanitizer(), parser.Strip_state());
} }

View File

@ -233,6 +233,7 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter {
* @return array A map with the fields 'interwiki', 'fragment', 'namespace', * @return array A map with the fields 'interwiki', 'fragment', 'namespace',
* 'user_case_dbkey', and 'dbkey'. * 'user_case_dbkey', and 'dbkey'.
*/ */
// private final byte[][] tmpPrefixRegex = new byte[2][];
public XomwMediaWikiTitleCodecParts splitTitleString(byte[] text, int defaultNamespace) { public XomwMediaWikiTitleCodecParts splitTitleString(byte[] text, int defaultNamespace) {
byte[] dbkey = XophpString.str_replace(Byte_ascii.Space, Byte_ascii.Underline, text); byte[] dbkey = XophpString.str_replace(Byte_ascii.Space, Byte_ascii.Underline, text);
@ -279,7 +280,13 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter {
parts.ns = XomwDefines.NS_FILE; parts.ns = XomwDefines.NS_FILE;
dbkey = Bry_.Mid(dbkey, 5); dbkey = Bry_.Mid(dbkey, 5);
} }
// $prefixRegexp = "/^(.+?)_*:_*(.*)$/S"; // do {
// byte[][] m = tmpPrefixRegex;
// if (XomwRegexTitlePrefix.preg_match(m, dbkey)) {
// byte[] p = m[0];
// int ns = this.language.getNsIndex(p);
// }
// } while (true);
// do { // do {
// $m = []; // $m = [];
// if (preg_match($prefixRegexp, dbkey, $m)) { // if (preg_match($prefixRegexp, dbkey, $m)) {

View File

@ -14,8 +14,8 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.xowa.mediawiki.languages; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; package gplx.xowa.mediawiki.languages; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
import gplx.core.lists.*;
import gplx.xowa.mediawiki.includes.*; import gplx.xowa.mediawiki.includes.*;
import gplx.xowa.langs.*;
public class XomwLanguage { public class XomwLanguage {
// /** // /**
// * @var LanguageConverter // * @var LanguageConverter
@ -30,7 +30,7 @@ public class XomwLanguage {
// public $mExtendedSpecialPageAliases; // public $mExtendedSpecialPageAliases;
// //
// /** @var array|null */ // /** @var array|null */
private HashByInt namespaceNames; private XomwNamespaceHash namespaceNames;
// protected $mNamespaceIds, $namespaceAliases; // protected $mNamespaceIds, $namespaceAliases;
// //
// /** // /**
@ -193,7 +193,9 @@ public class XomwLanguage {
// -\x{1edff}\x{1ef00}-\x{1efff}\x{608}\x{60b}\x{60d}\x{61b}-\x{64a}\x{66d}-\x{66f}\x{671}-\x{6d5}\x{6e5}\x{6e6}\x{6ee}\x{6ef}\x{6fa}-\x{710}\x{712}-\x{72f}\x{74b}-\x{7a5}\x{7b1}-\x{7bf}\x{8a0}-\x{8e2}\x{fb50}-\x{fd3d}\x{fd40}-\x{fdcf}\x{fdf0}-\x{fdfc}\x{fdfe}\x{fdff}\x{fe70}-\x{fefe}\x{1ee00}-\x{1eeef}\x{1eef2}-\x{1eeff}]))/u'; // -\x{1edff}\x{1ef00}-\x{1efff}\x{608}\x{60b}\x{60d}\x{61b}-\x{64a}\x{66d}-\x{66f}\x{671}-\x{6d5}\x{6e5}\x{6e6}\x{6ee}\x{6ef}\x{6fa}-\x{710}\x{712}-\x{72f}\x{74b}-\x{7a5}\x{7b1}-\x{7bf}\x{8a0}-\x{8e2}\x{fb50}-\x{fd3d}\x{fd40}-\x{fdcf}\x{fdf0}-\x{fdfc}\x{fdfe}\x{fdff}\x{fe70}-\x{fefe}\x{1ee00}-\x{1eeef}\x{1eef2}-\x{1eeff}]))/u';
// // @codeCoverageIgnoreEnd // // @codeCoverageIgnoreEnd
// // @codingStandardsIgnoreEnd // // @codingStandardsIgnoreEnd
// private Xol_lang_itm xoLang = null;
private final Bry_bfr tmpBfr = Bry_bfr_.New();
// /** // /**
// * Get a cached or new language Object for a given language code // * Get a cached or new language Object for a given language code
// * @param String $code // * @param String $code
@ -430,7 +432,7 @@ public class XomwLanguage {
// } // }
// return self::$dataCache; // return self::$dataCache;
// } // }
//
// function __construct() { // function __construct() {
// this.mConverter = new FakeConverter($this); // this.mConverter = new FakeConverter($this);
// // Set the code to the name of the descendant // // Set the code to the name of the descendant
@ -441,7 +443,10 @@ public class XomwLanguage {
// } // }
// self::getLocalisationCache(); // self::getLocalisationCache();
// } // }
// public XomwLanguage(Xol_lang_itm xoLang) {
this.xoLang = xoLang;
}
// /** // /**
// * Reduce memory usage // * Reduce memory usage
// */ // */
@ -480,11 +485,11 @@ public class XomwLanguage {
* *
* @return array * @return array
*/ */
public HashByInt getNamespaces() { public XomwNamespaceHash getNamespaces() {
if (this.namespaceNames == null) { if (this.namespaceNames == null) {
// global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces; // global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
// //
HashByInt validNamespaces = XomwNamespace.getCanonicalNamespaces(); XomwNamespaceHash validNamespaces = XomwNamespace.getCanonicalNamespaces();
// //
// this.namespaceNames = $wgExtraNamespaces + // this.namespaceNames = $wgExtraNamespaces +
// self::$dataCache->getItem(this.mCode, 'namespaceNames'); // self::$dataCache->getItem(this.mCode, 'namespaceNames');
@ -561,8 +566,8 @@ public class XomwLanguage {
* @return String|boolean String if the namespace value exists, otherwise false * @return String|boolean String if the namespace value exists, otherwise false
*/ */
public byte[] getNsText(int index) { public byte[] getNsText(int index) {
HashByInt ns = this.getNamespaces(); XomwNamespaceHash nsHash = this.getNamespaces();
return (byte[])ns.Get_by_or_null(index); return nsHash.GetTextOrNull(index);
} }
// /** // /**
@ -705,24 +710,25 @@ public class XomwLanguage {
// } // }
// return this.mNamespaceIds; // return this.mNamespaceIds;
// } // }
//
// /** /**
// * Get a namespace key by value, case insensitive. Canonical namespace * Get a namespace key by value, case insensitive. Canonical namespace
// * names override custom ones defined for the current language. * @Override names custom ones defined for the current language.
// * *
// * @param String $text * @param String $text
// * @return int|boolean An integer if $text is a valid value otherwise false * @return int|boolean An integer if $text is a valid value otherwise false
// */ */
// public function getNsIndex($text) { public int getNsIndex(byte[] text) {
// $lctext = this.lc($text); byte[] lctext = this.lc(text);
// $ns = XomwNamespace::getCanonicalIndex($lctext); int ns = XomwNamespace.getCanonicalIndex(lctext);
// if ($ns !== null) { if (ns != XomwNamespace.NULL_NS_ID) {
// return $ns; return ns;
// } }
// $ids = this.getNamespaceIds(); // $ids = this.getNamespaceIds();
// return isset($ids[$lctext]) ? $ids[$lctext] : false; // return isset($ids[$lctext]) ? $ids[$lctext] : false;
// } return XophpUtility.Null_int;
// }
// /** // /**
// * short names for language variants used for language conversion links. // * short names for language variants used for language conversion links.
// * // *
@ -2710,24 +2716,30 @@ public class XomwLanguage {
// return $str; // return $str;
// } // }
// } // }
//
// /** /**
// * @param String $str * @param String $str
// * @param boolean $first * @param boolean $first
// * @return mixed|String * @return mixed|String
// */ */
// function lc($str, $first = false) { private byte[] lc(byte[] str) {return lc(str, false);}
// if ($first) { private byte[] lc(byte[] str, boolean first) {
// if (this.isMultibyte($str)) { return first
// return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1); ? xoLang.Case_mgr().Case_build_1st_lower(tmpBfr, str, 0, str.length)
// } else { : xoLang.Case_mgr().Case_build_lower (str, 0, str.length);
// return strtolower(substr($str, 0, 1)) . substr($str, 1); // XO.MW:PORTED
// } // if (first) {
// } else { // if (this.isMultibyte(str)) {
// return this.isMultibyte($str) ? mb_strtolower($str) : strtolower($str); // return mb_strtolower(mb_substr(str, 0, 1)) . mb_substr(str, 1);
// } // } else {
// } // return strtolower(substr(str, 0, 1)) . substr(str, 1);
// // }
// } else {
// return this.isMultibyte(str) ? mb_strtolower(str) : strtolower(str);
// }
}
// /** // /**
// * @param String $str // * @param String $str
// * @return boolean // * @return boolean