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;
35 $this->img
= Image
::newFromTitle( $this->mTitle
);
36 $url = $this->img
->getUrl();
38 if ( $this->img
->exists() ) {
40 $sk = $wgUser->getSkin();
42 if ( $this->img
->getType() != "" ) {
44 $s = "<div class=\"fullImage\">" .
45 "<img src=\"{$url}\" width=\"" . $this->img
->getWidth() . "\" height=\"" . $this->img
->getHeight() .
46 "\" alt=\"".$wgRequest->getVal( 'image' )."\" /></div>";
48 $s = "<div class=\"fullMedia\">".$sk->makeMediaLink($this->img
->getName(),"")."</div>";
50 $wgOut->addHTML( $s );
54 function closeShowImage()
59 # If the page we've just displayed is in the "Image" namespace,
60 # we follow it with an upload history of the image and its usage.
62 function imageHistory()
64 global $wgUser, $wgOut;
66 $sk = $wgUser->getSkin();
67 $s = $sk->beginImageHistoryList();
69 $line = $this->img
->nextHistoryLine();
71 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
72 $this->mTitle
->getDBkey(), $line->img_user
,
73 $line->img_user_text
, $line->img_size
, $line->img_description
);
75 while ( $line = $this->img
->nextHistoryLine() ) {
76 $s .= $sk->imageHistoryLine( false, $line->img_timestamp
,
77 $line->oi_archive_name
, $line->img_user
,
78 $line->img_user_text
, $line->img_size
, $line->img_description
);
80 $s .= $sk->endImageHistoryList();
81 $wgOut->addHTML( $s );
86 global $wgUser, $wgOut;
88 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
90 $dbr =& wfGetDB( DB_SLAVE
);
91 $cur = $dbr->tableName( 'cur' );
92 $imagelinks = $dbr->tableName( 'imagelinks' );
94 $sql = "SELECT cur_namespace,cur_title FROM $imagelinks,$cur WHERE il_to=" .
95 $dbr->addQuotes( $this->mTitle
->getDBkey() ) . " AND il_from=cur_id";
96 $res = $dbr->query( $sql, DB_SLAVE
, "Article::imageLinks" );
98 if ( 0 == $dbr->numRows( $res ) ) {
99 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "</p>\n" );
102 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "</p>\n<ul>" );
104 $sk = $wgUser->getSkin();
105 while ( $s = $dbr->fetchObject( $res ) ) {
106 $name = Title
::MakeTitle( $s->cur_namespace
, $s->cur_title
);
107 $link = $sk->makeKnownLinkObj( $name, "" );
108 $wgOut->addHTML( "<li>{$link}</li>\n" );
110 $wgOut->addHTML( "</ul>\n" );
115 global $wgUser, $wgOut, $wgRequest;
117 $confirm = $wgRequest->getBool( 'wpConfirm' );
118 $image = $wgRequest->getVal( 'image' );
119 $oldimage = $wgRequest->getVal( 'oldimage' );
121 # Only sysops can delete images. Previously ordinary users could delete
122 # old revisions, but this is no longer the case.
123 if ( !$wgUser->isSysop() ) {
124 $wgOut->sysopRequired();
127 if ( wfReadOnly() ) {
128 $wgOut->readOnlyPage();
132 # Better double-check that it hasn't been deleted yet!
133 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
134 if ( !is_null( $image ) ) {
135 if ( "" == trim( $image ) ) {
136 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
141 # Deleting old images doesn't require confirmation
142 if ( !is_null( $oldimage ) ||
$confirm ) {
147 if ( !is_null( $image ) ) {
148 $q = "&image=" . urlencode( $image );
149 } else if ( !is_null( $oldimage ) ) {
150 $q = "&oldimage=" . urlencode( $oldimage );
154 return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
159 global $wgOut, $wgUser, $wgLang, $wgRequest;
160 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
161 $fname = "Article::doDelete";
163 $reason = $wgRequest->getVal( 'wpReason' );
164 $image = $wgRequest->getVal( 'image' );
165 $oldimage = $wgRequest->getVal( 'oldimage' );
167 $dbw =& wfGetDB( DB_MASTER
);
169 if ( !is_null( $image ) ) {
170 $dest = wfImageDir( $image );
171 $archive = wfImageDir( $image );
172 if ( ! @unlink
( "{$dest}/{$image}" ) ) {
173 $wgOut->fileDeleteError( "{$dest}/{$image}" );
176 $dbw->delete( 'image', array( 'img_name' => $image ) );
177 $res = $dbw->select( 'oldimage', array( 'oi_archive_name' ), array( 'oi_name' => $image ) );
182 $wgInternalServer . Image
::wfImageUrl( $image )
184 wfPurgeSquidServers($urlArr);
189 while ( $s = $dbr->fetchObject( $res ) ) {
190 $this->doDeleteOldImage( $s->oi_archive_name
);
191 $urlArr[] = $wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name
);
194 # Squid purging, part II
196 /* this needs to be done after LinksUpdate */
197 $u = new SquidUpdate( $urlArr );
198 array_push( $wgDeferredUpdateList, $u );
201 $dbw->delete( 'oldimage', array( 'oi_name' => $image ) );
203 # Image itself is now gone, and database is cleaned.
204 # Now we remove the image description page.
206 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
207 $article = new Article( $nt );
208 $article->doDeleteArticle( $reason ); # ignore errors
211 } else if ( !is_null( $oldimage ) ) {
215 $wgInternalServer.wfImageArchiveUrl( $oldimage )
217 wfPurgeSquidServers($urlArr);
219 $this->doDeleteOldImage( $oldimage );
220 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
221 $deleted = $oldimage;
223 $this->doDeleteArticle( $reason ); # ignore errors
224 $deleted = $this->mTitle
->getPrefixedText();
226 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
227 $wgOut->setRobotpolicy( "noindex,nofollow" );
229 $sk = $wgUser->getSkin();
230 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
231 Namespace::getWikipedia() ) .
232 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
234 $text = wfMsg( "deletedtext", $deleted, $loglink );
236 $wgOut->addHTML( "<p>" . $text . "</p>\n" );
237 $wgOut->returnToMain( false );
240 function doDeleteOldImage( $oldimage )
244 $name = substr( $oldimage, 15 );
245 $archive = wfImageArchiveDir( $name );
246 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
247 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
253 global $wgOut, $wgRequest;
254 global $wgUseSquid, $wgInternalServer, $wgDeferredUpdateList;
256 $oldimage = $wgRequest->getText( 'oldimage' );
258 if ( strlen( $oldimage ) < 16 ) {
259 $wgOut->unexpectedValueError( "oldimage", $oldimage );
262 if ( wfReadOnly() ) {
263 $wgOut->readOnlyPage();
266 if ( ! $this->mTitle
->userCanEdit() ) {
267 $wgOut->sysopRequired();
270 $name = substr( $oldimage, 15 );
272 $dest = wfImageDir( $name );
273 $archive = wfImageArchiveDir( $name );
274 $curfile = "{$dest}/{$name}";
276 if ( ! is_file( $curfile ) ) {
277 $wgOut->fileNotFoundError( $curfile );
280 $oldver = wfTimestampNow() . "!{$name}";
282 $dbr =& wfGetDB( DB_SLAVE
);
283 $size = $dbr->getField( "oldimage", "oi_size", "oi_archive_name='" .
284 $dbr->strencode( $oldimage ) . "'" );
286 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
287 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
290 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
291 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
293 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
297 $wgInternalServer.wfImageArchiveUrl( $name ),
298 $wgInternalServer . Image
::wfImageUrl( $name )
300 wfPurgeSquidServers($urlArr);
303 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
304 $wgOut->setRobotpolicy( "noindex,nofollow" );
305 $wgOut->addHTML( wfMsg( "imagereverted" ) );
306 $wgOut->returnToMain( false );