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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
<?php
/**
* @package MediaWiki
*/
/**
*
*/
require_once( 'Image.php' );
/**
* Special handling for image description pages
* @package MediaWiki
*/
class ImagePage extends Article {
/* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
// available in doDelete etc.
function view() {
if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
$this->openShowImage();
}
Article::view();
# If the article we've just shown is in the "Image" namespace,
# follow it with the history list and link list for the image
# it describes.
if ( Namespace::getImage() == $this->mTitle->getNamespace() ) {
$this->closeShowImage();
$this->imageHistory();
$this->imageLinks();
}
}
function openShowImage()
{
global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
$this->img = Image::newFromTitle( $this->mTitle );
$url = $this->img->getUrl();
$anchoropen = '';
$anchorclose = '';
if ( $this->img->exists() ) {
$sk = $wgUser->getSkin();
if ( $this->img->getType() != '' ) {
# image
$width = $this->img->getWidth();
$height = $this->img->getHeight();
if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
$anchoropen = "<a href=\"{$url}\">";
$anchorclose = '</a>';
$url=$this->img->createThumb( $wgMaxImageWidth );
$height = floor( $height * $wgMaxImageWidth / $width );
$width = $wgMaxImageWidth;
}
$s = "<div class=\"fullImage\">" . $anchoropen .
"<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
$wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
} else {
$s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),"")."</div>";
}
$wgOut->addHTML( $s );
}
}
function closeShowImage()
{
# For overloading
}
/**
* If the page we've just displayed is in the "Image" namespace,
* we follow it with an upload history of the image and its usage.
*/
function imageHistory()
{
global $wgUser, $wgOut;
$sk = $wgUser->getSkin();
$line = $this->img->nextHistoryLine();
if ( $line ) {
$s = $sk->beginImageHistoryList() .
$sk->imageHistoryLine( true, $line->img_timestamp,
$this->mTitle->getDBkey(), $line->img_user,
$line->img_user_text, $line->img_size, $line->img_description );
while ( $line = $this->img->nextHistoryLine() ) {
$s .= $sk->imageHistoryLine( false, $line->img_timestamp,
$line->oi_archive_name, $line->img_user,
$line->img_user_text, $line->img_size, $line->img_description );
}
$s .= $sk->endImageHistoryList();
} else { $s=''; }
$wgOut->addHTML( $s );
}
function imageLinks()
{
global $wgUser, $wgOut;
$wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
$dbr =& wfGetDB( DB_SLAVE );
$cur = $dbr->tableName( 'cur' );
$imagelinks = $dbr->tableName( 'imagelinks' );
$sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
$dbr->addQuotes( $this->mTitle->getDBkey() ) . " AND il_from=cur_id";
$res = $dbr->query( $sql, DB_SLAVE, "Article::imageLinks" );
if ( 0 == $dbr->numRows( $res ) ) {
$wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
return;
}
$wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
$sk = $wgUser->getSkin();
while ( $s = $dbr->fetchObject( $res ) ) {
$name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
$link = $sk->makeKnownLinkObj( $name, "" );
$wgOut->addHTML( "<li>{$link}</li>\n" );
}
$wgOut->addHTML( "</ul>\n" );
}
function delete()
{
global $wgUser, $wgOut, $wgRequest;
$confirm = $wgRequest->getBool( 'wpConfirm' );
$image = $wgRequest->getVal( 'image' );
$oldimage = $wgRequest->getVal( 'oldimage' );
# Only sysops can delete images. Previously ordinary users could delete
# old revisions, but this is no longer the case.
if ( !$wgUser->isSysop() ) {
$wgOut->sysopRequired();
return;
}
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
# Better double-check that it hasn't been deleted yet!
$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
if ( !is_null( $image ) ) {
if ( '' == trim( $image ) ) {
$wgOut->fatalError( wfMsg( 'cannotdelete' ) );
return;
}
}
# Deleting old images doesn't require confirmation
if ( !is_null( $oldimage ) || $confirm ) {
$this->doDelete();
return;
}
if ( !is_null( $image ) ) {
$q = '&image=' . urlencode( $image );
} else if ( !is_null( $oldimage ) ) {
$q = '&oldimage=' . urlencode( $oldimage );
} else {
$q = '';
}
return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
}
function doDelete()
{
global $wgOut, $wgUser, $wgLang, $wgRequest;
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
$fname = 'ImagePage::doDelete';
$reason = $wgRequest->getVal( 'wpReason' );
$image = $wgRequest->getVal( 'image' );
$oldimage = $wgRequest->getVal( 'oldimage' );
$dbw =& wfGetDB( DB_MASTER );
if ( !is_null( $oldimage ) ) {
# Squid purging
if ( $wgUseSquid ) {
$urlArr = Array(
$wgInternalServer.wfImageArchiveUrl( $oldimage )
);
wfPurgeSquidServers($urlArr);
}
$this->doDeleteOldImage( $oldimage );
$dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
$deleted = $oldimage;
} else {
if ( is_null ( $image ) ) {
$image = $this->mTitle->getDBkey();
}
$dest = wfImageDir( $image );
$archive = wfImageDir( $image );
if ( ! @unlink( "{$dest}/{$image}" ) ) {
$wgOut->fileDeleteError( "{$dest}/{$image}" );
return;
}
$dbw->delete( 'image', array( 'img_name' => $image ) );
$res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
# Squid purging
if ( $wgUseSquid ) {
$urlArr = Array(
$wgInternalServer . Image::wfImageUrl( $image )
);
wfPurgeSquidServers($urlArr);
}
$urlArr = Array();
while ( $s = $dbw->fetchObject( $res ) ) {
$this->doDeleteOldImage( $s->oi_archive_name );
$urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
}
# Squid purging, part II
if ( $wgUseSquid ) {
/* this needs to be done after LinksUpdate */
$u = new SquidUpdate( $urlArr );
array_push( $wgDeferredUpdateList, $u );
}
$dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
# Image itself is now gone, and database is cleaned.
# Now we remove the image description page.
$nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
$article = new Article( $nt );
$article->doDeleteArticle( $reason ); # ignore errors
$deleted = $image;
}
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$sk = $wgUser->getSkin();
$loglink = $sk->makeKnownLink( $wgLang->getNsText(
Namespace::getWikipedia() ) .
':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
$text = wfMsg( 'deletedtext', $deleted, $loglink );
$wgOut->addHTML( '<p>' . $text . "</p>\n" );
$wgOut->returnToMain( false );
}
function doDeleteOldImage( $oldimage )
{
global $wgOut;
$name = substr( $oldimage, 15 );
$archive = wfImageArchiveDir( $name );
if ( ! @unlink( "{$archive}/{$oldimage}" ) ) {
$wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
} else {
# Log the deletion
$log = new LogPage( 'delete' );
$log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
}
}
function revert()
{
global $wgOut, $wgRequest;
global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
$oldimage = $wgRequest->getText( 'oldimage' );
if ( strlen( $oldimage ) < 16 ) {
$wgOut->unexpectedValueError( 'oldimage', $oldimage );
return;
}
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
if ( ! $this->mTitle->userCanEdit() ) {
$wgOut->sysopRequired();
return;
}
$name = substr( $oldimage, 15 );
$dest = wfImageDir( $name );
$archive = wfImageArchiveDir( $name );
$curfile = "{$dest}/{$name}";
if ( ! is_file( $curfile ) ) {
$wgOut->fileNotFoundError( $curfile );
return;
}
$oldver = wfTimestampNow() . "!{$name}";
$dbr =& wfGetDB( DB_SLAVE );
$size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
$dbr->strencode( $oldimage ) . "'" );
if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
$wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
return;
}
if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
$wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
}
wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
# Squid purging
if ( $wgUseSquid ) {
$urlArr = Array(
$wgInternalServer.wfImageArchiveUrl( $name ),
$wgInternalServer . Image::wfImageUrl( $name )
);
wfPurgeSquidServers($urlArr);
}
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->addHTML( wfMsg( 'imagereverted' ) );
$wgOut->returnToMain( false );
}
}
?>
|