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

HTTP Server: Show correct tab / html.head name for pages ('wikiName - message' if mainPage, else 'pageName - wikiName') [#715]

This commit is contained in:
gnosygnu 2020-05-01 08:45:01 -04:00
parent db73b4302d
commit 105446f5ca
5 changed files with 211 additions and 120 deletions

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 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.
@ -13,16 +13,38 @@ 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.htmls; import gplx.*; import gplx.xowa.*;
import gplx.core.brys.fmtrs.*;
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.langs.htmls.*; import gplx.xowa.langs.vnts.*; import gplx.xowa.htmls.core.htmls.*;
import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.skins.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.*; import gplx.xowa.wikis.domains.*; import gplx.xowa.parsers.*; import gplx.xowa.xtns.wbases.*;
import gplx.xowa.xtns.pagebanners.*;
import gplx.xowa.apps.gfs.*; import gplx.xowa.htmls.portal.*;
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.*;
import gplx.xowa.htmls.core.*;
import gplx.xowa.xtns.pfuncs.times.*;
package gplx.xowa.htmls;
import gplx.Bool_;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.DateAdp;
import gplx.DateAdp_;
import gplx.core.brys.fmtrs.Bry_fmtr;
import gplx.langs.htmls.Gfh_utl;
import gplx.xowa.Xoa_app_;
import gplx.xowa.Xoa_ttl;
import gplx.xowa.Xoae_app;
import gplx.xowa.Xoae_page;
import gplx.xowa.Xowe_wiki;
import gplx.xowa.addons.wikis.ctgs.htmls.pageboxs.Xoctg_pagebox_itm;
import gplx.xowa.apps.gfs.Gfs_php_converter;
import gplx.xowa.htmls.core.Xow_hdump_mode;
import gplx.xowa.htmls.core.htmls.Xoh_html_wtr_escaper;
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
import gplx.xowa.htmls.portal.Xoh_page_body_cls;
import gplx.xowa.htmls.portal.Xow_portal_mgr;
import gplx.xowa.langs.vnts.Xol_vnt_mgr;
import gplx.xowa.parsers.Xop_ctx;
import gplx.xowa.wikis.Xow_page_tid;
import gplx.xowa.wikis.domains.Xow_domain_tid_;
import gplx.xowa.wikis.nss.Xow_ns_;
import gplx.xowa.wikis.pages.Xopg_view_mode_;
import gplx.xowa.wikis.pages.skins.Xopg_xtn_skin_fmtr_arg;
import gplx.xowa.wikis.pages.skins.Xopg_xtn_skin_itm_tid;
import gplx.xowa.xtns.pfuncs.times.Pft_func_formatdate;
import gplx.xowa.xtns.wbases.Wdata_xwiki_link_wtr;
public class Xoh_page_wtr_wkr {
private final Object thread_lock_1 = new Object(), thread_lock_2 = new Object();
private final Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
@ -102,15 +124,21 @@ public class Xoh_page_wtr_wkr {
converted_title = vnt_mgr.Convert_lang().Auto_convert(vnt_mgr.Cur_itm(), page_ttl.Page_txt());
page_ttl = Xoa_ttl.Parse(wiki, page_ttl.Ns().Id(), converted_title);
}
byte[] page_name = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, null); // NOTE: page_name does not show display_title (<i>). always pass in null
byte[] page_display_title = Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
page.Html_data().Custom_tab_name_(page_name); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05
// get pagename for (a) SWT tab name or (b) HTTP_server's <head><title>
byte[] pagename_for_tab = Xoh_page_wtr_wkr_.BuildPagenameForTab(tmp_bfr, wiki.Msg_mgr(), page_ttl, wiki.Props().Main_page()); // NOTE: page_name does not show display_title (<i>). always pass in null
page.Html_data().Custom_tab_name_(pagename_for_tab); // set tab_name to page_name; note that if null, gui code will ignore and use Ttl.Page_txt; PAGE: zh.w:釣魚臺列嶼主權問題 DATE:2015-10-05
// get pagename for <h1 id="firstHeading" class="firstHeading"></h1>
byte[] pagename_for_h1 = Xoh_page_wtr_wkr_.BuildPagenameForH1(tmp_bfr, page_ttl, page.Html_data().Display_ttl());
// main build
Xow_portal_mgr portal_mgr = wiki.Html_mgr().Portal_mgr().Init_assert();
boolean nightmode_enabled = app.Gui_mgr().Nightmode_mgr().Enabled();
fmtr.Bld_bfr_many(bfr
, root_dir_bry, Xoa_app_.Version, Xoa_app_.Build_date, app.Tcp_server().Running_str()
, page.Db().Page().Id(), page.Ttl().Full_db()
, page_name, page.Html_data().Page_heading().Init(wiki, html_gen_tid == Xopg_view_mode_.Tid__read, page.Html_data(), page.Ttl().Full_db(), page_display_title)
, pagename_for_tab, page.Html_data().Page_heading().Init(wiki, html_gen_tid == Xopg_view_mode_.Tid__read, page.Html_data(), page.Ttl().Full_db(), pagename_for_h1)
, modified_on_msg
, mgr.Css_common_bry(), mgr.Css_wiki_bry()
, mgr.Css_night_bry(nightmode_enabled)

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 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.
@ -13,10 +13,23 @@ 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.htmls; import gplx.*; import gplx.xowa.*;
import gplx.langs.htmls.*; import gplx.xowa.xtns.relatedSites.*;
import gplx.xowa.wikis.nss.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.pages.tags.*;
import gplx.xowa.parsers.utils.*;
package gplx.xowa.htmls;
import gplx.Bool_;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_find_;
import gplx.Gfo_usr_dlg_;
import gplx.langs.htmls.Gfh_tag_;
import gplx.xowa.Xoa_ttl;
import gplx.xowa.Xoae_app;
import gplx.xowa.Xoae_page;
import gplx.xowa.Xowe_wiki;
import gplx.xowa.langs.msgs.Xow_msg_mgr;
import gplx.xowa.parsers.utils.Xop_redirect_mgr;
import gplx.xowa.wikis.nss.Xow_ns_;
import gplx.xowa.wikis.pages.tags.Xopg_tag_wtr;
import gplx.xowa.wikis.pages.tags.Xopg_tag_wtr_cbk_;
public class Xoh_page_wtr_wkr_ {
public static byte[] Bld_page_content_sub(Xoae_app app, Xowe_wiki wiki, Xoae_page page, Bry_bfr tmp_bfr) {
byte[] subpages = app.Html_mgr().Page_mgr().Subpages_bldr().Bld(wiki, page.Ttl());
@ -24,14 +37,35 @@ public class Xoh_page_wtr_wkr_ {
byte[] redirect_msg = Xop_redirect_mgr.Bld_redirect_msg(app, wiki, page.Redirect_trail());
return Bry_.Add(subpages, page_content_sub, redirect_msg);
}
public static byte[] Bld_page_name(Bry_bfr tmp_bfr, Xoa_ttl ttl, byte[] display_ttl) {
if (Bry_.Len_gt_0(display_ttl)) return display_ttl; // display_ttl explicitly set; use it
if (ttl.Ns().Id() == Xow_ns_.Tid__special) { // special: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
tmp_bfr.Add(ttl.Ns().Name_ui_w_colon()).Add(ttl.Page_txt_wo_qargs());
return tmp_bfr.To_bry_and_clear();
public static byte[] BuildPagenameForTab(Bry_bfr tmp, Xow_msg_mgr msgMgr, Xoa_ttl ttl, byte[] mainPageTtl) {
byte[] pagename = BuildPagename(tmp, ttl);
// default to sitewide pagetitle; ISSUE#:715; DATE:2020-05-01
byte[] msgKey = Bry_.new_a7("pagetitle"); // $1 Travel guide at {{SITENAME}}
// if MAIN_PAGE, use the pageTitle for MAIN_PAGE; may not need Replace_unders depending on whether "mainPageTtl" is "MAIN PAGE"
if (Bry_.Eq(Xoa_ttl.Replace_unders(ttl.Raw()), Xoa_ttl.Replace_unders(mainPageTtl)))
msgKey = Bry_.new_a7("pagetitle-view-mainpage"); // {{SITENAME}} The free worldwide travel guide that you can edit
// do the actual swap
return msgMgr.Val_by_key_args(msgKey, pagename);
}
public static byte[] BuildPagenameForH1(Bry_bfr tmp, Xoa_ttl ttl, byte[] displayTtl) {
// display_ttl explicitly set; use it
return Bry_.Len_gt_0(displayTtl)
? displayTtl
: BuildPagename(tmp, ttl);
}
private static byte[] BuildPagename(Bry_bfr tmp, Xoa_ttl ttl) {
// SPECIAL page: omit query args, else excessively long titles: EX:"Special:Search/earth?fulltext=y&xowa page index=1"
if (ttl.Ns().Id() == Xow_ns_.Tid__special) {
tmp.Add(ttl.Ns().Name_ui_w_colon()).Add(ttl.Page_txt_wo_qargs());
return tmp.To_bry_and_clear();
}
else {
// NOTE: include ns with ttl as per defect d88a87b3
return ttl.Full_txt();
}
else
return ttl.Full_txt(); // NOTE: include ns with ttl as per defect d88a87b3
}
public static void Bld_head_end(Bry_bfr html_bfr, Bry_bfr tmp_bfr, Xoae_page page) {
byte[] head_end = Xopg_tag_wtr.Write(tmp_bfr, Bool_.Y, Xopg_tag_wtr_cbk_.Basic, page.Html_data().Custom_head_tags());

View File

@ -1,6 +1,6 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
Copyright (C) 2012-2020 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.
@ -13,44 +13,72 @@ 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.htmls; import gplx.*; import gplx.xowa.*;
import org.junit.*;
import gplx.xowa.guis.*; import gplx.xowa.wikis.pages.*;
import gplx.xowa.htmls.core.htmls.*;
package gplx.xowa.htmls;
import gplx.Bry_;
import gplx.Bry_bfr;
import gplx.Bry_bfr_;
import gplx.Tfds;
import gplx.core.tests.Gftest;
import gplx.xowa.Xoa_app_fxt;
import gplx.xowa.Xoa_page_;
import gplx.xowa.Xoa_ttl;
import gplx.xowa.Xoae_app;
import gplx.xowa.Xoae_page;
import gplx.xowa.Xowe_wiki;
import gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx;
import gplx.xowa.wikis.pages.Xopg_view_mode_;
import org.junit.Before;
import org.junit.Test;
public class Xoh_page_wtr_wkr_tst {
@Before public void init() {fxt.Clear();} private Xoh_page_wtr_fxt fxt = new Xoh_page_wtr_fxt();
@Test public void Page_name() {
fxt.Test_page_name_by_ttl("Earth", "Earth");
fxt.Test_page_name_by_ttl("File:A.png", "File:A.png");
fxt.Test_page_name_by_ttl("Special:Search/earth?fulltext=y", "Special:Search/earth");
fxt.Test_page_name_by_ttl("Special:Search/earth", "Special:Search/earth");
fxt.Test_page_name_by_display("Special:Allpages", "All pages", "All pages");
@Test public void BuildPagenameForTab() {
fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_a7("pagetitle-view-mainpage")).Atrs_set(Bry_.new_a7("{{SITENAME}} - WikiDescription"), false, true);
fxt.Wiki().Msg_mgr().Get_or_make(Bry_.new_a7("pagetitle")).Atrs_set(Bry_.new_a7("~{0} - {{SITENAME}}"), true, true);
fxt.Test_BuildPagenameForTab("basic" , "Earth - Wikipedia" , "Earth");
fxt.Test_BuildPagenameForTab("ns" , "File:A.png - Wikipedia" , "File:A.png");
fxt.Test_BuildPagenameForTab("special" , "Special:Search/earth - Wikipedia" , "Special:Search/earth");
fxt.Test_BuildPagenameForTab("special:no qargs" , "Special:Search/earth - Wikipedia" , "Special:Search/earth?fulltext=y");
fxt.Test_BuildPagenameForTab("mainpage" , "Wikipedia - WikiDescription" , "Main_Page");
}
@Test public void Edit() {
@Test public void BuildPagenameForH1() {
fxt.Test_BuildPagenameForH1("Full_txt" , "Two words" , "Two_words", null);
fxt.Test_BuildPagenameForH1("no qargs" , "Special:Search/earth", "Special:Search/earth?fulltext=y", null);
fxt.Test_BuildPagenameForH1("display overrides", "Display" , "Title", "Display");
}
@Test public void Edit() {
fxt.Test_edit("&#9;", "&amp;#9;\n"); // NOTE: cannot by &#9; or will show up in edit box as "\t" and save as "\t" instead of &#9;
}
@Test public void Css() {
@Test public void Css() {
fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("<pre style='overflow:auto'>~{page_text}</pre>");
fxt.Test_read("MediaWiki:Common.css", ".xowa {}", "<pre style='overflow:auto'>.xowa {}</pre>");
fxt.App().Html_mgr().Page_mgr().Content_code_fmt().Fmt_("<pre>~{page_text}</pre>");
}
@Test public void Amp_disable() { // PURPOSE: in js documents; &quot; should be rendered as &quot;, not as "; DATE:2013-11-07
@Test public void Amp_disable() { // PURPOSE: in js documents; &quot; should be rendered as &quot;, not as "; DATE:2013-11-07
fxt.Test_read("MediaWiki:Gadget.js", "&quot;", "<pre>&amp;quot;</pre>");
}
}
class Xoh_page_wtr_fxt {
private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255);
public void Clear() {
if (app == null) {
app = Xoa_app_fxt.Make__app__edit();
wiki = Xoa_app_fxt.Make__wiki__edit(app);
}
} private Bry_bfr tmp_bfr = Bry_bfr_.Reset(255); private Xowe_wiki wiki;
public Xoae_app App() {return app;} private Xoae_app app;
public void Test_page_name_by_display(String ttl, String display, String expd) {
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl)), Bry_.new_a7(display))));
}
public void Test_page_name_by_ttl(String raw, String expd) {
Tfds.Eq(expd, String_.new_a7(Xoh_page_wtr_wkr_.Bld_page_name(tmp_bfr, Xoa_ttl.Parse(wiki, Bry_.new_a7(raw)), null)));
public Xoae_app App() {return app;} private Xoae_app app;
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
public void Test_BuildPagenameForH1(String note, String expd, String ttl, String display) {
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(ttl));
Gftest.Eq__str(expd, Xoh_page_wtr_wkr_.BuildPagenameForH1(tmp_bfr, page_ttl, Bry_.new_a7(display)), note);
}
public void Test_BuildPagenameForTab(String note, String expd, String raw) {
Xoa_ttl page_ttl = Xoa_ttl.Parse(wiki, Bry_.new_a7(raw));
byte[] mainpage_title = Xoa_page_.Main_page_bry;
Gftest.Eq__str(expd, Xoh_page_wtr_wkr_.BuildPagenameForTab(tmp_bfr, wiki.Msg_mgr(), page_ttl, mainpage_title));
}
public void Test_edit(String raw, String expd) {
wiki.Html_mgr().Page_wtr_mgr().Html_capable_(true);

View File

@ -30,7 +30,7 @@ public class Xow_wiki_props {
// XO props
public byte Protocol_tid() {return protocol_tid;} private final byte protocol_tid = gplx.core.net.Gfo_protocol_itm.Tid_https; // NOTE: default protocol to https; handles external links like [//a.org]; may need to be changed for wikia or other non-WMF wikis; DATE:2015-07-27
public byte[] Main_page() {return main_page;} private byte[] main_page = Xoa_page_.Main_page_bry; // HACK: default to Main_Page b/c some code tries to do Xoa_ttl.Parse() which will not work with ""; DATE:2014-02-16
public byte[] Main_page() {return main_page;} private byte[] main_page = Xoa_page_.Main_page_bry; // HACK: default to Main_Page b/c some code tries to do Xoa_ttl.Parse() which will not work with ""; DATE:2014-02-16; QUESTION:is this always "Main_Page" or "Main Page"; See Xoh_page_wtr_wkr_; DATE:2020-05-01
public byte[] Bldr_version() {return bldr_version;} private byte[] bldr_version = Bry_.Empty;
public int Css_version() {return css_version;} private int css_version = 1;
public byte[] Siteinfo_misc() {return siteinfo_misc;} private byte[] siteinfo_misc = Bry_.Empty;

View File

@ -16,6 +16,7 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
package gplx.xowa.wikis.pages; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
import gplx.core.brys.*; import gplx.core.brys.fmtrs.*;
import gplx.xowa.wikis.pages.htmls.*;
// TODO: move pagename_for_h1 here; also test; WHEN: next major change; NOTE: may go away for XOMW
public class Xopg_page_heading implements Bfr_arg {
private Xowe_wiki wiki;
private Xopg_html_data html_data;