MediaWiki master
SpecialPageData.php
Go to the documentation of this file.
1<?php
6
7namespace MediaWiki\Specials;
8
9use MediaWiki\Exception\HttpError;
10use MediaWiki\LinkedData\PageDataRequestHandler;
11use MediaWiki\SpecialPage\UnlistedSpecialPage;
12
22
26 private $requestHandler = null;
27
28 public function __construct() {
29 parent::__construct( 'PageData' );
30 }
31
40 public function setRequestHandler( PageDataRequestHandler $requestHandler ) {
41 $this->requestHandler = $requestHandler;
42 }
43
48 protected function initDependencies() {
49 $this->requestHandler ??= $this->newDefaultRequestHandler();
50 }
51
57 private function newDefaultRequestHandler() {
58 return new PageDataRequestHandler();
59 }
60
68 public function execute( $subPage ) {
69 $this->initDependencies();
70
71 // If there is no title, show an HTML form
72 // TODO: Don't do this if HTML is not acceptable according to HTTP headers.
73 if ( !$this->requestHandler->canHandleRequest( $subPage, $this->getRequest() ) ) {
74 $this->showForm();
75 return;
76 }
77
78 $this->requestHandler->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
79 }
80
84 public function showForm() {
85 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
86 }
87}
88
89// @codeCoverageIgnoreStart
94class_alias( SpecialPageData::class, 'SpecialPageData' );
95// @codeCoverageIgnoreEnd
Request handler implementing a data interface for mediawiki pages.
getRequest()
Get the WebRequest being used for this instance.
getOutput()
Get the OutputPage being used for this instance.
Shortcut to construct a special page which is unlisted by default.
Special page to act as an endpoint for accessing raw page data.
initDependencies()
Initialize any un-initialized members from global context.
setRequestHandler(PageDataRequestHandler $requestHandler)
Sets the request handler to be used by the special page.
showForm()
Shows an informative page to the user; Called when there is no page to output.