4 Special handling for image description pages
7 require_once( 'Image.php' );
9 class ImagePage
extends Article
{
11 /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
12 // available in doDelete etc.
15 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
16 $this->openShowImage();
21 # If the article we've just shown is in the "Image" namespace,
22 # follow it with the history list and link list for the image
25 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
26 $this->closeShowImage();
27 $this->imageHistory();
32 function openShowImage()
34 global $wgOut, $wgUser, $wgRequest, $wgMaxImageWidth, $wgUseImageResize;
35 $this->img
= Image
::newFromTitle( $this->mTitle
);
36 $url = $this->img
->getUrl();
41 if ( $this->img
->exists() ) {
43 $sk = $wgUser->getSkin();
45 if ( $this->img
->getType() != '' ) {
47 $width = $this->img
->getWidth();
48 $height = $this->img
->getHeight();
49 if ( $width > $wgMaxImageWidth && $wgUseImageResize ) {
50 $anchoropen = "<a href=\"{$url}\">";
51 $anchorclose = '</a>';
52 $url=$this->img
->createThumb( $wgMaxImageWidth );
53 $height = floor( $height * $wgMaxImageWidth / $width );
54 $width = $wgMaxImageWidth;
56 $s = "<div class=\"fullImage\">" . $anchoropen .
57 "<img border=\"0\" src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" alt=\"" .
58 $wgRequest->getVal( 'image' )."\" />" . $anchorclose . "</div>";
60 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
62 $wgOut->addHTML( $s );
66 function closeShowImage()
71 # If the page we've just displayed is in the "Image" namespace,
72 # we follow it with an upload history of the image and its usage.
74 function imageHistory()
76 global $wgUser, $wgOut;
78 $sk = $wgUser->getSkin();
80 $line = $this->img
->nextHistoryLine();
83 $s = $sk->beginImageHistoryList() .
84 $sk->imageHistoryLine( true, $line->img_timestamp
,
85 $this->mTitle
->getDBkey(), $line->img_user
,
86 $line->img_user_text
, $line->img_size
, $line->img_description
);
88 while ( $line = $this->img
->nextHistoryLine() ) {
89 $s .= $sk->imageHistoryLine( false, $line->img_timestamp
,
90 $line->oi_archive_name
, $line->img_user
,
91 $line->img_user_text
, $line->img_size
, $line->img_description
);
93 $s .= $sk->endImageHistoryList();
95 $wgOut->addHTML( $s );
100 global $wgUser, $wgOut;
102 $wgOut->addHTML( '<h2>' . wfMsg( 'imagelinks' ) . "</h2>\n" );
104 $dbr =& wfGetDB( DB_SLAVE
);
105 $cur = $dbr->tableName( 'cur' );
106 $imagelinks = $dbr->tableName( 'imagelinks' );
108 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
109 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id";
110 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
112 if ( 0 == $dbr->numRows( $res ) ) {
113 $wgOut->addHtml( '<p>' . wfMsg( "nolinkstoimage" ) . "</p>\n" );
116 $wgOut->addHTML( '<p>' . wfMsg( 'linkstoimage' ) . "</p>\n<ul>" );
118 $sk = $wgUser->getSkin();
119 while ( $s = $dbr->fetchObject( $res ) ) {
120 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
121 $link = $sk->makeKnownLinkObj( $name, "" );
122 $wgOut->addHTML( "<li>{$link}</li>\n" );
124 $wgOut->addHTML( "</ul>\n" );
129 global $wgUser, $wgOut, $wgRequest;
131 $confirm = $wgRequest->getBool( 'wpConfirm' );
132 $image = $wgRequest->getVal( 'image' );
133 $oldimage = $wgRequest->getVal( 'oldimage' );
135 # Only sysops can delete images. Previously ordinary users could delete
136 # old revisions, but this is no longer the case.
137 if ( !$wgUser->isSysop() ) {
138 $wgOut->sysopRequired();
141 if ( wfReadOnly() ) {
142 $wgOut->readOnlyPage();
146 # Better double-check that it hasn't been deleted yet!
147 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
148 if ( !is_null( $image ) ) {
149 if ( '' == trim( $image ) ) {
150 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
155 # Deleting old images doesn't require confirmation
156 if ( !is_null( $oldimage ) ||
$confirm ) {
161 if ( !is_null( $image ) ) {
162 $q = '&image=' . urlencode( $image );
163 } else if ( !is_null( $oldimage ) ) {
164 $q = '&oldimage=' . urlencode( $oldimage );
168 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
173 global $wgOut, $wgUser, $wgLang, $wgRequest;
174 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
175 $fname = 'ImagePage::doDelete';
177 $reason = $wgRequest->getVal( 'wpReason' );
178 $image = $wgRequest->getVal( 'image' );
179 $oldimage = $wgRequest->getVal( 'oldimage' );
181 $dbw =& wfGetDB( DB_MASTER
);
183 if ( !is_null( $oldimage ) ) {
187 $wgInternalServer.wfImageArchiveUrl( $oldimage )
189 wfPurgeSquidServers($urlArr);
191 $this->doDeleteOldImage( $oldimage );
192 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
193 $deleted = $oldimage;
195 if ( is_null ( $image ) ) {
196 $image = $this->mTitle
->getDBkey();
198 $dest = wfImageDir( $image );
199 $archive = wfImageDir( $image );
200 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
201 $wgOut->fileDeleteError( "{$dest}/{$image}" );
204 $dbw->delete( 'image', array( 'img_name' => $image ) );
205 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
210 $wgInternalServer . Image
::wfImageUrl( $image )
212 wfPurgeSquidServers($urlArr);
217 while ( $s = $dbw->fetchObject( $res ) ) {
218 $this->doDeleteOldImage( $s->oi_archive_name
);
219 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
222 # Squid purging, part II
224 /* this needs to be done after LinksUpdate */
225 $u = new SquidUpdate( $urlArr );
226 array_push( $wgDeferredUpdateList, $u );
229 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
231 # Image itself is now gone, and database is cleaned.
232 # Now we remove the image description page.
234 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
235 $article = new Article( $nt );
236 $article->doDeleteArticle( $reason ); # ignore errors
241 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
242 $wgOut->setRobotpolicy( 'noindex,nofollow' );
244 $sk = $wgUser->getSkin();
245 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
246 Namespace::getWikipedia() ) .
247 ':' . wfMsg( 'dellogpage' ), wfMsg( 'deletionlog' ) );
249 $text = wfMsg( 'deletedtext', $deleted, $loglink );
251 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
252 $wgOut->returnToMain( false );
255 function doDeleteOldImage( $oldimage )
259 $name = substr( $oldimage, 15 );
260 $archive = wfImageArchiveDir( $name );
261 if ( ! @unlink
( "{$archive}/{$oldimage}" ) ) {
262 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
265 $log = new LogPage( 'delete' );
266 $log->addEntry( 'delete', $this->mTitle
, wfMsg('deletedrevision',$oldimage) );
272 global $wgOut, $wgRequest;
273 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
275 $oldimage = $wgRequest->getText( 'oldimage' );
277 if ( strlen( $oldimage ) < 16 ) {
278 $wgOut->unexpectedValueError( 'oldimage', $oldimage );
281 if ( wfReadOnly() ) {
282 $wgOut->readOnlyPage();
285 if ( ! $this->mTitle
->userCanEdit() ) {
286 $wgOut->sysopRequired();
289 $name = substr( $oldimage, 15 );
291 $dest = wfImageDir( $name );
292 $archive = wfImageArchiveDir( $name );
293 $curfile = "{$dest}/{$name}";
295 if ( ! is_file( $curfile ) ) {
296 $wgOut->fileNotFoundError( $curfile );
299 $oldver = wfTimestampNow() . "!{$name}";
301 $dbr =& wfGetDB( DB_SLAVE
);
302 $size = $dbr->getField( 'oldimage', 'oi_size', 'oi_archive_name=\'' .
303 $dbr->strencode( $oldimage ) . "'" );
305 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
306 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
309 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
310 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
312 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
316 $wgInternalServer.wfImageArchiveUrl( $name ),
317 $wgInternalServer . Image
::wfImageUrl( $name )
319 wfPurgeSquidServers($urlArr);
322 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
323 $wgOut->setRobotpolicy( 'noindex,nofollow' );
324 $wgOut->addHTML( wfMsg( 'imagereverted' ) );
325 $wgOut->returnToMain( false );