00001 <?php
00002
00003
00004
00005
00006
00007 class ImagePage extends Article {
00008
00009 var
$img;
00010
00011
00012 function
view() {
00013
if (
Namespace::getImage() == $this->mTitle->getNamespace() ) {
00014 $this->
openShowImage();
00015 }
00016
00017 Article::view();
00018
00019
# If the article we've just shown is in the "Image" namespace,
00020
# follow it with the history list and link list for the image
00021
# it describes.
00022
00023
if (
Namespace::getImage() == $this->mTitle->getNamespace() ) {
00024 $this->
closeShowImage();
00025 $this->
imageHistory();
00026 $this->
imageLinks();
00027 }
00028 }
00029
00030 function
openShowImage()
00031 {
00032 global
$wgOut,
$wgUser,
$wgRequest;
00033 $this->img = Image::newFromTitle( $this->mTitle );
00034
$url = $this->img->getUrl();
00035
00036
if ( $this->img->exists() ) {
00037
00038 $sk =
$wgUser->getSkin();
00039
00040
if ( $this->img->getType() !=
"" ) {
00041
# image
00042
$s =
"<div class=\"fullImage\">" .
00043
"<img src=\"{$url}\" width=\"" . $this->img->getWidth() .
"\" height=\"" . $this->img->getHeight() .
00044
"\" alt=\"".$wgRequest->getVal( 'image' ).
"\" /></div>";
00045 }
else {
00046
$s =
"<div class=\"fullMedia\">".$sk->makeMediaLink($this->img->getName(),
"").
"</div>";
00047 }
00048
$wgOut->addHTML( $s );
00049 }
00050 }
00051
00052 function
closeShowImage()
00053 {
00054
# For overloading
00055
}
00056
00057
# If the page we've just displayed is in the "Image" namespace,
00058
# we follow it with an upload history of the image and its usage.
00059
00060 function
imageHistory()
00061 {
00062 global
$wgUser,
$wgOut;
00063
00064 $sk =
$wgUser->getSkin();
00065
$s = $sk->beginImageHistoryList();
00066
00067
$line = $this->img->nextHistoryLine();
00068
00069
$s .= $sk->imageHistoryLine(
true, $line->img_timestamp,
00070 $this->mTitle->getDBkey(),
$line->img_user,
00071
$line->img_user_text,
$line->img_size,
$line->img_description );
00072
00073
while (
$line = $this->img->nextHistoryLine() ) {
00074
$s .= $sk->imageHistoryLine(
false, $line->img_timestamp,
00075 $line->oi_archive_name, $line->img_user,
00076 $line->img_user_text, $line->img_size, $line->img_description );
00077 }
00078
$s .= $sk->endImageHistoryList();
00079
$wgOut->addHTML( $s );
00080 }
00081
00082 function
imageLinks()
00083 {
00084 global
$wgUser,
$wgOut;
00085
00086
$wgOut->addHTML(
"<h2>" .
wfMsg(
"imagelinks" ) .
"</h2>\n" );
00087
00088
$sql =
"SELECT cur_namespace,cur_title FROM imagelinks,cur WHERE il_to='" .
00089
wfStrencode( $this->mTitle->getDBkey() ) .
"' AND il_from=cur_id";
00090
$res =
wfQuery( $sql,
DB_READ,
"Article::imageLinks" );
00091
00092
if ( 0 ==
wfNumRows( $res ) ) {
00093
$wgOut->addHtml(
"<p>" .
wfMsg(
"nolinkstoimage" ) .
"</p>\n" );
00094
return;
00095 }
00096
$wgOut->addHTML(
"<p>" .
wfMsg(
"linkstoimage" ) .
"</p>\n<ul>" );
00097
00098 $sk =
$wgUser->getSkin();
00099
while (
$s =
wfFetchObject( $res ) ) {
00100 $name = Title::MakeTitle( $s->cur_namespace, $s->cur_title );
00101 $link = $sk->makeKnownLinkObj( $
name,
"" );
00102
$wgOut->addHTML(
"<li>{$link}</li>\n" );
00103 }
00104
$wgOut->addHTML(
"</ul>\n" );
00105 }
00106
00107 function
delete()
00108 {
00109 global
$wgUser,
$wgOut,
$wgRequest;
00110
00111 $confirm =
$wgRequest->getBool( 'wpConfirm' );
00112 $image =
$wgRequest->getVal( 'image' );
00113 $oldimage =
$wgRequest->getVal( 'oldimage' );
00114
00115
# Only sysops can delete images. Previously ordinary users could delete
00116
# old revisions, but this is no longer the case.
00117
if ( !
$wgUser->isSysop() ) {
00118
$wgOut->sysopRequired();
00119
return;
00120 }
00121
if (
wfReadOnly() ) {
00122
$wgOut->readOnlyPage();
00123
return;
00124 }
00125
00126
# Better double-check that it hasn't been deleted yet!
00127
$wgOut->setPagetitle(
wfMsg(
"confirmdelete" ) );
00128
if ( !is_null( $image ) ) {
00129
if (
"" == trim( $image ) ) {
00130
$wgOut->fatalError(
wfMsg(
"cannotdelete" ) );
00131
return;
00132 }
00133 }
00134
00135
# Deleting old images doesn't require confirmation
00136
if ( !is_null( $oldimage ) || $confirm ) {
00137 $this->
doDelete();
00138
return;
00139 }
00140
00141
if ( !is_null( $image ) ) {
00142 $q =
"&image=" . urlencode( $image );
00143 }
else if ( !is_null( $oldimage ) ) {
00144 $q =
"&oldimage=" . urlencode( $oldimage );
00145 }
else {
00146 $q =
"";
00147 }
00148
return $this->confirmDelete( $q, $wgRequest->getText( 'wpReason' ) );
00149 }
00150
00151 function
doDelete()
00152 {
00153 global
$wgOut,
$wgUser,
$wgLang,
$wgRequest;
00154 global
$wgUseSquid,
$wgInternalServer,
$wgDeferredUpdateList;
00155 $fname =
"Article::doDelete";
00156
00157 $reason =
$wgRequest->getVal( 'wpReason' );
00158 $image =
$wgRequest->getVal( 'image' );
00159 $oldimage =
$wgRequest->getVal( 'oldimage' );
00160
00161
if ( !is_null( $image ) ) {
00162 $dest =
wfImageDir( $image );
00163 $archive =
wfImageDir( $image );
00164
if ( ! @unlink(
"{$dest}/{$image}" ) ) {
00165
$wgOut->fileDeleteError(
"{$dest}/{$image}" );
00166
return;
00167 }
00168
$sql =
"DELETE FROM image WHERE img_name='" .
00169
wfStrencode( $image ) .
"'";
00170
wfQuery( $sql,
DB_WRITE, $fname );
00171
00172
$sql =
"SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
00173
wfStrencode( $image ) .
"'";
00174
$res =
wfQuery( $sql,
DB_READ, $fname );
00175
00176
# Squid purging
00177
if (
$wgUseSquid ) {
00178 $urlArr = Array(
00179 $wgInternalServer . Image::wfImageUrl( $image )
00180 );
00181
wfPurgeSquidServers($urlArr);
00182 }
00183
00184
00185 $urlArr = Array();
00186
while (
$s =
wfFetchObject( $res ) ) {
00187 $this->
doDeleteOldImage( $s->oi_archive_name );
00188 $urlArr[] =
$wgInternalServer.wfImageArchiveUrl( $s->oi_archive_name );
00189 }
00190
00191
# Squid purging, part II
00192
if (
$wgUseSquid ) {
00193
00194 $u =
new SquidUpdate( $urlArr );
00195 array_push( $wgDeferredUpdateList, $u );
00196 }
00197
00198
$sql =
"DELETE FROM oldimage WHERE oi_name='" .
00199
wfStrencode( $image ) .
"'";
00200
wfQuery( $sql,
DB_WRITE, $fname );
00201
00202
# Image itself is now gone, and database is cleaned.
00203
# Now we remove the image description page.
00204
00205 $nt = Title::newFromText( $wgLang->getNsText( Namespace::getImage() ) .
":" . $image );
00206 $article =
new Article( $nt );
00207 $article->doDeleteArticle( $reason ); # ignore errors
00208
00209 $deleted = $image;
00210 }
else if ( !is_null( $oldimage ) ) {
00211
# Squid purging
00212
if (
$wgUseSquid ) {
00213 $urlArr = Array(
00214 $wgInternalServer.wfImageArchiveUrl( $oldimage )
00215 );
00216
wfPurgeSquidServers($urlArr);
00217 }
00218 $this->
doDeleteOldImage( $oldimage );
00219
$sql =
"DELETE FROM oldimage WHERE oi_archive_name='" .
00220
wfStrencode( $oldimage ) .
"'";
00221
wfQuery( $sql,
DB_WRITE, $fname );
00222
00223 $deleted = $oldimage;
00224 }
else {
00225 $this->doDeleteArticle( $reason ); # ignore errors
00226 $deleted = $this->mTitle->getPrefixedText();
00227 }
00228
$wgOut->setPagetitle(
wfMsg(
"actioncomplete" ) );
00229
$wgOut->setRobotpolicy(
"noindex,nofollow" );
00230
00231 $sk =
$wgUser->getSkin();
00232 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
00233 Namespace::getWikipedia() ) .
00234
":" .
wfMsg(
"dellogpage" ),
wfMsg(
"deletionlog" ) );
00235
00236 $text =
wfMsg(
"deletedtext", $deleted, $loglink );
00237
00238
$wgOut->addHTML(
"<p>" . $text .
"</p>\n" );
00239
$wgOut->returnToMain(
false );
00240 }
00241
00242 function
doDeleteOldImage( $oldimage )
00243 {
00244 global
$wgOut;
00245
00246 $name = substr( $oldimage, 15 );
00247 $archive =
wfImageArchiveDir( $
name );
00248
if ( ! unlink(
"{$archive}/{$oldimage}" ) ) {
00249
$wgOut->fileDeleteError(
"{$archive}/{$oldimage}" );
00250 }
00251 }
00252
00253 function
revert()
00254 {
00255 global
$wgOut,
$wgRequest;
00256 global
$wgUseSquid,
$wgInternalServer,
$wgDeferredUpdateList;
00257
00258 $oldimage =
$wgRequest->getText( 'oldimage' );
00259
00260
if ( strlen( $oldimage ) < 16 ) {
00261
$wgOut->unexpectedValueError(
"oldimage", $oldimage );
00262
return;
00263 }
00264
if (
wfReadOnly() ) {
00265
$wgOut->readOnlyPage();
00266
return;
00267 }
00268 $name = substr( $oldimage, 15 );
00269
00270 $dest =
wfImageDir( $
name );
00271 $archive =
wfImageArchiveDir( $
name );
00272 $curfile =
"{$dest}/{$name}";
00273
00274
if ( ! is_file( $curfile ) ) {
00275
$wgOut->fileNotFoundError( $curfile );
00276
return;
00277 }
00278 $oldver =
wfTimestampNow() .
"!{$name}";
00279 $size =
wfGetSQL(
"oldimage",
"oi_size",
"oi_archive_name='" .
00280
wfStrencode( $oldimage ) .
"'" );
00281
00282
if ( ! rename( $curfile,
"${archive}/{$oldver}" ) ) {
00283
$wgOut->fileRenameError( $curfile,
"${archive}/{$oldver}" );
00284
return;
00285 }
00286
if ( ! copy(
"{$archive}/{$oldimage}", $curfile ) ) {
00287
$wgOut->fileCopyError(
"${archive}/{$oldimage}", $curfile );
00288 }
00289
wfRecordUpload( $
name, $oldver, $size,
wfMsg(
"reverted" ) );
00290
# Squid purging
00291
if (
$wgUseSquid ) {
00292 $urlArr = Array(
00293 $wgInternalServer.wfImageArchiveUrl( $
name ),
00294
$wgInternalServer . Image::wfImageUrl( $
name )
00295 );
00296
wfPurgeSquidServers($urlArr);
00297 }
00298
00299
$wgOut->setPagetitle(
wfMsg(
"actioncomplete" ) );
00300
$wgOut->setRobotpolicy(
"noindex,nofollow" );
00301
$wgOut->addHTML(
wfMsg(
"imagereverted" ) );
00302
$wgOut->returnToMain(
false );
00303 }
00304 }
00305
00306 ?>