3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 use MediaWiki\Message\Message
;
22 use MediaWiki\Title\MalformedTitleException
;
25 * Show an error page on a badtitle.
27 * We always emit a HTTP 404 error code since pages with an invalid title will
28 * never have any content. In the past this emitted a 400 error code to ensure
29 * caching proxies and mobile browsers don't cache it as valid content (T35646),
30 * but that had the disadvantage of telling caches in front of MediaWiki
31 * (Varnish, etc.), not to cache it either.
37 class BadTitleError
extends ErrorPageError
{
41 * @param string|Message|MalformedTitleException $msg A message key (default: 'badtitletext'), or
42 * a MalformedTitleException to figure out things from
43 * @param array $params Parameter to wfMessage()
45 public function __construct( $msg = 'badtitletext', $params = [] ) {
46 if ( $msg instanceof MalformedTitleException
) {
47 $errorMessage = $msg->getErrorMessage();
48 if ( !$errorMessage ) {
49 parent
::__construct( 'badtitle', 'badtitletext', [] );
51 $errorMessageParams = $msg->getErrorMessageParameters();
52 parent
::__construct( 'badtitle', $errorMessage, $errorMessageParams );
55 parent
::__construct( 'badtitle', $msg, $params );
62 public function report( $action = self
::SEND_OUTPUT
) {
65 $wgOut->setStatusCode( 404 );
67 parent
::report( self
::STAGE_OUTPUT
);
69 // Unconditionally cache the error for an hour, see T316932
70 $wgOut->enableClientCache();
71 $wgOut->setCdnMaxage( 3600 );
73 if ( $action === self
::SEND_OUTPUT
) {