@ -1,6 +1,6 @@
/ *
/ *
XOWA: the XOWA Offline Wiki Application
XOWA: the XOWA Offline Wiki Application
Copyright ( C ) 2012 - 20 17 gnosygnu @gmail.com
Copyright ( C ) 2012 - 20 20 gnosygnu @gmail.com
XOWA is licensed under the terms of the General Public License ( GPL ) Version 3 ,
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 .
or alternatively under the terms of the Apache License Version 2.0 .
@ -13,77 +13,91 @@ 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
GPLv3 License : https : //github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License : https : //github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
Apache License : https : //github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
* /
* /
package gplx.xowa.mediawiki.extensions.Wikibase.client.includes.dataAccess.scribunto ; import gplx.* ; import gplx.xowa.* ; import gplx.xowa.mediawiki.* ; import gplx.xowa.mediawiki.extensions.* ; import gplx.xowa.mediawiki.extensions.Wikibase.* ; import gplx.xowa.mediawiki.extensions.Wikibase.client.* ; import gplx.xowa.mediawiki.extensions.Wikibase.client.includes.* ; import gplx.xowa.mediawiki.extensions.Wikibase.client.includes.dataAccess.* ;
package gplx.xowa.mediawiki.extensions.Wikibase.client.includes.dataAccess.scribunto ;
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.* ; import gplx.xowa.xtns.wbases.stores.* ;
public class Wbase_entity_accessor {
import gplx.Bry_ ;
private final Wbase_doc_mgr entity_mgr ;
import gplx.Err_ ;
public Wbase_entity_accessor ( Wbase_doc_mgr entity_mgr ) {
import gplx.Gfo_usr_dlg_ ;
this . entity_mgr = entity_mgr ;
import gplx.List_adp ;
}
import gplx.List_adp_ ;
public Wbase_claim_base [ ] getEntityStatements ( byte [ ] prefixedEntityId , byte [ ] propertyIdSerialization , byte [ ] rank ) {
import gplx.String_ ;
prefixedEntityId = Bry_ . Trim ( prefixedEntityId ) ;
import gplx.xowa.xtns.wbases.Wdata_doc ;
// entityId = $this->entityIdParser->parse( $prefixedEntityId );
import gplx.xowa.xtns.wbases.Wdata_prop_val_visitor_ ;
int propertyId = Wdata_prop_val_visitor_ . To_pid_int ( propertyIdSerialization ) ;
import gplx.xowa.xtns.wbases.claims.Wbase_claim_grp ;
// $this->usageAccumulator->addStatementUsage( $entityId, $propertyId );
import gplx.xowa.xtns.wbases.claims.enums.Wbase_claim_rank_ ;
// $this->usageAccumulator->addOtherUsage( $entityId );
import gplx.xowa.xtns.wbases.claims.itms.Wbase_claim_base ;
import gplx.xowa.xtns.wbases.stores.Wbase_doc_mgr ;
// for some reason, prefixedEntityId can be ""; PAGE:en.w:Nature_and_Art DATE:2017-11-28
if ( Bry_ . Len_eq_0 ( prefixedEntityId ) )
public class Wbase_entity_accessor {
return null ;
private final Wbase_doc_mgr entity_mgr ;
public Wbase_entity_accessor ( Wbase_doc_mgr entity_mgr ) {
Wdata_doc entity = null ;
this . entity_mgr = entity_mgr ;
try {
}
entity = entity_mgr . Get_by_xid_or_null ( prefixedEntityId ) ;
public Wbase_claim_base [ ] getEntityStatements ( byte [ ] prefixedEntityId , byte [ ] propertyIdSerialization , byte [ ] rank ) {
} catch ( Exception ex ) { // RevisionedUnresolvedRedirectException ex
prefixedEntityId = Bry_ . Trim ( prefixedEntityId ) ;
// We probably hit a double redirect
// entityId = $this->entityIdParser->parse( $prefixedEntityId );
Gfo_usr_dlg_ . Instance . Log_many ( "" , "" , "Encountered a UnresolvedRedirectException when trying to load {0}; exc={1}" , prefixedEntityId , Err_ . Message_lang ( ex ) ) ;
int propertyId = Wdata_prop_val_visitor_ . To_pid_int ( propertyIdSerialization ) ;
return null ;
// $this->usageAccumulator->addStatementUsage( $entityId, $propertyId );
}
// $this->usageAccumulator->addOtherUsage( $entityId );
int selected_rank = ID_NULL ;
// for some reason, prefixedEntityId can be ""; PAGE:en.w:Nature_and_Art DATE:2017-11-28
if ( Bry_ . Eq ( rank , RANK_BEST ) ) {
if ( Bry_ . Len_eq_0 ( prefixedEntityId ) )
selected_rank = ID_BEST ;
return null ;
}
else if ( Bry_ . Eq ( rank , RANK_ALL ) ) {
Wdata_doc entity = null ;
selected_rank = ID_ALL ;
try {
}
entity = entity_mgr . Get_by_xid_or_null ( prefixedEntityId ) ;
else {
} catch ( Exception ex ) { // RevisionedUnresolvedRedirectException ex
throw Err_ . new_wo_type ( "rank must be 'best' or 'all', " + String_ . new_u8 ( rank ) + " given" ) ;
// 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 ;
List_adp rv = List_adp_ . New ( ) ;
}
Wbase_claim_grp statements = entity . Get_claim_grp_or_null ( propertyId ) ;
if ( entity = = null ) return null ; // must check for null; PAGE:fr.w:Wikipédia:Ateliers_Bases/Recherche ISSUE#:773; DATE:2020-08-04
if ( statements = = null )
return null ;
int selected_rank = ID_NULL ;
if ( Bry_ . Eq ( rank , RANK_BEST ) ) {
int statements_len = statements . Len ( ) ;
selected_rank = ID_BEST ;
for ( int i = 0 ; i < statements_len ; i + + ) {
}
Wbase_claim_base statement = statements . Get_at ( i ) ;
else if ( Bry_ . Eq ( rank , RANK_ALL ) ) {
if ( selected_rank = = ID_ALL
selected_rank = ID_ALL ;
| | ( selected_rank = = ID_BEST & & statement . Rank_tid ( ) = = Wbase_claim_rank_ . Tid__preferred )
}
) {
else {
rv . Add ( statement ) ;
throw Err_ . new_wo_type ( "rank must be 'best' or 'all', " + String_ . new_u8 ( rank ) + " given" ) ;
}
}
}
List_adp rv = List_adp_ . New ( ) ;
// no preferred exists; add normal
Wbase_claim_grp statements = entity . Get_claim_grp_or_null ( propertyId ) ;
if ( rv . Len ( ) = = 0 & & selected_rank = = ID_BEST ) {
if ( statements = = null )
for ( int i = 0 ; i < statements_len ; i + + ) {
return null ;
Wbase_claim_base statement = statements . Get_at ( i ) ;
if ( statement . Rank_tid ( ) = = Wbase_claim_rank_ . Tid__normal ) {
int statements_len = statements . Len ( ) ;
rv . Add ( statement ) ;
for ( int i = 0 ; i < statements_len ; i + + ) {
}
Wbase_claim_base statement = statements . Get_at ( i ) ;
}
if ( selected_rank = = ID_ALL
}
| | ( selected_rank = = ID_BEST & & statement . Rank_tid ( ) = = Wbase_claim_rank_ . Tid__preferred )
) {
// $serialization = $this->newClientStatementListSerializer()->serialize( $statements );
rv . Add ( statement ) ;
// $this->renumber( $serialization );
}
// return $serialization;
}
return rv . Len ( ) = = 0 ? null : ( Wbase_claim_base [ ] ) rv . To_ary ( Wbase_claim_base . class ) ;
}
// no preferred exists; add normal
if ( rv . Len ( ) = = 0 & & selected_rank = = ID_BEST ) {
private static final int ID_NULL = 0 , ID_BEST = 1 , ID_ALL = 2 ;
for ( int i = 0 ; i < statements_len ; i + + ) {
private static final byte [ ]
Wbase_claim_base statement = statements . Get_at ( i ) ;
RANK_BEST = Bry_ . new_a7 ( "best" )
if ( statement . Rank_tid ( ) = = Wbase_claim_rank_ . Tid__normal ) {
, RANK_ALL = Bry_ . new_a7 ( "all" ) ;
rv . Add ( statement ) ;
}
}
}
}
// $serialization = $this->newClientStatementListSerializer()->serialize( $statements );
// $this->renumber( $serialization );
// return $serialization;
return rv . Len ( ) = = 0 ? null : ( 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" ) ;
}