4 Special handling for image description pages
7 class ImagePage
extends Article
{
9 /* private */ var $img; // Image object this page is shown for. Initilaized in openShowImage, not
10 // available in doDelete etc.
13 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
14 $this->openShowImage();
19 # If the article we've just shown is in the "Image" namespace,
20 # follow it with the history list and link list for the image
23 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
24 $this->closeShowImage();
25 $this->imageHistory();
30 function openShowImage()
32 global $wgOut, $wgUser,$wgRequest;
33 $this->img
= Image
::newFromTitle( $this->mTitle
);
34 $url = $this->img
->getUrl();
36 if ( $this->img
->exists() ) {
38 $sk = $wgUser->getSkin();
40 if ( $this->img
->getType() != "" ) {
42 $s = "<div class=\"fullImage\">" .
43 "<img src=\"{$url}\" width=\"" . $this->img
->getWidth() . "\" height=\"" . $this->img
->getHeight() .
44 "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
46 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
48 $wgOut->addHTML( $s );
52 function closeShowImage()
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;
64 $sk = $wgUser->getSkin();
65 $s = $sk->beginImageHistoryList();
67 $line = $this->img
->nextHistoryLine();
69 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
70 $this->mTitle
->getDBkey(), $line->img_user
,
71 $line->img_user_text
, $line->img_size
, $line->img_description
);
73 while ( $line = $this->img
->nextHistoryLine() ) {
74 $s .= $sk->imageHistoryLine( false, $line->img_timestamp
,
75 $line->oi_archive_name
, $line->img_user
,
76 $line->img_user_text
, $line->img_size
, $line->img_description
);
78 $s .= $sk->endImageHistoryList();
79 $wgOut->addHTML( $s );
84 global $wgUser, $wgOut;
86 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
88 $sql = "SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
89 wfStrencode( $this->mTitle
->getDBkey() ) . "' AND il_from=cur_id";
90 $res = wfQuery( $sql, DB_READ
, "Article::imageLinks" );
92 if ( 0 == wfNumRows( $res ) ) {
93 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
96 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
98 $sk = $wgUser->getSkin();
99 while ( $s = wfFetchObject( $res ) ) {
100 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
101 $link = $sk->makeKnownLinkObj( $name, "" );
102 $wgOut->addHTML( "<li>{$link}</li>\n" );
104 $wgOut->addHTML( "</ul>\n" );
109 global $wgUser, $wgOut, $wgRequest;
111 $confirm = $wgRequest->getBool( 'wpConfirm' );
112 $image = $wgRequest->getVal( 'image' );
113 $oldimage = $wgRequest->getVal( 'oldimage' );
115 # Only sysops can delete images. Previously ordinary users could delete
116 # old revisions, but this is no longer the case.
117 if ( !$wgUser->isSysop() ) {
118 $wgOut->sysopRequired();
121 if ( wfReadOnly() ) {
122 $wgOut->readOnlyPage();
126 # Better double-check that it hasn't been deleted yet!
127 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
128 if ( !is_null( $image ) ) {
129 if ( "" == trim( $image ) ) {
130 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
135 # Deleting old images doesn't require confirmation
136 if ( !is_null( $oldimage ) ||
$confirm ) {
141 if ( !is_null( $image ) ) {
142 $q = "&image=" . urlencode( $image );
143 } else if ( !is_null( $oldimage ) ) {
144 $q = "&oldimage=" . urlencode( $oldimage );
148 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
153 global $wgOut, $wgUser, $wgLang, $wgRequest;
154 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
155 $fname = "Article::doDelete";
157 $reason = $wgRequest->getVal( 'wpReason' );
158 $image = $wgRequest->getVal( 'image' );
159 $oldimage = $wgRequest->getVal( 'oldimage' );
161 if ( !is_null( $image ) ) {
162 $dest = wfImageDir( $image );
163 $archive = wfImageDir( $image );
164 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
165 $wgOut->fileDeleteError( "{$dest}/{$image}" );
168 $sql = "DELETE FROM image WHERE img_name='" .
169 wfStrencode( $image ) . "'";
170 wfQuery( $sql, DB_WRITE
, $fname );
172 $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
173 wfStrencode( $image ) . "'";
174 $res = wfQuery( $sql, DB_READ
, $fname );
179 $wgInternalServer . Image
::wfImageUrl( $image )
181 wfPurgeSquidServers($urlArr);
186 while ( $s = wfFetchObject( $res ) ) {
187 $this->doDeleteOldImage( $s->oi_archive_name
);
188 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
191 # Squid purging, part II
193 /* this needs to be done after LinksUpdate */
194 $u = new SquidUpdate( $urlArr );
195 array_push( $wgDeferredUpdateList, $u );
198 $sql = "DELETE FROM oldimage WHERE oi_name='" .
199 wfStrencode( $image ) . "'";
200 wfQuery( $sql, DB_WRITE
, $fname );
202 # Image itself is now gone, and database is cleaned.
203 # Now we remove the image description page.
205 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
206 $article = new Article( $nt );
207 $article->doDeleteArticle( $reason ); # ignore errors
210 } else if ( !is_null( $oldimage ) ) {
214 $wgInternalServer.wfImageArchiveUrl( $oldimage )
216 wfPurgeSquidServers($urlArr);
218 $this->doDeleteOldImage( $oldimage );
219 $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
220 wfStrencode( $oldimage ) . "'";
221 wfQuery( $sql, DB_WRITE
, $fname );
223 $deleted = $oldimage;
225 $this->doDeleteArticle( $reason ); # ignore errors
226 $deleted = $this->mTitle
->getPrefixedText();
228 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
229 $wgOut->setRobotpolicy( "noindex,nofollow" );
231 $sk = $wgUser->getSkin();
232 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
233 Namespace::getWikipedia() ) .
234 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
236 $text = wfMsg( "deletedtext", $deleted, $loglink );
238 $wgOut->addHTML( "<p>" . $text . "</p>\n" );
239 $wgOut->returnToMain( false );
242 function doDeleteOldImage( $oldimage )
246 $name = substr( $oldimage, 15 );
247 $archive = wfImageArchiveDir( $name );
248 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
249 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
255 global $wgOut, $wgRequest;
256 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
258 $oldimage = $wgRequest->getText( 'oldimage' );
260 if ( strlen( $oldimage ) < 16 ) {
261 $wgOut->unexpectedValueError( "oldimage", $oldimage );
264 if ( wfReadOnly() ) {
265 $wgOut->readOnlyPage();
268 $name = substr( $oldimage, 15 );
270 $dest = wfImageDir( $name );
271 $archive = wfImageArchiveDir( $name );
272 $curfile = "{$dest}/{$name}";
274 if ( ! is_file( $curfile ) ) {
275 $wgOut->fileNotFoundError( $curfile );
278 $oldver = wfTimestampNow() . "!{$name}";
279 $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
280 wfStrencode( $oldimage ) . "'" );
282 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
283 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
286 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
287 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
289 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
293 $wgInternalServer.wfImageArchiveUrl( $name ),
294 $wgInternalServer . Image
::wfImageUrl( $name )
296 wfPurgeSquidServers($urlArr);
299 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
300 $wgOut->setRobotpolicy( "noindex,nofollow" );
301 $wgOut->addHTML( wfMsg( "imagereverted" ) );
302 $wgOut->returnToMain( false );