* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
- *
- * @addtogroup SpecialPage
*/
+/**
+ * @todo document, briefly.
+ * @addtogroup SpecialPage
+ */
class ProtectionForm {
var $mRestrictions = array();
var $mReason = '';
var $mExpiry = null;
function __construct( &$article ) {
- global $wgRequest, $wgUser, $wgLang;
+ global $wgRequest, $wgUser;
global $wgRestrictionTypes, $wgRestrictionLevels;
$this->mArticle =& $article;
$this->mTitle =& $article->mTitle;
} else if ( strlen($this->mTitle->mRestrictionsExpiry) == 0 ) {
$this->mExpiry = '';
} else {
- $this->mExpiry = $wgLang->timeanddate( $this->mTitle->mRestrictionsExpiry );
+ $this->mExpiry = wfTimestamp( TS_RFC2822, $this->mTitle->mRestrictionsExpiry );
}
}
$this->mRestrictions[$action] = $val;
}
}
-
+ }
+ }
+
+ function execute() {
+ global $wgRequest;
+ if( $wgRequest->wasPosted() ) {
if( $this->save() ) {
global $wgOut;
$wgOut->redirect( $this->mTitle->getFullUrl() );
- return;
}
+ } else {
+ $this->show();
}
}
function show( $err = null ) {
- global $wgOut;
+ global $wgOut, $wgUser;
$wgOut->setRobotpolicy( 'noindex,nofollow' );
return;
}
- $cascadeSources = $this->mTitle->getCascadeProtectionSources();
+ list( $cascadeSources, /* $restrictions */ ) = $this->mTitle->getCascadeProtectionSources();
if ( "" != $err ) {
$wgOut->setSubtitle( wfMsgHtml( 'formerror' ) );
$titles .= '* [[:' . $title->getPrefixedText() . "]]\n";
}
- $notice = wfMsg( 'protect-cascadeon' ) . "\r\n$titles";
+ $notice = wfMsgExt( 'protect-cascadeon', array('parsemag'), count($cascadeSources) ) . "\r\n$titles";
$wgOut->addWikiText( $notice );
}
$wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
$wgOut->setSubtitle( wfMsg( 'protectsub', $this->mTitle->getPrefixedText() ) );
- $wgOut->addWikiText(
- wfMsg( $this->disabled ? "protect-viewtext" : "protect-text",
- wfEscapeWikiText( $this->mTitle->getPrefixedText() ) ) );
+ # Show an appropriate message if the user isn't allowed or able to change
+ # the protection settings at this time
+ if( $this->disabled ) {
+ if( $wgUser->isAllowed( 'protect' ) ) {
+ if( $wgUser->isBlocked() ) {
+ # Blocked
+ $message = 'protect-locked-blocked';
+ } else {
+ # Database lock
+ $message = 'protect-locked-dblock';
+ }
+ } else {
+ # Permission error
+ $message = 'protect-locked-access';
+ }
+ } else {
+ $message = 'protect-text';
+ }
+ $wgOut->addWikiText( wfMsg( $message, wfEscapeWikiText( $this->mTitle->getPrefixedText() ) ) );
$wgOut->addHTML( $this->buildForm() );
function save() {
global $wgRequest, $wgUser, $wgOut;
- if( !$wgRequest->wasPosted() ) {
- return false;
- }
-
+
if( $this->disabled ) {
+ $this->show();
return false;
}
$token = $wgRequest->getVal( 'wpEditToken' );
if( !$wgUser->matchEditToken( $token ) ) {
- throw new FatalError( wfMsg( 'sessionfailure' ) );
+ $this->show( wfMsg( 'sessionfailure' ) );
+ return false;
}
if ( strlen( $this->mExpiry ) == 0 ) {
if ( $expiry < 0 || $expiry === false ) {
$this->show( wfMsg( 'protect_expiry_invalid' ) );
- return;
+ return false;
}
$expiry = wfTimestamp( TS_MW, $expiry );
+
+ if ( $expiry < wfTimestampNow() ) {
+ $this->show( wfMsg( 'protect_expiry_old' ) );
+ return false;
+ }
+
}
$ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason, $this->mCascade, $expiry );
// The submission needs to reenable the move permission selector
// if it's in locked mode, or some browsers won't submit the data.
$out .= wfOpenElement( 'form', array(
+ 'id' => 'mw-Protect-Form',
'action' => $this->mTitle->getLocalUrl( 'action=protect' ),
'method' => 'post',
'onsubmit' => 'protectEnable(true)' ) );
$out .= "</tbody>\n";
$out .= "</table>\n";
- $out .= "<table>\n";
- $out .= "<tbody>\n";
-
global $wgEnableCascadingProtection;
if ($wgEnableCascadingProtection)
$out .= $this->buildCascadeInput();
+ $out .= "<table>\n";
+ $out .= "<tbody>\n";
+
$out .= $this->buildExpiryInput();
if( !$this->disabled ) {
wfElement( 'input', array(
'size' => 60,
'name' => $id,
- 'id' => $id ) );
+ 'id' => $id,
+ 'value' => $this->mReason ) );
}
function buildCascadeInput() {
$id = 'mwProtect-cascade';
- $ci = "<tr>" . wfCheckLabel( wfMsg( 'protect-cascade' ), $id, $id, $this->mCascade, $this->disabledAttrib) . "</tr>";
-
+ $ci = wfCheckLabel( wfMsg( 'protect-cascade' ), $id, $id, $this->mCascade, $this->disabledAttrib);
return $ci;
}
'id' => "$id-label",
'for' => $id ),
wfMsg( 'protectexpiry' ) );
- $ci .= "</td> <td aligh=\"left\">";
+ $ci .= "</td> <td align=\"left\">";
$ci .= wfElement( 'input', array(
'size' => 60,
'name' => $id,
'id' => $id,
- 'value' => $this->mExpiry ) );
+ 'value' => $this->mExpiry ) + $this->disabledAttrib );
$ci .= "</td></tr>";
return $ci;
function buildSubmit() {
return wfElement( 'input', array(
+ 'id' => 'mw-Protect-submit',
'type' => 'submit',
'value' => wfMsg( 'confirm' ) ) );
}
}
function buildCleanupScript() {
- return '<script type="text/javascript">protectInitialize("mwProtectSet","' .
- wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")</script>';
+ global $wgRestrictionLevels, $wgGroupPermissions;
+ $script = 'var wgCascadeableLevels=';
+ $CascadeableLevels = array();
+ foreach( $wgRestrictionLevels as $key ) {
+ if ( isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect'] ) {
+ $CascadeableLevels[]="'" . wfEscapeJsString($key) . "'";
+ }
+ }
+ $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
+ $script .= 'protectInitialize("mwProtectSet","' . wfEscapeJsString( wfMsg( 'protect-unchain' ) ) . '")';
+ return '<script type="text/javascript">' . $script . '</script>';
}
/**
* @access private
*/
function showLogExtract( &$out ) {
- # Show relevant lines from the deletion log:
+ # Show relevant lines from the protection log:
$out->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'protect' ) ) . "</h2>\n" );
$logViewer = new LogViewer(
new LogReader(