* (bug 1284) Inline styles for diffs in Recent Changes RSS/Atom feeds
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 30 Jan 2006 03:34:23 +0000 (03:34 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 30 Jan 2006 03:34:23 +0000 (03:34 +0000)
In a perfect world, HTML would have a version of the <style> element
which applies only to its own contents and is allowed in the body.
Or, secondarily, XSLT could be much much easier to use.

RELEASE-NOTES
includes/SpecialRecentchanges.php

index 0136bb9..ce3e2fa 100644 (file)
@@ -584,6 +584,7 @@ fully support the editing toolbar, but was found to be too confusing.
   Edit messages like "MediaWiki:Namespacenotice-" plus namespace name
   which is blank for main namespace, or like e.g. "User_talk"
 * Adjust user login/creation form hooks to work with a captcha plugin
+* (bug 1284) Inline styles for diffs in Recent Changes RSS/Atom feeds
 
 
 === Caveats ===
index f48a253..8accbfb 100644 (file)
@@ -593,6 +593,7 @@ function rcFormatDiff( $row ) {
                        } else {
                                // Diff output fine, clean up any illegal UTF-8
                                $diffText = UtfNormal::cleanUp( $diffText );
+                               $diffText = rcApplyDiffStyle( $diffText );
                        }
                        wfProfileOut( "$fname-dodiff" );
                } else {
@@ -612,4 +613,32 @@ function rcFormatDiff( $row ) {
        return $completeText;
 }
 
+/**
+ * Hacky application of diff styles for the feeds.
+ * Might be 'cleaner' to use DOM or XSLT or something,
+ * but *gack* it's a pain in the ass.
+ *
+ * @param string $text
+ * @return string
+ * @access private
+ */
+function rcApplyDiffStyle( $text ) {
+       $styles = array(
+               'diff'             => 'background-color: white;',
+               'diff-otitle'      => 'background-color: white;',
+               'diff-ntitle'      => 'background-color: white;',
+               'diff-addedline'   => 'background: #cfc; font-size: smaller;',
+               'diff-deletedline' => 'background: #ffa; font-size: smaller;',
+               'diff-context'     => 'background: #eee; font-size: smaller;',
+               'diffchange'       => 'color: red; font-wieght: bold;',
+       );
+       
+       foreach( $styles as $class => $style ) {
+               $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
+                       "\\1style=\"$style\"\\3", $text );
+       }
+       
+       return $text;
+}
+
 ?>