Merge "[FileRepo] Made getDescription() respect *_deleted fields."
authorDemon <chadh@wikimedia.org>
Mon, 4 Jun 2012 20:41:52 +0000 (20:41 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 4 Jun 2012 20:41:52 +0000 (20:41 +0000)
includes/Export.php
includes/ImagePage.php
includes/Revision.php
includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php

index 9debbb5..6c47e34 100644 (file)
@@ -789,10 +789,15 @@ class XmlDumpWriter {
                } else {
                        $contents = '';
                }
+               if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
+                       $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
+               } else {
+                       $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
+               }
                return "    <upload>\n" .
                        $this->writeTimestamp( $file->getTimestamp() ) .
                        $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
-                       "      " . Xml::elementClean( 'comment', null, $file->getDescription() ) . "\n" .
+                       "      " . $comment . "\n" .
                        "      " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
                        $archiveName .
                        "      " . Xml::element( 'src', null, $file->getCanonicalUrl() ) . "\n" .
index 63e9894..b1a5057 100644 (file)
@@ -990,7 +990,7 @@ class ImageHistoryList extends ContextSource {
                $img = $iscur ? $file->getName() : $file->getArchiveName();
                $userId = $file->getUser( 'id' );
                $userText = $file->getUser( 'text' );
-               $description = $file->getDescription();
+               $description = $file->getDescription( File::FOR_THIS_USER, $user );
 
                $local = $this->current->isLocal();
                $row = $selected = '';
index 6dbd808..6b8aabc 100644 (file)
@@ -598,7 +598,7 @@ class Revision {
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the ID regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
@@ -630,7 +630,7 @@ class Revision {
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
@@ -670,7 +670,7 @@ class Revision {
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
@@ -748,7 +748,7 @@ class Revision {
         *
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users
-        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::FOR_THIS_USER    to be displayed to the given user
         *      Revision::RAW              get the text regardless of permissions
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
index 2d6b218..065679a 100644 (file)
@@ -63,6 +63,11 @@ abstract class File {
 
        const DELETE_SOURCE = 1;
 
+       // Audience options for File::getDescription()
+       const FOR_PUBLIC = 1;
+       const FOR_THIS_USER = 2;
+       const RAW = 3;
+
        /**
         * Some member variables can be lazy-initialised using __get(). The
         * initialisation function for these variables is always a function named
@@ -1565,12 +1570,18 @@ abstract class File {
        }
 
        /**
-        * Get discription of file revision
+        * Get description of file revision
         * STUB
         *
+        * @param $audience Integer: one of:
+        *      File::FOR_PUBLIC       to be displayed to all users
+        *      File::FOR_THIS_USER    to be displayed to the given user
+        *      File::RAW              get the description regardless of permissions
+        * @param $user User object to check for, only if FOR_THIS_USER is passed
+        *              to the $audience parameter
         * @return string
         */
-       function getDescription() {
+       function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
                return null;
        }
 
index cc66649..d9ba9be 100644 (file)
@@ -1467,9 +1467,17 @@ class LocalFile extends File {
        /**
         * @return string
         */
-       function getDescription() {
+       function getDescription( $audience = self::FOR_PUBLIC, User $user = null ) {
                $this->load();
-               return $this->description;
+               if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) {
+                       return '';
+               } elseif ( $audience == self::FOR_THIS_USER
+                       && !$this->userCan( self::DELETED_COMMENT, $user ) )
+               {
+                       return '';
+               } else {
+                       return $this->description;
+               }
        }
 
        /**