rdbms: Avoid selectDB() call in LoadMonitor new connections
[mediawiki.git] / includes / specials / SpecialPageData.php
blobc52c426e8875dc0be059aa4747f80bd17fe34917
1 <?php
3 /**
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>.
8 * @license GPL-2.0+
9 */
10 class SpecialPageData extends SpecialPage {
12 /**
13 * @var PageDataRequestHandler|null
15 private $requestHandler = null;
17 public function __construct() {
18 parent::__construct( 'PageData' );
21 /**
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;
35 /**
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();
45 /**
46 * Creates a PageDataRequestHandler based on global defaults.
48 * @return PageDataRequestHandler
50 private function newDefaultRequestHandler() {
51 return new PageDataRequestHandler();
54 /**
55 * @see SpecialWikibasePage::execute
57 * @param string|null $subPage
59 * @throws HttpError
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() ) ) {
67 $this->showForm();
68 return;
71 $this->requestHandler->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
74 /**
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
83 return false;