-
Notifications
You must be signed in to change notification settings - Fork 5
Document internal surfaces and the PHP Cypher query path #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare( strict_types = 1 ); | ||
|
|
||
| namespace ProfessionalWiki\RedHerb\Specials; | ||
|
|
||
| use Exception; | ||
| use MediaWiki\Message\Message; | ||
| use MediaWiki\SpecialPage\SpecialPage; | ||
| use ProfessionalWiki\NeoWiki\GraphDatabasePlugins\Neo4j\Application\Neo4jQueryLimits; | ||
| use ProfessionalWiki\NeoWiki\GraphDatabasePlugins\Neo4j\Application\Neo4jQueryRequest; | ||
| use ProfessionalWiki\NeoWiki\NeoWikiExtension; | ||
|
|
||
| class SpecialRedHerbContentPageCount extends SpecialPage { | ||
|
|
||
| public function __construct() { | ||
| parent::__construct( 'RedHerbContentPageCount' ); | ||
| } | ||
|
|
||
| /** | ||
| * @param ?string $subPage | ||
| */ | ||
| public function execute( $subPage ): void { | ||
| parent::execute( $subPage ); | ||
|
|
||
| $out = $this->getOutput(); | ||
|
|
||
| try { | ||
| $result = NeoWikiExtension::getInstance()->newCypherQueryService()->execute( new Neo4jQueryRequest( | ||
| cypher: 'MATCH (page:Page) WHERE page.namespaceId = $namespaceId RETURN count(page) AS pageCount', | ||
| parameters: [ 'namespaceId' => NS_MAIN ], | ||
| limits: Neo4jQueryLimits::forUser( $this->getUser() ), | ||
| ) ); | ||
| } catch ( Exception $e ) { | ||
| $out->addWikiMsg( 'redherb-content-page-count-error', $e->getMessage() ); | ||
| return; | ||
| } | ||
|
|
||
| $out->addWikiMsg( 'redherb-content-page-count', $result->rows[0]['pageCount'] ); | ||
| } | ||
|
|
||
| public function getDescription(): Message { | ||
| return $this->msg( 'redherb-special-content-page-count' ); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| declare( strict_types = 1 ); | ||
|
|
||
| namespace ProfessionalWiki\NeoWiki\Tests\RedHerb; | ||
|
|
||
| use MediaWiki\Context\DerivativeContext; | ||
| use MediaWiki\Context\RequestContext; | ||
| use MediaWiki\Output\OutputPage; | ||
| use MediaWiki\Title\Title; | ||
| use ProfessionalWiki\NeoWiki\Tests\Data\TestSubject; | ||
| use ProfessionalWiki\NeoWiki\Tests\NeoWikiIntegrationTestCase; | ||
| use ProfessionalWiki\RedHerb\Specials\SpecialRedHerbContentPageCount; | ||
|
|
||
| /** | ||
| * @covers \ProfessionalWiki\RedHerb\Specials\SpecialRedHerbContentPageCount | ||
| * @group Database | ||
| */ | ||
| class SpecialRedHerbContentPageCountTest extends NeoWikiIntegrationTestCase { | ||
|
|
||
| protected function setUp(): void { | ||
| parent::setUp(); | ||
| $this->setUpNeo4j(); | ||
| $this->createSchema( TestSubject::DEFAULT_SCHEMA_ID ); | ||
| $this->markPageTableAsUsed(); | ||
| } | ||
|
|
||
| public function testCountsOnlyContentNamespacePagesTrackedInTheGraph(): void { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error branch at The helper already exists: wrapping Minor, since RedHerb is example code — but this PR's stated purpose is keeping the documented call shape working, and |
||
| $this->createPageWithSubjects( 'RedHerb content page one', TestSubject::build( id: 'sRedHerbCP11111' ) ); | ||
| $this->createPageWithSubjects( 'RedHerb content page two', TestSubject::build( id: 'sRedHerbCP22222' ) ); | ||
| $this->createPageWithSubjects( 'Help:RedHerb help page', TestSubject::build( id: 'sRedHerbHP33333' ) ); | ||
|
|
||
| $this->assertStringContainsString( | ||
| 'Content namespace pages tracked in the graph: 2', | ||
| $this->executeContentPageCount() | ||
| ); | ||
| } | ||
|
|
||
| public function testErrorOutputIncludesUnderlyingCauseWhenGraphBackendMissing(): void { | ||
| $html = $this->runWithoutGraphBackend( | ||
| fn() => $this->executeContentPageCount() | ||
| ); | ||
|
|
||
| $this->assertStringContainsString( 'A configured Neo4j backend is required', $html ); | ||
| } | ||
|
|
||
| private function executeContentPageCount(): string { | ||
| $context = new DerivativeContext( RequestContext::getMain() ); | ||
| $context->setTitle( Title::makeTitle( NS_SPECIAL, 'RedHerbContentPageCount' ) ); | ||
| $output = new OutputPage( $context ); | ||
| $context->setOutput( $output ); | ||
|
|
||
| $page = new SpecialRedHerbContentPageCount(); | ||
| $page->setContext( $context ); | ||
| $page->execute( null ); | ||
|
|
||
| return $output->getHTML(); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forbids exactly what the repo's own copy-me example does.
tests/RedHerb/resources/editMainSubject/init.js:11:and
:34/:38:That is "select these elements" and "read Subject IDs out of them" — both named in this sentence.
It isn't a distant contradiction. Lines 16-17 say "the fastest start is to copy the relevant RedHerb file and adapt it"; line 352 links
resources/editMainSubject/; this section's own escape-hatch bullet routes readers to "Mounting standalone Vue features", where that example is listed.tests/RedHerb/README.md:37links it too. And line 15 sells RedHerb as test-backed so "its examples stay working", which gives a reader no signal that this one is the forbidden pattern.editMainSubjectis the only RedHerb example doing this —createChildandsubjectFinderare clean. Either carve it out by name here, or rework that example onto a supported path.