定制 addwiki/wikibase-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

addwiki/wikibase-api

最新稳定版本:3.1.0

Composer 安装命令:

composer require addwiki/wikibase-api

包简介

Wikibase API library

README 文档

README

GitHub issue custom search in repo Latest Stable Version Download count

Issue tracker: https://github.com/addwiki/addwiki/issues

Installation

Use composer to install the library and all its dependencies:

composer require "addwiki/wikibase-api:~3.0"

Example Usage

The library provides users with a large collection of Services. These services should be retrieved from the WikibaseFactory class.

Below you will find some more examples using various services. Each example follows on from the previous example (so as not to repeat the first steps). Note: this library uses namespaces so please remember to add the relevant use clauses.

Load & General Setup

require_once( __DIR__ . '/vendor/autoload.php' );

$api = new MediawikiApi( 'http://localhost/w/api.php', new UserAndPassword( 'username', 'password' ) );

// Create our Factory, All services should be used through this!
// You will need to add more or different datavalues here.
// In the future Wikidata / Wikibase defaults will be provided in a separate library.
$dataValueClasses = array(
    'unknown' => 'DataValues\UnknownValue',
    'string' => 'DataValues\StringValue',
    'boolean' => 'DataValues\BooleanValue',
    'number' => 'DataValues\NumberValue',
    'globecoordinate' => 'DataValues\Geo\Values\GlobeCoordinateValue',
    'monolingualtext' => 'DataValues\MonolingualTextValue',
    'multilingualtext' => 'DataValues\MultilingualTextValue',
    'quantity' => 'DataValues\QuantityValue',
    'time' => 'DataValues\TimeValue',
    'wikibase-entityid' => 'Addwiki\Wikibase\DataModel\Entity\EntityIdValue',
);
$wbFactory = new WikibaseFactory(
    $api,
	new Addwiki\Wikibase\DataModel\DataModelFactory(
		new DataValues\Deserializers\DataValueDeserializer( $dataValueClasses ),
		new DataValues\Serializers\DataValueSerializer()
	)
);

Create an empty entity

Create a new empty item.

$saver = $wbFactory->newRevisionSaver();

$edit = new Revision(
    new ItemContent( Item::newEmpty() )
);
$resultingItem = $saver->save( $edit );

// You can get the ItemId object of the created item by doing the following
$itemId = $resultingItem->getId()

Set a label

Set an English label on the item Q87 assuming it exists, using a custom summary.

$getter = $wbFactory->newRevisionGetter();

$entityRevision = $getter->getFromId( 'Q87' );
$entityRevision->getContent()->getData()->setDescription( 'en', 'I am A description' );
$saver->save( $entityRevision, new EditInfo( 'Custom edit summary' ) );

Create a new statement

Create a new string statement on item Q777 if a statement for the property doesn't already exist.

$statementCreator = $wbFactory->newStatementCreator();
$revision = $getter->getFromId( 'Q777' );
$item = $revision->getContent()->getData();
$statementList = $item->getStatements();
if( $statementList->getByPropertyId( PropertyId::newFromNumber( 1320 ) )->isEmpty() ) {
    $statementCreator->create(
        new PropertyValueSnak(
            PropertyId::newFromNumber( 1320 ),
            new StringValue( 'New String Value' )
        ),
        'Q777'
    );
}

Remove a statement using a GUID

Remove the statement with the given claim (if it exists)

$statementRemover = $wbFactory->newStatementRemover();

$statementRemover->remove( 'Q123$f12bd80f-415a-c37e-9e18-234b9e19eece' );

Add a reference to a statement

$statementSetter = $wbFactory->newStatementSetter();
$revision = $getter->getFromId( 'Q9956' );
$item = $revision->getContent()->getData();
$statementList = $item->getStatements();
$referenceSnaks = array(
    new PropertyValueSnak( new PropertyId( 'P44' ), new StringValue( 'bar' ) ),
);
foreach( $statementList->getByPropertyId( PropertyId::newFromNumber( 99 ) )->getIterator() as $statement ) {
    if( $statement->getReferences()->isEmpty() ) {
        $statement->addNewReference( $referenceSnaks );
    }
}

Attempt to merge 2 items

Try to merge Q999 and Q888 if possible, catch any errors.

try{
    $wbFactory->newItemMerger()->merge( 'Q999', 'Q888' );
}
catch( UsageException $e ) {
    echo "Oh no! I failed to merge!";
}

Simple Lookups

Easily lookup an item object, an individual label and redirect sources.

$itemId = new ItemId( 'Q555' )
$itemLookup = $wbFactory->newItemLookup();
$termLookup = $wbFactory->newTermLookup();
$entityRedirectLookup = $wbFactory->newEntityRedirectLookup();

$item = $itemLookup->getItemForId( $itemId );
$enLabel = $termLookup->getLabel( $itemId, 'en' );
$redirectSources = $entityRedirectLookup->getRedirectIds( $itemId );

统计信息

  • 总下载量: 4.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 9
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2014-02-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固