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;
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 .= "<center><img src=\"{$url}\" width=\"{$width}\" height=\"{$height}\"></center>";
43 $s .= "<center>".$sk->makeMediaLink($name,"")."</center>";
45 $wgOut->AddHTML( $s );
49 function closeShowImage()
51 global $wgOut, $wgUser;
52 $sk = $wgUser->getSkin();
54 $wgOut->AddHTML( $s );
57 # If the page we've just displayed is in the "Image" namespace,
58 # we follow it with an upload history of the image and its usage.
60 function imageHistory()
62 global $wgUser, $wgOut, $wgLang;
63 $fname = "Article::imageHistory";
65 $sql = "SELECT img_size,img_description,img_user," .
66 "img_user_text,img_timestamp FROM image WHERE " .
67 "img_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "'";
68 $res = wfQuery( $sql, DB_READ
, $fname );
70 if ( 0 == wfNumRows( $res ) ) { return; }
72 $sk = $wgUser->getSkin();
73 $s = $sk->beginImageHistoryList();
75 $line = wfFetchObject( $res );
76 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
77 $this->mTitle
->getText(), $line->img_user
,
78 $line->img_user_text
, $line->img_size
, $line->img_description
);
80 $sql = "SELECT oi_size,oi_description,oi_user," .
81 "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " .
82 "oi_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
83 "ORDER BY oi_timestamp DESC";
84 $res = wfQuery( $sql, DB_READ
, $fname );
86 while ( $line = wfFetchObject( $res ) ) {
87 $s .= $sk->imageHistoryLine( false, $line->oi_timestamp
,
88 $line->oi_archive_name
, $line->oi_user
,
89 $line->oi_user_text
, $line->oi_size
, $line->oi_description
);
91 $s .= $sk->endImageHistoryList();
92 $wgOut->addHTML( $s );
97 global $wgUser, $wgOut;
99 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
101 $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
102 wfStrencode( $this->mTitle
->getDBkey() ) . "'";
103 $res = wfQuery( $sql, DB_READ
, "Article::imageLinks" );
105 if ( 0 == wfNumRows( $res ) ) {
106 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "\n" );
109 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "\n<ul>" );
111 $sk = $wgUser->getSkin();
112 while ( $s = wfFetchObject( $res ) ) {
114 $link = $sk->makeKnownLink( $name, "" );
115 $wgOut->addHTML( "<li>{$link}</li>\n" );
117 $wgOut->addHTML( "</ul>\n" );
122 global $wgUser, $wgOut;
123 global $wpConfirm, $wpReason, $image, $oldimage;
125 # Anybody can delete old revisions of images; only sysops
126 # can delete articles and current images
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" ) );
140 if ( "" == trim( $image ) ) {
141 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
146 # Likewise, deleting old images doesn't require confirmation
147 if ( $oldimage ||
1 == $wpConfirm ) {
153 $q = "&image={$image}";
154 } else if ( $oldimage ) {
155 $q = "&oldimage={$oldimage}";
157 return $this->confirmDelete( $q );
162 global $wgOut, $wgUser, $wgLang;
163 global $image, $oldimage, $wpReason;
164 $fname = "Article::doDelete";
167 $dest = wfImageDir( $image );
168 $archive = wfImageDir( $image );
169 if ( ! unlink( "{$dest}/{$image}" ) ) {
170 $wgOut->fileDeleteError( "{$dest}/{$image}" );
173 $sql = "DELETE FROM image WHERE img_name='" .
174 wfStrencode( $image ) . "'";
175 wfQuery( $sql, DB_WRITE
, $fname );
177 $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
178 wfStrencode( $image ) . "'";
179 $res = wfQuery( $sql, DB_READ
, $fname );
181 while ( $s = wfFetchObject( $res ) ) {
182 $this->doDeleteOldImage( $s->oi_archive_name
);
184 $sql = "DELETE FROM oldimage WHERE oi_name='" .
185 wfStrencode( $image ) . "'";
186 wfQuery( $sql, DB_WRITE
, $fname );
188 # Image itself is now gone, and database is cleaned.
189 # Now we remove the image description page.
191 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
192 $this->doDeleteArticle( $nt );
195 } else if ( $oldimage ) {
196 $this->doDeleteOldImage( $oldimage );
197 $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
198 wfStrencode( $oldimage ) . "'";
199 wfQuery( $sql, DB_WRITE
, $fname );
201 $deleted = $oldimage;
203 $this->doDeleteArticle( $this->mTitle
);
204 $deleted = $this->mTitle
->getPrefixedText();
206 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
207 $wgOut->setRobotpolicy( "noindex,nofollow" );
209 $sk = $wgUser->getSkin();
210 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
211 Namespace::getWikipedia() ) .
212 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
214 $text = wfMsg( "deletedtext", $deleted, $loglink );
216 $wgOut->addHTML( "<p>" . $text );
217 $wgOut->returnToMain( false );
220 function doDeleteOldImage( $oldimage )
224 $name = substr( $oldimage, 15 );
225 $archive = wfImageArchiveDir( $name );
226 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
227 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
236 if ( strlen( $oldimage ) < 16 ) {
237 $wgOut->unexpectedValueError( "oldimage", $oldimage );
240 if ( wfReadOnly() ) {
241 $wgOut->readOnlyPage();
244 $name = substr( $oldimage, 15 );
246 $dest = wfImageDir( $name );
247 $archive = wfImageArchiveDir( $name );
248 $curfile = "{$dest}/{$name}";
250 if ( ! is_file( $curfile ) ) {
251 $wgOut->fileNotFoundError( $curfile );
254 $oldver = wfTimestampNow() . "!{$name}";
255 $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
256 wfStrencode( $oldimage ) . "'" );
258 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
259 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
262 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
263 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
265 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
267 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
268 $wgOut->setRobotpolicy( "noindex,nofollow" );
269 $wgOut->addHTML( wfMsg( "imagereverted" ) );
270 $wgOut->returnToMain( false );