Changeset View
Changeset View
Standalone View
Standalone View
include/wb/DataModel.php
<?php | <?php | ||||
# Boz-MW - Another MediaWiki API handler in PHP | # Boz-MW - Another MediaWiki API handler in PHP | ||||
# Copyright (C) 2017, 2018, 2019, 2020 Valerio Bozzolan | # Copyright (C) 2017-2023 Valerio Bozzolan, contributors | ||||
# | # | ||||
# This program is free software: you can redistribute it and/or modify | # This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU Affero General Public License as published by | # it under the terms of the GNU Affero General Public License as published by | ||||
# the Free Software Foundation, either version 3 of the License, or | # the Free Software Foundation, either version 3 of the License, or | ||||
# (at your option) any later version. | # (at your option) any later version. | ||||
# | # | ||||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU Affero General Public License for more details. | # GNU Affero General Public License for more details. | ||||
# | # | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# Wikibase | # Wikibase | ||||
namespace wb; | namespace wb; | ||||
use \mw\WikibaseSite; | use \mw\WikibaseSite; | ||||
use \wb\Label; | |||||
use \wb\Description; | |||||
/** | /** | ||||
* Wikibase data container | * Wikibase data container | ||||
* | * | ||||
* It can be used to abstract a Wikibase Entity and | * It can be used to abstract a Wikibase Entity and | ||||
* remove/add labels, descriptions, attributes, | * remove/add labels, descriptions, attributes, | ||||
* references, etc. | * references, etc. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | class DataModel { | ||||
* @param $language string | * @param $language string | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function hasLabelInLanguage( $language ) { | public function hasLabelInLanguage( $language ) { | ||||
return $this->labels->have( $language ); | return $this->labels->have( $language ); | ||||
} | } | ||||
/** | /** | ||||
* Get a label in a specific language | |||||
* | |||||
* @param $language Language code, as accepted by Wikidata | |||||
* @return string|null | |||||
*/ | |||||
public function getLabelValue( $language ) { | |||||
return $this->labels->getLanguageValue( $language ); | |||||
} | |||||
/** | |||||
* Set a label in a specific language | |||||
* | |||||
* @param $language Language code, as accepted by Wikidata | |||||
* @param $value Language value | |||||
* @return self | |||||
*/ | |||||
public function setLabelValue( $language, $value ) { | |||||
$this->labels->setLanguageValue( $language, $value ); | |||||
return $this; | |||||
} | |||||
/** | |||||
* Set, delete, preserve if it exists, a label. | * Set, delete, preserve if it exists, a label. | ||||
* | |||||
* You may want to use setLabelValue() instead that is more user-friendly. | |||||
* | |||||
* @param $label Label object | |||||
* @return self | |||||
*/ | */ | ||||
public function setLabel( $label ) { | public function setLabel( $label ) { | ||||
$this->labels->set( $label ); | $this->labels->set( $label ); | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | /** | ||||
* Check if a label of a certain language exists | * Check if a description exists in a certain language | ||||
* | * | ||||
* @param $language string | * @param $language string Language code, as accepted by Wikidata | ||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public function hasDescriptionInLanguage( $language ) { | public function hasDescriptionInLanguage( $language ) { | ||||
return $this->descriptions->have( $language ); | return $this->descriptions->have( $language ); | ||||
} | } | ||||
/** | /** | ||||
* Get a description in a specific language | |||||
* | |||||
* @param $language Language code, as accepted by Wikidata | |||||
* @return string|null | |||||
*/ | |||||
public function getDescriptionValue( $language ) { | |||||
return $this->descriptions->getLanguageValue( $language ); | |||||
} | |||||
/** | |||||
* Set a label in a specific language | |||||
* | |||||
* @param $language Language code, as accepted by Wikidata | |||||
* @param $value Language value | |||||
* @return self | |||||
*/ | |||||
public function setDescriptionValue( $language, $value ) { | |||||
$this->descriptions->setLanguageValue( $language, $value ); | |||||
return $this; | |||||
} | |||||
/** | |||||
* Set, delete, preserve if it exists, a description. | * Set, delete, preserve if it exists, a description. | ||||
* | * | ||||
* @param $description Description | * @param $description Description | ||||
* @return self | * @return self | ||||
*/ | */ | ||||
public function setDescription( $description ) { | public function setDescription( $description ) { | ||||
$this->descriptions->set( $description ); | $this->descriptions->set( $description ); | ||||
return $this; | return $this; | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register