specialupload.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 1,110 行 · 第 1/3 页
PHP
1,110 行
$archive = wfImageArchiveDir( $saveName ); if ( !is_dir( $dest ) ) wfMkdirParents( $dest ); if ( !is_dir( $archive ) ) wfMkdirParents( $archive ); $this->mSavedFile = "{$dest}/{$saveName}"; if( is_file( $this->mSavedFile ) ) { $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; wfSuppressWarnings(); $success = rename( $this->mSavedFile, "${archive}/{$this->mUploadOldVersion}" ); wfRestoreWarnings(); if( ! $success ) { $wgOut->showFileRenameError( $this->mSavedFile, "${archive}/{$this->mUploadOldVersion}" ); return false; } else wfDebug("$fname: moved file ".$this->mSavedFile." to ${archive}/{$this->mUploadOldVersion}\n"); } else { $this->mUploadOldVersion = ''; } wfSuppressWarnings(); $success = $useRename ? rename( $tempName, $this->mSavedFile ) : move_uploaded_file( $tempName, $this->mSavedFile ); wfRestoreWarnings(); if( ! $success ) { $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); return false; } else { wfDebug("$fname: wrote tempfile $tempName to ".$this->mSavedFile."\n"); } chmod( $this->mSavedFile, 0644 ); return true; } /** * Stash a file in a temporary directory for later processing * after the user has confirmed it. * * If the user doesn't explicitly cancel or accept, these files * can accumulate in the temp directory. * * @param string $saveName - the destination filename * @param string $tempName - the source temporary file to save * @return string - full path the stashed file, or false on failure * @access private */ function saveTempUploadedFile( $saveName, $tempName ) { global $wgOut; $archive = wfImageArchiveDir( $saveName, 'temp' ); if ( !is_dir ( $archive ) ) wfMkdirParents( $archive ); $stash = $archive . '/' . gmdate( "YmdHis" ) . '!' . $saveName; $success = $this->mRemoveTempFile ? rename( $tempName, $stash ) : move_uploaded_file( $tempName, $stash ); if ( !$success ) { $wgOut->showFileCopyError( $tempName, $stash ); return false; } return $stash; } /** * Stash a file in a temporary directory for later processing, * and save the necessary descriptive info into the session. * Returns a key value which will be passed through a form * to pick up the path info on a later invocation. * * @return int * @access private */ function stashSession() { $stash = $this->saveTempUploadedFile( $this->mUploadSaveName, $this->mUploadTempName ); if( !$stash ) { # Couldn't save the file. return false; } $key = mt_rand( 0, 0x7fffffff ); $_SESSION['wsUploadData'][$key] = array( 'mUploadTempName' => $stash, 'mUploadSize' => $this->mUploadSize, 'mOname' => $this->mOname ); return $key; } /** * Remove a temporarily kept file stashed by saveTempUploadedFile(). * @access private * @return success */ function unsaveUploadedFile() { global $wgOut; wfSuppressWarnings(); $success = unlink( $this->mUploadTempName ); wfRestoreWarnings(); if ( ! $success ) { $wgOut->showFileDeleteError( $this->mUploadTempName ); return false; } else { return true; } } /* -------------------------------------------------------------- */ /** * Show some text and linkage on successful upload. * @access private */ function showSuccess() { global $wgUser, $wgOut, $wgContLang; $sk = $wgUser->getSkin(); $ilink = $sk->makeMediaLink( $this->mUploadSaveName, Image::imageUrl( $this->mUploadSaveName ) ); $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mUploadSaveName; $dlink = $sk->makeKnownLink( $dname, $dname ); $wgOut->addHTML( '<h2>' . wfMsgHtml( 'successfulupload' ) . "</h2>\n" ); $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink ); $wgOut->addHTML( $text ); $wgOut->returnToMain( false ); } /** * @param string $error as HTML * @access private */ function uploadError( $error ) { global $wgOut; $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" ); $wgOut->addHTML( "<span class='error'>{$error}</span>\n" ); } /** * There's something wrong with this file, not enough to reject it * totally but we require manual intervention to save it for real. * Stash it away, then present a form asking to confirm or cancel. * * @param string $warning as HTML * @access private */ function uploadWarning( $warning ) { global $wgOut; global $wgUseCopyrightUpload; $this->mSessionKey = $this->stashSession(); if( !$this->mSessionKey ) { # Couldn't save file; an error has been displayed so let's go. return; } $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" ); $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br />\n" ); $save = wfMsgHtml( 'savefile' ); $reupload = wfMsgHtml( 'reupload' ); $iw = wfMsgWikiHtml( 'ignorewarning' ); $reup = wfMsgWikiHtml( 'reuploaddesc' ); $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' ); $action = $titleObj->escapeLocalURL( 'action=submit' ); if ( $wgUseCopyrightUpload ) { $copyright = " <input type='hidden' name='wpUploadCopyStatus' value=\"" . htmlspecialchars( $this->mUploadCopyStatus ) . "\" /> <input type='hidden' name='wpUploadSource' value=\"" . htmlspecialchars( $this->mUploadSource ) . "\" /> "; } else { $copyright = ""; } $wgOut->addHTML( " <form id='uploadwarning' method='post' enctype='multipart/form-data' action='$action'> <input type='hidden' name='wpIgnoreWarning' value='1' /> <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" /> <input type='hidden' name='wpUploadDescription' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" /> <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" /> <input type='hidden' name='wpDestFile' value=\"" . htmlspecialchars( $this->mDestFile ) . "\" /> <input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" /> {$copyright} <table border='0'> <tr> <tr> <td align='right'> <input tabindex='2' type='submit' name='wpUpload' value=\"$save\" /> </td> <td align='left'>$iw</td> </tr> <tr> <td align='right'> <input tabindex='2' type='submit' name='wpReUpload' value=\"{$reupload}\" /> </td> <td align='left'>$reup</td> </tr> </tr> </table></form>\n" ); } /** * Displays the main upload form, optionally with a highlighted * error message up at the top. * * @param string $msg as HTML * @access private */ function mainUploadForm( $msg='' ) { global $wgOut, $wgUser; global $wgUseCopyrightUpload; $cols = intval($wgUser->getOption( 'cols' )); $ew = $wgUser->getOption( 'editwidth' ); if ( $ew ) $ew = " style=\"width:100%\""; else $ew = ''; if ( '' != $msg ) { $sub = wfMsgHtml( 'uploaderror' ); $wgOut->addHTML( "<h2>{$sub}</h2>\n" . "<span class='error'>{$msg}</span>\n" ); } $wgOut->addHTML( '<div id="uploadtext">' ); $wgOut->addWikiText( wfMsg( 'uploadtext' ) ); $wgOut->addHTML( '</div>' ); $sk = $wgUser->getSkin(); $sourcefilename = wfMsgHtml( 'sourcefilename' ); $destfilename = wfMsgHtml( 'destfilename' ); $summary = wfMsgWikiHtml( 'fileuploadsummary' ); $licenses = new Licenses(); $license = wfMsgHtml( 'license' ); $nolicense = wfMsgHtml( 'nolicense' ); $licenseshtml = $licenses->getHtml(); $ulb = wfMsgHtml( 'uploadbtn' ); $titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' ); $action = $titleObj->escapeLocalURL(); $encDestFile = htmlspecialchars( $this->mDestFile ); $watchChecked = $wgUser->getOption( 'watchdefault' ) ? 'checked="checked"' : ''; $wgOut->addHTML( " <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\"> <table border='0'> <tr> <td align='right'><label for='wpUploadFile'>{$sourcefilename}:</label></td> <td align='left'> <input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . ($this->mDestFile?"":"onchange='fillDestFilename()' ") . "size='40' /> </td> </tr> <tr> <td align='right'><label for='wpDestFile'>{$destfilename}:</label></td> <td align='left'> <input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" /> </td> </tr> <tr> <td align='right'><label for='wpUploadDescription'>{$summary}</label></td> <td align='left'> <textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" . htmlspecialchars( $this->mUploadDescription ) . "</textarea> </td> </tr> <tr>" ); if ( $licenseshtml != '' ) { global $wgStylePath; $wgOut->addHTML( " <td align='right'><label for='wpLicense'>$license:</label></td> <td align='left'> <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script> <select name='wpLicense' id='wpLicense' tabindex='4' onchange='licenseSelectorCheck()'> <option value=''>$nolicense</option> $licenseshtml </select> </td> </tr> <tr> "); } if ( $wgUseCopyrightUpload ) { $filestatus = wfMsgHtml ( 'filestatus' ); $copystatus = htmlspecialchars( $this->mUploadCopyStatus ); $filesource = wfMsgHtml ( 'filesource' ); $uploadsource = htmlspecialchars( $this->mUploadSource ); $wgOut->addHTML( " <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td> <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td> </tr> <tr> <td align='right'><label for='wpUploadCopyStatus'>$filesource:</label></td> <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td> </tr> <tr> "); } $wgOut->addHtml( " <td></td> <td> <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' /> <label for='wpWatchthis'>" . wfMsgHtml( 'watchthis' ) . "</label> <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' /> <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label> </td> </tr> <tr> </tr> <tr> <td></td> <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td> </tr> <tr> <td></td> <td align='left'> " ); $wgOut->addWikiText( wfMsgForContent( 'edittools' ) ); $wgOut->addHTML( " </td> </tr> </table> </form>" ); } /* -------------------------------------------------------------- */ /** * Split a file into a base name and all dot-delimited 'extensions' * on the end. Some web server configurations will fall back to * earlier pseudo-'extensions' to determine type and execute * scripts, so the blacklist needs to check them all. * * @return array */ function splitExtensions( $filename ) { $bits = explode( '.', $filename ); $basename = array_shift( $bits ); return array( $basename, $bits ); } /** * Perform case-insensitive match against a list of file extensions. * Returns true if the extension is in the list. * * @param string $ext * @param array $list * @return bool */ function checkFileExtension( $ext, $list ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?