1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Xomw: Convert Xoa_ttl to Xomw_Title

This commit is contained in:
gnosygnu
2017-02-11 09:55:27 -05:00
parent 8bc1a37531
commit 451c504166
17 changed files with 157 additions and 162 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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" )

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();