3 * Special page to act as an endpoint for accessing raw page data.
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.
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.
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
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>.
28 * @ingroup SpecialPage
30 class SpecialPageData
extends SpecialPage
{
33 * @var PageDataRequestHandler|null
35 private $requestHandler = null;
37 public function __construct() {
38 parent
::__construct( 'PageData' );
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.
46 * If no request handler is set using this method, a default handler is created
47 * on demand by initDependencies().
49 * @param PageDataRequestHandler $requestHandler
51 public function setRequestHandler( PageDataRequestHandler
$requestHandler ) {
52 $this->requestHandler
= $requestHandler;
56 * Initialize any un-initialized members from global context.
57 * In particular, this initializes $this->requestHandler
59 protected function initDependencies() {
60 if ( $this->requestHandler
=== null ) {
61 $this->requestHandler
= $this->newDefaultRequestHandler();
66 * Creates a PageDataRequestHandler based on global defaults.
68 * @return PageDataRequestHandler
70 private function newDefaultRequestHandler() {
71 return new PageDataRequestHandler();
75 * @see SpecialWikibasePage::execute
77 * @param string|null $subPage
81 public function execute( $subPage ) {
82 $this->initDependencies();
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() ) ) {
91 $this->requestHandler
->handleRequest( $subPage, $this->getRequest(), $this->getOutput() );
95 * Shows an informative page to the user; Called when there is no page to output.
97 public function showForm() {
98 $this->getOutput()->showErrorPage( 'pagedata-title', 'pagedata-text' );
101 public function isListed() {
102 // Do not list this page in Special:SpecialPages