Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| SpecialRedirectWithAction | |
0.00% |
0 / 32 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getRedirect | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| showNoRedirectPage | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| showForm | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| onFormSubmit | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| isListed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| prefixSearchSubpages | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @license GPL-2.0-or-later |
| 5 | * @author DannyS712 |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\SpecialPage; |
| 9 | |
| 10 | use MediaWiki\HTMLForm\HTMLForm; |
| 11 | use MediaWiki\Search\SearchEngineFactory; |
| 12 | use MediaWiki\Title\Title; |
| 13 | |
| 14 | /** |
| 15 | * Abstract to simplify creation of redirect special pages |
| 16 | * |
| 17 | * @stable to extend |
| 18 | * @ingroup SpecialPage |
| 19 | */ |
| 20 | abstract class SpecialRedirectWithAction extends RedirectSpecialPage { |
| 21 | /** @var string */ |
| 22 | protected $action; |
| 23 | |
| 24 | /** @var string */ |
| 25 | protected $msgPrefix; |
| 26 | |
| 27 | /** @var SearchEngineFactory */ |
| 28 | private $searchEngineFactory; |
| 29 | |
| 30 | /** |
| 31 | * @stable to call |
| 32 | * @since 1.39 SearchEngineFactory added |
| 33 | * |
| 34 | * @param string $name |
| 35 | * @param string $action |
| 36 | * @param string $msgPrefix |
| 37 | * @param SearchEngineFactory $searchEngineFactory |
| 38 | */ |
| 39 | public function __construct( |
| 40 | $name, |
| 41 | $action, |
| 42 | $msgPrefix, |
| 43 | SearchEngineFactory $searchEngineFactory |
| 44 | ) { |
| 45 | parent::__construct( $name ); |
| 46 | $this->action = $action; |
| 47 | $this->msgPrefix = $msgPrefix; |
| 48 | $this->searchEngineFactory = $searchEngineFactory; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @inheritDoc |
| 53 | */ |
| 54 | public function getRedirect( $subpage ) { |
| 55 | if ( $subpage === null || $subpage === '' ) { |
| 56 | return false; |
| 57 | } |
| 58 | $this->mAddedRedirectParams['title'] = $subpage; |
| 59 | $this->mAddedRedirectParams['action'] = $this->action; |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @stable to override |
| 65 | */ |
| 66 | protected function showNoRedirectPage() { |
| 67 | $this->setHeaders(); |
| 68 | $this->outputHeader(); |
| 69 | $this->showForm(); |
| 70 | } |
| 71 | |
| 72 | private function showForm() { |
| 73 | // Dynamic messages used: |
| 74 | // 'special' . $this->msgPrefix . '-page' |
| 75 | // 'special' . $this->msgPrefix . '-submit' |
| 76 | // Each special page that extends this should include those as comments for grep |
| 77 | $form = HTMLForm::factory( 'ooui', [ |
| 78 | 'page' => [ |
| 79 | 'type' => 'title', |
| 80 | 'name' => 'page', |
| 81 | 'label-message' => 'special' . $this->msgPrefix . '-page', |
| 82 | 'required' => true, |
| 83 | 'creatable' => true, |
| 84 | ], |
| 85 | ], $this->getContext(), $this->msgPrefix ); |
| 86 | $form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' ); |
| 87 | $form->setSubmitCallback( $this->onFormSubmit( ... ) ); |
| 88 | $form->show(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @stable to override |
| 93 | * |
| 94 | * @param array $formData |
| 95 | */ |
| 96 | public function onFormSubmit( $formData ) { |
| 97 | $title = $formData['page']; |
| 98 | $page = Title::newFromText( $title ); |
| 99 | $query = [ 'action' => $this->action ]; |
| 100 | $url = $page->getFullUrlForRedirect( $query ); |
| 101 | $this->getOutput()->redirect( $url ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @stable to override |
| 106 | * @return bool |
| 107 | */ |
| 108 | public function isListed() { |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Return an array of subpages beginning with $search that this special page will accept. |
| 114 | * |
| 115 | * @param string $search Prefix to search for |
| 116 | * @param int $limit Maximum number of results to return (usually 10) |
| 117 | * @param int $offset Number of results to skip (usually 0) |
| 118 | * @return string[] Matching subpages |
| 119 | */ |
| 120 | public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 121 | return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory ); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @stable to override |
| 126 | * @return string |
| 127 | */ |
| 128 | protected function getGroupName() { |
| 129 | return 'redirects'; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** @deprecated class alias since 1.41 */ |
| 134 | class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' ); |