Skip to content

Commit

Permalink
Treat passed user input as plaintext (#78)
Browse files Browse the repository at this point in the history
* Treat passed user input as plaintext

* Convert more message functions
  • Loading branch information
lens0021 authored Aug 27, 2021
1 parent 85450e4 commit 9ddb74a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions DiscordNotificationsCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static function onDiscordPageSaveComplete( $wikiPage, $user, $summary, $f
$message = self::msg( 'discordnotifications-article-created',
self::getDiscordUserText( $user ),
self::getDiscordArticleText( $wikiPage ),
$summary == "" ? "" : self::msg( 'discordnotifications-summary', $summary ) );
$summary == "" ? "" : wfMessage( 'discordnotifications-summary' )->plaintextParams( $summary ) );
if ( $wgDiscordIncludeDiffSize ) {
$message .= " (" . self::msg( 'discordnotifications-bytes', $revisionRecord->getSize() ) . ")";
}
Expand All @@ -156,7 +156,7 @@ public static function onDiscordPageSaveComplete( $wikiPage, $user, $summary, $f
self::getDiscordUserText( $user ),
$isMinor == true ? self::msg( 'discordnotifications-article-saved-minor-edits' ) : self::msg( 'discordnotifications-article-saved-edit' ),
self::getDiscordArticleText( $wikiPage, true ),
$summary == "" ? "" : self::msg( 'discordnotifications-summary', $summary ) );
$summary == "" ? "" : wfMessage( 'discordnotifications-summary' )->plaintextParams( $summary ) );
if ( $wgDiscordIncludeDiffSize ) {
$message .= ' (' . self::msg( 'discordnotifications-bytes',
$revisionRecord->getSize() - MediaWiki\MediaWikiServices::getInstance()->getRevisionLookup()->getPreviousRevision( $revisionRecord )->getSize() ) . ')';
Expand Down Expand Up @@ -192,12 +192,12 @@ public static function onDiscordArticleSaved( WikiPage $article, $user, $content
return;
}

$message = self::msg(
'discordnotifications-article-saved',
$message = wfMessage( 'discordnotifications-article-saved' )->plaintextParams(
self::getDiscordUserText( $user ),
$isMinor == true ? self::msg( 'discordnotifications-article-saved-minor-edits' ) : self::msg( 'discordnotifications-article-saved-edit' ),
self::getDiscordArticleText( $article, true ),
$summary == "" ? "" : self::msg( 'discordnotifications-summary', $summary ) );
$summary == "" ? "" : wfMessage( 'discordnotifications-summary' )->plaintextParams( $summary )->inContentLanguage()->plain()
)->inContentLanguage()->text();
if ( $wgDiscordIncludeDiffSize ) {
$message .= ' (' . self::msg( 'discordnotifications-bytes',
$article->getRevision()->getSize() - $article->getRevision()->getPrevious()->getSize() ) . ')';
Expand All @@ -219,10 +219,11 @@ public static function onDiscordArticleInserted( WikiPage $article, $user, $text
// Do not announce newly added file uploads as articles...
if ( $article->getTitle()->getNsText() == self::msg( 'discordnotifications-file-namespace' ) ) return true;

$message = self::msg( 'discordnotifications-article-created',
$message = wfMessage( 'discordnotifications-article-created' )->plaintextParams(
self::getDiscordUserText( $user ),
self::getDiscordArticleText( $article ),
$summary == "" ? "" : self::msg( 'discordnotifications-summary', $summary ) );
$summary == "" ? "" : wfMessage( 'discordnotifications-summary' )->plaintextParams( $summary )->inContentLanguage()->plain()
)->inContentLanguage()->text();
if ( $wgDiscordIncludeDiffSize ) {
if ( defined( 'MW_VERSION' ) && version_compare( MW_VERSION, '1.31', '>=' ) ) {
// WikiPage::getRevision was deprecated in MediaWiki 1.35
Expand Down Expand Up @@ -250,10 +251,11 @@ public static function onDiscordArticleDeleted( WikiPage $article, User $user, $

if ( self::titleIsExcluded( $article->getTitle() ) ) return;

$message = self::msg( 'discordnotifications-article-deleted',
$message = wfMessage( 'discordnotifications-article-deleted' )->plaintextParams(
self::getDiscordUserText( $user ),
self::getDiscordArticleText( $article ),
$reason );
$reason
)->inContentLanguage()->text();
self::pushDiscordNotify( $message, $user, 'article_deleted' );
return true;
}
Expand Down

0 comments on commit 9ddb74a

Please sign in to comment.