diff --git a/autoload.php b/autoload.php index d945280..0926d15 100644 --- a/autoload.php +++ b/autoload.php @@ -1,23 +1,23 @@ . -spl_autoload_register( function($name) { +spl_autoload_register( function( $name ) { $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; if( is_file( $path ) ) { require $path; } } ); diff --git "a/class-mw\\APIRequest.php" "b/class-mw\\APIRequest.php" index 0956ea2..ce1745d 100644 --- "a/class-mw\\APIRequest.php" +++ "b/class-mw\\APIRequest.php" @@ -1,275 +1,275 @@ . # MediaWiki namespace mw; class APIRequest { const WAIT = 0.2; const WAIT_POST = 5; const WAIT_DOS = 5; const VERSION = 0.3; private $api; private $data; private $args; private $continue; private $last = null; private $latestHttpResponseHeaders = []; private $cookies = []; private $debug = false; public function __construct( $api, $data = [], $args = [] ) { $this->api = $api; $this->data = array_replace( [ 'maxlag' => 5, 'format' => 'json' ], $data ); $this->args = array_replace( [ 'method' => 'GET', 'wait' => self::WAIT, 'wait-post' => self::WAIT_POST, 'user-agent' => sprintf( 'Boz-MW APIRequest.php/%s', self::VERSION ), 'headers' => [] ], $args ); } public static function factory( $api, $args = [] ) { return new self( $api, $args ); } public function lastfetch() { return isset( $this->last ) ? $this->last : $this->fetch(); } // https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=Q38&format=jsonfm public function fetchFirstClaimValue($property) { return @ $this->lastfetch()->claims->{$property}[0]->mainsnak->datavalue->value; } public function hasNext() { return $this->continue !== false; } public function setDebug( $debug ) { $this->debug = $debug; return $this; } public function fetch( $data = [], $args = [] ) { $data = array_replace( $this->data, $data ); $args = array_replace( $this->args, $args ); // HTTP query using file_get_contents() $url = $this->api; $query = http_build_query( $data ); $context = [ 'http' => [] ]; $context['http']['method'] = $args['method']; if( $args['user-agent'] ) { $args['headers'][] = self::header( 'User-Agent', $args['user-agent'] ); } if( $this->haveCookies() ) { $args['headers'][] = $this->getCookieHeader(); } if( $query ) { if( 'POST' === $args['method'] ) { $args['headers'][] = self::header('Content-Type', 'application/x-www-form-urlencoded' ); $context['http']['content'] = $query; } else { $url .= "?$query"; } } if( $args['headers'] ) { $context['http']['header'] = self::implodeHTTPHeaders( $args['headers'] ); } if( $this->debug ) { self::log('DEBUG', $url ); } if( $args['wait'] ) { self::log('INFO', sprintf( "Waiting %.2f s...", $args['wait'] ) ); usleep( $args['wait'] * 1000000 ); } self::log('INFO', sprintf( "%s request", $args['method'] ) ); $stream_context = stream_context_create( $context ); $result = file_get_contents( $url, false, $stream_context ); $result = json_decode( $result ); // Here $http_response_header exists magically (PHP merda!) $this->loadHTTPResponseHeaders( $http_response_header ); self::log('INFO', "Fetched"); if( isset( $result->error ) ) { if( 'maxlag' === $result->error->code ) { self::log( WARN, "Lag!"); $args = array_replace( [ 'wait' => self::WAIT_DOS ], $args ); return $this->fetch( $data , $args ); } else { print_r( $result->error ); - throw new Exception( "API error" ); + throw new \Exception( "API error" ); } } return $this->last = $result; } public function post( $data = [], $args = [] ) { $args = array_replace( [ 'method' => 'POST', 'wait' => $this->args['wait-post'] ], $args ); return $this->fetch( $data, $args ); } public function getNext() { $data = $this->data; if( $this->continue ) { self::log('INFO', "Will continue"); foreach($this->continue as $arg => $value) { $data[ $arg ] = $value; } } $next = $this->fetch( $data ); $this->continue = isset( $next->continue ) ? $next->continue : false; return $next; } public function getLatestHTTPResponseHeaders() { return $this->latestHttpResponseHeaders; } /** * Load HTTP response headers, filling cookies. */ private function loadHTTPResponseHeaders( $http_response_headers ) { $this->latestHttpResponseHeaders = self::parseHTTPResponseHeaders( $http_response_headers ); if( isset( $this->latestHttpResponseHeaders['Set-Cookie'] ) ) { foreach( $this->latestHttpResponseHeaders['Set-Cookie'] as $cookie ) { $this->setRawCookie( $cookie ); } } } /** * Group HTTP headers by keys. * * @return array */ private static function parseHTTPResponseHeaders( $http_response_headers ) { $headers = []; foreach( $http_response_headers as $header ) { $header_parts = explode(':', $header, 2); if( 2 === count( $header_parts ) ) { list( $name, $value ) = $header_parts; if( ! isset( $headers[ $name ] ) ) { $headers[ $name ] = []; } $headers[ $name ][] = ltrim( $value ); } } return $headers; } public function haveCookies() { return $this->cookies; } public function getCookies() { return $this->cookies; } public function setCookie( $name, $value ) { $this->cookies[ $name ] = $value; return $this; } private function setRawCookie( $cookie ) { $parts = explode(';', $cookie); if( isset( $parts[0] ) ) { $name_value = explode('=', $parts[0] ); if( 2 === count( $name_value ) ) { list( $name, $value ) = $name_value; $this->setCookie( $name, $value ); } } } public function getCookieHeader() { $cookies = []; foreach( $this->getCookies() as $name => $value ) { $cookies[] = urlencode( $name ) . '=' . urlencode( $value ); } return self::headerRaw( 'Cookie', implode( '; ', $cookies ) ); } public function getHTTPCookies() { return $this->cookies; } private function implodeHTTPHeaders( $headers ) { if( ! $headers ) { return null; } $s = ''; foreach( $headers as $header ) { $s .= "$header\r\n"; } return $s; } private static function header( $name, $value ) { return self::headerRaw( $name, urlencode( $value ) ); } private static function headerRaw( $name, $value ) { return sprintf( '%s: %s', $name, $value ); } private static function log( $type, $msg ) { printf("# [%s] \t %s\n", $type, $msg); } } diff --git "a/class-wb\\Claim.php" "b/class-wb\\Claim.php" new file mode 100644 index 0000000..b0f6bfd --- /dev/null +++ "b/class-wb\\Claim.php" @@ -0,0 +1,69 @@ +. + +# Wikibase +namespace wb; + +/** + * A Claim consists of a property and a value (Snak). + * + * Optionally, it can have qualifiers. + * + * @see https://www.wikidata.org/wiki/Wikidata:Glossary#Claim + */ +class Claim { + + var $property; + var $mainsnak; + //var $qualifiers; + + /** + * @param $property string Property as 'P123' + * @param $mainsnak Snak Main snak + */ + public function __construct( $property, $mainsnak ) { + $this->setProperty( $property ) + ->setMainsnak( $mainsnak ); + } + + public function getProperty() { + return $this->property; + } + + public function getMainsnak() { + return $this->property; + } + + public function getQualifiers() { + return $this->property; + } + + public function setProperty( $property ) { + $this->property = $property; + return $this; + } + + public function setMainsnak( Snak $mainsnak ) { + $this->mainsnak = $mainsnak; + return $this; + } + + public function setQualifiers( $qualifiers ) { + $this->qualifiers = $qualifiers; + return $this; + } +} diff --git "a/class-wb\\Claims.php" "b/class-wb\\Claims.php" new file mode 100644 index 0000000..dccad7e --- /dev/null +++ "b/class-wb\\Claims.php" @@ -0,0 +1,59 @@ +. + +# Wikibase +namespace wb; + +/** + * A Claim collector. + */ +class Claims { + + var $claims = []; + + public function __construct( $claims = [] ) { + $this->set( $claims ); + } + + public function add( Claim $claim ) { + $this->claims[] = $claim; + return $this; + } + + public function count() { + return count( $this->claims ); + } + + public function set( $claims ) { + foreach( $claims as $claim ) { + $this->add( $claim ); + } + return $this; + } + + public function get() { + $properties = []; + foreach( $this->claims as $claim ) { + $property = $claim->getProperty(); + if( ! isset( $properties[ $property ] ) ) { + $properties[ $property ] = []; + } + $properties[ $property ][] = $claim; + } + return $properties; + } +} diff --git "a/class-wb\\DataModel.php" "b/class-wb\\DataModel.php" index 4c829e8..1583eed 100644 --- "a/class-wb\\DataModel.php" +++ "b/class-wb\\DataModel.php" @@ -1,80 +1,110 @@ . # Wikibase namespace wb; class DataModel { - private $data; + private $labels; + private $descriptions; + private $claims; public function __construct() { - $this->data = []; + $this->labels = []; + $this->descriptions = []; + $this->claims = new Claims(); } - public function getJSON() { - return json_encode( $this->get() ); + public function getLabels() { + return $this->labels; } - public function get() { - return $this->data; + public function getDescriptions() { + return $this->descriptions; + } + + public function getClaims() { + return $this->claims->get(); + } + + public function addClaim( $claim ) { + $this->claims->add( $claim ); + return $this; + } + + public function setClaims( $claims ) { + $this->claims->set( $claims ); + return $this; } /** - * Set Wikidata labels - * - * @param array $langs_label Associative array of language-code => label. - * @param string $action Set to 'add' or 'remove' or NULL. + * Set, delete, preserve if it exists, a label. */ - public function setLabels( $langs_label = [], $action = null ) { - return $this->set( self::labels( $langs_label, $action ) ); + public function setLabel( $language, $value, $action = 'only-if-missing' ) { + $label = new LabelAction( $language, $value ); + switch( $action ) { + case 'only-if-missing': + $label->pleasePreserve(); + break; + case 'delete': + $label->pleaseDelete(); + case 'overwrite': + break; + default: + throw new Exception(); + } + $this->labels[] = $label; + return $this; } /** - * Wikidata labels data model - * - * @param array $langs_label Associative array of language-code => label. - * @param string $action Set to 'add' or 'remove' or NULL. - * @see https://www.wikidata.org/w/api.php?action=help&modules=wbeditentity + * Set, delete, preserve if it exists, a description. */ - static public function labels( $langs_label = [], $action = null ) { - if( null !== $action ) { - if( 'add' !== $action && 'remove' !== $action ) { - throw new Exception('wrong labels action'); - } - } - $labels = []; - foreach( $labels as $lang => $value ) { - $labels[ $lang ] = [ - 'language' => $lang, - 'value' => $value - ]; - if( $action ) { - $labels[ $lang ][ $action ] = ''; - } - } - if( $labels ) { - $labels = [ 'labels' => $labels ]; + public function setDescription( $language, $value, $action = 'only-if-missing' ) { + $description = new DescriptionAction( $language, $value ); + switch( $action ) { + case 'only-if-missing': + $description->pleasePreserve(); + break; + case 'delete': + $description->pleaseDelete(); + case 'overwrite': + break; + default: + throw new Exception(); } - return $labels; + $this->descriptions[] = $description; + return $this; } - public function set( $additional_data ) { - $this->data = array_merge( $this->data, $additional_data ); - return $this; + public function countClaims() { + return $this->claims->count(); + } + + public function get() { + return [ + 'labels' => $this->getLabels(), + 'descriptions' => $this->getDescriptions(), + 'claims' => $this->getClaims() + ]; + } + + public function getJSON( $args = null ) { + return json_encode( $this->get(), $args ); } } diff --git "a/class-wb\\DataType.php" "b/class-wb\\DataType.php" new file mode 100644 index 0000000..ce5131b --- /dev/null +++ "b/class-wb\\DataType.php" @@ -0,0 +1,39 @@ +. + +# Wikibase +namespace wb; + +/** + * A DataType. + * + * @see https://www.wikidata.org/wiki/Special:ListDatatypes + */ +class DataType { + + const COMMONS_MEDIA = 'commonsMedia'; + const STRING = 'string'; + const URL = 'url'; + const TIME = 'time'; + const QUANTITY = 'quantity'; + const MONOLINGUAL_TEXT = 'monolingualtext'; + const ITEM = 'wikibase-item'; + const ENTITY_ID = 'wikibase-entityid'; + const PROPERTY = 'wikibase-property'; + const EXTERNAL_ID = 'external-id'; + +} diff --git "a/class-wb\\DataValue.php" "b/class-wb\\DataValue.php" new file mode 100644 index 0000000..74af58b --- /dev/null +++ "b/class-wb\\DataValue.php" @@ -0,0 +1,55 @@ +. + +# Wikibase +namespace wb; + +/** + * A generic DataValue is part of a Snak. + */ +class DataValue { + + var $type; + var $value; + + /** + * @param $type string Type + * @param $value mixed Value + */ + public function __construct( $type, $value ) { + $this->setType( $type ) + ->setValue( $value ); + } + + public function getType() { + return $this->type; + } + + public function getValue() { + return $this->value(); + } + + public function setType( $type ) { + $this->type = $type; + return $this; + } + + public function setValue( $value ) { + $this->value = $value; + return $this; + } +} diff --git a/autoload.php "b/class-wb\\DataValueItem.php" similarity index 54% copy from autoload.php copy to "class-wb\\DataValueItem.php" index d945280..71c5db1 100644 --- a/autoload.php +++ "b/class-wb\\DataValueItem.php" @@ -1,23 +1,36 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A DataValue for a wikibase Item. + */ +class DataValueItem extends DataValue { + + /** + * @param $qcode string Entity Q-code as 'Q1' + */ + public function __construct( $qcode ) { + parent::__construct( DataType::ENTITY_ID, [ + 'entity-type' => 'item', + 'numeric-id' => Item::numericQCode( $qcode ), + 'id' => $qcode + ] ); } -} ); +} diff --git a/autoload.php "b/class-wb\\DataValueString.php" similarity index 61% copy from autoload.php copy to "class-wb\\DataValueString.php" index d945280..6e437a2 100644 --- a/autoload.php +++ "b/class-wb\\DataValueString.php" @@ -1,23 +1,32 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A DataValue for a string. + */ +class DataValueString extends DataValue { + + /** + * @param $value string Value + */ + public function __construct( $value ) { + parent::__construct( DataType::STRING, $value ); } -} ); +} diff --git a/autoload.php "b/class-wb\\Description.php" similarity index 66% copy from autoload.php copy to "class-wb\\Description.php" index d945280..2adbca5 100644 --- a/autoload.php +++ "b/class-wb\\Description.php" @@ -1,23 +1,26 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; - } -} ); +# Wikibase +namespace wb; + +/** + * An entity Description. + * + * @see https://www.wikidata.org/wiki/Wikidata:Glossary#Description + */ +class Description extends Label {} diff --git a/autoload.php "b/class-wb\\DescriptionAction.php" similarity index 67% copy from autoload.php copy to "class-wb\\DescriptionAction.php" index d945280..70b0c3a 100644 --- a/autoload.php +++ "b/class-wb\\DescriptionAction.php" @@ -1,23 +1,24 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; - } -} ); +# Wikibase +namespace wb; + +/** + * @see https://www.wikidata.org/w/api.php?action=help&modules=wbeditentity + */ +class DescriptionAction extends LabelAction { } diff --git a/autoload.php "b/class-wb\\Item.php" similarity index 52% copy from autoload.php copy to "class-wb\\Item.php" index d945280..b21ccbe 100644 --- a/autoload.php +++ "b/class-wb\\Item.php" @@ -1,23 +1,39 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * An Item is a Wikibase Q-entity. + * + * @see https://www.wikidata.org/wiki/Wikidata:Glossary#Item + */ +class Item { + + /** + * @param $qcode Q-code as 'Q123' + * @return string The numeric form of the Q-Code as `123` + */ + public static function numericQCode( $qcode ) { + $code = (int) substr( $qcode, 1 ); + if( ! $code ) { + throw new \Exception('invalid Q-code'); + } + return $code; } -} ); +} diff --git "a/class-wb\\Label.php" "b/class-wb\\Label.php" new file mode 100644 index 0000000..df8499a --- /dev/null +++ "b/class-wb\\Label.php" @@ -0,0 +1,53 @@ +. + +# Wikibase +namespace wb; + +/** + * An entity Label. + * + * @see https://www.wikidata.org/wiki/Wikidata:Glossary#Label + */ +class Label { + + var $language; + var $value; + + public function __construct( $language, $value ) { + $this->setLanguage( $language ) + ->setValue( $value ); + } + + public function getLanguage() { + return $this->language; + } + + public function getValue() { + return $this->value; + } + + public function setLanguage( $language ) { + $this->language = $language; + return $this; + } + + public function setValue( $value ) { + $this->value = $value; + return $this; + } +} diff --git a/autoload.php "b/class-wb\\LabelAction.php" similarity index 51% copy from autoload.php copy to "class-wb\\LabelAction.php" index d945280..9568907 100644 --- a/autoload.php +++ "b/class-wb\\LabelAction.php" @@ -1,23 +1,44 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * @see https://www.wikidata.org/w/api.php?action=help&modules=wbeditentity + */ +class LabelAction extends Label { + + /** + * Add a Label without overwriting if it already exists. + */ + public function pleasePreserve() { + $this->add = ''; + unset( $this->remove ); + return $this; } -} ); + + /** + * Remove the label. + */ + public function pleaseDelete() { + $this->remove = ''; + unset( $this->add ); + return $this; + } + +} diff --git "a/class-wb\\Snak.php" "b/class-wb\\Snak.php" new file mode 100644 index 0000000..875c90b --- /dev/null +++ "b/class-wb\\Snak.php" @@ -0,0 +1,82 @@ +. + +# Wikibase +namespace wb; + +/** + * A generic Snak is a combination of a property and a datatype + datavalue. + * + * A Snak is part of a Claim or a Reference. It's based on a DataValue. + */ +class Snak { + + //var $hash; + var $snaktype; + var $property; + var $datatype; + var $datavalue; + + /** + * @param $snaktype string + * @param $property string + * @param $datatype string + * @param $datavalue mixed + */ + public function __construct( $snaktype, $property, $datatype, $datavalue ) { + $this->setSnakType( $snaktype ) + ->setProperty( $property ) + ->setDataType( $datatype ) + ->setDataValue( $datavalue ); + } + + public function getProperty() { + return $this->property; + } + + public function getSnakType() { + return $this->snaktype; + } + + public function getDataType() { + return $this->datatype; + } + + public function getDataValue() { + return $this->datavalue; + } + + public function setSnakType( $snaktype ) { + $this->snaktype = $snaktype; + return $this; + } + + public function setProperty( $property ) { + $this->property = $property; + return $this; + } + + public function setDataType( $datatype ) { + $this->datatype = $datatype; + return $this; + } + + public function setDataValue( DataValue $datavalue ) { + $this->datavalue = $datavalue; + return $this; + } +} diff --git a/autoload.php "b/class-wb\\SnakCommonsMedia.php" similarity index 53% copy from autoload.php copy to "class-wb\\SnakCommonsMedia.php" index d945280..0a5a57d 100644 --- a/autoload.php +++ "b/class-wb\\SnakCommonsMedia.php" @@ -1,23 +1,38 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A Snak for a Commons filename. + */ +class SnakCommonsMedia extends Snak { + + /** + * @param $property string Property as 'P123' + * @param $filename string File name as 'File:Example.png' + */ + public function __construct( $property, $filename ) { + parent::__construct( + 'value', + $property, + DataType::COMMONS_MEDIA, + new DataValueString( $filename ) + ); } -} ); +} diff --git a/autoload.php "b/class-wb\\SnakItem.php" similarity index 55% copy from autoload.php copy to "class-wb\\SnakItem.php" index d945280..039807f 100644 --- a/autoload.php +++ "b/class-wb\\SnakItem.php" @@ -1,23 +1,38 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A Snak for a Wikibase Item. + */ +class SnakItem extends Snak { + + /** + * @param $property Wikidata property as 'P123' + * @param $item Wikidata item as 'Q1' + */ + public function __construct( $property, $item ) { + return parent::__construct( + 'value', + $property, + DataType::ITEM, + new DataValueItem( $item ) + ); } -} ); +} diff --git a/autoload.php "b/class-wb\\SnakString.php" similarity index 55% copy from autoload.php copy to "class-wb\\SnakString.php" index d945280..bbc82ba 100644 --- a/autoload.php +++ "b/class-wb\\SnakString.php" @@ -1,23 +1,38 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A Snak for a string. + */ +class SnakString extends Snak { + + /** + * @param $property string Wikidata property as 'P123' + * @param $value string + */ + public function __construct( $property, $value ) { + return parent::__construct( + 'value', + $property, + DataType::STRING, + new DataValueString( $value ) + ); } -} ); +} diff --git "a/class-wb\\Snaks.php" "b/class-wb\\Snaks.php" new file mode 100644 index 0000000..6d009af --- /dev/null +++ "b/class-wb\\Snaks.php" @@ -0,0 +1,55 @@ +. + +# Wikibase +namespace wb; + +/** + * A Snak collector. + */ +class Snaks { + + var $snaks = []; + + public function __construct( $snaks = [] ) { + $this->set( $snaks ); + } + + public function add( Snak $snak ) { + $this->snaks[] = $snak; + return $this; + } + + public function set( $snaks ) { + foreach( $snaks as $snak ) { + $this->add( $snak ); + } + return $this; + } + + public function get() { + $properties = []; + foreach( $this->snaks as $snak ) { + $property = $snak->getProperty(); + if( ! isset( $properties[ $property ] ) ) { + $properties[ $property ] = []; + } + $properties[ $property ][] = $snak; + } + return $properties; + } +} diff --git "a/class-wb\\Statement.php" "b/class-wb\\Statement.php" new file mode 100644 index 0000000..bfb6791 --- /dev/null +++ "b/class-wb\\Statement.php" @@ -0,0 +1,59 @@ +. + +# Wikibase +namespace wb; + +/** + * A Statement is a type of Claim with references and a rank. + * + * @see https://www.wikidata.org/wiki/Wikidata:Glossary#Statement + */ +class Statement extends Claim { + + //var $id; + var $type = 'statement'; + var $rank = 'normal'; + var $references = []; + + public function getType() { + return $this->type; + } + + public function getRank() { + return $this->rank; + } + + public function getReferences() { + return $this->references; + } + + public function setType( $type ) { + $this->type = $type; + return $this; + } + + public function setRank( $rank ) { + $this->rank = $rank; + return $this; + } + + public function setReferences( $references ) { + $this->references = $references; + return $this; + } +} diff --git a/autoload.php "b/class-wb\\StatementCommonsMedia.php" similarity index 52% copy from autoload.php copy to "class-wb\\StatementCommonsMedia.php" index d945280..9287679 100644 --- a/autoload.php +++ "b/class-wb\\StatementCommonsMedia.php" @@ -1,23 +1,35 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A StatementCommonMedia is a Statement that contains a SnakCommonMedia. + */ +class StatementCommonsMedia extends Statement { + + /** + * @param $property string Property as 'P123' + * @param $filename string File name as 'File:Example.png' + */ + public function __construct( $property, $filename ) { + parent::__construct( $property, + new SnakCommonsMedia( $property, $filename ) + ); } -} ); +} diff --git a/autoload.php "b/class-wb\\StatementItem.php" similarity index 55% copy from autoload.php copy to "class-wb\\StatementItem.php" index d945280..679fa7c 100644 --- a/autoload.php +++ "b/class-wb\\StatementItem.php" @@ -1,23 +1,35 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A StatementItem is a Statement that contains a SnakItem. + */ +class StatementItem extends Statement { + + /** + * @param $property Wikidata property as 'P123' + * @param $item Wikidata item as 'Q1' + */ + public function __construct( $property, $item ) { + parent::__construct( $property, + new SnakItem( $property, $item ) + ); } -} ); +} diff --git a/autoload.php "b/class-wb\\StatementString.php" similarity index 53% copy from autoload.php copy to "class-wb\\StatementString.php" index d945280..12d5541 100644 --- a/autoload.php +++ "b/class-wb\\StatementString.php" @@ -1,23 +1,35 @@ . +# along with this program. If not, see . -spl_autoload_register( function($name) { - $path = __DIR__ . DIRECTORY_SEPARATOR . "class-$name.php"; - if( is_file( $path ) ) { - require $path; +# Wikibase +namespace wb; + +/** + * A StatementString is a Statement that contains a SnakString. + */ +class StatementString extends Statement { + + /** + * @param $property string Property as 'P123' + * @param $filename string File name as 'File:Example.png' + */ + public function __construct( $property, $filename ) { + parent::__construct( $property, + new SnakString( $property, $filename ) + ); } -} ); +}