UnlistedSpecialPage.php 0000666 00000003116 15133472432 0011153 0 ustar 00 <?php
/**
* Shortcut to construct a special page which is unlisted by default.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
namespace MediaWiki\SpecialPage;
/**
* Shortcut to construct a special page which is unlisted by default.
*
* @stable to extend
*
* @ingroup SpecialPage
*/
class UnlistedSpecialPage extends SpecialPage {
/**
* @stable to call
*
* @param string $name
* @param string $restriction
* @param bool $function
* @param string $file
*/
public function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
parent::__construct( $name, $restriction, false, $function, $file );
}
public function isListed() {
return false;
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( UnlistedSpecialPage::class, 'UnlistedSpecialPage' );
RedirectSpecialArticle.php 0000666 00000012114 15133472432 0011632 0 ustar 00 <?php
/**
* Shortcuts to construct a special page alias.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
namespace MediaWiki\SpecialPage;
use MediaWiki\Title\Title;
/**
* Superclass for any RedirectSpecialPage which redirects the user
* to a particular article (as opposed to user contributions, logs, etc.).
*
* For security reasons these special pages are restricted to pass on
* the following subset of GET parameters to the target page while
* removing all others:
*
* - useskin, uselang, printable: to alter the appearance of the resulting page
*
* - redirect: allows viewing one's user page or talk page even if it is a
* redirect.
*
* - rdfrom: allows redirecting to one's user page or talk page from an
* external wiki with the "Redirect from..." notice.
*
* - limit, offset: Useful for linking to history of one's own user page or
* user talk page. For example, this would be a link to "the last edit to your
* user talk page in the year 2010":
* https://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
*
* - feed: would allow linking to the current user's RSS feed for their user
* talk page:
* https://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
*
* - preloadtitle: Can be used to provide a default section title for a
* preloaded new comment on one's own talk page.
*
* - summary : Can be used to provide a default edit summary for a preloaded
* edit to one's own user page or talk page.
*
* - preview: Allows showing/hiding preview on first edit regardless of user
* preference, useful for preloaded edits where you know preview wouldn't be
* useful.
*
* - redlink: Affects the message the user sees if their talk page/user talk
* page does not currently exist. Avoids confusion for newbies with no user
* pages over why they got a "permission error" following this link:
* https://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
*
* - debug: determines whether the debug parameter is passed to load.php,
* which disables reformatting and allows scripts to be debugged. Useful
* when debugging scripts that manipulate one's own user page or talk page.
*
* @par Hook extension:
* Extensions can add to the redirect parameters list by using the hook
* RedirectSpecialArticleRedirectParams
*
* This hook allows extensions which add GET parameters like FlaggedRevs to
* retain those parameters when redirecting using special pages.
*
* @par Hook extension example:
* @code
* $wgHooks['RedirectSpecialArticleRedirectParams'][] =
* 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
* public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
* $redirectParams[] = 'stable';
* return true;
* }
* @endcode
*
* @stable to extend
*
* @ingroup SpecialPage
*/
abstract class RedirectSpecialArticle extends RedirectSpecialPage {
/**
* @stable to call
*
* @param string $name
*/
public function __construct( $name ) {
parent::__construct( $name );
$redirectParams = [
'action',
'redirect', 'rdfrom',
# Options for preloaded edits
'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary',
# Options for overriding user settings
'preview', 'minor', 'watchthis',
# Options for history/diffs
'section', 'oldid', 'diff', 'dir',
'limit', 'offset', 'feed',
# Misc options
'redlink',
# Options for action=raw; missing ctype can break JS or CSS in some browsers
'ctype', 'maxage', 'smaxage',
];
$this->getHookRunner()->onRedirectSpecialArticleRedirectParams( $redirectParams );
$this->mAllowedRedirectParams = $redirectParams;
}
/**
* @inheritDoc
*/
public function getRedirectQuery( $subpage ) {
$query = parent::getRedirectQuery( $subpage );
$title = $this->getRedirect( $subpage );
// Avoid double redirect for action=edit&redlink=1 for existing pages
// (compare to the check in EditPage::edit)
if (
$query && isset( $query['action'] ) && isset( $query['redlink'] ) &&
( $query['action'] === 'edit' || $query['action'] === 'submit' ) &&
(bool)$query['redlink'] &&
$title instanceof Title &&
$title->exists()
) {
return false;
}
return $query;
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( RedirectSpecialArticle::class, 'RedirectSpecialArticle' );
SpecialRedirectWithAction.php 0000666 00000010642 15133472432 0012324 0 ustar 00 <?php
namespace MediaWiki\SpecialPage;
use HTMLForm;
use MediaWiki\MediaWikiServices;
use MediaWiki\Status\Status;
use MediaWiki\Title\MalformedTitleException;
use MediaWiki\Title\Title;
use SearchEngineFactory;
/**
* Abstract to simplify creation of redirect special pages
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @stable to extend
*
* @file
* @ingroup SpecialPage
* @author DannyS712
*/
abstract class SpecialRedirectWithAction extends RedirectSpecialPage {
/** @var string */
protected $action;
/** @var string */
protected $msgPrefix;
/** @var SearchEngineFactory */
private $searchEngineFactory;
/**
* @stable to call
* @since 1.39 SearchEngineFactory added
*
* @param string $name
* @param string $action
* @param string $msgPrefix
* @param SearchEngineFactory|null $searchEngineFactory Not providing this param is deprecated since 1.39
*/
public function __construct(
$name,
$action,
$msgPrefix,
SearchEngineFactory $searchEngineFactory = null
) {
parent::__construct( $name );
$this->action = $action;
$this->msgPrefix = $msgPrefix;
if ( !$searchEngineFactory ) {
// Fallback to global state if the new parameter was not provided
wfDeprecated( __METHOD__ . ' without providing SearchEngineFactory', '1.39' );
$searchEngineFactory = MediaWikiServices::getInstance()->getSearchEngineFactory();
}
$this->searchEngineFactory = $searchEngineFactory;
}
/**
* @inheritDoc
*/
public function getRedirect( $subpage ) {
if ( $subpage === null || $subpage === '' ) {
return false;
}
$this->mAddedRedirectParams['title'] = $subpage;
$this->mAddedRedirectParams['action'] = $this->action;
return true;
}
/**
* @stable to override
*/
protected function showNoRedirectPage() {
$this->setHeaders();
$this->outputHeader();
$this->showForm();
}
private function showForm() {
// Dynamic messages used:
// 'special' . $this->msgPrefix . '-page'
// 'special' . $this->msgPrefix . '-submit'
// Each special page that extends this should include those as comments for grep
$form = HTMLForm::factory( 'ooui', [
'page' => [
'type' => 'text',
'name' => 'page',
'label-message' => 'special' . $this->msgPrefix . '-page',
'required' => true,
],
], $this->getContext(), $this->msgPrefix );
$form->setSubmitTextMsg( 'special' . $this->msgPrefix . '-submit' );
$form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
$form->show();
}
/**
* @stable to override
*
* @param array $formData
*
* @return Status|null
*/
public function onFormSubmit( $formData ) {
$title = $formData['page'];
try {
$page = Title::newFromTextThrow( $title );
} catch ( MalformedTitleException $e ) {
return Status::newFatal( $e->getMessageObject() );
}
$query = [ 'action' => $this->action ];
$url = $page->getFullUrlForRedirect( $query );
$this->getOutput()->redirect( $url );
}
/**
* @stable to override
* @return bool
*/
public function isListed() {
return true;
}
/**
* Return an array of subpages beginning with $search that this special page will accept.
*
* @param string $search Prefix to search for
* @param int $limit Maximum number of results to return (usually 10)
* @param int $offset Number of results to skip (usually 0)
* @return string[] Matching subpages
*/
public function prefixSearchSubpages( $search, $limit, $offset ) {
return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
}
/**
* @stable to override
* @return string
*/
protected function getGroupName() {
return 'redirects';
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( SpecialRedirectWithAction::class, 'SpecialRedirectWithAction' );
SpecialRedirectToSpecial.php 0000666 00000004270 15133472432 0012136 0 ustar 00 <?php
/**
* Shortcuts to construct a special page alias.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
namespace MediaWiki\SpecialPage;
use MediaWiki\Title\Title;
/**
* @stable to extend
*
* @ingroup SpecialPage
*/
abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
/** @var string Name of redirect target */
protected $redirName;
/** @var string|false Name of subpage of redirect target */
protected $redirSubpage;
/**
* @stable to call
*
* @param string $name
* @param string $redirName
* @param string|false $redirSubpage
* @param array $allowedRedirectParams
* @param array $addedRedirectParams
*/
public function __construct(
$name, $redirName, $redirSubpage = false,
$allowedRedirectParams = [], $addedRedirectParams = []
) {
parent::__construct( $name );
$this->redirName = $redirName;
$this->redirSubpage = $redirSubpage;
$this->mAllowedRedirectParams = $allowedRedirectParams;
$this->mAddedRedirectParams = $addedRedirectParams;
}
/**
* @param string|null $subpage
* @return Title|bool
*/
public function getRedirect( $subpage ) {
if ( $this->redirSubpage === false ) {
return SpecialPage::getTitleFor( $this->redirName, $subpage );
}
return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( SpecialRedirectToSpecial::class, 'SpecialRedirectToSpecial' );
RedirectSpecialPage.php 0000666 00000007172 15133472432 0011133 0 ustar 00 <?php
/**
* Shortcuts to construct a special page alias.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
namespace MediaWiki\SpecialPage;
use LogicException;
use MediaWiki\Title\Title;
/**
* Shortcut to construct a special page alias.
*
* @stable to extend
*
* @ingroup SpecialPage
*/
abstract class RedirectSpecialPage extends UnlistedSpecialPage {
/** @var array Query parameters that can be passed through redirects */
protected $mAllowedRedirectParams = [];
/** @var array Query parameters added by redirects */
protected $mAddedRedirectParams = [];
/**
* @stable to override
* @param string|null $subpage
*/
public function execute( $subpage ) {
$redirect = $this->getRedirect( $subpage );
$query = $this->getRedirectQuery( $subpage );
if ( $redirect instanceof Title ) {
// Redirect to a page title with possible query parameters
$url = $redirect->getFullUrlForRedirect( $query );
$this->getOutput()->redirect( $url );
} elseif ( $redirect === true ) {
// Redirect to index.php with query parameters
$url = wfAppendQuery( wfScript( 'index' ), $query );
$this->getOutput()->redirect( $url );
} else {
$this->showNoRedirectPage();
}
}
/**
* If the special page is a redirect, then get the Title object it redirects to.
* False otherwise.
*
* @param string|null $subpage
* @return Title|bool
*/
abstract public function getRedirect( $subpage );
/**
* Return part of the request string for a special redirect page
* This allows passing, e.g. action=history to Special:Mypage, etc.
*
* @stable to override
* @param string|null $subpage
* @return array|false
*/
public function getRedirectQuery( $subpage ) {
$params = [];
$request = $this->getRequest();
foreach ( array_merge( $this->mAllowedRedirectParams,
[ 'uselang', 'useskin', 'variant', 'debug', 'safemode' ] // parameters which can be passed to all pages
) as $arg ) {
if ( $request->getVal( $arg, null ) !== null ) {
$params[$arg] = $request->getVal( $arg );
} elseif ( $request->getArray( $arg, null ) !== null ) {
$params[$arg] = $request->getArray( $arg );
}
}
foreach ( $this->mAddedRedirectParams as $arg => $val ) {
$params[$arg] = $val;
}
return count( $params )
? $params
: false;
}
/**
* Indicate if the target of this redirect can be used to identify
* a particular user of this wiki (e.g., if the redirect is to the
* user page of a User). See T109724.
*
* @stable to override
* @since 1.27
* @return bool
*/
public function personallyIdentifiableTarget() {
return false;
}
/**
* @stable to override
*/
protected function showNoRedirectPage() {
$class = static::class;
throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.41
*/
class_alias( RedirectSpecialPage::class, 'RedirectSpecialPage' );
Hook/ChangesListSpecialPageStructuredFiltersHook.php 0000666 00000003065 15133472432 0016732 0 ustar 00 <?php
namespace MediaWiki\SpecialPage\Hook;
use MediaWiki\SpecialPage\ChangesListSpecialPage;
/**
* This is a hook handler interface, see docs/Hooks.md.
* Use the hook name "ChangesListSpecialPageStructuredFilters" to register handlers implementing this interface.
*
* @stable to implement
* @ingroup Hooks
*/
interface ChangesListSpecialPageStructuredFiltersHook {
/**
* Use this hook to register filters for pages inheriting from ChangesListSpecialPage
* (in core: RecentChanges, RecentChangesLinked, and Watchlist). Generally, you will
* want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects.
* When constructing them, you specify which group they belong to. You can reuse
* existing groups (accessed through $special->getFilterGroup), or create your own
* (ChangesListBooleanFilterGroup or ChangesListStringOptionsFilterGroup).
* If you create new groups, you must register them with $special->registerFilterGroup.
* Note that this is called regardless of whether the user is currently using
* the new (structured) or old (unstructured) filter UI. If you want your boolean
* filter to show on both the new and old UI, specify all the supported fields.
* These include showHide, label, and description.
* See the constructor of each ChangesList* class for documentation of supported
* fields.
*
* @since 1.35
*
* @param ChangesListSpecialPage $special
* @return bool|void True or no return value to continue or false to abort
*/
public function onChangesListSpecialPageStructuredFilters( $special );
}
Hook/RedirectSpecialArticleRedirectParamsHook.php 0000666 00000001414 15133472432 0016202 0 ustar 00 <?php
namespace MediaWiki\SpecialPage\Hook;
/**
* This is a hook handler interface, see docs/Hooks.md.
* Use the hook name "RedirectSpecialArticleRedirectParams" to register handlers implementing this interface.
*
* @stable to implement
* @ingroup Hooks
*/
interface RedirectSpecialArticleRedirectParamsHook {
/**
* Use this hook to alter the set of parameter names such as "oldid" that
* are preserved when using redirecting special pages such as Special:MyPage
* and Special:MyTalk.
*
* @since 1.35
*
* @param string[] &$redirectParams Array of parameters preserved by redirecting special pages
* @return bool|void True or no return value to continue or false to abort
*/
public function onRedirectSpecialArticleRedirectParams( &$redirectParams );
}