Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / FeedUtils.php
index 6937c32..d7dbd22 100644 (file)
@@ -30,18 +30,19 @@ class FeedUtils {
 
        /**
         * Check whether feed's cache should be cleared; for changes feeds
-        * If the feed should be purged; $timekey and $key will be removed from
-        * $messageMemc
+        * If the feed should be purged; $timekey and $key will be removed from cache
         *
         * @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;
+               global $wgRequest, $wgUser;
+
                $purge = $wgRequest->getVal( 'action' ) === 'purge';
                if ( $purge && $wgUser->isAllowed( 'purge' ) ) {
-                       $messageMemc->delete( $timekey );
-                       $messageMemc->delete( $key );
+                       $cache = ObjectCache::getMainWANInstance();
+                       $cache->delete( $timekey, 1 );
+                       $cache->delete( $key, 1 );
                }
        }
 
@@ -106,14 +107,13 @@ class FeedUtils {
                $comment, $actiontext = ''
        ) {
                global $wgFeedDiffCutoff, $wgLang;
-               wfProfileIn( __METHOD__ );
 
                // log entries
                $completeText = '<p>' . implode( ' ',
                        array_filter(
-                               array(
+                               [
                                        $actiontext,
-                                       Linker::formatComment( $comment ) ) ) ) . "</p>\n";
+                                       Linker::formatComment( $comment ) ] ) ) . "</p>\n";
 
                // NOTE: Check permissions for anonymous users, not current user.
                //       No "privileged" version should end up in the cache.
@@ -124,18 +124,16 @@ 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 ) {
-                       wfProfileOut( __METHOD__ );
                        return $completeText;
                }
 
                if ( $oldid ) {
-                       wfProfileIn( __METHOD__ . "-dodiff" );
 
-                       #$diffText = $de->getDiff( wfMessage( 'revisionasof',
-                       #       $wgLang->timeanddate( $timestamp ),
-                       #       $wgLang->date( $timestamp ),
-                       #       $wgLang->time( $timestamp ) )->text(),
-                       #       wfMessage( 'currentrev' )->text() );
+                       # $diffText = $de->getDiff( wfMessage( 'revisionasof',
+                       #       $wgLang->timeanddate( $timestamp ),
+                       #       $wgLang->date( $timestamp ),
+                       #       $wgLang->time( $timestamp ) )->text(),
+                       #       wfMessage( 'currentrev' )->text() );
 
                        $diffText = '';
                        // Don't bother generating the diff if we won't be able to show it
@@ -167,10 +165,9 @@ class FeedUtils {
                                $diffText = "<p>Can't load revision $newid</p>";
                        } else {
                                // Diff output fine, clean up any illegal UTF-8
-                               $diffText = UtfNormal::cleanUp( $diffText );
+                               $diffText = UtfNormal\Validator::cleanUp( $diffText );
                                $diffText = self::applyDiffStyle( $diffText );
                        }
-                       wfProfileOut( __METHOD__ . "-dodiff" );
                } else {
                        $rev = Revision::newFromId( $newid );
                        if ( $wgFeedDiffCutoff <= 0 || is_null( $rev ) ) {
@@ -189,10 +186,10 @@ class FeedUtils {
                                        $html = nl2br( htmlspecialchars( $text ) );
                                }
                        } else {
-                               //XXX: we could get an HTML representation of the content via getParserOutput, but that may
+                               // XXX: we could get an HTML representation of the content via getParserOutput, but that may
                                //     contain JS magic and generally may not be suitable for inclusion in a feed.
                                //     Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
-                               //Compare also ApiFeedContributions::feedItemDesc
+                               // Compare also ApiFeedContributions::feedItemDesc
                                $html = null;
                        }
 
@@ -208,7 +205,6 @@ class FeedUtils {
                }
                $completeText .= $diffText;
 
-               wfProfileOut( __METHOD__ );
                return $completeText;
        }
 
@@ -222,13 +218,13 @@ class FeedUtils {
         * @return string
         */
        protected static function getDiffLink( Title $title, $newid, $oldid = null ) {
-               $queryParameters = array( 'diff' => $newid );
+               $queryParameters = [ 'diff' => $newid ];
                if ( $oldid != null ) {
                        $queryParameters['oldid'] = $oldid;
                }
                $diffUrl = $title->getFullURL( $queryParameters );
 
-               $diffLink = Html::element( 'a', array( 'href' => $diffUrl ),
+               $diffLink = Html::element( 'a', [ 'href' => $diffUrl ],
                        wfMessage( 'showdiff' )->inContentLanguage()->text() );
 
                return $diffLink;
@@ -243,7 +239,7 @@ class FeedUtils {
         * @return string Modified HTML
         */
        public static function applyDiffStyle( $text ) {
-               $styles = array(
+               $styles = [
                        '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;',
@@ -257,7 +253,7 @@ class FeedUtils {
                                . '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 ) {
                        $text = preg_replace( "/(<[^>]+)class=(['\"])$class\\2([^>]*>)/",