This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Wikibase\Repo\Api; |
||
| 4 | |||
| 5 | use ApiBase; |
||
| 6 | use ApiUsageException; |
||
| 7 | use InvalidArgumentException; |
||
| 8 | use LogicException; |
||
| 9 | use OutOfBoundsException; |
||
| 10 | use Wikibase\DataModel\Entity\EntityDocument; |
||
| 11 | use Wikibase\DataModel\Entity\EntityId; |
||
| 12 | use Wikibase\DataModel\Entity\EntityIdParser; |
||
| 13 | use Wikibase\DataModel\Entity\EntityIdParsingException; |
||
| 14 | use Wikibase\DataModel\Entity\PropertyId; |
||
| 15 | use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookupException; |
||
| 16 | use Wikibase\DataModel\Services\Statement\StatementGuidValidator; |
||
| 17 | use Wikibase\DataModel\Snak\Snak; |
||
| 18 | use Wikibase\DataModel\Statement\Statement; |
||
| 19 | use Wikibase\DataModel\Statement\StatementListProvider; |
||
| 20 | use Wikibase\Lib\Summary; |
||
| 21 | use Wikibase\Repo\ChangeOp\ChangeOp; |
||
| 22 | use Wikibase\Repo\ChangeOp\ChangeOpException; |
||
| 23 | use Wikibase\Repo\ChangeOp\ChangeOpValidationException; |
||
| 24 | use Wikibase\Repo\SnakFactory; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Helper class for modifying an entities statements. |
||
| 28 | * |
||
| 29 | * @license GPL-2.0-or-later |
||
| 30 | */ |
||
| 31 | class StatementModificationHelper { |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var SnakFactory |
||
| 35 | */ |
||
| 36 | private $snakFactory; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var EntityIdParser |
||
| 40 | */ |
||
| 41 | private $entityIdParser; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var StatementGuidValidator |
||
| 45 | */ |
||
| 46 | private $guidValidator; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var ApiErrorReporter |
||
| 50 | */ |
||
| 51 | private $errorReporter; |
||
| 52 | |||
| 53 | public function __construct( |
||
| 54 | SnakFactory $snakFactory, |
||
| 55 | EntityIdParser $entityIdParser, |
||
| 56 | StatementGuidValidator $guidValidator, |
||
| 57 | ApiErrorReporter $errorReporter |
||
| 58 | ) { |
||
| 59 | $this->snakFactory = $snakFactory; |
||
| 60 | $this->entityIdParser = $entityIdParser; |
||
| 61 | $this->guidValidator = $guidValidator; |
||
| 62 | $this->errorReporter = $errorReporter; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $guid |
||
| 67 | * |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function validateStatementGuid( $guid ) { |
||
| 71 | return $this->guidValidator->validate( $guid ); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param string $guid |
||
| 76 | * @param EntityDocument $entity |
||
| 77 | * |
||
| 78 | * @throws ApiUsageException |
||
| 79 | * @return Statement |
||
| 80 | */ |
||
| 81 | public function getStatementFromEntity( $guid, EntityDocument $entity ) { |
||
| 82 | if ( !( $entity instanceof StatementListProvider ) ) { |
||
| 83 | $this->errorReporter->dieError( 'Entity type does not support statements', 'no-such-claim' ); |
||
|
0 ignored issues
–
show
|
|||
| 84 | } |
||
| 85 | |||
| 86 | $statement = $entity->getStatements()->getFirstStatementWithGuid( $guid ); |
||
| 87 | |||
| 88 | if ( $statement === null ) { |
||
| 89 | $this->errorReporter->dieError( 'Could not find the statement', 'no-such-claim' ); |
||
|
0 ignored issues
–
show
The method
Wikibase\Repo\Api\ApiErrorReporter::dieError() has been deprecated with message: Use dieWithError() instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 90 | } |
||
| 91 | |||
| 92 | return $statement; |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param string[] $params Array with a 'snaktype' and an optional 'value' element. |
||
| 97 | * @param PropertyId $propertyId |
||
| 98 | * |
||
| 99 | * @throws ApiUsageException |
||
| 100 | * @throws LogicException |
||
| 101 | * @return Snak |
||
| 102 | */ |
||
| 103 | public function getSnakInstance( array $params, PropertyId $propertyId ) { |
||
| 104 | $valueData = null; |
||
| 105 | |||
| 106 | if ( isset( $params['value'] ) ) { |
||
| 107 | $valueData = json_decode( $params['value'], true ); |
||
| 108 | |||
| 109 | if ( $valueData === null ) { |
||
| 110 | $this->errorReporter->dieError( 'Could not decode snak value', 'invalid-snak' ); |
||
|
0 ignored issues
–
show
The method
Wikibase\Repo\Api\ApiErrorReporter::dieError() has been deprecated with message: Use dieWithError() instead.
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead. Loading history...
|
|||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | try { |
||
| 115 | $snak = $this->snakFactory->newSnak( $propertyId, $params['snaktype'], $valueData ); |
||
| 116 | return $snak; |
||
| 117 | } catch ( InvalidArgumentException $ex ) { |
||
| 118 | $this->errorReporter->dieException( $ex, 'invalid-snak' ); |
||
| 119 | } catch ( OutOfBoundsException $ex ) { |
||
| 120 | $this->errorReporter->dieException( $ex, 'invalid-snak' ); |
||
| 121 | } catch ( PropertyDataTypeLookupException $ex ) { |
||
| 122 | $this->errorReporter->dieException( $ex, 'invalid-snak' ); |
||
| 123 | } |
||
| 124 | |||
| 125 | throw new LogicException( 'ApiErrorReporter::dieException did not throw an exception' ); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Parses an entity id string coming from the user |
||
| 130 | * |
||
| 131 | * @param string $entityIdParam |
||
| 132 | * |
||
| 133 | * @throws ApiUsageException |
||
| 134 | * @return EntityId |
||
| 135 | * @todo this could go into an EntityModificationHelper or even in a ApiWikibaseHelper |
||
| 136 | */ |
||
| 137 | public function getEntityIdFromString( $entityIdParam ) { |
||
| 138 | try { |
||
| 139 | $entityId = $this->entityIdParser->parse( $entityIdParam ); |
||
| 140 | } catch ( EntityIdParsingException $ex ) { |
||
| 141 | $this->errorReporter->dieException( $ex, 'invalid-entity-id' ); |
||
| 142 | } |
||
| 143 | |||
| 144 | /** @var EntityId $entityId */ |
||
| 145 | return $entityId; |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Creates a new Summary instance suitable for representing the action performed by this module. |
||
| 150 | * |
||
| 151 | * @param array $params |
||
| 152 | * @param ApiBase $module |
||
| 153 | * |
||
| 154 | * @return Summary |
||
| 155 | */ |
||
| 156 | public function createSummary( array $params, ApiBase $module ) { |
||
| 157 | $summary = new Summary( $module->getModuleName() ); |
||
| 158 | if ( isset( $params['summary'] ) ) { |
||
| 159 | $summary->setUserSummary( $params['summary'] ); |
||
| 160 | } |
||
| 161 | return $summary; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Applies the given ChangeOp to the given Entity. |
||
| 166 | * Any ChangeOpException is converted into an ApiUsageException with the code 'modification-failed'. |
||
| 167 | * |
||
| 168 | * @param ChangeOp $changeOp |
||
| 169 | * @param EntityDocument $entity |
||
| 170 | * @param Summary|null $summary The summary object to update with information about the change. |
||
| 171 | */ |
||
| 172 | public function applyChangeOp( ChangeOp $changeOp, EntityDocument $entity, Summary $summary = null ) { |
||
| 173 | try { |
||
| 174 | $result = $changeOp->validate( $entity ); |
||
| 175 | |||
| 176 | if ( !$result->isValid() ) { |
||
| 177 | throw new ChangeOpValidationException( $result ); |
||
| 178 | } |
||
| 179 | |||
| 180 | $changeOp->apply( $entity, $summary ); |
||
| 181 | } catch ( ChangeOpException $ex ) { |
||
| 182 | $this->errorReporter->dieException( $ex, 'modification-failed' ); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | } |
||
| 187 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.