| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\SpecialPage; |
| 4 |
|
| 5 |
use MediaWiki\HTMLForm\HTMLForm; |
| 6 |
use MediaWiki\MediaWikiServices; |
| 7 |
use MediaWiki\Status\Status; |
| 8 |
use MediaWiki\Title\MalformedTitleException; |
| 9 |
use MediaWiki\Title\Title; |
| 10 |
use SearchEngineFactory; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
abstract class SpecialRedirectWithAction extends RedirectSpecialPage { |
| 37 |
|
| 38 |
protected $action; |
| 39 |
|
| 40 |
|
| 41 |
protected $msgPrefix; |
| 42 |
|
| 43 |
|
| 44 |
private $searchEngineFactory; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function __construct( |
| 56 |
$name, |
| 57 |
$action, |
| 58 |
$msgPrefix, |
| 59 |
?SearchEngineFactory $searchEngineFactory = null |
| 60 |
) { |
| 61 |
parent::__construct( $name ); |
| 62 |
$this->action = $action; |
| 63 |
$this->msgPrefix = $msgPrefix; |
| 64 |
if ( !$searchEngineFactory ) { |
| 65 |
|
| 66 |
wfDeprecated( __METHOD__ . ' without providing SearchEngineFactory', '1.39' ); |
| 67 |
$searchEngineFactory = MediaWikiServices::getInstance()->getSearchEngineFactory(); |
| 68 |
} |
| 69 |
$this->searchEngineFactory = $searchEngineFactory; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public function getRedirect( $subpage ) { |
| 76 |
if ( $subpage === null || $subpage === '' ) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
$this->mAddedRedirectParams['title'] = $subpage; |
| 80 |
$this->mAddedRedirectParams['action'] = $this->action; |
| 81 |
return true; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
protected function showNoRedirectPage() { |
| 88 |
$this->setHeaders(); |
| 89 |
$this->outputHeader(); |
| 90 |
$this->showForm(); |
| 91 |
} |
| 92 |
|
| 93 |
private function showForm() { |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
$form = HTMLForm::factory( 'ooui', [ |
| 99 |
'page' => [ |
| 100 |
'type' => 'text', |
| 101 |
'name' => 'page', |
| 102 |
'label-message' => 'special' . $this->msgPrefix . '-page', |
| 103 |
'required' => true, |
| 104 |
], |
| 105 |
], $this->getContext(), $this->msgPrefix ); |
| 106 |
$form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' ); |
| 107 |
$form->setSubmitCallback( [ $this, 'onFormSubmit' ] ); |
| 108 |
$form->show(); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public function onFormSubmit( $formData ) { |
| 119 |
$title = $formData['page']; |
| 120 |
try { |
| 121 |
$page = Title::newFromTextThrow( $title ); |
| 122 |
} catch ( MalformedTitleException $e ) { |
| 123 |
return Status::newFatal( $e->getMessageObject() ); |
| 124 |
} |
| 125 |
$query = [ 'action' => $this->action ]; |
| 126 |
$url = $page->getFullUrlForRedirect( $query ); |
| 127 |
$this->getOutput()->redirect( $url ); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function isListed() { |
| 135 |
return true; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 147 |
return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory ); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
protected function getGroupName() { |
| 155 |
return 'redirects'; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' ); |