X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FProtectionForm.php;h=451635e319dde1ed68e557d92261d2ec40488c3c;hb=98585221d685e7cfcb5a3bb0d766c6cd431f2b05;hp=4cad7b745ae4d668ecb3ddc716d4ab252df49c32;hpb=4f21e6be661f7305abc223bb31600970a3fb5326;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 4cad7b745a..451635e319 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -28,7 +28,7 @@ */ class ProtectionForm { /** @var array A map of action to restriction level, from request or default */ - protected $mRestrictions = array(); + protected $mRestrictions = []; /** @var string The custom/additional protection reason */ protected $mReason = ''; @@ -40,22 +40,22 @@ class ProtectionForm { protected $mCascade = false; /** @var array Map of action to "other" expiry time. Used in preference to mExpirySelection. */ - protected $mExpiry = array(); + protected $mExpiry = []; /** * @var array Map of action to value selected in expiry drop-down list. * Will be set to 'othertime' whenever mExpiry is set. */ - protected $mExpirySelection = array(); + protected $mExpirySelection = []; /** @var array Permissions errors for the protect action */ - protected $mPermErrors = array(); + protected $mPermErrors = []; /** @var array Types (i.e. actions) for which levels can be selected */ - protected $mApplicableTypes = array(); + protected $mApplicableTypes = []; /** @var array Map of action to the expiry time of the existing protection */ - protected $mExistingExpiry = array(); + protected $mExistingExpiry = []; /** @var IContextSource */ private $mContext; @@ -70,15 +70,17 @@ class ProtectionForm { // Check if the form should be disabled. // If it is, the form will be available in read-only to show levels. $this->mPermErrors = $this->mTitle->getUserPermissionsErrors( - 'protect', $this->mContext->getUser() + 'protect', + $this->mContext->getUser(), + $this->mContext->getRequest()->wasPosted() ? 'secure' : 'full' // T92357 ); if ( wfReadOnly() ) { - $this->mPermErrors[] = array( 'readonlytext', wfReadOnlyReason() ); + $this->mPermErrors[] = [ 'readonlytext', wfReadOnlyReason() ]; } - $this->disabled = $this->mPermErrors != array(); + $this->disabled = $this->mPermErrors != []; $this->disabledAttrib = $this->disabled - ? array( 'disabled' => 'disabled' ) - : array(); + ? [ 'disabled' => 'disabled' ] + : []; $this->loadData(); } @@ -176,7 +178,7 @@ class ProtectionForm { * Main entry point for action=protect and action=unprotect */ function execute() { - if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === array( '' ) ) { + if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === [ '' ] ) { throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' ); } @@ -206,7 +208,7 @@ class ProtectionForm { $out->addHTML( "

{$err}

\n" ); } - if ( $this->mTitle->getRestrictionTypes() === array() ) { + if ( $this->mTitle->getRestrictionTypes() === [] ) { // No restriction types available for the current title // this might happen if an extension alters the available types $out->setPageTitle( $this->mContext->msg( @@ -232,7 +234,7 @@ class ProtectionForm { /** @todo FIXME: i18n issue, should use formatted number. */ $out->wrapWikiMsg( "
\n$1\n" . $titles . "
", - array( 'protect-cascadeon', count( $cascadeSources ) ) + [ 'protect-cascadeon', count( $cascadeSources ) ] ); } @@ -270,8 +272,8 @@ class ProtectionForm { $user = $this->mContext->getUser(); $out = $this->mContext->getOutput(); $token = $request->getVal( 'wpEditToken' ); - if ( !$user->matchEditToken( $token, array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ) { - $this->show( array( 'sessionfailure' ) ); + if ( !$user->matchEditToken( $token, [ 'protect', $this->mTitle->getPrefixedDBkey() ] ) ) { + $this->show( [ 'sessionfailure' ] ); return false; } @@ -283,18 +285,18 @@ class ProtectionForm { } elseif ( $reasonstr == 'other' ) { $reasonstr = $this->mReason; } - $expiry = array(); + $expiry = []; foreach ( $this->mApplicableTypes as $action ) { $expiry[$action] = $this->getExpiry( $action ); if ( empty( $this->mRestrictions[$action] ) ) { continue; // unprotected } if ( !$expiry[$action] ) { - $this->show( array( 'protect_expiry_invalid' ) ); + $this->show( [ 'protect_expiry_invalid' ] ); return false; } if ( $expiry[$action] < wfTimestampNow() ) { - $this->show( array( 'protect_expiry_old' ) ); + $this->show( [ 'protect_expiry_old' ] ); return false; } } @@ -321,9 +323,9 @@ class ProtectionForm { * you can also return an array of message name and its parameters */ $errorMsg = ''; - if ( !Hooks::run( 'ProtectionForm::save', array( $this->mArticle, &$errorMsg, $reasonstr ) ) ) { + if ( !Hooks::run( 'ProtectionForm::save', [ $this->mArticle, &$errorMsg, $reasonstr ] ) ) { if ( $errorMsg == '' ) { - $errorMsg = array( 'hookaborted' ); + $errorMsg = [ 'hookaborted' ]; } } if ( $errorMsg != '' ) { @@ -351,14 +353,14 @@ class ProtectionForm { if ( !$this->disabled ) { $output->addModules( 'mediawiki.legacy.protect' ); $output->addJsConfigVars( 'wgCascadeableLevels', $cascadingRestrictionLevels ); - $out .= Xml::openElement( 'form', array( 'method' => 'post', + $out .= Xml::openElement( 'form', [ 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=protect' ), - 'id' => 'mw-Protect-Form' ) ); + 'id' => 'mw-Protect-Form' ] ); } $out .= Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, $context->msg( 'protect-legend' )->text() ) . - Xml::openElement( 'table', array( 'id' => 'mwProtectSet' ) ) . + Xml::openElement( 'table', [ 'id' => 'mwProtectSet' ] ) . Xml::openElement( 'tbody' ); $scExpiryOptions = wfMessage( 'protect-expiry-options' )->inContentLanguage()->text(); @@ -372,7 +374,7 @@ class ProtectionForm { $out .= "" . Xml::openElement( 'fieldset' ) . Xml::element( 'legend', null, $msg->exists() ? $msg->text() : $action ) . - Xml::openElement( 'table', array( 'id' => "mw-protect-table-$action" ) ) . + Xml::openElement( 'table', [ 'id' => "mw-protect-table-$action" ] ) . "" . $this->buildSelector( $action, $selected ) . ""; $mProtectexpiry = Xml::label( @@ -384,7 +386,11 @@ class ProtectionForm { "mwProtect-$action-expires" ); - $expiryFormOptions = new XmlSelect( "wpProtectExpirySelection-$action", "mwProtectExpirySelection-$action", $this->mExpirySelection[$action] ); + $expiryFormOptions = new XmlSelect( + "wpProtectExpirySelection-$action", + "mwProtectExpirySelection-$action", + $this->mExpirySelection[$action] + ); $expiryFormOptions->setAttribute( 'tabindex', '2' ); if ( $this->disabled ) { $expiryFormOptions->setAttribute( 'disabled', 'disabled' ); @@ -397,12 +403,20 @@ class ProtectionForm { $timestamp = $lang->userTimeAndDate( $this->mExistingExpiry[$action], $user ); $d = $lang->userDate( $this->mExistingExpiry[$action], $user ); $t = $lang->userTime( $this->mExistingExpiry[$action], $user ); - $existingExpiryMessage = $context->msg( 'protect-existing-expiry', $timestamp, $d, $t ); + $existingExpiryMessage = $context->msg( + 'protect-existing-expiry', + $timestamp, + $d, + $t + ); } $expiryFormOptions->addOption( $existingExpiryMessage->text(), 'existing' ); } - $expiryFormOptions->addOption( $context->msg( 'protect-othertime-op' )->text(), 'othertime' ); + $expiryFormOptions->addOption( + $context->msg( 'protect-othertime-op' )->text(), + 'othertime' + ); foreach ( explode( ',', $scExpiryOptions ) as $option ) { if ( strpos( $option, ":" ) === false ) { $show = $value = $option; @@ -424,7 +438,7 @@ class ProtectionForm { "; } # Add custom expiry field - $attribs = array( 'id' => "mwProtect-$action-expires" ) + $this->disabledAttrib; + $attribs = [ 'id' => "mwProtect-$action-expires" ] + $this->disabledAttrib; $out .= ""; } # Give extensions a chance to add items to the form - Hooks::run( 'ProtectionForm::buildForm', array( $this->mArticle, &$out ) ); + Hooks::run( 'ProtectionForm::buildForm', [ $this->mArticle, &$out ] ); $out .= Xml::closeElement( 'tbody' ) . Xml::closeElement( 'table' ); // JavaScript will add another row with a value-chaining checkbox if ( $this->mTitle->exists() ) { - $out .= Xml::openElement( 'table', array( 'id' => 'mw-protect-table2' ) ) . + $out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table2' ] ) . Xml::openElement( 'tbody' ); $out .= ' @@ -479,7 +493,7 @@ class ProtectionForm { $this->mReasonSelection, 'mwProtect-reason', 4 ); - $out .= Xml::openElement( 'table', array( 'id' => 'mw-protect-table3' ) ) . + $out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table3' ] ) . Xml::openElement( 'tbody' ); $out .= " @@ -495,8 +509,8 @@ class ProtectionForm { {$mProtectreason} \n"; @@ -532,8 +546,8 @@ class ProtectionForm { $link = Linker::linkKnown( $context->msg( 'protect-dropdown' )->inContentLanguage()->getTitle(), $context->msg( 'protect-edit-reasonlist' )->escaped(), - array(), - array( 'action' => 'edit' ) + [], + [ 'action' => 'edit' ] ); $out .= '

' . $link . '

'; } @@ -541,7 +555,7 @@ class ProtectionForm { if ( !$this->disabled ) { $out .= Html::hidden( 'wpEditToken', - $user->getEditToken( array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) + $user->getEditToken( [ 'protect', $this->mTitle->getPrefixedDBkey() ] ) ); $out .= Xml::closeElement( 'form' ); } @@ -609,6 +623,6 @@ class ProtectionForm { $out->addHTML( Xml::element( 'h2', null, $protectLogPage->getName()->text() ) ); LogEventsList::showLogExtract( $out, 'protect', $this->mTitle ); # Let extensions add other relevant log extracts - Hooks::run( 'ProtectionForm::showLogExtract', array( $this->mArticle, $out ) ); + Hooks::run( 'ProtectionForm::showLogExtract', [ $this->mArticle, $out ] ); } }
" . $mProtectother . @@ -439,13 +453,13 @@ class ProtectionForm { "
" . - Xml::input( 'mwProtect-reason', 60, $this->mReason, array( 'type' => 'text', - 'id' => 'mwProtect-reason', 'maxlength' => 180 ) ) . + Xml::input( 'mwProtect-reason', 60, $this->mReason, [ 'type' => 'text', + 'id' => 'mwProtect-reason', 'maxlength' => 180 ] ) . // Limited maxlength as the database trims at 255 bytes and other texts // chosen by dropdown menus on this page are also included in this database field. // The byte limit of 180 bytes is enforced in javascript @@ -520,7 +534,7 @@ class ProtectionForm { " . Xml::submitButton( $context->msg( 'confirm' )->text(), - array( 'id' => 'mw-Protect-submit' ) + [ 'id' => 'mw-Protect-submit' ] ) . "