r90510 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90509‎ | r90510 | r90511 >
Date:05:00, 21 June 2011
Author:nagelp
Status:ok (Comments)
Tags:
Comment:
More escaping to reduce reviewer anxiety (love that word ;). Also escaping wfMsg() now, and thus had to remove <em> tags from i18n file.
Modified paths:
  • /trunk/extensions/Notificator/Notificator.body.php (modified) (history)
  • /trunk/extensions/Notificator/Notificator.i18n.php (modified) (history)
  • /trunk/extensions/Notificator/SpecialNotificator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Notificator/Notificator.body.php
@@ -18,7 +18,7 @@
1919 // Check that the database table is in place
2020 if ( ! Notificator::checkDatabaseTableExists() ) {
2121 $output = '<span class="error">' .
22 - wfMsg( 'notificator-db-table-does-not-exist' ) . '</span>';
 22+ htmlspecialchars( wfMsg( 'notificator-db-table-does-not-exist' ) ) . '</span>';
2323 return array( $output, 'noparse' => true, 'isHTML' => true );
2424 }
2525
@@ -145,7 +145,7 @@
146146
147147 if ( $oldRevisionObj->getTitle() != $newRevisionObj->getTitle() ) {
148148 return '<span class="error">' .
149 - wfMsg( 'notificator-revs-not-from-same-title' ) . '</span>';
 149+ htmlspecialchars( wfMsg( 'notificator-revs-not-from-same-title' ) ) . '</span>';
150150 }
151151
152152 $titleObj = $oldRevisionObj->getTitle();
@@ -207,8 +207,19 @@
208208 }
209209
210210 public static function getReturnToText( $linkToPage, $pageTitle ) {
211 - return '<p style="margin-top: 2em;">' .
212 - wfMsg( 'notificator-return-to' ) . ' <a href="' . $linkToPage . '">' . $pageTitle . '</a>.';
 211+ $aElement = Html::element(
 212+ 'a',
 213+ array( 'href' => $linkToPage ),
 214+ $pageTitle
 215+ );
 216+
 217+ $returnToText = Html::rawElement(
 218+ 'p',
 219+ array( 'style' => 'margin-top: 2em;' ),
 220+ htmlspecialchars( wfMsg( 'notificator-return-to' ) ) . ' ' . $aElement
 221+ );
 222+
 223+ return $returnToText;
213224 }
214225
215226 }
Index: trunk/extensions/Notificator/Notificator.i18n.php
@@ -13,14 +13,14 @@
1414 'notificator-return-to' => 'Return to',
1515 'notificator-special-page-accessed-directly' => 'This special page cannot be accessed directly. It is intended to be used through a Notificator button.',
1616 'notificator-e-mail-address-invalid' => 'The provided e-mail address is invalid.',
17 - 'notificator-notification-not-sent' => 'Notification <em>not</em> sent.',
 17+ 'notificator-notification-not-sent' => 'Notification not sent.',
1818 'notificator-change-tag' => 'change',
1919 'notificator-new-tag' => 'new',
2020 'notificator-notification-text-changes' => '$1 wants to notify you about the following changes to $2:',
2121 'notificator-notification-text-new' => '$1 wants to notify you about $2.',
22 - 'notificator-following-e-mail-sent-to' => 'The following e-mail has been sent to <em>$1</em>:',
 22+ 'notificator-following-e-mail-sent-to' => 'The following e-mail has been sent to $1:',
2323 'notificator-subject' => 'Subject:',
24 - 'notificator-error-sending-e-mail' => 'There was an error when sending the notification e-mail to <em>$1</em>.',
 24+ 'notificator-error-sending-e-mail' => 'There was an error when sending the notification e-mail to $1.',
2525 'notificator-error-parameter-missing' => 'Error: Missing parameter.',
2626 'notificator-notified-already' => '$1 has been notified about this page or page change before.',
2727 );
@@ -69,14 +69,14 @@
7070 'notificator-return-to' => 'Keer terug na',
7171 'notificator-special-page-accessed-directly' => "Die spesiale bladsy kan nie direk aangevra word. Dit is bedoel om gebruik te word deur 'n kennisgewing-knoppie.",
7272 'notificator-e-mail-address-invalid' => 'Die verskafde e-posadres is ongeldig.',
73 - 'notificator-notification-not-sent' => 'Kennisgewing is <em>nie</em> gestuur <em>nie</em>.',
 73+ 'notificator-notification-not-sent' => 'Kennisgewing is nie gestuur nie.',
7474 'notificator-change-tag' => 'verandering',
7575 'notificator-new-tag' => 'nuut',
7676 'notificator-notification-text-changes' => '$1 wil u in kennis stel van die volgende wysigings aan $2:',
7777 'notificator-notification-text-new' => '$1 wil u in kennis van $2.',
78 - 'notificator-following-e-mail-sent-to' => 'Die volgende e-pos is aan <em>$1</em> gestuur:',
 78+ 'notificator-following-e-mail-sent-to' => 'Die volgende e-pos is aan $1 gestuur:',
7979 'notificator-subject' => 'Onderwerp:',
80 - 'notificator-error-sending-e-mail' => "Daar was 'n fout met die stuur van die kennisgewing per e-pos aan <em>$1</em>.",
 80+ 'notificator-error-sending-e-mail' => "Daar was 'n fout met die stuur van die kennisgewing per e-pos aan $1.",
8181 'notificator-error-parameter-missing' => 'Fout: Vermiste parameter.',
8282 'notificator-notified-already' => '$1 is reeds in kennis gestel oor hierdie bladsy of veranderinge.',
8383 );
@@ -96,14 +96,14 @@
9797 'notificator-return-to' => 'Вярнуцца да',
9898 'notificator-special-page-accessed-directly' => 'Гэтая спэцыяльная старонка не выкарыстоўваецца напрамую. Пераход да яе ажыцьцяўляецца пасьля націсканьня кнопкі.',
9999 'notificator-e-mail-address-invalid' => 'Пададзены няслушны адрас электроннай пошты.',
100 - 'notificator-notification-not-sent' => 'Паведамленьне <em>не</em> дасланае.',
 100+ 'notificator-notification-not-sent' => 'Паведамленьне не дасланае.',
101101 'notificator-change-tag' => 'зьмена',
102102 'notificator-new-tag' => 'новае',
103103 'notificator-notification-text-changes' => '$1 паведамляе Вам пра наступныя зьмены на $2:',
104104 'notificator-notification-text-new' => '$1 паведамляе Вам пра $2.',
105 - 'notificator-following-e-mail-sent-to' => 'Наступны ліст быў дасланы на <em>$1</em>:',
 105+ 'notificator-following-e-mail-sent-to' => 'Наступны ліст быў дасланы на $1:',
106106 'notificator-subject' => 'Тэма:',
107 - 'notificator-error-sending-e-mail' => 'Адбылася памылка падчас адпраўкі ліста да <em>$1</em>.',
 107+ 'notificator-error-sending-e-mail' => 'Адбылася памылка падчас адпраўкі ліста да $1.',
108108 'notificator-error-parameter-missing' => 'Памылка: бракуе парамэтру.',
109109 'notificator-notified-already' => '$1 ужо паведамілі пра зьмены на старонцы ці саму старонку.',
110110 );
@@ -122,14 +122,14 @@
123123 'notificator-return-to' => 'Zurück zu',
124124 'notificator-special-page-accessed-directly' => 'Auf diese Spezialseite kann nicht direkt zugegriffen werden. Sie kann nur über eine von der Softwareerweiterung „Notificator“ bereitgestellt Schaltfläche genutzt werden.',
125125 'notificator-e-mail-address-invalid' => 'Die angegebene E-Mail-Adresse ist ungültig.',
126 - 'notificator-notification-not-sent' => 'Die Benachrichtigung wurde <em>nicht</em> versendet.',
 126+ 'notificator-notification-not-sent' => 'Die Benachrichtigung wurde nicht versendet.',
127127 'notificator-change-tag' => 'Änderung',
128128 'notificator-new-tag' => 'Neu',
129129 'notificator-notification-text-changes' => '$1 möchte auf die folgenden Änderungen an $2 hinweisen:',
130130 'notificator-notification-text-new' => '$1 möchte auf $2 hinweisen.',
131 - 'notificator-following-e-mail-sent-to' => 'Die folgende E-Mail wurde an <em>$1</em> gesendet:',
 131+ 'notificator-following-e-mail-sent-to' => 'Die folgende E-Mail wurde an $1 gesendet:',
132132 'notificator-subject' => 'Betreff:',
133 - 'notificator-error-sending-e-mail' => 'Beim Versenden der Benachrichtigungs-E-Mail an <em>$1</em> ist ein Fehler aufgetreten.',
 133+ 'notificator-error-sending-e-mail' => 'Beim Versenden der Benachrichtigungs-E-Mail an $1 ist ein Fehler aufgetreten.',
134134 'notificator-error-parameter-missing' => 'Fehler: Fehlender Parameter.',
135135 'notificator-notified-already' => '$1 wurde bereits zu dieser Seite oder Seitenänderung benachrichtigt.',
136136 );
@@ -148,14 +148,14 @@
149149 'notificator-return-to' => 'Volver a',
150150 'notificator-special-page-accessed-directly' => 'No se puede acceder a esta página especial directamente. Está destinada a ser utilizada a través de un botón de Notificador.',
151151 'notificator-e-mail-address-invalid' => 'La dirección de correo electrónico proporcionada no es válida.',
152 - 'notificator-notification-not-sent' => 'Notificación <em>no</em> enviada.',
 152+ 'notificator-notification-not-sent' => 'Notificación no enviada.',
153153 'notificator-change-tag' => 'cambio',
154154 'notificator-new-tag' => 'nuevo',
155155 'notificator-notification-text-changes' => '$1 quiere informarle acerca de los siguientes cambios en $2:',
156156 'notificator-notification-text-new' => '$1 quiere informarle sobre $2.',
157 - 'notificator-following-e-mail-sent-to' => 'Se ha enviado el correo electrónico siguiente a <em>$1</em>:',
 157+ 'notificator-following-e-mail-sent-to' => 'Se ha enviado el correo electrónico siguiente a $1:',
158158 'notificator-subject' => 'Asunto:',
159 - 'notificator-error-sending-e-mail' => 'Hubo un error al enviar el correo electrónico de notificación a <em>$1</em>.',
 159+ 'notificator-error-sending-e-mail' => 'Hubo un error al enviar el correo electrónico de notificación a $1.',
160160 'notificator-error-parameter-missing' => 'Error: Falta un parámetro.',
161161 'notificator-notified-already' => '$1 ha sido notificado sobre esta página o cambio de página antes.',
162162 );
@@ -174,14 +174,14 @@
175175 'notificator-return-to' => 'Volver a',
176176 'notificator-special-page-accessed-directly' => 'Non se pode acceder directamente a esta páxina especial. Cómpre empregala a través dun botón de notificación.',
177177 'notificator-e-mail-address-invalid' => 'O enderezo de correo electrónico proporcionado non é válido.',
178 - 'notificator-notification-not-sent' => '<em>Non</em> se enviou a notificación.',
 178+ 'notificator-notification-not-sent' => 'Non se enviou a notificación.',
179179 'notificator-change-tag' => 'cambio',
180180 'notificator-new-tag' => 'novo',
181181 'notificator-notification-text-changes' => '$1 quere notificarlle sobre os seguintes cambios feitos en $2:',
182182 'notificator-notification-text-new' => '$1 quere notificarlle sobre $2:',
183 - 'notificator-following-e-mail-sent-to' => 'O seguinte correo electrónico enviouse a <em>$1</em>:',
 183+ 'notificator-following-e-mail-sent-to' => 'O seguinte correo electrónico enviouse a $1:',
184184 'notificator-subject' => 'Asunto:',
185 - 'notificator-error-sending-e-mail' => 'Houbo un erro ao enviar a notificación por correo electrónico a <em>$1</em>.',
 185+ 'notificator-error-sending-e-mail' => 'Houbo un erro ao enviar a notificación por correo electrónico a $1.',
186186 'notificator-error-parameter-missing' => 'Erro: Falta o parámetro.',
187187 'notificator-notified-already' => '$1 xa fora notificado antes sobre esta páxina ou cambio na páxina.',
188188 );
@@ -200,7 +200,7 @@
201201 'notificator-return-to' => 'Retornar a',
202202 'notificator-special-page-accessed-directly' => 'Non es possibile acceder directemente a iste pagina special. Iste pagina pote solmente esser usate via un button de Notificator.',
203203 'notificator-e-mail-address-invalid' => 'Le adresse de e-mail fornite es invalide.',
204 - 'notificator-notification-not-sent' => 'Notification <em>non</em> inviate.',
 204+ 'notificator-notification-not-sent' => 'Notification non inviate.',
205205 'notificator-change-tag' => 'cambiar',
206206 'notificator-new-tag' => 'nove',
207207 'notificator-notification-text-changes' => '$1 vole notificar te del sequente modificationes in $2:',
@@ -232,14 +232,14 @@
233233 'notificator-return-to' => 'Назад на',
234234 'notificator-special-page-accessed-directly' => 'До оваа специјална страница не може да се дојде директно. Наменета е да се користи преку копчето за Известувач.',
235235 'notificator-e-mail-address-invalid' => 'Наведената е-пошта е неважечка.',
236 - 'notificator-notification-not-sent' => 'Известувањето <em>не е</em> испратено.',
 236+ 'notificator-notification-not-sent' => 'Известувањето не е испратено.',
237237 'notificator-change-tag' => 'измена',
238238 'notificator-new-tag' => 'ново',
239239 'notificator-notification-text-changes' => '$1 сака да ве извести за следниве измени $2:',
240240 'notificator-notification-text-new' => '$1 сака да ве извести за $2.',
241 - 'notificator-following-e-mail-sent-to' => 'На <em>$1</em> ја пративте следнава порака:',
 241+ 'notificator-following-e-mail-sent-to' => 'На $1 ја пративте следнава порака:',
242242 'notificator-subject' => 'Наслов:',
243 - 'notificator-error-sending-e-mail' => 'Се појави грешка испраќајќи го известувањетоа на <em>$1</em>.',
 243+ 'notificator-error-sending-e-mail' => 'Се појави грешка испраќајќи го известувањетоа на $1.',
244244 'notificator-error-parameter-missing' => 'Грешка: Недостасува параметар.',
245245 'notificator-notified-already' => 'Корисникот $1 е известен за оваа страница или претходните измени на страницата.',
246246 );
@@ -254,7 +254,7 @@
255255 'notificator-e-mail-address-invalid' => 'Het opgegeven e-mailadres is ongeldig.',
256256 'notificator-change-tag' => 'wijzigen',
257257 'notificator-new-tag' => 'nieuw',
258 - 'notificator-following-e-mail-sent-to' => 'De volgende e-mail is verzonden naar <em>$1</em>:',
 258+ 'notificator-following-e-mail-sent-to' => 'De volgende e-mail is verzonden naar $1:',
259259 'notificator-subject' => 'Onderwerp:',
260260 'notificator-error-parameter-missing' => 'Fout: Ontbrekende parameter.',
261261 );
@@ -273,14 +273,14 @@
274274 'notificator-return-to' => 'Voltar a',
275275 'notificator-special-page-accessed-directly' => 'Não pode aceder directamente a esta página especial. Ela é utilizada através de um botão Notificador.',
276276 'notificator-e-mail-address-invalid' => 'O endereço de correio electrónico fornecido é inválido.',
277 - 'notificator-notification-not-sent' => 'A notificação <em>não foi</em> enviada.',
 277+ 'notificator-notification-not-sent' => 'A notificação não foi enviada.',
278278 'notificator-change-tag' => 'alterada',
279279 'notificator-new-tag' => 'nova',
280280 'notificator-notification-text-changes' => 'A $1 pretende notificar as seguintes alterações a $2:',
281281 'notificator-notification-text-new' => 'A $1 pretende fazer uma notificação acerca de $2.',
282 - 'notificator-following-e-mail-sent-to' => 'A seguinte mensagem foi enviada por correio electrónico para <em>$1</em>:',
 282+ 'notificator-following-e-mail-sent-to' => 'A seguinte mensagem foi enviada por correio electrónico para $1:',
283283 'notificator-subject' => 'Assunto:',
284 - 'notificator-error-sending-e-mail' => 'Ocorreu um erro ao enviar a notificação por correio electrónico a <em>$1</em>.',
 284+ 'notificator-error-sending-e-mail' => 'Ocorreu um erro ao enviar a notificação por correio electrónico a $1.',
285285 'notificator-error-parameter-missing' => 'Erro: Parâmetro em falta.',
286286 'notificator-notified-already' => '$1 já foi notificado acerca desta página ou da alteração desta página.',
287287 );
Index: trunk/extensions/Notificator/SpecialNotificator.php
@@ -22,15 +22,17 @@
2323 $receiver = $wgRequest->getText( 'receiver' );
2424
2525 if ( ! $pageId || ! $revId || ! $receiver ) {
26 - $output = '<span class="error">' . wfMsg( 'notificator-special-page-accessed-directly' ) . '</span>';
 26+ $output = '<span class="error">' . htmlspecialchars(
 27+ wfMsg( 'notificator-special-page-accessed-directly' ) ) . '</span>';
2728 } else {
2829 $titleObj = Title::newFromID( $pageId );
2930 $pageTitle = $titleObj->getFullText();
3031 $linkToPage = $titleObj->getFullURL();
3132
3233 if ( ! Notificator::receiverIsValid( $receiver ) ) {
33 - $output = '<span class="error">' . wfMsg( 'notificator-e-mail-address-invalid' ) . ' ' .
34 - wfMsg( 'notificator-notification-not-sent' ) . '</span>';
 34+ $output = '<span class="error">' . htmlspecialchars(
 35+ wfMsg( 'notificator-e-mail-address-invalid' ) . ' ' .
 36+ wfMsg( 'notificator-notification-not-sent' ) ) . '</span>';
3537 $output .= Notificator::getReturnToText( $linkToPage, $pageTitle );
3638 $wgOut->addHTML( $output );
3739 return;
@@ -41,37 +43,53 @@
4244 if ( $oldRevId >= 0 ) {
4345 if ( $oldRevId > 0 ) {
4446 // Receiver has been notified before - send the diff to the last notified revision
45 - $mailSubjectPrefix = '[' . wfMsg( 'notificator-change-tag' ) . '] ';
 47+ $mailSubjectPrefix = '[' . htmlspecialchars( wfMsg( 'notificator-change-tag' ) ) . '] ';
4648
4749 $wgOut->addModules( 'mediawiki.legacy.diff' );
4850 $diff = Notificator::getNotificationDiffHtml( $oldRevId, $revId );
4951 $notificationText = wfMsg( 'notificator-notification-text-changes',
50 - htmlspecialchars( $wgUser->getName() ), '<a href="' . $linkToPage . '">' .
51 - $pageTitle . '</a>' ) . '<div style="margin-top: 1em;">' . $diff . '</div>';
 52+ htmlspecialchars( $wgUser->getName() ),
 53+ Html::element(
 54+ 'a',
 55+ array( 'href' => $linkToPage ),
 56+ $pageTitle
 57+ )
 58+ ) .
 59+ Html::rawElement(
 60+ 'div',
 61+ array( 'style' => 'margin-top: 1em' ),
 62+ $diff
 63+ );
5264 } else {
5365 // Receiver has never been notified about this page - so don't send a diff, just the link
54 - $mailSubjectPrefix = '[' . wfMsg( 'notificator-new-tag' ) . '] ';
 66+ $mailSubjectPrefix = '[' . htmlspecialchars( wfMsg( 'notificator-new-tag' ) ) . '] ';
5567 $notificationText = wfMsg( 'notificator-notification-text-new',
56 - htmlspecialchars( $wgUser->getName() ), '<a href="' . $linkToPage . '">' .
57 - $pageTitle . '</a>' );
 68+ htmlspecialchars( $wgUser->getName() ),
 69+ Html::element(
 70+ 'a',
 71+ array( 'href' => $linkToPage ),
 72+ $pageTitle
 73+ )
 74+ );
5875 }
5976 $mailSubject = htmlspecialchars( $mailSubjectPrefix . $pageTitle );
6077
6178 if ( Notificator::sendNotificationMail( $receiver, $mailSubject, $notificationText ) ) {
62 - $output = '<strong>' . wfMsg( 'notificator-following-e-mail-sent-to',
 79+ $output = '<strong>' . htmlspecialchars( wfMsg( 'notificator-following-e-mail-sent-to' ),
6380 htmlspecialchars( $receiver ) ) . '</strong><div style="margin-top: 1em;"><h3>' .
6481 wfMsg( 'notificator-subject' ) . ' ' . $mailSubject . '</h3><p>' . $notificationText .
6582 '</p></div>';
6683 Notificator::recordNotificationInDatabase( $pageId, $revId, $receiver );
6784 } else {
68 - $output = '<span class="error">' . wfMsg( 'notificator-error-sending-e-mail',
69 - htmlspecialchars( $receiver ) ) . '</span>';
 85+ $output = '<span class="error">' . htmlspecialchars(
 86+ wfMsg( 'notificator-error-sending-e-mail', $receiver ) ) . '</span>';
7087 }
7188 } elseif ( $oldRevId == -1 ) {
72 - $output = '<span class="error">' . wfMsg( 'notificator-error-parameter-missing' ) . '</span>';
 89+ $output = '<span class="error">' . htmlspecialchars(
 90+ wfMsg( 'notificator-error-parameter-missing' ) ) . '</span>';
7391 } elseif ( $oldRevId == -2 ) {
74 - $output = '<strong>' . wfMsg( 'notificator-notified-already', htmlspecialchars( $receiver ) ) .
75 - ' ' . wfMsg( 'notificator-notification-not-sent' ) . '</strong>';
 92+ $output = '<strong>' . htmlspecialchars ( wfMsg( 'notificator-notified-already',
 93+ $receiver ) . ' ' . wfMsg( 'notificator-notification-not-sent' ) ) . '</strong>';
7694 }
7795
7896 $output .= Notificator::getReturnToText( $linkToPage, $pageTitle );

Comments

#Comment by Raymond (talk | contribs)   11:13, 21 June 2011

Just a note: It it not necessary to update translated messages. These will be handled by Transatewiki staff.

#Comment by Nikerabbit (talk | contribs)   10:38, 17 August 2011

Better. In some places OutputPage->addWikiMsg and wrapWikiMsg would make the code more concise and readable.

Status & tagging log