4 Special handling for image description pages
7 class ImagePage
extends Article
{
10 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
11 $this->openShowImage();
16 # If the article we've just shown is in the "Image" namespace,
17 # follow it with the history list and link list for the image
20 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
21 $this->closeShowImage();
22 $this->imageHistory();
27 function openShowImage()
29 global $wgOut, $wgUser,$wgRequest;
30 $name = $this->mTitle
->getText();
31 $path = wfImagePath( $name );
32 $url = wfImageUrl( $name );
34 if ( file_exists( $path ) ) {
35 list($width, $height, $type, $attr) = getimagesize( $path );
37 $sk = $wgUser->getSkin();
41 $s = "<div class=\"fullImage\"><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"".
42 "alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
44 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($name,"")."</div>";
46 $wgOut->addHTML( $s );
50 function closeShowImage()
55 # If the page we've just displayed is in the "Image" namespace,
56 # we follow it with an upload history of the image and its usage.
58 function imageHistory()
60 global $wgUser, $wgOut, $wgLang;
61 $fname = "Article::imageHistory";
63 $sql = "SELECT img_size,img_description,img_user," .
64 "img_user_text,img_timestamp FROM image WHERE " .
65 "img_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "'";
66 $res = wfQuery( $sql, DB_READ
, $fname );
68 if ( 0 == wfNumRows( $res ) ) { return; }
70 $sk = $wgUser->getSkin();
71 $s = $sk->beginImageHistoryList();
73 $line = wfFetchObject( $res );
74 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
75 $this->mTitle
->getText(), $line->img_user
,
76 $line->img_user_text
, $line->img_size
, $line->img_description
);
78 $sql = "SELECT oi_size,oi_description,oi_user," .
79 "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " .
80 "oi_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
81 "ORDER BY oi_timestamp DESC";
82 $res = wfQuery( $sql, DB_READ
, $fname );
84 while ( $line = wfFetchObject( $res ) ) {
85 $s .= $sk->imageHistoryLine( false, $line->oi_timestamp
,
86 $line->oi_archive_name
, $line->oi_user
,
87 $line->oi_user_text
, $line->oi_size
, $line->oi_description
);
89 $s .= $sk->endImageHistoryList();
90 $wgOut->addHTML( $s );
95 global $wgUser, $wgOut;
97 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
99 $sql = "SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
100 wfStrencode( $this->mTitle
->getDBkey() ) . "' AND il_from=cur_id";
101 $res = wfQuery( $sql, DB_READ
, "Article::imageLinks" );
103 if ( 0 == wfNumRows( $res ) ) {
104 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
107 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
109 $sk = $wgUser->getSkin();
110 while ( $s = wfFetchObject( $res ) ) {
111 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
112 $link = $sk->makeKnownLinkObj( $name, "" );
113 $wgOut->addHTML( "<li>{$link}</li>\n" );
115 $wgOut->addHTML( "</ul>\n" );
120 global $wgUser, $wgOut, $wgRequest;
122 $confirm = $wgRequest->getBool( 'wpConfirm' );
123 $image = $wgRequest->getVal( 'image' );
124 $oldimage = $wgRequest->getVal( 'oldimage' );
126 # Only sysops can delete images. Previously ordinary users could delete
127 # old revisions, but this is no longer the case.
128 if ( !$wgUser->isSysop() ) {
129 $wgOut->sysopRequired();
132 if ( wfReadOnly() ) {
133 $wgOut->readOnlyPage();
137 # Better double-check that it hasn't been deleted yet!
138 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
139 if ( !is_null( $image ) ) {
140 if ( "" == trim( $image ) ) {
141 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
146 # Deleting old images doesn't require confirmation
147 if ( !is_null( $oldimage ) ||
$confirm ) {
152 if ( !is_null( $image ) ) {
153 $q = "&image={$image}";
154 } else if ( !is_null( $oldimage ) ) {
155 $q = "&oldimage={$oldimage}";
159 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
164 global $wgOut, $wgUser, $wgLang, $wgRequest;
165 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
166 $fname = "Article::doDelete";
168 $reason = $wgRequest->getVal( 'wpReason' );
169 $image = $wgRequest->getVal( 'image' );
170 $oldimage = $wgRequest->getVal( 'oldimage' );
172 if ( !is_null( $image ) ) {
173 $dest = wfImageDir( $image );
174 $archive = wfImageDir( $image );
175 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
176 $wgOut->fileDeleteError( "{$dest}/{$image}" );
179 $sql = "DELETE FROM image WHERE img_name='" .
180 wfStrencode( $image ) . "'";
181 wfQuery( $sql, DB_WRITE
, $fname );
183 $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
184 wfStrencode( $image ) . "'";
185 $res = wfQuery( $sql, DB_READ
, $fname );
190 $wgInternalServer.wfImageUrl( $image )
192 wfPurgeSquidServers($urlArr);
197 while ( $s = wfFetchObject( $res ) ) {
198 $this->doDeleteOldImage( $s->oi_archive_name
);
199 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
202 # Squid purging, part II
204 /* this needs to be done after LinksUpdate */
205 $u = new SquidUpdate( $urlArr );
206 array_push( $wgDeferredUpdateList, $u );
209 $sql = "DELETE FROM oldimage WHERE oi_name='" .
210 wfStrencode( $image ) . "'";
211 wfQuery( $sql, DB_WRITE
, $fname );
213 # Image itself is now gone, and database is cleaned.
214 # Now we remove the image description page.
216 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
217 $article = new Article( $nt );
218 $article->doDeleteArticle( $reason ); # ignore errors
221 } else if ( !is_null( $oldimage ) ) {
225 $wgInternalServer.wfImageArchiveUrl( $oldimage )
227 wfPurgeSquidServers($urlArr);
229 $this->doDeleteOldImage( $oldimage );
230 $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
231 wfStrencode( $oldimage ) . "'";
232 wfQuery( $sql, DB_WRITE
, $fname );
234 $deleted = $oldimage;
236 $this->doDeleteArticle( $reason ); # ignore errors
237 $deleted = $this->mTitle
->getPrefixedText();
239 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
240 $wgOut->setRobotpolicy( "noindex,nofollow" );
242 $sk = $wgUser->getSkin();
243 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
244 Namespace::getWikipedia() ) .
245 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
247 $text = wfMsg( "deletedtext", $deleted, $loglink );
249 $wgOut->addHTML( "<p>" . $text . "</p>\n" );
250 $wgOut->returnToMain( false );
253 function doDeleteOldImage( $oldimage )
257 $name = substr( $oldimage, 15 );
258 $archive = wfImageArchiveDir( $name );
259 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
260 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
266 global $wgOut, $wgRequest;
267 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
269 $oldimage = $wgRequest->getText( 'oldimage' );
271 if ( strlen( $oldimage ) < 16 ) {
272 $wgOut->unexpectedValueError( "oldimage", $oldimage );
275 if ( wfReadOnly() ) {
276 $wgOut->readOnlyPage();
279 $name = substr( $oldimage, 15 );
281 $dest = wfImageDir( $name );
282 $archive = wfImageArchiveDir( $name );
283 $curfile = "{$dest}/{$name}";
285 if ( ! is_file( $curfile ) ) {
286 $wgOut->fileNotFoundError( $curfile );
289 $oldver = wfTimestampNow() . "!{$name}";
290 $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
291 wfStrencode( $oldimage ) . "'" );
293 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
294 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
297 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
298 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
300 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
304 $wgInternalServer.wfImageArchiveUrl( $name ),
305 $wgInternalServer.wfImageUrl( $name )
307 wfPurgeSquidServers($urlArr);
310 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
311 $wgOut->setRobotpolicy( "noindex,nofollow" );
312 $wgOut->addHTML( wfMsg( "imagereverted" ) );
313 $wgOut->returnToMain( false );