function test_white_between_words() { // From FS#2161 global $lang; $df = new Diff(explode("\n", "example"), explode("\n", "example example2")); $idf = new InlineDiffFormatter(); $tdf = new TableDiffFormatter(); $this->assertEqual($idf->format($df), '<tr><td colspan="4" class="diff-blockheader">@@ ' . $lang['line'] . ' -1 +1 @@ <span class="diff-deletedline"><del>' . $lang['deleted'] . '</del></span> <span class="diff-addedline">' . $lang['created'] . '</span></td></tr> <tr><td colspan="4">example <span class="diff-addedline">example2</span></td></tr> '); $this->assertEqual($tdf->format($df), '<tr><td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td> <td class="diff-blockheader" colspan="2">' . $lang['line'] . ' 1:</td> </tr> <tr><td>-</td><td class="diff-deletedline">example</td><td>+</td><td class="diff-addedline">example <strong>example2</strong></td></tr> '); }
/** * Sends a notify mail on page change or registration * * @param string $id The changed page * @param string $who Who to notify (admin|subscribers|register) * @param int|string $rev Old page revision * @param string $summary What changed * @param boolean $minor Is this a minor edit? * @param array $replace Additional string substitutions, @KEY@ to be replaced by value * * @return bool * @author Andreas Gohr <*****@*****.**> */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { global $lang; global $conf; global $INFO; global $DIFF_INLINESTYLES; // decide if there is something to do, eg. whom to mail if ($who == 'admin') { if (empty($conf['notify'])) { return false; } //notify enabled? $text = rawLocale('mailtext'); $to = $conf['notify']; $bcc = ''; } elseif ($who == 'subscribers') { if (!$conf['subscribers']) { return false; } //subscribers enabled? if ($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) { return false; } //skip minors $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event('COMMON_NOTIFY_ADDRESSLIST', $data, 'subscription_addresslist'); $bcc = $data['addresslist']; if (empty($bcc)) { return false; } $to = ''; $text = rawLocale('subscr_single'); } elseif ($who == 'register') { if (empty($conf['registernotify'])) { return false; } $text = rawLocale('registermail'); $to = $conf['registernotify']; $bcc = ''; } else { return false; //just to be safe } // prepare replacements (keys not set in hrep will be taken from trep) $trep = array('NEWPAGE' => wl($id, '', true, '&'), 'PAGE' => $id, 'SUMMARY' => $summary); $trep = array_merge($trep, $replace); $hrep = array(); // prepare content if ($who == 'register') { $subject = $lang['mail_new_user'] . ' ' . $summary; } elseif ($rev) { $subject = $lang['mail_changed'] . ' ' . $id; $trep['OLDPAGE'] = wl($id, "rev={$rev}", true, '&'); $df = new Diff(explode("\n", rawWiki($id, $rev)), explode("\n", rawWiki($id))); $dformat = new UnifiedDiffFormatter(); $tdiff = $dformat->format($df); $DIFF_INLINESTYLES = true; $dformat = new InlineDiffFormatter(); $hdiff = $dformat->format($df); $hdiff = '<table>' . $hdiff . '</table>'; $DIFF_INLINESTYLES = false; } else { $subject = $lang['mail_newpage'] . ' ' . $id; $trep['OLDPAGE'] = '---'; $tdiff = rawWiki($id); $hdiff = nl2br(hsc($tdiff)); } $trep['DIFF'] = $tdiff; $hrep['DIFF'] = $hdiff; // send mail $mail = new Mailer(); $mail->to($to); $mail->bcc($bcc); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); if ($who == 'subscribers') { $mail->setHeader('List-Unsubscribe', '<' . wl($id, array('do' => 'subscribe'), true, '&') . '>', false); } return $mail->send(); }
/** * Send the diff for some page change * * @param string $subscriber_mail The target mail address * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...) * @param string $id Page for which the notification is * @param int|null $rev Old revision if any * @param string $summary Change summary if any * @return bool true if successfully sent */ public function send_diff($subscriber_mail, $template, $id, $rev = null, $summary = '') { global $DIFF_INLINESTYLES; // prepare replacements (keys not set in hrep will be taken from trep) $trep = array('PAGE' => $id, 'NEWPAGE' => wl($id, '', true, '&'), 'SUMMARY' => $summary, 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&')); $hrep = array(); if ($rev) { $subject = 'changed'; $trep['OLDPAGE'] = wl($id, "rev={$rev}", true, '&'); $old_content = rawWiki($id, $rev); $new_content = rawWiki($id); $df = new Diff(explode("\n", $old_content), explode("\n", $new_content)); $dformat = new UnifiedDiffFormatter(); $tdiff = $dformat->format($df); $DIFF_INLINESTYLES = true; $df = new Diff(explode("\n", $old_content), explode("\n", $new_content)); $dformat = new InlineDiffFormatter(); $hdiff = $dformat->format($df); $hdiff = '<table>' . $hdiff . '</table>'; $DIFF_INLINESTYLES = false; } else { $subject = 'newpage'; $trep['OLDPAGE'] = '---'; $tdiff = rawWiki($id); $hdiff = nl2br(hsc($tdiff)); } $trep['DIFF'] = $tdiff; $hrep['DIFF'] = $hdiff; $headers = array('Message-Id' => $this->getMessageID($id)); if ($rev) { $headers['In-Reply-To'] = $this->getMessageID($id, $rev); } return $this->send($subscriber_mail, $subject, $id, $template, $trep, $hrep, $headers); }
/** * Creates an inline diff * @param Content $otext Old content * @param Content $ntext New content * * @return string */ function generateTextDiffBody($otext, $ntext) { global $wgContLang; # First try wikidiff2 if (function_exists('wikidiff2_inline_diff')) { $text = wikidiff2_inline_diff($otext, $ntext, 2); $text .= $this->debug('wikidiff2-inline'); return $text; } # Else slow native PHP diff $ota = explode("\n", $wgContLang->segmentForDiff($otext)); $nta = explode("\n", $wgContLang->segmentForDiff($ntext)); $diffs = new Diff($ota, $nta); $formatter = new InlineDiffFormatter(); $difftext = $wgContLang->unsegmentForDiff($formatter->format($diffs)); return $difftext; }