aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-11-15 09:56:15 +0000
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-11-15 09:56:15 +0000
commita574a5c1b352b6c016cc132c561bebdbe0996f8d (patch)
tree4d1e2d76fa62cbe973852e877084d454267d61bf
parentf1b2dce1a89e2d53492375f5f2847a5c498caa07 (diff)
disable and deprecate transformBeforeSave(), fixes #1601
Closes #1601 Merge request studip/studip!1159
-rw-r--r--app/controllers/course/forum/index.php9
-rw-r--r--lib/classes/ForumEntry.php4
-rw-r--r--lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php4
-rw-r--r--lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php4
-rw-r--r--lib/classes/JsonApi/Routes/Wiki/WikiCreate.php5
-rw-r--r--lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php5
-rw-r--r--lib/classes/StudipTransformFormat.php1
-rw-r--r--lib/models/BlubberComment.php17
-rw-r--r--lib/models/BlubberThread.php30
-rw-r--r--lib/visual.inc.php8
-rw-r--r--lib/wiki.inc.php5
11 files changed, 27 insertions, 65 deletions
diff --git a/app/controllers/course/forum/index.php b/app/controllers/course/forum/index.php
index f62a6c1..02e2e9a 100644
--- a/app/controllers/course/forum/index.php
+++ b/app/controllers/course/forum/index.php
@@ -341,14 +341,9 @@ class Course_Forum_IndexController extends ForumController
*/
function preview_action() {
if (Request::isXhr()) {
- $this->set_content_type('text/html; charset=UTF-8');
- $this->render_text(formatReady(transformBeforeSave(Request::get('posting'))));
+ $this->render_text(formatReady(Request::get('posting')));
} else {
- $this->render_text(
- ForumEntry::getContentAsHtml(
- transformBeforeSave(Request::get('posting'))
- )
- );
+ $this->render_text(ForumEntry::getContentAsHtml(Request::get('posting')));
}
}
diff --git a/lib/classes/ForumEntry.php b/lib/classes/ForumEntry.php
index f18fbb2..ec1185f 100644
--- a/lib/classes/ForumEntry.php
+++ b/lib/classes/ForumEntry.php
@@ -948,7 +948,7 @@ class ForumEntry implements PrivacyObject
chdate, author, author_host, lft, rgt, depth, anonymous)
VALUES (? ,?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?, ?, ?, ?, ?, ?)");
$stmt->execute([$data['topic_id'], $data['seminar_id'], $data['user_id'],
- $data['name'], transformBeforeSave($data['content']), $data['author'], $data['author_host'],
+ $data['name'], $data['content'], $data['author'], $data['author_host'],
$constraint['rgt'], $constraint['rgt'] + 1, $constraint['depth'] + 1, $data['anonymous'] ?? 0]);
// update "latest_chdate" for easier sorting of actual threads
@@ -979,7 +979,7 @@ class ForumEntry implements PrivacyObject
$stmt = DBManager::get()->prepare("UPDATE forum_entries
SET name = ?, content = ?, chdate = UNIX_TIMESTAMP(), latest_chdate = UNIX_TIMESTAMP()
WHERE topic_id = ?");
- $stmt->execute([$name, transformBeforeSave($content), $topic_id]);
+ $stmt->execute([$name, $content, $topic_id]);
// update "latest_chdate" for easier sorting of actual threads
$parent_id = ForumEntry::getParentTopicId($topic_id);
diff --git a/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php b/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php
index a4905b6..204414b 100644
--- a/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php
+++ b/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php
@@ -24,9 +24,7 @@ abstract class AbstractEntriesCreate extends JsonApiController
//Check whether the parent is category or entry of first or seccond depth
$title = self::arrayGet($json, 'data.attributes.title');
$content = self::arrayGet($json, 'data.attributes.content');
- if (method_exists(\Studip\Markup::class, 'purifyHtml')) {
- $content = transformBeforeSave(\Studip\Markup::purifyHtml($content));
- }
+ $content = \Studip\Markup::purifyHtml($content);
$parent = $this->getParentObject($parentId);
return $this->createEntry($title, $content, $parent, $user);
diff --git a/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php b/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php
index 4ef1ee1..1165ff2 100644
--- a/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php
+++ b/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php
@@ -50,9 +50,7 @@ class ForumEntriesUpdate extends JsonApiController
$entry->name = $title;
}
if (!empty($content)) {
- if (method_exists(\Studip\Markup::class, 'purifyHtml')) {
- $content = transformBeforeSave(\Studip\Markup::purifyHtml($content));
- }
+ $content = \Studip\Markup::purifyHtml($content);
$entry->content = $content;
}
if ($entry->isDirty()) {
diff --git a/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php b/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php
index 79a8a55..ffd4efc 100644
--- a/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php
+++ b/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php
@@ -54,10 +54,7 @@ class WikiCreate extends JsonApiController
{
$keyword = self::arrayGet($json, 'data.attributes.keyword');
$content = self::arrayGet($json, 'data.attributes.content');
-
- if (method_exists(\Studip\Markup::class, 'purifyHtml')) {
- $content = transformBeforeSave(\Studip\Markup::purifyHtml($content));
- }
+ $content = \Studip\Markup::purifyHtml($content);
$wiki = new \WikiPage();
$wiki->keyword = $keyword;
diff --git a/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php b/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php
index 7fc7088..15acd60 100644
--- a/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php
+++ b/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php
@@ -40,10 +40,7 @@ class WikiUpdate extends JsonApiController
protected function updateWikiFromJSON(\User $user, \WikiPage $wikiPage, $json)
{
$content = self::arrayGet($json, 'data.attributes.content');
-
- if (method_exists(\Studip\Markup::class, 'purifyHtml')) {
- $content = transformBeforeSave(\Studip\Markup::purifyHtml($content));
- }
+ $content = \Studip\Markup::purifyHtml($content);
if ($wikiPage->body === $content) {
return $wikiPage;
diff --git a/lib/classes/StudipTransformFormat.php b/lib/classes/StudipTransformFormat.php
index 9b56d1a..04cf7a3 100644
--- a/lib/classes/StudipTransformFormat.php
+++ b/lib/classes/StudipTransformFormat.php
@@ -12,6 +12,7 @@
/**
* Format class to transform text before it is saved into the database.
+ * @deprecated since Stud.IP 5.3
*/
class StudipTransformFormat extends TextFormat
{
diff --git a/lib/models/BlubberComment.php b/lib/models/BlubberComment.php
index 1da6743..3e076af 100644
--- a/lib/models/BlubberComment.php
+++ b/lib/models/BlubberComment.php
@@ -117,21 +117,8 @@ class BlubberComment extends SimpleORMap implements PrivacyObject
public function transformMentions()
{
- BlubberThread::$mention_thread_id = $this->thread_id;
- StudipTransformFormat::addStudipMarkup(
- 'mention1',
- '(?:^|\W)(@\"[^\n\"]*\")',
- '',
- 'BlubberThread::mention'
- );
- StudipTransformFormat::addStudipMarkup(
- 'mention2',
- '(?:^|\W)(@[^\s]*[\d\w_]+)',
- '',
- 'BlubberThread::mention'
- );
- $this['content'] = \Studip\Markup::purifyHtml($this['content']);
- $this['content'] = transformBeforeSave($this['content']);
+ $callback = [$this->thread, 'mention'];
+ $this['content'] = preg_replace_callback('/\B@("[^\n"]+"|\S+)/', $callback, $this['content']);
}
/**
diff --git a/lib/models/BlubberThread.php b/lib/models/BlubberThread.php
index 70d99e2..0048c21 100644
--- a/lib/models/BlubberThread.php
+++ b/lib/models/BlubberThread.php
@@ -47,22 +47,18 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
parent::configure($config);
}
- public static $mention_thread_id = null;
protected $last_visit = null;
/**
- * Pre-Markup rule. Recognizes mentions in blubber as @username or @"Firstname lastname"
+ * Recognizes mentions in blubber as @username or @"Firstname lastname"
* and turns them into usual studip-links. The mentioned person is notified by
* sending a message to him/her as a side-effect.
- * @param StudipTransformFormat $markup
* @param array $matches
* @return string
*/
- public static function mention($markup, $matches)
+ public function mention($matches)
{
- $mention = $matches[1];
- $thread = self::find(self::$mention_thread_id);
- $username = stripslashes(mb_substr($mention, 1));
+ $username = stripslashes(mb_substr($matches[0], 1));
if ($username[0] !== '"') {
$user = User::findByUsername($username);
} else {
@@ -70,21 +66,21 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
$user = User::findOneBySQL("CONCAT(Vorname, ' ', Nachname) = ?", [$name]);
}
if ($user
- && !$thread->isNew()
+ && !$this->isNew()
&& $user->getId()
&& $user->getId() !== $GLOBALS['user']->id
) {
- if ($thread['context_type'] === 'private') {
+ if ($this['context_type'] === 'private') {
$mention = new BlubberMention();
- $mention['thread_id'] = $thread->getId();
+ $mention['thread_id'] = $this->getId();
$mention['user_id'] = $user->getId();
$mention->store();
- } elseif ($thread['context_type'] === 'public') {
+ } elseif ($this['context_type'] === 'public') {
PersonalNotifications::add(
$user->getId(),
- $thread->getURL(),
+ $this->getURL(),
sprintf(_('%s hat Sie in einem Blubber erwähnt.'), get_fullname()),
- 'blubberthread_' . $thread->getId(),
+ 'blubberthread_' . $this->getId(),
Icon::create('blubber'),
true
);
@@ -93,14 +89,10 @@ class BlubberThread extends SimpleORMap implements PrivacyObject
$url = URLHelper::getLink('dispatch.php/profile', ['username' => $user->username]);
URLHelper::setBaseURL($oldbase);
- return str_replace(
- $matches[1],
- '[' . $user->getFullName() . ']' . $url . ' ',
- $matches[0]
- );
+ return '[' . $user->getFullName() . ']' . $url . ' ';
}
- return $markup->quote($matches[0]);
+ return $matches[0];
}
public static function findBySQL($sql, $params = [])
diff --git a/lib/visual.inc.php b/lib/visual.inc.php
index 1c3cd9e..a4bb96e 100644
--- a/lib/visual.inc.php
+++ b/lib/visual.inc.php
@@ -173,14 +173,14 @@ function blubberReady($text, $trim=TRUE) {
}
/**
- * Apply StudipTransformFormat rules to marked-up text.
+ * Obsolete function for compatibility, returns text unchanged.
*
* @param string $text Marked-up text.
- * @return string HTML code computed by applying markup-rules.
+ * @return string Marked-up text.
+ * @deprecated since Stud.IP 5.3
*/
function transformBeforeSave($text){
- $markup = new StudipTransformFormat();
- return $markup->format($text);
+ return $text;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/lib/wiki.inc.php b/lib/wiki.inc.php
index e5a0ff4..0b6be7b 100644
--- a/lib/wiki.inc.php
+++ b/lib/wiki.inc.php
@@ -69,8 +69,7 @@ function submitWikiPage($keyword, $version, $body, $user_id, $range_id, $ancesto
$wp = WikiPage::find([$range_id, $keyword, $version]);
if ($wp) {
if ($wp->isEditableBy($GLOBALS['user'])) {
- // apply replace-before-save transformations
- $wp->body = transformBeforeSave($body);
+ $wp->body = $body;
if ($wp->isValidAncestor($ancestor)) {
$wp->setAncestorForAllVersions($ancestor);
} else {
@@ -88,8 +87,6 @@ function submitWikiPage($keyword, $version, $body, $user_id, $range_id, $ancesto
$version = $latestVersion['version'] + 1;
}
- // apply replace-before-save transformations
- $body = transformBeforeSave($body);
WikiPage::create(compact('range_id', 'user_id', 'keyword', 'body', 'ancestor', 'version'));
}
StudipTransformFormat::removeStudipMarkup('wiki-comments');