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 = "Article::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( $image ) ) {
184 $dest = wfImageDir( $image );
185 $archive = wfImageDir( $image );
186 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
187 $wgOut->fileDeleteError( "{$dest}/{$image}" );
190 $dbw->delete( 'image', array( 'img_name' => $image ) );
191 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
196 $wgInternalServer . Image
::wfImageUrl( $image )
198 wfPurgeSquidServers($urlArr);
203 while ( $s = $dbr->fetchObject( $res ) ) {
204 $this->doDeleteOldImage( $s->oi_archive_name
);
205 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
208 # Squid purging, part II
210 /* this needs to be done after LinksUpdate */
211 $u = new SquidUpdate( $urlArr );
212 array_push( $wgDeferredUpdateList, $u );
215 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
217 # Image itself is now gone, and database is cleaned.
218 # Now we remove the image description page.
220 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
221 $article = new Article( $nt );
222 $article->doDeleteArticle( $reason ); # ignore errors
225 } else if ( !is_null( $oldimage ) ) {
229 $wgInternalServer.wfImageArchiveUrl( $oldimage )
231 wfPurgeSquidServers($urlArr);
233 $this->doDeleteOldImage( $oldimage );
234 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
235 $deleted = $oldimage;
237 $this->doDeleteArticle( $reason ); # ignore errors
238 $deleted = $this->mTitle
->getPrefixedText();
240 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
241 $wgOut->setRobotpolicy( "noindex,nofollow" );
243 $sk = $wgUser->getSkin();
244 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
245 Namespace::getWikipedia() ) .
246 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
248 $text = wfMsg( "deletedtext", $deleted, $loglink );
250 $wgOut->addHTML( "<p>" . $text . "</p>\n" );
251 $wgOut->returnToMain( false );
254 function doDeleteOldImage( $oldimage )
258 $name = substr( $oldimage, 15 );
259 $archive = wfImageArchiveDir( $name );
260 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
261 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
267 global $wgOut, $wgRequest;
268 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
270 $oldimage = $wgRequest->getText( 'oldimage' );
272 if ( strlen( $oldimage ) < 16 ) {
273 $wgOut->unexpectedValueError( "oldimage", $oldimage );
276 if ( wfReadOnly() ) {
277 $wgOut->readOnlyPage();
280 if ( ! $this->mTitle
->userCanEdit() ) {
281 $wgOut->sysopRequired();
284 $name = substr( $oldimage, 15 );
286 $dest = wfImageDir( $name );
287 $archive = wfImageArchiveDir( $name );
288 $curfile = "{$dest}/{$name}";
290 if ( ! is_file( $curfile ) ) {
291 $wgOut->fileNotFoundError( $curfile );
294 $oldver = wfTimestampNow() . "!{$name}";
296 $dbr =& wfGetDB( DB_SLAVE
);
297 $size = $dbr->getField( "oldimage", "oi_size", "oi_archive_name='" .
298 $dbr->strencode( $oldimage ) . "'" );
300 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
301 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
304 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
305 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
307 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
311 $wgInternalServer.wfImageArchiveUrl( $name ),
312 $wgInternalServer . Image
::wfImageUrl( $name )
314 wfPurgeSquidServers($urlArr);
317 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
318 $wgOut->setRobotpolicy( "noindex,nofollow" );
319 $wgOut->addHTML( wfMsg( "imagereverted" ) );
320 $wgOut->returnToMain( false );