Merge "RevisionStorageTest: Add tests for Revision::newFromTitle()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 12 Oct 2017 07:02:16 +0000 (07:02 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 12 Oct 2017 07:02:16 +0000 (07:02 +0000)
includes/CommentStore.php
includes/GlobalFunctions.php
includes/installer/PostgresUpdater.php
maintenance/postgres/archives/patch-add-3d.sql [deleted file]
phpcs.xml
tests/phpunit/includes/CommentStoreTest.php

index b8a31e6..0d679d3 100644 (file)
@@ -29,10 +29,24 @@ use Wikimedia\Rdbms\IDatabase;
  */
 class CommentStore {
 
-       /** Maximum length of a comment. Longer comments will be truncated. */
+       /**
+        * Maximum length of a comment in UTF-8 characters. Longer comments will be truncated.
+        * @note This must be at least 255 and not greater than floor( MAX_COMMENT_LENGTH / 4 ).
+        */
+       const COMMENT_CHARACTER_LIMIT = 1000;
+
+       /**
+        * Maximum length of a comment in bytes. Longer comments will be truncated.
+        * @note This value is determined by the size of the underlying database field,
+        *  currently BLOB in MySQL/MariaDB.
+        */
        const MAX_COMMENT_LENGTH = 65535;
 
-       /** Maximum length of serialized data. Longer data will result in an exception. */
+       /**
+        * Maximum length of serialized data in bytes. Longer data will result in an exception.
+        * @note This value is determined by the size of the underlying database field,
+        *  currently BLOB in MySQL/MariaDB.
+        */
        const MAX_DATA_LENGTH = 65535;
 
        /**
@@ -371,6 +385,15 @@ class CommentStore {
 
                # Truncate comment in a Unicode-sensitive manner
                $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH );
+               if ( mb_strlen( $comment->text, 'UTF-8' ) > self::COMMENT_CHARACTER_LIMIT ) {
+                       $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this->lang )->escaped();
+                       if ( mb_strlen( $ellipsis ) >= self::COMMENT_CHARACTER_LIMIT ) {
+                               // WTF?
+                               $ellipsis = '...';
+                       }
+                       $maxLength = self::COMMENT_CHARACTER_LIMIT - mb_strlen( $ellipsis, 'UTF-8' );
+                       $comment->text = mb_substr( $comment->text, 0, $maxLength, 'UTF-8' ) . $ellipsis;
+               }
 
                if ( $this->stage > MIGRATION_OLD && !$comment->id ) {
                        $dbData = $comment->data;
index 069e1be..d53e98d 100644 (file)
@@ -2259,6 +2259,7 @@ function wfEscapeShellArg( /*...*/ ) {
  * @deprecated since 1.30 use MediaWiki\Shell::isDisabled()
  */
 function wfShellExecDisabled() {
+       wfDeprecated( __FUNCTION__, '1.30' );
        return Shell::isDisabled() ? 'disabled' : false;
 }
 
index 07aeb13..0475fe4 100644 (file)
@@ -454,7 +454,7 @@ class PostgresUpdater extends DatabaseUpdater {
                        [ 'addPgIndex', 'user_groups', 'user_groups_expiry', '( ug_expiry )' ],
 
                        // 1.30
-                       [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ],
+                       [ 'addPgEnumValue', 'media_type', '3D' ],
                        [ 'setDefault', 'revision', 'rev_comment', '' ],
                        [ 'changeNullableField', 'revision', 'rev_comment', 'NOT NULL', true ],
                        [ 'setDefault', 'archive', 'ar_comment', '' ],
@@ -838,6 +838,46 @@ END;
                }
        }
 
+       /**
+        * Add a value to an existing PostgreSQL enum type
+        * @since 1.31
+        * @param string $type Type name. Must be in the core schema.
+        * @param string $value Value to add.
+        */
+       public function addPgEnumValue( $type, $value ) {
+               $row = $this->db->selectRow(
+                       [
+                               't' => 'pg_catalog.pg_type',
+                               'n' => 'pg_catalog.pg_namespace',
+                               'e' => 'pg_catalog.pg_enum',
+                       ],
+                       [ 't.typname', 't.typtype', 'e.enumlabel' ],
+                       [
+                               't.typname' => $type,
+                               'n.nspname' => $this->db->getCoreSchema(),
+                       ],
+                       __METHOD__,
+                       [],
+                       [
+                               'n' => [ 'JOIN', 't.typnamespace = n.oid' ],
+                               'e' => [ 'LEFT JOIN', [ 'e.enumtypid = t.oid', 'e.enumlabel' => $value ] ],
+                       ]
+               );
+
+               if ( !$row ) {
+                       $this->output( "...Type $type does not exist, skipping modify enum.\n" );
+               } elseif ( $row->typtype !== 'e' ) {
+                       $this->output( "...Type $type does not seem to be an enum, skipping modify enum.\n" );
+               } elseif ( $row->enumlabel === $value ) {
+                       $this->output( "...Enum type $type already contains value '$value'.\n" );
+               } else {
+                       $this->output( "...Adding value '$value' to enum type $type.\n" );
+                       $etype = $this->db->addIdentifierQuotes( $type );
+                       $evalue = $this->db->addQuotes( $value );
+                       $this->db->query( "ALTER TYPE $etype ADD VALUE $evalue" );
+               }
+       }
+
        protected function dropFkey( $table, $field ) {
                $fi = $this->db->fieldInfo( $table, $field );
                if ( is_null( $fi ) ) {
diff --git a/maintenance/postgres/archives/patch-add-3d.sql b/maintenance/postgres/archives/patch-add-3d.sql
deleted file mode 100644 (file)
index f892755..0000000
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TYPE media_type ADD VALUE '3D';
index 29ddca3..4be45b1 100644 (file)
--- a/phpcs.xml
+++ b/phpcs.xml
        </rule>
        <rule ref="MediaWiki.NamingConventions.PrefixedGlobalFunctions">
                <properties>
-                       <property name="ignoreList" type="array" value="bfNormalizeTitleStrReplace,bfNormalizeTitleStrTr,cdbShowHelp,codepointToUtf8,compare_point,cssfilter,escapeSingleString,findAuxFile,findFiles,getEscapedProfileUrl,getFileCommentFromSourceWiki,getFileUserFromSourceWiki,hexSequenceToUtf8,mccGetHelp,mccShowUsage,mimeTypeMatch,moveToExternal,NothingFunction,NothingFunctionData,resolveStub,resolveStubs,showUsage,splitFilename,utf8ToCodepoint,utf8ToHexSequence" />
+                       <!--
+                       includes/compat/normal/UtfNormalUtil.php
+                       * codepointToUtf8
+                       * escapeSingleString
+                       * hexSequenceToUtf8
+                       * utf8ToCodepoint
+                       * utf8ToHexSequence
+                       includes/GlobalFunctions.php
+                       * mimeTypeMatch
+                       maintenance/benchmarks/bench_strtr_str_replace.php
+                       * bfNormalizeTitleStrReplace
+                       * bfNormalizeTitleStrTr
+                       maintenance/cdb.php
+                       * cdbShowHelp
+                       maintenance/language/transstat.php
+                       * showUsage
+                       maintenance/mcc.php
+                       * mccGetHelp
+                       * mccShowUsage
+                       maintenance/storage/moveToExternal.php
+                       * moveToExternal
+                       maintenance/storage/resolveStubs.php
+                       * resolveStub
+                       * resolveStubs
+                       profileinfo.php
+                       * compare_point
+                       * getEscapedProfileUrl
+                       tests/phpunit/includes/HooksTest.php
+                       * NothingFunction
+                       * NothingFunctionData
+                       tests/qunit/data/styleTest.css.php
+                       * cssfilter
+                       -->
+                       <property name="ignoreList" type="array" value="bfNormalizeTitleStrReplace,bfNormalizeTitleStrTr,cdbShowHelp,codepointToUtf8,compare_point,cssfilter,escapeSingleString,getEscapedProfileUrl,hexSequenceToUtf8,mccGetHelp,mccShowUsage,mimeTypeMatch,moveToExternal,NothingFunction,NothingFunctionData,resolveStub,resolveStubs,showUsage,utf8ToCodepoint,utf8ToHexSequence" />
                </properties>
        </rule>
        <rule ref="MediaWiki.NamingConventions.ValidGlobalName">
index b0f7678..9369f30 100644 (file)
@@ -618,7 +618,7 @@ class CommentStoreTest extends MediaWikiLangTestCase {
        public function testInsertTruncation() {
                $comment = str_repeat( '💣', 16400 );
                $truncated1 = str_repeat( '💣', 63 ) . '...';
-               $truncated2 = str_repeat( '💣', 16383 ) . '...';
+               $truncated2 = str_repeat( '💣', CommentStore::COMMENT_CHARACTER_LIMIT - 3 ) . '...';
 
                $store = $this->makeStore( MIGRATION_WRITE_BOTH, 'ipb_reason' );
                $fields = $store->insert( $this->db, $comment );