diff --git "a/class-wb\\Descriptions.php" "b/class-wb\\DataValueCommonsMedia.php" similarity index 74% copy from "class-wb\\Descriptions.php" copy to "class-wb\\DataValueCommonsMedia.php" index a8e950a..8865fa4 100644 --- "a/class-wb\\Descriptions.php" +++ "b/class-wb\\DataValueCommonsMedia.php" @@ -1,24 +1,33 @@ . # Wikibase namespace wb; /** - * A Label collector. + * A DataValue for a Wikimedia Commons file. */ -class Descriptions extends Labels {} +class DataValueCommonsMedia extends DataValueString { + + /** + * @return string + */ + public function __toString() { + return "[[c:File:{$this->getValue()}]]"; + } + +} diff --git "a/class-wb\\Descriptions.php" "b/class-wb\\Descriptions.php" index a8e950a..7ba3ec6 100644 --- "a/class-wb\\Descriptions.php" +++ "b/class-wb\\Descriptions.php" @@ -1,24 +1,35 @@ . # Wikibase namespace wb; /** - * A Label collector. + * Description collector */ -class Descriptions extends Labels {} +class Descriptions extends Labels { + + /** + * String rappresentation + * + * @return string + */ + public function __toString() { + return sprintf( 'description: %s', $this->getImplodedLanguages() ); + } + +} diff --git "a/class-wb\\Labels.php" "b/class-wb\\Labels.php" index 08c8b4b..8fbc169 100644 --- "a/class-wb\\Labels.php" +++ "b/class-wb\\Labels.php" @@ -1,91 +1,115 @@ . # Wikibase namespace wb; /** * Label collector */ class Labels { /** * @var array */ private $labels = []; /** * Constructor * * @param $labels array */ public function __construct( $labels = [] ) { foreach( $labels as $label ) { $this->add( $label ); } } /** * Get a certain language * * @param $language string * @return Label */ public function get( $language ) { foreach( $this->labels as $label ) { if( $label->getLanguage() === $language ) { return $label; } } return false; } /** * Does it have a certain label? * * @param $language string * @return bool */ public function have( $language ) { return false !== $this->get( $language ); } /** * Set/add a certain label * * @param $label Label * @return self */ public function set( Label $label ) { $existing = $this->get( $label->getLanguage() ); if( $existing ) { $existing = $language; } else { $this->labels[] = $label; } return $this; } /** * Get all the labels * * @return array */ public function getAll() { return $this->labels; } + + /** + * Get all the languages imploded + * + * @param $glue string + * @return string + */ + protected function getImplodedLanguages( $glue = ',' ) { + $all = $this->getAll(); + $codes = []; + foreach( $all as $label ) { + $codes[] = $label->getLanguage(); + } + return implode( $glue, $codes ); + } + + /** + * String rappresentation + * + * @return string + */ + public function __toString() { + return sprintf( 'label: %s', $this->getImplodedLanguages() ); + } }