From 3d3f61a0ab6fcd58a0e60300920138725b5a4796 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Mon, 7 Mar 2011 17:07:10 +0000 Subject: [PATCH] (bug 27722) list=filearchive now supports revdel * Adds a condition fa_deleted=0 if the user does not have the suppressrevision rights. This field is unindexed. This should however not be a big problem as files with fa_deleted are rare. Unfortunately this hides files that do not have DELETED_RESTRICTED, but I don't know how bad fa_deleted & DELETED_RESTRICTED = 0 is for performance * Added deletedfile, deletedcomment, deleteduser and deletedrestricted to the output for what I think are appropriate fa_deleted fields, but it's hard to tell what's corrent without a single line of documentation or even comment in the code. Perhaps somebody can dig up a commit message where the purpose of the constants is explained? --- includes/api/ApiQueryFilearchive.php | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/includes/api/ApiQueryFilearchive.php b/includes/api/ApiQueryFilearchive.php index 042fa8b30f..d590ee1517 100644 --- a/includes/api/ApiQueryFilearchive.php +++ b/includes/api/ApiQueryFilearchive.php @@ -66,7 +66,7 @@ class ApiQueryFilearchive extends ApiQueryBase { $this->addTables( 'filearchive' ); - $this->addFields( 'fa_name' ); + $this->addFields( array( 'fa_name', 'fa_deleted' ) ); $this->addFieldsIf( 'fa_storage_key', $fld_sha1 ); $this->addFieldsIf( 'fa_timestamp', $fld_timestamp ); @@ -92,9 +92,22 @@ class ApiQueryFilearchive extends ApiQueryBase { $dir = ( $params['dir'] == 'descending' ? 'older' : 'newer' ); $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) ); $this->addWhereRange( 'fa_name', $dir, $from, null ); - if ( isset( $params['prefix'] ) ) + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'fa_name' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); + } + + if ( !$wgUser->isAllowed( 'suppressrevision' ) ) { + // Filter out revisions that the user is not allowed to see. There + // is no way to indicate that we have skipped stuff because the + // continuation parameter is fa_name + + // Note that this field is unindexed. This should however not be + // a big problem as files with fa_deleted are rare + $this->addWhereFld( 'fa_deleted', 0 ); + } + + $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); $this->addOption( 'ORDER BY', 'fa_name' . @@ -147,7 +160,22 @@ class ApiQueryFilearchive extends ApiQueryBase { if ( $fld_mime ) { $file['mime'] = "$row->fa_major_mime/$row->fa_minor_mime"; } + + if ( $row->fa_deleted & File::DELETED_FILE ) { + $file['deletedfile'] = ''; + } + if ( $row->fa_deleted & File::DELETED_COMMENT ) { + $file['deletedcomment'] = ''; + } + if ( $row->fa_deleted & File::DELETED_USER ) { + $file['deleteduser'] = ''; + } + if ( $row->fa_deleted & File::DELETED_RESTRICTED ) { + // This file is deleted for normal admins + $file['deletedrestricted'] = ''; + } + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $file ); if ( !$fit ) { $this->setContinueEnumParameter( 'from', $this->keyToTitle( $row->fa_name ) ); -- 2.20.1