From: Aaron Date: Fri, 25 May 2012 23:00:49 +0000 (-0700) Subject: [FileRepo] Made getDescription() respect *_deleted fields. X-Git-Tag: 1.31.0-rc.0~23407^2 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=9f6afeab0dbdf6895645d42f5c68266742ebb9b7;p=lhc%2Fweb%2Fwiklou.git [FileRepo] Made getDescription() respect *_deleted fields. Change-Id: I1dd54611501d6747fb4ad6cbe6b58b0010b1d6d4 --- diff --git a/includes/Export.php b/includes/Export.php index c201c97ada..92502e7459 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -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 " \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" . diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 3aeb70afe8..5dd1fb0a85 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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 = ''; diff --git a/includes/Revision.php b/includes/Revision.php index 6928eb97f6..3e5e8bda1f 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -592,7 +592,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 @@ -624,7 +624,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 @@ -664,7 +664,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 @@ -742,7 +742,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 diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 2d6b218836..065679a87a 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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; } diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 336aca9972..b2d0a38ed5 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -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; + } } /**