1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
<?php
/**
* Contains class with job for deleting translatable and translation pages.
*
* @file
* @author Niklas Laxström
* @copyright Copyright © 2008-2013, Niklas Laxström
* @license GPL-2.0-or-later
*/
/**
* Contains class with job for deleting translatable and translation pages.
*
* @ingroup PageTranslation JobQueue
*/
class TranslateDeleteJob extends Job {
/**
* @param Title $target
* @param string $base
* @param string $full
* @param User $performer
* @param string $reason
* @return self
*/
public static function newJob( Title $target, $base, $full, /*User*/$performer, $reason ) {
$job = new self( $target );
$job->setUser( FuzzyBot::getUser() );
$job->setFull( $full );
$job->setBase( $base );
$msg = $job->getFull() ? 'pt-deletepage-full-logreason' : 'pt-deletepage-lang-logreason';
$job->setSummary( wfMessage( $msg, $base )->inContentLanguage()->text() );
$job->setPerformer( $performer );
$job->setReason( $reason );
return $job;
}
/**
* @param Title $title
* @param array $params
*/
public function __construct( $title, $params = [] ) {
parent::__construct( __CLASS__, $title, $params );
}
public function run() {
// Initialization
$title = $this->title;
// Other stuff
$user = $this->getUser();
$summary = $this->getSummary();
$base = $this->getBase();
$doer = User::newFromName( $this->getPerformer() );
$reason = $this->getReason();
PageTranslationHooks::$allowTargetEdit = true;
PageTranslationHooks::$jobQueueRunning = true;
$error = '';
$wikipage = new WikiPage( $title );
$status = $wikipage->doDeleteArticleReal( "{$summary}: $reason", false, 0, true, $error,
$user, [], 'delete', true );
if ( !$status->isGood() ) {
$params = [
'target' => $base,
'errors' => $status->getErrorsArray(),
];
$type = $this->getFull() ? 'deletefnok' : 'deletelnok';
$entry = new ManualLogEntry( 'pagetranslation', $type );
$entry->setPerformer( $doer );
$entry->setComment( $reason );
$entry->setTarget( $title );
$entry->setParameters( $params );
$logid = $entry->insert();
$entry->publish( $logid );
}
PageTranslationHooks::$allowTargetEdit = false;
$cache = wfGetCache( CACHE_DB );
$pages = (array)$cache->get( wfMemcKey( 'pt-base', $base ) );
$lastitem = array_pop( $pages );
if ( $title->getPrefixedText() === $lastitem ) {
$cache->delete( wfMemcKey( 'pt-base', $base ) );
$type = $this->getFull() ? 'deletefok' : 'deletelok';
$entry = new ManualLogEntry( 'pagetranslation', $type );
$entry->setPerformer( $doer );
$entry->setComment( $reason );
$entry->setTarget( Title::newFromText( $base ) );
$logid = $entry->insert();
$entry->publish( $logid );
$tpage = TranslatablePage::newFromTitle( $title );
$tpage->getTranslationPercentages( true );
foreach ( $tpage->getTranslationPages() as $page ) {
$page->invalidateCache();
}
$title->invalidateCache();
PageTranslationHooks::$jobQueueRunning = false;
}
return true;
}
public function setSummary( $summary ) {
$this->params['summary'] = $summary;
}
public function getSummary() {
return $this->params['summary'];
}
public function setReason( $reason ) {
$this->params['reason'] = $reason;
}
public function getReason() {
return $this->params['reason'];
}
public function setFull( $full ) {
$this->params['full'] = $full;
}
public function getFull() {
return $this->params['full'];
}
/**
* @param User|string $performer
*/
public function setPerformer( $performer ) {
if ( is_object( $performer ) ) {
$this->params['performer'] = $performer->getName();
} else {
$this->params['performer'] = $performer;
}
}
public function getPerformer() {
return $this->params['performer'];
}
/**
* @param User|string $user
*/
public function setUser( $user ) {
if ( is_object( $user ) ) {
$this->params['user'] = $user->getName();
} else {
$this->params['user'] = $user;
}
}
public function setBase( $base ) {
$this->params['base'] = $base;
}
public function getBase() {
return $this->params['base'];
}
/**
* Get a user object for doing edits.
* @return User
*/
public function getUser() {
return User::newFromName( $this->params['user'], false );
}
}
|