Merge "Improved rate limit log to mention IP"
[lhc/web/wiklou.git] / includes / FeedUtils.php
index 4842c38..83ce755 100644 (file)
@@ -33,8 +33,8 @@ class FeedUtils {
         * If the feed should be purged; $timekey and $key will be removed from
         * $messageMemc
         *
-        * @param string $timekey cache key of the timestamp of the last item
-        * @param string $key cache key of feed's content
+        * @param string $timekey Cache key of the timestamp of the last item
+        * @param string $key Cache key of feed's content
         */
        public static function checkPurge( $timekey, $key ) {
                global $wgRequest, $wgUser, $messageMemc;
@@ -49,7 +49,7 @@ class FeedUtils {
         * Check whether feeds can be used and that $type is a valid feed type
         *
         * @param string $type feed type, as requested by the user
-        * @return Boolean
+        * @return bool
         */
        public static function checkFeedOutput( $type ) {
                global $wgOut, $wgFeed, $wgFeedClasses;
@@ -59,7 +59,7 @@ class FeedUtils {
                        return false;
                }
 
-               if( !isset( $wgFeedClasses[$type] ) ) {
+               if ( !isset( $wgFeedClasses[$type] ) ) {
                        $wgOut->addWikiMsg( 'feed-invalid' );
                        return false;
                }
@@ -70,21 +70,21 @@ class FeedUtils {
        /**
         * Format a diff for the newsfeed
         *
-        * @param $row Object: row from the recentchanges table
-        * @return String
+        * @param object $row Row from the recentchanges table
+        * @return string
         */
        public static function formatDiff( $row ) {
                $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
                $timestamp = wfTimestamp( TS_MW, $row->rc_timestamp );
                $actiontext = '';
-               if( $row->rc_type == RC_LOG ) {
+               if ( $row->rc_type == RC_LOG ) {
                        $rcRow = (array)$row; // newFromRow() only accepts arrays for RC rows
                        $actiontext = LogFormatter::newFromRow( $rcRow )->getActionText();
                }
                return self::formatDiffRow( $titleObj,
                        $row->rc_last_oldid, $row->rc_this_oldid,
                        $timestamp,
-                       ($row->rc_deleted & Revision::DELETED_COMMENT)
+                       $row->rc_deleted & Revision::DELETED_COMMENT
                                ? wfMessage( 'rev-deleted-comment' )->escaped()
                                : $row->rc_comment,
                        $actiontext
@@ -94,15 +94,17 @@ class FeedUtils {
        /**
         * Really format a diff for the newsfeed
         *
-        * @param $title Title object
-        * @param $oldid Integer: old revision's id
-        * @param $newid Integer: new revision's id
-        * @param $timestamp Integer: new revision's timestamp
-        * @param string $comment new revision's comment
-        * @param string $actiontext text of the action; in case of log event
-        * @return String
+        * @param Title $title Title object
+        * @param int $oldid Old revision's id
+        * @param int $newid New revision's id
+        * @param int $timestamp New revision's timestamp
+        * @param string $comment New revision's comment
+        * @param string $actiontext Text of the action; in case of log event
+        * @return string
         */
-       public static function formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext = '' ) {
+       public static function formatDiffRow( $title, $oldid, $newid, $timestamp,
+               $comment, $actiontext = ''
+       ) {
                global $wgFeedDiffCutoff, $wgLang;
                wfProfileIn( __METHOD__ );
 
@@ -121,12 +123,12 @@ class FeedUtils {
 
                // Can't diff special pages, unreadable pages or pages with no new revision
                // to compare against: just return the text.
-               if( $title->getNamespace() < 0 || $accErrors || !$newid ) {
+               if ( $title->getNamespace() < 0 || $accErrors || !$newid ) {
                        wfProfileOut( __METHOD__ );
                        return $completeText;
                }
 
-               if( $oldid ) {
+               if ( $oldid ) {
                        wfProfileIn( __METHOD__ . "-dodiff" );
 
                        #$diffText = $de->getDiff( wfMessage( 'revisionasof',
@@ -171,7 +173,7 @@ class FeedUtils {
                        wfProfileOut( __METHOD__ . "-dodiff" );
                } else {
                        $rev = Revision::newFromId( $newid );
-                       if( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
+                       if ( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
                                $newContent = ContentHandler::getForTitle( $title )->makeEmptyContent();
                        } else {
                                $newContent = $rev->getContent();
@@ -214,15 +216,16 @@ class FeedUtils {
         * Generates a diff link. Used when the full diff is not wanted for example
         * when $wgFeedDiffCutoff is 0.
         *
-        * @param $title Title object: used to generate the diff URL
-        * @param $newid Integer newid for this diff
-        * @param $oldid Integer|null oldid for the diff. Null means it is a new article
+        * @param Title $title Title object: used to generate the diff URL
+        * @param int $newid Newid for this diff
+        * @param int|null $oldid Oldid for the diff. Null means it is a new article
         * @return string
         */
        protected static function getDiffLink( Title $title, $newid, $oldid = null ) {
-               $queryParameters = ($oldid == null)
-                       ? "diff={$newid}"
-                       : "diff={$newid}&oldid={$oldid}";
+               $queryParameters = array( 'diff' => $newid );
+               if ( $oldid != null ) {
+                       $queryParameters['oldid'] = $oldid;
+               }
                $diffUrl = $title->getFullURL( $queryParameters );
 
                $diffLink = Html::element( 'a', array( 'href' => $diffUrl ),
@@ -236,21 +239,27 @@ class FeedUtils {
         * Might be 'cleaner' to use DOM or XSLT or something,
         * but *gack* it's a pain in the ass.
         *
-        * @param string $text diff's HTML output
-        * @return String: modified HTML
+        * @param string $text Diff's HTML output
+        * @return string Modified HTML
         */
        public static function applyDiffStyle( $text ) {
                $styles = array(
                        'diff'             => 'background-color: white; color:black;',
                        'diff-otitle'      => 'background-color: white; color:black; text-align: center;',
                        'diff-ntitle'      => 'background-color: white; color:black; text-align: center;',
-                       'diff-addedline'   => 'color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;',
-                       'diff-deletedline' => 'color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;',
-                       'diff-context'     => 'background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;',
+                       'diff-addedline'   => 'color:black; font-size: 88%; border-style: solid; '
+                               . 'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; '
+                               . 'vertical-align: top; white-space: pre-wrap;',
+                       'diff-deletedline' => 'color:black; font-size: 88%; border-style: solid; '
+                               . 'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; '
+                               . 'vertical-align: top; white-space: pre-wrap;',
+                       'diff-context'     => 'background-color: #f9f9f9; color: #333333; font-size: 88%; '
+                               . 'border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; '
+                               . 'border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;',
                        'diffchange'       => 'font-weight: bold; text-decoration: none;',
                );
 
-               foreach( $styles as $class => $style ) {
+               foreach ( $styles as $class => $style ) {
                        $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",
                                "\\1style=\"$style\"\\3", $text );
                }