MediaWiki master
RevDelFileList.php
Go to the documentation of this file.
1<?php
31
36
37 protected const SUPPRESS_BIT = File::DELETED_RESTRICTED;
38
40 private $htmlCacheUpdater;
41
43 private $repoGroup;
44
47
50
53
62 public function __construct(
63 IContextSource $context,
65 array $ids,
66 LBFactory $lbFactory,
67 HTMLCacheUpdater $htmlCacheUpdater,
68 RepoGroup $repoGroup
69 ) {
70 parent::__construct( $context, $page, $ids, $lbFactory );
71 $this->htmlCacheUpdater = $htmlCacheUpdater;
72 $this->repoGroup = $repoGroup;
73 }
74
75 public function getType() {
76 return 'oldimage';
77 }
78
79 public static function getRelationType() {
80 return 'oi_archive_name';
81 }
82
83 public static function getRestriction() {
84 return 'deleterevision';
85 }
86
87 public static function getRevdelConstant() {
88 return File::DELETED_FILE;
89 }
90
95 public function doQuery( $db ) {
96 $archiveNames = [];
97 foreach ( $this->ids as $timestamp ) {
98 $archiveNames[] = $timestamp . '!' . $this->page->getDBkey();
99 }
100
101 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $db );
102 $queryBuilder
103 ->where( [ 'oi_name' => $this->page->getDBkey(), 'oi_archive_name' => $archiveNames ] )
104 ->orderBy( 'oi_timestamp', SelectQueryBuilder::SORT_DESC );
105 return $queryBuilder->caller( __METHOD__ )->fetchResultSet();
106 }
107
108 public function newItem( $row ) {
109 return new RevDelFileItem( $this, $row );
110 }
111
112 public function clearFileOps() {
113 $this->deleteBatch = [];
114 $this->storeBatch = [];
115 $this->cleanupBatch = [];
116 }
117
118 public function doPreCommitUpdates() {
119 $status = Status::newGood();
120 $repo = $this->repoGroup->getLocalRepo();
121 if ( $this->storeBatch ) {
122 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
123 }
124 if ( !$status->isOK() ) {
125 return $status;
126 }
127 if ( $this->deleteBatch ) {
128 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
129 }
130 if ( !$status->isOK() ) {
131 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
132 // modified (but destined for rollback) causes data loss
133 return $status;
134 }
135 if ( $this->cleanupBatch ) {
136 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
137 }
138
139 return $status;
140 }
141
142 public function doPostCommitUpdates( array $visibilityChangeMap ) {
143 $file = $this->repoGroup->getLocalRepo()->newFile( $this->page );
144 $file->purgeCache();
145 $file->purgeDescription();
146
147 // Purge full images from cache
148 $purgeUrls = [];
149 foreach ( $this->ids as $timestamp ) {
150 $archiveName = $timestamp . '!' . $this->page->getDBkey();
151 $file->purgeOldThumbnails( $archiveName );
152 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
153 }
154
155 $this->htmlCacheUpdater->purgeUrls(
156 $purgeUrls,
157 HTMLCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
158 );
159
160 return Status::newGood();
161 }
162
163}
const OVERWRITE_SAME
Definition FileRepo.php:60
Class to invalidate the CDN and HTMLFileCache entries associated with URLs/titles.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Prioritized list of file repositories.
Definition RepoGroup.php:32
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.