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
|
|
|
*/
|
2017-01-18 20:55:20 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
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
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
/** @var IContextSource */
|
|
|
|
|
private $mContext;
|
|
|
|
|
|
|
|
|
|
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();
|
2012-10-10 18:13:40 +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.
|
2014-08-23 08:30:53 +00:00
|
|
|
$this->mPermErrors = $this->mTitle->getUserPermissionsErrors(
|
2016-05-10 05:12:38 +00:00
|
|
|
'protect',
|
|
|
|
|
$this->mContext->getUser(),
|
|
|
|
|
$this->mContext->getRequest()->wasPosted() ? 'secure' : '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
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->disabled = $this->mPermErrors != [];
|
2005-12-22 05:41:06 +00:00
|
|
|
$this->disabledAttrib = $this->disabled
|
2016-02-17 09:09:32 +00:00
|
|
|
? [ '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.
|
|
|
|
|
*/
|
2009-11-06 10:27:44 +00:00
|
|
|
function loadData() {
|
2014-08-23 08:30:53 +00:00
|
|
|
$levels = MWNamespace::getRestrictionLevels(
|
|
|
|
|
$this->mTitle->getNamespace(), $this->mContext->getUser()
|
|
|
|
|
);
|
2009-11-06 10:27:44 +00:00
|
|
|
$this->mCascade = $this->mTitle->areRestrictionsCascading();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$request = $this->mContext->getRequest();
|
|
|
|
|
$this->mReason = $request->getText( 'mwProtect-reason' );
|
|
|
|
|
$this->mReasonSelection = $request->getText( 'wpProtectReasonSelection' );
|
|
|
|
|
$this->mCascade = $request->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;
|
|
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$requestExpiry = $request->getText( "mwProtect-expiry-$action" );
|
|
|
|
|
$requestExpirySelection = $request->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
|
|
|
}
|
|
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$val = $request->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
|
|
|
*/
|
|
|
|
|
function getExpiry( $action ) {
|
|
|
|
|
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
|
|
|
|
|
*/
|
2007-01-22 20:59:00 +00:00
|
|
|
function execute() {
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === [ '' ] ) {
|
2011-11-01 15:45:52 +00:00
|
|
|
throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' );
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
if ( $this->mContext->getRequest()->wasPosted() ) {
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->save() ) {
|
2008-09-11 20:01:39 +00:00
|
|
|
$q = $this->mArticle->isRedirect() ? 'redirect=no' : '';
|
2017-01-21 18:54:21 +00:00
|
|
|
$this->mContext->getOutput()->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
|
|
|
|
|
*
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $err Error message or null if there's no error
|
2010-05-23 19:25:07 +00:00
|
|
|
*/
|
2007-01-22 08:26:41 +00:00
|
|
|
function show( $err = null ) {
|
2014-08-23 08:30:53 +00:00
|
|
|
$out = $this->mContext->getOutput();
|
|
|
|
|
$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 ) ) {
|
2018-09-27 15:44:15 +00:00
|
|
|
$out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", $err );
|
2011-11-01 15:45:52 +00:00
|
|
|
} elseif ( is_string( $err ) ) {
|
2018-09-27 15:44:15 +00:00
|
|
|
$out->addHTML( "<div class='error'>{$err}</div>\n" );
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( $this->mTitle->getRestrictionTypes() === [] ) {
|
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
|
2014-08-23 08:30:53 +00:00
|
|
|
$this->showLogExtract( $out );
|
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 {
|
2015-01-17 20:04:39 +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() );
|
|
|
|
|
$this->showLogExtract( $out );
|
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
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
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
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$request = $this->mContext->getRequest();
|
|
|
|
|
$user = $this->mContext->getUser();
|
|
|
|
|
$out = $this->mContext->getOutput();
|
|
|
|
|
$token = $request->getVal( 'wpEditToken' );
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !$user->matchEditToken( $token, [ 'protect', $this->mTitle->getPrefixedDBkey() ] ) ) {
|
|
|
|
|
$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;
|
|
|
|
|
}
|
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] ) ) {
|
2009-01-03 16:33:15 +00:00
|
|
|
continue; // unprotected
|
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
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
$this->mCascade = $request->getBool( 'mwProtect-cascade' );
|
2008-06-21 03:17:35 +00:00
|
|
|
|
2014-05-12 14:42:51 +00:00
|
|
|
$status = $this->mArticle->doUpdateRestrictions(
|
|
|
|
|
$this->mRestrictions,
|
|
|
|
|
$expiry,
|
|
|
|
|
$this->mCascade,
|
|
|
|
|
$reasonstr,
|
2014-08-23 08:30:53 +00:00
|
|
|
$user
|
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() ) {
|
2018-10-26 15:39:07 +00:00
|
|
|
$this->show( $out->parseInlineAsInterface( $status->getWikiText() ) );
|
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 = '';
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( !Hooks::run( 'ProtectionForm::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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
WatchAction::doWatchOrUnwatch( $request->getCheck( 'mwProtectWatch' ), $this->mTitle, $user );
|
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
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildForm() {
|
2015-01-17 20:04:39 +00:00
|
|
|
$context = $this->mContext;
|
|
|
|
|
$user = $context->getUser();
|
|
|
|
|
$output = $context->getOutput();
|
|
|
|
|
$lang = $context->getLanguage();
|
2005-12-22 05:41:06 +00:00
|
|
|
$out = '';
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( !$this->disabled ) {
|
2014-08-23 08:30:53 +00:00
|
|
|
$output->addModules( 'mediawiki.legacy.protect' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$out .= Xml::openElement( 'form', [ 'method' => 'post',
|
2013-03-27 13:36:05 +00:00
|
|
|
'action' => $this->mTitle->getLocalURL( 'action=protect' ),
|
2016-02-17 09:09:32 +00:00
|
|
|
'id' => 'mw-Protect-Form' ] );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-03-12 15:19:29 +00:00
|
|
|
$out .= Xml::openElement( 'fieldset' ) .
|
2015-01-17 20:04:39 +00:00
|
|
|
Xml::element( 'legend', null, $context->msg( 'protect-legend' )->text() ) .
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::openElement( 'table', [ 'id' => 'mwProtectSet' ] ) .
|
2008-09-13 05:33:24 +00:00
|
|
|
Xml::openElement( 'tbody' );
|
2007-12-11 09:51:56 +00:00
|
|
|
|
2014-07-06 18:53:18 +00:00
|
|
|
$scExpiryOptions = wfMessage( 'protect-expiry-options' )->inContentLanguage()->text();
|
|
|
|
|
$showProtectOptions = $scExpiryOptions !== '-' && !$this->disabled;
|
|
|
|
|
|
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
|
2015-01-17 20:04:39 +00:00
|
|
|
$msg = $context->msg( 'restriction-' . $action );
|
2013-04-13 11:36:24 +00:00
|
|
|
$out .= "<tr><td>" .
|
2008-09-25 02:08:59 +00:00
|
|
|
Xml::openElement( 'fieldset' ) .
|
2011-08-17 14:10:41 +00:00
|
|
|
Xml::element( 'legend', null, $msg->exists() ? $msg->text() : $action ) .
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::openElement( 'table', [ 'id' => "mw-protect-table-$action" ] ) .
|
2008-09-25 02:08:59 +00:00
|
|
|
"<tr><td>" . $this->buildSelector( $action, $selected ) . "</td></tr><tr><td>";
|
2008-09-13 08:53:07 +00:00
|
|
|
|
2012-08-21 17:23:53 +00:00
|
|
|
$mProtectexpiry = Xml::label(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'protectexpiry' )->text(),
|
2012-08-21 17:23:53 +00:00
|
|
|
"mwProtectExpirySelection-$action"
|
|
|
|
|
);
|
|
|
|
|
$mProtectother = Xml::label(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'protect-othertime' )->text(),
|
2012-08-21 17:23:53 +00:00
|
|
|
"mwProtect-$action-expires"
|
|
|
|
|
);
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2015-09-28 12:43:19 +00:00
|
|
|
$expiryFormOptions = new XmlSelect(
|
|
|
|
|
"wpProtectExpirySelection-$action",
|
|
|
|
|
"mwProtectExpirySelection-$action",
|
|
|
|
|
$this->mExpirySelection[$action]
|
|
|
|
|
);
|
2015-07-30 20:00:41 +00:00
|
|
|
$expiryFormOptions->setAttribute( 'tabindex', '2' );
|
|
|
|
|
if ( $this->disabled ) {
|
|
|
|
|
$expiryFormOptions->setAttribute( 'disabled', 'disabled' );
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 15:30:37 +00:00
|
|
|
if ( $this->mExistingExpiry[$action] ) {
|
|
|
|
|
if ( $this->mExistingExpiry[$action] == 'infinity' ) {
|
2015-01-17 20:04:39 +00:00
|
|
|
$existingExpiryMessage = $context->msg( 'protect-existing-expiry-infinity' );
|
2014-08-29 15:30:37 +00:00
|
|
|
} else {
|
2015-01-17 20:04:39 +00:00
|
|
|
$timestamp = $lang->userTimeAndDate( $this->mExistingExpiry[$action], $user );
|
|
|
|
|
$d = $lang->userDate( $this->mExistingExpiry[$action], $user );
|
|
|
|
|
$t = $lang->userTime( $this->mExistingExpiry[$action], $user );
|
2015-09-28 12:43:19 +00:00
|
|
|
$existingExpiryMessage = $context->msg(
|
|
|
|
|
'protect-existing-expiry',
|
|
|
|
|
$timestamp,
|
|
|
|
|
$d,
|
|
|
|
|
$t
|
|
|
|
|
);
|
2014-08-29 15:30:37 +00:00
|
|
|
}
|
2015-07-30 20:00:41 +00:00
|
|
|
$expiryFormOptions->addOption( $existingExpiryMessage->text(), 'existing' );
|
2008-09-16 04:09:06 +00:00
|
|
|
}
|
2009-06-18 02:50:16 +00:00
|
|
|
|
2015-09-28 12:43:19 +00:00
|
|
|
$expiryFormOptions->addOption(
|
|
|
|
|
$context->msg( 'protect-othertime-op' )->text(),
|
|
|
|
|
'othertime'
|
|
|
|
|
);
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( explode( ',', $scExpiryOptions ) as $option ) {
|
2013-02-03 20:05:24 +00:00
|
|
|
if ( strpos( $option, ":" ) === false ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
$show = $value = $option;
|
|
|
|
|
} else {
|
2013-02-03 20:05:24 +00:00
|
|
|
list( $show, $value ) = explode( ":", $option );
|
2008-09-16 04:09:06 +00:00
|
|
|
}
|
2015-07-30 20:00:41 +00:00
|
|
|
$expiryFormOptions->addOption( $show, htmlspecialchars( $value ) );
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
# Add expiry dropdown
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $showProtectOptions && !$this->disabled ) {
|
2008-09-13 05:33:24 +00:00
|
|
|
$out .= "
|
2008-09-13 08:53:07 +00:00
|
|
|
<table><tr>
|
2008-09-13 05:33:24 +00:00
|
|
|
<td class='mw-label'>
|
|
|
|
|
{$mProtectexpiry}
|
|
|
|
|
</td>
|
|
|
|
|
<td class='mw-input'>" .
|
2015-07-30 20:00:41 +00:00
|
|
|
$expiryFormOptions->getHTML() .
|
2008-09-13 05:33:24 +00:00
|
|
|
"</td>
|
2008-09-13 08:53:07 +00:00
|
|
|
</tr></table>";
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
# Add custom expiry field
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs = [ 'id' => "mwProtect-$action-expires" ] + $this->disabledAttrib;
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= "<table><tr>
|
2008-09-13 05:33:24 +00:00
|
|
|
<td class='mw-label'>" .
|
|
|
|
|
$mProtectother .
|
|
|
|
|
'</td>
|
|
|
|
|
<td class="mw-input">' .
|
2008-09-24 11:53:03 +00:00
|
|
|
Xml::input( "mwProtect-expiry-$action", 50, $this->mExpiry[$action], $attribs ) .
|
2008-09-13 05:33:24 +00:00
|
|
|
'</td>
|
2008-09-13 08:53:07 +00:00
|
|
|
</tr></table>';
|
2008-09-25 02:08:59 +00:00
|
|
|
$out .= "</td></tr>" .
|
|
|
|
|
Xml::closeElement( 'table' ) .
|
|
|
|
|
Xml::closeElement( 'fieldset' ) .
|
|
|
|
|
"</td></tr>";
|
2008-09-06 23:20:58 +00:00
|
|
|
}
|
2009-10-02 18:46:19 +00:00
|
|
|
# Give extensions a chance to add items to the form
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ProtectionForm::buildForm', [ $this->mArticle, &$out ] );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
|
2007-03-19 07:08:58 +00:00
|
|
|
|
2008-09-13 08:53:07 +00:00
|
|
|
// JavaScript will add another row with a value-chaining checkbox
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $this->mTitle->exists() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table2' ] ) .
|
2008-09-13 08:53:07 +00:00
|
|
|
Xml::openElement( 'tbody' );
|
2008-03-12 15:19:29 +00:00
|
|
|
$out .= '<tr>
|
|
|
|
|
<td></td>
|
2008-04-16 15:58:25 +00:00
|
|
|
<td class="mw-input">' .
|
2012-08-21 17:23:53 +00:00
|
|
|
Xml::checkLabel(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'protect-cascade' )->text(),
|
2012-08-21 17:23:53 +00:00
|
|
|
'mwProtect-cascade',
|
|
|
|
|
'mwProtect-cascade',
|
|
|
|
|
$this->mCascade, $this->disabledAttrib
|
|
|
|
|
) .
|
2008-03-12 15:19:29 +00:00
|
|
|
"</td>
|
|
|
|
|
</tr>\n";
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
|
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 ) {
|
2014-07-06 18:53:18 +00:00
|
|
|
$mProtectreasonother = Xml::label(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'protectcomment' )->text(),
|
2014-07-06 18:53:18 +00:00
|
|
|
'wpProtectReasonSelection'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$mProtectreason = Xml::label(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'protect-otherreason' )->text(),
|
2014-07-06 18:53:18 +00:00
|
|
|
'mwProtect-reason'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$reasonDropDown = Xml::listDropDown( 'wpProtectReasonSelection',
|
|
|
|
|
wfMessage( 'protect-dropdown' )->inContentLanguage()->text(),
|
|
|
|
|
wfMessage( 'protect-otherreason-op' )->inContentLanguage()->text(),
|
|
|
|
|
$this->mReasonSelection,
|
|
|
|
|
'mwProtect-reason', 4 );
|
|
|
|
|
|
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;
|
2018-02-08 21:22:34 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table3' ] ) .
|
2008-09-13 08:53:07 +00:00
|
|
|
Xml::openElement( 'tbody' );
|
2008-09-06 23:20:58 +00:00
|
|
|
$out .= "
|
|
|
|
|
<tr>
|
|
|
|
|
<td class='mw-label'>
|
|
|
|
|
{$mProtectreasonother}
|
|
|
|
|
</td>
|
|
|
|
|
<td class='mw-input'>
|
|
|
|
|
{$reasonDropDown}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td class='mw-label'>
|
|
|
|
|
{$mProtectreason}
|
|
|
|
|
</td>
|
|
|
|
|
<td class='mw-input'>" .
|
2016-02-17 09:09:32 +00:00
|
|
|
Xml::input( 'mwProtect-reason', 60, $this->mReason, [ 'type' => 'text',
|
2018-02-08 21:22:34 +00:00
|
|
|
'id' => 'mwProtect-reason', 'maxlength' => $maxlength ] ) .
|
2008-03-12 15:19:29 +00:00
|
|
|
"</td>
|
2009-11-14 11:07:46 +00:00
|
|
|
</tr>";
|
|
|
|
|
# Disallow watching is user is not logged in
|
2014-08-23 08:30:53 +00:00
|
|
|
if ( $user->isLoggedIn() ) {
|
2009-11-14 11:07:46 +00:00
|
|
|
$out .= "
|
2008-03-12 15:19:29 +00:00
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
2008-04-16 15:58:25 +00:00
|
|
|
<td class='mw-input'>" .
|
2015-01-17 20:04:39 +00:00
|
|
|
Xml::checkLabel( $context->msg( 'watchthis' )->text(),
|
2008-03-12 15:19:29 +00:00
|
|
|
'mwProtectWatch', 'mwProtectWatch',
|
2014-08-23 08:30:53 +00:00
|
|
|
$user->isWatched( $this->mTitle ) || $user->getOption( 'watchdefault' ) ) .
|
2008-03-12 15:19:29 +00:00
|
|
|
"</td>
|
2009-11-14 11:07:46 +00:00
|
|
|
</tr>";
|
|
|
|
|
}
|
|
|
|
|
$out .= "
|
2008-03-12 15:19:29 +00:00
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
2008-04-16 15:58:25 +00:00
|
|
|
<td class='mw-submit'>" .
|
2012-08-21 17:23:53 +00:00
|
|
|
Xml::submitButton(
|
2015-01-17 20:04:39 +00:00
|
|
|
$context->msg( 'confirm' )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'id' => 'mw-Protect-submit' ]
|
2012-08-21 17:23:53 +00:00
|
|
|
) .
|
2008-03-12 15:19:29 +00:00
|
|
|
"</td>
|
|
|
|
|
</tr>\n";
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' );
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::closeElement( 'fieldset' );
|
2007-01-22 08:26:41 +00:00
|
|
|
|
2014-08-23 08:30:53 +00:00
|
|
|
if ( $user->isAllowed( 'editinterface' ) ) {
|
2017-01-18 20:55:20 +00:00
|
|
|
$linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
|
|
|
|
|
$link = $linkRenderer->makeKnownLink(
|
2014-12-13 19:55:13 +00:00
|
|
|
$context->msg( 'protect-dropdown' )->inContentLanguage()->getTitle(),
|
2017-01-18 20:55:20 +00:00
|
|
|
$context->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 ) {
|
2014-05-12 14:42:51 +00:00
|
|
|
$out .= Html::hidden(
|
|
|
|
|
'wpEditToken',
|
2016-02-17 09:09:32 +00:00
|
|
|
$user->getEditToken( [ 'protect', $this->mTitle->getPrefixedDBkey() ] )
|
2014-05-12 14:42:51 +00:00
|
|
|
);
|
2010-09-04 04:00:09 +00:00
|
|
|
$out .= Xml::closeElement( 'form' );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
return $out;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2010-05-23 19:25:07 +00:00
|
|
|
/**
|
|
|
|
|
* Build protection level selector
|
|
|
|
|
*
|
2014-04-20 19:16:57 +00:00
|
|
|
* @param string $action Action to protect
|
|
|
|
|
* @param string $selected Current protection level
|
|
|
|
|
* @return string HTML fragment
|
2010-05-23 19:25:07 +00:00
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildSelector( $action, $selected ) {
|
2013-06-28 20:49:47 +00:00
|
|
|
// If the form is disabled, display all relevant levels. Otherwise,
|
|
|
|
|
// just show the ones this user can use.
|
|
|
|
|
$levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(),
|
2014-08-23 08:30:53 +00:00
|
|
|
$this->disabled ? null : $this->mContext->getUser()
|
2013-06-28 20:49:47 +00:00
|
|
|
);
|
2008-09-07 08:24:00 +00:00
|
|
|
|
|
|
|
|
$id = 'mwProtect-level-' . $action;
|
|
|
|
|
|
2015-07-30 20:00:41 +00:00
|
|
|
$select = new XmlSelect( $id, $id, $selected );
|
|
|
|
|
$select->setAttribute( 'size', count( $levels ) );
|
|
|
|
|
if ( $this->disabled ) {
|
|
|
|
|
$select->setAttribute( 'disabled', 'disabled' );
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
foreach ( $levels as $key ) {
|
2015-07-30 20:00:41 +00:00
|
|
|
$select->addOption( $this->getOptionLabel( $key ), $key );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2015-07-30 20:00:41 +00:00
|
|
|
|
|
|
|
|
return $select->getHTML();
|
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
|
|
|
|
|
*
|
2019-03-10 18:12:48 +00:00
|
|
|
* @param OutputPage $out
|
2005-12-22 05:41:06 +00:00
|
|
|
*/
|
2019-03-11 09:34:23 +00:00
|
|
|
private function showLogExtract( OutputPage $out ) {
|
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' );
|
|
|
|
|
$out->addHTML( Xml::element( 'h2', null, $protectLogPage->getName()->text() ) );
|
2011-09-24 17:52:53 +00:00
|
|
|
LogEventsList::showLogExtract( $out, 'protect', $this->mTitle );
|
2009-10-02 18:46:19 +00:00
|
|
|
# Let extensions add other relevant log extracts
|
2016-02-17 09:09:32 +00:00
|
|
|
Hooks::run( 'ProtectionForm::showLogExtract', [ $this->mArticle, $out ] );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2007-12-01 09:08:43 +00:00
|
|
|
}
|