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 $dbr =& wfGetDB( DB_SLAVE
);
89 $cur = $dbr->tableName( 'cur' );
90 $imagelinks = $dbr->tableName( 'imagelinks' );
92 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
93 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id";
94 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
96 if ( 0 == $dbr->numRows( $res ) ) {
97 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
100 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
102 $sk = $wgUser->getSkin();
103 while ( $s = $dbr->fetchObject( $res ) ) {
104 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
105 $link = $sk->makeKnownLinkObj( $name, "" );
106 $wgOut->addHTML( "<li>{$link}</li>\n" );
108 $wgOut->addHTML( "</ul>\n" );
113 global $wgUser, $wgOut, $wgRequest;
115 $confirm = $wgRequest->getBool( 'wpConfirm' );
116 $image = $wgRequest->getVal( 'image' );
117 $oldimage = $wgRequest->getVal( 'oldimage' );
119 # Only sysops can delete images. Previously ordinary users could delete
120 # old revisions, but this is no longer the case.
121 if ( !$wgUser->isSysop() ) {
122 $wgOut->sysopRequired();
125 if ( wfReadOnly() ) {
126 $wgOut->readOnlyPage();
130 # Better double-check that it hasn't been deleted yet!
131 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
132 if ( !is_null( $image ) ) {
133 if ( "" == trim( $image ) ) {
134 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
139 # Deleting old images doesn't require confirmation
140 if ( !is_null( $oldimage ) ||
$confirm ) {
145 if ( !is_null( $image ) ) {
146 $q = "&image=" . urlencode( $image );
147 } else if ( !is_null( $oldimage ) ) {
148 $q = "&oldimage=" . urlencode( $oldimage );
152 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
157 global $wgOut, $wgUser, $wgLang, $wgRequest;
158 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
159 $fname = "Article::doDelete";
161 $reason = $wgRequest->getVal( 'wpReason' );
162 $image = $wgRequest->getVal( 'image' );
163 $oldimage = $wgRequest->getVal( 'oldimage' );
165 $dbw =& wfGetDB( DB_MASTER
);
167 if ( !is_null( $image ) ) {
168 $dest = wfImageDir( $image );
169 $archive = wfImageDir( $image );
170 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
171 $wgOut->fileDeleteError( "{$dest}/{$image}" );
174 $dbw->delete( 'image', array( 'img_name' => $image ) );
175 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
180 $wgInternalServer . Image
::wfImageUrl( $image )
182 wfPurgeSquidServers($urlArr);
187 while ( $s = $dbr->fetchObject( $res ) ) {
188 $this->doDeleteOldImage( $s->oi_archive_name
);
189 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
192 # Squid purging, part II
194 /* this needs to be done after LinksUpdate */
195 $u = new SquidUpdate( $urlArr );
196 array_push( $wgDeferredUpdateList, $u );
199 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
201 # Image itself is now gone, and database is cleaned.
202 # Now we remove the image description page.
204 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
205 $article = new Article( $nt );
206 $article->doDeleteArticle( $reason ); # ignore errors
209 } else if ( !is_null( $oldimage ) ) {
213 $wgInternalServer.wfImageArchiveUrl( $oldimage )
215 wfPurgeSquidServers($urlArr);
217 $this->doDeleteOldImage( $oldimage );
218 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
219 $deleted = $oldimage;
221 $this->doDeleteArticle( $reason ); # ignore errors
222 $deleted = $this->mTitle
->getPrefixedText();
224 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
225 $wgOut->setRobotpolicy( "noindex,nofollow" );
227 $sk = $wgUser->getSkin();
228 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
229 Namespace::getWikipedia() ) .
230 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
232 $text = wfMsg( "deletedtext", $deleted, $loglink );
234 $wgOut->addHTML( "<p>" . $text . "</p>\n" );
235 $wgOut->returnToMain( false );
238 function doDeleteOldImage( $oldimage )
242 $name = substr( $oldimage, 15 );
243 $archive = wfImageArchiveDir( $name );
244 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
245 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
251 global $wgOut, $wgRequest;
252 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
254 $oldimage = $wgRequest->getText( 'oldimage' );
256 if ( strlen( $oldimage ) < 16 ) {
257 $wgOut->unexpectedValueError( "oldimage", $oldimage );
260 if ( wfReadOnly() ) {
261 $wgOut->readOnlyPage();
264 if ( ! $this->mTitle
->userCanEdit() ) {
265 $wgOut->sysopRequired();
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}";
280 $dbr =& wfGetDB( DB_SLAVE
);
281 $size = $dbr->getField( "oldimage", "oi_size", "oi_archive_name='" .
282 $dbr->strencode( $oldimage ) . "'" );
284 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
285 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
288 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
289 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
291 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
295 $wgInternalServer.wfImageArchiveUrl( $name ),
296 $wgInternalServer . Image
::wfImageUrl( $name )
298 wfPurgeSquidServers($urlArr);
301 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
302 $wgOut->setRobotpolicy( "noindex,nofollow" );
303 $wgOut->addHTML( wfMsg( "imagereverted" ) );
304 $wgOut->returnToMain( false );