Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialPermanentLink
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 7
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getRedirect
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 showNoRedirectPage
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 showForm
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
2
 onFormSubmit
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 isListed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21namespace MediaWiki\Specials;
22
23use MediaWiki\HTMLForm\HTMLForm;
24use MediaWiki\SpecialPage\RedirectSpecialPage;
25use MediaWiki\Title\Title;
26
27/**
28 * Redirect from Special:PermanentLink/### to index.php?oldid=###.
29 *
30 * @ingroup SpecialPage
31 */
32class SpecialPermanentLink extends RedirectSpecialPage {
33    public function __construct() {
34        parent::__construct( 'PermanentLink' );
35        $this->mAllowedRedirectParams = [];
36    }
37
38    /**
39     * @param string|null $subpage
40     * @return Title|bool
41     */
42    public function getRedirect( $subpage ) {
43        $subpage = intval( $subpage );
44        if ( $subpage === 0 ) {
45            return false;
46        }
47        $this->mAddedRedirectParams['oldid'] = $subpage;
48
49        return true;
50    }
51
52    protected function showNoRedirectPage() {
53        $this->addHelpLink( 'Help:PermanentLink' );
54        $this->setHeaders();
55        $this->outputHeader();
56        $this->showForm();
57    }
58
59    private function showForm() {
60        HTMLForm::factory( 'ooui', [
61            'revid' => [
62                'type' => 'int',
63                'name' => 'revid',
64                'label-message' => 'permanentlink-revid',
65            ],
66        ], $this->getContext(), 'permanentlink' )
67            ->setSubmitTextMsg( 'permanentlink-submit' )
68            ->setSubmitCallback( [ $this, 'onFormSubmit' ] )
69            ->show();
70    }
71
72    public function onFormSubmit( $formData ) {
73        $revid = $formData['revid'];
74        $title = $this->getPageTitle( $revid ?: null );
75        $url = $title->getFullUrlForRedirect();
76        $this->getOutput()->redirect( $url );
77    }
78
79    public function isListed() {
80        return true;
81    }
82
83    protected function getGroupName() {
84        return 'redirects';
85    }
86}
87
88/**
89 * Retain the old class name for backwards compatibility.
90 * @deprecated since 1.41
91 */
92class_alias( SpecialPermanentLink::class, 'SpecialPermanentLink' );