Merge "Special:Newpages feed now shows first revision instead of latest revision"
[lhc/web/wiklou.git] / includes / specials / SpecialPageData.php
1 <?php
2
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>.
7 *
8 * @license GPL-2.0+
9 */
10 class SpecialPageData extends SpecialPage {
11
12 /**
13 * @var PageDataRequestHandler|null
14 */
15 private $requestHandler = null;
16
17 public function __construct() {
18 parent::__construct( 'PageData' );
19 }
20
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.
25 *
26 * If no request handler is set using this method, a default handler is created
27 * on demand by initDependencies().
28 *
29 * @param PageDataRequestHandler $requestHandler
30 */
31 public function setRequestHandler( PageDataRequestHandler $requestHandler ) {
32 $this->requestHandler = $requestHandler;
33 }
34
35 /**
36 * Initialize any un-initialized members from global context.
37 * In particular, this initializes $this->requestHandler
38 */
39 protected function initDependencies() {
40 if ( $this->requestHandler === null ) {
41 $this->requestHandler = $this->newDefaultRequestHandler();
42 }
43 }
44
45 /**
46 * Creates a PageDataRequestHandler based on global defaults.
47 *
48 * @return PageDataRequestHandler
49 */
50 private function newDefaultRequestHandler() {
51 return new PageDataRequestHandler();
52 }
53
54 /**
55 * @see SpecialWikibasePage::execute
56 *
57 * @param string|null $subPage
58 *
59 * @throws HttpError
60 */
61 public function execute( $subPage ) {
62 $this->initDependencies();
63
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;
69 }
70
71 $this->requestHandler->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
72 }
73
74 /**
75 * Shows an informative page to the user; Called when there is no page to output.
76 */
77 public function showForm() {
78 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
79 }
80
81 public function isListed() {
82 // Do not list this page in Special:SpecialPages
83 return false;
84 }
85
86 }