4 Special handling for image description pages
7 class ImagePage
extends Article
{
12 # If the article we've just shown is in the "Image" namespace,
13 # follow it with the history list and link list for the image
16 if ( Namespace::getImage() == $this->mTitle
->getNamespace() ) {
17 $this->imageHistory();
22 # If the page we've just displayed is in the "Image" namespace,
23 # we follow it with an upload history of the image and its usage.
25 function imageHistory()
27 global $wgUser, $wgOut, $wgLang;
28 $fname = "Article::imageHistory";
30 $sql = "SELECT img_size,img_description,img_user," .
31 "img_user_text,img_timestamp FROM image WHERE " .
32 "img_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "'";
33 $res = wfQuery( $sql, $fname );
35 if ( 0 == wfNumRows( $res ) ) { return; }
37 $sk = $wgUser->getSkin();
38 $s = $sk->beginImageHistoryList();
40 $line = wfFetchObject( $res );
41 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
42 $this->mTitle
->getText(), $line->img_user
,
43 $line->img_user_text
, $line->img_size
, $line->img_description
);
45 $sql = "SELECT oi_size,oi_description,oi_user," .
46 "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " .
47 "oi_name='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
48 "ORDER BY oi_timestamp DESC";
49 $res = wfQuery( $sql, $fname );
51 while ( $line = wfFetchObject( $res ) ) {
52 $s .= $sk->imageHistoryLine( false, $line->oi_timestamp
,
53 $line->oi_archive_name
, $line->oi_user
,
54 $line->oi_user_text
, $line->oi_size
, $line->oi_description
);
56 $s .= $sk->endImageHistoryList();
57 $wgOut->addHTML( $s );
62 global $wgUser, $wgOut;
64 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
66 $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
67 wfStrencode( $this->mTitle
->getDBkey() ) . "'";
68 $res = wfQuery( $sql, "Article::imageLinks" );
70 if ( 0 == wfNumRows( $res ) ) {
71 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "\n" );
74 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "\n<ul>" );
76 $sk = $wgUser->getSkin();
77 while ( $s = wfFetchObject( $res ) ) {
79 $link = $sk->makeKnownLink( $name, "" );
80 $wgOut->addHTML( "<li>{$link}</li>\n" );
82 $wgOut->addHTML( "</ul>\n" );
87 global $wgUser, $wgOut;
88 global $wpConfirm, $wpReason, $image, $oldimage;
90 # Anybody can delete old revisions of images; only sysops
91 # can delete articles and current images
93 if ( ( ! $oldimage ) && ( ! $wgUser->isSysop() ) ) {
94 $wgOut->sysopRequired();
98 $wgOut->readOnlyPage();
102 # Better double-check that it hasn't been deleted yet!
103 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
105 if ( "" == trim( $image ) ) {
106 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
111 # Likewise, deleting old images doesn't require confirmation
112 if ( $oldimage ||
1 == $wpConfirm ) {
118 $q = "&image={$image}";
119 } else if ( $oldimage ) {
120 $q = "&oldimage={$oldimage}";
122 return $this->confirmDelete( $q );
127 global $wgOut, $wgUser, $wgLang;
128 global $image, $oldimage, $wpReason;
129 $fname = "Article::doDelete";
132 $dest = wfImageDir( $image );
133 $archive = wfImageDir( $image );
134 if ( ! unlink( "{$dest}/{$image}" ) ) {
135 $wgOut->fileDeleteError( "{$dest}/{$image}" );
138 $sql = "DELETE FROM image WHERE img_name='" .
139 wfStrencode( $image ) . "'";
140 wfQuery( $sql, $fname );
142 $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
143 wfStrencode( $image ) . "'";
144 $res = wfQuery( $sql, $fname );
146 while ( $s = wfFetchObject( $res ) ) {
147 $this->doDeleteOldImage( $s->oi_archive_name
);
149 $sql = "DELETE FROM oldimage WHERE oi_name='" .
150 wfStrencode( $image ) . "'";
151 wfQuery( $sql, $fname );
153 # Image itself is now gone, and database is cleaned.
154 # Now we remove the image description page.
156 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
157 $this->doDeleteArticle( $nt );
160 } else if ( $oldimage ) {
161 $this->doDeleteOldImage( $oldimage );
162 $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
163 wfStrencode( $oldimage ) . "'";
164 wfQuery( $sql, $fname );
166 $deleted = $oldimage;
168 $this->doDeleteArticle( $this->mTitle
);
169 $deleted = $this->mTitle
->getPrefixedText();
171 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
172 $wgOut->setRobotpolicy( "noindex,nofollow" );
174 $sk = $wgUser->getSkin();
175 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
176 Namespace::getWikipedia() ) .
177 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
179 $text = str_replace( "$1" , $deleted, wfMsg( "deletedtext" ) );
180 $text = str_replace( "$2", $loglink, $text );
182 $wgOut->addHTML( "<p>" . $text );
183 $wgOut->returnToMain( false );
186 function doDeleteOldImage( $oldimage )
190 $name = substr( $oldimage, 15 );
191 $archive = wfImageArchiveDir( $name );
192 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
193 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
202 if ( strlen( $oldimage ) < 16 ) {
203 $wgOut->unexpectedValueError( "oldimage", $oldimage );
206 if ( wfReadOnly() ) {
207 $wgOut->readOnlyPage();
210 $name = substr( $oldimage, 15 );
212 $dest = wfImageDir( $name );
213 $archive = wfImageArchiveDir( $name );
214 $curfile = "{$dest}/{$name}";
216 if ( ! is_file( $curfile ) ) {
217 $wgOut->fileNotFoundError( $curfile );
220 $oldver = wfTimestampNow() . "!{$name}";
221 $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
222 wfStrencode( $oldimage ) . "'" );
224 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
225 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
228 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
229 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
231 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
233 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
234 $wgOut->setRobotpolicy( "noindex,nofollow" );
235 $wgOut->addHTML( wfMsg( "imagereverted" ) );
236 $wgOut->returnToMain( false );