| 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 |
use SearchEngineFactory; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class SpecialNewSection extends RedirectSpecialPage { |
| 35 |
|
| 36 |
private SearchEngineFactory $searchEngineFactory; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public function __construct( |
| 42 |
SearchEngineFactory $searchEngineFactory |
| 43 |
) { |
| 44 |
parent::__construct( 'NewSection' ); |
| 45 |
$this->mAllowedRedirectParams = [ 'preloadtitle', 'nosummary', 'editintro', |
| 46 |
'preload', 'preloadparams', 'summary' ]; |
| 47 |
$this->searchEngineFactory = $searchEngineFactory; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function getRedirect( $subpage ) { |
| 54 |
if ( $subpage === null || $subpage === '' ) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
$this->mAddedRedirectParams['title'] = $subpage; |
| 58 |
$this->mAddedRedirectParams['action'] = 'edit'; |
| 59 |
$this->mAddedRedirectParams['section'] = 'new'; |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
protected function showNoRedirectPage() { |
| 64 |
$this->setHeaders(); |
| 65 |
$this->outputHeader(); |
| 66 |
$this->addHelpLink( 'Help:New section' ); |
| 67 |
$this->showForm(); |
| 68 |
} |
| 69 |
|
| 70 |
private function showForm() { |
| 71 |
$form = HTMLForm::factory( 'ooui', [ |
| 72 |
'page' => [ |
| 73 |
'type' => 'title', |
| 74 |
'name' => 'page', |
| 75 |
'label-message' => 'newsection-page', |
| 76 |
'required' => true, |
| 77 |
'creatable' => true, |
| 78 |
], |
| 79 |
], $this->getContext(), 'newsection' ); |
| 80 |
$form->setSubmitTextMsg( 'newsection-submit' ); |
| 81 |
$form->setSubmitCallback( [ $this, 'onFormSubmit' ] ); |
| 82 |
$form->show(); |
| 83 |
} |
| 84 |
|
| 85 |
public function onFormSubmit( $formData ) { |
| 86 |
$title = $formData['page']; |
| 87 |
$page = Title::newFromTextThrow( $title ); |
| 88 |
$query = [ 'action' => 'edit', 'section' => 'new' ]; |
| 89 |
$url = $page->getFullUrlForRedirect( $query ); |
| 90 |
$this->getOutput()->redirect( $url ); |
| 91 |
} |
| 92 |
|
| 93 |
public function isListed() { |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function prefixSearchSubpages( $search, $limit, $offset ) { |
| 106 |
return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory ); |
| 107 |
} |
| 108 |
|
| 109 |
protected function getGroupName() { |
| 110 |
return 'redirects'; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
class_alias( SpecialNewSection::class, 'SpecialNewSection' ); |