mirror of https://github.com/gnosygnu/xowa
pull/620/head
parent
66877212bf
commit
3126b46faf
@ -0,0 +1,77 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.dataAccess.scribunto; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*; import gplx.xowa.xtns.wbases.mediawiki.client.dataAccess.*;
|
||||
import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.claims.*; import gplx.xowa.xtns.wbases.claims.itms.*; import gplx.xowa.xtns.wbases.claims.enums.*;
|
||||
public class Wbase_entity_accessor {
|
||||
private final Wbase_doc_mgr entity_mgr;
|
||||
public Wbase_entity_accessor(Wbase_doc_mgr entity_mgr) {
|
||||
this.entity_mgr = entity_mgr;
|
||||
}
|
||||
public Wbase_claim_base[] getEntityStatements(byte[] prefixedEntityId, byte[] propertyIdSerialization, byte[] rank) {
|
||||
prefixedEntityId = Bry_.Trim(prefixedEntityId);
|
||||
// entityId = $this->entityIdParser->parse( $prefixedEntityId );
|
||||
int propertyId = Wdata_prop_val_visitor_.To_pid_int(propertyIdSerialization);
|
||||
// $this->usageAccumulator->addStatementUsage( $entityId, $propertyId );
|
||||
// $this->usageAccumulator->addOtherUsage( $entityId );
|
||||
|
||||
// for some reason, prefixedEntityId can be ""; PAGE:en.w:Nature_and_Art DATE:2017-11-28
|
||||
if (Bry_.Len_eq_0(prefixedEntityId))
|
||||
return null;
|
||||
|
||||
Wdata_doc entity = null;
|
||||
try {
|
||||
entity = entity_mgr.Get_by_xid_or_null(prefixedEntityId);
|
||||
} catch (Exception ex) { // RevisionedUnresolvedRedirectException ex
|
||||
// We probably hit a double redirect
|
||||
Gfo_usr_dlg_.Instance.Log_many("", "", "Encountered a UnresolvedRedirectException when trying to load {0}; exc={1}", prefixedEntityId, Err_.Message_lang(ex));
|
||||
return null;
|
||||
}
|
||||
|
||||
int selected_rank = ID_NULL;
|
||||
if (Bry_.Eq(rank, RANK_BEST)) {
|
||||
selected_rank = ID_BEST;
|
||||
}
|
||||
else if (Bry_.Eq(rank, RANK_ALL)) {
|
||||
selected_rank = ID_ALL;
|
||||
}
|
||||
else {
|
||||
throw Err_.new_wo_type("rank must be 'best' or 'all', " + String_.new_u8(rank) + " given");
|
||||
}
|
||||
|
||||
List_adp rv = List_adp_.New();
|
||||
Wbase_claim_grp statements = entity.Claim_list_get(propertyId);
|
||||
if (statements == null)
|
||||
return null;
|
||||
int statements_len = statements.Len();
|
||||
for (int i = 0; i < statements_len; i++) {
|
||||
Wbase_claim_base statement = statements.Get_at(0);
|
||||
if ( selected_rank == ID_ALL
|
||||
|| (selected_rank == ID_BEST && statement.Rank_tid() == Wbase_claim_rank_.Tid__preferred)
|
||||
) {
|
||||
rv.Add(statement);
|
||||
}
|
||||
}
|
||||
// $serialization = $this->newClientStatementListSerializer()->serialize( $statements );
|
||||
// $this->renumber( $serialization );
|
||||
// return $serialization;
|
||||
return (Wbase_claim_base[])rv.To_ary(Wbase_claim_base.class);
|
||||
}
|
||||
|
||||
private static final int ID_NULL = 0, ID_BEST = 1, ID_ALL = 2;
|
||||
private static final byte[]
|
||||
RANK_BEST = Bry_.new_a7("best")
|
||||
, RANK_ALL = Bry_.new_a7("all");
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
import gplx.xowa.mediawiki.*;
|
||||
public class Wbase_client {
|
||||
private Wbase_repo_linker repoLinker;
|
||||
public Wbase_client(Wbase_settings settings) {
|
||||
this.repoLinker = new Wbase_repo_linker
|
||||
( settings.getSetting(Wbase_settings.Setting_repoUrl)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoArticlePath)
|
||||
, settings.getSetting(Wbase_settings.Setting_repoScriptPath)
|
||||
);
|
||||
}
|
||||
public Wbase_repo_linker RepoLinker() {return repoLinker;}
|
||||
|
||||
private static Wbase_client defaultInstance;
|
||||
public static Wbase_client getDefaultInstance() {
|
||||
if (defaultInstance == null) {
|
||||
defaultInstance = new Wbase_client(Wbase_settings.New_dflt());
|
||||
}
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
import gplx.xowa.mediawiki.*;
|
||||
// https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/client/includes/RepoLinker.php
|
||||
public class Wbase_repo_linker {
|
||||
private byte[] baseUrl;
|
||||
private byte[] articlePath;
|
||||
// private byte[] scriptPath;
|
||||
public Wbase_repo_linker(byte[] baseUrl, byte[] articlePath, byte[] scriptPath) {
|
||||
this.baseUrl = Bry_.Trim(baseUrl, 0, baseUrl.length, false, true, Bry_.mask_(256, Byte_ascii.Slash_bry)); // getBaseUrl
|
||||
this.articlePath = articlePath;
|
||||
// this.scriptPath = scriptPath;
|
||||
}
|
||||
|
||||
public byte[] getPageUrl(byte[] page) {
|
||||
byte[] encodedPage = this.encodePage(page);
|
||||
return Bry_.Add(this.getBaseUrl(), XophpString.str_replace(Format_Arg1, encodedPage, this.articlePath));
|
||||
}
|
||||
|
||||
private byte[] encodePage(byte[] page) {
|
||||
return gplx.langs.htmls.encoders.Gfo_url_encoder_.Mw_wfUrlencode.Encode(Bry_.Replace(page, Byte_ascii.Space, Byte_ascii.Underline));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Format a link, with url encoding
|
||||
// *
|
||||
// * @param String $url
|
||||
// * @param String $text
|
||||
// * @param array $attribs
|
||||
// *
|
||||
// * @return String (html)
|
||||
// */
|
||||
// public function formatLink( $url, $text, array $attribs = [] ) {
|
||||
// $attribs['class'] = isset( $attribs['class'] )
|
||||
// ? 'extiw ' . $attribs['class']
|
||||
// : 'extiw';
|
||||
// $attribs['href'] = $url;
|
||||
// return Html::element( 'a', $attribs, $text );
|
||||
// }
|
||||
// /**
|
||||
// * Constructs an html link to an entity
|
||||
// *
|
||||
// * @param EntityId $entityId
|
||||
// * @param array $classes
|
||||
// * @param String $text Defaults to the entity id serialization.
|
||||
// *
|
||||
// * @return String (html)
|
||||
// */
|
||||
// public function buildEntityLink( EntityId $entityId, array $classes = [], $text = null ) {
|
||||
// if ( $text === null ) {
|
||||
// $text = $entityId->getSerialization();
|
||||
// }
|
||||
// $class = 'wb-entity-link';
|
||||
// if ( $classes !== [] ) {
|
||||
// $class .= ' ' . implode( ' ', $classes );
|
||||
// }
|
||||
// return $this->formatLink(
|
||||
// $this->getEntityUrl( $entityId ),
|
||||
// $text,
|
||||
// [ 'class' => $class ]
|
||||
// );
|
||||
// }
|
||||
|
||||
public byte[] getEntityTitle(byte[] entityId ) {
|
||||
byte[] title = entityId; // title = entityId.getSerialization();
|
||||
return Bry_.Add(Special_EntityPage, title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a link to an entity
|
||||
*/
|
||||
public byte[] getEntityUrl(byte[] entityId) {
|
||||
byte[] title = this.getEntityTitle(entityId);
|
||||
return this.getPageUrl(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public byte[] getBaseUrl() {
|
||||
// return rtrim( $this->baseUrl, '/' );
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return String
|
||||
// */
|
||||
// public function getApiUrl() {
|
||||
// return $this->getBaseUrl() . $this->scriptPath . '/api.php';
|
||||
// }
|
||||
// /**
|
||||
// * @return String
|
||||
// */
|
||||
// public function getIndexUrl() {
|
||||
// return $this->getBaseUrl() . $this->scriptPath . '/index.php';
|
||||
// }
|
||||
// /**
|
||||
// * @param String $url
|
||||
// * @param array $params
|
||||
// *
|
||||
// * @return String
|
||||
// */
|
||||
// public function addQueryParams( $url, array $params ) {
|
||||
// return wfAppendQuery( $url, wfArrayToCgi( $params ) );
|
||||
// }
|
||||
|
||||
private static final byte[]
|
||||
Format_Arg1 = Bry_.new_a7("$1")
|
||||
, Special_EntityPage = Bry_.new_a7("Special:EntityPage/");
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.client.includes; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.client.*;
|
||||
public class Wbase_settings {
|
||||
private static final Hash_adp_bry hash = Hash_adp_bry.cs();
|
||||
public byte[] getSetting(String key) {return getSetting(Bry_.new_u8(key));}
|
||||
public byte[] getSetting(byte[] key) {
|
||||
return (byte[])hash.Get_by_bry(key);
|
||||
}
|
||||
public void setSetting(String key, String val) {setSetting(Bry_.new_u8(key), Bry_.new_u8(val));}
|
||||
public void setSetting(byte[] key, byte[] val) {
|
||||
hash.Add(key, val);
|
||||
}
|
||||
|
||||
public static Wbase_settings New_dflt() {
|
||||
// https://www.mediawiki.org/wiki/Wikibase/Installation/Advanced_configuration
|
||||
return New
|
||||
( "https://www.wikidata.org" // NOTE: should be "//wikidata.org", but "//wikidata.org" will open page in browser, not XOWA
|
||||
, "/wiki/$1"
|
||||
, "/w"
|
||||
);
|
||||
}
|
||||
|
||||
public static Wbase_settings New(String repoUrl, String repoArticlePath, String repoScriptPath) {
|
||||
Wbase_settings rv = new Wbase_settings();
|
||||
rv.setSetting(Setting_repoUrl, repoUrl);
|
||||
rv.setSetting(Setting_repoArticlePath, repoArticlePath);
|
||||
rv.setSetting(Setting_repoScriptPath, repoScriptPath);
|
||||
return rv;
|
||||
}
|
||||
public static final String
|
||||
Setting_repoUrl = "repoUrl"
|
||||
, Setting_repoArticlePath = "repoArticlePath"
|
||||
, Setting_repoScriptPath = "repoScriptPath"
|
||||
;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.xtns.wbases.mediawiki.repo.includes.specials; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.wbases.*; import gplx.xowa.xtns.wbases.mediawiki.*; import gplx.xowa.xtns.wbases.mediawiki.repo.*; import gplx.xowa.xtns.wbases.mediawiki.repo.includes.*;
|
||||
import gplx.xowa.specials.*; import gplx.core.net.qargs.*;
|
||||
public class Wbase_entityPage implements Xow_special_page {
|
||||
public void Special__gen(Xow_wiki wiki, Xoa_page page, Xoa_url url, Xoa_ttl ttl) {
|
||||
if (url.Segs_ary().length != 4) { // EX: www.wikidata.org/wiki/Special:EntityPage/Q2
|
||||
throw Err_.new_wo_type("entityPage url must have format of 'domain/wiki/Special:EntityPage/entityId'", "url", url.To_bry(true, true));
|
||||
}
|
||||
byte[] entityId = url.Segs_ary()[3];
|
||||
byte[] pageId = Wbase_doc_mgr.Prepend_property_if_needed(entityId);
|
||||
|
||||
Xowe_wiki wikie = (Xowe_wiki)wiki;
|
||||
wikie.Data_mgr().Redirect((Xoae_page)page, pageId);
|
||||
}
|
||||
Wbase_entityPage(Xow_special_meta special__meta) {this.special__meta = special__meta;}
|
||||
public Xow_special_meta Special__meta() {return special__meta;} private final Xow_special_meta special__meta;
|
||||
public Xow_special_page Special__clone() {return this;}
|
||||
public static final String SPECIAL_KEY = "EntityPage";
|
||||
public static final Xow_special_page Prototype = new Wbase_entityPage(Xow_special_meta.New_xo(SPECIAL_KEY, "Entity Page"));
|
||||
}
|
Loading…
Reference in new issue