| Current File : /home/jvzmxxx/wiki/extensions/Wikibase/repo/includes/Specials/SpecialSetLabel.php |
<?php
namespace Wikibase\Repo\Specials;
use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Term\LabelsProvider;
use Wikibase\Summary;
/**
* Special page for setting the label of a Wikibase entity.
*
* @since 0.4
*
* @license GPL-2.0+
* @author Bene* < benestar.wikimedia@gmail.com >
*/
class SpecialSetLabel extends SpecialModifyTerm {
/**
* @since 0.4
*/
public function __construct() {
parent::__construct( 'SetLabel' );
}
public function doesWrites() {
return true;
}
/**
* @see SpecialModifyTerm::validateInput
*
* @return bool
*/
protected function validateInput() {
if ( !parent::validateInput() ) {
return false;
}
return $this->entityRevision->getEntity() instanceof LabelsProvider;
}
/**
* @see SpecialSetEntity::getPostedValue()
*
* @since 0.4
*
* @return string
*/
protected function getPostedValue() {
return $this->getRequest()->getVal( 'label' );
}
/**
* @see SpecialSetEntity::getValue()
*
* @since 0.4
*
* @param EntityDocument $entity
* @param string $languageCode
*
* @throws InvalidArgumentException
* @return string
*/
protected function getValue( EntityDocument $entity, $languageCode ) {
if ( !( $entity instanceof LabelsProvider ) ) {
throw new InvalidArgumentException( '$entity must be a LabelsProvider' );
}
$labels = $entity->getLabels();
if ( $labels->hasTermForLanguage( $languageCode ) ) {
return $labels->getByLanguage( $languageCode )->getText();
}
return '';
}
/**
* @see SpecialSetEntity::setValue()
*
* @since 0.4
*
* @param EntityDocument $entity
* @param string $languageCode
* @param string $value
*
* @return Summary
*/
protected function setValue( EntityDocument $entity, $languageCode, $value ) {
$value = $value === '' ? null : $value;
$summary = new Summary( 'wbsetlabel' );
if ( $value === null ) {
$changeOp = $this->termChangeOpFactory->newRemoveLabelOp( $languageCode );
} else {
$changeOp = $this->termChangeOpFactory->newSetLabelOp( $languageCode, $value );
}
$this->applyChangeOp( $changeOp, $entity, $summary );
return $summary;
}
}