mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-09-28 14:30:51 +00:00
Xomw: Convert Xoa_ttl to Xomw_Title
This commit is contained in:
parent
8bc1a37531
commit
451c504166
@ -798,16 +798,16 @@ public class Xomw_Title {
|
||||
return this.mInterwiki != Bry_.Empty;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the interwiki prefix
|
||||
// *
|
||||
// * Use Title::isExternal to check if a interwiki is set
|
||||
// *
|
||||
// * @return String Interwiki prefix
|
||||
// */
|
||||
// public function getInterwiki() {
|
||||
// return this.mInterwiki;
|
||||
// }
|
||||
/**
|
||||
* Get the interwiki prefix
|
||||
*
|
||||
* Use Title::isExternal to check if a interwiki is set
|
||||
*
|
||||
* @return String Interwiki prefix
|
||||
*/
|
||||
public byte[] getInterwiki() {
|
||||
return this.mInterwiki;
|
||||
}
|
||||
|
||||
/**
|
||||
* Was this a local interwiki link?
|
||||
@ -889,16 +889,16 @@ public class Xomw_Title {
|
||||
// public function getPartialURL() {
|
||||
// return this.mUrlform;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get the main part with underscores
|
||||
// *
|
||||
// * @return String Main part of the title, with underscores
|
||||
// */
|
||||
// public function getDBkey() {
|
||||
// return this.mDbkeyform;
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* Get the main part with underscores
|
||||
*
|
||||
* @return String Main part of the title, with underscores
|
||||
*/
|
||||
public byte[] getDBkey() {
|
||||
return this.mDbkeyform;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the DB key with the initial letter case as specified by the user
|
||||
// *
|
||||
@ -912,16 +912,16 @@ public class Xomw_Title {
|
||||
// return this.mDbkeyform;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get the namespace index, i.e. one of the NS_xxxx constants.
|
||||
// *
|
||||
// * @return int Namespace index
|
||||
// */
|
||||
// public function getNamespace() {
|
||||
// return this.mNamespace;
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* Get the namespace index, i.e. one of the NS_xxxx constants.
|
||||
*
|
||||
* @return int Namespace index
|
||||
*/
|
||||
public int getNamespace() {
|
||||
return this.mNamespace;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the page's content model id, see the CONTENT_MODEL_XXX constants.
|
||||
// *
|
||||
@ -1391,22 +1391,23 @@ public class Xomw_Title {
|
||||
// public function setFragment($fragment) {
|
||||
// this.mFragment = strtr(substr($fragment, 1), '_', ' ');
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Creates a new Title for a different fragment of the same page.
|
||||
// *
|
||||
// * @since 1.27
|
||||
// * @param String $fragment
|
||||
// * @return Title
|
||||
// */
|
||||
// public function createFragmentTarget($fragment) {
|
||||
|
||||
/**
|
||||
* Creates a new Title for a different fragment of the same page.
|
||||
*
|
||||
* @since 1.27
|
||||
* @param String $fragment
|
||||
* @return Title
|
||||
*/
|
||||
public Xomw_Title createFragmentTarget(byte[] fragment) {
|
||||
return null;
|
||||
// return self::makeTitle(
|
||||
// this.getNamespace(),
|
||||
// this.getText(),
|
||||
// $fragment,
|
||||
// this.getInterwiki()
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix some arbitrary text with the namespace or interwiki prefix
|
||||
@ -1808,7 +1809,7 @@ public class Xomw_Title {
|
||||
// $ret = this.getLocalURL($query, $query2) . this.getFragmentForURL();
|
||||
// }
|
||||
// return $ret;
|
||||
return Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, this.mPrefixedText);
|
||||
return Bry_.Add(gplx.xowa.htmls.hrefs.Xoh_href_.Bry__wiki, this.getPrefixedText());
|
||||
}
|
||||
|
||||
// /**
|
||||
@ -4219,20 +4220,20 @@ public class Xomw_Title {
|
||||
// $authors = this.getAuthorsBetween($old, $new, $limit, $options);
|
||||
// return $authors ? count($authors) : 0;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Compare with another title.
|
||||
// *
|
||||
// * @param Title $title
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function equals(Title $title) {
|
||||
// // Note: == is necessary for proper matching of number-like titles.
|
||||
// return this.getInterwiki() == $title.getInterwiki()
|
||||
// && this.getNamespace() == $title.getNamespace()
|
||||
// && this.getDBkey() == $title.getDBkey();
|
||||
// }
|
||||
//
|
||||
|
||||
/**
|
||||
* Compare with another title.
|
||||
*
|
||||
* @param Title $title
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean equals(Xomw_Title title) {
|
||||
// Note: == is necessary for proper matching of number-like titles.
|
||||
return Bry_.Eq(this.getInterwiki(), title.getInterwiki())
|
||||
&& this.getNamespace() == title.getNamespace()
|
||||
&& Bry_.Eq(this.getDBkey(), title.getDBkey());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Check if this title is a subpage of another title
|
||||
// *
|
||||
@ -4320,22 +4321,23 @@ public class Xomw_Title {
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
//
|
||||
// /**
|
||||
// * Does this title refer to a page that can (or might) be meaningfully
|
||||
// * viewed? In particular, this function may be used to determine if
|
||||
// * links to the title should be rendered as "bluelinks" (as opposed to
|
||||
// * "redlinks" to non-existent pages).
|
||||
// * Adding something else to this function will cause inconsistency
|
||||
// * since LinkHolderArray calls isAlwaysKnown() and does its own
|
||||
// * page existence check.
|
||||
// *
|
||||
// * @return boolean
|
||||
// */
|
||||
// public function isKnown() {
|
||||
|
||||
/**
|
||||
* Does this title refer to a page that can (or might) be meaningfully
|
||||
* viewed? In particular, this function may be used to determine if
|
||||
* links to the title should be rendered as "bluelinks" (as opposed to
|
||||
* "redlinks" to non-existent pages).
|
||||
* Adding something else to this function will cause inconsistency
|
||||
* since LinkHolderArray calls isAlwaysKnown() and does its own
|
||||
* page existence check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isKnown() {
|
||||
// return this.isAlwaysKnown() || this.exists();
|
||||
// }
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Does this page have source text?
|
||||
// *
|
||||
|
@ -127,7 +127,7 @@ public class Xomw_linker {
|
||||
// 'https': Force a full URL with https:// as the scheme.
|
||||
// 'stubThreshold' => (int): Stub threshold to use when determining link classes.
|
||||
// @return String HTML <a> attribute
|
||||
public void Link(Bry_bfr bfr, Xoa_ttl target, byte[] html, Xomw_atr_mgr custom_attribs, Xomw_qry_mgr query, Xomw_opt_mgr options) {
|
||||
public void Link(Bry_bfr bfr, Xomw_Title target, byte[] html, Xomw_atr_mgr custom_attribs, Xomw_qry_mgr query, Xomw_opt_mgr options) {
|
||||
// XO.MW.UNSUPPORTED:MW has different renderers -- presumably for forcing "https:" and others; XO only has one
|
||||
//if (options != null) {
|
||||
// // Custom options, create new LinkRenderer
|
||||
@ -193,10 +193,10 @@ public class Xomw_linker {
|
||||
* @return String
|
||||
*/
|
||||
// XO.MW:SYNC:1.29; DATE:2017-02-08
|
||||
public void makeSelfLinkObj(Bry_bfr bfr, Xoa_ttl nt, byte[] html, byte[] query, byte[] trail, byte[] prefix) {
|
||||
public void makeSelfLinkObj(Bry_bfr bfr, Xomw_Title nt, byte[] html, byte[] query, byte[] trail, byte[] prefix) {
|
||||
// MW.HOOK:SelfLinkBegin
|
||||
if (html == Bry_.Empty) {
|
||||
html = tmp.Add_bry_escape_html(nt.Get_prefixed_text()).To_bry_and_clear();
|
||||
html = tmp.Add_bry_escape_html(nt.getPrefixedText()).To_bry_and_clear();
|
||||
}
|
||||
byte[] inside = Bry_.Empty;
|
||||
byte[][] split_trail = splitTrail(trail);
|
||||
@ -239,7 +239,7 @@ public class Xomw_linker {
|
||||
// * @param LinkTarget $target
|
||||
// * @return LinkTarget
|
||||
// */
|
||||
public static Xoa_ttl normaliseSpecialPage(Xoa_ttl target) {
|
||||
public static Xomw_Title normaliseSpecialPage(Xomw_Title target) {
|
||||
// if (target.Ns().Id_is_special() && !target.Is_external()) {
|
||||
// list($name, $subpage) = SpecialPageFactory::resolveAlias($target->getDBkey());
|
||||
// if (!$name) {
|
||||
@ -334,7 +334,7 @@ public class Xomw_linker {
|
||||
// @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, Xomw_parser_ctx pctx, Xomw_parser parser, Xoa_ttl title, Xomw_File file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query, int widthOption) {
|
||||
public void makeImageLink(Bry_bfr bfr, Xomw_parser_ctx pctx, Xomw_parser parser, Xomw_Title title, Xomw_File file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query, int widthOption) {
|
||||
Xomw_parser_env env = parser.Env();
|
||||
// XO.MW.HOOK:ImageBeforeProduceHTML
|
||||
|
||||
@ -538,7 +538,7 @@ public class Xomw_linker {
|
||||
* @return String
|
||||
*/
|
||||
// XO.MW:SYNC:1.29; DATE:2017-02-08
|
||||
private void makeThumbLink2(Bry_bfr bfr, Xomw_parser_ctx pctx, Xoa_ttl title, Xomw_File file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query) {
|
||||
private void makeThumbLink2(Bry_bfr bfr, Xomw_parser_ctx pctx, Xomw_Title title, Xomw_File file, Xomw_params_frame frameParams, Xomw_params_handler handlerParams, Object time, byte[] query) {
|
||||
boolean exists = file != null && file.exists();
|
||||
|
||||
int page = handlerParams.page;
|
||||
@ -1372,7 +1372,7 @@ public class Xomw_linker {
|
||||
* @return String
|
||||
*/
|
||||
// XO.MW:SYNC:1.29; DATE:2017-02-08
|
||||
public void normalizeSubpageLink(Xomw_linker__normalize_subpage_link rv, Xoa_ttl context_title, byte[] target, byte[] text) {
|
||||
public void normalizeSubpageLink(Xomw_linker__normalize_subpage_link rv, Xomw_Title context_title, byte[] target, byte[] text) {
|
||||
// Valid link forms:
|
||||
// Foobar -- normal
|
||||
// :Foobar -- override special treatment of prefix (images, language links)
|
||||
@ -1388,7 +1388,7 @@ public class Xomw_linker {
|
||||
|
||||
// Some namespaces don't allow subpages,
|
||||
// so only perform processing if subpages are allowed
|
||||
if (context_title != null && context_title.Ns().Subpages_enabled()) {
|
||||
if (context_title != null) {// && context_title.Ns().Subpages_enabled()) {
|
||||
int hash = Bry_find_.Find_fwd(target, Byte_ascii.Hash);
|
||||
byte[] suffix = null;
|
||||
if (hash != Bry_find_.Not_found) {
|
||||
@ -1413,7 +1413,7 @@ public class Xomw_linker {
|
||||
no_slash = Bry_.Mid(target, 1);
|
||||
}
|
||||
|
||||
ret = Bry_.Add(context_title.Get_prefixed_text(), Byte_ascii.Slash_bry, Bry_.Trim(no_slash), suffix);
|
||||
ret = Bry_.Add(context_title.getPrefixedText(), Byte_ascii.Slash_bry, Bry_.Trim(no_slash), suffix);
|
||||
if (text == Bry_.Empty) {
|
||||
text = Bry_.Add(target, suffix);
|
||||
} // this might be changed for ugliness reasons
|
||||
@ -1427,7 +1427,7 @@ public class Xomw_linker {
|
||||
dot2_stripped = Bry_.Mid(dot2_stripped, 3);
|
||||
}
|
||||
if (dot2_count > 0) {
|
||||
byte[][] exploded = Bry_split_.Split(context_title.Get_prefixed_text(), Byte_ascii.Slash);
|
||||
byte[][] exploded = Bry_split_.Split(context_title.getPrefixedText(), Byte_ascii.Slash);
|
||||
int exploded_len = exploded.length;
|
||||
if (exploded_len > dot2_count) { // not allowed to go below top level page
|
||||
// PORTED: ret = implode('/', array_slice($exploded, 0, -dot2_count));
|
||||
|
@ -29,14 +29,9 @@ public class Xomw_linker__normalize_subpage_link__tst {
|
||||
}
|
||||
class Xomw_linker__normalize_subpage_link__fxt {
|
||||
private final Xomw_linker mgr = new Xomw_linker(new gplx.xowa.mediawiki.includes.linkers.Xomw_link_renderer(new Xomw_sanitizer()));
|
||||
private final Xowe_wiki wiki;
|
||||
private final Xomw_linker__normalize_subpage_link normalize_subpage_link = new Xomw_linker__normalize_subpage_link();
|
||||
public Xomw_linker__normalize_subpage_link__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
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, wiki.Ttl_parse(Bry_.new_u8(page_title_str)), Bry_.new_u8(link), Bry_.new_u8(text));
|
||||
mgr.normalizeSubpageLink(normalize_subpage_link, Xomw_Title.newFromText(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));
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.*;
|
||||
public interface Xomw_file_finder {
|
||||
Xomw_File Find_file(Xoa_ttl ttl);
|
||||
Xomw_File Find_file(Xomw_Title ttl);
|
||||
}
|
||||
|
@ -20,13 +20,14 @@ import gplx.xowa.mediawiki.includes.parsers.*;
|
||||
public class Xomw_file_finder__mock implements Xomw_file_finder {
|
||||
private final Xomw_parser_env env;
|
||||
public Xomw_file_finder__mock(Xomw_parser_env env) {this.env = env;}
|
||||
private final Hash_adp hash = Hash_adp_.New();
|
||||
private final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public void Clear() {hash.Clear();}
|
||||
public Xomw_File Find_file(Xoa_ttl ttl) {
|
||||
return (Xomw_File)hash.Get_by(ttl.Page_db_as_str());
|
||||
public Xomw_File Find_file(Xomw_Title ttl) {
|
||||
return (Xomw_File)hash.Get_by(ttl.getPrefixedDBkey());
|
||||
}
|
||||
public void Add(String title, Xomw_FileRepo repo, int w, int h, byte[] mime) {
|
||||
Xomw_LocalFile file = new Xomw_LocalFile(env, Bry_.new_u8(title), repo, w, h, mime);
|
||||
hash.Add_if_dupe_use_nth(title, file);
|
||||
byte[] title_bry = Bry_.new_u8(title);
|
||||
Xomw_LocalFile file = new Xomw_LocalFile(env, title_bry, repo, w, h, mime);
|
||||
hash.Add_if_dupe_use_nth(title_bry, file);
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.*;
|
||||
public class Xomw_file_finder__noop implements Xomw_file_finder {
|
||||
public Xomw_File Find_file(Xoa_ttl ttl) {return null;}
|
||||
public Xomw_File Find_file(Xomw_Title ttl) {return null;}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public class Xomw_link_renderer {
|
||||
this.sanitizer = sanitizer;
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
public void Make_link(Bry_bfr bfr, Xoa_ttl target, byte[] text, byte[] classes, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
if (target.Is_known()) {
|
||||
public void Make_link(Bry_bfr bfr, Xomw_Title target, byte[] text, byte[] classes, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
if (target.isKnown()) {
|
||||
this.Make_known_link(bfr, target, text, extra_atrs, query);
|
||||
} else {
|
||||
this.Make_broken_link(bfr, target, text, extra_atrs, query);
|
||||
@ -45,7 +45,7 @@ public class Xomw_link_renderer {
|
||||
// If you have already looked up the proper CSS classes using LinkRenderer::getLinkClasses()
|
||||
// or some other method, use this to avoid looking it up again.
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
public void Make_preloaded_link(Bry_bfr bfr, Xoa_ttl target, byte[] text, byte[] classes, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
public void Make_preloaded_link(Bry_bfr bfr, Xomw_Title target, byte[] text, byte[] classes, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
// XO.MW.HOOK: $this->runBeginHook --> 'HtmlPageLinkRendererBegin', 'LinkBegin'
|
||||
|
||||
target = Normalize_target(target);
|
||||
@ -54,7 +54,7 @@ public class Xomw_link_renderer {
|
||||
attribs.Add(Gfh_atr_.Bry__href, url); // XO.MW: add url 1st; MW does attribs["url", url] + attribs + extra_attribs
|
||||
if (classes.length > 0) // XO.MW:do not bother adding if empty
|
||||
attribs.Add(Gfh_atr_.Bry__class, classes);
|
||||
byte[] prefixed_text = target.Get_prefixed_text();
|
||||
byte[] prefixed_text = target.getPrefixedText();
|
||||
if (prefixed_text != Bry_.Empty) {
|
||||
attribs.Add(Gfh_atr_.Bry__title, prefixed_text);
|
||||
}
|
||||
@ -69,9 +69,9 @@ public class Xomw_link_renderer {
|
||||
}
|
||||
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
public void Make_known_link(Bry_bfr bfr, Xoa_ttl target, byte[] text, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
public void Make_known_link(Bry_bfr bfr, Xomw_Title target, byte[] text, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
byte[] classes = Bry_.Empty;
|
||||
if (target.Is_external()) {
|
||||
if (target.isExternal()) {
|
||||
classes = Bry__classes__extiw;
|
||||
}
|
||||
byte[] colour = Get_link_classes(target);
|
||||
@ -82,17 +82,17 @@ public class Xomw_link_renderer {
|
||||
Make_preloaded_link(bfr, target, text, classes, extra_atrs, query);
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
public void Make_broken_link(Bry_bfr bfr, Xoa_ttl target, byte[] text, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
public void Make_broken_link(Bry_bfr bfr, Xomw_Title target, byte[] text, Xomw_atr_mgr extra_atrs, Xomw_qry_mgr query) {
|
||||
// XO.MW.HOOK: Run legacy hook
|
||||
|
||||
// We don't want to include fragments for broken links, because they
|
||||
// generally make no sense.
|
||||
if (target.Has_fragment()) {
|
||||
target = target.Create_fragment_target();
|
||||
if (target.hasFragment()) {
|
||||
target = target.createFragmentTarget(target.getFragment());
|
||||
}
|
||||
target = Normalize_target(target);
|
||||
|
||||
if (query.action == null && target.Ns().Id() != gplx.xowa.wikis.nss.Xow_ns_.Tid__special) {
|
||||
if (query.action == null && target.getNamespace() != Xomw_Defines.NS_SPECIAL) {
|
||||
query.action = Bry_.new_a7("edit");
|
||||
query.redlink = 1;
|
||||
}
|
||||
@ -118,7 +118,7 @@ public class Xomw_link_renderer {
|
||||
Build_a_element(bfr, target, text, attribs, false);
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
private void Build_a_element(Bry_bfr bfr, Xoa_ttl target, byte[] text, Xomw_atr_mgr attribs, boolean is_known) {
|
||||
private void Build_a_element(Bry_bfr bfr, Xomw_Title target, byte[] text, Xomw_atr_mgr attribs, boolean is_known) {
|
||||
// XO.MW.HOOK:HtmlPageLinkRendererEnd
|
||||
|
||||
byte[] html = text;
|
||||
@ -129,16 +129,16 @@ public class Xomw_link_renderer {
|
||||
html_utl.Raw_element(bfr, Gfh_tag_.Bry__a, attribs, html);
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
private byte[] Get_link_text(Xoa_ttl target) {
|
||||
byte[] prefixed_text = target.Get_prefixed_text();
|
||||
private byte[] Get_link_text(Xomw_Title target) {
|
||||
byte[] prefixed_text = target.getPrefixedText();
|
||||
// If the target is just a fragment, with no title, we return the fragment
|
||||
// text. Otherwise, we return the title text itself.
|
||||
if (prefixed_text == Bry_.Empty && target.Has_fragment()) {
|
||||
return target.Get_fragment();
|
||||
if (prefixed_text == Bry_.Empty && target.hasFragment()) {
|
||||
return target.getFragment();
|
||||
}
|
||||
return prefixed_text;
|
||||
}
|
||||
private byte[] Get_link_url(Xoa_ttl target, Xomw_qry_mgr query) {
|
||||
private byte[] Get_link_url(Xomw_Title target, Xomw_qry_mgr query) {
|
||||
// TODO: Use a LinkTargetResolver service instead of Title
|
||||
|
||||
// if ($this->forceArticlePath) {
|
||||
@ -148,7 +148,7 @@ public class Xomw_link_renderer {
|
||||
// else {
|
||||
// $realQuery = [];
|
||||
// }
|
||||
byte[] url = target.Get_link_url(query, false, expand_urls);
|
||||
byte[] url = target.getLinkURL(query, false, expand_urls);
|
||||
|
||||
// if ($this->forceArticlePath && $realQuery) {
|
||||
// $url = wfAppendQuery($url, $realQuery);
|
||||
@ -156,7 +156,7 @@ public class Xomw_link_renderer {
|
||||
return url;
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-01-31
|
||||
private Xoa_ttl Normalize_target(Xoa_ttl target) {
|
||||
private Xomw_Title Normalize_target(Xomw_Title target) {
|
||||
return Xomw_linker.normaliseSpecialPage(target);
|
||||
}
|
||||
// XO.MW:SYNC:1.29; DATE:2017-02-01
|
||||
@ -188,7 +188,7 @@ public class Xomw_link_renderer {
|
||||
tmp_merge_deleted.Clear();
|
||||
}
|
||||
}
|
||||
public byte[] Get_link_classes(Xoa_ttl target) {
|
||||
public byte[] Get_link_classes(Xomw_Title target) {
|
||||
// Make sure the target is in the cache
|
||||
// $id = $this->linkCache->addLinkObj($target);
|
||||
// if ($id == 0) {
|
||||
|
@ -36,7 +36,7 @@ public class Xomw_link_holders {
|
||||
|
||||
link_id = 0;
|
||||
}
|
||||
public void Make_holder(Bry_bfr bfr, Xoa_ttl nt, byte[] text, byte[][] query, byte[] trail, byte[] prefix) {
|
||||
public void Make_holder(Bry_bfr bfr, Xomw_Title nt, byte[] text, byte[][] query, byte[] trail, byte[] prefix) {
|
||||
if (nt == null) {
|
||||
// Fail gracefully
|
||||
bfr.Add_str_a7("<!-- ERROR -->").Add(prefix).Add(text).Add(trail);
|
||||
@ -62,7 +62,7 @@ public class Xomw_link_holders {
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Test__add(Xoa_ttl ttl, byte[] capt) {
|
||||
public void Test__add(Xomw_Title ttl, byte[] capt) {
|
||||
int key = link_id++;
|
||||
Xomw_link_holder_item item = new Xomw_link_holder_item(ttl, capt, Bry_.Ary_empty);
|
||||
internals.Add(key, item);
|
||||
@ -239,13 +239,13 @@ class Xomw_link_holder_list {
|
||||
public Xomw_link_holder_item Get_by(int key) {return ary[key];}
|
||||
}
|
||||
class Xomw_link_holder_item {
|
||||
public Xomw_link_holder_item(Xoa_ttl title, byte[] text, byte[][] query) {
|
||||
public Xomw_link_holder_item(Xomw_Title title, byte[] text, byte[][] query) {
|
||||
this.title = title;
|
||||
this.text = text;
|
||||
this.query = query;
|
||||
}
|
||||
public Xoa_ttl Title() {return title;} private final Xoa_ttl title;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public byte[] Pdbk() {return title.Get_prefixed_db_key();}
|
||||
public byte[][] Query() {return query;} private final byte[][] query;
|
||||
public Xomw_Title Title() {return title;} private final Xomw_Title title;
|
||||
public byte[] Text() {return text;} private final byte[] text;
|
||||
public byte[] Pdbk() {return title.getPrefixedDBkey();}
|
||||
public byte[][] Query() {return query;} private final byte[][] query;
|
||||
}
|
||||
|
@ -28,14 +28,11 @@ public class Xomw_link_holders__tst {
|
||||
class Xomw_link_holders__fxt {
|
||||
private final Xomw_link_holders holders = new Xomw_link_holders(new Xomw_link_renderer(new Xomw_sanitizer()), Bry_bfr_.New());
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
private final Xowe_wiki wiki;
|
||||
private boolean apos = true;
|
||||
public Xomw_link_holders__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
this.wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
}
|
||||
public void Init__add(String ttl, String capt) {
|
||||
holders.Test__add(wiki.Ttl_parse(Bry_.new_u8(ttl)), Bry_.new_u8(capt));
|
||||
holders.Test__add(Xomw_Title.newFromText(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);
|
||||
|
@ -81,7 +81,7 @@ public class Xomw_parser {
|
||||
doubleunder_wkr.Init_by_wiki(doubleunder_data, wiki.Lang());
|
||||
magiclinks_wkr.Init_by_wiki();
|
||||
}
|
||||
public void Init_by_page(Xoa_ttl ttl) {
|
||||
public void Init_by_page(Xomw_Title ttl) {
|
||||
pctx.Init_by_page(ttl);
|
||||
}
|
||||
public void Internal_parse(Xomw_parser_bfr pbfr, byte[] text) {
|
||||
|
@ -66,7 +66,7 @@ class Xomw_parser__fxt {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
mgr.Init_by_wiki(wiki);
|
||||
mgr.Init_by_page(wiki.Ttl_parse(Bry_.new_a7("Page_1")));
|
||||
mgr.Init_by_page(Xomw_Title.newFromText(Bry_.new_a7("Page_1")));
|
||||
}
|
||||
public void Test__parse(String src_str, String expd) {
|
||||
byte[] src_bry = Bry_.new_u8(src_str);
|
||||
|
@ -18,13 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package gplx.xowa.mediawiki.includes.parsers; import gplx.*; import gplx.xowa.*; import gplx.xowa.mediawiki.*; import gplx.xowa.mediawiki.includes.*;
|
||||
import gplx.xowa.mediawiki.includes.parsers.lnkis.*;
|
||||
public class Xomw_parser_ctx {
|
||||
public Xoa_ttl Page_title() {return page_title;} private Xoa_ttl page_title;
|
||||
public Xomw_Title Page_title() {return page_title;} private Xomw_Title page_title;
|
||||
public Xomw_image_params Lnki_wkr__make_image__img_params = new Xomw_image_params();
|
||||
public byte[][] Lnki_wkr__make_image__match_magic_word = new byte[2][];
|
||||
public int[] Lnki_wkr__make_image__img_size = new int[2];
|
||||
public Xomw_params_mto Linker__makeImageLink__prms = new Xomw_params_mto();
|
||||
|
||||
public void Init_by_page(Xoa_ttl page_title) {
|
||||
public void Init_by_page(Xomw_Title page_title) {
|
||||
this.page_title = page_title;
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
private final Xomw_strip_state strip_state;
|
||||
private Xomw_parser_env env;
|
||||
private Xow_wiki wiki;
|
||||
private Xoa_ttl page_title;
|
||||
private final Xomw_linker__normalize_subpage_link normalize_subpage_link = new Xomw_linker__normalize_subpage_link();
|
||||
private Xomw_Title mPageTitle;
|
||||
// private final Xomw_linker__normalize_subpage_link normalize_subpage_link = new Xomw_linker__normalize_subpage_link();
|
||||
private final Bry_bfr tmp;
|
||||
private final Xomw_parser parser;
|
||||
private final Xomw_atr_mgr extra_atrs = new Xomw_atr_mgr();
|
||||
@ -88,7 +88,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
Bry_bfr bfr = pbfr.Trg();
|
||||
pbfr.Switch();
|
||||
|
||||
this.page_title = pctx.Page_title();
|
||||
this.mPageTitle = pctx.Page_title();
|
||||
|
||||
Replace_internal_links(pctx, bfr, src, src_bgn, src_end);
|
||||
}
|
||||
@ -254,17 +254,16 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
link = Bry_.Mid(link, 1);
|
||||
}
|
||||
// $nt = is_string( $unstrip ) ? Title::newFromText( $unstrip ) : null;
|
||||
// Xomw_Title nt2 = Xomw_Title.newFromText(link);
|
||||
Xoa_ttl nt = wiki.Ttl_parse(link);
|
||||
Xomw_Title nt = Xomw_Title.newFromText(link);
|
||||
|
||||
// Make subpage if necessary
|
||||
boolean subpages_enabled = nt.Ns().Subpages_enabled();
|
||||
if (subpages_enabled) {
|
||||
Maybe_do_subpage_link(normalize_subpage_link, orig_link, text);
|
||||
link = normalize_subpage_link.link;
|
||||
text = normalize_subpage_link.text;
|
||||
nt = wiki.Ttl_parse(link);
|
||||
}
|
||||
// boolean useSubpages = nt.Ns().Subpages_enabled();
|
||||
// if (useSubpages) {
|
||||
// Maybe_do_subpage_link(normalize_subpage_link, orig_link, text);
|
||||
// link = normalize_subpage_link.link;
|
||||
// text = normalize_subpage_link.text;
|
||||
// nt = Xomw_Title.newFromText(link);
|
||||
// }
|
||||
// IGNORE: handled in rewrite above
|
||||
// else {
|
||||
// link = orig_link;
|
||||
@ -272,18 +271,18 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
|
||||
byte[] unstrip = strip_state.Unstrip_nowiki(link);
|
||||
if (!Bry_.Eq(unstrip, link))
|
||||
nt = wiki.Ttl_parse(unstrip);
|
||||
nt = Xomw_Title.newFromText(unstrip);
|
||||
if (nt == null) {
|
||||
bfr.Add_mid(src, prv, lnki_bgn + 2); // $s .= $prefix . '[[' . $line;
|
||||
prv = cur = lnki_bgn + 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
Xow_ns ns = nt.Ns();
|
||||
Xow_xwiki_itm iw = nt.Wik_itm();
|
||||
byte[] iw = nt.getInterwiki();
|
||||
int ns = nt.getNamespace();
|
||||
|
||||
if (might_be_img) { // if this is actually an invalid link
|
||||
if (ns.Id_is_file() && no_force) { // but might be an image
|
||||
if (ns == Xomw_Defines.NS_FILE && no_force) { // but might be an image
|
||||
boolean found = false;
|
||||
// while (true) {
|
||||
// // look at the next 'line' to see if we can close it there
|
||||
@ -358,7 +357,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
if (ns.Id_is_file()) {
|
||||
if (ns == Xomw_Defines.NS_FILE) {
|
||||
// boolean is_good_image = !wfIsBadImage(nt->getDBkey(), this->mTitle)
|
||||
boolean is_good_image = true;
|
||||
if (is_good_image) {
|
||||
@ -384,7 +383,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (ns.Id_is_ctg()) {
|
||||
else if (ns == Xomw_Defines.NS_CATEGORY) {
|
||||
bfr.Trim_end_ws(); // s = rtrim(s . "\n"); // T2087
|
||||
|
||||
if (was_blank) {
|
||||
@ -408,7 +407,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// Self-link checking. For some languages, variants of the title are checked in
|
||||
// LinkHolderArray::doVariants() to allow batching the existence checks necessary
|
||||
// for linking to a different variant.
|
||||
if (!ns.Id_is_special() && nt.Eq_full_db(page_title) && !nt.Has_fragment()) {
|
||||
if (ns != Xomw_Defines.NS_SPECIAL && nt.equals(mPageTitle) && !nt.hasFragment()) {
|
||||
bfr.Add(prefix);
|
||||
linker.makeSelfLinkObj(bfr, nt, text, Bry_.Empty, trail, Bry_.Empty);
|
||||
continue;
|
||||
@ -416,7 +415,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
|
||||
// NS_MEDIA is a pseudo-namespace for linking directly to a file
|
||||
// @todo FIXME: Should do batch file existence checks, see comment below
|
||||
if (ns.Id_is_media()) {
|
||||
if (ns == Xomw_Defines.NS_MEDIA) {
|
||||
// Give extensions a chance to select the file revision for us
|
||||
// options = [];
|
||||
// desc_query = false;
|
||||
@ -435,7 +434,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
// batch file existence checks for NS_FILE and NS_MEDIA
|
||||
bfr.Add_mid(src, prv, lnki_bgn);
|
||||
prv = cur;
|
||||
if (iw == null && nt.Is_always_known()) {
|
||||
if (iw == null && nt.isAlwaysKnown()) {
|
||||
// this->mOutput->addLink(nt);
|
||||
Make_known_link_holder(bfr, nt, text, trail, prefix);
|
||||
}
|
||||
@ -445,7 +444,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
}
|
||||
}
|
||||
}
|
||||
public void makeImage(Xomw_parser_ctx pctx, Bry_bfr bfr, Xoa_ttl title, byte[] options_at_link, Xomw_link_holders holders) {
|
||||
public void makeImage(Xomw_parser_ctx pctx, Bry_bfr bfr, Xomw_Title title, byte[] options_at_link, Xomw_link_holders holders) {
|
||||
// Check if the options text is of the form "options|alt text"
|
||||
// Options are:
|
||||
// * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
|
||||
@ -643,7 +642,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
if (caption == Bry_.Empty && frameParams.alt == null) {
|
||||
// No caption or alt text, add the filename as the alt text so
|
||||
// that screen readers at least get some description of the image
|
||||
frameParams.alt = title.Get_text();
|
||||
frameParams.alt = title.getText();
|
||||
}
|
||||
// Do not set $params['frame']['title'] because tooltips don't make sense
|
||||
// for framed images
|
||||
@ -657,7 +656,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
else {
|
||||
// No caption, fall back to using the filename for the
|
||||
// alt text
|
||||
frameParams.alt = title.Get_text();
|
||||
frameParams.alt = title.getText();
|
||||
}
|
||||
}
|
||||
// Use the "caption" for the tooltip text
|
||||
@ -778,7 +777,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
* @param array $options Array of options to RepoGroup::findFile
|
||||
* @return array ( File or false, Title of file )
|
||||
*/
|
||||
public Xomw_File fetchFileAndTitle(Xoa_ttl title, Hash_adp options) {
|
||||
public Xomw_File fetchFileAndTitle(Xomw_Title title, Hash_adp options) {
|
||||
Xomw_File file = fetchFileNoRegister(title, options);
|
||||
|
||||
//$time = $file ? $file->getTimestamp() : false;
|
||||
@ -802,7 +801,7 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
* @param array $options Array of options to RepoGroup::findFile
|
||||
* @return File|boolean
|
||||
*/
|
||||
private Xomw_File fetchFileNoRegister(Xoa_ttl title, Hash_adp options) {
|
||||
private Xomw_File fetchFileNoRegister(Xomw_Title title, Hash_adp options) {
|
||||
Xomw_File file = null;
|
||||
// if ( isset( $options['broken'] ) ) {
|
||||
// file = false; // broken thumbnail forced by hook
|
||||
@ -814,18 +813,18 @@ public class Xomw_lnki_wkr {// THREAD.UNSAFE: caching for repeated calls
|
||||
return file;
|
||||
}
|
||||
public void Maybe_do_subpage_link(Xomw_linker__normalize_subpage_link rv, byte[] target, byte[] text) {
|
||||
linker.normalizeSubpageLink(rv, page_title, target, text);
|
||||
linker.normalizeSubpageLink(rv, mPageTitle, target, text);
|
||||
}
|
||||
public void Replace_link_holders(Xomw_parser_ctx pctx, Xomw_parser_bfr pbfr) {
|
||||
holders.Replace(pctx, pbfr);
|
||||
}
|
||||
public void Make_known_link_holder(Bry_bfr bfr, Xoa_ttl nt, byte[] text, byte[] trail, byte[] prefix) {
|
||||
public void Make_known_link_holder(Bry_bfr bfr, Xomw_Title nt, byte[] text, byte[] trail, byte[] prefix) {
|
||||
byte[][] split_trail = linker.splitTrail(trail);
|
||||
byte[] inside = split_trail[0];
|
||||
trail = split_trail[1];
|
||||
|
||||
if (text == Bry_.Empty) {
|
||||
text = Bry_.Escape_html(nt.Get_prefixed_text());
|
||||
text = Bry_.Escape_html(nt.getPrefixedText());
|
||||
}
|
||||
|
||||
// PORTED:new HtmlArmor( "$prefix$text$inside" )
|
||||
|
@ -86,7 +86,7 @@ class Xomw_lnki_wkr__fxt {
|
||||
|
||||
// ctx
|
||||
pctx = new Xomw_parser_ctx();
|
||||
pctx.Init_by_page(wiki.Ttl_parse(Bry_.new_a7("Page_1")));
|
||||
pctx.Init_by_page(Xomw_Title.newFromText(Bry_.new_a7("Page_1")));
|
||||
}
|
||||
public void Clear() {
|
||||
wkr.Clear_state();
|
||||
|
@ -188,7 +188,7 @@ public class Xomw_magiclinks_wkr {
|
||||
else {
|
||||
// handle free
|
||||
if (regex_tid == Regex__free) {
|
||||
this.page_title = pctx.Page_title().Full_db();
|
||||
this.page_title = pctx.Page_title().getPrefixedDBkey();
|
||||
dirty = true;
|
||||
bfr.Add_mid(src, prv, hook_bgn);
|
||||
byte[] url = Bry_.Mid(src, hook_bgn, cur);
|
||||
|
@ -71,11 +71,8 @@ class Xomw_magiclinks_wkr__fxt {
|
||||
private final Xomw_parser_ctx pctx = new Xomw_parser_ctx();
|
||||
private final Xomw_parser_bfr pbfr = new Xomw_parser_bfr();
|
||||
public Xomw_magiclinks_wkr__fxt() {
|
||||
Xoae_app app = Xoa_app_fxt.Make__app__edit();
|
||||
Xowe_wiki wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
|
||||
Xomw_regex_space regex_space = new Xomw_regex_space();
|
||||
pctx.Init_by_page(wiki.Ttl_parse(Bry_.new_a7("Page_1")));
|
||||
pctx.Init_by_page(Xomw_Title.newFromText(Bry_.new_a7("Page_1")));
|
||||
Xomw_parser parser = new Xomw_parser();
|
||||
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();
|
||||
|
@ -273,6 +273,10 @@ public class Xomw_MediaWikiTitleCodec {
|
||||
}
|
||||
|
||||
// Namespace or interwiki prefix
|
||||
if (Bry_.Has_at_bgn(dbkey, Bry_.new_a7("File:"))) {
|
||||
parts.ns = Xomw_Defines.NS_FILE;
|
||||
dbkey = Bry_.Mid(dbkey, 5);
|
||||
}
|
||||
// $prefixRegexp = "/^(.+?)_*:_*(.*)$/S";
|
||||
// do {
|
||||
// $m = [];
|
||||
|
Loading…
Reference in New Issue
Block a user