Skip to content

Commit c81ceab

Browse files
JeroenDeDauwclaude
authored andcommitted
Add a View RDF link to the page-tools sidebar
The per-page RDF export (GET /rest.php/neowiki/v0/page/{pageId}/rdf) was only reachable by hand-constructing the URL. Add a "View RDF" link to the NeoWiki page-tools sidebar section, next to "View JSON", pointing at the current page's Turtle export. It is shown only when the page has Subjects, so it never points at the endpoint's 404-on-empty response. It uses ?format=turtle so the result renders as readable text in the browser instead of downloading a TriG file, and targets the native projection. Per-ontology projection links and a per-subject RDF endpoint (#1087) are out of scope here. Relates to #1023 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cdba2dd commit c81ceab

5 files changed

Lines changed: 61 additions & 4 deletions

File tree

i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"neowiki-page-tools-view-subjects": "View subjects",
4343
"neowiki-page-tools-edit-json": "View or edit JSON",
4444
"neowiki-page-tools-view-json": "View JSON",
45+
"neowiki-page-tools-rdf": "View RDF",
4546

4647
"neowiki-property-editor-name": "Name",
4748
"neowiki-property-editor-type": "Type",

i18n/qqq.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"neowiki-page-tools-view-subjects": "Read-only counterpart of neowiki-page-tools-manage-subjects: label for the sidebar link to the Subject management page, shown to users who lack edit permission.",
4444
"neowiki-page-tools-edit-json": "Label for the sidebar link that navigates to Special:NeoJson for the current page. Only visible when development UIs are enabled.",
4545
"neowiki-page-tools-view-json": "Read-only counterpart of neowiki-page-tools-edit-json: label for the sidebar link to Special:NeoJson, shown to users who lack edit permission. Only visible when development UIs are enabled.",
46+
"neowiki-page-tools-rdf": "Label for the sidebar link that opens the current page's RDF export (Turtle serialization of the page's Subjects), served by the per-page RDF REST endpoint. Only shown when the page has NeoWiki Subjects.",
4647

4748
"neowiki-subject-creator-creating-schema": "Subtitle shown in the subject creator dialog header when the user is creating a new schema.",
4849
"neowiki-subject-creator-create-schema": "Label for the button that creates a new schema in the subject creator dialog.",

src/EntryPoints/NeoWikiHooks.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,16 @@ public static function onSidebarBeforeOutput( Skin $skin, array &$sidebar ): voi
300300
$hints = $extension->newSubjectPermissionHints( $skin->getAuthority() );
301301
$pageId = new PageId( $title->getArticleID() );
302302

303+
$isContentNamespace = MediaWikiServices::getInstance()
304+
->getNamespaceInfo()
305+
->isContent( $title->getNamespace() );
306+
303307
$neoWikiTools = ( new PageToolsBuilder() )->build(
304308
title: $title,
305-
isContentNamespace: MediaWikiServices::getInstance()
306-
->getNamespaceInfo()
307-
->isContent( $title->getNamespace() ),
309+
pageId: $title->getArticleID(),
310+
isContentNamespace: $isContentNamespace,
311+
hasSubjects: $isContentNamespace
312+
&& $extension->newPageSubjectsLookup()->pageHasSubjects( $pageId ),
308313
canCreateMainSubject: $hints->canCreateMainSubject( $pageId ),
309314
canEditSubject: $hints->canEditSubject( $pageId ),
310315
isLatestRevision: self::pageIsLatestRevision( $skin->getOutput() ),

src/Presentation/PageToolsBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class PageToolsBuilder {
1515
*/
1616
public function build(
1717
Title $title,
18+
int $pageId,
1819
bool $isContentNamespace,
20+
bool $hasSubjects,
1921
bool $canCreateMainSubject,
2022
bool $canEditSubject,
2123
bool $isLatestRevision,
@@ -49,6 +51,15 @@ public function build(
4951
];
5052
}
5153

54+
if ( $hasSubjects ) {
55+
$items[] = [
56+
'text' => wfMessage( 'neowiki-page-tools-rdf' )->text(),
57+
'href' => wfScript( 'rest' ) . '/neowiki/v0/page/'
58+
. $pageId . '/rdf?format=turtle',
59+
'id' => 't-neowiki-rdf',
60+
];
61+
}
62+
5263
if ( $devUiEnabled ) {
5364
$items[] = [
5465
'text' => wfMessage(

tests/phpunit/Presentation/PageToolsBuilderTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class PageToolsBuilderTest extends MediaWikiIntegrationTestCase {
1616

1717
private const PAGE_NAME = 'PageToolsBuilderTestPage';
18+
private const PAGE_ID = 42;
1819

1920
public function testReturnsNoItemsOutsideContentNamespace(): void {
2021
$this->assertSame(
@@ -28,9 +29,32 @@ public function testShowsAllItemsWhenEverythingOpenAndDevUiEnabled(): void {
2829
[
2930
$this->createSubjectItem(),
3031
$this->manageSubjectsItem(),
32+
$this->rdfItem(),
3133
$this->editJsonItem(),
3234
],
33-
$this->build()
35+
$this->build( hasSubjects: true )
36+
);
37+
}
38+
39+
public function testShowsRdfLinkWhenPageHasSubjects(): void {
40+
$this->assertSame(
41+
[ $this->manageSubjectsItem(), $this->rdfItem() ],
42+
$this->build(
43+
hasSubjects: true,
44+
canCreateMainSubject: false,
45+
devUiEnabled: false
46+
)
47+
);
48+
}
49+
50+
public function testHidesRdfLinkWhenPageHasNoSubjects(): void {
51+
$this->assertSame(
52+
[ $this->manageSubjectsItem() ],
53+
$this->build(
54+
hasSubjects: false,
55+
canCreateMainSubject: false,
56+
devUiEnabled: false
57+
)
3458
);
3559
}
3660

@@ -101,6 +125,7 @@ public function testUsesViewLabelsWhenUserCannotEditSubjects(): void {
101125
*/
102126
private function build(
103127
bool $isContentNamespace = true,
128+
bool $hasSubjects = false,
104129
bool $canCreateMainSubject = true,
105130
bool $canEditSubject = true,
106131
bool $isLatestRevision = true,
@@ -109,7 +134,9 @@ private function build(
109134
): array {
110135
return ( new PageToolsBuilder() )->build(
111136
title: Title::newFromText( self::PAGE_NAME ),
137+
pageId: self::PAGE_ID,
112138
isContentNamespace: $isContentNamespace,
139+
hasSubjects: $hasSubjects,
113140
canCreateMainSubject: $canCreateMainSubject,
114141
canEditSubject: $canEditSubject,
115142
isLatestRevision: $isLatestRevision,
@@ -143,6 +170,18 @@ private function manageSubjectsItem( string $messageKey = 'neowiki-page-tools-ma
143170
];
144171
}
145172

173+
/**
174+
* @return array<string, mixed>
175+
*/
176+
private function rdfItem(): array {
177+
return [
178+
'text' => wfMessage( 'neowiki-page-tools-rdf' )->text(),
179+
'href' => wfScript( 'rest' ) . '/neowiki/v0/page/'
180+
. self::PAGE_ID . '/rdf?format=turtle',
181+
'id' => 't-neowiki-rdf',
182+
];
183+
}
184+
146185
/**
147186
* @return array<string, mixed>
148187
*/

0 commit comments

Comments
 (0)