| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\HTMLForm\HTMLForm; |
| 24 |
use MediaWiki\SpecialPage\RedirectSpecialPage; |
| 25 |
use MediaWiki\Title\Title; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class SpecialPermanentLink extends RedirectSpecialPage { |
| 33 |
public function __construct() { |
| 34 |
parent::__construct( 'PermanentLink' ); |
| 35 |
$this->mAllowedRedirectParams = []; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
|
| 90 |
|
| 91 |
|
| 92 |
class_alias( SpecialPermanentLink::class, 'SpecialPermanentLink' ); |