Followup r97138 - could not reproduce myself
[lhc/web/wiklou.git] / includes / logging / LogFormatter.php
index 0cbcc69..40f8783 100644 (file)
@@ -78,9 +78,9 @@ class LogFormatter {
 
        /**
         * Replace the default context
-        * @param $context RequestContext
+        * @param $context IContextSource
         */
-       public function setContext( RequestContext $context ) {
+       public function setContext( IContextSource $context ) {
                $this->context = $context;
        }
 
@@ -211,6 +211,9 @@ class LogFormatter {
                if ( !$this->plaintext ) {
                        $link = Linker::link( $title, null, array(), $parameters );
                } else {
+                       if ( !$title instanceof Title ) {
+                               throw new MWException( "Expected title, got null" );
+                       }
                        $link = '[[' . $title->getPrefixedText() . ']]';
                }
                return $link;
@@ -223,25 +226,7 @@ class LogFormatter {
         */
        public function getPerformerElement() {
                $performer = $this->entry->getPerformer();
-
-               if ( $this->plaintext ) {
-                       $element = $performer->getName();
-               } else {
-                       $element = Linker::userLink(
-                               $performer->getId(),
-                               $performer->getName()
-                       );
-
-                       if ( $this->linkFlood ) {
-                               $element .= Linker::userToolLinks(
-                                       $performer->getId(),
-                                       $performer->getName(),
-                                       true, // Red if no edits
-                                       0, // Flags
-                                       $performer->getEditCount()
-                               );
-                       }
-               }
+               $element = $this->makeUserLink( $performer );
 
                if ( $this->entry->isDeleted( LogPage::DELETED_USER ) ) {
                        $element = self::getRestrictedElement( 'rev-deleted-user' );
@@ -293,6 +278,28 @@ class LogFormatter {
                        ->title( $this->context->getTitle() );
        }
 
+       protected function makeUserLink( User $user ) {
+               if ( $this->plaintext ) {
+                       $element = $user->getName();
+               } else {
+                       $element = Linker::userLink(
+                               $user->getId(),
+                               $user->getName()
+                       );
+
+                       if ( $this->linkFlood ) {
+                               $element .= Linker::userToolLinks(
+                                       $user->getId(),
+                                       $user->getName(),
+                                       true, // Red if no edits
+                                       0, // Flags
+                                       $user->getEditCount()
+                               );
+                       }
+               }
+               return $element;
+       }
+
 }
 
 /**
@@ -369,7 +376,10 @@ class DeleteLogFormatter extends LogFormatter {
                $params = parent::getMessageParameters();
                $subtype = $this->entry->getSubtype();
                if ( in_array( $subtype, array( 'event', 'revision' ) ) ) {
-                       if ( count( $params ) > 5 ) {
+                       if (
+                               ($subtype === 'event' && count( $params ) === 6 ) ||
+                               ($subtype === 'revision' && isset( $params[3] ) && $params[3] === 'revision' )
+                       ) {
                                $paramStart = $subtype === 'revision' ? 4 : 3;
 
                                $old = $this->parseBitField( $params[$paramStart+1] );
@@ -411,3 +421,73 @@ class DeleteLogFormatter extends LogFormatter {
                }
        }
 }
+
+/**
+ * This class formats patrol log entries.
+ * @since 1.19
+ */
+class PatrolLogFormatter extends LogFormatter {
+       protected function getMessageKey() {
+               $key = parent::getMessageKey();
+               $params = $this->getMessageParameters();
+               if ( isset( $params[5] ) && $params[5] ) {
+                       $key .= '-auto';
+               }
+               return $key;
+       }
+
+       protected function getMessageParameters() {
+               $params = parent::getMessageParameters();
+               $newParams = array_slice( $params, 0, 3 );
+
+               $target = $this->entry->getTarget();
+               $oldid = $params[3];
+               $revision = $this->context->getLang()->formatNum( $oldid, true );
+
+               if ( $this->plaintext ) {
+                       $revlink = $revision;
+               } elseif ( $target->exists() ) {
+                       $query = array(
+                               'oldid' => $oldid,
+                               'diff' => 'prev'
+                       );
+                       $revlink = Linker::link( $target, htmlspecialchars( $revision ), array(), $query );
+               } else {
+                       $revlink = htmlspecialchars( $revision );
+               }
+
+               $newParams[3] = Message::rawParam( $revlink );
+               return $newParams;
+       }
+}
+
+/**
+ * This class formats new user log entries.
+ * @since 1.19
+ */
+class NewUsersLogFormatter extends LogFormatter {
+       protected function getMessageParameters() {
+               $params = parent::getMessageParameters();
+               if ( $this->entry->getSubtype() === 'create2' ) {
+                       if ( isset( $params[3] ) ) {
+                               $target = User::newFromId( $params[3] );
+                       } else {
+                               $target = User::newFromName( $this->entry->getTarget()->getText(), false );
+                       }
+                       $params[2] = Message::rawParam( $this->makeUserLink( $target ) );
+                       $params[3] = $target->getName();
+               }
+               return $params;
+       }
+
+       public function getComment() {
+               $subtype = $this->entry->getSubtype();
+               $timestamp = wfTimestamp( TS_MW, $this->entry->getTimestamp() );
+               if ( $timestamp < '20080129000000' ) {
+                       # Suppress $comment from old entries (before 2008-01-29),
+                       # not needed and can contain incorrect links
+                       return '';
+               }
+               return parent::getComment();
+       }
+}
\ No newline at end of file