Merge "mediawiki.searchSuggest: Show full article title as a tooltip for each suggestion"
[lhc/web/wiklou.git] / includes / changes / RecentChange.php
index bbf4ab6..370e109 100644 (file)
@@ -102,6 +102,70 @@ class RecentChange {
                return $rc;
        }
 
+       /**
+        * Parsing text to RC_* constants
+        * @since 1.24
+        * @param string|array $type
+        * @throws MWException
+        * @return int|array RC_TYPE
+        */
+       public static function parseToRCType( $type ) {
+               if ( is_array( $type ) ) {
+                       $retval = array();
+                       foreach ( $type as $t ) {
+                               $retval[] = RecentChange::parseToRCType( $t );
+                       }
+
+                       return $retval;
+               }
+
+               switch ( $type ) {
+                       case 'edit':
+                               return RC_EDIT;
+                       case 'new':
+                               return RC_NEW;
+                       case 'log':
+                               return RC_LOG;
+                       case 'external':
+                               return RC_EXTERNAL;
+                       default:
+                               throw new MWException( "Unknown type '$type'" );
+               }
+       }
+
+       /**
+        * Parsing RC_* constants to human-readable test
+        * @since 1.24
+        * @param int $rc_type
+        * @return string $type
+        */
+       public static function parseFromRCType( $rcType ) {
+               switch ( $rcType ) {
+                       case RC_EDIT:
+                               $type = 'edit';
+                               break;
+                       case RC_NEW:
+                               $type = 'new';
+                               break;
+                       case RC_MOVE:
+                               $type = 'move';
+                               break;
+                       case RC_LOG:
+                               $type = 'log';
+                               break;
+                       case RC_EXTERNAL:
+                               $type = 'external';
+                               break;
+                       case RC_MOVE_OVER_REDIRECT:
+                               $type = 'move over redirect';
+                               break;
+                       default:
+                               $type = "$rcType";
+               }
+
+               return $type;
+       }
+
        /**
         * No uses left in Gerrit on 2013-11-19.
         * @deprecated since 1.22
@@ -279,7 +343,7 @@ class RecentChange {
                        $editor = $this->getPerformer();
                        $title = $this->getTitle();
 
-                       if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title ) ) ) {
+                       if ( wfRunHooks( 'AbortEmailNotification', array( $editor, $title, $this ) ) ) {
                                # @todo FIXME: This would be better as an extension hook
                                $enotif = new EmailNotification();
                                $enotif->notifyOnPageChange( $editor, $title,
@@ -326,13 +390,17 @@ class RecentChange {
 
        /**
         * Notify all the feeds about the change.
+        * @param array $feeds Optional feeds to send to, defaults to $wgRCFeeds
         */
-       public function notifyRCFeeds() {
+       public function notifyRCFeeds( array $feeds = null ) {
                global $wgRCFeeds;
+               if ( $feeds === null ) {
+                       $feeds = $wgRCFeeds;
+               }
 
                $performer = $this->getPerformer();
 
-               foreach ( $wgRCFeeds as $feed ) {
+               foreach ( $feeds as $feed ) {
                        $feed += array(
                                'omit_bots' => false,
                                'omit_anon' => false,
@@ -361,7 +429,7 @@ class RecentChange {
                        }
 
                        /** @var $formatter RCFeedFormatter */
-                       $formatter = new $feed['formatter']();
+                       $formatter = is_object( $feed['formatter'] ) ? $feed['formatter'] : new $feed['formatter']();
                        $line = $formatter->getLine( $feed, $this, $actionComment );
 
                        $engine->send( $feed, $line );