9 require_once( 'Image.php' );
12 * Special handling for image description pages
15 class ImagePage
extends Article
{
17 /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
18 // available in doDelete etc.
21 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
22 $this->openShowImage();
27 # If the article we've just shown is in the "Image" namespace,
28 # follow it with the history list and link list for the image
31 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
32 $this->closeShowImage();
33 $this->imageHistory();
38 function openShowImage()
40 global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
41 $this->img
= Image
::newFromTitle( $this->mTitle
);
42 $url = $this->img
->getUrl();
47 if ( $this->img
->exists() ) {
49 $sk = $wgUser->getSkin();
51 if ( $this->img
->getType() != '' ) {
53 $width = $this->img
->getWidth();
54 $height = $this->img
->getHeight();
55 if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
56 $anchoropen = "<a href=\"{$url}\">";
57 $anchorclose = '</a>';
58 $url=$this->img
->createThumb( $wgMaxImageWidth );
59 $height = floor( $height * $wgMaxImageWidth / $width );
60 $width = $wgMaxImageWidth;
62 $s = "<div class=\"fullImage\">" . $anchoropen .
63 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
64 $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
66 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
68 $wgOut->addHTML( $s );
72 function closeShowImage()
78 * If the page we've just displayed is in the "Image" namespace,
79 * we follow it with an upload history of the image and its usage.
81 function imageHistory()
83 global $wgUser, $wgOut;
85 $sk = $wgUser->getSkin();
87 $line = $this->img
->nextHistoryLine();
90 $s = $sk->beginImageHistoryList() .
91 $sk->imageHistoryLine( true, $line->img_timestamp
,
92 $this->mTitle
->getDBkey(), $line->img_user
,
93 $line->img_user_text
, $line->img_size
, $line->img_description
);
95 while ( $line = $this->img
->nextHistoryLine() ) {
96 $s .= $sk->imageHistoryLine( false, $line->img_timestamp
,
97 $line->oi_archive_name
, $line->img_user
,
98 $line->img_user_text
, $line->img_size
, $line->img_description
);
100 $s .= $sk->endImageHistoryList();
102 $wgOut->addHTML( $s );
105 function imageLinks()
107 global $wgUser, $wgOut;
109 $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
111 $dbr =& wfGetDB( DB_SLAVE
);
112 $cur = $dbr->tableName( 'cur' );
113 $imagelinks = $dbr->tableName( 'imagelinks' );
115 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
116 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id";
117 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
119 if ( 0 == $dbr->numRows( $res ) ) {
120 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
123 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
125 $sk = $wgUser->getSkin();
126 while ( $s = $dbr->fetchObject( $res ) ) {
127 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
128 $link = $sk->makeKnownLinkObj( $name, "" );
129 $wgOut->addHTML( "<li>{$link}</li>\n" );
131 $wgOut->addHTML( "</ul>\n" );
136 global $wgUser, $wgOut, $wgRequest;
138 $confirm = $wgRequest->getBool( 'wpConfirm' );
139 $image = $wgRequest->getVal( 'image' );
140 $oldimage = $wgRequest->getVal( 'oldimage' );
142 # Only sysops can delete images. Previously ordinary users could delete
143 # old revisions, but this is no longer the case.
144 if ( !$wgUser->isSysop() ) {
145 $wgOut->sysopRequired();
148 if ( wfReadOnly() ) {
149 $wgOut->readOnlyPage();
153 # Better double-check that it hasn't been deleted yet!
154 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
155 if ( !is_null( $image ) ) {
156 if ( '' == trim( $image ) ) {
157 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
162 # Deleting old images doesn't require confirmation
163 if ( !is_null( $oldimage ) ||
$confirm ) {
168 if ( !is_null( $image ) ) {
169 $q = '&image=' . urlencode( $image );
170 } else if ( !is_null( $oldimage ) ) {
171 $q = '&oldimage=' . urlencode( $oldimage );
175 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
180 global $wgOut, $wgUser, $wgLang, $wgRequest;
181 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
182 $fname = 'ImagePage::doDelete';
184 $reason = $wgRequest->getVal( 'wpReason' );
185 $image = $wgRequest->getVal( 'image' );
186 $oldimage = $wgRequest->getVal( 'oldimage' );
188 $dbw =& wfGetDB( DB_MASTER
);
190 if ( !is_null( $oldimage ) ) {
194 $wgInternalServer.wfImageArchiveUrl( $oldimage )
196 wfPurgeSquidServers($urlArr);
198 $this->doDeleteOldImage( $oldimage );
199 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
200 $deleted = $oldimage;
202 if ( is_null ( $image ) ) {
203 $image = $this->mTitle
->getDBkey();
205 $dest = wfImageDir( $image );
206 $archive = wfImageDir( $image );
207 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
208 $wgOut->fileDeleteError( "{$dest}/{$image}" );
211 $dbw->delete( 'image', array( 'img_name' => $image ) );
212 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
217 $wgInternalServer . Image
::wfImageUrl( $image )
219 wfPurgeSquidServers($urlArr);
224 while ( $s = $dbw->fetchObject( $res ) ) {
225 $this->doDeleteOldImage( $s->oi_archive_name
);
226 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
229 # Squid purging, part II
231 /* this needs to be done after LinksUpdate */
232 $u = new SquidUpdate( $urlArr );
233 array_push( $wgDeferredUpdateList, $u );
236 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
238 # Image itself is now gone, and database is cleaned.
239 # Now we remove the image description page.
241 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
242 $article = new Article( $nt );
243 $article->doDeleteArticle( $reason ); # ignore errors
248 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
249 $wgOut->setRobotpolicy( 'noindex,nofollow' );
251 $sk = $wgUser->getSkin();
252 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
253 Namespace::getWikipedia() ) .
254 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
256 $text = wfMsg( 'deletedtext', $deleted, $loglink );
258 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
259 $wgOut->returnToMain( false );
262 function doDeleteOldImage( $oldimage )
266 $name = substr( $oldimage, 15 );
267 $archive = wfImageArchiveDir( $name );
268 if ( ! @unlink
( "{$archive}/{$oldimage}" ) ) {
269 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
272 $log = new LogPage( 'delete' );
273 $log->addEntry( 'delete', $this->mTitle
, wfMsg('deletedrevision',$oldimage) );
279 global $wgOut, $wgRequest;
280 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
282 $oldimage = $wgRequest->getText( 'oldimage' );
284 if ( strlen( $oldimage ) < 16 ) {
285 $wgOut->unexpectedValueError( 'oldimage', $oldimage );
288 if ( wfReadOnly() ) {
289 $wgOut->readOnlyPage();
292 if ( ! $this->mTitle
->userCanEdit() ) {
293 $wgOut->sysopRequired();
296 $name = substr( $oldimage, 15 );
298 $dest = wfImageDir( $name );
299 $archive = wfImageArchiveDir( $name );
300 $curfile = "{$dest}/{$name}";
302 if ( ! is_file( $curfile ) ) {
303 $wgOut->fileNotFoundError( $curfile );
306 $oldver = wfTimestampNow() . "!{$name}";
308 $dbr =& wfGetDB( DB_SLAVE
);
309 $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
310 $dbr->strencode( $oldimage ) . "'" );
312 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
313 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
316 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
317 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
319 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
323 $wgInternalServer.wfImageArchiveUrl( $name ),
324 $wgInternalServer . Image
::wfImageUrl( $name )
326 wfPurgeSquidServers($urlArr);
329 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
330 $wgOut->setRobotpolicy( 'noindex,nofollow' );
331 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
332 $wgOut->returnToMain( false );