Skip to content
7 changes: 7 additions & 0 deletions PersistentPageIdentifiers.alias.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$specialPageAliases = [];

/** English (English) */
$specialPageAliases['en'] = [
'PURIResolver' => [ 'PURIResolver' ],
];
5 changes: 5 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
}
],

"SpecialPages": {
"PURIResolver": "ProfessionalWiki\\PersistentPageIdentifiers\\EntryPoints\\SpecialPURIResolver"
},

"ExtensionMessagesFiles": {
"PersistentPageIdentifiersAlias": "PersistentPageIdentifiers.alias.php",
"PersistentPageIdentifiersMagic": "i18n/Magic/MagicWords.php"
},

Expand Down
5 changes: 4 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
},
"persistentpageidentifiers-name": "Persistent Page Identifiers",
"persistentpageidentifiers-description": "Stable unique identifiers for your wiki pages. UUID v7 or PURIs, accessible via parser function and REST API",
"persistentpageidentifiers-info-label": "Persistent page identifier"
"persistentpageidentifiers-info-label": "Persistent page identifier",
"puriresolver": "Redirect by PURI",
"puriresolver-puri": "PURI",
"puriresolver-not-exists": "PURI does not exist"
}
5 changes: 4 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
},
"persistentpageidentifiers-name": "{{Name}}",
"persistentpageidentifiers-description": "{{Desc|name=PersistentPageIdentifiers|url=https://github.com/ProfessionalWiki/PersistentPageIdentifiers}}",
"persistentpageidentifiers-info-label": "Persistent page identifier label on action=info page"
"persistentpageidentifiers-info-label": "Persistent page identifier label on action=info page",
"puriresolver": "Special page name for redirect by PURI",
"puriresolver-puri": "Label for PURI input field",
"puriresolver-not-exists": "Error message when PURI does not exist"
}
11 changes: 11 additions & 0 deletions src/Adapters/PageIdsRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@
);
}

public function getPageIdFromPersistentId( string $persistentId ): ?int {
$row = $this->database->newSelectQueryBuilder()
->select( [ 'p.page_id', 'ppi.persistent_id' ] )
->from( 'page', 'p' )
->leftJoin( 'persistent_page_ids', 'ppi', 'p.page_id = ppi.page_id' )
->where( [ 'ppi.persistent_id' => $persistentId ] )
->fetchRow();

return $row ? (int)$row->page_id : null;

Check failure on line 41 in src/Adapters/PageIdsRepo.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Cannot access property $page_id on stdClass|true.

Check failure on line 41 in src/Adapters/PageIdsRepo.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Cannot access property $page_id on stdClass|true.
}

}
77 changes: 77 additions & 0 deletions src/EntryPoints/SpecialPURIResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare( strict_types = 1 );

namespace ProfessionalWiki\PersistentPageIdentifiers\EntryPoints;

use FormSpecialPage;
use ProfessionalWiki\PersistentPageIdentifiers\PersistentPageIdentifiersExtension;
use Status;
use Title;

class SpecialPURIResolver extends FormSpecialPage {

public function __construct() {
parent::__construct( 'PURIResolver' );
}

public function execute( $subPage ): void {
parent::execute( $subPage );

if ( !$subPage ) {
return;
}

$title = $this->getTitleFromPersistentId( $subPage );

if ( !$title ) {
return;
}

$this->getOutput()->redirect( $title->getFullURL() );
}

protected function getFormFields() {

Check failure on line 34 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::getFormFields() return type has no value type specified in iterable type array.

Check failure on line 34 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::getFormFields() return type has no value type specified in iterable type array.
return [
'puri' => [
'type' => 'text',
'label-message' => 'puriresolver-puri',
'required' => true,
]
];
}

public function onSubmit( array $data ) {

Check failure on line 44 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() has parameter $data with no value type specified in iterable type array.

Check failure on line 44 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() return type has no value type specified in iterable type array.

Check failure on line 44 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() has parameter $data with no value type specified in iterable type array.

Check failure on line 44 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() return type has no value type specified in iterable type array.
$title = $this->getTitleFromPersistentId( $data['puri'] );

if ( !$title ) {
// Message: puri-not-exists
return Status::newFatal( $this->getMessagePrefix() . '-not-exists' );
}

$this->getOutput()->redirect( $title->getFullURL() );

Check failure on line 52 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() should return array|bool|Status|string but return statement is missing.

Check failure on line 52 in src/EntryPoints/SpecialPURIResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan: MW REL1_39, PHP 8.2

Method ProfessionalWiki\PersistentPageIdentifiers\EntryPoints\SpecialPURIResolver::onSubmit() should return array|bool|Status|string but return statement is missing.
}

protected function getDisplayFormat() {
return 'ooui';
}

public function getGroupName(): string {
return 'redirects';
}

private function getTitleFromPersistentId( string $persistentId ): ?Title {
$pageId = $this->getPageIdFromPersistentId( $persistentId );

if ( $pageId ) {
return Title::newFromID( $pageId );
}

return null;
}

private function getPageIdFromPersistentId( string $persistentId ): ?int {
return PersistentPageIdentifiersExtension::getInstance()->getPageIdsRepo()->getPageIdFromPersistentId( $persistentId );
}

}
17 changes: 17 additions & 0 deletions tests/Adapters/PageIdsRepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ public function testReturnsPageIdsForPagesWithoutPersistentIdsUpToLimit(): void
);
}

public function testGetPageIdFromPersistentId(): void {
$page = $this->createPageWithText();

$persistentId = $this->db->newSelectQueryBuilder()
->select( 'ppi.persistent_id' )
->from( 'persistent_page_ids', 'ppi' )
->where( [ 'ppi.page_id' => $page->getId() ] )
->fetchField();

$this->assertIsString( $persistentId );
$this->assertSame( $page->getId(), $this->repo->getPageIdFromPersistentId( $persistentId ) );
}

public function testGetPageIdFromNonExistentPersistentId(): void {
$this->assertNull( $this->repo->getPageIdFromPersistentId( 'non-existent' ) );
}

}
Loading