87 $this->mArticle = $article;
88 $this->mTitle = $article->
getTitle();
89 $this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
92 $services = MediaWikiServices::getInstance();
93 $this->permManager = $services->getPermissionManager();
94 $this->hookRunner =
new HookRunner( $services->getHookContainer() );
98 $this->mPermErrors = $this->permManager->getPermissionErrors(
100 $this->mContext->getUser(),
102 $this->mContext->getRequest()->wasPosted()
103 ? PermissionManager::RIGOR_SECURE
104 : PermissionManager::RIGOR_FULL
109 $this->disabled = $this->mPermErrors !== [];
110 $this->disabledAttrib = $this->disabled
111 ? [
'disabled' =>
'disabled' ]
121 $levels = $this->permManager->getNamespaceRestrictionLevels(
122 $this->mTitle->getNamespace(), $this->mContext->getUser()
124 $this->mCascade = $this->mTitle->areRestrictionsCascading();
126 $request = $this->mContext->getRequest();
127 $this->mReason = $request->getText(
'mwProtect-reason' );
128 $this->mReasonSelection = $request->getText(
'wpProtectReasonSelection' );
129 $this->mCascade = $request->getBool(
'mwProtect-cascade', $this->mCascade );
131 foreach ( $this->mApplicableTypes as $action ) {
136 $this->mRestrictions[$action] = implode(
'', $this->mTitle->getRestrictions( $action ) );
138 if ( !$this->mRestrictions[$action] ) {
140 $existingExpiry =
'';
142 $existingExpiry = $this->mTitle->getRestrictionExpiry( $action );
144 $this->mExistingExpiry[$action] = $existingExpiry;
146 $requestExpiry = $request->getText(
"mwProtect-expiry-$action" );
147 $requestExpirySelection = $request->getVal(
"wpProtectExpirySelection-$action" );
149 if ( $requestExpiry ) {
151 $this->mExpiry[$action] = $requestExpiry;
152 $this->mExpirySelection[$action] =
'othertime';
153 } elseif ( $requestExpirySelection ) {
155 $this->mExpiry[$action] =
'';
156 $this->mExpirySelection[$action] = $requestExpirySelection;
157 } elseif ( $existingExpiry ) {
159 $this->mExpiry[$action] =
'';
160 $this->mExpirySelection[$action] = $existingExpiry;
164 $this->mExpiry[$action] =
'';
165 $this->mExpirySelection[$action] =
'infinite';
168 $val = $request->getVal(
"mwProtect-level-$action" );
169 if ( isset( $val ) && in_array( $val, $levels ) ) {
170 $this->mRestrictions[$action] = $val;
233 private function show( $err =
null ) {
234 $out = $this->mContext->getOutput();
235 $out->setRobotPolicy(
'noindex,nofollow' );
236 $out->addBacklinkSubtitle( $this->mTitle );
238 if ( is_array( $err ) ) {
239 $out->wrapWikiMsg(
"<div class='error'>\n$1\n</div>\n", $err );
240 } elseif ( is_string( $err ) ) {
241 $out->addHTML(
"<div class='error'>{$err}</div>\n" );
244 if ( $this->mTitle->getRestrictionTypes() === [] ) {
247 $out->setPageTitle( $this->mContext->msg(
248 'protect-norestrictiontypes-title',
249 $this->mTitle->getPrefixedText()
251 $out->addWikiTextAsInterface(
252 $this->mContext->msg(
'protect-norestrictiontypes-text' )->plain()
261 list( $cascadeSources, ) = $this->mTitle->getCascadeProtectionSources();
262 if ( $cascadeSources && count( $cascadeSources ) > 0 ) {
265 foreach ( $cascadeSources as
$title ) {
266 $titles .=
'* [[:' .
$title->getPrefixedText() .
"]]\n";
271 "<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles .
"</div>",
272 [
'protect-cascadeon', count( $cascadeSources ) ]
276 # Show an appropriate message if the user isn't allowed or able to change
277 # the protection settings at this time
278 if ( $this->disabled ) {
280 $this->mContext->msg(
'protect-title-notallowed',
281 $this->mTitle->getPrefixedText() )
283 $out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage(
284 $this->mPermErrors,
'protect'
287 $out->setPageTitle( $this->mContext->msg(
'protect-title', $this->mTitle->getPrefixedText() ) );
288 $out->addWikiMsg(
'protect-text',
303 if ( $this->disabled ) {
308 $request = $this->mContext->getRequest();
309 $user = $this->mContext->getUser();
310 $out = $this->mContext->getOutput();
311 $token = $request->getVal(
'wpEditToken' );
312 if ( !$user->matchEditToken( $token, [
'protect', $this->mTitle->getPrefixedDBkey() ] ) ) {
313 $this->
show( [
'sessionfailure' ] );
317 # Create reason string. Use list and/or custom string.
319 if ( $reasonstr !=
'other' && $this->mReason !=
'' ) {
321 $reasonstr .= $this->mContext->msg(
'colon-separator' )->text() .
$this->mReason;
322 } elseif ( $reasonstr ==
'other' ) {
326 foreach ( $this->mApplicableTypes as $action ) {
327 $expiry[$action] = $this->
getExpiry( $action );
328 if ( empty( $this->mRestrictions[$action] ) ) {
332 if ( !$expiry[$action] ) {
333 $this->
show( [
'protect_expiry_invalid' ] );
337 $this->
show( [
'protect_expiry_old' ] );
342 $this->mCascade = $request->getBool(
'mwProtect-cascade' );
344 $status = $this->mArticle->getPage()->doUpdateRestrictions(
345 $this->mRestrictions,
352 if ( !$status->isOK() ) {
353 $this->
show( $out->parseInlineAsInterface(
354 $status->getWikiText(
false,
false, $this->mContext->getLanguage() )
366 if ( !$this->hookRunner->onProtectionForm__save( $this->mArticle, $errorMsg, $reasonstr ) ) {
367 if ( $errorMsg ==
'' ) {
368 $errorMsg = [
'hookaborted' ];
371 if ( $errorMsg !=
'' ) {
372 $this->
show( $errorMsg );
389 $output = $context->getOutput();
390 $lang = $context->getLanguage();
392 if ( !$this->disabled ) {
393 $output->addModules(
'mediawiki.legacy.protect' );
394 $out .= Xml::openElement(
'form', [
'method' =>
'post',
395 'action' => $this->mTitle->getLocalURL(
'action=protect' ),
396 'id' =>
'mw-Protect-Form' ] );
399 $out .= Xml::openElement(
'fieldset' ) .
400 Xml::element(
'legend',
null, $context->msg(
'protect-legend' )->text() ) .
401 Xml::openElement(
'table', [
'id' =>
'mwProtectSet' ] ) .
402 Xml::openElement(
'tbody' );
404 $expiryOptionsMsg =
wfMessage(
'protect-expiry-options' )->inContentLanguage()->text();
409 foreach ( $this->mRestrictions as $action => $selected ) {
412 $msg = $context->msg(
'restriction-' . $action );
414 Xml::openElement(
'fieldset' ) .
415 Xml::element(
'legend',
null, $msg->exists() ? $msg->text() : $action ) .
416 Xml::openElement(
'table', [
'id' =>
"mw-protect-table-$action" ] ) .
417 "<tr><td>" . $this->
buildSelector( $action, $selected ) .
"</td></tr><tr><td>";
419 $mProtectexpiry = Xml::label(
420 $context->msg(
'protectexpiry' )->text(),
421 "mwProtectExpirySelection-$action"
423 $mProtectother = Xml::label(
424 $context->msg(
'protect-othertime' )->text(),
425 "mwProtect-$action-expires"
429 "wpProtectExpirySelection-$action",
430 "mwProtectExpirySelection-$action",
431 $this->mExpirySelection[$action]
433 $expiryFormOptions->setAttribute(
'tabindex',
'2' );
434 if ( $this->disabled ) {
435 $expiryFormOptions->setAttribute(
'disabled',
'disabled' );
438 if ( $this->mExistingExpiry[$action] ) {
439 if ( $this->mExistingExpiry[$action] ==
'infinity' ) {
440 $existingExpiryMessage = $context->msg(
'protect-existing-expiry-infinity' );
442 $timestamp =
$lang->userTimeAndDate( $this->mExistingExpiry[$action], $user );
443 $d =
$lang->userDate( $this->mExistingExpiry[$action], $user );
444 $t =
$lang->userTime( $this->mExistingExpiry[$action], $user );
445 $existingExpiryMessage = $context->msg(
446 'protect-existing-expiry',
452 $expiryFormOptions->addOption( $existingExpiryMessage->text(),
'existing' );
455 $expiryFormOptions->addOption(
456 $context->msg(
'protect-othertime-op' )->text(),
459 $expiryFormOptions->addOptions( $expiryOptions );
460 # Add expiry dropdown
461 if ( $showProtectOptions && !$this->disabled ) {
464 <td class='mw-label'>
467 <td class='mw-input'>" .
468 $expiryFormOptions->getHTML() .
472 # Add custom expiry field
475 <td class='mw-label'>" .
478 <td class="mw-input">' .
479 Xml::input(
"mwProtect-expiry-$action", 50, $this->mExpiry[$action], $attribs ) .
482 $out .=
"</td></tr>" .
483 Xml::closeElement(
'table' ) .
484 Xml::closeElement(
'fieldset' ) .
487 # Give extensions a chance to add items to the form
488 $this->hookRunner->onProtectionForm__buildForm( $this->mArticle, $out );
490 $out .= Xml::closeElement(
'tbody' ) . Xml::closeElement(
'table' );
493 if ( $this->mTitle->exists() ) {
494 $out .= Xml::openElement(
'table', [
'id' =>
'mw-protect-table2' ] ) .
495 Xml::openElement(
'tbody' );
498 <td class="mw-input">' .
500 $context->msg(
'protect-cascade' )->text(),
503 $this->mCascade, $this->disabledAttrib
507 $out .= Xml::closeElement(
'tbody' ) . Xml::closeElement(
'table' );
510 # Add manual and custom reason field/selects as well as submit
511 if ( !$this->disabled ) {
512 $mProtectreasonother = Xml::label(
513 $context->msg(
'protectcomment' )->text(),
514 'wpProtectReasonSelection'
517 $mProtectreason = Xml::label(
518 $context->msg(
'protect-otherreason' )->text(),
522 $reasonDropDown = Xml::listDropDown(
'wpProtectReasonSelection',
523 wfMessage(
'protect-dropdown' )->inContentLanguage()->text(),
524 wfMessage(
'protect-otherreason-op' )->inContentLanguage()->text(),
525 $this->mReasonSelection,
526 'mwProtect-reason', 4 );
533 $maxlength = CommentStore::COMMENT_CHARACTER_LIMIT - 75;
535 $out .= Xml::openElement(
'table', [
'id' =>
'mw-protect-table3' ] ) .
536 Xml::openElement(
'tbody' );
539 <td class='mw-label'>
540 {$mProtectreasonother}
542 <td class='mw-input'>
547 <td class='mw-label'>
550 <td class='mw-input'>" .
551 Xml::input(
'mwProtect-reason', 60, $this->mReason, [
'type' =>
'text',
552 'id' =>
'mwProtect-reason',
'maxlength' => $maxlength ] ) .
555 # Disallow watching is user is not logged in
556 if ( $user->isLoggedIn() ) {
560 <td class='mw-input'>" .
561 Xml::checkLabel( $context->msg(
'watchthis' )->text(),
562 'mwProtectWatch',
'mwProtectWatch',
563 $user->isWatched( $this->mTitle ) || $user->getOption(
'watchdefault' ) ) .
570 <td class='mw-submit'>" .
572 $context->msg(
'confirm' )->text(),
573 [
'id' =>
'mw-Protect-submit' ]
577 $out .= Xml::closeElement(
'tbody' ) . Xml::closeElement(
'table' );
579 $out .= Xml::closeElement(
'fieldset' );
581 if ( $this->permManager->userHasRight( $user,
'editinterface' ) ) {
582 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
583 $link = $linkRenderer->makeKnownLink(
584 $context->msg(
'protect-dropdown' )->inContentLanguage()->getTitle(),
585 $context->msg(
'protect-edit-reasonlist' )->text(),
587 [
'action' =>
'edit' ]
589 $out .=
'<p class="mw-protect-editreasons">' . $link .
'</p>';
592 if ( !$this->disabled ) {
593 $out .= Html::hidden(
595 $user->getEditToken( [
'protect', $this->mTitle->getPrefixedDBkey() ] )
597 $out .= Xml::closeElement(
'form' );