3 function wfSpecialUpload()
5 global $wgUser, $wgOut, $wpUpload, $wpReUpload, $action;
7 $fields = array( "wpUploadFile", "wpUploadDescription" );
8 wfCleanFormFields( $fields );
10 if ( ( 0 == $wgUser->getID() )
11 or $wgUser->isBlocked() ) {
12 $wgOut->errorpage( "uploadnologin", "uploadnologintext" );
16 $wgOut->readOnlyPage();
19 if ( isset( $wpReUpload) ) {
22 } else if ( "submit" == $action ||
isset( $wpUpload ) ) {
29 function processUpload()
31 global $wgUser, $wgOut, $wgLang, $wpUploadAffirm, $wpUploadFile;
32 global $wpUploadDescription, $wpIgnoreWarning;
33 global $HTTP_POST_FILES, $wgUploadDirectory;
34 global $wpUploadSaveName, $wpUploadTempName, $wpUploadSize;
35 global $wgSavedFile, $wgUploadOldVersion, $wpUploadOldVersion;
37 if ( 1 != $wpUploadAffirm ) {
38 mainUploadForm( WfMsg( "noaffirmation" ) );
41 if ( ! $wpUploadTempName ) {
42 $wpUploadTempName = $HTTP_POST_FILES['wpUploadFile']['tmp_name'];
44 if ( ! $wpUploadSize ) {
45 $wpUploadSize = $HTTP_POST_FILES['wpUploadFile']['size'];
47 $prev = error_reporting( E_ALL
& ~
( E_NOTICE | E_WARNING
) );
48 $oname = wfCleanQueryVar( $HTTP_POST_FILES['wpUploadFile']['name'] );
49 if ( $wpUploadSaveName != "" ) $wpUploadSaveName = wfCleanQueryVar( $wpUploadSaveName );
50 error_reporting( $prev );
53 $basename = strrchr( $oname, "/" );
54 if ( false === $basename ) { $basename = $oname; }
55 else ( $basename = substr( $basename, 1 ) );
57 $ext = strrchr( $basename, "." );
58 if ( false === $ext ) { $ext = ""; }
59 else { $ext = substr( $ext, 1 ); }
61 if ( "" == $ext ) { $xl = 0; } else { $xl = strlen( $ext ) +
1; }
62 $partname = substr( $basename, 0, strlen( $basename ) - $xl );
64 if ( strlen( $partname ) < 3 ) {
65 mainUploadForm( WfMsg( "minlength" ) );
68 $nt = Title
::newFromText( $basename );
69 $wpUploadSaveName = $nt->getDBkey();
72 if ( ( ! $wpIgnoreWarning ) &&
73 ( 0 != strcmp( ucfirst( $basename ), $wpUploadSaveName ) ) ) {
74 $warn = str_replace( "$1", $wpUploadSaveName,
75 wfMsg( "badfilename" ) );
76 return uploadWarning( $warn );
78 $extensions = array( "png", "jpg", "jpeg", "ogg" );
79 if ( ( ! $wpIgnoreWarning ) &&
80 ( ! in_array( strtolower( $ext ), $extensions ) ) ) {
81 $warn = str_replace( "$1", $ext, wfMsg( "badfiletype" ) );
82 return uploadWarning( $warn );
84 if ( ( ! $wpIgnoreWarning ) && ( $wpUploadSize > 150000 ) ) {
85 return uploadWarning( WfMsg( "largefile" ) );
88 if ( isset( $wpUploadOldVersion ) ) {
89 $wgUploadOldVersion = $wpUploadOldVersion;
91 wfRecordUpload( $wpUploadSaveName, $wgUploadOldVersion,
92 $wpUploadSize, $wpUploadDescription );
94 $sk = $wgUser->getSkin();
95 $ilink = $sk->makeMediaLink( $wpUploadSaveName, wfImageUrl(
96 $wpUploadSaveName ) );
97 $dname = $wgLang->getNsText( Namespace::getImage() ) . ":{$wpUploadSaveName}";
98 $dlink = $sk->makeKnownLink( $dname, $dname );
100 $wgOut->addHTML( "<h2>" . wfMsg( "successfulupload" ) . "</h2>\n" );
101 $text = str_replace( "$1", $ilink, wfMsg( "fileuploaded" ) );
102 $text = str_replace( "$2", $dlink, $text );
103 $wgOut->addHTML( "<p>{$text}\n" );
104 $wgOut->returnToMain( false );
107 function saveUploadedFile()
109 global $wpUploadSaveName, $wpUploadTempName;
110 global $wgSavedFile, $wgUploadOldVersion;
111 global $wgUploadDirectory, $wgOut;
113 $dest = wfImageDir( $wpUploadSaveName );
114 $archive = wfImageArchiveDir( $wpUploadSaveName );
115 $wgSavedFile = "{$dest}/{$wpUploadSaveName}";
117 if ( is_file( $wgSavedFile ) ) {
118 $wgUploadOldVersion = gmdate( "YmdHis" ) . "!{$wpUploadSaveName}";
120 if ( ! rename( $wgSavedFile, "${archive}/{$wgUploadOldVersion}" ) ) {
121 $wgOut->fileRenameError( $wgSavedFile,
122 "${archive}/{$wgUploadOldVersion}" );
126 $wgUploadOldVersion = "";
128 if ( ! move_uploaded_file( $wpUploadTempName, $wgSavedFile ) ) {
129 $wgOut->fileCopyError( $wpUploadTempName, $wgSavedFile );
131 chmod( $wgSavedFile, 0644 );
134 function unsaveUploadedFile()
136 global $wgSavedFile, $wgUploadOldVersion;
137 global $wpSavedFile, $wpUploadOldVersion;
138 global $wgUploadDirectory, $wgOut;
140 $wgSavedFile = $wpSavedFile;
141 $wgUploadOldVersion = $wpUploadOldVersion;
143 if ( ! unlink( $wgSavedFile ) ) {
144 $wgOut->fileDeleteError( $wgSavedFile );
147 if ( "" != $wgUploadOldVersion ) {
148 $hash = md5( substr( $wgUploadOldVersion, 15 ) );
149 $archive = "{$wgUploadDirectory}/archive/" . $hash{0} .
150 "/" . substr( $hash, 0, 2 );
152 if ( ! rename( "{$archive}/{$wgUploadOldVersion}", $wgSavedFile ) ) {
153 $wgOut->fileRenameError( "{$archive}/{$wgUploadOldVersion}",
159 function uploadWarning( $warning )
161 global $wgOut, $wgUser, $wgLang, $wgUploadDirectory;
162 global $wpUpload, $wpReUpload, $wpUploadAffirm, $wpUploadFile;
163 global $wpUploadDescription, $wpIgnoreWarning;
164 global $wpUploadSaveName, $wpUploadTempName, $wpUploadSize;
165 global $wgSavedFile, $wgUploadOldVersion;
166 global $wpSavedFile, $wpUploadOldVersion;
168 $sub = wfMsg( "uploadwarning" );
169 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
170 $wgOut->addHTML( "<h4><font color=red>{$warning}</font></h4>\n" );
172 $save = wfMsg( "savefile" );
173 $reupload = wfMsg( "reupload" );
174 $iw = wfMsg( "ignorewarning" );
175 $reup = wfMsg( "reuploaddesc" );
176 $action = wfLocalUrlE( $wgLang->specialPage( "Upload" ),
180 <form id=\"uploadwarning\" method=\"post\" enctype=\"multipart/form-data\"
181 action=\"{$action}\">
182 <input type=hidden name=\"wpUploadAffirm\" value=\"1\">
183 <input type=hidden name=\"wpIgnoreWarning\" value=\"1\">
184 <input type=hidden name=\"wpUploadDescription\" value=\"" . htmlspecialchars( $wpUploadDescription ) . "\">
185 <input type=hidden name=\"wpUploadSaveName\" value=\"" . htmlspecialchars( $wpUploadSaveName ) . "\">
186 <input type=hidden name=\"wpUploadTempName\" value=\"" . htmlspecialchars( $wpUploadTempName ) . "\">
187 <input type=hidden name=\"wpUploadSize\" value=\"" . htmlspecialchars( $wpUploadSize ) . "\">
188 <input type=hidden name=\"wpSavedFile\" value=\"" . htmlspecialchars( $wgSavedFile ) . "\">
189 <input type=hidden name=\"wpUploadOldVersion\" value=\"" . htmlspecialchars( $wgUploadOldVersion) . "\">
192 <input tabindex=2 type=submit name=\"wpUpload\" value=\"{$save}\">
193 </td><td align=left>{$iw}</td></tr>
195 <input tabindex=2 type=submit name=\"wpReUpload\" value=\"{$reupload}\">
196 </td><td align=left>{$reup}</td></tr></table></form>\n" );
199 function mainUploadForm( $msg )
201 global $wgOut, $wgUser, $wgLang, $wgUploadDirectory;
202 global $wpUpload, $wpUploadAffirm, $wpUploadFile;
203 global $wpUploadDescription, $wpIgnoreWarning;
206 $sub = wfMsg( "uploaderror" );
207 $wgOut->addHTML( "<h2>{$sub}</h2>\n" .
208 "<h4><font color=red>{$msg}</font></h4>\n" );
210 $sub = wfMsg( "uploadfile" );
211 $wgOut->addHTML( "<h2>{$sub}</h2>\n" );
213 $wgOut->addHTML( "<p>" . wfMsg( "uploadtext" ) );
214 $sk = $wgUser->getSkin();
216 $fn = wfMsg( "filename" );
217 $fd = wfMsg( "filedesc" );
218 $ulb = wfMsg( "uploadbtn" );
220 $clink = $sk->makeKnownLink( wfMsg( "copyrightpage" ),
221 wfMsg( "copyrightpagename" ) );
222 $ca = str_replace( "$1", $clink, wfMsg( "affirmation" ) );
223 $iw = wfMsg( "ignorewarning" );
225 $action = wfLocalUrl( $wgLang->specialPage( "Upload" ) );
227 <form id=\"upload\" method=\"post\" enctype=\"multipart/form-data\"
228 action=\"{$action}\">
230 <td align=right>{$fn}:</td><td align=left>
231 <input tabindex=1 type=file name=\"wpUploadFile\" value=\""
232 . htmlspecialchars( $wpUploadFile ) . "\" size=40>
234 <td align=right>{$fd}:</td><td align=left>
235 <input tabindex=2 type=text name=\"wpUploadDescription\" value=\""
236 . htmlspecialchars( $wpUploadDescription ) . "\" size=40>
239 <input tabindex=3 type=checkbox name=\"wpUploadAffirm\" value=\"1\" id=\"wpUploadAffirm\">
240 </td><td align=left><label for=\"wpUploadAffirm\">{$ca}</label></td></tr>
241 <tr><td> </td><td align=left>
242 <input tabindex=5 type=submit name=\"wpUpload\" value=\"{$ulb}\">
243 </td></tr></table></form>\n" );