MediaWiki  master
RevDelFileList.php
Go to the documentation of this file.
1 <?php
25 
29 class RevDelFileList extends RevDelList {
30 
33 
35  private $repoGroup;
36 
38  public $storeBatch;
39 
41  public $deleteBatch;
42 
44  public $cleanupBatch;
45 
54  public function __construct(
56  PageIdentity $page,
57  array $ids,
61  ) {
62  parent::__construct( $context, $page, $ids, $lbFactory );
63  $this->htmlCacheUpdater = $htmlCacheUpdater;
64  $this->repoGroup = $repoGroup;
65  }
66 
67  public function getType() {
68  return 'oldimage';
69  }
70 
71  public static function getRelationType() {
72  return 'oi_archive_name';
73  }
74 
75  public static function getRestriction() {
76  return 'deleterevision';
77  }
78 
79  public static function getRevdelConstant() {
80  return File::DELETED_FILE;
81  }
82 
87  public function doQuery( $db ) {
88  $archiveNames = [];
89  foreach ( $this->ids as $timestamp ) {
90  $archiveNames[] = $timestamp . '!' . $this->title->getDBkey();
91  }
92 
93  $oiQuery = OldLocalFile::getQueryInfo();
94  return $db->select(
95  $oiQuery['tables'],
96  $oiQuery['fields'],
97  [
98  'oi_name' => $this->title->getDBkey(),
99  'oi_archive_name' => $archiveNames
100  ],
101  __METHOD__,
102  [ 'ORDER BY' => 'oi_timestamp DESC' ],
103  $oiQuery['joins']
104  );
105  }
106 
107  public function newItem( $row ) {
108  return new RevDelFileItem( $this, $row );
109  }
110 
111  public function clearFileOps() {
112  $this->deleteBatch = [];
113  $this->storeBatch = [];
114  $this->cleanupBatch = [];
115  }
116 
117  public function doPreCommitUpdates() {
118  $status = Status::newGood();
119  $repo = $this->repoGroup->getLocalRepo();
120  if ( $this->storeBatch ) {
121  $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
122  }
123  if ( !$status->isOK() ) {
124  return $status;
125  }
126  if ( $this->deleteBatch ) {
127  $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
128  }
129  if ( !$status->isOK() ) {
130  // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
131  // modified (but destined for rollback) causes data loss
132  return $status;
133  }
134  if ( $this->cleanupBatch ) {
135  $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
136  }
137 
138  return $status;
139  }
140 
141  public function doPostCommitUpdates( array $visibilityChangeMap ) {
142  $file = $this->repoGroup->getLocalRepo()->newFile( $this->title );
143  $file->purgeCache();
144  $file->purgeDescription();
145 
146  // Purge full images from cache
147  $purgeUrls = [];
148  foreach ( $this->ids as $timestamp ) {
149  $archiveName = $timestamp . '!' . $this->title->getDBkey();
150  $file->purgeOldThumbnails( $archiveName );
151  $purgeUrls[] = $file->getArchiveUrl( $archiveName );
152  }
153 
154  $this->htmlCacheUpdater->purgeUrls(
155  $purgeUrls,
156  HtmlCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
157  );
158 
159  return Status::newGood();
160  }
161 
162  public function getSuppressBit() {
164  }
165 }
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:39
FileRepo\OVERWRITE_SAME
const OVERWRITE_SAME
Definition: FileRepo.php:48
File\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: File.php:74
OldLocalFile\getQueryInfo
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
Definition: OldLocalFile.php:137
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
RevDelFileList\newItem
newItem( $row)
Create an item object from a DB result row.
Definition: RevDelFileList.php:107
RevDelFileList\$repoGroup
RepoGroup $repoGroup
Definition: RevDelFileList.php:35
RevDelFileList\clearFileOps
clearFileOps()
Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates() STUB.
Definition: RevDelFileList.php:111
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
RevDelFileList\getRestriction
static getRestriction()
Get the user right required for this list type Override this function.
Definition: RevDelFileList.php:75
RevDelFileList\__construct
__construct(IContextSource $context, PageIdentity $page, array $ids, LBFactory $lbFactory, HtmlCacheUpdater $htmlCacheUpdater, RepoGroup $repoGroup)
Definition: RevDelFileList.php:54
RevDelList\$lbFactory
LBFactory $lbFactory
Definition: RevDelList.php:40
RevDelList
Definition: RevDelList.php:37
RevDelFileList\getRevdelConstant
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
Definition: RevDelFileList.php:79
RevDelFileList\$htmlCacheUpdater
HtmlCacheUpdater $htmlCacheUpdater
Definition: RevDelFileList.php:32
RevDelFileList\doPreCommitUpdates
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
Definition: RevDelFileList.php:117
RevDelFileList\getRelationType
static getRelationType()
Get the DB field name associated with the ID list.
Definition: RevDelFileList.php:71
RevDelFileList\doPostCommitUpdates
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
Definition: RevDelFileList.php:141
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
RevisionListBase\$ids
int[] null $ids
Definition: RevisionListBase.php:37
HtmlCacheUpdater
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
Definition: HtmlCacheUpdater.php:32
RevDelFileItem
Item class for an oldimage table row.
Definition: RevDelFileItem.php:28
RevDelFileList\getType
getType()
Get the internal type name of this list.
Definition: RevDelFileList.php:67
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:58
RevDelFileList\$deleteBatch
array $deleteBatch
Definition: RevDelFileList.php:41
RevDelFileList\getSuppressBit
getSuppressBit()
Get the integer value of the flag used for suppression.
Definition: RevDelFileList.php:162
Wikimedia\Rdbms\LBFactory
An interface for generating database load balancers.
Definition: LBFactory.php:42
RepoGroup
Prioritized list of file repositories.
Definition: RepoGroup.php:32
RevDelFileList
List for oldimage table items.
Definition: RevDelFileList.php:29
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:71
RevDelFileList\doQuery
doQuery( $db)
Definition: RevDelFileList.php:87
RevDelFileList\$storeBatch
array $storeBatch
Definition: RevDelFileList.php:38
RevDelFileList\$cleanupBatch
array $cleanupBatch
Definition: RevDelFileList.php:44