Extension:UploadLocal

Special:UploadLocal is a special page written by User:Ambush Commander that allows the "hooking in" of files residing on the server into MediaWiki. This has numerous practical applications, notably the streamlining of the upload of large files, renaming of image files, and the upload of many files (aka. mass upload).

Installation
There are two files, both confusingly named. The one that has the comment  goes inside your  directory, while the other goes in your directory.

Create a folder called  in your extensions folder, and chmod it 777.

Then, in LocalSettings, add these lines:

It should be installed. There are a few more settings:

sets the absolute path for the directory where uploaded files reside, so you can set it to whatever you want. The default is:

Also, the extension adds a new right called  and a new user group, uploader, along with sysop, are allowed to use this extension. You can change this however you want, although remember, in order for the extension to be useful, the user must also have FTP access.

Using it
Upload files into the directory /extensions/uploadlocal of your wiki folder. Then surf to Special:UploadLocal and you should see the files you uploaded listed there. Follow the instructions.

Known bugs
The result page will randomnly spit out stuff you inserted in the summary. This is largely unavoidable due to the nature of the extension (aka: it is a hack).

Also, files with single quotes in their names will not be renamed or given summaries unless magic_quotes is off or the patch is applied. Patching stuff is as easy as executing the command:

patch -p0 < Magic_quotes_2.patch

from the directory where MediaWiki is installed (but you need shell). I haven't made a drop-dead easy installation script yet.

License
Special:UploadLocal, a special page for MediaWiki Copyright (C) 2006 Edward Z. Yang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Code
I will make a tarball available soon. Make sure you verify that no one has been twiddling with the code before you copy and paste.

extension/SpecialUploadLocal.php
."'	  ,'uploadednolocalfiles' => 'You did not upload any files.'	   ,'allfilessuccessful' => 'All files uploaded successfully'	   ,'uploadlocalerrors' => 'Some files had errors'	   ,'allfilessuccessfultext' => 'All files uploaded successfully. Return to'.	       ' Main Page.'	   ,'uploadlocal_descriptions_append' => 'Append to description: '	   ,'uploadlocal_descriptions_prepend' => 'Prepend to description: '	   ,'uploadlocal_dest_file_append' => 'Append to dest. filename: '	   ,'uploadlocal_dest_file_prepend' => 'Prepend to dest. filename: '	   ,'uploadlocal_file_list' => 'Files ready for upload'	   ,'uploadlocal_file_list_explanation' => '\'\'\'X\'\'\' indicates'.	       ' whether or not you want the file to be uploaded (uncheck to'.	       ' prevent a file from being processed). \'\'\'W\'\'\' indicates'.	       ' whether you want the file added to your watchlist.'	   ,'uploadlocal_global_params' => 'Global parameters' ,'uploadlocal_global_params_explanation' => 'What is entered here will'. ' automatically get added to the entries listed above. This helps'. ' remove repetitive text such as categories and metadata. To \'\'\''. 'append\'\'\' is to add to the end of text, while to \'\'\'prepend'. '\'\'\' means to add to the beginning of text. Especially for'. ' descriptions, make sure you give a few linebreaks before/after'. ' the text.' );	$wgMessageCache->addMessages($messages);   SpecialPage::addPage( new SpecialPage( 'UploadLocal', 'uploadlocal' ) ); }

$wgUploadLocalDirectory = $IP. '/extensions/uploadlocal';

$wgAvailableRights[] = 'uploadlocal'; $wgGroupPermissions['uploader']['uploadlocal'] = true; $wgGroupPermissions['sysop']  ['uploadlocal'] = true;

?>

includes/SpecialUploadLocal.php
';       $wgOut->addHTML($html); $wgOut->addWikitext('==' . wfMsg('uploadlocal_global_params') . '=='); $wgOut->addWikitext(wfMsg('uploadlocal_global_params_explanation')); $html = ''; $html .= ' '; $html .= ' '; $wgOut->addHTML($html); }   function getFilenamesOfFilesInDirectory($directory) { if (!is_dir($directory)) return array; if ($directory[strlen($directory)-1] !== '/') $directory .= '/'; $dh = opendir($directory); $filenames = array; while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') continue; // check if it's a directory if (is_dir($directory. $file)) continue; // check if it's a hidden file - regexp: /\.[^.]+/ if ($file[0] == '.' && strpos($file,'.',1) === false) { continue; }           $filenames[] = $file; }       closedir($dh); return $filenames; }   function processUploads($request) { global $wgOut, $wgContLang; $r_files       = $request->getArray('wpUploadFiles', array); $r_descriptions = $request->getArray('wpUploadDescriptions', array); $r_watch_these = $request->getArray('wpWatchThese', array); $r_dest_files  = $request->getArray('wpDestFiles', array); $r_descriptions_prepend = $request->getVal('wpUploadDescriptionsPrepend', ''); $r_descriptions_append = $request->getVal('wpUploadDescriptionsAppend', ''); $r_dest_files_prepend  = $request->getVal('wpDestFilesPrepend', ''); $r_dest_files_append   = $request->getVal('wpDestFilesAppend', ''); $files_to_process = array; $forms = array; foreach ($r_files as $file) { if (!in_array($file, $this->_available_files)) continue; // this is really convoluted // also, we'd like the appending for filenames to be smart and // come before the period, otherwise it's pretty useless $forms[] =& new UploadLocalForm(              $file,               $r_descriptions_prepend . (isset($r_descriptions[$file]) ? $r_descriptions[$file] : '') . $r_descriptions_append,              in_array($file, $r_watch_these),               $r_dest_files_prepend . (isset($r_dest_files[$file]) ? $r_dest_files[$file] : $file) . $r_dest_files_append           ); }       if (empty($forms)) { $wgOut->addWikitext( wfMsg( 'uploadednolocalfiles' ) ); return; }       $no_error = true; $errors = array; foreach($forms as $key => $value) { $forms[$key]->processUpload; if ($forms[$key]->getError) { $errors[$forms[$key]->getFilename] = $forms[$key]->getError; unset($forms[$key]); }       }        //ugly hack to stop the thing from redirecting. Really annoying. $wgOut->redirect(''); if (empty($errors)) { $wgOut->setPageTitle(wfMsg('allfilessuccessful')); $wgOut->addWikitext(wfMsg('allfilessuccessfultext')); } else { $wgOut->setPageTitle(wfMsg('uploadlocalerrors')); $wgOut->addHTML(''); foreach ($errors as $name => $error) { $wgOut->addHTML(''.$name.' - '.$error.''); }           $wgOut->addHTML(''); }       $links_to_images = ''; foreach($forms as $key => $form) { // language-neutral namespacing thanks to Eric Lemoine $links_to_images .= '* '.$wgContLang->getNsText( NS_IMAGE ).':'.$forms[$key]->getUploadSaveName.''."\n"; }       $wgOut->addWikitext($links_to_images); } }

class UploadLocalForm extends UploadForm {   var $_error = ''; var $_filename; //overload form initialization: we're not dealing with any http uploads function UploadLocalForm($filename, $description, $watch, $dest) { global $wgUploadLocalDirectory; $this->_filename = $filename; $directory = $wgUploadLocalDirectory; if ($directory[strlen($directory)-1] !== '/') $directory .= '/'; $this->mUploadTempName = $directory. $filename; // there is no "real" old name, as it's already on the server $this->mOname = $directory. $filename; $this->mUploadSize = filesize($this->mUploadTempName); $this->mDestFile = $dest; // should check every time, since there are no fresh/stale uploads $this->mStashed = false; $this->mIgnoreWarning = true; //ignore warnings... don't wanna deal with 'em                                     //however, this attitude means that it's                                      //extremely easy to accidently overwrite //files. Solution? $this->mSessionKey = true; //makes it think that it is locally stored $this->mUploadDescription = $description; $this->mUploadCopyStatus = ''; //not supported yet $this->mUploadSource = ''; //not supported yet $this->mWatchthis = $watch; }   function getFilename {return $this->_filename;} function getUploadSaveName {return $this->mUploadSaveName;} function mainUploadForm($error) {$this->_error = $error;} function uploadError($error) {$this->_error = $error;} function showSuccess {} function getError {return $this->_error;} }

?>