From 7d2bf6aac13fced0733a51aa494af61f4f8bbdbd Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sat, 1 Dec 2012 20:11:21 +0100 Subject: [PATCH] Trim spaces on user supplied comments This helps on bug 29575 Change-Id: Ic05e5898f8a7c93a95188c9342d22c70d7413b09 --- includes/EditPage.php | 5 ++++- includes/RecentChange.php | 3 +++ includes/WikiPage.php | 3 +++ includes/filerepo/file/LocalFile.php | 3 +++ includes/logging/LogEntry.php | 5 ++++- includes/logging/LogPage.php | 3 +++ 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index f3c0237f76..5f38cf360c 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -617,8 +617,11 @@ class EditPage { wfProfileOut( get_class( $this ) . "::importContentFormData" ); } + # Trim spaces on user supplied text + $summary = trim( $request->getText( 'wpSummary' ) ); + # Truncate for whole multibyte characters - $this->summary = $wgContLang->truncate( $request->getText( 'wpSummary' ), 255 ); + $this->summary = $wgContLang->truncate( $summary, 255 ); # If the summary consists of a heading, e.g. '==Foobar==', extract the title from the # header syntax, e.g. 'Foobar'. This is mainly an issue when we are using wpSummary for diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 87fa428201..56df21e2f5 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -235,6 +235,9 @@ class RecentChange { unset( $this->mAttribs['rc_ip'] ); } + # Trim spaces on user supplied text + $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] ); + # Make sure summary is truncated (whole multibyte characters) $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 ); diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 70ed7e7d9d..e2cd5d988f 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2792,6 +2792,9 @@ class WikiPage extends Page implements IDBAccessObject { $summary = wfMsgReplaceArgs( $summary, $args ); } + // Trim spaces on user supplied text + $summary = trim( $summary ); + // Truncate for whole multibyte characters. $summary = $wgContLang->truncate( $summary, 255 ); diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index a9678b7b20..9babe5a0e4 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -996,6 +996,9 @@ class LocalFile extends File { $options['headers'] = array(); } + // Trim spaces on user supplied text + $comment = trim( $comment ); + // truncate nicely or the DB will do it for us // non-nicely (dangling multi-byte chars, non-truncated version in cache). $comment = $wgContLang->truncate( $comment, 255 ); diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 1f94b43a89..ed9aa5a0f0 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -442,8 +442,11 @@ class ManualLogEntry extends LogEntryBase { $this->timestamp = wfTimestampNow(); } + # Trim spaces on user supplied text + $comment = trim( $this->getComment() ); + # Truncate for whole multibyte characters. - $comment = $wgContLang->truncate( $this->getComment(), 255 ); + $comment = $wgContLang->truncate( $comment, 255 ); $data = array( 'log_id' => $id, diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 07238a053a..5854e99b77 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -421,6 +421,9 @@ class LogPage { $comment = ''; } + # Trim spaces on user supplied text + $comment = trim( $comment ); + # Truncate for whole multibyte characters. $comment = $wgContLang->truncate( $comment, 255 ); -- 2.20.1