2005-12-22 05:41:06 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2010-08-08 14:23:14 +00:00
|
|
|
* Page protection
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2005 Brion Vibber <brion@pobox.com>
|
2014-03-12 22:30:35 +00:00
|
|
|
* https://www.mediawiki.org/
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-12-22 05:41:06 +00:00
|
|
|
* 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
|
2006-01-07 13:09:30 +00:00
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2005-12-22 05:41:06 +00:00
|
|
|
* (at your option) any later version.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-12-22 05:41:06 +00:00
|
|
|
* 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.
|
2006-01-07 13:09:30 +00:00
|
|
|
*
|
2005-12-22 05:41:06 +00:00
|
|
|
* 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.,
|
2006-04-05 07:43:17 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-22 05:41:06 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-08 14:23:14 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2005-12-22 05:41:06 +00:00
|
|
|
*/
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
|
|
|
|
|
use MediaWiki\HookContainer\HookRunner;
|
2017-01-18 20:55:20 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2019-12-06 20:39:40 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
2021-04-13 03:03:50 +00:00
|
|
|
use MediaWiki\Watchlist\WatchlistManager;
|
2005-12-22 05:41:06 +00:00
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
2008-10-06 15:31:03 +00:00
|
|
|
* Handles the page protection UI and backend
|
2007-04-04 05:22:37 +00:00
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
class ProtectionForm {
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var array A map of action to restriction level, from request or default */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mRestrictions = [];
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var string The custom/additional protection reason */
|
|
|
|
|
protected $mReason = '';
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var string The reason selected from the list, blank for other/additional */
|
|
|
|
|
protected $mReasonSelection = '';
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var bool True if the restrictions are cascading, from request or existing protection */
|
|
|
|
|
protected $mCascade = false;
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var array Map of action to "other" expiry time. Used in preference to mExpirySelection. */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mExpiry = [];
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2009-06-18 02:50:16 +00:00
|
|
|
/**
|
2014-05-12 14:42:51 +00:00
|
|
|
* @var array Map of action to value selected in expiry drop-down list.
|
2009-06-18 02:50:16 +00:00
|
|
|
* Will be set to 'othertime' whenever mExpiry is set.
|
2008-09-16 04:09:06 +00:00
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mExpirySelection = [];
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var array Permissions errors for the protect action */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mPermErrors = [];
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var array Types (i.e. actions) for which levels can be selected */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mApplicableTypes = [];
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @var array Map of action to the expiry time of the existing protection */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $mExistingExpiry = [];
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2019-09-11 09:07:30 +00:00
|
|
|
/** @var Article */
|
|
|
|
|
protected $mArticle;
|
|
|
|
|
|
|
|
|
|
/** @var Title */
|
|
|
|
|
protected $mTitle;
|
|
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
|
protected $disabled;
|
|
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
|
protected $disabledAttrib;
|
|
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
/** @var IContextSource */
|
|
|
|
|
private $mContext;
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
/** @var WebRequest */
|
|
|
|
|
private $mRequest;
|
|
|
|
|
|
|
|
|
|
/** @var User */
|
|
|
|
|
private $mUser;
|
|
|
|
|
|
|
|
|
|
/** @var Language */
|
|
|
|
|
private $mLang;
|
|
|
|
|
|
|
|
|
|
/** @var OutputPage */
|
|
|
|
|
private $mOut;
|
|
|
|
|
|
2020-02-26 04:26:00 +00:00
|
|
|
/** @var PermissionManager */
|
|
|
|
|
private $permManager;
|
|
|
|
|
|
2021-04-13 03:03:50 +00:00
|
|
|
/**
|
|
|
|
|
* @var WatchlistManager
|
|
|
|
|
*/
|
|
|
|
|
private $watchlistManager;
|
|
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
/** @var HookRunner */
|
|
|
|
|
private $hookRunner;
|
|
|
|
|
|
2019-11-30 23:03:59 +00:00
|
|
|
public function __construct( Article $article ) {
|
2009-11-06 10:27:44 +00:00
|
|
|
// Set instance variables.
|
2008-09-11 20:01:39 +00:00
|
|
|
$this->mArticle = $article;
|
2011-06-28 14:10:55 +00:00
|
|
|
$this->mTitle = $article->getTitle();
|
2009-11-09 12:05:30 +00:00
|
|
|
$this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
|
2014-08-23 08:30:53 +00:00
|
|
|
$this->mContext = $article->getContext();
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mRequest = $this->mContext->getRequest();
|
|
|
|
|
$this->mUser = $this->mContext->getUser();
|
|
|
|
|
$this->mOut = $this->mContext->getOutput();
|
|
|
|
|
$this->mLang = $this->mContext->getLanguage();
|
2012-10-10 18:13:40 +00:00
|
|
|
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
$this->permManager = $services->getPermissionManager();
|
|
|
|
|
$this->hookRunner = new HookRunner( $services->getHookContainer() );
|
2021-04-13 03:03:50 +00:00
|
|
|
$this->watchlistManager = $services->getWatchlistManager();
|
2020-02-26 04:26:00 +00:00
|
|
|
|
2009-11-06 10:27:44 +00:00
|
|
|
// Check if the form should be disabled.
|
|
|
|
|
// If it is, the form will be available in read-only to show levels.
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->mPermErrors = $this->permManager->getPermissionErrors(
|
2016-05-10 05:12:38 +00:00
|
|
|
'protect',
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mUser,
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->mTitle,
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mRequest->wasPosted()
|
2019-12-06 20:39:40 +00:00
|
|
|
? PermissionManager::RIGOR_SECURE
|
|
|
|
|
: PermissionManager::RIGOR_FULL // T92357
|
2014-08-23 08:30:53 +00:00
|
|
|
);
|
2011-11-01 15:45:52 +00:00
|
|
|
if ( wfReadOnly() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->mPermErrors[] = [ 'readonlytext', wfReadOnlyReason() ];
|
2011-11-01 15:45:52 +00:00
|
|
|
}
|
2019-09-11 09:07:30 +00:00
|
|
|
$this->disabled = $this->mPermErrors !== [];
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->disabledAttrib = $this->disabled ? [ 'disabled' => 'disabled' ] : [];
|
2012-06-18 22:56:55 +00:00
|
|
|
|
2009-11-06 10:27:44 +00:00
|
|
|
$this->loadData();
|
|
|
|
|
}
|
2012-06-18 22:56:55 +00:00
|
|
|
|
2010-05-23 19:25:07 +00:00
|
|
|
/**
|
|
|
|
|
* Loads the current state of protection into the object.
|
|
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
private function loadData() {
|
2020-02-26 04:26:00 +00:00
|
|
|
$levels = $this->permManager->getNamespaceRestrictionLevels(
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mTitle->getNamespace(), $this->mUser
|
2014-08-23 08:30:53 +00:00
|
|
|
);
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mCascade = $this->mTitle->areRestrictionsCascading();
|
|
|
|
|
$this->mReason = $this->mRequest->getText( 'mwProtect-reason' );
|
|
|
|
|
$this->mReasonSelection = $this->mRequest->getText( 'wpProtectReasonSelection' );
|
|
|
|
|
$this->mCascade = $this->mRequest->getBool( 'mwProtect-cascade', $this->mCascade );
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( $this->mApplicableTypes as $action ) {
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: This form currently requires individual selections,
|
2008-09-16 04:09:06 +00:00
|
|
|
// but the db allows multiples separated by commas.
|
2012-06-18 22:56:55 +00:00
|
|
|
|
2009-11-06 10:27:44 +00:00
|
|
|
// Pull the actual restriction from the DB
|
2008-09-16 04:09:06 +00:00
|
|
|
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
|
|
|
|
|
|
|
|
|
|
if ( !$this->mRestrictions[$action] ) {
|
|
|
|
|
// No existing expiry
|
|
|
|
|
$existingExpiry = '';
|
|
|
|
|
} else {
|
|
|
|
|
$existingExpiry = $this->mTitle->getRestrictionExpiry( $action );
|
|
|
|
|
}
|
|
|
|
|
$this->mExistingExpiry[$action] = $existingExpiry;
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$requestExpiry = $this->mRequest->getText( "mwProtect-expiry-$action" );
|
|
|
|
|
$requestExpirySelection = $this->mRequest->getVal( "wpProtectExpirySelection-$action" );
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
if ( $requestExpiry ) {
|
|
|
|
|
// Custom expiry takes precedence
|
|
|
|
|
$this->mExpiry[$action] = $requestExpiry;
|
|
|
|
|
$this->mExpirySelection[$action] = 'othertime';
|
|
|
|
|
} elseif ( $requestExpirySelection ) {
|
|
|
|
|
// Expiry selected from list
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = $requestExpirySelection;
|
|
|
|
|
} elseif ( $existingExpiry ) {
|
|
|
|
|
// Use existing expiry in its own list item
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = $existingExpiry;
|
|
|
|
|
} else {
|
2014-06-15 23:49:34 +00:00
|
|
|
// Catches 'infinity' - Existing expiry is infinite, use "infinite" in drop-down
|
2008-09-16 04:09:06 +00:00
|
|
|
// Final default: infinite
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = 'infinite';
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$val = $this->mRequest->getVal( "mwProtect-level-$action" );
|
2013-06-28 20:49:47 +00:00
|
|
|
if ( isset( $val ) && in_array( $val, $levels ) ) {
|
2008-09-06 07:20:13 +00:00
|
|
|
$this->mRestrictions[$action] = $val;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2007-01-22 20:59:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2009-06-18 02:50:16 +00:00
|
|
|
/**
|
2008-09-16 04:09:06 +00:00
|
|
|
* Get the expiry time for a given action, by combining the relevant inputs.
|
2010-05-23 19:25:07 +00:00
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $action
|
2012-06-18 22:56:55 +00:00
|
|
|
*
|
2016-12-08 05:04:53 +00:00
|
|
|
* @return string|false 14-char timestamp or "infinity", or false if the input was invalid
|
2008-09-16 04:09:06 +00:00
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
private function getExpiry( $action ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
if ( $this->mExpirySelection[$action] == 'existing' ) {
|
|
|
|
|
return $this->mExistingExpiry[$action];
|
|
|
|
|
} elseif ( $this->mExpirySelection[$action] == 'othertime' ) {
|
|
|
|
|
$value = $this->mExpiry[$action];
|
|
|
|
|
} else {
|
|
|
|
|
$value = $this->mExpirySelection[$action];
|
|
|
|
|
}
|
2014-06-18 02:45:32 +00:00
|
|
|
if ( wfIsInfinity( $value ) ) {
|
Clean up handling of 'infinity'
There's a bunch of stuff that probably only works because the database
representation of infinity is actually 'infinity' on all databases
besides Oracle, and Oracle in general isn't maintained.
Generally, we should probably use 'infinity' everywhere except where
directly dealing with the database.
* Many extension callers of Language::formatExpiry() with $format !==
true are assuming it'll return 'infinity', none are checking for
$db->getInfinity().
* And Language::formatExpiry() would choke if passed 'infinity', despite
callers doing this.
* And Language::formatExpiry() could be more useful for the API if we
can override the string returned for infinity.
* As for core, Title is using Language::formatExpiry() with TS_MW which
is going to be changing anyway. Extension callers mostly don't exist.
* Block already normalizes its mExpiry field (and ->getExpiry()),
but some stuff is comparing it with $db->getInfinity() anyway. A few
external users set mExpiry to $db->getInfinity(), but this is mostly
because SpecialBlock::parseExpiryInput() returns $db->getInfinity()
while most callers (including all extensions) are assuming 'infinity'.
* And for that matter, Block should use $db->decodeExpiry() instead of
manually doing it, once we make that safe to call with 'infinity' for
all the extensions passing $db->getInfinity() to Block's contructor.
* WikiPage::doUpdateRestrictions() and some of its callers are using
$db->getInfinity(), when all the inserts using that value are using
$db->encodeExpiry() which will convert 'infinity'.
This also cleans up a slave-lag issue I noticed in ApiBlock while
testing.
Bug: T92550
Change-Id: I5eb68c1fb6029da8289276ecf7c81330575029ef
2015-03-12 16:37:04 +00:00
|
|
|
$time = 'infinity';
|
2008-09-16 04:09:06 +00:00
|
|
|
} else {
|
|
|
|
|
$unix = strtotime( $value );
|
|
|
|
|
|
|
|
|
|
if ( !$unix || $unix === -1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-17 22:03:20 +00:00
|
|
|
// @todo FIXME: Non-qualified absolute times are not in users specified timezone
|
2008-09-16 04:09:06 +00:00
|
|
|
// and there isn't notice about it in the ui
|
|
|
|
|
$time = wfTimestamp( TS_MW, $unix );
|
|
|
|
|
}
|
|
|
|
|
return $time;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-23 19:25:07 +00:00
|
|
|
/**
|
|
|
|
|
* Main entry point for action=protect and action=unprotect
|
|
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
public function execute() {
|
2018-08-05 17:58:51 +00:00
|
|
|
if (
|
2020-02-26 04:26:00 +00:00
|
|
|
$this->permManager->getNamespaceRestrictionLevels(
|
2018-08-05 17:58:51 +00:00
|
|
|
$this->mTitle->getNamespace()
|
|
|
|
|
) === [ '' ]
|
|
|
|
|
) {
|
2011-11-01 15:45:52 +00:00
|
|
|
throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
if ( $this->mRequest->wasPosted() ) {
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->save() ) {
|
2020-03-26 00:43:50 +00:00
|
|
|
$q = $this->mArticle->getPage()->isRedirect() ? 'redirect=no' : '';
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mOut->redirect( $this->mTitle->getFullURL( $q ) );
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
2007-01-22 20:59:00 +00:00
|
|
|
} else {
|
|
|
|
|
$this->show();
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-05-23 19:25:07 +00:00
|
|
|
/**
|
|
|
|
|
* Show the input form with optional error message
|
|
|
|
|
*
|
2019-06-29 15:22:44 +00:00
|
|
|
* @param string|string[]|null $err Error message or null if there's no error
|
2010-05-23 19:25:07 +00:00
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
private function show( $err = null ) {
|
2020-08-31 22:54:56 +00:00
|
|
|
$out = $this->mOut;
|
2014-08-23 08:30:53 +00:00
|
|
|
$out->setRobotPolicy( 'noindex,nofollow' );
|
|
|
|
|
$out->addBacklinkSubtitle( $this->mTitle );
|
2005-12-22 05:41:06 +00:00
|
|
|
|
2011-11-01 15:45:52 +00:00
|
|
|
if ( is_array( $err ) ) {
|
2021-04-23 07:35:55 +00:00
|
|
|
$out->addHTML( Html::errorBox( $out->msg( ...$err )->plain() ) );
|
2011-11-01 15:45:52 +00:00
|
|
|
} elseif ( is_string( $err ) ) {
|
2021-04-23 07:35:55 +00:00
|
|
|
$out->addHTML( Html::errorBox( $err ) );
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
if ( $this->mApplicableTypes === [] ) {
|
2012-11-22 21:04:40 +00:00
|
|
|
// No restriction types available for the current title
|
|
|
|
|
// this might happen if an extension alters the available types
|
2015-01-17 20:04:39 +00:00
|
|
|
$out->setPageTitle( $this->mContext->msg(
|
2014-05-12 14:42:51 +00:00
|
|
|
'protect-norestrictiontypes-title',
|
|
|
|
|
$this->mTitle->getPrefixedText()
|
|
|
|
|
) );
|
2018-09-25 15:02:07 +00:00
|
|
|
$out->addWikiTextAsInterface(
|
|
|
|
|
$this->mContext->msg( 'protect-norestrictiontypes-text' )->plain()
|
|
|
|
|
);
|
2012-11-22 21:04:40 +00:00
|
|
|
|
|
|
|
|
// Show the log in case protection was possible once
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->showLogExtract();
|
2012-11-22 21:04:40 +00:00
|
|
|
// return as there isn't anything else we can do
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-01 15:45:52 +00:00
|
|
|
list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
|
2013-02-03 20:05:24 +00:00
|
|
|
if ( $cascadeSources && count( $cascadeSources ) > 0 ) {
|
2007-01-12 07:31:34 +00:00
|
|
|
$titles = '';
|
2007-01-12 04:43:33 +00:00
|
|
|
|
2007-01-12 07:31:34 +00:00
|
|
|
foreach ( $cascadeSources as $title ) {
|
2007-01-12 09:10:30 +00:00
|
|
|
$titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
|
2007-01-12 07:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
/** @todo FIXME: i18n issue, should use formatted number. */
|
2014-08-23 08:30:53 +00:00
|
|
|
$out->wrapWikiMsg(
|
2014-05-12 14:42:51 +00:00
|
|
|
"<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles . "</div>",
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'protect-cascadeon', count( $cascadeSources ) ]
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-01-12 04:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-02 07:39:32 +00:00
|
|
|
# Show an appropriate message if the user isn't allowed or able to change
|
|
|
|
|
# the protection settings at this time
|
2011-11-01 15:45:52 +00:00
|
|
|
if ( $this->disabled ) {
|
2014-08-23 08:30:53 +00:00
|
|
|
$out->setPageTitle(
|
2015-01-17 20:04:39 +00:00
|
|
|
$this->mContext->msg( 'protect-title-notallowed',
|
2014-05-12 14:42:51 +00:00
|
|
|
$this->mTitle->getPrefixedText() )
|
|
|
|
|
);
|
2018-09-25 15:02:07 +00:00
|
|
|
$out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage(
|
|
|
|
|
$this->mPermErrors, 'protect'
|
|
|
|
|
) );
|
2007-04-02 07:39:32 +00:00
|
|
|
} else {
|
2020-08-31 22:54:56 +00:00
|
|
|
$out->setPageTitle(
|
|
|
|
|
$this->mContext->msg( 'protect-title', $this->mTitle->getPrefixedText() )
|
|
|
|
|
);
|
2014-08-23 08:30:53 +00:00
|
|
|
$out->addWikiMsg( 'protect-text',
|
2011-06-20 19:45:35 +00:00
|
|
|
wfEscapeWikiText( $this->mTitle->getPrefixedText() ) );
|
2007-04-02 07:39:32 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$out->addHTML( $this->buildForm() );
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->showLogExtract();
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-05-23 19:25:07 +00:00
|
|
|
/**
|
|
|
|
|
* Save submitted protection form
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return bool Success
|
2010-05-23 19:25:07 +00:00
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
private function save() {
|
2008-09-06 23:20:58 +00:00
|
|
|
# Permission check!
|
|
|
|
|
if ( $this->disabled ) {
|
2007-01-22 20:59:00 +00:00
|
|
|
$this->show();
|
2005-12-22 05:41:06 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$token = $this->mRequest->getVal( 'wpEditToken' );
|
|
|
|
|
if ( !$this->mUser->matchEditToken( $token, [ 'protect', $this->mTitle->getPrefixedDBkey() ] ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->show( [ 'sessionfailure' ] );
|
2007-01-22 20:59:00 +00:00
|
|
|
return false;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2009-06-18 02:50:16 +00:00
|
|
|
|
2008-09-06 23:20:58 +00:00
|
|
|
# Create reason string. Use list and/or custom string.
|
2008-09-16 04:09:06 +00:00
|
|
|
$reasonstr = $this->mReasonSelection;
|
2008-09-06 23:20:58 +00:00
|
|
|
if ( $reasonstr != 'other' && $this->mReason != '' ) {
|
|
|
|
|
// Entry from drop down menu + additional comment
|
2015-01-17 20:04:39 +00:00
|
|
|
$reasonstr .= $this->mContext->msg( 'colon-separator' )->text() . $this->mReason;
|
2008-09-06 23:20:58 +00:00
|
|
|
} elseif ( $reasonstr == 'other' ) {
|
|
|
|
|
$reasonstr = $this->mReason;
|
|
|
|
|
}
|
2020-08-31 22:54:56 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$expiry = [];
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( $this->mApplicableTypes as $action ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
$expiry[$action] = $this->getExpiry( $action );
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( empty( $this->mRestrictions[$action] ) ) {
|
2020-05-09 22:50:56 +00:00
|
|
|
// unprotected
|
|
|
|
|
continue;
|
2013-04-20 22:49:30 +00:00
|
|
|
}
|
2008-09-16 04:09:06 +00:00
|
|
|
if ( !$expiry[$action] ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->show( [ 'protect_expiry_invalid' ] );
|
2008-09-16 04:09:06 +00:00
|
|
|
return false;
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
2008-09-16 04:09:06 +00:00
|
|
|
if ( $expiry[$action] < wfTimestampNow() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->show( [ 'protect_expiry_old' ] );
|
2008-09-16 04:09:06 +00:00
|
|
|
return false;
|
2007-02-16 07:39:33 +00:00
|
|
|
}
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mCascade = $this->mRequest->getBool( 'mwProtect-cascade' );
|
2008-06-21 03:17:35 +00:00
|
|
|
|
2020-03-26 00:43:50 +00:00
|
|
|
$status = $this->mArticle->getPage()->doUpdateRestrictions(
|
2014-05-12 14:42:51 +00:00
|
|
|
$this->mRestrictions,
|
|
|
|
|
$expiry,
|
|
|
|
|
$this->mCascade,
|
|
|
|
|
$reasonstr,
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mUser
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2007-12-11 09:51:56 +00:00
|
|
|
|
2011-12-18 16:02:14 +00:00
|
|
|
if ( !$status->isOK() ) {
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->show( $this->mOut->parseInlineAsInterface(
|
|
|
|
|
$status->getWikiText( false, false, $this->mLang )
|
2018-09-18 20:01:56 +00:00
|
|
|
) );
|
2011-12-18 16:02:14 +00:00
|
|
|
return false;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-11-01 15:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* Give extensions a change to handle added form items
|
|
|
|
|
*
|
|
|
|
|
* @since 1.19 you can (and you should) return false to abort saving;
|
|
|
|
|
* you can also return an array of message name and its parameters
|
|
|
|
|
*/
|
2009-10-02 18:46:19 +00:00
|
|
|
$errorMsg = '';
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
if ( !$this->hookRunner->onProtectionForm__save( $this->mArticle, $errorMsg, $reasonstr ) ) {
|
2011-11-01 15:45:52 +00:00
|
|
|
if ( $errorMsg == '' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$errorMsg = [ 'hookaborted' ];
|
2011-11-01 15:45:52 +00:00
|
|
|
}
|
2009-10-02 18:46:19 +00:00
|
|
|
}
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $errorMsg != '' ) {
|
2009-10-02 18:46:19 +00:00
|
|
|
$this->show( $errorMsg );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 03:03:50 +00:00
|
|
|
$this->watchlistManager->setWatch(
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mRequest->getCheck( 'mwProtectWatch' ),
|
2021-04-21 04:25:46 +00:00
|
|
|
$this->mUser,
|
|
|
|
|
$this->mTitle
|
2020-08-31 22:54:56 +00:00
|
|
|
);
|
2013-06-13 18:02:55 +00:00
|
|
|
|
2011-12-18 16:02:14 +00:00
|
|
|
return true;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-03-13 10:05:11 +00:00
|
|
|
/**
|
|
|
|
|
* Build the input form
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @return string HTML form
|
2008-03-13 10:05:11 +00:00
|
|
|
*/
|
2020-05-09 22:50:56 +00:00
|
|
|
private function buildForm() {
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mOut->enableOOUI();
|
2005-12-22 05:41:06 +00:00
|
|
|
$out = '';
|
2020-08-31 22:54:56 +00:00
|
|
|
$fields = [];
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->disabled ) {
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mOut->addModules( 'mediawiki.action.protect' );
|
2021-03-26 16:33:51 +00:00
|
|
|
$this->mOut->addModuleStyles( 'mediawiki.action.styles' );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2020-08-31 22:54:56 +00:00
|
|
|
$scExpiryOptions = $this->mContext->msg( 'protect-expiry-options' )->inContentLanguage()->text();
|
|
|
|
|
$levels = $this->permManager->getNamespaceRestrictionLevels(
|
|
|
|
|
$this->mTitle->getNamespace(),
|
|
|
|
|
$this->disabled ? null : $this->mUser
|
|
|
|
|
);
|
2014-07-06 18:53:18 +00:00
|
|
|
|
2013-08-28 00:38:27 +00:00
|
|
|
// Not all languages have V_x <-> N_x relation
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( $this->mRestrictions as $action => $selected ) {
|
2013-08-28 00:38:27 +00:00
|
|
|
// Messages:
|
2013-08-16 12:58:07 +00:00
|
|
|
// restriction-edit, restriction-move, restriction-create, restriction-upload
|
2020-08-31 22:54:56 +00:00
|
|
|
$section = 'restriction-' . $action;
|
|
|
|
|
$id = 'mwProtect-level-' . $action;
|
|
|
|
|
$options = [];
|
|
|
|
|
foreach ( $levels as $key ) {
|
|
|
|
|
$options[$this->getOptionLabel( $key )] = $key;
|
2015-07-30 20:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields[$id] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'select',
|
|
|
|
|
'name' => $id,
|
|
|
|
|
'default' => $selected,
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'size' => count( $levels ),
|
|
|
|
|
'options' => $options,
|
|
|
|
|
'disabled' => $this->disabled,
|
|
|
|
|
'section' => $section,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$expiryOptions = [];
|
|
|
|
|
|
2014-08-29 15:30:37 +00:00
|
|
|
if ( $this->mExistingExpiry[$action] ) {
|
|
|
|
|
if ( $this->mExistingExpiry[$action] == 'infinity' ) {
|
2020-08-31 22:54:56 +00:00
|
|
|
$existingExpiryMessage = $this->mContext->msg( 'protect-existing-expiry-infinity' );
|
2014-08-29 15:30:37 +00:00
|
|
|
} else {
|
2020-08-31 22:54:56 +00:00
|
|
|
$timestamp = $this->mLang->userTimeAndDate( $this->mExistingExpiry[$action], $this->mUser );
|
|
|
|
|
$date = $this->mLang->userDate( $this->mExistingExpiry[$action], $this->mUser );
|
|
|
|
|
$time = $this->mLang->userTime( $this->mExistingExpiry[$action], $this->mUser );
|
|
|
|
|
$existingExpiryMessage = $this->mContext->msg(
|
2015-09-28 12:43:19 +00:00
|
|
|
'protect-existing-expiry',
|
|
|
|
|
$timestamp,
|
2020-08-31 22:54:56 +00:00
|
|
|
$date,
|
|
|
|
|
$time
|
2015-09-28 12:43:19 +00:00
|
|
|
);
|
2014-08-29 15:30:37 +00:00
|
|
|
}
|
2020-08-31 22:54:56 +00:00
|
|
|
$expiryOptions[$existingExpiryMessage->text()] = 'existing';
|
2008-09-16 04:09:06 +00:00
|
|
|
}
|
2009-06-18 02:50:16 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$expiryOptions[$this->mContext->msg( 'protect-othertime-op' )->text()] = 'othertime';
|
|
|
|
|
foreach ( explode( ',', $scExpiryOptions ) as $option ) {
|
|
|
|
|
if ( strpos( $option, ":" ) === false ) {
|
|
|
|
|
$show = $value = $option;
|
|
|
|
|
} else {
|
|
|
|
|
list( $show, $value ) = explode( ":", $option );
|
|
|
|
|
}
|
|
|
|
|
$expiryOptions[$show] = htmlspecialchars( $value );
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
2020-08-31 22:54:56 +00:00
|
|
|
|
|
|
|
|
# Add expiry dropdown
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields["wpProtectExpirySelection-$action"] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'select',
|
|
|
|
|
'name' => "wpProtectExpirySelection-$action",
|
|
|
|
|
'id' => "mwProtectExpirySelection-$action",
|
|
|
|
|
'tabindex' => '2',
|
|
|
|
|
'disabled' => $this->disabled,
|
|
|
|
|
'label' => $this->mContext->msg( 'protectexpiry' )->text(),
|
|
|
|
|
'options' => $expiryOptions,
|
|
|
|
|
'default' => $this->mExpirySelection[$action],
|
|
|
|
|
'section' => $section,
|
|
|
|
|
];
|
|
|
|
|
|
2008-09-13 05:33:24 +00:00
|
|
|
# Add custom expiry field
|
2020-08-31 22:54:56 +00:00
|
|
|
if ( !$this->disabled ) {
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields["mwProtect-expiry-$action"] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'text',
|
|
|
|
|
'label' => $this->mContext->msg( 'protect-othertime' )->text(),
|
|
|
|
|
'name' => "mwProtect-expiry-$action",
|
|
|
|
|
'id' => "mwProtect-$action-expires",
|
|
|
|
|
'size' => 50,
|
|
|
|
|
'default' => $this->mExpiry[$action],
|
|
|
|
|
'disabled' => $this->disabled,
|
|
|
|
|
'section' => $section,
|
|
|
|
|
];
|
|
|
|
|
}
|
2008-09-06 23:20:58 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
# Give extensions a chance to add items to the form
|
|
|
|
|
$hookFormRaw = '';
|
|
|
|
|
$hookFormOptions = [];
|
|
|
|
|
|
|
|
|
|
$this->hookRunner->onProtectionForm__buildForm( $this->mArticle, $hookFormRaw );
|
|
|
|
|
$this->hookRunner->onProtectionFormAddFormFields( $this->mArticle, $hookFormOptions );
|
|
|
|
|
|
|
|
|
|
# Merge forms added from addFormFields
|
|
|
|
|
$fields = array_merge( $fields, $hookFormOptions );
|
|
|
|
|
|
|
|
|
|
# Add raw sections added in buildForm
|
|
|
|
|
if ( $hookFormRaw ) {
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['rawinfo'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'info',
|
|
|
|
|
'default' => $hookFormRaw,
|
|
|
|
|
'raw' => true,
|
|
|
|
|
'section' => 'restriction-blank'
|
|
|
|
|
];
|
|
|
|
|
}
|
2007-03-19 07:08:58 +00:00
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
# JavaScript will add another row with a value-chaining checkbox
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->mTitle->exists() ) {
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['mwProtect-cascade'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label' => $this->mContext->msg( 'protect-cascade' )->text(),
|
|
|
|
|
'id' => 'mwProtect-cascade',
|
|
|
|
|
'name' => 'mwProtect-cascade',
|
|
|
|
|
'default' => $this->mCascade,
|
|
|
|
|
'disabled' => $this->disabled,
|
|
|
|
|
];
|
2008-03-12 15:19:29 +00:00
|
|
|
}
|
2009-06-18 02:50:16 +00:00
|
|
|
|
2008-09-13 08:53:07 +00:00
|
|
|
# Add manual and custom reason field/selects as well as submit
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->disabled ) {
|
2018-02-08 21:22:34 +00:00
|
|
|
// HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
|
|
|
|
|
// (e.g. emojis) count for two each. This limit is overridden in JS to instead count
|
2019-01-04 18:55:11 +00:00
|
|
|
// Unicode codepoints.
|
2018-02-08 21:22:34 +00:00
|
|
|
// Subtract arbitrary 75 to leave some space for the autogenerated null edit's summary
|
|
|
|
|
// and other texts chosen by dropdown menus on this page.
|
2019-01-04 18:55:11 +00:00
|
|
|
$maxlength = CommentStore::COMMENT_CHARACTER_LIMIT - 75;
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['wpProtectReasonSelection'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'select',
|
|
|
|
|
'cssclass' => 'mwProtect-reason',
|
|
|
|
|
'label' => $this->mContext->msg( 'protectcomment' )->text(),
|
|
|
|
|
'tabindex' => 4,
|
|
|
|
|
'id' => 'wpProtectReasonSelection',
|
|
|
|
|
'name' => 'wpProtectReasonSelection',
|
|
|
|
|
'flatlist' => true,
|
|
|
|
|
'options' => Xml::listDropDownOptions(
|
|
|
|
|
$this->mContext->msg( 'protect-dropdown' )->inContentLanguage()->text(),
|
|
|
|
|
[ 'other' => $this->mContext->msg( 'protect-otherreason-op' )->inContentLanguage()->text() ]
|
|
|
|
|
),
|
|
|
|
|
'default' => $this->mReasonSelection,
|
|
|
|
|
];
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['mwProtect-reason'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'text',
|
|
|
|
|
'id' => 'mwProtect-reason',
|
|
|
|
|
'label' => $this->mContext->msg( 'protect-otherreason' )->text(),
|
|
|
|
|
'name' => 'mwProtect-reason',
|
|
|
|
|
'size' => 60,
|
|
|
|
|
'maxlength' => $maxlength,
|
|
|
|
|
'default' => $this->mReason,
|
|
|
|
|
];
|
|
|
|
|
# Disallow watching if user is not logged in
|
|
|
|
|
if ( $this->mUser->isRegistered() ) {
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['mwProtectWatch'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'id' => 'mwProtectWatch',
|
|
|
|
|
'label' => $this->mContext->msg( 'watchthis' )->text(),
|
|
|
|
|
'name' => 'mwProtectWatch',
|
2021-02-17 21:16:05 +00:00
|
|
|
'default' => (
|
2021-04-13 03:03:50 +00:00
|
|
|
$this->watchlistManager->isWatched( $this->mUser, $this->mTitle )
|
2020-08-31 22:54:56 +00:00
|
|
|
|| $this->mUser->getOption( 'watchdefault' )
|
|
|
|
|
),
|
|
|
|
|
];
|
2009-11-14 11:07:46 +00:00
|
|
|
}
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
if ( $this->permManager->userHasRight( $this->mUser, 'editinterface' ) ) {
|
2017-01-18 20:55:20 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mContext->msg( 'protect-dropdown' )->inContentLanguage()->getTitle(),
|
|
|
|
|
$this->mContext->msg( 'protect-edit-reasonlist' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'action' => 'edit' ]
|
2009-05-27 20:35:16 +00:00
|
|
|
);
|
2008-09-22 16:16:37 +00:00
|
|
|
$out .= '<p class="mw-protect-editreasons">' . $link . '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-22 08:26:41 +00:00
|
|
|
if ( !$this->disabled ) {
|
2021-02-17 21:16:05 +00:00
|
|
|
$fields['wpEditToken'] = [
|
2020-08-31 22:54:56 +00:00
|
|
|
'name' => 'wpEditToken',
|
|
|
|
|
'type' => 'hidden',
|
|
|
|
|
'default' => $this->mUser->getEditToken( [ 'protect', $this->mTitle->getPrefixedDBkey() ] ),
|
|
|
|
|
];
|
2015-07-30 20:00:41 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-31 22:54:56 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $fields, $this->mContext );
|
|
|
|
|
$htmlForm
|
|
|
|
|
->setMethod( 'post' )
|
|
|
|
|
->setId( 'mw-Protect-Form' )
|
|
|
|
|
->setTableId( 'mw-protect-table2' )
|
|
|
|
|
->setAction( $this->mTitle->getLocalURL( 'action=protect' ) )
|
|
|
|
|
->setSubmitID( 'mw-Protect-submit' )
|
|
|
|
|
->setSubmitText( $this->mContext->msg( 'confirm' )->text() )
|
|
|
|
|
->suppressDefaultSubmit( $this->disabled )
|
|
|
|
|
->setWrapperLegend( $this->mContext->msg( 'protect-legend' )->text() )
|
|
|
|
|
->loadData();
|
|
|
|
|
|
|
|
|
|
return $htmlForm->getHTML( false ) . $out;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-08-11 16:24:01 +00:00
|
|
|
/**
|
|
|
|
|
* Prepare the label for a protection selector option
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $permission Permission required
|
|
|
|
|
* @return string
|
2007-08-11 16:24:01 +00:00
|
|
|
*/
|
|
|
|
|
private function getOptionLabel( $permission ) {
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $permission == '' ) {
|
2015-01-17 20:04:39 +00:00
|
|
|
return $this->mContext->msg( 'protect-default' )->text();
|
2007-08-11 16:24:01 +00:00
|
|
|
} else {
|
2013-09-04 11:56:47 +00:00
|
|
|
// Messages: protect-level-autoconfirmed, protect-level-sysop
|
2015-01-17 20:04:39 +00:00
|
|
|
$msg = $this->mContext->msg( "protect-level-{$permission}" );
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $msg->exists() ) {
|
2011-01-14 10:51:05 +00:00
|
|
|
return $msg->text();
|
|
|
|
|
}
|
2015-01-17 20:04:39 +00:00
|
|
|
return $this->mContext->msg( 'protect-fallback', $permission )->text();
|
2007-08-11 16:24:01 +00:00
|
|
|
}
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2012-06-18 22:56:55 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
/**
|
2010-05-23 19:25:07 +00:00
|
|
|
* Show protection long extracts for this page
|
2005-12-22 05:41:06 +00:00
|
|
|
*/
|
2020-08-31 22:54:56 +00:00
|
|
|
private function showLogExtract() {
|
2007-06-02 00:41:16 +00:00
|
|
|
# Show relevant lines from the protection log:
|
2012-06-18 22:56:55 +00:00
|
|
|
$protectLogPage = new LogPage( 'protect' );
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->mOut->addHTML( Xml::element( 'h2', null, $protectLogPage->getName()->text() ) );
|
|
|
|
|
/** @phan-suppress-next-line PhanTypeMismatchPropertyByRef */
|
|
|
|
|
LogEventsList::showLogExtract( $this->mOut, 'protect', $this->mTitle );
|
2009-10-02 18:46:19 +00:00
|
|
|
# Let extensions add other relevant log extracts
|
2020-08-31 22:54:56 +00:00
|
|
|
$this->hookRunner->onProtectionForm__showLogExtract( $this->mArticle, $this->mOut );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2007-12-01 09:08:43 +00:00
|
|
|
}
|