mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v3.1.4.1
This commit is contained in:
@@ -20,6 +20,7 @@ import gplx.xowa.drds.pages.*; import gplx.xowa.drds.files.*;
|
||||
import gplx.xowa.apps.*; import gplx.xowa.wikis.data.tbls.*;
|
||||
import gplx.xowa.wikis.nss.*; import gplx.xowa.files.gui.*;
|
||||
import gplx.xowa.specials.search.*; import gplx.xowa.specials.randoms.*;
|
||||
import gplx.langs.htmls.encoders.*; import gplx.xowa.htmls.hrefs.*;
|
||||
public class Xod_app {
|
||||
private final Xoav_app app;
|
||||
private final Xod_page_mgr page_mgr = new Xod_page_mgr();
|
||||
@@ -27,10 +28,6 @@ public class Xod_app {
|
||||
public Xod_app(Xoav_app app) {
|
||||
this.app = app;
|
||||
}
|
||||
public int Wikis__count() {
|
||||
int rv = app.Wiki_mgri().Count();
|
||||
return rv - 1; // ignore home wiki
|
||||
}
|
||||
public Xow_wiki Wikis__get_by_domain(String wiki_domain) {
|
||||
Xow_wiki rv = app.Wiki_mgri().Get_by_or_make_init_y(Bry_.new_u8(wiki_domain));
|
||||
if (rv != null && rv.Data__core_mgr() == null) rv.Init_by_wiki();
|
||||
@@ -54,7 +51,20 @@ public class Xod_app {
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
public void Wiki__search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search, Xod_search_cmd[] cmds) {
|
||||
for (Xod_search_cmd cmd : cmds)
|
||||
cmd.Search(cancelable, wiki, ui_async, search);
|
||||
}
|
||||
public void Page__load_files(Xow_wiki wiki, Xod_page_itm pg, Xog_js_wkr js_wkr) {
|
||||
file_mgr.Load_files(wiki, pg, js_wkr);
|
||||
app.User().User_db_mgr().Cache_mgr().Db_save();
|
||||
}
|
||||
public static byte[] To_page_url(Xow_wiki wiki, String canonical_str) {// NOTE: need canonical_url to handle "A:B" where "A:" is not a ns, even though PageTitle treats "A:" as a namespace
|
||||
byte[] canonical_bry = Bry_.new_u8(canonical_str);
|
||||
int page_bgn = Bry_find_.Move_fwd(canonical_bry, Xoh_href_.Bry__wiki, 0); if (page_bgn == Bry_find_.Not_found) throw Err_.new_("drd", "uknown url format: no '/wiki/'", "url", canonical_bry);
|
||||
byte[] page_bry = Bry_.Mid(canonical_bry, page_bgn, canonical_bry.length); // get bry; EX: https://en.wikipedia.org/wiki/A -> A
|
||||
page_bry = Gfo_url_encoder_.Http_url.Decode(page_bry); // decode %-encoding; convert + to space
|
||||
page_bry = Xoa_ttl.Replace_spaces(page_bry); // convert spaces to unders; canonical-url has spaces
|
||||
return page_bry;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,14 @@ public class Xod_app_tst {
|
||||
tstr.Data_mgr().Html__insert(1, "abc");
|
||||
tstr.Test__get("A", tstr.Make_page(1, "A", "2015-10-19T00:01:02Z", tstr.Make_section(0, 2, "", "", "abc")));
|
||||
}
|
||||
@Test public void To_page_db() {
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A" , "A");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A:B" , "A:B");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/Help:A" , "Help:A");
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A B" , "A_B"); // NOTE:canonical url has spaces;
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A%27B" , "A'B"); // NOTE:canonical url has percent-encoding;
|
||||
tstr.Test__to_page_url("http://en.wikipedia.org/wiki/A+B" , "A_B"); // NOTE:canonical url sometimes has "+" for space
|
||||
}
|
||||
}
|
||||
class Xod_app_tstr {
|
||||
private final gplx.xowa.apps.Xoav_app app; private final Xowv_wiki wiki;
|
||||
@@ -46,6 +54,10 @@ class Xod_app_tstr {
|
||||
Xod_page_itm itm = drd_provider.Wiki__get_by_url(wiki, page_url);
|
||||
Tfds.Eq(expd.To_str(), itm.To_str());
|
||||
}
|
||||
public void Test__to_page_url(String raw, String expd) {
|
||||
// // canonical url has spaces as well as %-encoding; PAGE:en.w:List_of_Fire_Emblem:Shadow_Dragon_characters
|
||||
Tfds.Eq_bry(Bry_.new_u8(expd), Xod_app.To_page_url(wiki, raw));
|
||||
}
|
||||
public Xod_page_itm Make_page(int page_id, String ttl, String modified_on, Xoh_section_itm... section_ary) {
|
||||
Xod_page_itm rv = new Xod_page_itm();
|
||||
rv.Init(page_id, page_id, ttl, ttl, null, null, modified_on, Bool_.N, Bool_.N, Bool_.N, 1, null, null, null);
|
||||
|
||||
22
400_xowa/src/gplx/xowa/drds/Xod_search_cmd.java
Normal file
22
400_xowa/src/gplx/xowa/drds/Xod_search_cmd.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
public interface Xod_search_cmd {
|
||||
void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search);
|
||||
}
|
||||
74
400_xowa/src/gplx/xowa/drds/Xod_search_cmd_.java
Normal file
74
400_xowa/src/gplx/xowa/drds/Xod_search_cmd_.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
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.drds; import gplx.*; import gplx.xowa.*;
|
||||
import gplx.xowa.specials.search.*;
|
||||
import gplx.xowa.wikis.data.tbls.*;
|
||||
public class Xod_search_cmd_ {
|
||||
public static final Xod_search_cmd
|
||||
New__page_eq = Xod_search_cmd__page_eq.Instance
|
||||
, New__page_like = Xod_search_cmd__page_like.Instance
|
||||
, New__word_eq = Xod_search_cmd__word_tbl.Instance_eq
|
||||
, New__word_like = Xod_search_cmd__word_tbl.Instance_like
|
||||
;
|
||||
}
|
||||
class Xod_search_cmd__page_eq implements Xod_search_cmd {
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
Xowd_page_itm page_itm = new Xowd_page_itm();
|
||||
if (wiki.Data__core_mgr().Tbl__page().Select_by_ttl(page_itm, wiki.Ns_mgr().Ns_main(), Bry_.Ucase__1st(Bry_.new_u8(search)))) {
|
||||
Xows_db_row search_itm = new Xows_db_row(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
ui_async.Add(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_eq Instance = new Xod_search_cmd__page_eq(); Xod_search_cmd__page_eq() {}
|
||||
}
|
||||
class Xod_search_cmd__page_like implements Xod_search_cmd {// NOTE: slow; takes at least 10+ seconds
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
List_adp tmp_list = List_adp_.new_();
|
||||
wiki.Data__core_mgr().Tbl__page().Select_by_search(cancelable, tmp_list, Bry_.Ucase__1st(Bry_.new_u8(search + "*")), 50);
|
||||
int len = tmp_list.Count();
|
||||
for (int i = 0; i < len; ++i) {
|
||||
Xowd_page_itm page_itm = (Xowd_page_itm)tmp_list.Get_at(i);
|
||||
Xows_db_row search_itm = new Xows_db_row(wiki.Domain_bry(), wiki.Ttl_parse(page_itm.Ttl_page_db()), page_itm.Id(), page_itm.Text_len());
|
||||
ui_async.Add(search_itm);
|
||||
}
|
||||
}
|
||||
public static final Xod_search_cmd__page_like Instance = new Xod_search_cmd__page_like(); Xod_search_cmd__page_like() {}
|
||||
}
|
||||
class Xod_search_cmd__word_tbl implements Xod_search_cmd {
|
||||
private final boolean wildcard;
|
||||
private final int results_wanted;
|
||||
private final Xows_db_wkr search_wkr = new Xows_db_wkr();
|
||||
Xod_search_cmd__word_tbl(boolean wildcard, int results_wanted) {this.wildcard = wildcard; this.results_wanted = results_wanted;}
|
||||
public void Search(Cancelable cancelable, Xow_wiki wiki, Xows_ui_async ui_async, String search) {
|
||||
search_wkr.Search_by_drd(cancelable, wiki, ui_async, Bry_.new_u8(Standardize_search(search, wildcard)), results_wanted);
|
||||
}
|
||||
public static final Xod_search_cmd__word_tbl Instance_eq = new Xod_search_cmd__word_tbl(Bool_.N, 10), Instance_like = new Xod_search_cmd__word_tbl(Bool_.Y, 50);
|
||||
private static String Standardize_search(String search, boolean wildcard) {
|
||||
String rv = "";
|
||||
String[] words = String_.Split(search, " ");
|
||||
int words_len = words.length;
|
||||
for (int i = 0; i < words_len; ++i) {
|
||||
String word = words[i];
|
||||
if (String_.Len(word) < 3) continue;
|
||||
if (String_.Len(rv) != 0) rv += " ";
|
||||
rv += word;
|
||||
if (wildcard) rv += "*";
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user