Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| SpecialNewSection | |
0.00% |
0 / 34 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getRedirect | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| showNoRedirectPage | |
0.00% |
0 / 4 |
|
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 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\HTMLForm\HTMLForm; |
| 10 | use MediaWiki\Search\SearchEngineFactory; |
| 11 | use MediaWiki\SpecialPage\RedirectSpecialPage; |
| 12 | use MediaWiki\Title\Title; |
| 13 | |
| 14 | /** |
| 15 | * Redirect from Special:NewSection/$1 to index.php?title=$1&action=edit§ion=new. |
| 16 | * |
| 17 | * @ingroup SpecialPage |
| 18 | * @author DannyS712 |
| 19 | */ |
| 20 | class SpecialNewSection extends RedirectSpecialPage { |
| 21 | |
| 22 | private SearchEngineFactory $searchEngineFactory; |
| 23 | |
| 24 | public function __construct( |
| 25 | SearchEngineFactory $searchEngineFactory |
| 26 | ) { |
| 27 | parent::__construct( 'NewSection' ); |
| 28 | $this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro', |
| 29 | 'preload', 'preloadparams', 'summary' ]; |
| 30 | $this->searchEngineFactory = $searchEngineFactory; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @inheritDoc |
| 35 | */ |
| 36 | public function getRedirect( $subpage ) { |
| 37 | if ( $subpage === null || $subpage === '' ) { |
| 38 | return false; |
| 39 | } |
| 40 | $this->mAddedRedirectParams['title'] = $subpage; |
| 41 | $this->mAddedRedirectParams['action'] = 'edit'; |
| 42 | $this->mAddedRedirectParams['section'] = 'new'; |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | protected function showNoRedirectPage() { |
| 47 | $this->setHeaders(); |
| 48 | $this->outputHeader(); |
| 49 | $this->addHelpLink( 'Help:New section' ); |
| 50 | $this->showForm(); |
| 51 | } |
| 52 | |
| 53 | private function showForm() { |
| 54 | $form = HTMLForm::factory( 'ooui', [ |
| 55 | 'page' => [ |
| 56 | 'type' => 'title', |
| 57 | 'name' => 'page', |
| 58 | 'label-message' => 'newsection-page', |
| 59 | 'required' => true, |
| 60 | 'creatable' => true, |
| 61 | ], |
| 62 | ], $this->getContext(), 'newsection' ); |
| 63 | $form->setSubmitTextMsg( 'newsection-submit' ); |
| 64 | $form->setSubmitCallback( $this->onFormSubmit( ... ) ); |
| 65 | $form->show(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param array $formData |
| 70 | */ |
| 71 | private function onFormSubmit( $formData ) { |
| 72 | $title = $formData['page']; |
| 73 | $page = Title::newFromTextThrow( $title ); |
| 74 | $query = [ 'action' => 'edit', 'section' => 'new' ]; |
| 75 | $url = $page->getFullUrlForRedirect( $query ); |
| 76 | $this->getOutput()->redirect( $url ); |
| 77 | } |
| 78 | |
| 79 | /** @inheritDoc */ |
| 80 | public function isListed() { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Return an array of subpages beginning with $search that this special page will accept. |
| 86 | * |
| 87 | * @param string $search Prefix to search for |
| 88 | * @param int $limit Maximum number of results to return (usually 10) |
| 89 | * @param int $offset Number of results to skip (usually 0) |
| 90 | * @return string[] Matching subpages |
| 91 | */ |
| 92 | public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 93 | return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory ); |
| 94 | } |
| 95 | |
| 96 | /** @inheritDoc */ |
| 97 | protected function getGroupName() { |
| 98 | return 'redirects'; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Retain the old class name for backwards compatibility. |
| 104 | * @deprecated since 1.41 |
| 105 | */ |
| 106 | class_alias( SpecialNewSection::class, 'SpecialNewSection' ); |