78 $this->mArticle = $article;
79 $this->mTitle = $article->
getTitle();
80 $this->mApplicableTypes = $this->mTitle->getRestrictionTypes();
85 $this->mPermErrors = $this->mTitle->getUserPermissionsErrors(
87 $this->mContext->getUser(),
88 $this->mContext->getRequest()->wasPosted() ?
'secure' :
'full'
93 $this->disabled = $this->mPermErrors !== [];
94 $this->disabledAttrib = $this->disabled
95 ? [
'disabled' =>
'disabled' ]
105 $levels = MediaWikiServices::getInstance()->getPermissionManager()->getNamespaceRestrictionLevels(
106 $this->mTitle->getNamespace(), $this->mContext->getUser()
108 $this->mCascade = $this->mTitle->areRestrictionsCascading();
110 $request = $this->mContext->getRequest();
111 $this->mReason = $request->getText(
'mwProtect-reason' );
112 $this->mReasonSelection = $request->getText(
'wpProtectReasonSelection' );
113 $this->mCascade = $request->getBool(
'mwProtect-cascade', $this->mCascade );
115 foreach ( $this->mApplicableTypes as $action ) {
120 $this->mRestrictions[$action] = implode(
'', $this->mTitle->getRestrictions( $action ) );
122 if ( !$this->mRestrictions[$action] ) {
124 $existingExpiry =
'';
126 $existingExpiry = $this->mTitle->getRestrictionExpiry( $action );
128 $this->mExistingExpiry[$action] = $existingExpiry;
130 $requestExpiry = $request->getText(
"mwProtect-expiry-$action" );
131 $requestExpirySelection = $request->getVal(
"wpProtectExpirySelection-$action" );
133 if ( $requestExpiry ) {
135 $this->mExpiry[$action] = $requestExpiry;
136 $this->mExpirySelection[$action] =
'othertime';
137 } elseif ( $requestExpirySelection ) {
139 $this->mExpiry[$action] =
'';
140 $this->mExpirySelection[$action] = $requestExpirySelection;
141 } elseif ( $existingExpiry ) {
143 $this->mExpiry[$action] =
'';
144 $this->mExpirySelection[$action] = $existingExpiry;
148 $this->mExpiry[$action] =
'';
149 $this->mExpirySelection[$action] =
'infinite';
152 $val = $request->getVal(
"mwProtect-level-$action" );
153 if ( isset( $val ) && in_array( $val, $levels ) ) {
154 $this->mRestrictions[$action] = $val;
167 if ( $this->mExpirySelection[$action] ==
'existing' ) {
168 return $this->mExistingExpiry[$action];
169 } elseif ( $this->mExpirySelection[$action] ==
'othertime' ) {
170 $value = $this->mExpiry[$action];
172 $value = $this->mExpirySelection[$action];
177 $unix = strtotime( $value );
179 if ( !$unix || $unix === -1 ) {
196 $this->mTitle->getNamespace()
199 throw new ErrorPageError(
'protect-badnamespace-title',
'protect-badnamespace-text' );
202 if ( $this->mContext->getRequest()->wasPosted() ) {
203 if ( $this->
save() ) {
204 $q = $this->mArticle->isRedirect() ?
'redirect=no' :
'';
205 $this->mContext->getOutput()->redirect( $this->mTitle->getFullURL( $q ) );
218 $out = $this->mContext->getOutput();
219 $out->setRobotPolicy(
'noindex,nofollow' );
220 $out->addBacklinkSubtitle( $this->mTitle );
222 if ( is_array( $err ) ) {
223 $out->wrapWikiMsg(
"<div class='error'>\n$1\n</div>\n", $err );
224 } elseif ( is_string( $err ) ) {
225 $out->addHTML(
"<div class='error'>{$err}</div>\n" );
228 if ( $this->mTitle->getRestrictionTypes() === [] ) {
231 $out->setPageTitle( $this->mContext->msg(
232 'protect-norestrictiontypes-title',
233 $this->mTitle->getPrefixedText()
235 $out->addWikiTextAsInterface(
236 $this->mContext->msg(
'protect-norestrictiontypes-text' )->plain()
245 list( $cascadeSources, ) = $this->mTitle->getCascadeProtectionSources();
246 if ( $cascadeSources && count( $cascadeSources ) > 0 ) {
249 foreach ( $cascadeSources as
$title ) {
250 $titles .=
'* [[:' .
$title->getPrefixedText() .
"]]\n";
255 "<div id=\"mw-protect-cascadeon\">\n$1\n" . $titles .
"</div>",
256 [
'protect-cascadeon', count( $cascadeSources ) ]
260 # Show an appropriate message if the user isn't allowed or able to change
261 # the protection settings at this time
262 if ( $this->disabled ) {
264 $this->mContext->msg(
'protect-title-notallowed',
265 $this->mTitle->getPrefixedText() )
267 $out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage(
268 $this->mPermErrors,
'protect'
271 $out->setPageTitle( $this->mContext->msg(
'protect-title', $this->mTitle->getPrefixedText() ) );
272 $out->addWikiMsg(
'protect-text',
287 if ( $this->disabled ) {
292 $request = $this->mContext->getRequest();
293 $user = $this->mContext->getUser();
294 $out = $this->mContext->getOutput();
295 $token = $request->getVal(
'wpEditToken' );
296 if ( !$user->matchEditToken( $token, [
'protect', $this->mTitle->getPrefixedDBkey() ] ) ) {
297 $this->
show( [
'sessionfailure' ] );
301 # Create reason string. Use list and/or custom string.
303 if ( $reasonstr !=
'other' && $this->mReason !=
'' ) {
305 $reasonstr .= $this->mContext->msg(
'colon-separator' )->text() .
$this->mReason;
306 } elseif ( $reasonstr ==
'other' ) {
310 foreach ( $this->mApplicableTypes as $action ) {
311 $expiry[$action] = $this->
getExpiry( $action );
312 if ( empty( $this->mRestrictions[$action] ) ) {
315 if ( !$expiry[$action] ) {
316 $this->
show( [
'protect_expiry_invalid' ] );
320 $this->
show( [
'protect_expiry_old' ] );
325 $this->mCascade = $request->getBool(
'mwProtect-cascade' );
327 $status = $this->mArticle->doUpdateRestrictions(
328 $this->mRestrictions,
335 if ( !$status->isOK() ) {
336 $this->
show( $out->parseInlineAsInterface(
337 $status->getWikiText(
false,
false, $this->mContext->getLanguage() )
349 if ( !
Hooks::run(
'ProtectionForm::save', [ $this->mArticle, &$errorMsg, $reasonstr ] ) ) {
350 if ( $errorMsg ==
'' ) {
351 $errorMsg = [
'hookaborted' ];
354 if ( $errorMsg !=
'' ) {
355 $this->
show( $errorMsg );
375 if ( !$this->disabled ) {
376 $output->addModules(
'mediawiki.legacy.protect' );
378 'action' => $this->mTitle->getLocalURL(
'action=protect' ),
379 'id' =>
'mw-Protect-Form' ] );
387 $scExpiryOptions =
wfMessage(
'protect-expiry-options' )->inContentLanguage()->text();
391 foreach ( $this->mRestrictions as $action => $selected ) {
394 $msg =
$context->msg(
'restriction-' . $action );
397 Xml::element(
'legend',
null, $msg->exists() ? $msg->text() : $action ) .
399 "<tr><td>" . $this->
buildSelector( $action, $selected ) .
"</td></tr><tr><td>";
402 $context->msg(
'protectexpiry' )->text(),
403 "mwProtectExpirySelection-$action"
406 $context->msg(
'protect-othertime' )->text(),
407 "mwProtect-$action-expires"
411 "wpProtectExpirySelection-$action",
412 "mwProtectExpirySelection-$action",
413 $this->mExpirySelection[$action]
415 $expiryFormOptions->setAttribute(
'tabindex',
'2' );
416 if ( $this->disabled ) {
417 $expiryFormOptions->setAttribute(
'disabled',
'disabled' );
420 if ( $this->mExistingExpiry[$action] ) {
421 if ( $this->mExistingExpiry[$action] ==
'infinity' ) {
422 $existingExpiryMessage =
$context->msg(
'protect-existing-expiry-infinity' );
424 $timestamp =
$lang->userTimeAndDate( $this->mExistingExpiry[$action], $user );
425 $d =
$lang->userDate( $this->mExistingExpiry[$action], $user );
426 $t =
$lang->userTime( $this->mExistingExpiry[$action], $user );
427 $existingExpiryMessage =
$context->msg(
428 'protect-existing-expiry',
434 $expiryFormOptions->addOption( $existingExpiryMessage->text(),
'existing' );
437 $expiryFormOptions->addOption(
438 $context->msg(
'protect-othertime-op' )->text(),
441 foreach ( explode(
',', $scExpiryOptions ) as $option ) {
442 if ( strpos( $option,
":" ) ===
false ) {
443 $show = $value = $option;
445 list( $show, $value ) = explode(
":", $option );
447 $expiryFormOptions->addOption( $show, htmlspecialchars( $value ) );
449 # Add expiry dropdown
450 if ( $showProtectOptions && !$this->disabled ) {
453 <td class='mw-label'>
456 <td class='mw-input'>" .
457 $expiryFormOptions->getHTML() .
461 # Add custom expiry field
464 <td class='mw-label'>" .
467 <td class="mw-input">' .
468 Xml::input(
"mwProtect-expiry-$action", 50, $this->mExpiry[$action], $attribs ) .
471 $out .=
"</td></tr>" .
476 # Give extensions a chance to add items to the form
477 Hooks::run(
'ProtectionForm::buildForm', [ $this->mArticle, &$out ] );
482 if ( $this->mTitle->exists() ) {
487 <td class="mw-input">' .
489 $context->msg(
'protect-cascade' )->text(),
492 $this->mCascade, $this->disabledAttrib
499 # Add manual and custom reason field/selects as well as submit
500 if ( !$this->disabled ) {
502 $context->msg(
'protectcomment' )->text(),
503 'wpProtectReasonSelection'
507 $context->msg(
'protect-otherreason' )->text(),
512 wfMessage(
'protect-dropdown' )->inContentLanguage()->text(),
513 wfMessage(
'protect-otherreason-op' )->inContentLanguage()->text(),
514 $this->mReasonSelection,
515 'mwProtect-reason', 4 );
528 <td class='mw-label'>
529 {$mProtectreasonother}
531 <td class='mw-input'>
536 <td class='mw-label'>
539 <td class='mw-input'>" .
540 Xml::input(
'mwProtect-reason', 60, $this->mReason, [
'type' =>
'text',
541 'id' =>
'mwProtect-reason',
'maxlength' => $maxlength ] ) .
544 # Disallow watching is user is not logged in
545 if ( $user->isLoggedIn() ) {
549 <td class='mw-input'>" .
551 'mwProtectWatch',
'mwProtectWatch',
552 $user->isWatched( $this->mTitle ) || $user->getOption(
'watchdefault' ) ) .
559 <td class='mw-submit'>" .
562 [
'id' =>
'mw-Protect-submit' ]
571 ->userHasRight( $user,
'editinterface' ) ) {
572 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
573 $link = $linkRenderer->makeKnownLink(
574 $context->msg(
'protect-dropdown' )->inContentLanguage()->getTitle(),
575 $context->msg(
'protect-edit-reasonlist' )->text(),
577 [
'action' =>
'edit' ]
579 $out .=
'<p class="mw-protect-editreasons">' . $link .
'</p>';
582 if ( !$this->disabled ) {
585 $user->getEditToken( [
'protect', $this->mTitle->getPrefixedDBkey() ] )
603 $levels = MediaWikiServices::getInstance()
604 ->getPermissionManager()
605 ->getNamespaceRestrictionLevels(
606 $this->mTitle->getNamespace(),
607 $this->disabled ?
null : $this->mContext->getUser()
610 $id =
'mwProtect-level-' . $action;
612 $select =
new XmlSelect( $id, $id, $selected );
613 $select->setAttribute(
'size', count( $levels ) );
614 if ( $this->disabled ) {
615 $select->setAttribute(
'disabled',
'disabled' );
618 foreach ( $levels as $key ) {
622 return $select->getHTML();
632 if ( $permission ==
'' ) {
633 return $this->mContext->msg(
'protect-default' )->text();
636 $msg = $this->mContext->msg(
"protect-level-{$permission}" );
637 if ( $msg->exists() ) {
640 return $this->mContext->msg(
'protect-fallback', $permission )->text();
650 # Show relevant lines from the protection log:
651 $protectLogPage =
new LogPage(
'protect' );
654 # Let extensions add other relevant log extracts
655 Hooks::run(
'ProtectionForm::showLogExtract', [ $this->mArticle, $out ] );