Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / includes / specials / SpecialPageData.php
1 <?php
2 /**
3 * Special page to act as an endpoint for accessing raw page data.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * Special page to act as an endpoint for accessing raw page data.
25 * The web server should generally be configured to make this accessible via a canonical URL/URI,
26 * such as <http://my.domain.org/data/main/Foo>.
27 *
28 * @ingroup SpecialPage
29 */
30 class SpecialPageData extends SpecialPage {
31
32 /**
33 * @var PageDataRequestHandler|null
34 */
35 private $requestHandler = null;
36
37 public function __construct() {
38 parent::__construct( 'PageData' );
39 }
40
41 /**
42 * Sets the request handler to be used by the special page.
43 * May be used when a particular instance of PageDataRequestHandler is already
44 * known, e.g. during testing.
45 *
46 * If no request handler is set using this method, a default handler is created
47 * on demand by initDependencies().
48 *
49 * @param PageDataRequestHandler $requestHandler
50 */
51 public function setRequestHandler( PageDataRequestHandler $requestHandler ) {
52 $this->requestHandler = $requestHandler;
53 }
54
55 /**
56 * Initialize any un-initialized members from global context.
57 * In particular, this initializes $this->requestHandler
58 */
59 protected function initDependencies() {
60 if ( $this->requestHandler === null ) {
61 $this->requestHandler = $this->newDefaultRequestHandler();
62 }
63 }
64
65 /**
66 * Creates a PageDataRequestHandler based on global defaults.
67 *
68 * @return PageDataRequestHandler
69 */
70 private function newDefaultRequestHandler() {
71 return new PageDataRequestHandler();
72 }
73
74 /**
75 * @see SpecialWikibasePage::execute
76 *
77 * @param string|null $subPage
78 *
79 * @throws HttpError
80 */
81 public function execute( $subPage ) {
82 $this->initDependencies();
83
84 // If there is no title, show an HTML form
85 // TODO: Don't do this if HTML is not acceptable according to HTTP headers.
86 if ( !$this->requestHandler->canHandleRequest( $subPage, $this->getRequest() ) ) {
87 $this->showForm();
88 return;
89 }
90
91 $this->requestHandler->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
92 }
93
94 /**
95 * Shows an informative page to the user; Called when there is no page to output.
96 */
97 public function showForm() {
98 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
99 }
100
101 public function isListed() {
102 // Do not list this page in Special:SpecialPages
103 return false;
104 }
105
106 }