Skip to content

Commit

Permalink
feat: Parse title on API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
it-spiderman authored and pwirth committed Jan 26, 2022
1 parent eabd5e4 commit 0a87a0a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 21 deletions.
12 changes: 5 additions & 7 deletions includes/API/GetHashChainInfoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ public function getParamSettings() {
*/
protected function getEntity( string $identifierType ): ?VerificationEntity {
$identifier = $this->getValidatedParams()['identifier'];
$conds = [];
if ( $identifierType === 'title' ) {
// TODO: DB data should hold Db key, not prefixed text (spaces replaced with _)
// Once that is done, remove next line
$identifier = str_replace( '_', ' ', $identifier );
$conds['page_title'] = $identifier;
$title = \Title::newFromText( $identifier );
return $this->verificationEngine->getLookup()->verificationEntityFromTitle( $title );
} else {
$conds[VerificationEntity::GENESIS_HASH] = $identifier;
return $this->verificationEngine->getLookup()->verificationEntityFromQuery( [
VerificationEntity::GENESIS_HASH => $identifier,
] );
}
return $this->verificationEngine->getLookup()->verificationEntityFromQuery( $conds );
}
}
8 changes: 2 additions & 6 deletions includes/API/GetPageAllRevsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ public function getParamSettings() {
* @return VerificationEntity|null
*/
protected function getEntity( string $pageTitle ): ?VerificationEntity {
// TODO: DB data should hold Db key, not prefixed text (spaces replaced with _)
// Once that is done, remove next line
$pageTitle = str_replace( '_', ' ', $pageTitle );
return $this->verificationEngine->getLookup()->verificationEntityFromQuery( [
'page_title' => $pageTitle
] );
$title = \Title::newFromText( $pageTitle );
return $this->verificationEngine->getLookup()->verificationEntityFromTitle( $title );
}
}
9 changes: 2 additions & 7 deletions includes/API/GetPageLastRevHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ public function getParamSettings() {
* @return VerificationEntity|null
*/
protected function getEntity(): ?VerificationEntity {
$pageTitle = $this->getValidatedParams()['page_title'];
// TODO: DB data should hold Db key, not prefixed text (spaces replaced with _)
// Once that is done, remove next line
$pageTitle = str_replace( '_', ' ', $pageTitle );
return $this->verificationEngine->getLookup()->verificationEntityFromQuery( [
'page_title' => $pageTitle
] );
$title = \Title::newFromText( $this->getValidatedParams()['page_title'] );
return $this->verificationEngine->getLookup()->verificationEntityFromTitle( $title );
}
}
2 changes: 1 addition & 1 deletion includes/Verification/VerificationLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function verificationEntityFromRevId( int $revId ): ?VerificationEntity {
* @return VerificationEntity|null
*/
public function verificationEntityFromTitle( Title $title ): ?VerificationEntity {
if ( !$title->exists() ) {
if ( !( $title instanceof Title ) || !$title->exists() ) {
return null;
}
// TODO: Replace with getPrefixedDBkey, once database enties use it
Expand Down

0 comments on commit 0a87a0a

Please sign in to comment.