4 * Special page to act as an endpoint for accessing raw page data.
5 * The web server should generally be configured to make this accessible via a canonical URL/URI,
6 * such as <http://my.domain.org/data/main/Foo>.
10 class SpecialPageData
extends SpecialPage
{
13 * @var PageDataRequestHandler|null
15 private $requestHandler = null;
17 public function __construct() {
18 parent
::__construct( 'PageData' );
22 * Sets the request handler to be used by the special page.
23 * May be used when a particular instance of PageDataRequestHandler is already
24 * known, e.g. during testing.
26 * If no request handler is set using this method, a default handler is created
27 * on demand by initDependencies().
29 * @param PageDataRequestHandler $requestHandler
31 public function setRequestHandler( PageDataRequestHandler
$requestHandler ) {
32 $this->requestHandler
= $requestHandler;
36 * Initialize any un-initialized members from global context.
37 * In particular, this initializes $this->requestHandler
39 protected function initDependencies() {
40 if ( $this->requestHandler
=== null ) {
41 $this->requestHandler
= $this->newDefaultRequestHandler();
46 * Creates a PageDataRequestHandler based on global defaults.
48 * @return PageDataRequestHandler
50 private function newDefaultRequestHandler() {
51 return new PageDataRequestHandler();
55 * @see SpecialWikibasePage::execute
57 * @param string|null $subPage
61 public function execute( $subPage ) {
62 $this->initDependencies();
64 // If there is no title, show an HTML form
65 // TODO: Don't do this if HTML is not acceptable according to HTTP headers.
66 if ( !$this->requestHandler
->canHandleRequest( $subPage, $this->getRequest() ) ) {
71 $this->requestHandler
->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
75 * Shows an informative page to the user; Called when there is no page to output.
77 public function showForm() {
78 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
81 public function isListed() {
82 // Do not list this page in Special:SpecialPages