Merge "rdbms: add "use" statement for UnexpectedValueExcetion in Database"
[lhc/web/wiklou.git] / includes / ProtectionForm.php
index 70192b9..51c2923 100644 (file)
@@ -22,6 +22,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Handles the page protection UI and backend
@@ -70,7 +71,9 @@ 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[] = [ 'readonlytext', wfReadOnlyReason() ];
@@ -146,7 +149,7 @@ class ProtectionForm {
         *
         * @param string $action
         *
-        * @return string 14-char timestamp or "infinity", or false if the input was invalid
+        * @return string|false 14-char timestamp or "infinity", or false if the input was invalid
         */
        function getExpiry( $action ) {
                if ( $this->mExpirySelection[$action] == 'existing' ) {
@@ -346,7 +349,9 @@ class ProtectionForm {
                $user = $context->getUser();
                $output = $context->getOutput();
                $lang = $context->getLanguage();
-               $cascadingRestrictionLevels = $context->getConfig()->get( 'CascadingRestrictionLevels' );
+               $conf = $context->getConfig();
+               $cascadingRestrictionLevels = $conf->get( 'CascadingRestrictionLevels' );
+               $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
                $out = '';
                if ( !$this->disabled ) {
                        $output->addModules( 'mediawiki.legacy.protect' );
@@ -491,6 +496,13 @@ class ProtectionForm {
                                $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 (or 180 UTF-8 bytes for old schema).
+                       // 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 = $oldCommentSchema ? 180 : CommentStore::COMMENT_CHARACTER_LIMIT - 75;
+
                        $out .= Xml::openElement( 'table', [ 'id' => 'mw-protect-table3' ] ) .
                                Xml::openElement( 'tbody' );
                        $out .= "
@@ -508,10 +520,7 @@ class ProtectionForm {
                                        </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
@@ -541,9 +550,10 @@ class ProtectionForm {
                $out .= Xml::closeElement( 'fieldset' );
 
                if ( $user->isAllowed( 'editinterface' ) ) {
-                       $link = Linker::linkKnown(
+                       $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+                       $link = $linkRenderer->makeKnownLink(
                                $context->msg( 'protect-dropdown' )->inContentLanguage()->getTitle(),
-                               $context->msg( 'protect-edit-reasonlist' )->escaped(),
+                               $context->msg( 'protect-edit-reasonlist' )->text(),
                                [],
                                [ 'action' => 'edit' ]
                        );
@@ -612,7 +622,7 @@ class ProtectionForm {
        /**
         * Show protection long extracts for this page
         *
-        * @param OutputPage $out
+        * @param OutputPage &$out
         * @access private
         */
        function showLogExtract( &$out ) {