* Loads the current state of protection into the object.
*/
function loadData() {
- $levels = MWNamespace::getRestrictionLevels(
+ $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
$this->mTitle->getNamespace(), $this->mContext->getUser()
);
$this->mCascade = $this->mTitle->areRestrictionsCascading();
* Main entry point for action=protect and action=unprotect
*/
function execute() {
- if ( MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace() ) === [ '' ] ) {
+ if (
+ MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+ $this->mTitle->getNamespace()
+ ) === [ '' ]
+ ) {
throw new ErrorPageError( 'protect-badnamespace-title', 'protect-badnamespace-text' );
}
/**
* Show the input form with optional error message
*
- * @param string $err Error message or null if there's no error
+ * @param string|null $err Error message or null if there's no error
*/
function show( $err = null ) {
$out = $this->mContext->getOutput();
$out->addBacklinkSubtitle( $this->mTitle );
if ( is_array( $err ) ) {
- $out->wrapWikiMsg( "<p class='error'>\n$1\n</p>\n", $err );
+ $out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", $err );
} elseif ( is_string( $err ) ) {
- $out->addHTML( "<p class='error'>{$err}</p>\n" );
+ $out->addHTML( "<div class='error'>{$err}</div>\n" );
}
if ( $this->mTitle->getRestrictionTypes() === [] ) {
'protect-norestrictiontypes-title',
$this->mTitle->getPrefixedText()
) );
- $out->addWikiText( $this->mContext->msg( 'protect-norestrictiontypes-text' )->plain() );
+ $out->addWikiTextAsInterface(
+ $this->mContext->msg( 'protect-norestrictiontypes-text' )->plain()
+ );
// Show the log in case protection was possible once
$this->showLogExtract( $out );
$this->mContext->msg( 'protect-title-notallowed',
$this->mTitle->getPrefixedText() )
);
- $out->addWikiText( $out->formatPermissionsErrorMessage( $this->mPermErrors, 'protect' ) );
+ $out->addWikiTextAsInterface( $out->formatPermissionsErrorMessage(
+ $this->mPermErrors, 'protect'
+ ) );
} else {
$out->setPageTitle( $this->mContext->msg( 'protect-title', $this->mTitle->getPrefixedText() ) );
$out->addWikiMsg( 'protect-text',
);
if ( !$status->isOK() ) {
- $this->show( $out->parseInline( $status->getWikiText() ) );
+ $this->show( $out->parseInlineAsInterface( $status->getWikiText() ) );
return false;
}
$user = $context->getUser();
$output = $context->getOutput();
$lang = $context->getLanguage();
- $cascadingRestrictionLevels = $context->getConfig()->get( 'CascadingRestrictionLevels' );
$out = '';
if ( !$this->disabled ) {
$output->addModules( 'mediawiki.legacy.protect' );
- $output->addJsConfigVars( 'wgCascadeableLevels', $cascadingRestrictionLevels );
$out .= Xml::openElement( 'form', [ 'method' => 'post',
'action' => $this->mTitle->getLocalURL( 'action=protect' ),
'id' => 'mw-Protect-Form' ] );
$this->mReasonSelection,
'mwProtect-reason', 4 );
+ // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
+ // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
+ // Unicode codepoints.
+ // Subtract arbitrary 75 to leave some space for the autogenerated null edit's summary
+ // and other texts chosen by dropdown menus on this page.
+ $maxlength = CommentStore::COMMENT_CHARACTER_LIMIT - 75;
+
$out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table3' ] ) .
Xml::openElement( 'tbody' );
$out .= "
</td>
<td class='mw-input'>" .
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
+ 'id' => 'mwProtect-reason', 'maxlength' => $maxlength ] ) .
"</td>
</tr>";
# Disallow watching is user is not logged in
function buildSelector( $action, $selected ) {
// If the form is disabled, display all relevant levels. Otherwise,
// just show the ones this user can use.
- $levels = MWNamespace::getRestrictionLevels( $this->mTitle->getNamespace(),
+ $levels = MediaWikiServices::getInstance()->getNamespaceInfo()->getRestrictionLevels(
+ $this->mTitle->getNamespace(),
$this->disabled ? null : $this->mContext->getUser()
);
* Show protection long extracts for this page
*
* @param OutputPage $out
- * @access private
*/
- function showLogExtract( &$out ) {
+ private function showLogExtract( OutputPage $out ) {
# Show relevant lines from the protection log:
$protectLogPage = new LogPage( 'protect' );
$out->addHTML( Xml::element( 'h2', null, $protectLogPage->getName()->text() ) );