MediaWiki master
RevDelFileList.php
Go to the documentation of this file.
1<?php
29
34
35 protected const SUPPRESS_BIT = File::DELETED_RESTRICTED;
36
38 private $htmlCacheUpdater;
39
41 private $repoGroup;
42
45
48
51
60 public function __construct(
61 IContextSource $context,
63 array $ids,
64 LBFactory $lbFactory,
65 HtmlCacheUpdater $htmlCacheUpdater,
66 RepoGroup $repoGroup
67 ) {
68 parent::__construct( $context, $page, $ids, $lbFactory );
69 $this->htmlCacheUpdater = $htmlCacheUpdater;
70 $this->repoGroup = $repoGroup;
71 }
72
73 public function getType() {
74 return 'oldimage';
75 }
76
77 public static function getRelationType() {
78 return 'oi_archive_name';
79 }
80
81 public static function getRestriction() {
82 return 'deleterevision';
83 }
84
85 public static function getRevdelConstant() {
86 return File::DELETED_FILE;
87 }
88
93 public function doQuery( $db ) {
94 $archiveNames = [];
95 foreach ( $this->ids as $timestamp ) {
96 $archiveNames[] = $timestamp . '!' . $this->page->getDBkey();
97 }
98
99 $queryBuilder = FileSelectQueryBuilder::newForOldFile( $db );
100 $queryBuilder
101 ->where( [ 'oi_name' => $this->page->getDBkey(), 'oi_archive_name' => $archiveNames ] )
102 ->orderBy( 'oi_timestamp', SelectQueryBuilder::SORT_DESC );
103 return $queryBuilder->caller( __METHOD__ )->fetchResultSet();
104 }
105
106 public function newItem( $row ) {
107 return new RevDelFileItem( $this, $row );
108 }
109
110 public function clearFileOps() {
111 $this->deleteBatch = [];
112 $this->storeBatch = [];
113 $this->cleanupBatch = [];
114 }
115
116 public function doPreCommitUpdates() {
117 $status = Status::newGood();
118 $repo = $this->repoGroup->getLocalRepo();
119 if ( $this->storeBatch ) {
120 $status->merge( $repo->storeBatch( $this->storeBatch, FileRepo::OVERWRITE_SAME ) );
121 }
122 if ( !$status->isOK() ) {
123 return $status;
124 }
125 if ( $this->deleteBatch ) {
126 $status->merge( $repo->deleteBatch( $this->deleteBatch ) );
127 }
128 if ( !$status->isOK() ) {
129 // Running cleanupDeletedBatch() after a failed storeBatch() with the DB already
130 // modified (but destined for rollback) causes data loss
131 return $status;
132 }
133 if ( $this->cleanupBatch ) {
134 $status->merge( $repo->cleanupDeletedBatch( $this->cleanupBatch ) );
135 }
136
137 return $status;
138 }
139
140 public function doPostCommitUpdates( array $visibilityChangeMap ) {
141 $file = $this->repoGroup->getLocalRepo()->newFile( $this->page );
142 $file->purgeCache();
143 $file->purgeDescription();
144
145 // Purge full images from cache
146 $purgeUrls = [];
147 foreach ( $this->ids as $timestamp ) {
148 $archiveName = $timestamp . '!' . $this->page->getDBkey();
149 $file->purgeOldThumbnails( $archiveName );
150 $purgeUrls[] = $file->getArchiveUrl( $archiveName );
151 }
152
153 $this->htmlCacheUpdater->purgeUrls(
154 $purgeUrls,
155 HtmlCacheUpdater::PURGE_INTENT_TXROUND_REFLECTED
156 );
157
158 return Status::newGood();
159 }
160
161}
const OVERWRITE_SAME
Definition FileRepo.php:53
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:30
Item class for an oldimage table row.
List for oldimage table items.
__construct(IContextSource $context, PageIdentity $page, array $ids, LBFactory $lbFactory, HtmlCacheUpdater $htmlCacheUpdater, RepoGroup $repoGroup)
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.
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.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
Result wrapper for grabbing data queried from an IDatabase object.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42