mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-06-06 01:14:17 +00:00
Hzip: Use canonical name, not local name, for images linking to namespaces in other wikis
This commit is contained in:
parent
02a289dc80
commit
2abefa1ab9
@ -27,9 +27,11 @@ public class Host_eval_wkr implements Bry_eval_wkr {
|
|||||||
int type = hash.Get_as_byte_or(src, args_bgn, args_end, Byte_.Max_value_127);
|
int type = hash.Get_as_byte_or(src, args_bgn, args_end, Byte_.Max_value_127);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type__wiki_abrv:
|
case Type__wiki_abrv:
|
||||||
// handle wikidata separately; DATE:2016-10-19
|
// handle wikidata, commonswiki separately; DATE:2016-10-20
|
||||||
if (String_.Eq(domain_itm.Domain_str(), "www.wikidata.org"))
|
if (String_.Eq(domain_itm.Domain_str(), "www.wikidata.org"))
|
||||||
rv.Add_str_a7("wikidatawiki");
|
rv.Add_str_a7("wikidatawiki");
|
||||||
|
else if (String_.Eq(domain_itm.Domain_str(), "commons.wikimedia.org"))
|
||||||
|
rv.Add_str_a7("commonswiki");
|
||||||
// do not use Abrv_mw(); all other wikis will be "generalized" to their language url; EX:"en.wiktionary.org" -> "enwiki" x> "enwiktionary"
|
// do not use Abrv_mw(); all other wikis will be "generalized" to their language url; EX:"en.wiktionary.org" -> "enwiki" x> "enwiktionary"
|
||||||
else {
|
else {
|
||||||
byte[] lang_key = domain_itm.Lang_orig_key();
|
byte[] lang_key = domain_itm.Lang_orig_key();
|
||||||
|
@ -244,7 +244,11 @@ public class Xoh_img_hzip implements Xoh_hzip_wkr, Gfo_poolable_itm {
|
|||||||
|| href_ns_id != Xow_ns_.Tid__main) { // or if site and !main_ns; handles /site/en.wiktionary.org/wiki/Special:Search but not /site/creativecommons.org/wiki/by/2.5; DATE:2015-12-28
|
|| href_ns_id != Xow_ns_.Tid__main) { // or if site and !main_ns; handles /site/en.wiktionary.org/wiki/Special:Search but not /site/creativecommons.org/wiki/by/2.5; DATE:2015-12-28
|
||||||
if (href_page.length == 0) { // handle invalid titles in link arg; EX:[[File:A.png|link=wikt:]]; PAGE:en.w:List_of_Saint_Petersburg_Metro_stations; DATE:2016-01-04
|
if (href_page.length == 0) { // handle invalid titles in link arg; EX:[[File:A.png|link=wikt:]]; PAGE:en.w:List_of_Saint_Petersburg_Metro_stations; DATE:2016-01-04
|
||||||
Xow_ns href_ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(href_ns_id);
|
Xow_ns href_ns = hctx.Wiki__ttl_parser().Ns_mgr().Ids_get_or_null(href_ns_id);
|
||||||
ttl_full = href_ns.Name_db_w_colon(); // ASSUME:use db_name not ui_name; EX: "Category_talk" vs "Category talk"
|
|
||||||
|
// 2 notes:
|
||||||
|
// (1) use db_name not ui_name; EX: "Category_talk" vs "Category talk"
|
||||||
|
// (2) use canonical name, not local name; EX: "Help:A" not "Aide:A"; DATE:2016-10-28
|
||||||
|
ttl_full = Xow_ns_canonical_.To_canonical_or_local_as_bry_w_colon(href_ns);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (anch__ns_is_custom) // handle ns aliases; EX: "Image:Page"; EX:WP; PAGE:en.w:Wikipedia:WikiProject_Molecular_and_Cell_Biology; DATE:2016-01-11
|
if (anch__ns_is_custom) // handle ns aliases; EX: "Image:Page"; EX:WP; PAGE:en.w:Wikipedia:WikiProject_Molecular_and_Cell_Biology; DATE:2016-01-11
|
||||||
|
@ -108,4 +108,12 @@ public class Xoh_img_hzip__dump__link__tst {
|
|||||||
, "</a>"
|
, "</a>"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@Test public void Link__xwiki_foreign() { // PURPOSE:ns in linked wikis should use canonical name, not current wiki's name PAGE:pl.w:Terytoria_Północno-Zachodnie DATE:2016-10-28
|
||||||
|
fxt.Wiki().Ns_mgr().Ids_get_or_null(gplx.xowa.wikis.nss.Xow_ns_.Tid__help).Name_bry_(Bry_.new_a7("Aide")); // simulate non-English wiki with non-english names
|
||||||
|
fxt.Test__bicode // fails if "Aide:" instead of "Help:"
|
||||||
|
( "~%.qen.wiktionary.org|~A.png~/Help~)#Sabc~"
|
||||||
|
, "<a href='/site/en.wiktionary.org/wiki/Help:' class='image' title='abc' xowa_title='A.png'><img data-xowa-title='A.png' data-xoimg='0|220|-1|-1|-1|-1' src='' width='0' height='0' alt='abc'></a>"
|
||||||
|
);
|
||||||
|
fxt.Wiki().Ns_mgr().Ids_get_or_null(gplx.xowa.wikis.nss.Xow_ns_.Tid__help).Name_bry_(Bry_.new_a7("Help")); // revert
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||||
import org.junit.*; import gplx.xowa.files.*;
|
import org.junit.*; import gplx.xowa.files.*;
|
||||||
public class Xoh_file_wtr__image__tst {
|
public class Xoh_file_wtr__image__basic__tst {
|
||||||
private final Xop_fxt fxt = new Xop_fxt();
|
private final Xop_fxt fxt = new Xop_fxt();
|
||||||
@Before public void init() {fxt.Reset();}
|
@Before public void init() {fxt.Reset();}
|
||||||
@Test public void Img__full() { // PURPOSE: full with title was outputting invalid html; DATE:2013-12-31
|
@Test public void Img__full() { // PURPOSE: full with title was outputting invalid html; DATE:2013-12-31
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
XOWA: the XOWA Offline Wiki Application
|
||||||
|
Copyright (C) 2012 gnosygnu@gmail.com
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package gplx.xowa.htmls.core.wkrs.lnkis.htmls; import gplx.*; import gplx.xowa.*; import gplx.xowa.htmls.*; import gplx.xowa.htmls.core.*; import gplx.xowa.htmls.core.wkrs.*; import gplx.xowa.htmls.core.wkrs.lnkis.*;
|
||||||
|
import org.junit.*; import gplx.xowa.files.*;
|
||||||
|
public class Xoh_file_wtr__image__link__tst {
|
||||||
|
private final Xop_fxt fxt = new Xop_fxt();
|
||||||
|
@Before public void init() {fxt.Reset();}
|
||||||
|
@Test public void Link__file() { // PURPOSE.FIX: link=file:/// was creating "href='/wiki/file'" handle IPA links; EX:[[File:Speakerlink-new.svg|11px|link=file:///C:/xowa/file/commons.wikimedia.org/orig/c/7/a/3/En-LudwigVanBeethoven.ogg|Listen]]; PAGE:en.w:Beethoven DATE:2015-12-28
|
||||||
|
fxt.Test_parse_page_wiki_str
|
||||||
|
( "[[File:A.png|11px|link=file:///C:/A.ogg|b]]", String_.Concat_lines_nl_skip_last
|
||||||
|
( "<a href=\"file:///C:/A.ogg\" class=\"image\" xowa_title=\"A.ogg\">"
|
||||||
|
+ "<img id=\"xoimg_0\" alt=\"b\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/11px.png\" width=\"11\" height=\"0\" />"
|
||||||
|
+ "</a>"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
@Test public void Link__empty() { // empty link should not create anchor; EX:[[File:A.png|link=|abc]]; PAGE:en.w:List_of_counties_in_New_York; DATE:2016-01-10
|
||||||
|
fxt.Test_parse_page_wiki_str
|
||||||
|
( "[[File:A.png|11px|link=|abc]]", String_.Concat_lines_nl_skip_last
|
||||||
|
( "<img id=\"xoimg_0\" alt=\"abc\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/11px.png\" width=\"11\" height=\"0\" />"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
@Test public void Link__lc() { // links to items in same Srch_rslt_cbk should automatically title-case words; DATE:2016-01-11
|
||||||
|
fxt.Init_xwiki_add_wiki_and_user_("en", "en.wikipedia.org");
|
||||||
|
fxt.Test_parse_page_wiki_str
|
||||||
|
( "[[File:A.png|11px|link=en:Help:a?b=c#d|abc]]", String_.Concat_lines_nl_skip_last
|
||||||
|
( "<a href=\"/wiki/Help:A?b=c#d\" class=\"image\" xowa_title=\"A.png\">" // "Help:A" not "Help:a"
|
||||||
|
+ "<img id=\"xoimg_0\" alt=\"abc\" src=\"file:///mem/wiki/repo/trg/thumb/7/0/A.png/11px.png\" width=\"11\" height=\"0\" />"
|
||||||
|
+ "</a>"));
|
||||||
|
fxt.Init_xwiki_clear();
|
||||||
|
}
|
||||||
|
}
|
@ -101,4 +101,30 @@ public class Xow_ns_canonical_ {
|
|||||||
default: return ns.Name_ui();
|
default: return ns.Name_ui();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static byte[] To_canonical_or_local_as_bry_w_colon(Xow_ns ns) {
|
||||||
|
byte[] rv = null;
|
||||||
|
switch (ns.Id()) {
|
||||||
|
case Xow_ns_.Tid__media: rv = Xow_ns_.Bry__media; break;
|
||||||
|
case Xow_ns_.Tid__special: rv = Xow_ns_.Bry__special; break;
|
||||||
|
case Xow_ns_.Tid__talk: rv = Xow_ns_.Bry__talk; break;
|
||||||
|
case Xow_ns_.Tid__user: rv = Xow_ns_.Bry__user; break;
|
||||||
|
case Xow_ns_.Tid__user_talk: rv = Xow_ns_.Bry__user_talk; break;
|
||||||
|
case Xow_ns_.Tid__project: rv = Xow_ns_.Bry__project; break;
|
||||||
|
case Xow_ns_.Tid__project_talk: rv = Xow_ns_.Bry__project_talk; break;
|
||||||
|
case Xow_ns_.Tid__file: rv = Xow_ns_.Bry__file; break;
|
||||||
|
case Xow_ns_.Tid__file_talk: rv = Xow_ns_.Bry__file_talk; break;
|
||||||
|
case Xow_ns_.Tid__mediawiki: rv = Xow_ns_.Bry__mediawiki; break;
|
||||||
|
case Xow_ns_.Tid__mediawiki_talk: rv = Xow_ns_.Bry__mediawiki_talk; break;
|
||||||
|
case Xow_ns_.Tid__template: rv = Xow_ns_.Bry__template; break;
|
||||||
|
case Xow_ns_.Tid__template_talk: rv = Xow_ns_.Bry__template_talk; break;
|
||||||
|
case Xow_ns_.Tid__help: rv = Xow_ns_.Bry__help; break;
|
||||||
|
case Xow_ns_.Tid__help_talk: rv = Xow_ns_.Bry__help_talk; break;
|
||||||
|
case Xow_ns_.Tid__category: rv = Xow_ns_.Bry__category; break;
|
||||||
|
case Xow_ns_.Tid__category_talk: rv = Xow_ns_.Bry__category_talk; break;
|
||||||
|
case Xow_ns_.Tid__module: rv = Xow_ns_.Bry__module; break;
|
||||||
|
case Xow_ns_.Tid__module_talk: rv = Xow_ns_.Bry__module_talk; break;
|
||||||
|
default: return ns.Name_db_w_colon();
|
||||||
|
}
|
||||||
|
return Bry_.Add(rv, Byte_ascii.Colon_bry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user