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:
parent
a661f90ede
commit
5a6ac3a335
@ -24,6 +24,10 @@ public class HashByInt {
|
||||
public int 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) {
|
||||
synchronized (tmp_key) {
|
||||
HashByIntItem item = (HashByIntItem)hash.Get_by_or_fail(tmp_key.Val_(key));
|
||||
|
@ -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
|
||||
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.*;
|
||||
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 int User__default__thumbsize = 220;
|
||||
|
||||
@ -23,10 +26,21 @@ public class XomwParserEnv {
|
||||
public double Global__wgThumbUpright = .75d;
|
||||
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 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 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()));
|
||||
}
|
||||
}
|
@ -1375,7 +1375,7 @@ public class XomwGlobalFunctions {
|
||||
*
|
||||
* @see Message::__construct
|
||||
*/
|
||||
public static XomwMessage wfMessage(XomwParserEnv env, String key) {
|
||||
public static XomwMessage wfMessage(XomwEnv env, String key) {
|
||||
// function wfMessage($key /*...*/) {
|
||||
// $message = new Message($key);
|
||||
|
||||
|
@ -26,7 +26,7 @@ import gplx.xowa.mediawiki.includes.parsers.lnkis.*;
|
||||
* P7: $html = HtmlArmor::getHtml($text);
|
||||
*/
|
||||
public class XomwLinker {
|
||||
// private XomwParserEnv env;
|
||||
// private XomwEnv 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 byte[] wg_title = null;
|
||||
@ -51,7 +51,7 @@ public class XomwLinker {
|
||||
public XomwLinker(XomwLinkRenderer 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.split_trail_trie = trie;
|
||||
}
|
||||
@ -331,7 +331,7 @@ public class XomwLinker {
|
||||
// @since 1.20
|
||||
// @return String HTML for an image, with links, wrappers, etc.
|
||||
// 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
|
||||
|
||||
if (file != null && !file.allowInlineDisplay()) {
|
||||
@ -534,7 +534,7 @@ public class XomwLinker {
|
||||
* @return String
|
||||
*/
|
||||
// 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();
|
||||
|
||||
int page = handlerParams.page;
|
||||
|
@ -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");}
|
||||
}
|
||||
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_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) {
|
||||
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_text, String_.new_u8(normalize_subpage_link.text));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class XomwLinker_SplitTrailFxt {
|
||||
String[] ary = new String[] {"a", "b", "c", "d", "e", "f"};
|
||||
for (String itm : ary)
|
||||
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) {
|
||||
byte[][] split_trail = linker.splitTrail(Bry_.new_u8(trail_str));
|
||||
|
@ -30,37 +30,11 @@ import gplx.xowa.mediawiki.includes.title.*;
|
||||
* MediaWiki code super.
|
||||
*/
|
||||
public class XomwMediaWikiServices {
|
||||
/**
|
||||
* @var MediaWikiServices|null
|
||||
*/
|
||||
private static XomwMediaWikiServices instance = null;
|
||||
// XO.MW.SKIP:remove global getInstance(). See XomwEnv
|
||||
private final XomwMediaWikiTitleCodec titleParser;
|
||||
|
||||
/**
|
||||
* Returns the global default instance of the top level service locator.
|
||||
*
|
||||
* @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;
|
||||
public XomwMediaWikiServices(XomwLanguage language) {
|
||||
this.titleParser = new XomwMediaWikiTitleCodec(language);
|
||||
}
|
||||
|
||||
// /**
|
||||
@ -581,7 +555,6 @@ public class XomwMediaWikiServices {
|
||||
// return $this->getService( 'TitleParser' );
|
||||
return titleParser;
|
||||
}
|
||||
private XomwMediaWikiTitleCodec titleParser = new XomwMediaWikiTitleCodec(new XomwLanguage());
|
||||
|
||||
// /**
|
||||
// * @since 1.28
|
||||
|
@ -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
|
||||
*/
|
||||
package gplx.xowa.mediawiki.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*;
|
||||
import gplx.core.lists.*;
|
||||
public class XomwNamespace {
|
||||
// /**
|
||||
// * These namespaces should always be first-letter capitalized, now and
|
||||
@ -189,13 +188,13 @@ public class XomwNamespace {
|
||||
* @return array
|
||||
* @since 1.17
|
||||
*/
|
||||
private static HashByInt namespaces = null;
|
||||
public static HashByInt getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static HashByInt getCanonicalNamespaces(boolean rebuild) {
|
||||
private static XomwNamespaceHash namespaces = null;
|
||||
public static XomwNamespaceHash getCanonicalNamespaces() {return getCanonicalNamespaces(false);}
|
||||
public static XomwNamespaceHash getCanonicalNamespaces(boolean rebuild) {
|
||||
if (namespaces == null || rebuild) {
|
||||
// global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
||||
namespaces = XomwSetup.wgCanonicalNamespaceNames.Clone();
|
||||
namespaces.Add_as_bry(XomwDefines.NS_MAIN, "");
|
||||
namespaces.Add(XomwDefines.NS_MAIN, "");
|
||||
|
||||
// // Add extension namespaces
|
||||
// $namespaces += ExtensionRegistry::getInstance()->getAttribute('ExtensionNamespaces');
|
||||
@ -221,29 +220,32 @@ public class XomwNamespace {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Returns the index for a given canonical name, or NULL
|
||||
// * The input *must* be converted to lower case first
|
||||
// *
|
||||
// * @param String $name Namespace name
|
||||
// * @return int
|
||||
// */
|
||||
// public static function getCanonicalIndex($name) {
|
||||
// static $xNamespaces = false;
|
||||
// if ($xNamespaces == false) {
|
||||
// $xNamespaces = [];
|
||||
// foreach (self::getCanonicalNamespaces() as $i => $text) {
|
||||
// $xNamespaces[strtolower($text)] = $i;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns the index for a given canonical name, or NULL
|
||||
* The input *must* be converted to lower case first
|
||||
*
|
||||
* @param String $name Namespace name
|
||||
* @return int
|
||||
*/
|
||||
private static Hash_adp xNamespaces = null;
|
||||
public static int getCanonicalIndex(byte[] name) {
|
||||
if (xNamespaces == null) {
|
||||
xNamespaces = Hash_adp_bry.cs();
|
||||
int len = namespaces.Len();
|
||||
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)) {
|
||||
// return $xNamespaces[$name];
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
return XomwNamespace.NULL_NS_ID;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Returns an array of the namespaces (by integer id) that exist on the
|
||||
// * wiki. Used primarily by the api in help documentation.
|
||||
@ -496,4 +498,5 @@ public class XomwNamespace {
|
||||
//
|
||||
// return $usableLevels;
|
||||
// }
|
||||
public static final int NULL_NS_ID = XophpUtility.Null_int;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@ -393,24 +392,24 @@ public class XomwSetup {
|
||||
* Definitions of the NS_ constants are in Defines.php
|
||||
* @private
|
||||
*/
|
||||
public static HashByInt wgCanonicalNamespaceNames = new HashByInt()
|
||||
.Add_as_bry(XomwDefines.NS_MEDIA , "Media")
|
||||
.Add_as_bry(XomwDefines.NS_SPECIAL , "Special")
|
||||
.Add_as_bry(XomwDefines.NS_TALK , "Talk")
|
||||
.Add_as_bry(XomwDefines.NS_USER , "User")
|
||||
.Add_as_bry(XomwDefines.NS_USER_TALK , "User_talk")
|
||||
.Add_as_bry(XomwDefines.NS_PROJECT , "Project")
|
||||
.Add_as_bry(XomwDefines.NS_PROJECT_TALK , "Project_talk")
|
||||
.Add_as_bry(XomwDefines.NS_FILE , "File")
|
||||
.Add_as_bry(XomwDefines.NS_FILE_TALK , "File_talk")
|
||||
.Add_as_bry(XomwDefines.NS_MEDIAWIKI , "MediaWiki")
|
||||
.Add_as_bry(XomwDefines.NS_MEDIAWIKI_TALK , "MediaWiki_talk")
|
||||
.Add_as_bry(XomwDefines.NS_TEMPLATE , "Template")
|
||||
.Add_as_bry(XomwDefines.NS_TEMPLATE_TALK , "Template_talk")
|
||||
.Add_as_bry(XomwDefines.NS_HELP , "Help")
|
||||
.Add_as_bry(XomwDefines.NS_HELP_TALK , "Help_talk")
|
||||
.Add_as_bry(XomwDefines.NS_CATEGORY , "Category")
|
||||
.Add_as_bry(XomwDefines.NS_CATEGORY_TALK , "Category_talk")
|
||||
public static XomwNamespaceHash wgCanonicalNamespaceNames = new XomwNamespaceHash()
|
||||
.Add(XomwDefines.NS_MEDIA , "Media")
|
||||
.Add(XomwDefines.NS_SPECIAL , "Special")
|
||||
.Add(XomwDefines.NS_TALK , "Talk")
|
||||
.Add(XomwDefines.NS_USER , "User")
|
||||
.Add(XomwDefines.NS_USER_TALK , "User_talk")
|
||||
.Add(XomwDefines.NS_PROJECT , "Project")
|
||||
.Add(XomwDefines.NS_PROJECT_TALK , "Project_talk")
|
||||
.Add(XomwDefines.NS_FILE , "File")
|
||||
.Add(XomwDefines.NS_FILE_TALK , "File_talk")
|
||||
.Add(XomwDefines.NS_MEDIAWIKI , "MediaWiki")
|
||||
.Add(XomwDefines.NS_MEDIAWIKI_TALK , "MediaWiki_talk")
|
||||
.Add(XomwDefines.NS_TEMPLATE , "Template")
|
||||
.Add(XomwDefines.NS_TEMPLATE_TALK , "Template_talk")
|
||||
.Add(XomwDefines.NS_HELP , "Help")
|
||||
.Add(XomwDefines.NS_HELP_TALK , "Help_talk")
|
||||
.Add(XomwDefines.NS_CATEGORY , "Category")
|
||||
.Add(XomwDefines.NS_CATEGORY_TALK , "Category_talk")
|
||||
;
|
||||
|
||||
// /// @todo UGLY UGLY
|
||||
|
@ -156,6 +156,7 @@ public class XomwTitle {
|
||||
// private $mIsBigDeletion = null;
|
||||
// // @}
|
||||
|
||||
private final XomwEnv env;
|
||||
/**
|
||||
* B/C kludge: provide a TitleParser for use by Title.
|
||||
* Ideally, Title would have no methods that need this.
|
||||
@ -164,9 +165,9 @@ public class XomwTitle {
|
||||
*
|
||||
* @return TitleFormatter
|
||||
*/
|
||||
private static XomwMediaWikiTitleCodec getTitleFormatter() {
|
||||
return XomwMediaWikiServices.getInstance().getTitleFormatter();
|
||||
}
|
||||
// private static XomwMediaWikiTitleCodec getTitleFormatter() {
|
||||
// return XomwMediaWikiServices.getInstance().getTitleFormatter();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * B/C kludge: provide an InterwikiLookup for use by Title.
|
||||
@ -179,13 +180,14 @@ public class XomwTitle {
|
||||
// private static function getInterwikiLookup() {
|
||||
// return MediaWikiServices::getInstance().getInterwikiLookup();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @access protected
|
||||
// */
|
||||
// function __construct() {
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
XomwTitle(XomwEnv env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Create a new Title from a prefixed DB key
|
||||
// *
|
||||
@ -250,8 +252,8 @@ public class XomwTitle {
|
||||
* @throws InvalidArgumentException
|
||||
* @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(byte[] text, int defaultNamespace) {
|
||||
public static XomwTitle newFromText(XomwEnv env, byte[] text) {return newFromText(env, text, XomwDefines.NS_MAIN);}
|
||||
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.
|
||||
// XO.MW.SKIP:STRONGCAST
|
||||
// if ($text != null && !is_string($text) && !is_int($text)) {
|
||||
@ -262,7 +264,7 @@ public class XomwTitle {
|
||||
}
|
||||
|
||||
try {
|
||||
return XomwTitle.newFromTextThrow(text, defaultNamespace);
|
||||
return XomwTitle.newFromTextThrow(env, text, defaultNamespace);
|
||||
} catch (XomwMalformedTitleException ex) {
|
||||
Err_.Noop(ex);
|
||||
return null;
|
||||
@ -283,7 +285,7 @@ public class XomwTitle {
|
||||
* @throws XomwMalformedTitleException If the title is invalid
|
||||
* @return Title
|
||||
*/
|
||||
public static XomwTitle newFromTextThrow(byte[] text, int defaultNamespace) {
|
||||
private static XomwTitle newFromTextThrow(XomwEnv env, byte[] text, int defaultNamespace) {
|
||||
// if (is_object($text)) {
|
||||
// throw new MWException('$text must be a String, given an Object');
|
||||
// }
|
||||
@ -306,11 +308,11 @@ public class XomwTitle {
|
||||
// $filteredText = Sanitizer::decodeCharReferencesAndNormalize($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.mDefaultNamespace = defaultNamespace;
|
||||
|
||||
t.secureAndSplit();
|
||||
t.secureAndSplit(env);
|
||||
// XO.MW.SKIP:CACHE
|
||||
// if ($defaultNamespace == NS_MAIN) {
|
||||
// $titleCache.set($text, t);
|
||||
@ -985,7 +987,7 @@ public class XomwTitle {
|
||||
}
|
||||
|
||||
// try {
|
||||
XomwTitleFormatter formatter = getTitleFormatter();
|
||||
XomwTitleFormatter formatter = env.MediaWikiServices().getTitleFormatter();
|
||||
return formatter.getNamespaceName(this.mNamespace, this.mDbkeyform);
|
||||
// } catch (InvalidArgumentException $ex) {
|
||||
// wfDebug(__METHOD__ . ': ' . $ex.getMessage() . "\n");
|
||||
@ -3351,7 +3353,7 @@ public class XomwTitle {
|
||||
* @throws XomwMalformedTitleException On invalid titles
|
||||
* @return boolean True on success
|
||||
*/
|
||||
private boolean secureAndSplit() {
|
||||
private boolean secureAndSplit(XomwEnv env) {
|
||||
// Initialisation
|
||||
this.mInterwiki = Bry_.Empty;
|
||||
this.mFragment = Bry_.Empty;
|
||||
@ -3364,7 +3366,7 @@ public class XomwTitle {
|
||||
// @todo: get rid of secureAndSplit, refactor parsing code.
|
||||
// @note: getTitleParser() returns a TitleParser implementation which does not have a
|
||||
// splitTitleString method, but the only implementation (MediaWikiTitleCodec) does
|
||||
XomwMediaWikiTitleCodec titleCodec = XomwMediaWikiServices.getInstance().getTitleParser();
|
||||
XomwMediaWikiTitleCodec titleCodec = env.MediaWikiServices().getTitleParser();
|
||||
// XomwMalformedTitleException can be thrown here
|
||||
XomwMediaWikiTitleCodecParts parts = titleCodec.splitTitleString(dbkey, this.getDefaultNamespace());
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class XomwFile {
|
||||
* P8: normalizeExtension
|
||||
* P8: normalizeTitle
|
||||
*/
|
||||
private final XomwParserEnv env;
|
||||
private final XomwEnv env;
|
||||
// // Bitfield values akin to the Revision deletion constants
|
||||
// static final DELETED_FILE = 1;
|
||||
// static final DELETED_COMMENT = 2;
|
||||
@ -265,7 +265,7 @@ public class XomwFile {
|
||||
// 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.title = title;
|
||||
// change title.getDBKey to normalizeTitle
|
||||
|
@ -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.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class XomwFileFinderMock implements XomwFileFinder {
|
||||
private final XomwParserEnv env;
|
||||
public XomwFileFinderMock(XomwParserEnv env) {this.env = env;}
|
||||
private final XomwEnv env;
|
||||
public XomwFileFinderMock(XomwEnv env) {this.env = env;}
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {hash.Clear();}
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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.height = h;
|
||||
this.mime = mime;
|
||||
|
@ -17,6 +17,7 @@ package gplx.xowa.mediawiki.includes.media; import gplx.*; import gplx.xowa.*; i
|
||||
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.filerepo.*; import gplx.xowa.mediawiki.includes.filerepo.file.*;
|
||||
import gplx.xowa.mediawiki.languages.*;
|
||||
public class XomwImageHandlerTest {
|
||||
private final XomwImageHandler_fxt fxt = new XomwImageHandler_fxt();
|
||||
@Before public void init() {
|
||||
@ -30,10 +31,10 @@ public class XomwImageHandlerTest {
|
||||
class XomwImageHandler_fxt {
|
||||
private final XomwImageHandler handler;
|
||||
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;
|
||||
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, int h, int phys_w, int phys_h) {
|
||||
@ -45,7 +46,7 @@ class XomwImageHandler_fxt {
|
||||
return rv;
|
||||
}
|
||||
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) {
|
||||
// exec
|
||||
|
@ -24,13 +24,17 @@ public class XomwLinkHolderArrayTest {
|
||||
}
|
||||
}
|
||||
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 boolean apos = true;
|
||||
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) {
|
||||
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) {
|
||||
if (apos) expd = gplx.langs.htmls.Gfh_utl.Replace_apos(expd);
|
||||
|
@ -259,7 +259,7 @@ public class XomwParser implements XomwParserIface {
|
||||
|
||||
// XOWA
|
||||
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 Xomw_table_wkr tableWkr;
|
||||
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");
|
||||
// }
|
||||
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 XomwLinker Linker() {return linker;} private final XomwLinker linker;
|
||||
public byte[] Get_external_link_rel;
|
||||
private static byte[] Atr__rel;
|
||||
public XomwParser() {
|
||||
public XomwParser(XomwEnv env) {
|
||||
if (regex_space == null) {
|
||||
synchronized (Type_adp_.ClassOf_obj(this)) {
|
||||
regex_space = new Xomw_regex_space();
|
||||
@ -324,6 +324,7 @@ public class XomwParser implements XomwParserIface {
|
||||
}
|
||||
}
|
||||
|
||||
this.env = env;
|
||||
this.mLinkRenderer = new XomwLinkRenderer(sanitizer);
|
||||
this.linker = new XomwLinker(mLinkRenderer);
|
||||
this.protocols_trie = XomwParser.Protocols__dflt();
|
||||
|
@ -58,15 +58,16 @@ public class XomwParserTest {
|
||||
}
|
||||
}
|
||||
class XomwParserFxt {
|
||||
private final XomwParser parser = new XomwParser();
|
||||
private final XomwParser parser;
|
||||
private final XomwParserCtx pctx = new XomwParserCtx();
|
||||
private final XomwParserBfr pbfr = new XomwParserBfr();
|
||||
public XomwParserFxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
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_page(XomwTitle.newFromText(Bry_.new_a7("Page_1")));
|
||||
pctx.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(parser.Env(), Bry_.new_a7("Page_1")));
|
||||
}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
|
@ -57,7 +57,7 @@ class Xomw_lnke_wkr__fxt {
|
||||
private final XomwParserBfr pbfr = new XomwParserBfr();
|
||||
private boolean apos = true;
|
||||
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());
|
||||
Xomw_regex_space regex_space = new Xomw_regex_space();
|
||||
wkr.Init_by_wiki(XomwParser.Protocols__dflt(), new Xomw_regex_url(regex_space), regex_space);
|
||||
|
@ -40,7 +40,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// private final Btrie_slim_mgr protocols_trie;
|
||||
private final Xomw_quote_wkr quote_wkr;
|
||||
private final XomwStripState strip_state;
|
||||
private XomwParserEnv env;
|
||||
private XomwEnv env;
|
||||
private Xow_wiki wiki;
|
||||
private XomwTitle mPageTitle;
|
||||
// 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.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.wiki = wiki;
|
||||
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() {
|
||||
holders.clear();
|
||||
}
|
||||
public void replaceInternalLinks(XomwParserBfr pbfr, XomwParserEnv env, XomwParserCtx pctx) {
|
||||
public void replaceInternalLinks(XomwParserBfr pbfr, XomwEnv env, XomwParserCtx pctx) {
|
||||
// XO.PBFR
|
||||
Bry_bfr src_bfr = pbfr.Src();
|
||||
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);
|
||||
}
|
||||
// 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
|
||||
// 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);
|
||||
}
|
||||
// $nt = is_string( $unstrip ) ? Title::newFromText( $unstrip ) : null;
|
||||
XomwTitle nt = XomwTitle.newFromText(link);
|
||||
XomwTitle nt = XomwTitle.newFromText(env, link);
|
||||
|
||||
// Make subpage if necessary
|
||||
// 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);
|
||||
if (!Bry_.Eq(unstrip, link))
|
||||
nt = XomwTitle.newFromText(unstrip);
|
||||
nt = XomwTitle.newFromText(env, unstrip);
|
||||
if (nt == null) {
|
||||
bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line;
|
||||
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"
|
||||
// Options are:
|
||||
// * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
|
||||
|
@ -74,14 +74,15 @@ class Xomw_lnki_wkr__fxt {
|
||||
private final Xomw_lnki_wkr wkr;
|
||||
private final XomwParserCtx pctx;
|
||||
private final XomwParserBfr pbfr = new XomwParserBfr();
|
||||
private final XomwParserEnv env;
|
||||
private final XomwEnv env;
|
||||
private final XomwFileFinderMock file_finder;
|
||||
private final XomwFileRepo repo = new XomwFileRepo(Bry_.new_a7("/orig"), Bry_.new_a7("/thumb"));
|
||||
private boolean apos = true;
|
||||
public Xomw_lnki_wkr__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
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();
|
||||
|
||||
// env
|
||||
@ -95,7 +96,7 @@ class Xomw_lnki_wkr__fxt {
|
||||
|
||||
// ctx
|
||||
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() {
|
||||
wkr.Clear_state();
|
||||
|
@ -70,8 +70,8 @@ class Xomw_magiclinks_wkr__fxt {
|
||||
private final XomwParserBfr pbfr = new XomwParserBfr();
|
||||
public Xomw_magiclinks_wkr__fxt() {
|
||||
Xomw_regex_space regex_space = new Xomw_regex_space();
|
||||
pctx.Init_by_page(XomwTitle.newFromText(Bry_.new_a7("Page_1")));
|
||||
XomwParser parser = new XomwParser();
|
||||
XomwParser parser = new XomwParser(XomwEnv.NewTest());
|
||||
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));
|
||||
wkr.Init_by_wiki();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class Xomw_table_wkr__fxt {
|
||||
private final XomwParserCtx pctx = new XomwParserCtx();
|
||||
private final Xomw_table_wkr wkr;
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -233,6 +233,7 @@ public class XomwMediaWikiTitleCodec implements XomwTitleFormatter {
|
||||
* @return array A map with the fields 'interwiki', 'fragment', 'namespace',
|
||||
* 'user_case_dbkey', and 'dbkey'.
|
||||
*/
|
||||
// private final byte[][] tmpPrefixRegex = new byte[2][];
|
||||
public XomwMediaWikiTitleCodecParts splitTitleString(byte[] text, int defaultNamespace) {
|
||||
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;
|
||||
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 {
|
||||
// $m = [];
|
||||
// if (preg_match($prefixRegexp, dbkey, $m)) {
|
||||
|
@ -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
|
||||
*/
|
||||
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.langs.*;
|
||||
public class XomwLanguage {
|
||||
// /**
|
||||
// * @var LanguageConverter
|
||||
@ -30,7 +30,7 @@ public class XomwLanguage {
|
||||
// public $mExtendedSpecialPageAliases;
|
||||
//
|
||||
// /** @var array|null */
|
||||
private HashByInt namespaceNames;
|
||||
private XomwNamespaceHash namespaceNames;
|
||||
// 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';
|
||||
// // @codeCoverageIgnoreEnd
|
||||
// // @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
|
||||
// * @param String $code
|
||||
@ -430,7 +432,7 @@ public class XomwLanguage {
|
||||
// }
|
||||
// return self::$dataCache;
|
||||
// }
|
||||
//
|
||||
|
||||
// function __construct() {
|
||||
// this.mConverter = new FakeConverter($this);
|
||||
// // Set the code to the name of the descendant
|
||||
@ -441,7 +443,10 @@ public class XomwLanguage {
|
||||
// }
|
||||
// self::getLocalisationCache();
|
||||
// }
|
||||
//
|
||||
public XomwLanguage(Xol_lang_itm xoLang) {
|
||||
this.xoLang = xoLang;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Reduce memory usage
|
||||
// */
|
||||
@ -480,11 +485,11 @@ public class XomwLanguage {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public HashByInt getNamespaces() {
|
||||
public XomwNamespaceHash getNamespaces() {
|
||||
if (this.namespaceNames == null) {
|
||||
// global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces;
|
||||
//
|
||||
HashByInt validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
||||
XomwNamespaceHash validNamespaces = XomwNamespace.getCanonicalNamespaces();
|
||||
//
|
||||
// this.namespaceNames = $wgExtraNamespaces +
|
||||
// self::$dataCache->getItem(this.mCode, 'namespaceNames');
|
||||
@ -561,8 +566,8 @@ public class XomwLanguage {
|
||||
* @return String|boolean String if the namespace value exists, otherwise false
|
||||
*/
|
||||
public byte[] getNsText(int index) {
|
||||
HashByInt ns = this.getNamespaces();
|
||||
return (byte[])ns.Get_by_or_null(index);
|
||||
XomwNamespaceHash nsHash = this.getNamespaces();
|
||||
return nsHash.GetTextOrNull(index);
|
||||
}
|
||||
|
||||
// /**
|
||||
@ -705,24 +710,25 @@ public class XomwLanguage {
|
||||
// }
|
||||
// return this.mNamespaceIds;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get a namespace key by value, case insensitive. Canonical namespace
|
||||
// * names override custom ones defined for the current language.
|
||||
// *
|
||||
// * @param String $text
|
||||
// * @return int|boolean An integer if $text is a valid value otherwise false
|
||||
// */
|
||||
// public function getNsIndex($text) {
|
||||
// $lctext = this.lc($text);
|
||||
// $ns = XomwNamespace::getCanonicalIndex($lctext);
|
||||
// if ($ns !== null) {
|
||||
// return $ns;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get a namespace key by value, case insensitive. Canonical namespace
|
||||
* @Override names custom ones defined for the current language.
|
||||
*
|
||||
* @param String $text
|
||||
* @return int|boolean An integer if $text is a valid value otherwise false
|
||||
*/
|
||||
public int getNsIndex(byte[] text) {
|
||||
byte[] lctext = this.lc(text);
|
||||
int ns = XomwNamespace.getCanonicalIndex(lctext);
|
||||
if (ns != XomwNamespace.NULL_NS_ID) {
|
||||
return ns;
|
||||
}
|
||||
// $ids = this.getNamespaceIds();
|
||||
// return isset($ids[$lctext]) ? $ids[$lctext] : false;
|
||||
// }
|
||||
//
|
||||
return XophpUtility.Null_int;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * short names for language variants used for language conversion links.
|
||||
// *
|
||||
@ -2710,24 +2716,30 @@ public class XomwLanguage {
|
||||
// return $str;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param String $str
|
||||
// * @param boolean $first
|
||||
// * @return mixed|String
|
||||
// */
|
||||
// function lc($str, $first = false) {
|
||||
// if ($first) {
|
||||
// if (this.isMultibyte($str)) {
|
||||
// return mb_strtolower(mb_substr($str, 0, 1)) . mb_substr($str, 1);
|
||||
|
||||
/**
|
||||
* @param String $str
|
||||
* @param boolean $first
|
||||
* @return mixed|String
|
||||
*/
|
||||
private byte[] lc(byte[] str) {return lc(str, false);}
|
||||
private byte[] lc(byte[] str, boolean first) {
|
||||
return first
|
||||
? xoLang.Case_mgr().Case_build_1st_lower(tmpBfr, str, 0, str.length)
|
||||
: xoLang.Case_mgr().Case_build_lower (str, 0, str.length);
|
||||
// XO.MW:PORTED
|
||||
// if (first) {
|
||||
// if (this.isMultibyte(str)) {
|
||||
// return mb_strtolower(mb_substr(str, 0, 1)) . mb_substr(str, 1);
|
||||
// } else {
|
||||
// return strtolower(substr($str, 0, 1)) . substr($str, 1);
|
||||
// return strtolower(substr(str, 0, 1)) . substr(str, 1);
|
||||
// }
|
||||
// } else {
|
||||
// return this.isMultibyte($str) ? mb_strtolower($str) : strtolower($str);
|
||||
// return this.isMultibyte(str) ? mb_strtolower(str) : strtolower(str);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param String $str
|
||||
// * @return boolean
|
||||
|
Loading…
Reference in New Issue
Block a user