PHPackages                             addwiki/wikibase-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. addwiki/wikibase-api

ActiveLibrary[API Development](/categories/api)

addwiki/wikibase-api
====================

Wikibase API library

3.1.0(1y ago)254.7k143GPL-2.0-or-laterPHPPHP &gt;=8.1CI failing

Since Feb 23Pushed 1y ago9 watchersCompare

[ Source](https://github.com/addwiki/wikibase-api)[ Packagist](https://packagist.org/packages/addwiki/wikibase-api)[ RSS](/packages/addwiki-wikibase-api/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (17)Versions (16)Used By (3)

wikibase-api
============

[](#wikibase-api)

[![GitHub issue custom search in repo](https://camo.githubusercontent.com/ba230573dc3bc3363e431527fdc183209742d4130fdeacbd7d9b1bc0befc7583/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d7365617263682f61646477696b692f61646477696b693f6c6162656c3d6973737565732671756572793d6973253341697373756525323069732533416f70656e25323025354277696b69626173652d617069253544)](https://github.com/addwiki/addwiki/issues?q=is%3Aissue+is%3Aopen+%5Bwikibase-api%5D+)[![Latest Stable Version](https://camo.githubusercontent.com/08412ca264638826c3dc6ebdd182c99cf630d72c8d9d0d1846eaaefc29848b20/68747470733a2f2f706f7365722e707567782e6f72672f61646477696b692f77696b69626173652d6170692f76657273696f6e2e706e67)](https://packagist.org/packages/addwiki/wikibase-api)[![Download count](https://camo.githubusercontent.com/08e2a7fe89165b215d3ecd12e0d827e060d074bf03727038ade259e98aa55362/68747470733a2f2f706f7365722e707567782e6f72672f61646477696b692f77696b69626173652d6170692f642f746f74616c2e706e67)](https://packagist.org/packages/addwiki/wikibase-api)

Issue tracker:

Installation
------------

[](#installation)

Use composer to install the library and all its dependencies:

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

```

Example Usage
-------------

[](#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](http://php.net/manual/en/language.namespaces.importing.php).

#### Load &amp; General Setup

[](#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-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-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-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-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

[](#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

[](#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

[](#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 );
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 78% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~299 days

Recently: every ~337 days

Total

14

Last Release

580d ago

Major Versions

0.8.1 → 2.6.02021-02-02

2.8.0 → 3.0.02021-10-23

PHP version history (6 changes)0.3PHP &gt;=5.3.0

0.7PHP &gt;=5.5

2.6.0PHP ^7.2

2.8.0PHP &gt;=7.3

3.0.0PHP &gt;=7.4

3.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccc2c40c150701b6b72f598f342b6a7aa57d7ab06a08c5f085f6add75094b82b?d=identicon)[addshore](/maintainers/addshore)

---

Top Contributors

[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (181 commits)")[![Tpt](https://avatars.githubusercontent.com/u/458123?v=4)](https://github.com/Tpt "Tpt (19 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (16 commits)")[![Benestar](https://avatars.githubusercontent.com/u/2998254?v=4)](https://github.com/Benestar "Benestar (9 commits)")[![mbch331](https://avatars.githubusercontent.com/u/12393536?v=4)](https://github.com/mbch331 "mbch331 (3 commits)")[![sascha-hendel](https://avatars.githubusercontent.com/u/1225897?v=4)](https://github.com/sascha-hendel "sascha-hendel (2 commits)")[![z38](https://avatars.githubusercontent.com/u/3948085?v=4)](https://github.com/z38 "z38 (1 commits)")[![Nikerabbit](https://avatars.githubusercontent.com/u/1109395?v=4)](https://github.com/Nikerabbit "Nikerabbit (1 commits)")

---

Tags

apimediawikiwikidatawikibase

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/addwiki-wikibase-api/health.svg)

```
[![Health](https://phpackages.com/badges/addwiki-wikibase-api/health.svg)](https://phpackages.com/packages/addwiki-wikibase-api)
```

###  Alternatives

[addwiki/mediawiki-api

A MediaWiki API library

43106.3k7](/packages/addwiki-mediawiki-api)[addwiki/mediawiki-api-base

Simple MediaWiki API library

37149.7k12](/packages/addwiki-mediawiki-api-base)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)[wikibase/data-model-serialization

Serializers and deserializers for the Wikibase DataModel

10196.3k8](/packages/wikibase-data-model-serialization)[professional-wiki/wikibase-local-media

Adds the local media data type to Wikibase

127.0k](/packages/professional-wiki-wikibase-local-media)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
