2005-12-22 05:41:06 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2005 Brion Vibber <brion@pobox.com>
|
|
|
|
|
* http://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
|
|
|
|
|
*/
|
|
|
|
|
|
2007-04-04 05:22:37 +00:00
|
|
|
/**
|
|
|
|
|
* @todo document, briefly.
|
|
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
class ProtectionForm {
|
2008-09-16 04:09:06 +00:00
|
|
|
/** A map of action to restriction level, from request or default */
|
2005-12-22 05:41:06 +00:00
|
|
|
var $mRestrictions = array();
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
/** The custom/additional protection reason */
|
2005-12-22 05:41:06 +00:00
|
|
|
var $mReason = '';
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
/** The reason selected from the list, blank for other/additional */
|
|
|
|
|
var $mReasonSelection = '';
|
|
|
|
|
|
|
|
|
|
/** True if the restrictions are cascading, from request or existing protection */
|
2007-01-10 23:32:38 +00:00
|
|
|
var $mCascade = false;
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
/** Map of action to "other" expiry time. Used in preference to mExpirySelection. */
|
|
|
|
|
var $mExpiry = array();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map of action to value selected in expiry drop-down list.
|
|
|
|
|
* Will be set to 'othertime' whenever mExpiry is set.
|
|
|
|
|
*/
|
|
|
|
|
var $mExpirySelection = array();
|
|
|
|
|
|
|
|
|
|
/** Permissions errors for the protect action */
|
2007-12-01 09:08:43 +00:00
|
|
|
var $mPermErrors = array();
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
/** Types (i.e. actions) for which levels can be selected */
|
2007-12-11 09:51:56 +00:00
|
|
|
var $mApplicableTypes = array();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
/** Map of action to the expiry time of the existing protection */
|
|
|
|
|
var $mExistingExpiry = array();
|
|
|
|
|
|
2008-09-11 20:01:39 +00:00
|
|
|
function __construct( Article $article ) {
|
2007-01-23 07:29:58 +00:00
|
|
|
global $wgRequest, $wgUser;
|
2005-12-22 05:41:06 +00:00
|
|
|
global $wgRestrictionTypes, $wgRestrictionLevels;
|
2008-09-11 20:01:39 +00:00
|
|
|
$this->mArticle = $article;
|
|
|
|
|
$this->mTitle = $article->mTitle;
|
2007-12-11 09:51:56 +00:00
|
|
|
$this->mApplicableTypes = $this->mTitle->exists() ? $wgRestrictionTypes : array('create');
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
$this->mCascade = $this->mTitle->areRestrictionsCascading();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
// The form will be available in read-only to show levels.
|
2008-09-16 04:09:06 +00:00
|
|
|
$this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect',$wgUser);
|
|
|
|
|
$this->disabled = wfReadOnly() || $this->mPermErrors != array();
|
2005-12-22 05:41:06 +00:00
|
|
|
$this->disabledAttrib = $this->disabled
|
|
|
|
|
? array( 'disabled' => 'disabled' )
|
|
|
|
|
: array();
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-06 07:20:13 +00:00
|
|
|
$this->mReason = $wgRequest->getText( 'mwProtect-reason' );
|
2008-09-16 04:09:06 +00:00
|
|
|
$this->mReasonSelection = $wgRequest->getText( 'wpProtectReasonSelection' );
|
2008-09-06 17:12:45 +00:00
|
|
|
$this->mCascade = $wgRequest->getBool( 'mwProtect-cascade', $this->mCascade );
|
2008-09-16 04:09:06 +00:00
|
|
|
|
2008-09-06 07:20:13 +00:00
|
|
|
foreach( $this->mApplicableTypes as $action ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
// Fixme: this form currently requires individual selections,
|
|
|
|
|
// but the db allows multiples separated by commas.
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
|
|
$requestExpiry = $wgRequest->getText( "mwProtect-expiry-$action" );
|
|
|
|
|
$requestExpirySelection = $wgRequest->getVal( "wpProtectExpirySelection-$action" );
|
|
|
|
|
|
|
|
|
|
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;
|
2008-09-16 18:46:58 +00:00
|
|
|
} elseif ( $existingExpiry == 'infinity' ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
// Existing expiry is infinite, use "infinite" in drop-down
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = 'infinite';
|
|
|
|
|
} elseif ( $existingExpiry ) {
|
|
|
|
|
// Use existing expiry in its own list item
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = $existingExpiry;
|
|
|
|
|
} else {
|
|
|
|
|
// Final default: infinite
|
|
|
|
|
$this->mExpiry[$action] = '';
|
|
|
|
|
$this->mExpirySelection[$action] = 'infinite';
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-06 07:20:13 +00:00
|
|
|
$val = $wgRequest->getVal( "mwProtect-level-$action" );
|
|
|
|
|
if( isset( $val ) && in_array( $val, $wgRestrictionLevels ) ) {
|
|
|
|
|
// Prevent users from setting levels that they cannot later unset
|
|
|
|
|
if( $val == 'sysop' ) {
|
|
|
|
|
// Special case, rewrite sysop to either protect and editprotected
|
|
|
|
|
if( !$wgUser->isAllowed('protect') && !$wgUser->isAllowed('editprotected') )
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if( !$wgUser->isAllowed($val) )
|
|
|
|
|
continue;
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
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
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get the expiry time for a given action, by combining the relevant inputs.
|
|
|
|
|
* Returns a 14-char timestamp or "infinity", or false if the input was invalid
|
|
|
|
|
*/
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
if ( $value == 'infinite' || $value == 'indefinite' || $value == 'infinity' ) {
|
|
|
|
|
$time = Block::infinity();
|
|
|
|
|
} else {
|
|
|
|
|
$unix = strtotime( $value );
|
|
|
|
|
|
|
|
|
|
if ( !$unix || $unix === -1 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fixme: non-qualified absolute times are not in users specified timezone
|
|
|
|
|
// and there isn't notice about it in the ui
|
|
|
|
|
$time = wfTimestamp( TS_MW, $unix );
|
|
|
|
|
}
|
|
|
|
|
return $time;
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-22 20:59:00 +00:00
|
|
|
function execute() {
|
2007-06-26 21:24:23 +00:00
|
|
|
global $wgRequest, $wgOut;
|
2007-01-22 20:59:00 +00:00
|
|
|
if( $wgRequest->wasPosted() ) {
|
2007-01-22 08:26:41 +00:00
|
|
|
if( $this->save() ) {
|
2008-09-11 20:01:39 +00:00
|
|
|
$q = $this->mArticle->isRedirect() ? 'redirect=no' : '';
|
2007-06-26 21:24:23 +00:00
|
|
|
$wgOut->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
|
|
|
|
2007-01-22 08:26:41 +00:00
|
|
|
function show( $err = null ) {
|
2007-04-02 07:39:32 +00:00
|
|
|
global $wgOut, $wgUser;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-07-23 19:05:43 +00:00
|
|
|
$wgOut->setRobotPolicy( 'noindex,nofollow' );
|
2005-12-22 05:41:06 +00:00
|
|
|
|
|
|
|
|
if( is_null( $this->mTitle ) ||
|
|
|
|
|
$this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
|
2006-06-07 06:40:24 +00:00
|
|
|
$wgOut->showFatalError( wfMsg( 'badarticleerror' ) );
|
2005-12-22 05:41:06 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-05-08 09:09:46 +00:00
|
|
|
list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
|
2007-01-12 04:43:33 +00:00
|
|
|
|
2007-01-22 08:26:41 +00:00
|
|
|
if ( "" != $err ) {
|
|
|
|
|
$wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
|
|
|
|
|
$wgOut->addHTML( "<p class='error'>{$err}</p>\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-12 08:37:07 +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
|
|
|
}
|
|
|
|
|
|
2008-02-18 07:25:35 +00:00
|
|
|
$wgOut->wrapWikiMsg( "$1\n$titles", array( 'protect-cascadeon', count($cascadeSources) ) );
|
2007-01-12 04:43:33 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-12 15:19:29 +00:00
|
|
|
$sk = $wgUser->getSkin();
|
2008-03-12 15:48:11 +00:00
|
|
|
$titleLink = $sk->makeLinkObj( $this->mTitle );
|
2008-03-12 15:19:29 +00:00
|
|
|
$wgOut->setPageTitle( wfMsg( 'protect-title', $this->mTitle->getPrefixedText() ) );
|
|
|
|
|
$wgOut->setSubtitle( wfMsg( 'protect-backlink', $titleLink ) );
|
2006-01-07 13:31:29 +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
|
|
|
|
|
if( $this->disabled ) {
|
2008-01-15 01:55:48 +00:00
|
|
|
if( wfReadOnly() ) {
|
|
|
|
|
$wgOut->readOnlyPage();
|
2008-02-18 07:25:35 +00:00
|
|
|
} elseif( $this->mPermErrors ) {
|
|
|
|
|
$wgOut->addWikiText( $wgOut->formatPermissionsErrorMessage( $this->mPermErrors ) );
|
2008-01-15 01:55:48 +00:00
|
|
|
}
|
2007-04-02 07:39:32 +00:00
|
|
|
} else {
|
2008-02-18 07:25:35 +00:00
|
|
|
$wgOut->addWikiMsg( 'protect-text', $this->mTitle->getPrefixedText() );
|
2007-04-02 07:39:32 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
$wgOut->addHTML( $this->buildForm() );
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
$this->showLogExtract( $wgOut );
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
function save() {
|
2006-01-10 16:19:32 +00:00
|
|
|
global $wgRequest, $wgUser, $wgOut;
|
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
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
$token = $wgRequest->getVal( 'wpEditToken' );
|
2008-09-06 23:20:58 +00:00
|
|
|
if ( !$wgUser->matchEditToken( $token ) ) {
|
2007-01-22 20:59:00 +00:00
|
|
|
$this->show( wfMsg( 'sessionfailure' ) );
|
|
|
|
|
return false;
|
2005-12-22 05:41:06 +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
|
|
|
|
|
$reasonstr .= ': ' . $this->mReason;
|
|
|
|
|
} elseif ( $reasonstr == 'other' ) {
|
|
|
|
|
$reasonstr = $this->mReason;
|
|
|
|
|
}
|
2008-09-13 05:33:24 +00:00
|
|
|
$expiry = array();
|
|
|
|
|
foreach( $this->mApplicableTypes as $action ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
$expiry[$action] = $this->getExpiry( $action );
|
|
|
|
|
if ( !$expiry[$action] ) {
|
|
|
|
|
$this->show( wfMsg( 'protect_expiry_invalid' ) );
|
|
|
|
|
return false;
|
2007-01-22 08:26:41 +00:00
|
|
|
}
|
2008-09-16 04:09:06 +00:00
|
|
|
if ( $expiry[$action] < wfTimestampNow() ) {
|
|
|
|
|
$this->show( wfMsg( 'protect_expiry_old' ) );
|
|
|
|
|
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
|
|
|
|
2008-06-21 03:17:35 +00:00
|
|
|
# They shouldn't be able to do this anyway, but just to make sure, ensure that cascading restrictions aren't being applied
|
|
|
|
|
# to a semi-protected page.
|
|
|
|
|
global $wgGroupPermissions;
|
2007-09-10 06:27:36 +00:00
|
|
|
|
2008-06-21 03:17:35 +00:00
|
|
|
$edit_restriction = $this->mRestrictions['edit'];
|
2008-09-14 01:11:54 +00:00
|
|
|
$this->mCascade = $wgRequest->getBool( 'mwProtect-cascade' );
|
2008-06-21 03:17:35 +00:00
|
|
|
if ($this->mCascade && ($edit_restriction != 'protect') &&
|
|
|
|
|
!(isset($wgGroupPermissions[$edit_restriction]['protect']) && $wgGroupPermissions[$edit_restriction]['protect'] ) )
|
|
|
|
|
$this->mCascade = false;
|
|
|
|
|
|
|
|
|
|
if ($this->mTitle->exists()) {
|
2008-09-06 23:20:58 +00:00
|
|
|
$ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $reasonstr, $this->mCascade, $expiry );
|
2007-12-11 09:51:56 +00:00
|
|
|
} else {
|
2008-09-13 05:33:24 +00:00
|
|
|
$ok = $this->mTitle->updateTitleProtection( $this->mRestrictions['create'], $reasonstr, $expiry['create'] );
|
2007-12-11 09:51:56 +00:00
|
|
|
}
|
|
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
if( !$ok ) {
|
2006-06-07 06:40:24 +00:00
|
|
|
throw new FatalError( "Unknown error at restriction save time." );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-06-05 02:18:49 +00:00
|
|
|
if( $wgRequest->getCheck( 'mwProtectWatch' ) ) {
|
|
|
|
|
$this->mArticle->doWatch();
|
|
|
|
|
} elseif( $this->mTitle->userIsWatching() ) {
|
|
|
|
|
$this->mArticle->doUnwatch();
|
|
|
|
|
}
|
2005-12-22 05:41:06 +00:00
|
|
|
return $ok;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-03-13 10:05:11 +00:00
|
|
|
/**
|
|
|
|
|
* Build the input form
|
|
|
|
|
*
|
|
|
|
|
* @return $out string HTML form
|
|
|
|
|
*/
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildForm() {
|
2008-09-16 04:09:06 +00:00
|
|
|
global $wgUser, $wgLang;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
$mProtectreasonother = Xml::label( wfMsg( 'protectcomment' ), 'wpProtectReasonSelection' );
|
2008-09-06 23:20:58 +00:00
|
|
|
$mProtectreason = Xml::label( wfMsg( 'protect-otherreason' ), 'mwProtect-reason' );
|
|
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
$out = '';
|
|
|
|
|
if( !$this->disabled ) {
|
|
|
|
|
$out .= $this->buildScript();
|
2008-09-06 23:20:58 +00:00
|
|
|
$out .= Xml::openElement( 'form', array( 'method' => 'post',
|
|
|
|
|
'action' => $this->mTitle->getLocalUrl( 'action=protect' ),
|
2008-09-16 04:09:06 +00:00
|
|
|
'id' => 'mw-Protect-Form', 'onsubmit' => 'ProtectionForm.enableUnchainedInputs(true)' ) );
|
2008-09-06 23:20:58 +00:00
|
|
|
$out .= Xml::hidden( 'wpEditToken',$wgUser->editToken() );
|
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' ) .
|
|
|
|
|
Xml::element( 'legend', null, wfMsg( 'protect-legend' ) ) .
|
2008-03-19 00:08:58 +00:00
|
|
|
Xml::openElement( 'table', array( 'id' => 'mwProtectSet' ) ) .
|
2008-09-13 05:33:24 +00:00
|
|
|
Xml::openElement( 'tbody' );
|
2007-12-11 09:51:56 +00:00
|
|
|
|
2008-09-13 05:33:24 +00:00
|
|
|
foreach( $this->mRestrictions as $action => $selected ) {
|
2006-02-18 15:07:02 +00:00
|
|
|
/* Not all languages have V_x <-> N_x relation */
|
2008-09-07 08:28:45 +00:00
|
|
|
$msg = wfMsg( 'restriction-' . $action );
|
|
|
|
|
if( wfEmptyMsg( 'restriction-' . $action, $msg ) ) {
|
|
|
|
|
$msg = $action;
|
|
|
|
|
}
|
2008-09-25 02:08:59 +00:00
|
|
|
$out .= "<tr><td>".
|
|
|
|
|
Xml::openElement( 'fieldset' ) .
|
|
|
|
|
Xml::element( 'legend', null, $msg ) .
|
|
|
|
|
Xml::openElement( 'table', array( 'id' => "mw-protect-table-$action" ) ) .
|
|
|
|
|
"<tr><td>" . $this->buildSelector( $action, $selected ) . "</td></tr><tr><td>";
|
2008-09-13 08:53:07 +00:00
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
$reasonDropDown = Xml::listDropDown( 'wpProtectReasonSelection',
|
2008-09-13 08:53:07 +00:00
|
|
|
wfMsgForContent( 'protect-dropdown' ),
|
2008-09-16 04:09:06 +00:00
|
|
|
wfMsgForContent( 'protect-otherreason-op' ),
|
|
|
|
|
$this->mReasonSelection,
|
|
|
|
|
'mwProtect-reason', 4 );
|
2008-09-29 01:35:04 +00:00
|
|
|
$scExpiryOptions = wfMsgForContent( 'protect-expiry-options' );
|
2008-09-13 05:33:24 +00:00
|
|
|
|
|
|
|
|
$showProtectOptions = ($scExpiryOptions !== '-' && !$this->disabled);
|
2008-09-13 08:53:07 +00:00
|
|
|
|
2008-09-16 04:09:06 +00:00
|
|
|
$mProtectexpiry = Xml::label( wfMsg( 'protectexpiry' ), "mwProtectExpirySelection-$action" );
|
2008-09-13 05:33:24 +00:00
|
|
|
$mProtectother = Xml::label( wfMsg( 'protect-othertime' ), "mwProtect-$action-expires" );
|
2008-09-16 04:09:06 +00:00
|
|
|
|
|
|
|
|
$expiryFormOptions = '';
|
|
|
|
|
if ( $this->mExistingExpiry[$action] && $this->mExistingExpiry[$action] != 'infinity' ) {
|
|
|
|
|
$expiryFormOptions .=
|
|
|
|
|
Xml::option(
|
|
|
|
|
wfMsg( 'protect-existing-expiry', $wgLang->timeanddate( $this->mExistingExpiry[$action] ) ),
|
|
|
|
|
'existing',
|
|
|
|
|
$this->mExpirySelection[$action] == 'existing'
|
|
|
|
|
) . "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expiryFormOptions .= Xml::option( wfMsg( 'protect-othertime-op' ), "othertime" ) . "\n";
|
2008-09-13 05:33:24 +00:00
|
|
|
foreach( explode(',', $scExpiryOptions) as $option ) {
|
2008-09-16 04:09:06 +00:00
|
|
|
if ( strpos($option, ":") === false ) {
|
|
|
|
|
$show = $value = $option;
|
|
|
|
|
} else {
|
|
|
|
|
list($show, $value) = explode(":", $option);
|
|
|
|
|
}
|
2008-09-13 05:33:24 +00:00
|
|
|
$show = htmlspecialchars($show);
|
|
|
|
|
$value = htmlspecialchars($value);
|
2008-09-16 04:09:06 +00:00
|
|
|
$expiryFormOptions .= Xml::option( $show, $value, $this->mExpirySelection[$action] === $value ) . "\n";
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
# Add expiry dropdown
|
|
|
|
|
if( $showProtectOptions && !$this->disabled ) {
|
|
|
|
|
$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'>" .
|
|
|
|
|
Xml::tags( 'select',
|
|
|
|
|
array(
|
2008-09-16 04:09:06 +00:00
|
|
|
'id' => "mwProtectExpirySelection-$action",
|
|
|
|
|
'name' => "wpProtectExpirySelection-$action",
|
|
|
|
|
'onchange' => "ProtectionForm.updateExpiryList(this)",
|
2008-09-13 05:33:24 +00:00
|
|
|
'tabindex' => '2' ) + $this->disabledAttrib,
|
|
|
|
|
$expiryFormOptions ) .
|
|
|
|
|
"</td>
|
2008-09-13 08:53:07 +00:00
|
|
|
</tr></table>";
|
2008-09-13 05:33:24 +00:00
|
|
|
}
|
|
|
|
|
# Add custom expiry field
|
2008-09-16 04:09:06 +00:00
|
|
|
$attribs = array( 'id' => "mwProtect-$action-expires", 'onkeyup' => 'ProtectionForm.updateExpiry(this)' ) + $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
|
|
|
}
|
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
|
2008-06-11 21:36:07 +00:00
|
|
|
if( $this->mTitle->exists() ) {
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::openElement( 'table', array( 'id' => 'mw-protect-table2' ) ) .
|
|
|
|
|
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">' .
|
2008-09-06 23:20:58 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'protect-cascade' ), '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
|
|
|
}
|
2008-09-13 08:53:07 +00:00
|
|
|
|
|
|
|
|
# Add manual and custom reason field/selects as well as submit
|
2005-12-22 05:41:06 +00:00
|
|
|
if( !$this->disabled ) {
|
2008-09-13 08:53:07 +00:00
|
|
|
$out .= Xml::openElement( 'table', array( 'id' => 'mw-protect-table3' ) ) .
|
|
|
|
|
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'>" .
|
|
|
|
|
Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text',
|
|
|
|
|
'id' => 'mwProtect-reason', 'maxlength' => 255 ) ) .
|
2008-03-12 15:19:29 +00:00
|
|
|
"</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
2008-04-16 15:58:25 +00:00
|
|
|
<td class='mw-input'>" .
|
2008-03-12 15:19:29 +00:00
|
|
|
Xml::checkLabel( wfMsg( 'watchthis' ),
|
|
|
|
|
'mwProtectWatch', 'mwProtectWatch',
|
|
|
|
|
$this->mTitle->userIsWatching() || $wgUser->getOption( 'watchdefault' ) ) .
|
|
|
|
|
"</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
2008-04-16 15:58:25 +00:00
|
|
|
<td class='mw-submit'>" .
|
2008-03-12 15:19:29 +00:00
|
|
|
Xml::submitButton( wfMsg( 'confirm' ), array( 'id' => 'mw-Protect-submit' ) ) .
|
|
|
|
|
"</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
|
|
|
|
2008-09-22 16:16:37 +00:00
|
|
|
if ( $wgUser->isAllowed( 'editinterface' ) ) {
|
|
|
|
|
$linkTitle = Title::makeTitleSafe( NS_MEDIAWIKI, 'protect-dropdown' );
|
|
|
|
|
$link = $wgUser->getSkin()->Link ( $linkTitle, wfMsgHtml( 'protect-edit-reasonlist' ) );
|
|
|
|
|
$out .= '<p class="mw-protect-editreasons">' . $link . '</p>';
|
|
|
|
|
}
|
|
|
|
|
|
2007-01-22 08:26:41 +00:00
|
|
|
if ( !$this->disabled ) {
|
2008-03-12 15:19:29 +00:00
|
|
|
$out .= Xml::closeElement( 'form' ) .
|
|
|
|
|
$this->buildCleanupScript();
|
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
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildSelector( $action, $selected ) {
|
2008-05-24 16:49:05 +00:00
|
|
|
global $wgRestrictionLevels, $wgUser;
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2008-09-07 08:24:00 +00:00
|
|
|
$levels = array();
|
2005-12-22 05:41:06 +00:00
|
|
|
foreach( $wgRestrictionLevels as $key ) {
|
2008-05-24 16:49:05 +00:00
|
|
|
//don't let them choose levels above their own (aka so they can still unprotect and edit the page). but only when the form isn't disabled
|
|
|
|
|
if( $key == 'sysop' ) {
|
|
|
|
|
//special case, rewrite sysop to protect and editprotected
|
2008-07-02 01:44:20 +00:00
|
|
|
if( !$wgUser->isAllowed('protect') && !$wgUser->isAllowed('editprotected') && !$this->disabled )
|
2008-05-24 16:49:05 +00:00
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
if( !$wgUser->isAllowed($key) && !$this->disabled )
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-09-07 08:24:00 +00:00
|
|
|
$levels[] = $key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$id = 'mwProtect-level-' . $action;
|
|
|
|
|
$attribs = array(
|
|
|
|
|
'id' => $id,
|
|
|
|
|
'name' => $id,
|
|
|
|
|
'size' => count( $levels ),
|
2008-09-16 04:09:06 +00:00
|
|
|
'onchange' => 'ProtectionForm.updateLevels(this)',
|
2008-09-07 08:24:00 +00:00
|
|
|
) + $this->disabledAttrib;
|
|
|
|
|
|
|
|
|
|
$out = Xml::openElement( 'select', $attribs );
|
|
|
|
|
foreach( $levels as $key ) {
|
2007-08-11 16:24:01 +00:00
|
|
|
$out .= Xml::option( $this->getOptionLabel( $key ), $key, $key == $selected );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2008-03-12 15:19:29 +00:00
|
|
|
$out .= Xml::closeElement( 'select' );
|
2005-12-22 05:41:06 +00:00
|
|
|
return $out;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2007-08-11 16:24:01 +00:00
|
|
|
/**
|
|
|
|
|
* Prepare the label for a protection selector option
|
|
|
|
|
*
|
|
|
|
|
* @param string $permission Permission required
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function getOptionLabel( $permission ) {
|
|
|
|
|
if( $permission == '' ) {
|
|
|
|
|
return wfMsg( 'protect-default' );
|
|
|
|
|
} else {
|
|
|
|
|
$key = "protect-level-{$permission}";
|
|
|
|
|
$msg = wfMsg( $key );
|
|
|
|
|
if( wfEmptyMsg( $key, $msg ) )
|
|
|
|
|
$msg = wfMsg( 'protect-fallback', $permission );
|
|
|
|
|
return $msg;
|
|
|
|
|
}
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildScript() {
|
2006-10-13 21:48:19 +00:00
|
|
|
global $wgStylePath, $wgStyleVersion;
|
2008-04-16 17:40:47 +00:00
|
|
|
return Xml::tags( 'script', array(
|
|
|
|
|
'type' => 'text/javascript',
|
2008-09-16 04:09:06 +00:00
|
|
|
'src' => $wgStylePath . "/common/protect.js?$wgStyleVersion.1" ), '' );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
function buildCleanupScript() {
|
2007-03-15 02:52:28 +00:00
|
|
|
global $wgRestrictionLevels, $wgGroupPermissions;
|
|
|
|
|
$script = 'var wgCascadeableLevels=';
|
|
|
|
|
$CascadeableLevels = array();
|
|
|
|
|
foreach( $wgRestrictionLevels as $key ) {
|
2008-06-21 03:17:35 +00:00
|
|
|
if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
|
2008-03-12 15:19:29 +00:00
|
|
|
$CascadeableLevels[] = "'" . Xml::escapeJsString( $key ) . "'";
|
2007-03-15 02:52:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$script .= "[" . implode(',',$CascadeableLevels) . "];\n";
|
2008-09-16 04:09:06 +00:00
|
|
|
$options = (object)array(
|
2008-09-25 02:08:59 +00:00
|
|
|
'tableId' => 'mw-protect-table-move',
|
2008-09-16 04:09:06 +00:00
|
|
|
'labelText' => wfMsg( 'protect-unchain' ),
|
|
|
|
|
'numTypes' => count($this->mApplicableTypes),
|
|
|
|
|
'existingMatch' => 1 == count( array_unique( $this->mExistingExpiry ) ),
|
|
|
|
|
);
|
|
|
|
|
$encOptions = Xml::encodeJsVar( $options );
|
|
|
|
|
|
|
|
|
|
$script .= "ProtectionForm.init($encOptions)";
|
2008-04-16 15:58:25 +00:00
|
|
|
return Xml::tags( 'script', array( 'type' => 'text/javascript' ), $script );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-12-22 05:41:06 +00:00
|
|
|
/**
|
|
|
|
|
* @param OutputPage $out
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
function showLogExtract( &$out ) {
|
2007-06-02 00:41:16 +00:00
|
|
|
# Show relevant lines from the protection log:
|
2008-03-12 15:19:29 +00:00
|
|
|
$out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'protect' ) ) );
|
2008-04-02 20:20:47 +00:00
|
|
|
LogEventsList::showLogExtract( $out, 'protect', $this->mTitle->getPrefixedText() );
|
2005-12-22 05:41:06 +00:00
|
|
|
}
|
2007-12-01 09:08:43 +00:00
|
|
|
}
|