mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Wiki: Support renamed folders (fix)
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.xtns.wbases.specials.*;
|
||||
public class Xoa_special_mgr implements Gfo_invk {
|
||||
private Wdata_itemByTitle_cfg wbase_cfg = new Wdata_itemByTitle_cfg();
|
||||
private Ordered_hash hash = Ordered_hash_.New();
|
||||
public Xoa_special_mgr() {
|
||||
hash.Add(Wdata_itemByTitle_cfg.Key, wbase_cfg);
|
||||
}
|
||||
public void Init_by_app(Xoae_app app) {
|
||||
wbase_cfg.Init_by_app(app);
|
||||
}
|
||||
public void Add(String key, Gfo_invk cfg) {hash.Add(key, cfg);}
|
||||
public Gfo_invk Get_or_null(String key) {return (Gfo_invk)hash.Get_by(key);}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_get)) return Get_or_null(m.ReadStr("v"));
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_get = "get";
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
public class Xow_special_meta {
|
||||
public Xow_special_meta(int src, String key_str, String... aliases) {
|
||||
this.src = src; this.key_str = key_str;
|
||||
this.key_bry = Bry_.new_u8(key_str);
|
||||
this.ttl_bry = Bry_.Add(gplx.xowa.wikis.nss.Xow_ns_.Bry__special, Byte_ascii.Colon_bry, key_bry);
|
||||
this.ttl_str = String_.new_u8(ttl_bry);
|
||||
this.aliases = Bry_.Ary(aliases);
|
||||
}
|
||||
public int Src() {return src;} private final int src; // either MW or XOWA
|
||||
public String Key_str() {return key_str;} private final String key_str; // EX: AllPages
|
||||
public byte[] Key_bry() {return key_bry;} private final byte[] key_bry;
|
||||
public String Ttl_str() {return ttl_str;} private final String ttl_str; // EX: Special:AllPages
|
||||
public byte[] Ttl_bry() {return ttl_bry;} private final byte[] ttl_bry;
|
||||
public byte[][] Aliases() {return aliases;} private final byte[][] aliases; // EX: Special:RandomPage has Special:Random as alias
|
||||
public byte[] Display_ttl() {return display_ttl;} private byte[] display_ttl; public Xow_special_meta Display_ttl_(String v) {display_ttl = Bry_.new_u8(v); return this;}
|
||||
public String Url__home() {
|
||||
return String_.Concat(gplx.xowa.wikis.domains.Xow_domain_itm_.Str__home, gplx.xowa.htmls.hrefs.Xoh_href_.Str__wiki, ttl_str);
|
||||
}
|
||||
|
||||
public boolean Match_ttl(Xoa_ttl ttl) {
|
||||
return ttl.Ns().Id_is_special() && Bry_.Eq(ttl.Root_txt(), key_bry);
|
||||
}
|
||||
|
||||
public static Xow_special_meta New_xo(String key, String display, String... aliases) {
|
||||
return new Xow_special_meta(Xow_special_meta_.Src__xowa, key, aliases).Display_ttl_(display);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
public class Xow_special_meta_ {
|
||||
public static final int Src__mw = 1, Src__xowa = 2;
|
||||
public static final String
|
||||
Ttl__all_pages = "AllPages"
|
||||
, Ttl__random = "RandomPage"
|
||||
, Ttl__random_root_page = "RandomRootPage"
|
||||
, Ttl__search = "Search"
|
||||
, Ttl__statistics = "Statistics"
|
||||
, Ttl__move_page = "MovePage"
|
||||
, Ttl__my_language = "MyLanguage"
|
||||
, Ttl__item_by_title = "ItemByTitle"
|
||||
, Ttl__default_tab = "XowaDefaultTab"
|
||||
, Ttl__popup_history = "XowaPopupHistory"
|
||||
, Ttl__system_data = "XowaSystemData"
|
||||
, Ttl__nearby = "Nearby"
|
||||
, Ttl__page_history = "XowaHistory"
|
||||
, Ttl__bookmarks = "XowaBookmarks"
|
||||
, Ttl__diag = "XowaDiag"
|
||||
;
|
||||
public static final Xow_special_meta
|
||||
Itm__all_pages = new Xow_special_meta(Src__mw , Ttl__all_pages)
|
||||
, Itm__random = new Xow_special_meta(Src__mw , Ttl__random)
|
||||
, Itm__random_root_page = new Xow_special_meta(Src__mw , Ttl__random_root_page)
|
||||
, Itm__search = new Xow_special_meta(Src__mw , Ttl__search)
|
||||
, Itm__statistics = new Xow_special_meta(Src__mw , Ttl__statistics)
|
||||
, Itm__move_page = new Xow_special_meta(Src__xowa , Ttl__move_page)
|
||||
, Itm__my_language = new Xow_special_meta(Src__xowa , Ttl__my_language)
|
||||
, Itm__item_by_title = new Xow_special_meta(Src__xowa , Ttl__item_by_title)
|
||||
, Itm__default_tab = new Xow_special_meta(Src__xowa , Ttl__default_tab)
|
||||
, Itm__popup_history = new Xow_special_meta(Src__xowa , Ttl__popup_history)
|
||||
, Itm__system_data = new Xow_special_meta(Src__xowa , Ttl__system_data)
|
||||
, Itm__nearby = new Xow_special_meta(Src__xowa , Ttl__nearby)
|
||||
, Itm__page_history = new Xow_special_meta(Src__xowa , Ttl__page_history)
|
||||
, Itm__bookmarks = new Xow_special_meta(Src__xowa , Ttl__bookmarks)
|
||||
, Itm__diag = new Xow_special_meta(Src__xowa , Ttl__diag)
|
||||
;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.users.history.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.specials.*;
|
||||
import gplx.xowa.specials.*;
|
||||
import gplx.xowa.specials.allPages.*; import gplx.xowa.specials.nearby.*; import gplx.xowa.specials.statistics.*; import gplx.xowa.xtns.translates.*; import gplx.xowa.specials.movePage.*;
|
||||
import gplx.xowa.specials.xowa.system_data.*; import gplx.xowa.specials.xowa.default_tab.*; import gplx.xowa.specials.xowa.popup_history.*; import gplx.xowa.addons.wikis.imports.*; import gplx.xowa.specials.xowa.diags.*;
|
||||
import gplx.xowa.xtns.wbases.specials.*;
|
||||
import gplx.xowa.users.data.*; import gplx.xowa.users.bmks.*;
|
||||
import gplx.xowa.specials.mgrs.*; import gplx.xowa.addons.wikis.searchs.specials.*;
|
||||
public class Xow_special_mgr {
|
||||
private final Hash_adp_bry hash;
|
||||
private Xoa_app app;
|
||||
public Xow_special_mgr(Xowe_wiki wiki, Xol_lang_itm lang) {
|
||||
this.app = wiki.App();
|
||||
hash = Hash_adp_bry.ci_u8(lang.Case_mgr());
|
||||
page_allpages = new Xows_page_allpages(wiki);
|
||||
Evt_lang_changed(wiki.Lang());
|
||||
}
|
||||
public Xows_page_allpages Page_allpages() {return page_allpages;} private final Xows_page_allpages page_allpages;
|
||||
public Srch_special_page Page_search() {return page_search;} private final Srch_special_page page_search = new Srch_special_page();
|
||||
public Xou_history_html Page_history() {return page_history;} private final Xou_history_html page_history = new Xou_history_html();
|
||||
public Xoud_history_special Page_history2() {return page_history2;} private final Xoud_history_special page_history2 = new Xoud_history_special();
|
||||
public Nearby_mgr Page_nearby() {return page_nearby;} private final Nearby_mgr page_nearby = new Nearby_mgr();
|
||||
public Xop_mylanguage_page Page_mylanguage() {return page_mylanguage;} private final Xop_mylanguage_page page_mylanguage = new Xop_mylanguage_page();
|
||||
public Wdata_itemByTitle_page Page_itemByTitle() {return page_itemByTitle;} private final Wdata_itemByTitle_page page_itemByTitle = new Wdata_itemByTitle_page();
|
||||
public Xop_statistics_page Page_statistics() {return page_statistics;} private final Xop_statistics_page page_statistics = new Xop_statistics_page();
|
||||
public Move_page Page_movePage() {return page_movePage;} private final Move_page page_movePage = new Move_page();
|
||||
public System_data_page Page_system_data() {return page_system_data;} private final System_data_page page_system_data = new System_data_page();
|
||||
public Default_tab_page Page_default_tab() {return page_default_tab;} private final Default_tab_page page_default_tab = new Default_tab_page();
|
||||
public Popup_history_page Page_popup_history() {return page_popup_history;} private final Popup_history_page page_popup_history = new Popup_history_page();
|
||||
public Xows_bmk_page Page_bmk() {return page_bmk;} private final Xows_bmk_page page_bmk = new Xows_bmk_page();
|
||||
public Xows_diag_page Page_diag() {return page_diag;} private final Xows_diag_page page_diag = new Xows_diag_page();
|
||||
public void Evt_lang_changed(Xol_lang_itm lang) {
|
||||
// add special pages by old manual method; DEPRECATED
|
||||
hash.Clear();
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__search , page_search);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__all_pages , page_allpages);
|
||||
hash.Add_str_obj("prefixindex" , page_allpages);
|
||||
hash.Add_bry_obj(Xou_history_mgr.Ttl_name , page_history);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__page_history , page_history2);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__nearby , page_nearby);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__my_language , page_mylanguage);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__item_by_title , page_itemByTitle);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__statistics , page_statistics);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__move_page , page_movePage);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__system_data , page_system_data);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__default_tab , page_default_tab);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__popup_history , page_popup_history);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__bookmarks , page_bmk);
|
||||
hash.Add_str_obj(Xow_special_meta_.Ttl__diag , page_diag);
|
||||
|
||||
// add app's Special_regy to hash table; needed for case insensitivity by wiki's lang; EX: Special:rANDom; NOTE: needs to go before lang aliases
|
||||
Xoa_special_regy special_regy = app.Special_regy();
|
||||
int len = special_regy.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xow_special_page proto = special_regy.Get_at(i);
|
||||
Xow_special_meta proto_meta = proto.Special__meta();
|
||||
hash.Add_if_dupe_use_1st(proto_meta.Key_bry(), proto);
|
||||
for (byte[] alias : proto_meta.Aliases())
|
||||
hash.Add_if_dupe_use_1st(alias, proto);
|
||||
}
|
||||
|
||||
// add lang's special aliases to hash table; EX: Special:Recherche
|
||||
Xol_specials_mgr lang_mgr = lang.Specials_mgr();
|
||||
len = lang_mgr.Len();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xol_specials_itm lang_itm = lang_mgr.Get_at(i);
|
||||
Xow_special_page page = (Xow_special_page)hash.Get_by_bry(lang_itm.Special());
|
||||
if (page == null) continue; // NOTE: ignore specials that are not in XOWA; EX: Special:ChangeEmail
|
||||
for (byte[] alias : lang_itm.Aliases())
|
||||
hash.Add_if_dupe_use_1st(alias, page);
|
||||
}
|
||||
}
|
||||
public void Special__gen(Xoa_app app, Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
int slash_pos = Bry_find_.Find_fwd(ttl.Page_txt_wo_qargs(), Xoa_ttl.Subpage_spr); // check for slash
|
||||
byte[] special_name = slash_pos == Bry_find_.Not_found
|
||||
? ttl.Base_txt_wo_qarg() // no slash found; use base_txt; ignore qry args and just get page_names; EX: Search/Earth?fulltext=y; Allpages?from=Earth...
|
||||
: Bry_.Mid(ttl.Page_txt_wo_qargs(), 0, slash_pos); // slash found; use root page; EX: Special:ItemByTitle/enwiki/Earth
|
||||
special_name = Xoa_ttl.Replace_spaces(special_name); // handle spaces; EX:Spezial:Zufällige_Seite
|
||||
Xow_special_page special = (Xow_special_page)hash.Get_by_bry(special_name);
|
||||
if (special != null) { // special found; generate it;
|
||||
special = special.Special__clone();
|
||||
page.Db().Page().Modified_on_(Datetime_now.Get());
|
||||
try {special.Special__gen(wiki, page, url, ttl);}
|
||||
catch (Exception e) {Gfo_log_.Instance.Warn("failed to generate special page", "url", url.To_str(), "err", Err_.Message_gplx_log(e));}
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_search)) return page_search;
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
} private static final String Invk_search = "search";
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
public interface Xow_special_page {
|
||||
Xow_special_meta Special__meta();
|
||||
Xow_special_page Special__clone();
|
||||
void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl);
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
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.specials; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.langs.mustaches.*; import gplx.xowa.wikis.pages.*;
|
||||
public abstract class Xow_special_wtr__base {
|
||||
public void Bld_page_by_mustache(Xoa_app app, Xoa_page page, Xow_special_page special) {
|
||||
Mustache_doc_itm mustache_root = Bld_mustache_root(app);
|
||||
if (mustache_root == null) { // handle invalid urls; EX: Special:XowaWikiInfo?wiki=deleted_wiki
|
||||
Handle_invalid(app, page, special);
|
||||
return;
|
||||
}
|
||||
Io_url addon_dir = this.Get_addon_dir(app);
|
||||
byte[] body = Bld_html_body(addon_dir, mustache_root);
|
||||
Xopage_html_data page_data = new Xopage_html_data(special.Special__meta().Display_ttl(), body);
|
||||
Bld_tags(app, addon_dir, page_data);
|
||||
page_data.Apply(page);
|
||||
}
|
||||
@gplx.Virtual protected byte[] Bld_html_body(Io_url addon_dir, gplx.langs.mustaches.Mustache_doc_itm itm) {
|
||||
byte[] tmpl = Io_mgr.Instance.LoadFilBry(this.Get_mustache_fil(addon_dir));
|
||||
return gplx.langs.mustaches.Mustache_wtr_.Write_to_bry(Bry_bfr_.New(), tmpl, itm);
|
||||
}
|
||||
|
||||
protected abstract Io_url Get_addon_dir(Xoa_app app);
|
||||
protected abstract Io_url Get_mustache_fil(Io_url addon_dir);
|
||||
protected abstract Mustache_doc_itm Bld_mustache_root(Xoa_app app);
|
||||
protected abstract void Bld_tags(Xoa_app app, Io_url addon_dir, Xopage_html_data data);
|
||||
@gplx.Virtual protected void Handle_invalid(Xoa_app app, Xoa_page page, Xow_special_page special) {
|
||||
new Xopage_html_data(special.Special__meta().Display_ttl(), Bry_.new_a7("Not available")).Apply(page);
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
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.specials.allPages; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.htmls.core.htmls.*; import gplx.xowa.htmls.hrefs.*; import gplx.xowa.htmls.core.wkrs.lnkis.htmls.*;
|
||||
import gplx.xowa.wikis.domains.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
public class Xows_page_allpages implements gplx.core.brys.Bfr_arg, Gfo_invk, Xow_special_page {
|
||||
public Xows_page_allpages(Xowe_wiki wiki) {
|
||||
this.wiki = wiki;
|
||||
html_itm_fmtr = new Xos_pagelist_html_itm_fmtr(this, wiki);
|
||||
} private Xos_pagelist_html_itm_fmtr html_itm_fmtr;
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__all_pages;}
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki;
|
||||
public Bry_fmtr Html_all() {return html_all;} Bry_fmtr html_all = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( "<table class=\"mw-allpages-table-form\">"
|
||||
, " <tr>"
|
||||
, " <td class=\"mw-allpages-nav\">"
|
||||
, "~{anchor_prv} |"
|
||||
, "~{anchor_nxt}"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, "<table class=\"mw-allpages-table-chunk\">"
|
||||
, "<tbody>~{grps}"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "<hr/>"
|
||||
, "<div class=\"mw-allpages-nav\">"
|
||||
, "~{anchor_prv} |"
|
||||
, "~{anchor_nxt}"
|
||||
, "</div>"
|
||||
), "grps", "anchor_prv", "anchor_nxt");
|
||||
public Bry_fmtr Html_list_grp() {return html_list_grp;} Bry_fmtr html_list_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>~{itms}"
|
||||
, " </tr>"
|
||||
), "itms");
|
||||
public Bry_fmtr Html_list_itm_normal() {return html_list_itm_normal;} Bry_fmtr html_list_itm_normal = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td style=\"width:~{itm_pct}%\"><a~{lnki_atr_cls} href=\"~{lnki_href}\" title=\"~{lnki_title}\">~{lnki_text}</a></td>"
|
||||
), "itm_pct", "lnki_href", "lnki_title", "lnki_text", "lnki_atr_cls");
|
||||
public Bry_fmtr Html_list_itm_redirect() {return html_list_itm_redirect;} Bry_fmtr html_list_itm_redirect = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <td style=\"width:~{itm_pct}%\"><div class=\"allpagesredirect\"><a href=\"~{lnki_href}\" class=\"mw-redirect\" title=\"~{lnki_title}\">~{lnki_text}</a></div></td>"
|
||||
), "itm_pct", "lnki_href", "lnki_title", "lnki_text");
|
||||
public Bry_fmtr Html_list_end() {return html_list_end;} Bry_fmtr html_list_end = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<a href=\"/wiki/Special:AllPages?from=~{arg_from}~{args__rest}\" title=\"Special:AllPages\">~{lbl_text}</a>"
|
||||
), "arg_from", "args__rest", "lbl_text");
|
||||
public int Itms_per_page() {return itms_per_page;} private int itms_per_page = 345;
|
||||
public void Itms_per_page_(int v) {itms_per_page = v; rslt_list_ttls = new Xowd_page_itm[v];}
|
||||
public int Itms_per_grp() {return itms_per_grp;} private int itms_per_grp = 3;
|
||||
public boolean List_include_redirects() {return show_redirects;} private boolean show_redirects = true;
|
||||
public Xowd_page_itm Rslt_prv() {return rslt_prv;} public void Rslt_prv_(Xowd_page_itm v) {rslt_prv = v;} private Xowd_page_itm rslt_prv;
|
||||
public Xowd_page_itm Rslt_nxt() {return rslt_nxt;} public void Rslt_nxt_(Xowd_page_itm v) {rslt_nxt = v;} private Xowd_page_itm rslt_nxt;
|
||||
public int Rslt_list_len() {return rslt_list_len;} public void Rslt_list_len_(int v) {rslt_list_len = v;} private int rslt_list_len;
|
||||
public Xowd_page_itm[] Rslt_list_ttls() {return rslt_list_ttls;} private Xowd_page_itm[] rslt_list_ttls;
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
wiki.Parser_mgr().Ctx().Page().Html_data().Display_ttl_(wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_sp_allpages_hdr));
|
||||
url.Page_bry_(Bry_.Add(Bry_.new_a7("Special:"), ttl.Page_txt_wo_qargs())); // HACK: need to re-set Page b/c href_wtr does not eliminate qargs; DATE:2013-02-08
|
||||
if (wiki.Domain_tid() == Xow_domain_tid_.Tid__home) {wiki.Appe().Usr_dlg().Prog_many(GRP_KEY, "home.invalid", "AllPages not implemented for home wiki"); return;}
|
||||
if (rslt_list_ttls == null) this.Itms_per_page_(itms_per_page);
|
||||
boolean found = Build_data(url, ttl); if (!found) return;
|
||||
Build_html(page);
|
||||
}
|
||||
private static byte[] Get_from(Gfo_qarg_mgr_old arg_hash, Xowe_wiki wiki, Xoa_url url, Xoa_ttl ttl) {
|
||||
return ttl.Leaf_bgn() == -1
|
||||
? arg_hash.Get_val_bry_or(Bry_arg_from, null)
|
||||
: ttl.Leaf_url()
|
||||
;
|
||||
}
|
||||
public boolean Build_data(Xoa_url url, Xoa_ttl ttl) {
|
||||
init_ns = wiki.Ns_mgr().Ns_main();
|
||||
arg_hash.Load(url.Qargs_ary());
|
||||
byte[] from_val = Get_from(arg_hash, wiki, url, ttl); if (from_val == null) return false;
|
||||
from_val = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Decode(from_val);
|
||||
int ns_val = arg_hash.Get_val_int_or(Bry_arg_ns, init_ns.Id()); init_ns = wiki.Ns_mgr().Ids_get_or_null(ns_val);
|
||||
boolean hide_redirects_val = arg_hash.Get_val_int_or(Bry_arg_hideredirects, 0) == 1;
|
||||
for (int i = 0; i < itms_per_page; i++)
|
||||
rslt_list_ttls[i] = null;
|
||||
rslt_list_len = 0;
|
||||
rslt_nxt = rslt_prv = null;
|
||||
Xoa_ttl from_ttl = Xoa_ttl.Parse(wiki, from_val); if (from_ttl == null) return false;
|
||||
if (!from_ttl.Ns().Id_is_main()) { // ns specified in title
|
||||
init_ns = from_ttl.Ns();
|
||||
arg_hash.Set_val_by_int(Bry_arg_ns, init_ns.Id());
|
||||
arg_hash.Set_val_by_bry(Bry_arg_from, from_ttl.Page_db());
|
||||
url.Qargs_ary_(arg_hash.To_ary());
|
||||
}
|
||||
Int_obj_ref rslt_len = Int_obj_ref.New(rslt_list_len);
|
||||
Xowd_page_itm rslt_nxt2 = new Xowd_page_itm();
|
||||
Xowd_page_itm rslt_prv2 = new Xowd_page_itm();
|
||||
int all_pages_min = 0;// no minimum for all pages
|
||||
List_adp rslt_list = List_adp_.New();
|
||||
wiki.Db_mgr().Load_mgr().Load_ttls_for_all_pages(Cancelable_.Never, rslt_list, rslt_nxt2, rslt_prv2, rslt_len, init_ns, from_ttl.Page_db(), itms_per_page, all_pages_min, itms_per_page, !hide_redirects_val, true);
|
||||
rslt_list_len = rslt_len.Val();
|
||||
for (int i = 0; i < rslt_list_len; i++)
|
||||
rslt_list_ttls[i] = (Xowd_page_itm)rslt_list.Get_at(i);
|
||||
rslt_nxt = rslt_nxt2;
|
||||
rslt_prv = rslt_prv2;
|
||||
return true;
|
||||
} private Gfo_qarg_mgr_old arg_hash = new Gfo_qarg_mgr_old();
|
||||
private static final byte[] Bry_arg_from = Bry_.new_a7("from"), Bry_arg_ns = Bry_.new_a7("namespace"), Bry_arg_hideredirects = Bry_.new_a7("hideredirects");
|
||||
public Xow_ns Init_ns() {return init_ns;} private Xow_ns init_ns;
|
||||
public void Build_html(Xoae_page page) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
Bry_fmtr fmtr = Bry_fmtr.New__tmp();
|
||||
|
||||
byte[] anchor_prv = Build_html_end(tmp_bfr, fmtr, rslt_prv, false);
|
||||
byte[] anchor_nxt = Build_html_end(tmp_bfr, fmtr, rslt_nxt, true);
|
||||
html_all.Bld_bfr_many(tmp_bfr, this, anchor_prv, anchor_nxt);
|
||||
page.Db().Text().Text_bry_(tmp_bfr.To_bry_and_clear());
|
||||
tmp_bfr.Mkr_rls();
|
||||
page.Html_data().Html_restricted_n_();
|
||||
}
|
||||
byte[] Build_html_end(Bry_bfr bfr, Bry_fmtr fmtr, Xowd_page_itm itm, boolean fwd) {
|
||||
Xoa_ttl ttl = Xows_page_allpages.ttl_(wiki, init_ns, itm); if (ttl == null) return Bry_.Empty; // occurs when range is empty; EX: Module:A in simplewikibooks
|
||||
int msg_id = fwd ? Xol_msg_itm_.Id_sp_allpages_fwd : Xol_msg_itm_.Id_sp_allpages_bwd;
|
||||
Xol_msg_itm msg_itm = wiki.Lang().Msg_mgr().Itm_by_id_or_null(msg_id);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_b512();
|
||||
try {
|
||||
byte[] lbl_text = msg_itm.Fmt(tmp_bfr, fmtr, ttl.Full_txt_w_ttl_case());
|
||||
byte[] args__rest = arg_hash.Concat(tmp_bfr, Bry_arg_ns, Bry_arg_hideredirects);
|
||||
byte[] arg_from = gplx.langs.htmls.encoders.Gfo_url_encoder_.Id.Encode(ttl.Page_txt_wo_qargs());
|
||||
return html_list_end.Bld_bry_many(bfr, arg_from, args__rest, lbl_text);
|
||||
} finally {tmp_bfr.Mkr_rls();}
|
||||
}
|
||||
public static Xoa_ttl ttl_(Xowe_wiki wiki, Xow_ns ns, Xowd_page_itm itm) {
|
||||
byte[] ttl_bry = itm.Ttl_page_db();
|
||||
if (!ns.Id_is_main()) ttl_bry = Bry_.Add(ns.Name_db_w_colon(), ttl_bry);
|
||||
return Xoa_ttl.Parse(wiki, ttl_bry);
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int len = rslt_list_ttls.length;
|
||||
html_itm_fmtr.XferAry_bgn();
|
||||
for (int i = 0; i < len; i += itms_per_grp) {
|
||||
html_itm_fmtr.Itm_idx_(i);
|
||||
html_list_grp.Bld_bfr_many(bfr, html_itm_fmtr);
|
||||
}
|
||||
html_itm_fmtr.XferAry_end();
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_html_all_)) html_all.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html_list_grp_)) html_list_grp.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html_list_itm_normal_)) html_list_itm_normal.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_html_list_itm_redirect_)) html_list_itm_redirect.Fmt_(m.ReadBry("v"));
|
||||
else if (ctx.Match(k, Invk_itms_per_page_)) Itms_per_page_(m.ReadInt("v"));
|
||||
else if (ctx.Match(k, Invk_itms_per_grp_)) itms_per_grp = m.ReadInt("v");
|
||||
else if (ctx.Match(k, Invk_show_redirects_)) show_redirects = m.ReadYn("v");
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_html_all_ = "html_all_", Invk_html_list_grp_ = "html_list_grp_", Invk_html_list_itm_normal_ = "html_list_itm_normal_", Invk_html_list_itm_redirect_ = "html_list_itm_redirect_"
|
||||
, Invk_itms_per_page_ = "itms_per_page_", Invk_itms_per_grp_ = "itms_per_grp_", Invk_show_redirects_ = "show_redirects_";
|
||||
public static final String GRP_KEY = "xowa.special.allpages";
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
class Xos_pagelist_html_itm_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
public Xos_pagelist_html_itm_fmtr(Xows_page_allpages mgr, Xowe_wiki wiki) {
|
||||
this.mgr = mgr; this.wiki = wiki; this.href_wtr = wiki.Html__href_wtr(); this.wiki_key = wiki.Domain_bry();
|
||||
this.itm_normal = mgr.Html_list_itm_normal(); this.itm_redirect = mgr.Html_list_itm_redirect();
|
||||
history_mgr = wiki.Appe().Usere().History_mgr();
|
||||
} private Xows_page_allpages mgr; Xowe_wiki wiki; Xoh_href_wtr href_wtr; Bry_fmtr itm_normal, itm_redirect; byte[] wiki_key; gplx.xowa.users.history.Xou_history_mgr history_mgr;
|
||||
public void Itm_idx_(int v) {itm_idx = v;} private int itm_idx;
|
||||
public void XferAry_bgn() {
|
||||
itms_per_grp = mgr.Itms_per_grp();
|
||||
ttls = mgr.Rslt_list_ttls();
|
||||
ttls_len = ttls.length;
|
||||
itm_pct = 100 / itms_per_grp;
|
||||
init_ns = mgr.Init_ns();
|
||||
} int itms_per_grp, ttls_len, itm_pct; Xowd_page_itm[] ttls; Xow_ns init_ns;
|
||||
public void XferAry_end() {ttls = null;}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
int itm_end = itm_idx + itms_per_grp;
|
||||
for (int i = itm_idx; i < itm_end; i++) {
|
||||
if (i >= ttls_len) break; // handle odd number of itms; EX: interval=3; items=4; proc gets called on 0 (0-2) and 3 (3-5); ArrayIndex for 4, 5
|
||||
Xowd_page_itm ttl_itm = ttls[i];
|
||||
if (ttl_itm == null) break; // ttl_itm can be null at bgn or end of title list; EX: list=A-Z; count=5; key=Z; itms=X,Y,Z,null,null
|
||||
Xoa_ttl ttl = Xows_page_allpages.ttl_(wiki, init_ns, ttl_itm);
|
||||
byte[] href = href_wtr.Build_to_bry(wiki, ttl);
|
||||
byte[] title = ttl.Full_txt_w_ttl_case();
|
||||
byte[] cls = Xoh_lnki_wtr.Lnki_cls_visited(history_mgr, wiki_key, ttl.Page_txt()); // NOTE: must be ttl.Page_txt() in order to match Xou_history_mgr.Add
|
||||
Bry_fmtr fmtr = ttl_itm.Redirected() ? itm_redirect : itm_normal;
|
||||
fmtr.Bld_bfr_many(bfr, itm_pct, href, title, ttl.Full_txt_w_ttl_case(), cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
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.specials.allPages; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import org.junit.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.wikis.tdbs.hives.*;
|
||||
public class Xows_page_allpages_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xows_page_allpages_fxt fxt = new Xows_page_allpages_fxt();
|
||||
@Test public void Build_data() {
|
||||
Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 5, 7);
|
||||
fxt.Clear().Init_ttl_leaf("/B1").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // SpecialPage:AllPages/B1
|
||||
fxt.Clear().Init_arg("from", "B1").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // single file
|
||||
fxt.Clear().Init_arg("from", "A6").Expd_prv("A1").Expd_nxt("B4").Expd_ttls("A6", "B0", "B1", "B2", "B3").Test_build_data(); // overflow rhs
|
||||
fxt.Clear().Init_arg("from", "E4").Expd_prv("D6").Expd_nxt("E6").Expd_ttls("E4", "E5", "E6", null, null).Test_build_data(); // bounds rhs
|
||||
fxt.Clear().Init_arg("from", "A0").Expd_prv("A0").Expd_nxt("A5").Expd_ttls("A0", "A1", "A2", "A3", "A4").Test_build_data(); // bounds lhs
|
||||
fxt.Clear().Init_arg("from", "B0a").Expd_prv("A3").Expd_nxt("B6").Expd_ttls("B1", "B2", "B3", "B4", "B5").Test_build_data(); // inexact match; B0a matches "hi" value
|
||||
fxt.Clear().Init_arg("from", "B1").Init_arg("hideredirects", "1").Expd_prv("A0").Expd_nxt("C4").Expd_ttls("B2", "B4", "B6", "C0", "C2").Test_build_data(); // hide redirects
|
||||
fxt.Clear().Init_arg("from", "A6").Expd_prv("A0").Expd_nxt("E1").Init_itms_per_page(23).Expd_ttls("A6", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "E0").Test_build_data(); // overflow rhs x2
|
||||
}
|
||||
@Test public void Build_html_main() {
|
||||
Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 5, 7);
|
||||
fxt.Clear().Init_arg("from", "B2").Init_itms_per_page(5).Test_build_html(String_.Concat_lines_nl
|
||||
( "<table class=\"mw-allpages-table-form\">"
|
||||
, " <tr>"
|
||||
, " <td class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A4\" title=\"Special:AllPages\">Previous page (A4)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=C0\" title=\"Special:AllPages\">Next page (C0)</a>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, "<table class=\"mw-allpages-table-chunk\">"
|
||||
, "<tbody>"
|
||||
, " <tr>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/B2\" title=\"B2\">B2</a></td>"
|
||||
, " <td style=\"width:33%\"><div class=\"allpagesredirect\"><a href=\"/wiki/B3\" class=\"mw-redirect\" title=\"B3\">B3</a></div></td>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/B4\" title=\"B4\">B4</a></td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td style=\"width:33%\"><div class=\"allpagesredirect\"><a href=\"/wiki/B5\" class=\"mw-redirect\" title=\"B5\">B5</a></div></td>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/B6\" title=\"B6\">B6</a></td>"
|
||||
, " </tr>"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "<hr/>"
|
||||
, "<div class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A4\" title=\"Special:AllPages\">Previous page (A4)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=C0\" title=\"Special:AllPages\">Next page (C0)</a>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Build_html_redirect() {
|
||||
Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), 1, 7);
|
||||
fxt.Clear().Init_arg("from", "A2").Init_arg("hideredirects", "1").Init_itms_per_page(2).Test_build_html(String_.Concat_lines_nl
|
||||
( "<table class=\"mw-allpages-table-form\">"
|
||||
, " <tr>"
|
||||
, " <td class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A0&hideredirects=1\" title=\"Special:AllPages\">Previous page (A0)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A6&hideredirects=1\" title=\"Special:AllPages\">Next page (A6)</a>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, "<table class=\"mw-allpages-table-chunk\">"
|
||||
, "<tbody>"
|
||||
, " <tr>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/A2\" title=\"A2\">A2</a></td>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/A4\" title=\"A4\">A4</a></td>"
|
||||
, " </tr>"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "<hr/>"
|
||||
, "<div class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A0&hideredirects=1\" title=\"Special:AllPages\">Previous page (A0)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A6&hideredirects=1\" title=\"Special:AllPages\">Next page (A6)</a>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Build_html_ns() {
|
||||
Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), fxt.Wiki().Ns_mgr().Ns_template(), 1, 7);
|
||||
fxt.Clear().Init_arg("from", "A2").Init_arg("namespace", "10").Init_itms_per_page(2).Test_build_html(String_.Concat_lines_nl
|
||||
( "<table class=\"mw-allpages-table-form\">"
|
||||
, " <tr>"
|
||||
, " <td class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A0&namespace=10\" title=\"Special:AllPages\">Previous page (Template:A0)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A4&namespace=10\" title=\"Special:AllPages\">Next page (Template:A4)</a>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, "<table class=\"mw-allpages-table-chunk\">"
|
||||
, "<tbody>"
|
||||
, " <tr>"
|
||||
, " <td style=\"width:33%\"><a href=\"/wiki/Template:A2\" title=\"Template:A2\">Template:A2</a></td>"
|
||||
, " <td style=\"width:33%\"><div class=\"allpagesredirect\"><a href=\"/wiki/Template:A3\" class=\"mw-redirect\" title=\"Template:A3\">Template:A3</a></div></td>"
|
||||
, " </tr>"
|
||||
, "</tbody>"
|
||||
, "</table>"
|
||||
, "<hr/>"
|
||||
, "<div class=\"mw-allpages-nav\">"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A0&namespace=10\" title=\"Special:AllPages\">Previous page (Template:A0)</a> |"
|
||||
, "<a href=\"/wiki/Special:AllPages?from=A4&namespace=10\" title=\"Special:AllPages\">Next page (Template:A4)</a>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
@Test public void Misc() {
|
||||
Xow_hive_mgr_fxt.Ttls_create_rng(fxt.Wiki(), fxt.Wiki().Ns_mgr().Ns_template(), 1, 7);
|
||||
fxt.Clear().Init_arg("from", "Template:B1").Expd_arg("from", "B1").Expd_arg("namespace", "10").Test_build_data(); // extract ns from ttl
|
||||
fxt.Clear().Init_arg("from", "Template:B1").Expd_display_ttl("All pages").Expd_address_page("Special:AllPages").Test_special_gen(); // display ttl
|
||||
}
|
||||
}
|
||||
class Xows_page_allpages_fxt {
|
||||
public Xows_page_allpages_fxt Clear() {
|
||||
if (app == null) {
|
||||
app = Xoa_app_fxt.Make__app__edit();
|
||||
wiki = Xoa_app_fxt.Make__wiki__edit(app);
|
||||
allpages = wiki.Special_mgr().Page_allpages();
|
||||
Gfo_invk_.Invk_by_val(allpages, Xows_page_allpages.Invk_itms_per_page_, 5);
|
||||
}
|
||||
init_ttl_leaf = "";
|
||||
expd_prv = expd_nxt = null;
|
||||
expd_ttls = null;
|
||||
expd_display_ttl = null;
|
||||
return this;
|
||||
} private Xoae_app app;
|
||||
public Xowe_wiki Wiki() {return wiki;} private Xowe_wiki wiki; Xows_page_allpages allpages;
|
||||
public Xows_page_allpages_fxt Init_arg(String key, String val) {init_args.Add(new Gfo_qarg_itm(Bry_.new_a7(key), Bry_.new_a7(val))); return this;} private List_adp init_args = List_adp_.New();
|
||||
public Xows_page_allpages_fxt Init_ttl_leaf(String val) {init_ttl_leaf = val; return this;} private String init_ttl_leaf;
|
||||
public Xows_page_allpages_fxt Init_itms_per_page(int v) {init_itms_per_page = v; return this;} private int init_itms_per_page = 5;
|
||||
public Xows_page_allpages_fxt Expd_arg(String key, String val) {expd_args.Add(new Gfo_qarg_itm(Bry_.new_a7(key), Bry_.new_a7(val))); return this;} private List_adp expd_args = List_adp_.New();
|
||||
public Xows_page_allpages_fxt Expd_prv(String v) {expd_prv = v; return this;} private String expd_prv;
|
||||
public Xows_page_allpages_fxt Expd_nxt(String v) {expd_nxt = v; return this;} private String expd_nxt;
|
||||
public Xows_page_allpages_fxt Expd_ttls(String... v) {expd_ttls = v; return this;} private String[] expd_ttls;
|
||||
public Xows_page_allpages_fxt Expd_display_ttl(String v) {expd_display_ttl = v; return this;} private String expd_display_ttl;
|
||||
public Xows_page_allpages_fxt Expd_address_page(String v) {expd_address_page = v; return this;} private String expd_address_page;
|
||||
|
||||
public static String Xto_str(Xowe_wiki wiki, Xowd_page_itm v) {
|
||||
if (v == null) return null;
|
||||
Xow_ns ns = wiki.Ns_mgr().Ids_get_or_null(v.Ns_id());
|
||||
String ns_str = ns == null ? "" : String_.new_a7(ns.Name_db_w_colon());
|
||||
return ns_str + String_.new_a7(v.Ttl_page_db());
|
||||
}
|
||||
public static String[] Xto_str_ary(Xowe_wiki wiki, Xowd_page_itm[] ary) {
|
||||
int ary_len = ary.length;
|
||||
String[] rv = new String[ary_len];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Xowd_page_itm itm = ary[i];
|
||||
rv[i] = Xto_str(wiki, itm);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public static String[] Xto_str_ary(Gfo_qarg_itm[] ary) {
|
||||
int ary_len = ary.length;
|
||||
String[] rv = new String[ary_len];
|
||||
for (int i = 0; i < ary_len; i++) {
|
||||
Gfo_qarg_itm itm = ary[i];
|
||||
rv[i] = String_.new_u8(itm.Key_bry()) + "=" + String_.new_u8(itm.Val_bry());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public Xows_page_allpages_fxt Test_special_gen() {
|
||||
init_url = app.User().Wikii().Utl__url_parser().Parse(Xow_special_meta_.Itm__all_pages.Ttl_bry());
|
||||
Xoa_ttl init_ttl = Make_init_ttl();
|
||||
allpages.Special__gen(wiki, wiki.Parser_mgr().Ctx().Page(), init_url, init_ttl);
|
||||
if (expd_display_ttl != null) Tfds.Eq(expd_display_ttl, String_.new_u8(wiki.Parser_mgr().Ctx().Page().Html_data().Display_ttl()));
|
||||
if (expd_address_page != null) Tfds.Eq(expd_address_page, String_.new_u8(init_url.Page_bry()));
|
||||
return this;
|
||||
}
|
||||
public Xows_page_allpages_fxt Test_build_data() {
|
||||
Exec_build();
|
||||
if (expd_ttls != null) Tfds.Eq_ary_str(expd_ttls, Xto_str_ary(wiki, allpages.Rslt_list_ttls()));
|
||||
if (expd_nxt != null) Tfds.Eq(expd_nxt, Xto_str(wiki, allpages.Rslt_nxt()));
|
||||
if (expd_prv != null) Tfds.Eq(expd_prv, Xto_str(wiki, allpages.Rslt_prv()));
|
||||
if (expd_args.Count() > 0) {
|
||||
Gfo_qarg_itm[] expd_args_ary = (Gfo_qarg_itm[])expd_args.To_ary(Gfo_qarg_itm.class);
|
||||
Tfds.Eq_ary_str(Xto_str_ary(expd_args_ary), Xto_str_ary(init_url.Qargs_ary()));
|
||||
}
|
||||
return this;
|
||||
} private Xoa_url init_url = Xoa_url.blank();
|
||||
public Xows_page_allpages_fxt Test_build_html(String expd) {
|
||||
Exec_build();
|
||||
allpages.Build_html(wiki.Parser_mgr().Ctx().Page());
|
||||
Tfds.Eq_str_lines(expd, String_.new_a7(wiki.Parser_mgr().Ctx().Page().Db().Text().Text_bry()));
|
||||
return this;
|
||||
}
|
||||
private void Exec_build() {
|
||||
if (allpages.Itms_per_page() != init_itms_per_page) allpages.Itms_per_page_(init_itms_per_page);
|
||||
init_url.Qargs_ary_((Gfo_qarg_itm[])init_args.To_ary(Gfo_qarg_itm.class));
|
||||
init_args.Clear();
|
||||
Xoa_ttl init_ttl = Make_init_ttl();
|
||||
allpages.Build_data(init_url, init_ttl);
|
||||
}
|
||||
private Xoa_ttl Make_init_ttl() {return Xoa_ttl.Parse(wiki, Bry_.new_u8(Xow_special_meta_.Itm__all_pages.Ttl_str() + init_ttl_leaf));}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
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.specials.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.xowa.specials.*;
|
||||
public class Xoa_special_regy {
|
||||
private final Ordered_hash hash = Ordered_hash_.New_bry(); // NOTE: case-sensitive; case-insensitive requires lang, but regy is at app level
|
||||
public int Len() {return hash.Len();}
|
||||
public Xow_special_page Get_at(int i) {return (Xow_special_page)hash.Get_at(i);}
|
||||
public Xow_special_page Get_by_or_null(byte[] key) {return (Xow_special_page)hash.Get_by(key);}
|
||||
public void Add(Xow_special_page page) {
|
||||
hash.Add(page.Special__meta().Key_bry(), page);
|
||||
byte[][] aliases = page.Special__meta().Aliases();
|
||||
for (byte[] alias : aliases)
|
||||
hash.Add(alias, page);
|
||||
}
|
||||
public void Add_many(Xow_special_page... ary) {for (Xow_special_page itm : ary) Add(itm);}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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.specials.mgrs; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.net.*;
|
||||
import gplx.xowa.htmls.*;
|
||||
import gplx.xowa.wikis.*;
|
||||
import gplx.xowa.langs.specials.*;
|
||||
public class Xosp_special_mgr {
|
||||
// private final Xowv_wiki wiki;
|
||||
private final Hash_adp_bry hash;
|
||||
public Xosp_special_mgr(Xowv_wiki wiki) {
|
||||
// this.wiki = wiki;
|
||||
// hash.Add_str_obj(Xow_special_meta_.Ttl__statistics , page_statistics);
|
||||
this.hash = Hash_adp_bry.cs();
|
||||
}
|
||||
public void Get_by_ttl(Xoh_page rv, Gfo_url url, Xoa_ttl ttl) {
|
||||
// Xosp_fbrow_rslt rslt = Xosp_fbrow_special.Gen(url.Qargs(), wiki.Appv().Wiki_mgr());
|
||||
// rv.Init(wiki, null, ttl, -1);
|
||||
// rv.Body_(rslt.Html_body());
|
||||
// rv.Html_head_xtn_(rslt.Html_head());
|
||||
}
|
||||
public void Get_by_url1(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
int slash_pos = Bry_find_.Find_fwd(ttl.Page_txt_wo_qargs(), Xoa_ttl.Subpage_spr); // check for slash
|
||||
byte[] special_name = slash_pos == Bry_find_.Not_found
|
||||
? ttl.Base_txt_wo_qarg() // no slash found; use base_txt; ignore qry args and just get page_names; EX: Search/Earth?fulltext=y; Allpages?from=Earth...
|
||||
: Bry_.Mid(ttl.Page_txt_wo_qargs(), 0, slash_pos); // slash found; use root page; EX: Special:ItemByTitle/enwiki/Earth
|
||||
Object o = hash.Get_by_bry(special_name);
|
||||
if (o == null) {
|
||||
Xol_specials_itm special_itm = wiki.Lang().Specials_mgr().Get_by_alias(special_name);
|
||||
if (special_itm != null)
|
||||
o = hash.Get_by_bry(special_itm.Special());
|
||||
}
|
||||
if (o != null) {
|
||||
// Xow_special_page special = (Xow_special_page)o;
|
||||
// page.Revision_data().Modified_on_(Datetime_now.Get());
|
||||
// special.Special__gen(wiki, page, url, ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
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.specials.movePage; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.langs.msgs.*;
|
||||
import gplx.xowa.htmls.hrefs.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
import gplx.xowa.parsers.utils.*;
|
||||
public class Move_page implements Xow_special_page {
|
||||
private Move_trg_ns_list_fmtr ns_list_fmtr = new Move_trg_ns_list_fmtr();
|
||||
private Move_url_args args = new Move_url_args();
|
||||
private Xoa_ttl src_ttl;
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__move_page;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
args.Parse(url);
|
||||
byte[] src_ttl_bry = args.Src_ttl();
|
||||
src_ttl = Xoa_ttl.Parse(wiki, src_ttl_bry);
|
||||
if (args.Submitted()) {
|
||||
Exec_rename(wiki, page);
|
||||
return;
|
||||
}
|
||||
byte[] html = Bld_html(page);
|
||||
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
|
||||
page.Db().Text().Text_bry_(html);
|
||||
}
|
||||
private void Exec_rename(Xowe_wiki wiki, Xoae_page page) {
|
||||
gplx.xowa.wikis.dbs.Xodb_save_mgr save_mgr = wiki.Db_mgr().Save_mgr();
|
||||
int trg_ns_id = args.Trg_ns();
|
||||
Xow_ns trg_ns = wiki.Ns_mgr().Ids_get_or_null(trg_ns_id); if (trg_ns == null) throw Err_.new_wo_type("unknown ns", "ns", trg_ns_id);
|
||||
byte[] trg_ttl_bry = args.Trg_ttl();
|
||||
Xoa_ttl trg_ttl = Xoa_ttl.Parse(wiki, trg_ns_id, trg_ttl_bry);
|
||||
Xowd_page_itm src_page = new Xowd_page_itm();
|
||||
wiki.Db_mgr().Load_mgr().Load_by_ttl(src_page, src_ttl.Ns(), src_ttl.Page_db());
|
||||
page.Db().Page().Id_(src_page.Id()).Modified_on_(src_page.Modified_on());
|
||||
page.Db().Text().Text_bry_(src_page.Text());
|
||||
if (args.Create_redirect()) { // NOTE: not tested; DATE:2014-02-27
|
||||
save_mgr.Data_update(page, Xop_redirect_mgr.Make_redirect_text(trg_ttl.Full_db()));
|
||||
Xowd_page_itm trg_page = new Xowd_page_itm();
|
||||
boolean trg_page_exists = wiki.Db_mgr().Load_mgr().Load_by_ttl(trg_page, trg_ns, trg_ttl_bry);
|
||||
if (trg_page_exists)
|
||||
save_mgr.Data_update(page, page.Db().Text().Text_bry());
|
||||
else
|
||||
save_mgr.Data_create(trg_ttl, page.Db().Text().Text_bry());
|
||||
}
|
||||
else
|
||||
save_mgr.Data_rename(page, trg_ns_id, trg_ttl_bry);
|
||||
wiki.Data_mgr().Redirect(page, trg_ns.Gen_ttl(trg_ttl_bry));
|
||||
}
|
||||
private byte[] Bld_html(Xoae_page page) {
|
||||
Xowe_wiki wiki = page.Wikie(); Xow_msg_mgr msg_mgr = wiki.Msg_mgr();
|
||||
if (src_ttl == null) return Bry_.Empty;
|
||||
ns_list_fmtr.Init_by_page(wiki, page, src_ttl);
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
wiki.Parser_mgr().Main().Parse_text_to_html(tmp_bfr, wiki.Parser_mgr().Ctx(), page, true, msg_mgr.Val_by_key_obj("movepagetext"));
|
||||
fmtr_all.Bld_bfr_many(tmp_bfr
|
||||
, msg_mgr.Val_by_key_obj("move-page-legend")
|
||||
, Bry_.Add(Xoh_href_.Bry__wiki, src_ttl.Full_db())
|
||||
, gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(src_ttl.Full_txt_w_ttl_case())
|
||||
, src_ttl.Full_txt_w_ttl_case()
|
||||
, msg_mgr.Val_by_key_obj("newtitle")
|
||||
, ns_list_fmtr
|
||||
, args.Trg_ttl()
|
||||
, msg_mgr.Val_by_key_obj("move-leave-redirect")
|
||||
, msg_mgr.Val_by_key_obj("movepagebtn")
|
||||
);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<form action='/wiki/Special:MovePage' id='movepage'>"
|
||||
, " <fieldset>"
|
||||
, " <legend>~{move-page-legend}</legend>"
|
||||
, " <table id='mw-movepage-table'>"
|
||||
, " <tr>"
|
||||
, " <td class='mw-label'>Move page:</td>"
|
||||
, " <td class='mw-input'>"
|
||||
, " <strong><a href='~{src_href}' title='~{src_title}'>~{src_text}</a></strong>"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td class='mw-label'>"
|
||||
, " <label for='wpNewTitleMain'>~{newtitle}</label>"
|
||||
, " </td>"
|
||||
, " <td class='mw-input'>"
|
||||
, " <select id='wpNewTitleNs' name='wpNewTitleNs'>~{trg_ns_list}"
|
||||
, " </select>"
|
||||
, " <input name='wpNewTitleMain' size='60' value='~{trg_title}' type='text' id='wpNewTitleMain' maxlength='255' />"
|
||||
, " <input type='hidden' value='~{src_title}' name='wpOldTitle' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, "<!-- <tr>"
|
||||
, " <td></td>"
|
||||
, " <td class='mw-input'>"
|
||||
, " <input name='wpLeaveRedirect' type='checkbox' value='1' checked='checked' id='wpLeaveRedirect' /> <label for='wpLeaveRedirect'>~{move-leave-redirect}</label>"
|
||||
, " </td>"
|
||||
, " </tr> -->"
|
||||
, " <tr>"
|
||||
, " <td> </td>"
|
||||
, " <td class='mw-submit'>"
|
||||
, " <input type='submit' value='~{movepagebtn}' name='wpMove' />"
|
||||
, " </td>"
|
||||
, " </tr>"
|
||||
, " </table>"
|
||||
, " </fieldset>"
|
||||
, "</form>"
|
||||
), "move-page-legend", "src_href", "src_title", "src_text", "newtitle", "trg_ns_list", "trg_title", "move-leave-redirect", "movepagebtn");
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
class Move_trg_ns_list_fmtr implements gplx.core.brys.Bfr_arg {
|
||||
private Xowe_wiki wiki; private Xoa_ttl ttl;
|
||||
public void Init_by_page(Xowe_wiki wiki, Xoae_page page, Xoa_ttl ttl) {
|
||||
this.wiki = wiki;
|
||||
this.ttl = ttl;
|
||||
}
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
|
||||
int ns_len = ns_mgr.Ids_len();
|
||||
for (int i = 0; i < ns_len; i++) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_at(i);
|
||||
if (ns.Is_meta()) continue; // ignore [[Special:]] and [[Media:]]
|
||||
byte[] bry_selected = ttl.Ns().Id() == ns.Id() ? Bry_selected : Bry_.Empty;
|
||||
fmtr.Bld_bfr_many(bfr, ns.Id(), bry_selected, ns.Name_combo());
|
||||
}
|
||||
}
|
||||
private static final byte[] Bry_selected = Bry_.new_a7(" selected=''");
|
||||
private Bry_fmtr fmtr = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <option value='~{ns_id}' ~{ns_selected}>~{ns_name}</option>"
|
||||
), "ns_id", "ns_selected", "ns_name");
|
||||
}
|
||||
class Move_url_args {
|
||||
public boolean Submitted() {return submitted;} private boolean submitted;
|
||||
public byte[] Src_ttl() {return src_ttl;} private byte[] src_ttl;
|
||||
public byte[] Trg_ttl() {return trg_ttl;} private byte[] trg_ttl;
|
||||
public int Trg_ns() {return trg_ns;} private int trg_ns;
|
||||
public boolean Create_redirect() {return create_redirect;} private boolean create_redirect;
|
||||
public void Parse(Xoa_url url) {
|
||||
this.Clear();
|
||||
Gfo_qarg_itm[] args = url.Qargs_ary();
|
||||
int args_len = args.length;
|
||||
for (int i = 0; i < args_len; i++) {
|
||||
Gfo_qarg_itm arg = args[i];
|
||||
Object tid_obj = arg_keys.Get_by(arg.Key_bry());
|
||||
byte[] val_bry = arg.Val_bry();
|
||||
if (tid_obj != null) {
|
||||
switch (((Byte_obj_val)tid_obj).Val()) {
|
||||
case Key_submitted: submitted = true; break; // wpMove will only be in query_args if move button is pressed
|
||||
case Key_src_ttl: src_ttl = val_bry; break;
|
||||
case Key_trg_ns: trg_ns = Bry_.To_int(val_bry); break;
|
||||
case Key_trg_ttl: trg_ttl = val_bry; break;
|
||||
case Key_create_redirect: create_redirect = Bry_.To_bool_by_int(val_bry); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Clear() {
|
||||
submitted = false;
|
||||
src_ttl = trg_ttl = null;
|
||||
trg_ns = Int_.Min_value;
|
||||
create_redirect = false;
|
||||
}
|
||||
private static final byte Key_submitted = 1, Key_src_ttl = 2, Key_trg_ns = 3, Key_trg_ttl = 4, Key_create_redirect = 5;
|
||||
private static final Hash_adp_bry arg_keys = Hash_adp_bry.ci_a7()
|
||||
.Add_str_byte("wpMove" , Key_submitted)
|
||||
.Add_str_byte("wpOldTitle" , Key_src_ttl)
|
||||
.Add_str_byte("wpNewTitleNs" , Key_trg_ns)
|
||||
.Add_str_byte("wpNewTitleMain" , Key_trg_ttl)
|
||||
.Add_str_byte("wpLeaveRedirect" , Key_create_redirect)
|
||||
;
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
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.specials.nearby; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.parsers.*; import gplx.xowa.parsers.lnkis.*;
|
||||
public class Nearby_mgr implements Xow_special_page {
|
||||
Xowe_wiki wiki; byte[] trg;
|
||||
private Hash_adp_bry excluded = Hash_adp_bry.ci_a7();
|
||||
private Hash_adp_bry visited = Hash_adp_bry.ci_a7();
|
||||
List_adp trail = List_adp_.New();
|
||||
List_adp results = List_adp_.New();
|
||||
int results_cur = 0;
|
||||
// int depth_max = 5;
|
||||
// int pages_count = 0;
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
public int Results_max() {return results_max;} public Nearby_mgr Results_max_(int v) {results_max = v; return this;} private int results_max = 1;
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__nearby;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
page.Db().Text().Text_bry_(Bld_html(wiki));
|
||||
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
|
||||
// wiki.Parser_mgr().Parse(page, false); // do not clear else previous Search_text will be lost
|
||||
}
|
||||
byte[] Bld_html(Xowe_wiki wiki) {
|
||||
form_fmtr.Bld_bfr_many(tmp_bfr);
|
||||
List_adp list = Find_from_to(wiki, Bry_.new_a7("Earth"), Bry_.new_a7("Atom"), excluded);
|
||||
tmp_bfr.Add_str_a7("<table>");
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Nearby_rslt rslt = (Nearby_rslt)list.Get_at(i);
|
||||
tmp_bfr.Add_str_a7("<tr>");
|
||||
int cell_len = rslt.Len();
|
||||
for (int j = 0; j < cell_len; j++) {
|
||||
Xoa_ttl ttl = (Xoa_ttl)rslt.Get_at(j);
|
||||
tmp_bfr.Add_str_a7("<td>[[");
|
||||
tmp_bfr.Add(ttl.Page_db());
|
||||
tmp_bfr.Add_str_a7("]]</td>");
|
||||
}
|
||||
tmp_bfr.Add_str_a7("</tr>");
|
||||
}
|
||||
tmp_bfr.Add_str_a7("</table>");
|
||||
return tmp_bfr.To_bry_and_clear();
|
||||
}
|
||||
Bry_fmtr form_fmtr = Bry_fmtr.new_(String_.Concat_lines_nl
|
||||
( "<form id='xowa_nearby_form' action='/wiki/Special:XowaNearby'>"
|
||||
, "<table>"
|
||||
, " <tr><td>From:</td><td><input name='xowa_bgn' value='Earth' /></td></tr>"
|
||||
, " <tr><td>To: </td><td><input name='xowa_end' value='Atom' /></td></tr>"
|
||||
, " <tr><td>Max: </td><td><input name='xowa_max' value='1' /></td></tr>"
|
||||
, " <tr><td>Skip:</td><td><input name='xowa_skip' value='' /></td></tr>"
|
||||
, " <tr><td/><td align='right'><input type='submit' value='go' /></td></tr>"
|
||||
, "</table>"
|
||||
, "</form>"
|
||||
));
|
||||
Xoa_ttl trg_ttl;
|
||||
Ordered_hash src_pool = Ordered_hash_.New_bry();
|
||||
public List_adp Find_from_to(Xowe_wiki wiki, byte[] src_bry, byte[] trg_bry, Hash_adp_bry excluded) {
|
||||
this.wiki = wiki; this.excluded = excluded;
|
||||
Xoa_ttl src_ttl = Xoa_ttl.Parse(wiki, src_bry); if (src_ttl == null) return List_adp_.Noop;
|
||||
trg_ttl = Xoa_ttl.Parse(wiki, trg_bry); if (trg_ttl == null) return List_adp_.Noop;
|
||||
trg = trg_ttl.Page_db();
|
||||
trail.Clear();
|
||||
results.Clear();
|
||||
results_cur = 0;
|
||||
// pages_count = 0;
|
||||
visited.Clear();
|
||||
src_pool.Clear();
|
||||
src_pool.Add(src_ttl.Page_db(), new Nearby_itmx(trail, src_ttl));
|
||||
Examine_page(src_pool);
|
||||
return results;
|
||||
}
|
||||
private void Examine_page(Ordered_hash src_pool){
|
||||
int len = src_pool.Count();
|
||||
Ordered_hash next_pool = Ordered_hash_.New_bry();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Nearby_itmx itmx = (Nearby_itmx)src_pool.Get_at(i);
|
||||
Xoa_ttl ttl = itmx.Ttl();
|
||||
byte[] ttl_bry = ttl.Page_db();
|
||||
if (excluded.Has(ttl_bry)) continue;
|
||||
if (visited.Has(ttl_bry)) continue;
|
||||
visited.Add_bry_bry(ttl_bry);
|
||||
Xoae_page page = wiki.Data_mgr().Load_page_by_ttl(ttl);
|
||||
if (page.Db().Page().Exists_n()) continue;
|
||||
wiki.Parser_mgr().Parse(page, true);
|
||||
Ordered_hash lnkis = Ordered_hash_.New_bry();
|
||||
Collect_lnkis(lnkis, page.Root());
|
||||
if (lnkis.Has(trg)) {
|
||||
++results_cur;
|
||||
results.Add(new Nearby_rslt(itmx.Trail(), trg_ttl));
|
||||
if (results_cur == results_max) return;
|
||||
}
|
||||
int lnkis_len = lnkis.Count();
|
||||
for (int j = 0; j < lnkis_len; j++) {
|
||||
Xoa_ttl lnki_ttl = (Xoa_ttl)lnkis.Get_at(j);
|
||||
if (next_pool.Has(lnki_ttl.Page_db())) continue;
|
||||
Nearby_itmx next_itmx = new Nearby_itmx(itmx.Trail(), lnki_ttl);
|
||||
next_pool.Add(lnki_ttl.Page_db(), next_itmx);
|
||||
}
|
||||
}
|
||||
if (next_pool.Count() > 0)
|
||||
Examine_page(next_pool);
|
||||
// ++pages_count;
|
||||
// wiki.Parser_mgr().Parse(page, true);
|
||||
// Ordered_hash lnkis = Ordered_hash_.New_bry();
|
||||
// int len = lnkis.Count();
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Xoa_ttl lnki_ttl = (Xoa_ttl)lnkis.Get_at(i);
|
||||
// if (!lnki_ttl.Ns().Id_main()) continue;
|
||||
// if (Bry_.Eq(lnki_ttl.Page_db(), trg)) continue; // skip trg page
|
||||
// trail.Add(lnki_ttl);
|
||||
// Examine_page(wiki, lnki_ttl, trail);
|
||||
// List_adp_.Del_at_last(trail);
|
||||
// if (results_cur == results_max) return;
|
||||
// }
|
||||
}
|
||||
// private void Examine_page(Xowe_wiki wiki, Xoa_ttl ttl, List_adp trail){
|
||||
// byte[] ttl_bry = ttl.Page_db();
|
||||
// if (excluded.Has(ttl_bry)) return;
|
||||
// if (visited.Has(ttl_bry)) return;
|
||||
// visited.Add_bry_bry(ttl_bry);
|
||||
// Xoae_page page = wiki.Data_mgr().Get_page(ttl, false);
|
||||
// if (page.Missing()) return;
|
||||
// ++pages_count;
|
||||
// wiki.Parser_mgr().Parse(page, true);
|
||||
// Ordered_hash lnkis = Ordered_hash_.New_bry();
|
||||
// Collect_lnkis(lnkis, page.Root());
|
||||
// if (lnkis.Has(trg)) {
|
||||
// ++results_cur;
|
||||
// results.Add(new Nearby_rslt(trail, trg_ttl));
|
||||
// if (results_cur == results_max) return;
|
||||
// }
|
||||
// int len = lnkis.Count();
|
||||
// for (int i = 0; i < len; i++) {
|
||||
// Xoa_ttl lnki_ttl = (Xoa_ttl)lnkis.Get_at(i);
|
||||
// if (!lnki_ttl.Ns().Id_main()) continue;
|
||||
// if (Bry_.Eq(lnki_ttl.Page_db(), trg)) continue; // skip trg page
|
||||
// trail.Add(lnki_ttl);
|
||||
// Examine_page(wiki, lnki_ttl, trail);
|
||||
// List_adp_.Del_at_last(trail);
|
||||
// if (results_cur == results_max) return;
|
||||
// }
|
||||
// }
|
||||
private void Collect_lnkis(Ordered_hash lnkis, Xop_tkn_itm tkn) {
|
||||
if (tkn.Tkn_tid() == Xop_tkn_itm_.Tid_lnki) {
|
||||
Xop_lnki_tkn lnki_tkn = (Xop_lnki_tkn)tkn;
|
||||
Xoa_ttl lnki_ttl = lnki_tkn.Ttl();
|
||||
if (!lnkis.Has(lnki_ttl.Page_db()))
|
||||
lnkis.Add(lnki_ttl.Page_db(), lnki_ttl);
|
||||
}
|
||||
else {
|
||||
int len = tkn.Subs_len();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xop_tkn_itm sub = tkn.Subs_get(i);
|
||||
Collect_lnkis(lnkis, sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
class Nearby_rslt {
|
||||
public Nearby_rslt(List_adp trail, Xoa_ttl trg_ttl) {
|
||||
int len = trail.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_ttl ttl = (Xoa_ttl)trail.Get_at(i);
|
||||
list.Add(ttl);
|
||||
}
|
||||
list.Add(trg_ttl);
|
||||
}
|
||||
public int Len() {return list.Count();}
|
||||
public Xoa_ttl Get_at(int i) {return (Xoa_ttl)list.Get_at(i);}
|
||||
List_adp list = List_adp_.New();
|
||||
}
|
||||
class Nearby_itmx {
|
||||
public Nearby_itmx(List_adp v, Xoa_ttl ttl) {
|
||||
int len = v.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Xoa_ttl v_ttl = (Xoa_ttl)v.Get_at(i);
|
||||
trail.Add(v_ttl);
|
||||
}
|
||||
trail.Add(ttl);
|
||||
this.ttl = ttl;
|
||||
}
|
||||
public Xoa_ttl Ttl() {return ttl;} private Xoa_ttl ttl;
|
||||
public List_adp Trail() {return trail;} List_adp trail = List_adp_.New();
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
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.specials.nearby; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import org.junit.*;
|
||||
public class Nearby_mgr_tst {
|
||||
@Before public void init() {fxt.Clear();} Nearby_mgr_fxt fxt = new Nearby_mgr_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Init_page("A", "[[B]]");
|
||||
fxt.Test_find("A", "B", "A|B");
|
||||
}
|
||||
@Test public void Shortest() {
|
||||
fxt.Init_page("A", "[[B]]");
|
||||
fxt.Init_page("B", "[[C]] [[D]]");
|
||||
fxt.Init_page("C", "[[D]]");
|
||||
fxt.Test_find("A", "D", "A|B|D");
|
||||
fxt.Init_results_max(2).Test_find("A", "D", "A|B|D", "A|B|C|D");
|
||||
}
|
||||
@Test public void Circular() {
|
||||
fxt.Init_page("A", "[[B]]");
|
||||
fxt.Init_page("B", "[[C]]");
|
||||
fxt.Init_page("C", "[[A]]");
|
||||
fxt.Test_find("A", "D", "");
|
||||
}
|
||||
@Test public void Page_doesnt_exist() {
|
||||
fxt.Init_page("A", "[[B]]");
|
||||
fxt.Test_find("A", "C", "");
|
||||
}
|
||||
}
|
||||
class Nearby_mgr_fxt {
|
||||
public Nearby_mgr_fxt Clear() {
|
||||
if (fxt == null) {
|
||||
fxt = new Xop_fxt();
|
||||
nearby_mgr = new Nearby_mgr();
|
||||
excluded = Hash_adp_bry.ci_a7();
|
||||
tmp_bfr = Bry_bfr_.New();
|
||||
}
|
||||
fxt.Reset();
|
||||
Io_mgr.Instance.InitEngine_mem();
|
||||
nearby_mgr.Results_max_(1);
|
||||
return this;
|
||||
} private Xop_fxt fxt; Nearby_mgr nearby_mgr; Hash_adp_bry excluded; Bry_bfr tmp_bfr;
|
||||
public void Init_page(String ttl, String text) {fxt.Init_page_create(ttl, text);}
|
||||
public Nearby_mgr_fxt Init_results_max(int v) {nearby_mgr.Results_max_(v); return this;}
|
||||
public void Test_find(String src, String trg, String... expd) {
|
||||
List_adp actl = nearby_mgr.Find_from_to(fxt.Wiki(), Bry_.new_a7(src), Bry_.new_a7(trg), excluded);
|
||||
Tfds.Eq_ary(String_.SplitLines_nl(Xto_str(actl)), expd);
|
||||
}
|
||||
String Xto_str(List_adp list) {
|
||||
int len = list.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Nearby_rslt rslt = (Nearby_rslt)list.Get_at(i);
|
||||
int ttls = rslt.Len();
|
||||
if (i != 0) tmp_bfr.Add_byte_nl();
|
||||
for (int j = 0; j < ttls; j++) {
|
||||
Xoa_ttl ttl = rslt.Get_at(j);
|
||||
if (j != 0) tmp_bfr.Add_byte(Byte_ascii.Pipe);
|
||||
tmp_bfr.Add(ttl.Page_db());
|
||||
}
|
||||
}
|
||||
return tmp_bfr.To_str_and_clear();
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
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.specials.statistics; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.langs.*; import gplx.xowa.langs.msgs.*; import gplx.xowa.langs.numbers.*;
|
||||
import gplx.xowa.wikis.nss.*;
|
||||
public class Xop_statistics_page implements Xow_special_page {
|
||||
private Xop_statistics_stats_page_grp stats_page = new Xop_statistics_stats_page_grp();
|
||||
// private Xop_statistics_stats_wiki_grp stats_wiki = new Xop_statistics_stats_wiki_grp();
|
||||
private Xop_statistics_stats_ns_grp stats_ns = new Xop_statistics_stats_ns_grp();
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__statistics;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
byte[] html = Build_html(wiki);
|
||||
page.Html_data().Html_restricted_n_(); // [[Special:]] pages allow all HTML
|
||||
page.Db().Text().Text_bry_(html);
|
||||
}
|
||||
public byte[] Build_html(Xowe_wiki wiki) {
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
stats_page.Wiki_(wiki);
|
||||
// stats_wiki.Wiki_(wiki);
|
||||
stats_ns.Wiki_(wiki);
|
||||
fmtr_all.Bld_bfr_many(tmp_bfr, stats_page, stats_ns);
|
||||
return tmp_bfr.To_bry_and_rls();
|
||||
}
|
||||
private Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"mw-content-text\">"
|
||||
, "<table class=\"wikitable mw-statistics-table\">~{page_stats}~{ns_stats}"
|
||||
, "</table>"
|
||||
, "</div>"
|
||||
), "page_stats", "ns_stats");
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
class Xop_statistics_stats_page_grp implements gplx.core.brys.Bfr_arg {
|
||||
public void Wiki_(Xowe_wiki v) {this.wiki = v;} private Xowe_wiki wiki;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
byte[] lbl_header_pages = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_statistics_header_pages);
|
||||
byte[] lbl_articles = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_statistics_articles);
|
||||
byte[] lbl_pages = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_statistics_pages);
|
||||
byte[] lbl_pages_desc = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_statistics_pages_desc);
|
||||
Xol_num_mgr num_mgr = wiki.Lang().Num_mgr();
|
||||
fmtr_page.Bld_bfr_many(bfr, lbl_header_pages, lbl_articles, lbl_pages, lbl_pages_desc , num_mgr.Format_num_by_long(wiki.Stats().Num_articles()), num_mgr.Format_num_by_long(wiki.Stats().Num_pages()));
|
||||
}
|
||||
private Bry_fmtr fmtr_page = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <th colspan=\"2\">~{lbl_header_pages}</th>"
|
||||
, " </tr>"
|
||||
, " <tr class=\"mw-statistics-articles\">"
|
||||
, " <td>~{lbl_articles}</td>"
|
||||
, " <td class=\"mw-statistics-numbers\" style='text-align:right'>~{page_count_main}</td>"
|
||||
, " </tr>"
|
||||
, " <tr class=\"mw-statistics-pages\">"
|
||||
, " <td>~{lbl_pages}<br /><small class=\"mw-statistic-desc\"> ~{lbl_pages_desc}</small></td>"
|
||||
, " <td class=\"mw-statistics-numbers\" style='text-align:right'>~{page_count_all}</td>"
|
||||
, " </tr>"
|
||||
), "lbl_header_pages", "lbl_articles", "lbl_pages", "lbl_pages_desc", "page_count_main", "page_count_all");
|
||||
}
|
||||
class Xop_statistics_stats_ns_grp implements gplx.core.brys.Bfr_arg {
|
||||
private Xop_statistics_stats_ns_itm ns_itm_fmtr = new Xop_statistics_stats_ns_itm();
|
||||
public void Wiki_(Xowe_wiki v) {this.wiki = v; ns_itm_fmtr.Wiki_(v);} private Xowe_wiki wiki;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
byte[] lbl_header_ns = wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_statistics_header_ns);
|
||||
fmtr_ns_grp.Bld_bfr_many(bfr, lbl_header_ns, ns_itm_fmtr);
|
||||
}
|
||||
private Bry_fmtr fmtr_ns_grp = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <th colspan=\"2\">~{lbl_header_ns}</th>"
|
||||
, " </tr>~{ns_itms}"
|
||||
), "lbl_header_ns", "ns_itms");
|
||||
}
|
||||
class Xop_statistics_stats_ns_itm implements gplx.core.brys.Bfr_arg {
|
||||
public void Wiki_(Xowe_wiki v) {this.wiki = v;} private Xowe_wiki wiki;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
Xow_ns_mgr ns_mgr = wiki.Ns_mgr();
|
||||
int ns_len = ns_mgr.Count();
|
||||
for (int i = 0; i < ns_len; i++) {
|
||||
Xow_ns ns = ns_mgr.Ids_get_at(i);
|
||||
if (ns.Is_meta()) continue;
|
||||
if (ns.Count() == 0) continue;
|
||||
byte[] ns_name = ns.Id_is_main() ? wiki.Msg_mgr().Val_by_id(Xol_msg_itm_.Id_ns_blankns) : ns.Name_ui();
|
||||
fmtr_ns_itm.Bld_bfr_many(bfr, ns_name, wiki.Lang().Num_mgr().Format_num(ns.Count()));
|
||||
}
|
||||
}
|
||||
private Bry_fmtr fmtr_ns_itm = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <td>~{ns_name}</td>"
|
||||
, " <td style='text-align:right'>~{ns_count}</td>"
|
||||
, " </tr>"
|
||||
), "ns_name", "ns_count");
|
||||
}
|
||||
class Xop_statistics_stats_wiki_grp implements gplx.core.brys.Bfr_arg {
|
||||
public void Wiki_(Xowe_wiki v) {this.wiki = v;} private Xowe_wiki wiki;
|
||||
public void Bfr_arg__add(Bry_bfr bfr) {
|
||||
fmtr_wiki.Bld_bfr_many(bfr, wiki.Db_mgr().Tid_name(), wiki.Fsys_mgr().Root_dir().Raw(), Byte_.To_str(wiki.Db_mgr().Category_version()), wiki.Maint_mgr().Wiki_dump_date().XtoStr_fmt_iso_8561());
|
||||
}
|
||||
private Bry_fmtr fmtr_wiki = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( ""
|
||||
, " <tr>"
|
||||
, " <th colspan=\"2\">Wiki statistics</th>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>Wiki format</td>"
|
||||
, " <td>~{wiki_format}</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>Wiki location</td>"
|
||||
, " <td>~{wiki_url}</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>Category level</td>"
|
||||
, " <td>~{ctg_version}</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <td>Last page updated on</td>"
|
||||
, " <td>~{page_modified_max}</td>"
|
||||
, " </tr>"
|
||||
), "wiki_format", "wiki_url", "ctg_version", "page_modified_max");
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
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.specials.statistics; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*;
|
||||
import org.junit.*;
|
||||
public class Xop_statistics_page_tst {
|
||||
@Before public void init() {fxt.Clear();} private Xop_statistics_page_fxt fxt = new Xop_statistics_page_fxt();
|
||||
@Test public void Basic() {
|
||||
fxt.Test_html(String_.Concat_lines_nl_skip_last
|
||||
( "<div id=\"mw-content-text\">"
|
||||
, "<table class=\"wikitable mw-statistics-table\">"
|
||||
, " <tr>"
|
||||
, " <th colspan=\"2\">Page statistics</th>"
|
||||
, " </tr>"
|
||||
, " <tr class=\"mw-statistics-articles\">"
|
||||
, " <td>Content pages</td>"
|
||||
, " <td class=\"mw-statistics-numbers\" style='text-align:right'>0</td>"
|
||||
, " </tr>"
|
||||
, " <tr class=\"mw-statistics-pages\">"
|
||||
, " <td>Pages<br /><small class=\"mw-statistic-desc\"> All pages in the wiki, including talk pages, redirects, etc.</small></td>"
|
||||
, " <td class=\"mw-statistics-numbers\" style='text-align:right'>0</td>"
|
||||
, " </tr>"
|
||||
, " <tr>"
|
||||
, " <th colspan=\"2\">Namespace statistics</th>"
|
||||
, " </tr>"
|
||||
, "</table>"
|
||||
, "</div>"
|
||||
));
|
||||
}
|
||||
}
|
||||
class Xop_statistics_page_fxt {
|
||||
public void Clear() {
|
||||
parser_fxt = new Xop_fxt();
|
||||
parser_fxt.Reset();
|
||||
wiki = parser_fxt.Wiki();
|
||||
special_page = wiki.Special_mgr().Page_statistics();
|
||||
} private Xop_fxt parser_fxt; private Xop_statistics_page special_page; private Xowe_wiki wiki;
|
||||
public void Test_html(String expd) {
|
||||
Tfds.Eq_str_lines(expd, String_.new_u8(special_page.Build_html(wiki)));
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.default_tab; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
public class Default_tab_page implements Xow_special_page {
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__default_tab;}
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xoae_page page = (Xoae_page)pagei;
|
||||
page.Db().Text().Text_bry_(Bry_.Empty);
|
||||
page.Html_data().Custom_html_(Bry_.Empty);
|
||||
page.Html_data().Custom_tab_name_(Tab_name_bry);
|
||||
}
|
||||
public static final byte[] Tab_name_bry = Bry_.new_a7("New Tab");
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.diags; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.stores.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.dbs.engines.mems.*;
|
||||
class Db_rdr_utl {
|
||||
public static void Load_and_write(Db_conn conn, String sql, Bry_bfr bfr) {
|
||||
Write_to_bfr(bfr, Load(conn, sql));
|
||||
}
|
||||
public static Mem_qry_set Load_as_qry_set(Db_conn conn, Dbmeta_fld_list fld_list, String sql) {
|
||||
Mem_qry_set qry_set = new Mem_qry_set();
|
||||
DataRdr rdr = conn.Exec_sql_as_old_rdr(sql);
|
||||
try {
|
||||
int fld_count = rdr.FieldCount();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Mem_row row = new Mem_row();
|
||||
for (int i = 0; i < fld_count; ++i)
|
||||
row.Add(fld_list.Get_at(i).Name(), rdr.ReadAt(i));
|
||||
qry_set.Add(row);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
return qry_set;
|
||||
}
|
||||
public static Object[][] Load(Db_conn conn, String sql) {
|
||||
List_adp list = List_adp_.New();
|
||||
DataRdr rdr = conn.Exec_sql_as_old_rdr(sql);
|
||||
try {
|
||||
int fld_count = rdr.FieldCount();
|
||||
while (rdr.MoveNextPeer()) {
|
||||
Object[] row = new Object[fld_count];
|
||||
for (int i = 0; i < fld_count; ++i) {
|
||||
row[i] = rdr.ReadAt(i);
|
||||
}
|
||||
list.Add(row);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
rdr.Rls();
|
||||
}
|
||||
return (Object[][])list.To_ary_and_clear(Object[].class);
|
||||
}
|
||||
public static void Write_to_bfr(Bry_bfr bfr, Object[][] rows, int... skip) {
|
||||
int rows_len = rows.length;
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = (Object[])rows[i];
|
||||
int row_len = row.length;
|
||||
for (int j = 0; j < row_len; ++j) {
|
||||
if (skip != null && Int_.In(j, skip)) continue;
|
||||
Object val = row[j];
|
||||
bfr.Add_obj(val).Add_byte_pipe();
|
||||
}
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.diags; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.net.*; import gplx.core.net.qargs.*; import gplx.core.envs.*;
|
||||
import gplx.fsdb.*; import gplx.fsdb.meta.*;
|
||||
import gplx.xowa.files.origs.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
class Xows_cmd__file_check {
|
||||
private Io_url tmp_dir;
|
||||
public void Exec(Bry_bfr bfr, Xoa_app app, Xoa_url url, Gfo_qarg_mgr_old arg_hash) {
|
||||
byte[] wiki_bry = arg_hash.Get_val_bry_or(Arg_wiki, null); if (wiki_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no wiki: url=~{0}", url.Raw()); return;}
|
||||
byte[] file_bry = arg_hash.Get_val_bry_or(Arg_file, null); if (file_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no file: url=~{0}", url.Raw()); return;}
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_y(wiki_bry);
|
||||
tmp_dir = wiki.Fsys_mgr().Tmp_dir();
|
||||
boolean schema_1 = wiki.File__fsdb_core().File__schema_is_1();
|
||||
Fsdb_db_file atr_main = null;
|
||||
try {Write_kv(bfr, "machine.op_sys", Op_sys.Cur().Os_name());} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "app.version", Xoa_app_.Version);} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "cfg_file_retrieve", ((Xowe_wiki)wiki).File_mgr().Cfg_download().Enabled());} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "fsdb.schema_is_1", schema_1);} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "fsdb.mnt_file", wiki.File__fsdb_core().File__mnt_file().Url());} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "fsdb.abc_file", wiki.File__fsdb_core().File__abc_file__at(Fsm_mnt_mgr.Mnt_idx_main).Url());} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {
|
||||
atr_main = wiki.File__fsdb_core().File__atr_file__at(Fsm_mnt_mgr.Mnt_idx_main);
|
||||
Write_kv(bfr, "fsdb.atr_file", atr_main.Url());
|
||||
} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
try {Write_kv(bfr, "fsdb.orig", wiki.File__fsdb_core().File__orig_tbl_ary()[0].Conn().Conn_info().Raw());} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
Fsdb_sql_mkr sql_mkr = schema_1 ? Fsdb_sql_mkr__v1.Instance : Fsdb_sql_mkr__v2.Instance;
|
||||
String sql = "";
|
||||
try {
|
||||
Xof_orig_tbl orig_tbl = wiki.File__fsdb_core().File__orig_tbl_ary()[0];
|
||||
sql = sql_mkr.Orig_by_ttl(file_bry);
|
||||
Write_sect(bfr, "fsdb.orig.select", sql);
|
||||
Db_rdr_utl.Load_and_write(orig_tbl.Conn(), sql, bfr);
|
||||
} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
Object[][] rows = null;
|
||||
try {
|
||||
sql = sql_mkr.Fil_by_ttl(file_bry);
|
||||
Write_sect(bfr, "fsdb.fil.select", sql);
|
||||
rows = Db_rdr_utl.Load(atr_main.Conn(), sql);
|
||||
Db_rdr_utl.Write_to_bfr(bfr, rows);
|
||||
Write_thms(bfr, file_bry, sql_mkr, wiki.File__mnt_mgr().Mnts__get_main(), atr_main, rows);
|
||||
} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
}
|
||||
private void Write_thms(Bry_bfr bfr, byte[] file_bry, Fsdb_sql_mkr sql_mkr, Fsm_mnt_itm mnt_itm, Fsdb_db_file atr_main, Object[][] rows) {
|
||||
int rows_len = rows.length;
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
int file_id = Int_.cast(row[0]);
|
||||
String sql = sql_mkr.Thm_by_id(file_id);
|
||||
Write_sect(bfr, "fsdb.thm.select", sql);
|
||||
Object[][] thm_rows = Db_rdr_utl.Load(atr_main.Conn(), sql);
|
||||
Db_rdr_utl.Write_to_bfr(bfr, thm_rows);
|
||||
Write_bins(bfr, file_bry, sql_mkr, mnt_itm, thm_rows, 0, 6);
|
||||
Object bin_db_id_obj = row[4];
|
||||
if (bin_db_id_obj != null) {
|
||||
Write_bins(bfr, file_bry, sql_mkr, mnt_itm, rows, 0, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Write_bins(Bry_bfr bfr, byte[] file_bry, Fsdb_sql_mkr sql_mkr, Fsm_mnt_itm mnt_itm, Object[][] rows, int owner_id_ordinal, int bin_db_id_ordinal) {
|
||||
int rows_len = rows.length;
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
int bin_db_id = Int_.cast(row[bin_db_id_ordinal]); if (bin_db_id == -1) continue;
|
||||
Fsm_bin_fil bin_db = mnt_itm.Bin_mgr().Dbs__get_at(bin_db_id);
|
||||
int owner_id = Int_.cast(row[owner_id_ordinal]);
|
||||
String sql = sql_mkr.Bin_by_id(owner_id);
|
||||
Write_sect(bfr, "fsdb.bin.select", sql);
|
||||
Object[][] bin_rows = Db_rdr_utl.Load(bin_db.Conn(), sql);
|
||||
Db_rdr_utl.Write_to_bfr(bfr, bin_rows, 4);
|
||||
Export_bins(bfr, file_bry, bin_rows, 0, 4);
|
||||
}
|
||||
}
|
||||
private void Export_bins(Bry_bfr bfr, byte[] file_bry, Object[][] rows, int owner_id_ordinal, int bin_data_ordinal) {
|
||||
int rows_len = rows.length;
|
||||
Bry_bfr tmp_bfr = Bry_bfr_.New();
|
||||
for (int i = 0; i < rows_len; ++i) {
|
||||
Object[] row = rows[i];
|
||||
int owner_id = Int_.cast(row[owner_id_ordinal]);
|
||||
byte[] bin_data = (byte[])row[bin_data_ordinal];
|
||||
file_bry = gplx.xowa.files.repos.Xof_itm_ttl_.Remove_invalid(tmp_bfr, file_bry);
|
||||
Io_url bin_url = tmp_dir.GenSubFil(String_.new_u8(file_bry));
|
||||
bin_url = tmp_dir.GenSubFil(bin_url.NameOnly() + "_" + Int_.To_str(owner_id) + bin_url.Ext());
|
||||
Write_kv(bfr, "fsdb.bin.export", bin_url.Raw());
|
||||
Write_kv(bfr, "fsdb.bin.len", bin_data.length);
|
||||
Io_mgr.Instance.SaveFilBry(bin_url, bin_data);
|
||||
}
|
||||
}
|
||||
private static void Write_kv(Bry_bfr bfr, String key, Object val) {
|
||||
bfr.Add_str_u8(key);
|
||||
bfr.Add_str_a7(" = ");
|
||||
bfr.Add_obj(val);
|
||||
bfr.Add_byte_nl();
|
||||
}
|
||||
private static void Write_sect(Bry_bfr bfr, String key, Object val) {
|
||||
bfr.Add_byte_nl();
|
||||
bfr.Add_str_u8("------------------------------------------------------").Add_byte_nl();
|
||||
bfr.Add_str_u8(key).Add_str_a7(": ").Add_obj(val).Add_byte_nl();
|
||||
bfr.Add_str_u8("------------------------------------------------------").Add_byte_nl();
|
||||
}
|
||||
private static final byte[] Arg_wiki = Bry_.new_a7("wiki"), Arg_file = Bry_.new_a7("file");
|
||||
public static final Xows_cmd__file_check Instance = new Xows_cmd__file_check(); Xows_cmd__file_check() {}
|
||||
}
|
||||
interface Fsdb_sql_mkr {
|
||||
String Orig_by_ttl(byte[] ttl);
|
||||
String Fil_by_ttl(byte[] ttl);
|
||||
String Thm_by_id(int id);
|
||||
String Bin_by_id(int id);
|
||||
}
|
||||
abstract class Fsdb_sql_mkr__base {
|
||||
public String Fil_by_ttl(byte[] ttl) {return String_.Format("SELECT * FROM fsdb_fil WHERE fil_name = '{0}';", ttl);}
|
||||
public String Bin_by_id(int id) {return String_.Format("SELECT * FROM fsdb_bin WHERE bin_owner_id = {0};", id);}
|
||||
}
|
||||
class Fsdb_sql_mkr__v1 extends Fsdb_sql_mkr__base implements Fsdb_sql_mkr {
|
||||
public String Orig_by_ttl(byte[] ttl) {return String_.Format("SELECT * FROM wiki_orig WHERE orig_ttl = '{0}';", ttl);}
|
||||
public String Thm_by_id(int id) {return String_.Format("SELECT * FROM fsdb_xtn_thm WHERE thm_owner_id = {0};", id);}
|
||||
public static final Fsdb_sql_mkr Instance = new Fsdb_sql_mkr__v1(); Fsdb_sql_mkr__v1() {}
|
||||
}
|
||||
class Fsdb_sql_mkr__v2 extends Fsdb_sql_mkr__base implements Fsdb_sql_mkr {
|
||||
public String Orig_by_ttl(byte[] ttl) {return String_.Format("SELECT * FROM orig_reg WHERE orig_ttl = '{0}';", ttl);}
|
||||
public String Thm_by_id(int id) {return String_.Format("SELECT * FROM fsdb_thm WHERE thm_owner_id = {0};", id);}
|
||||
public static final Fsdb_sql_mkr Instance = new Fsdb_sql_mkr__v2(); Fsdb_sql_mkr__v2() {}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.diags; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.ios.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.fsdb.meta.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
class Xows_cmd__fs_check {
|
||||
public void Exec(Bry_bfr bfr, Xoa_app app, Xoa_url url, Gfo_qarg_mgr_old arg_hash) {
|
||||
byte[] dir_bry = arg_hash.Get_val_bry_or(Arg_dir, null);
|
||||
if (dir_bry != null) {
|
||||
Write_dir(bfr, Io_url_.new_dir_(String_.new_u8(dir_bry)));
|
||||
return;
|
||||
}
|
||||
byte[] wiki_bry = arg_hash.Get_val_bry_or(Arg_wiki, null); if (wiki_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no wiki: url=~{0}", url.Raw()); return;}
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_y(wiki_bry);
|
||||
Io_url wiki_dir = wiki.Fsys_mgr().Root_dir();
|
||||
Io_url file_dir = wiki.Fsys_mgr().File_dir();
|
||||
Write_dir(bfr, wiki_dir);
|
||||
Write_dir(bfr, file_dir);
|
||||
Write_dir(bfr, file_dir.GenSubDir(Fsm_mnt_tbl.Mnt_name_main));
|
||||
Write_dir(bfr, file_dir.GenSubDir(Fsm_mnt_tbl.Mnt_name_user));
|
||||
Write_dir(bfr, file_dir.GenSubDir("fsdb.update_00"));
|
||||
}
|
||||
private void Write_dir(Bry_bfr bfr, Io_url dir_url) {
|
||||
bfr.Add_byte_nl().Add_str_a7("scanning: ").Add_str_u8(dir_url.Raw()).Add_byte_nl();
|
||||
if (!Io_mgr.Instance.ExistsDir(dir_url)) return;
|
||||
IoItmDir dir_itm = Io_mgr.Instance.QueryDir_args(dir_url).Recur_(false).DirInclude_(true).ExecAsDir();
|
||||
IoItmList sub_itms = dir_itm.SubDirs(); int len = sub_itms.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
try {
|
||||
IoItmDir sub_itm = (IoItmDir)sub_itms.Get_at(i);
|
||||
bfr.Add_str_a7("dir").Add_byte_pipe().Add_str_u8(sub_itm.Name()).Add_byte_nl();
|
||||
} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
}
|
||||
sub_itms = dir_itm.SubFils(); len = sub_itms.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
try {
|
||||
IoItmFil sub_itm = (IoItmFil)sub_itms.Get_at(i);
|
||||
bfr.Add_str_a7("fil").Add_byte_pipe().Add_str_u8(sub_itm.Name()).Add_byte_pipe().Add_long_variable(sub_itm.Size()).Add_byte_pipe().Add_dte(sub_itm.ModifiedTime()).Add_byte_nl();
|
||||
} catch (Exception e) {bfr.Add_str_u8(Err_.Message_gplx_full(e));}
|
||||
}
|
||||
}
|
||||
public static final Xows_cmd__fs_check Instance = new Xows_cmd__fs_check(); Xows_cmd__fs_check() {}
|
||||
private static final byte[] Arg_wiki = Bry_.new_a7("wiki"), Arg_dir = Bry_.new_a7("dir");
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.diags; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.ios.*; import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.dbs.*;
|
||||
import gplx.fsdb.meta.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
class Xows_cmd__sql_dump {
|
||||
public void Exec(Bry_bfr bfr, Xoa_app app, Xoa_url url, Gfo_qarg_mgr_old arg_hash) {
|
||||
Db_conn conn = null;
|
||||
byte[] sql_bry = arg_hash.Get_val_bry_or(Arg_sql, null); if (sql_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no sql: url=~{0}", url.Raw()); return;}
|
||||
byte[] wiki_bry = arg_hash.Get_val_bry_or(Arg_wiki, null);
|
||||
if (wiki_bry == null) {
|
||||
byte[] db_file_bry = arg_hash.Get_val_bry_or(Arg_db_file, null); if (db_file_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no db_type: url=~{0}", url.Raw()); return;}
|
||||
conn = Db_conn_bldr.Instance.Get(Io_url_.new_fil_(String_.new_u8(db_file_bry)));
|
||||
}
|
||||
else {
|
||||
byte[] db_type_bry = arg_hash.Get_val_bry_or(Arg_db_type, null); if (db_type_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no db_type: url=~{0}", url.Raw()); return;}
|
||||
Xow_wiki wiki = app.Wiki_mgri().Get_by_or_make_init_y(wiki_bry);
|
||||
Byte_obj_val db_type_val = (Byte_obj_val)db_type_hash.Get_by_bry(db_type_bry); if (db_type_val == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; bad db_type: url=~{0}", url.Raw()); return;}
|
||||
switch (db_type_val.Val()) {
|
||||
case Db_type_wiki_core: conn = wiki.Data__core_mgr().Db__core().Conn(); break;
|
||||
case Db_type_fsdb_abc: conn = wiki.File__fsdb_core().File__abc_file__at(Fsm_mnt_mgr.Mnt_idx_main).Conn(); break;
|
||||
case Db_type_fsdb_atr: conn = wiki.File__fsdb_core().File__atr_file__at(Fsm_mnt_mgr.Mnt_idx_main).Conn(); break;
|
||||
}
|
||||
}
|
||||
Db_rdr_utl.Load_and_write(conn, String_.new_u8(sql_bry), bfr);
|
||||
}
|
||||
public static final Xows_cmd__sql_dump Instance = new Xows_cmd__sql_dump(); Xows_cmd__sql_dump() {}
|
||||
private static final byte[] Arg_wiki = Bry_.new_a7("wiki"), Arg_db_file = Bry_.new_a7("db_file"), Arg_db_type = Bry_.new_a7("db_type"), Arg_sql = Bry_.new_a7("sql");
|
||||
private static final byte Db_type_fsdb_abc = 1, Db_type_fsdb_atr = 2, Db_type_wiki_core = 3;
|
||||
private static final Hash_adp_bry db_type_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("fsdb.abc" , Db_type_fsdb_abc)
|
||||
.Add_str_byte("fsdb.atr" , Db_type_fsdb_atr)
|
||||
.Add_str_byte("wiki.core" , Db_type_wiki_core)
|
||||
;
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.diags; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
public class Xows_diag_page implements Xow_special_page {
|
||||
private Gfo_qarg_mgr_old arg_hash = new Gfo_qarg_mgr_old();
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__diag;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
arg_hash.Load(url.Qargs_ary());
|
||||
byte[] cmd_type_bry = arg_hash.Get_val_bry_or(Arg_type, null); if (cmd_type_bry == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; no type: url=~{0}", url.Raw()); return;}
|
||||
Byte_obj_val cmd_type_val = (Byte_obj_val)type_hash.Get_by_bry(cmd_type_bry); if (cmd_type_val == null) {Xoa_app_.Usr_dlg().Warn_many("", "", "special.cmd; bad type: url=~{0}", url.Raw()); return;}
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
bfr.Add_str_a7("<pre>\n");
|
||||
switch (cmd_type_val.Val()) {
|
||||
case Type_file_check: Xows_cmd__file_check.Instance.Exec(bfr, wiki.App(), url, arg_hash); break;
|
||||
case Type_fs_check: Xows_cmd__fs_check.Instance.Exec(bfr, wiki.App(), url, arg_hash); break;
|
||||
case Type_sql_dump: Xows_cmd__sql_dump.Instance.Exec(bfr, wiki.App(), url, arg_hash); break;
|
||||
}
|
||||
bfr.Add_str_a7("</pre>\n");
|
||||
page.Db().Text().Text_bry_(bfr.To_bry_and_clear());
|
||||
}
|
||||
private static final byte[] Arg_type = Bry_.new_a7("type");
|
||||
private static final byte Type_file_check = 1, Type_fs_check = 2, Type_sql_dump = 3;
|
||||
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("file.check" , Type_file_check)
|
||||
.Add_str_byte("fs.check" , Type_fs_check)
|
||||
.Add_str_byte("sql.dump" , Type_sql_dump)
|
||||
;
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.popup_history; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.xowa.htmls.modules.popups.*;
|
||||
public class Popup_history_page implements Xow_special_page {
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__popup_history;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
Xoae_page cur_page = wiki.Appe().Gui_mgr().Browser_win().Active_page(); if (cur_page == null) return;
|
||||
Ordered_hash hash = cur_page.Popup_mgr().Itms();
|
||||
int len = hash.Count();
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_k004();
|
||||
for (int i = len - 1; i > -1; --i) {
|
||||
Xow_popup_itm itm = (Xow_popup_itm)hash.Get_at(i);
|
||||
if (Ttl_chk(itm.Page_ttl())) continue;
|
||||
fmtr_main.Bld_bfr_many(bfr, itm.Page_href(), itm.Page_ttl().Full_txt_w_ttl_case());
|
||||
}
|
||||
page.Db().Text().Text_bry_(bfr.Trim_end(Byte_ascii.Nl).To_bry_and_rls());
|
||||
page.Html_data().Html_restricted_n_();
|
||||
}
|
||||
private Bry_fmtr fmtr_main = Bry_fmtr.new_("<a href='~{href}'>~{ttl}</a>\n\n", "href", "ttl"); // NOTE: need to use anchor (as opposed to lnki or lnke) b/c xwiki will not work on all wikis
|
||||
public static boolean Ttl_chk(Xoa_ttl ttl) {
|
||||
return ttl.Ns().Id_is_special()
|
||||
&& Bry_.Eq(ttl.Page_db(), Xow_special_meta_.Itm__popup_history.Key_bry());
|
||||
}
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
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.specials.xowa.system_data; import gplx.*; import gplx.xowa.*; import gplx.xowa.specials.*; import gplx.xowa.specials.xowa.*;
|
||||
import gplx.core.primitives.*; import gplx.core.brys.fmtrs.*; import gplx.core.net.*; import gplx.core.net.qargs.*;
|
||||
import gplx.xowa.langs.*;
|
||||
import gplx.xowa.apps.urls.*;
|
||||
public class System_data_page implements Xow_special_page {
|
||||
private Gfo_qarg_mgr_old arg_hash = new Gfo_qarg_mgr_old();
|
||||
public Xow_special_meta Special__meta() {return Xow_special_meta_.Itm__system_data;}
|
||||
public void Special__gen(Xow_wiki wikii, Xoa_page pagei, Xoa_url url, Xoa_ttl ttl) {
|
||||
Xowe_wiki wiki = (Xowe_wiki)wikii; Xoae_page page = (Xoae_page)pagei;
|
||||
arg_hash.Load(url.Qargs_ary());
|
||||
byte[] file_type = arg_hash.Get_val_bry_or(Arg_type, null); if (file_type == null) return;
|
||||
Byte_obj_val type_val = (Byte_obj_val)type_hash.Get_by_bry(file_type); if (type_val == null) return;
|
||||
Io_url file_url = Path_from_type(wiki, type_val.Val()); if (file_url == null) return;
|
||||
|
||||
// get log text
|
||||
byte[] file_txt = Io_mgr.Instance.LoadFilBry(file_url);
|
||||
file_txt = gplx.langs.htmls.Gfh_utl.Escape_html_as_bry(file_txt, true, false, false, false, false); // escape < or "</pre>" in messages will cause pre to break
|
||||
if (file_txt.length > Io_mgr.Len_mb) {
|
||||
int file_txt_len = file_txt.length;
|
||||
file_txt = Bry_.Add
|
||||
( Bry_.new_a7("*** truncated to 1 MB due to large file size: " + Int_.To_str(file_txt_len) + " ***\n\n")
|
||||
, Bry_.Mid(file_txt, file_txt_len - Io_mgr.Len_mb, file_txt_len));
|
||||
}
|
||||
|
||||
Bry_bfr tmp_bfr = wiki.Utl__bfr_mkr().Get_m001();
|
||||
fmtr_all.Bld_bfr_many(tmp_bfr, file_url.Raw(), file_txt);
|
||||
page.Db().Text().Text_bry_(tmp_bfr.To_bry_and_rls());
|
||||
}
|
||||
private static Io_url Path_from_type(Xowe_wiki wiki, byte type) {
|
||||
Xoae_app app = wiki.Appe();
|
||||
switch (type) {
|
||||
case Type_log_session: return app.Log_wtr().Session_fil();
|
||||
case Type_cfg_app: return app.Fsys_mgr().Cfg_app_fil();
|
||||
case Type_cfg_lang: return Xol_lang_itm_.xo_lang_fil_(app.Fsys_mgr(), wiki.Lang().Key_str());
|
||||
case Type_usr_history: return app.Usere().Fsys_mgr().App_data_history_fil();
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
private static final byte[] Arg_type = Bry_.new_a7("type");
|
||||
private static final byte Type_log_session = 1, Type_cfg_app = 2, Type_cfg_lang = 3, Type_usr_history = 6;
|
||||
private static final Hash_adp_bry type_hash = Hash_adp_bry.cs()
|
||||
.Add_str_byte("log_session" , Type_log_session)
|
||||
.Add_str_byte("cfg_app" , Type_cfg_app)
|
||||
.Add_str_byte("cfg_lang" , Type_cfg_lang)
|
||||
.Add_str_byte("usr_history" , Type_usr_history)
|
||||
;
|
||||
private Bry_fmtr fmtr_all = Bry_fmtr.new_(String_.Concat_lines_nl_skip_last
|
||||
( "<p><b>Path</b>: <code>~{path}</code>"
|
||||
, "</p>"
|
||||
, "<pre style='overflow:auto;'>"
|
||||
, "~{text}</pre>"
|
||||
), "path", "text");
|
||||
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
}
|
||||
Reference in New Issue
Block a user