X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCommentStore.php;h=bf3e3d6608a6d993bfaf95f1fdbb4785ad09fa0d;hb=261236c964b8862e5fa7566fad9a5fce0c2048d5;hp=1fea309a70167ea9343088b3895efae04dd11dc5;hpb=6866cfec3731409994b3edf857504e8674c00a8e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/CommentStore.php b/includes/CommentStore.php index 1fea309a70..bf3e3d6608 100644 --- a/includes/CommentStore.php +++ b/includes/CommentStore.php @@ -98,7 +98,7 @@ class CommentStore { /** * @param Language $lang Language to use for comment truncation. Defaults - * to $wgContLang. + * to content language. * @param int $migrationStage One of the MIGRATION_* constants */ public function __construct( Language $lang, $migrationStage ) { @@ -114,10 +114,11 @@ class CommentStore { * @return CommentStore */ public static function newKey( $key ) { - global $wgCommentTableSchemaMigrationStage, $wgContLang; + global $wgCommentTableSchemaMigrationStage; // TODO uncomment once not used in extensions // wfDeprecated( __METHOD__, '1.31' ); - $store = new CommentStore( $wgContLang, $wgCommentTableSchemaMigrationStage ); + $store = new CommentStore( MediaWikiServices::getInstance()->getContentLanguage(), + $wgCommentTableSchemaMigrationStage ); $store->key = $key; return $store; } @@ -158,7 +159,7 @@ class CommentStore { * * @since 1.30 * @since 1.31 Method signature changed, $key parameter added (with deprecated back compat) - * @param string $key A key such as "rev_comment" identifying the comment + * @param string|null $key A key such as "rev_comment" identifying the comment * field being fetched. * @return string[] to include in the `$vars` to `IDatabase->select()`. All * fields are aliased, so `+` is safe to use. @@ -191,7 +192,7 @@ class CommentStore { * * @since 1.30 * @since 1.31 Method signature changed, $key parameter added (with deprecated back compat) - * @param string $key A key such as "rev_comment" identifying the comment + * @param string|null $key A key such as "rev_comment" identifying the comment * field being fetched. * @return array With three keys: * - tables: (string[]) to include in the `$table` to `IDatabase->select()` @@ -381,7 +382,7 @@ class CommentStore { * @since 1.31 Method signature changed, $key parameter added (with deprecated back compat) * @param string $key A key such as "rev_comment" identifying the comment * field being fetched. - * @param object|array $row Result row. + * @param object|array|null $row Result row. * @param bool $fallback If true, fall back as well as possible instead of throwing an exception. * @return CommentStoreComment */ @@ -415,7 +416,7 @@ class CommentStore { * @param IDatabase $db Database handle to use for lookup * @param string $key A key such as "rev_comment" identifying the comment * field being fetched. - * @param object|array $row Result row. + * @param object|array|null $row Result row. * @param bool $fallback If true, fall back as well as possible instead of throwing an exception. * @return CommentStoreComment */ @@ -458,16 +459,7 @@ class CommentStore { $comment = CommentStoreComment::newUnsavedComment( $comment, $data ); # 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; - } + $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT ); if ( $this->stage > MIGRATION_OLD && !$comment->id ) { $dbData = $comment->data; @@ -530,7 +522,7 @@ class CommentStore { $comment = $this->createComment( $dbw, $comment, $data ); if ( $this->stage <= MIGRATION_WRITE_BOTH ) { - $fields[$key] = $this->lang->truncate( $comment->text, 255 ); + $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 ); } if ( $this->stage >= MIGRATION_WRITE_BOTH ) { @@ -567,7 +559,7 @@ class CommentStore { * @param IDatabase $dbw Database handle to insert on * @param string $key A key such as "rev_comment" identifying the comment * field being fetched. - * @param string|Message|CommentStoreComment $comment As for `self::createComment()` + * @param string|Message|CommentStoreComment|null $comment As for `self::createComment()` * @param array|null $data As for `self::createComment()` * @return array Fields for the insert or update */ @@ -606,7 +598,7 @@ class CommentStore { * @param IDatabase $dbw Database handle to insert on * @param string $key A key such as "rev_comment" identifying the comment * field being fetched. - * @param string|Message|CommentStoreComment $comment As for `self::createComment()` + * @param string|Message|CommentStoreComment|null $comment As for `self::createComment()` * @param array|null $data As for `self::createComment()` * @return array Two values: * - array Fields for the insert or update