MediaWiki master
RevDelFileList.php
Go to the documentation of this file.
1<?php
34
39
40 protected const SUPPRESS_BIT = File::DELETED_RESTRICTED;
41
43 private $htmlCacheUpdater;
44
46 private $repoGroup;
47
50
53
56
65 public function __construct(
66 IContextSource $context,
68 array $ids,
69 LBFactory $lbFactory,
70 HTMLCacheUpdater $htmlCacheUpdater,
71 RepoGroup $repoGroup
72 ) {
73 parent::__construct( $context, $page, $ids, $lbFactory );
74 $this->htmlCacheUpdater = $htmlCacheUpdater;
75 $this->repoGroup = $repoGroup;
76 }
77
78 public function getType() {
79 return 'oldimage';
80 }
81
82 public static function getRelationType() {
83 return 'oi_archive_name';
84 }
85
86 public static function getRestriction() {
87 return 'deleterevision';
88 }
89
90 public static function getRevdelConstant() {
91 return File::DELETED_FILE;
92 }
93
98 public function doQuery( $db ) {
99 $archiveNames = [];
100 foreach ( $this->ids as $timestamp ) {
101 $archiveNames[] = $timestamp . '!' . $this->page->getDBkey();
102 }
103
104 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $db );
105 $queryBuilder
106 ->where( [ 'oi_name' => $this->page->getDBkey(), 'oi_archive_name' => $archiveNames ] )
107 ->orderBy( 'oi_timestamp', SelectQueryBuilder::SORT_DESC );
108 return $queryBuilder->caller( __METHOD__ )->fetchResultSet();
109 }
110
111 public function newItem( $row ) {
112 return new RevDelFileItem( $this, $row );
113 }
114
115 public function clearFileOps() {
116 $this->deleteBatch = [];
117 $this->storeBatch = [];
118 $this->cleanupBatch = [];
119 }
120
121 public function doPreCommitUpdates() {
122 $status = Status::newGood();
123 $repo = $this->repoGroup->getLocalRepo();
124 if ( $this->storeBatch ) {
125 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
126 }
127 if ( !$status->isOK() ) {
128 return $status;
129 }
130 if ( $this->deleteBatch ) {
131 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
132 }
133 if ( !$status->isOK() ) {
134 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
135 // modified (but destined for rollback) causes data loss
136 return $status;
137 }
138 if ( $this->cleanupBatch ) {
139 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
140 }
141
142 return $status;
143 }
144
145 public function doPostCommitUpdates( array $visibilityChangeMap ) {
146 $file = $this->repoGroup->getLocalRepo()->newFile( $this->page );
147 $file->purgeCache();
148 $file->purgeDescription();
149
150 // Purge full images from cache
151 $purgeUrls = [];
152 foreach ( $this->ids as $timestamp ) {
153 $archiveName = $timestamp . '!' . $this->page->getDBkey();
154 $file->purgeOldThumbnails( $archiveName );
155 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
156 }
157
158 $this->htmlCacheUpdater->purgeUrls(
159 $purgeUrls,
160 HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
161 );
162
163 return Status::newGood();
164 }
165
166}
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
Base class for file repositories.
Definition FileRepo.php:68
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:93
Prioritized list of file repositories.
Definition RepoGroup.php:38
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Item class for an oldimage table row.
List for oldimage table items.
static getRelationType()
Get the DB field name associated with the ID list.
doPostCommitUpdates(array $visibilityChangeMap)
A hook for setVisibility(): do any necessary updates post-commit.
doPreCommitUpdates()
A hook for setVisibility(): do batch updates pre-commit.
clearFileOps()
Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates() STUB.
newItem( $row)
Create an item object from a DB result row.
getType()
Get the internal type name of this list.
static getRevdelConstant()
Get the revision deletion constant for this list type Override this function.
static getRestriction()
Get the user right required for this list type Override this function.
__construct(IContextSource $context, PageIdentity $page, array $ids, LBFactory $lbFactory, HTMLCacheUpdater $htmlCacheUpdater, RepoGroup $repoGroup)
Build SELECT queries with a fluent interface.
Interface for objects which can provide a MediaWiki context on request.
Interface for objects (potentially) representing an editable wiki page.
A database connection without write operations.
Result wrapper for grabbing data queried from an IDatabase object.