1. Go to this page and download the library: Download addwiki/wikibase-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
addwiki / wikibase-api example snippets
$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()
)
);
$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()
$getter = $wbFactory->newRevisionGetter();
$entityRevision = $getter->getFromId( 'Q87' );
$entityRevision->getContent()->getData()->setDescription( 'en', 'I am A description' );
$saver->save( $entityRevision, new EditInfo( 'Custom edit summary' ) );