6 public static function checkPurge( $timekey, $key ) {
7 global $wgRequest, $wgUser, $messageMemc;
8 $purge = $wgRequest->getVal( 'action' ) === 'purge';
9 if ( $purge && $wgUser->isAllowed('purge') ) {
10 $messageMemc->delete( $timekey );
11 $messageMemc->delete( $key );
15 public static function checkFeedOutput( $type ) {
16 global $wgFeed, $wgFeedClasses;
20 $wgOut->addWikiMsg( 'feed-unavailable' );
24 if( !isset( $wgFeedClasses[$type] ) ) {
25 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
33 * Format a diff for the newsfeed
35 public static function formatDiff( $row ) {
38 $titleObj = Title
::makeTitle( $row->rc_namespace
, $row->rc_title
);
39 $timestamp = wfTimestamp( TS_MW
, $row->rc_timestamp
);
41 if( $row->rc_type
== RC_LOG
) {
42 if( $row->rc_deleted
& LogPage
::DELETED_ACTION
) {
43 $actiontext = wfMsgHtml('rev-deleted-event');
45 $actiontext = LogPage
::actionText( $row->rc_log_type
, $row->rc_log_action
,
46 $titleObj, $wgUser->getSkin(), LogPage
::extractParams($row->rc_params
,true,true) );
49 return self
::formatDiffRow( $titleObj,
50 $row->rc_last_oldid
, $row->rc_this_oldid
,
52 ($row->rc_deleted
& Revision
::DELETED_COMMENT
) ?
wfMsgHtml('rev-deleted-comment') : $row->rc_comment
,
56 public static function formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='' ) {
57 global $wgFeedDiffCutoff, $wgContLang, $wgUser;
58 wfProfileIn( __FUNCTION__
);
60 $skin = $wgUser->getSkin();
62 $completeText = '<p>' . implode( ' ',
66 $skin->formatComment( $comment ) ) ) ) . "</p>\n";
68 //NOTE: Check permissions for anonymous users, not current user.
69 // No "privileged" version should end up in the cache.
70 // Most feed readers will not log in anway.
72 $accErrors = $title->getUserPermissionsErrors( 'read', $anon, true );
74 if( $title->getNamespace() >= 0 && !$accErrors ) {
76 wfProfileIn( __FUNCTION__
."-dodiff" );
78 #$diffText = $de->getDiff( wfMsg( 'revisionasof',
79 # $wgContLang->timeanddate( $timestamp ),
80 # $wgContLang->date( $timestamp ),
81 # $wgContLang->time( $timestamp ) ),
82 # wfMsg( 'currentrev' ) );
84 // Don't bother generating the diff if we won't be able to show it
85 if ( $wgFeedDiffCutoff > 0 ) {
86 $de = new DifferenceEngine( $title, $oldid, $newid );
87 $diffText = $de->getDiff(
88 wfMsg( 'previousrevision' ), // hack
89 wfMsg( 'revisionasof',
90 $wgContLang->timeanddate( $timestamp ),
91 $wgContLang->date( $timestamp ),
92 $wgContLang->time( $timestamp ) ) );
95 if ( ( strlen( $diffText ) > $wgFeedDiffCutoff ) ||
( $wgFeedDiffCutoff <= 0 ) ) {
97 $diffLink = $title->escapeFullUrl(
100 $diffText = '<a href="' .
103 htmlspecialchars( wfMsgForContent( 'showdiff' ) ) .
105 } elseif ( $diffText === false ) {
106 // Error in diff engine, probably a missing revision
107 $diffText = "<p>Can't load revision $newid</p>";
109 // Diff output fine, clean up any illegal UTF-8
110 $diffText = UtfNormal
::cleanUp( $diffText );
111 $diffText = self
::applyDiffStyle( $diffText );
113 wfProfileOut( __FUNCTION__
."-dodiff" );
115 $rev = Revision
::newFromId( $newid );
116 if( is_null( $rev ) ) {
119 $newtext = $rev->getText();
121 $diffText = '<p><b>' . wfMsg( 'newpage' ) . '</b></p>' .
122 '<div>' . nl2br( htmlspecialchars( $newtext ) ) . '</div>';
124 $completeText .= $diffText;
127 wfProfileOut( __FUNCTION__
);
128 return $completeText;
132 * Hacky application of diff styles for the feeds.
133 * Might be 'cleaner' to use DOM or XSLT or something,
134 * but *gack* it's a pain in the ass.
136 * @param $text String:
140 public static function applyDiffStyle( $text ) {
142 'diff' => 'background-color: white; color:black;',
143 'diff-otitle' => 'background-color: white; color:black;',
144 'diff-ntitle' => 'background-color: white; color:black;',
145 'diff-addedline' => 'background: #cfc; color:black; font-size: smaller;',
146 'diff-deletedline' => 'background: #ffa; color:black; font-size: smaller;',
147 'diff-context' => 'background: #eee; color:black; font-size: smaller;',
148 'diffchange' => 'color: red; font-weight: bold; text-decoration: none;',
151 foreach( $styles as $class => $style ) {
152 $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
153 "\\1style=\"$style\"\\3", $text );