Merge "mw.Feedback: If the message is posted remotely, link the title correctly"
[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 * @class
29 * @ingroup SpecialPage
30 */
31 class SpecialPageData extends SpecialPage {
32
33 /**
34 * @var PageDataRequestHandler|null
35 */
36 private $requestHandler = null;
37
38 public function __construct() {
39 parent::__construct( 'PageData' );
40 }
41
42 /**
43 * Sets the request handler to be used by the special page.
44 * May be used when a particular instance of PageDataRequestHandler is already
45 * known, e.g. during testing.
46 *
47 * If no request handler is set using this method, a default handler is created
48 * on demand by initDependencies().
49 *
50 * @param PageDataRequestHandler $requestHandler
51 */
52 public function setRequestHandler( PageDataRequestHandler $requestHandler ) {
53 $this->requestHandler = $requestHandler;
54 }
55
56 /**
57 * Initialize any un-initialized members from global context.
58 * In particular, this initializes $this->requestHandler
59 */
60 protected function initDependencies() {
61 if ( $this->requestHandler === null ) {
62 $this->requestHandler = $this->newDefaultRequestHandler();
63 }
64 }
65
66 /**
67 * Creates a PageDataRequestHandler based on global defaults.
68 *
69 * @return PageDataRequestHandler
70 */
71 private function newDefaultRequestHandler() {
72 return new PageDataRequestHandler();
73 }
74
75 /**
76 * @see SpecialWikibasePage::execute
77 *
78 * @param string|null $subPage
79 *
80 * @throws HttpError
81 */
82 public function execute( $subPage ) {
83 $this->initDependencies();
84
85 // If there is no title, show an HTML form
86 // TODO: Don't do this if HTML is not acceptable according to HTTP headers.
87 if ( !$this->requestHandler->canHandleRequest( $subPage, $this->getRequest() ) ) {
88 $this->showForm();
89 return;
90 }
91
92 $this->requestHandler->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
93 }
94
95 /**
96 * Shows an informative page to the user; Called when there is no page to output.
97 */
98 public function showForm() {
99 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
100 }
101
102 public function isListed() {
103 // Do not list this page in Special:SpecialPages
104 return false;
105 }
106
107 }