UltrasonicNXT has submitted this change and it was merged. Change subject: Fix smileys ......................................................................
Fix smileys Parse them straight to html, rather than preproccessing to wikitext and then parsing that. Prevent double parsing. Change-Id: I764cade8d777daf43f98d48fad0e1b07aeeb2be4 --- M GetNew.api.php M MediaWikiChatClass.php 2 files changed, 26 insertions(+), 44 deletions(-) Approvals: UltrasonicNXT: Verified; Looks good to me, approved diff --git a/GetNew.api.php b/GetNew.api.php index 76d55a9..a3a3f4c 100644 --- a/GetNew.api.php +++ b/GetNew.api.php @@ -65,8 +65,6 @@ $message = $row->chat_message; $timestamp = $row->chat_timestamp; - $message = MediaWikiChat::parseMessage( $message ); - $result->addValue( array( $mName, 'messages', $timestamp ), 'from', strval( $id ) ); $result->addValue( array( $mName, 'messages', $timestamp ), '*', $message ); diff --git a/MediaWikiChatClass.php b/MediaWikiChatClass.php index b0e6a0a..1f3c929 100644 --- a/MediaWikiChatClass.php +++ b/MediaWikiChatClass.php @@ -173,47 +173,10 @@ * @return String: parsed message */ static function parseMessage( $message ) { - global $wgChatRichMessages; + global $wgChatRichMessages, $wgUploadPath; if ( $wgChatRichMessages ) { - - $rawSmileyData = wfMessage( 'smileys' )->plain(); - $smileyData = explode( '* ', $rawSmileyData ); - - $smileys = array(); - - if ( is_array( $smileyData ) ) { - foreach ( $smileyData as $line ) { - $bits = explode( ' ', $line ); - - if ( count( $bits ) > 1 ) { - $chars = trim( $bits[0] ); - $charsSafe = htmlspecialchars( $chars ); - $filename = trim( $bits[1] ); - - $image = "[[!File:$filename|x20px|alt=$charsSafe|link=|$charsSafe]]"; - - $smileys[$chars] = $image; // given chars give given image - $smileys[strtolower( $chars )] = $image; // given chars in upper or - $smileys[strtoupper( $chars )] = $image; // lower case give given image - } - } - } - - $message = ' ' . $message . ' '; - - if ( is_array( $smileys ) ) { - foreach ( $smileys as $chars => $image ) { - $chars = preg_quote( $chars ); - - $message = preg_replace( '` ' . $chars . ' `', ' ' . $image . ' ', $message ); - } - } - - $message = trim( $message ); - $message = str_ireplace( '[[File:', '[[:File:', $message ); // prevent users showing huge local images in chat - $message = str_ireplace( '[[!File:', '[[File:', $message ); $message = "MWCHAT $message"; // flag to show the parser this is a chat message @@ -232,9 +195,7 @@ ); $message = $parseOut->getText(); - $message = str_replace( 'MWCHAT', '', $message ); - - $message = trim( $message ); + $message = str_replace( 'MWCHAT', '', $message ); // remove flag for parser $message = str_replace( '<p>', '', $message ); // remove MW's automatical p, $message = str_replace( '</p>', '', $message ); // it's pointless @@ -246,7 +207,30 @@ $message = htmlentities($message); } - return $message; + $rawSmileyData = wfMessage( 'smileys' )->plain(); + $smileyData = explode( '*', $rawSmileyData ); + + if ( is_array( $smileyData ) ) { + foreach ( $smileyData as $line ) { + $line = trim( $line ); + $bits = explode( ' ', $line ); + + if ( count( $bits ) > 1 ) { + $chars = $bits[0]; + $charsSafe = htmlspecialchars( $chars ); + + $filename = $bits[1]; + $file = wfFindFile( $filename ); + $url = $file->getFullUrl(); + + $image = "<img src='$url' alt='$charsSafe' title='$charsSafe' />"; + + $message = str_ireplace( $chars, $image, $message ); + } + } + } + + return trim( $message ); } /** -- To view, visit https://gerrit.wikimedia.org/r/113965 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I764cade8d777daf43f98d48fad0e1b07aeeb2be4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MediaWikiChat Gerrit-Branch: master Gerrit-Owner: UltrasonicNXT <adamr_car...@btinternet.com> Gerrit-Reviewer: UltrasonicNXT <adamr_car...@btinternet.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits