3 namespace MediaWiki\SpecialPage
;
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
;
13 * Abstract to simplify creation of redirect special pages
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 * http://www.gnu.org/copyleft/gpl.html
33 * @ingroup SpecialPage
36 abstract class SpecialRedirectWithAction
extends RedirectSpecialPage
{
43 /** @var SearchEngineFactory */
44 private $searchEngineFactory;
48 * @since 1.39 SearchEngineFactory added
51 * @param string $action
52 * @param string $msgPrefix
53 * @param SearchEngineFactory|null $searchEngineFactory Not providing this param is deprecated since 1.39
55 public function __construct(
59 ?SearchEngineFactory
$searchEngineFactory = null
61 parent
::__construct( $name );
62 $this->action
= $action;
63 $this->msgPrefix
= $msgPrefix;
64 if ( !$searchEngineFactory ) {
65 // Fallback to global state if the new parameter was not provided
66 wfDeprecated( __METHOD__
. ' without providing SearchEngineFactory', '1.39' );
67 $searchEngineFactory = MediaWikiServices
::getInstance()->getSearchEngineFactory();
69 $this->searchEngineFactory
= $searchEngineFactory;
75 public function getRedirect( $subpage ) {
76 if ( $subpage === null ||
$subpage === '' ) {
79 $this->mAddedRedirectParams
['title'] = $subpage;
80 $this->mAddedRedirectParams
['action'] = $this->action
;
87 protected function showNoRedirectPage() {
89 $this->outputHeader();
93 private function showForm() {
94 // Dynamic messages used:
95 // 'special' . $this->msgPrefix . '-page'
96 // 'special' . $this->msgPrefix . '-submit'
97 // Each special page that extends this should include those as comments for grep
98 $form = HTMLForm
::factory( 'ooui', [
102 'label-message' => 'special' . $this->msgPrefix
. '-page',
105 ], $this->getContext(), $this->msgPrefix
);
106 $form->setSubmitTextMsg( 'special' . $this->msgPrefix
. '-submit' );
107 $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
112 * @stable to override
114 * @param array $formData
116 * @return Status|null
118 public function onFormSubmit( $formData ) {
119 $title = $formData['page'];
121 $page = Title
::newFromTextThrow( $title );
122 } catch ( MalformedTitleException
$e ) {
123 return Status
::newFatal( $e->getMessageObject() );
125 $query = [ 'action' => $this->action
];
126 $url = $page->getFullUrlForRedirect( $query );
127 $this->getOutput()->redirect( $url );
131 * @stable to override
134 public function isListed() {
139 * Return an array of subpages beginning with $search that this special page will accept.
141 * @param string $search Prefix to search for
142 * @param int $limit Maximum number of results to return (usually 10)
143 * @param int $offset Number of results to skip (usually 0)
144 * @return string[] Matching subpages
146 public function prefixSearchSubpages( $search, $limit, $offset ) {
147 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory
);
151 * @stable to override
154 protected function getGroupName() {
159 /** @deprecated class alias since 1.41 */
160 class_alias( SpecialRedirectWithAction
::class, 'SpecialRedirectWithAction' );