r44857 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44856‎ | r44857 | r44858 >
Date:19:31, 20 December 2008
Author:ashley
Status:deferred
Tags:
Comment:
MultiUpload:
*split up the classes and setup file
*doxygen tweaks
*move javascript to its own file
*make license selector work
*coding style tweaks
Modified paths:
  • /trunk/extensions/MultiUpload/SpecialMultipleUpload.body.php (added) (history)
  • /trunk/extensions/MultiUpload/SpecialMultipleUpload.i18n.php (modified) (history)
  • /trunk/extensions/MultiUpload/SpecialMultipleUpload.php (modified) (history)
  • /trunk/extensions/MultiUpload/multiupload.js (added) (history)

Diff [purge]

Index: trunk/extensions/MultiUpload/SpecialMultipleUpload.body.php
@@ -0,0 +1,399 @@
 2+<?php
 3+// Sanity check - check for MediaWiki environment...
 4+if( !defined( 'MEDIAWIKI' ) )
 5+ die( "This is an extension to the MediaWiki package and cannot be run standalone." );
 6+
 7+class MultipleUpload extends SpecialPage {
 8+
 9+ /**
 10+ * Constructor
 11+ */
 12+ public function __construct() {
 13+ parent::__construct( 'MultipleUpload'/*class*/, 'upload'/*restriction*/ );
 14+ }
 15+
 16+ /**
 17+ * Show the special page
 18+ *
 19+ * @param $par Mixed: parameter passed to the page or null
 20+ */
 21+ public function execute( $par ) {
 22+ global $wgRequest, $wgOut, $wgUser;
 23+ wfLoadExtensionMessages( 'MultiUpload' );
 24+ $this->setHeaders();
 25+
 26+ # Check permissions
 27+ if( !$wgUser->isAllowed( 'upload' ) ) {
 28+ $wgOut->permissionRequired( 'upload' );
 29+ return;
 30+ }
 31+
 32+ # Show a message if the database is in read-only mode
 33+ if ( wfReadOnly() ) {
 34+ $wgOut->readOnlyPage();
 35+ return;
 36+ }
 37+
 38+ # If user is blocked, s/he doesn't need to access this page
 39+ if ( $wgUser->isBlocked() ) {
 40+ $wgOut->blockedPage();
 41+ return;
 42+ }
 43+
 44+ $form = new MultipleUploadForm( $wgRequest );
 45+ $form->execute();
 46+ }
 47+}
 48+
 49+/**
 50+ * Main class
 51+ * @ingroup SpecialPage
 52+ */
 53+class MultipleUploadForm extends UploadForm {
 54+
 55+ // extra goodies
 56+ // access private
 57+ var $mUploadTempNameArray, $mUploadSizeArray, $mOnameArray, $mUploadError, $mDestFileArray;
 58+ var $mUploadDescriptionArray;
 59+ var $mShowUploadForm, $mHasWarning, $mFileIndex;
 60+
 61+ /**
 62+ * Constructor : initialise object
 63+ * Get data POSTed through the form and assign them to the object
 64+ * @param $request Data posted.
 65+ */
 66+ function MultipleUploadForm( &$request ) {
 67+ global $wgMaxUploadFiles;
 68+ // call the parent constructor
 69+ parent::UploadForm($request);
 70+
 71+ // initialize
 72+ $this->mUploadTempNameArray = $this->mUploadSizeArray = $this->mOnameArray = $this->mUploadError = $this->mDestFileArray = $this->mUploadDescriptionArray = array();
 73+ $this->mShowUploadForm = true;
 74+ $this->mFileIndex = 0;
 75+
 76+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) $this->mDestFileArray[$x] = $request->getText( "wpDestFile_$x" );
 77+
 78+ if( !$request->wasPosted() ) {
 79+ # GET requests just give the main form; no data except wpDestfile.
 80+ return;
 81+ }
 82+
 83+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) {
 84+ $this->mDestFile[$x] = $request->getText( "wpDestFile_$x" );
 85+ $this->mUploadDescriptionArray[$x] = $request->getText( "wpUploadDescription_$x" );
 86+ }
 87+ $this->mSessionKey = $request->getInt( 'wpSessionKey' );
 88+
 89+ if( !empty( $this->mSessionKey ) ) {
 90+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) {
 91+ //if (!isset($_SESSION["wsUploadData_$x"][$this->mSessionKey])) continue;
 92+ $data = $_SESSION["wsUploadData_$x"][$this->mSessionKey];
 93+ $this->mUploadTempNameArray[$x] = $data['mUploadTempName'];
 94+ $this->mUploadSizeArray[$x] = $data['mUploadSize'];
 95+ $this->mOnameArray[$x] = $data['mOname'];
 96+ }
 97+ } else {
 98+ /**
 99+ *Check for a newly uploaded file.
 100+ */
 101+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) {
 102+ $this->mUploadTempNameArray[$x] = $request->getFileTempName( "wpUploadFile_$x" );
 103+ $this->mUploadSizeArray [$x] = $request->getFileSize( "wpUploadFile_$x" );
 104+ $this->mOnameArray[$x] = $request->getFileName( "wpUploadFile_$x" );
 105+ $this->mUploadErrorArray[$x] = $request->getUploadError( "wpUploadFile_$x" );
 106+ $this->mUploadDescriptionArray [$x] = $request->getVal( "wpUploadDescription_$x" );
 107+ }
 108+ }
 109+
 110+ }
 111+
 112+ /**
 113+ * Really do the upload
 114+ * Checks are made in SpecialUpload::execute()
 115+ * @access private
 116+ */
 117+ function processUpload() {
 118+ global $wgMaxUploadFiles, $wgOut;
 119+
 120+ $wgOut->addHTML("<table>");
 121+ $this->mShowUploadForm = false;
 122+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) {
 123+ $this->mFileIndex = $x;
 124+ if( !isset( $this->mUploadTempNameArray[$x] ) || $this->mUploadTempNameArray[$x] == null ) continue;
 125+
 126+ $this->mTempPath = $this->mUploadTempNameArray[$x];
 127+ $this->mFileSize = $this->mUploadSizeArray[$x];
 128+ $this->mSrcName = $this->mOnameArray[$x]; // for mw > 1.9
 129+ $this->mRemoveTempFile = true;
 130+ $this->mIgnoreWarning = true;
 131+
 132+ $this->mUploadError = $this->mUploadErrorArray [$x];
 133+ $this->mDesiredDestName = $this->mDestFileArray [$x];
 134+ $this->mComment = $this->mUploadDescriptionArray [$x];
 135+ $wgOut->addHTML("<tr><td>");
 136+ parent::processUpload();
 137+ $wgOut->addHTML("</td></tr>");
 138+ }
 139+
 140+ $wgOut->addHTML("</table>");
 141+ $this->mShowUploadForm = false;
 142+ $wgOut->redirect(''); // clear the redirect, we want to show a nice page of images
 143+ $this->mShowUploadForm = true;
 144+ if( $this->mHasWarning ) {
 145+ $this->showWarningOptions();
 146+ }
 147+ }
 148+
 149+ /**
 150+ * Show some text and linkage on successful upload.
 151+ * @access private
 152+ */
 153+ function showSuccess() {
 154+ global $wgUser, $wgOut, $wgContLang;
 155+
 156+ $sk = $wgUser->getSkin();
 157+ $ilink = $sk->makeMediaLink( $this->mUploadSaveName, Image::imageUrl( $this->mUploadSaveName ) );
 158+ $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mUploadSaveName;
 159+ $dlink = $sk->makeKnownLink( $dname, $dname );
 160+
 161+ $wgOut->addWikiText( "[[$dname|left|thumb]]" );
 162+ $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink );
 163+ $wgOut->addHTML( $text );
 164+ }
 165+
 166+ /**
 167+ * @param string $error as HTML
 168+ * @access private
 169+ */
 170+ function uploadError( $error ) {
 171+ global $wgOut;
 172+ $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n" );
 173+ $wgOut->addHTML( "<span class='error'>{$error}</span>\n" );
 174+ }
 175+
 176+ /**
 177+ * There's something wrong with this file, not enough to reject it
 178+ * totally but we require manual intervention to save it for real.
 179+ * Stash it away, then present a form asking to confirm or cancel.
 180+ *
 181+ * @param string $warning as HTML
 182+ * @access private
 183+ */
 184+ function uploadWarning( $warning ) {
 185+ global $wgOut;
 186+
 187+ if( !$this->mHasWarning ) {
 188+ $titleObj = Title::makeTitle( NS_SPECIAL, 'MultipleUpload' );
 189+ $action = $titleObj->escapeLocalURL( 'action=submit' );
 190+ $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n
 191+ <form id='uploadwarning' method='post' enctype='multipart/form-data' action='$action'>");
 192+ }
 193+ $this->mHasWarning = true;
 194+ $this->mSessionKey = $this->stashSession();
 195+ if( !$this->mSessionKey ) {
 196+ # Couldn't save file; an error has been displayed so let's go.
 197+ return;
 198+ }
 199+
 200+ $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n" );
 201+ $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br />\n" );
 202+ $wgOut->addHTML(" <input type='hidden' name='wpUploadDescription_{$this->mFileIndex}' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />");
 203+ }
 204+
 205+ function stashSession() {
 206+ $stash = $this->saveTempUploadedFile( $this->mUploadSaveName, $this->mUploadTempName );
 207+
 208+ if( !$stash ) {
 209+ # Couldn't save the file.
 210+ return false;
 211+ }
 212+
 213+ if( $this->mSessionKey == null )
 214+ $key = mt_rand( 0, 0x7fffffff );
 215+ else
 216+ $key = $this->mSessionKey;
 217+ $_SESSION["wsUploadData_" . $this->mFileIndex][$key] = array(
 218+ 'mUploadTempName' => $stash,
 219+ 'mUploadSize' => $this->mUploadSize,
 220+ 'mOname' => $this->mOname
 221+ );
 222+ return $key;
 223+ }
 224+
 225+ function showWarningOptions() {
 226+ global $wgOut, $wgMaxUploadFiles, $wgUseCopyrightUpload;
 227+
 228+ $save = wfMsgHtml( 'multipleupload-saveallfiles' );
 229+ $reupload = wfMsgHtml( 'reupload' );
 230+ $iw = wfMsgWikiHtml( 'multipleupload-ignoreallwarnings' );
 231+ $reup = wfMsgWikiHtml( 'reuploaddesc' );
 232+
 233+ if ( $wgUseCopyrightUpload ) {
 234+ $copyright = '
 235+ <input type="hidden" name="wpUploadCopyStatus" value="' . htmlspecialchars( $this->mUploadCopyStatus ) . '" />
 236+ <input type="hidden" name="wpUploadSource" value="' . htmlspecialchars( $this->mUploadSource ) . '" />';
 237+ } else {
 238+ $copyright = '';
 239+ }
 240+
 241+ $wgOut->addHTML( '<input type="hidden" name="wpIgnoreWarning" value="1" />
 242+ <input type="hidden" name="wpSessionKey" value="' . htmlspecialchars( $this->mSessionKey ) . '" />
 243+ <input type="hidden" name="wpLicense" value="' . htmlspecialchars( $this->mLicense ) . '" />');
 244+
 245+ for( $x = 0; $x < $wgMaxUploadFiles; $x++ ) {
 246+ $wgOut->addHTML("<input type='hidden' name='wpDestFile_$x' value=\"" . htmlspecialchars( $this->mDestFileArray[$x] ) . "\" />");
 247+ }
 248+
 249+ $wgOut->addHTML("<input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" />
 250+ {$copyright}
 251+ <table border='0'>
 252+ <tr>
 253+ <tr>
 254+ <td align='right'>
 255+ <input tabindex='2' type='submit' name='wpUpload' value='$save' />
 256+ </td>
 257+ <td align='left'>$iw</td>
 258+ </tr>
 259+ <tr>
 260+ <td align='right'>
 261+ <input tabindex='2' type='submit' name='wpReUpload' value='{$reupload}' />
 262+ </td>
 263+ <td align='left'>$reup</td>
 264+ </tr>
 265+ </tr>
 266+ </table></form>\n" );
 267+
 268+ }
 269+
 270+ /**
 271+ * Displays the main upload form, optionally with a highlighted
 272+ * error message up at the top.
 273+ *
 274+ * @param string $msg as HTML
 275+ * @access private
 276+ */
 277+ function mainUploadForm( $msg = '' ) {
 278+ global $wgOut, $wgUser, $wgScriptPath, $wgUseCopyrightUpload, $wgMaxUploadFiles;
 279+
 280+ if( $msg == '' && !$this->mShowUploadForm ) return;
 281+ $cols = intval( $wgUser->getOption( 'cols' ) );
 282+ $ew = $wgUser->getOption( 'editwidth' );
 283+ if ( $ew ) $ew = " style=\"width:100%\"";
 284+ else $ew = '';
 285+
 286+ if ( '' != $msg ) {
 287+ $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n<br />" );
 288+ $sub = wfMsgHtml( 'multipleupload-addresswarnings' );
 289+ $wgOut->addHTML( "<b>{$sub}</b><br /><span class='error'>{$msg}</span>\n" );
 290+ }
 291+ $wgOut->addHTML( '<div id="uploadtext">' );
 292+ $wgOut->addWikiMsg('multipleupload-text', $wgMaxUploadFiles);
 293+ $wgOut->addHTML( '</div>' );
 294+ $sk = $wgUser->getSkin();
 295+
 296+ $sourcefilename = wfMsgHtml( 'sourcefilename' );
 297+ $destfilename = wfMsgHtml( 'destfilename' );
 298+ $summary = wfMsg( 'fileuploadsummary' );
 299+ $licenses = new Licenses();
 300+ $license = wfMsgHtml( 'license' );
 301+ $nolicense = wfMsgHtml( 'nolicense' );
 302+ $licenseshtml = $licenses->getHtml();
 303+ $ulb = wfMsgHtml( 'uploadbtn' );
 304+
 305+ $titleObj = Title::makeTitle( NS_SPECIAL, 'MultipleUpload' );
 306+ $action = $titleObj->escapeLocalURL();
 307+
 308+ $watchChecked = $wgUser->getOption( 'watchdefault' )
 309+ ? 'checked="checked"'
 310+ : '';
 311+
 312+ $wgOut->addScriptFile( $wgScriptPath.'/extensions/MultiUpload/multiupload.js' );
 313+ $wgOut->addHTML( "
 314+ <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
 315+ <table border='0'>
 316+ <tr>
 317+ <td align='left'><label for='wpUploadFile'><b>{$sourcefilename}</b></label></td>
 318+ <td align='left'><label for='wpDestFile'><b>{$destfilename}</b></label></td>
 319+ <td align='left' valign='middle'><b>{$summary}</b></td>
 320+ </tr>");
 321+ for( $i = 0; $i < $wgMaxUploadFiles; $i++ ) {
 322+ $encDestFile = htmlspecialchars( $this->mDestFileArray[$i] );
 323+ $wgOut->addHTML("
 324+ <tr>
 325+ <td align='left'>
 326+ <input tabindex='1' type='file' name='wpUploadFile_$i' id='wpUploadFile_$i' " . ( $this->mDestName ? "" : "onchange='fillDestFilenameMulti($i)' " ) . "size='25' />
 327+ </td>
 328+ <td align='left'>
 329+ <input tabindex='2' type='text' name='wpDestFile_$i' id='wpDestFile_$i' size='25' value=\"$encDestFile\" />
 330+ </td>
 331+ <td align='left'>
 332+ <input tabindex='3' name='wpUploadDescription_$i' id='wpUploadDescription' value=\"". htmlspecialchars( $this->mComment ) . "\" size=25>
 333+ </td>
 334+ </tr>
 335+ <tr>" );
 336+ }
 337+
 338+ if ( $licenseshtml != '' ) {
 339+ global $wgAjaxLicensePreview, $wgJsMimeType;
 340+ $wgOut->addScriptFile( 'upload.js' );
 341+ // This is one nasty hack...but necessary to make upload.js not bitch if the user actually touches the "Licensing" dropdown menu instead of just admiring it from a distance.
 342+ $wgOut->addInlineScript( 'var wgAjaxLicensePreview = "'.$wgAjaxLicensePreview.'";' );
 343+ $wgOut->addHTML( "
 344+ <td align='left' colspan=3>
 345+ <label for='wpLicense'>$license</label>
 346+ <select name='wpLicense' id='wpLicense' tabindex='4' style='font-size: xx-small;'
 347+ onchange='licenseSelectorCheck()'>
 348+ <option value=''>$nolicense</option>
 349+ $licenseshtml
 350+ </select>
 351+ </td>
 352+ </tr>
 353+ <tr>");
 354+ // So that the license previews will show up on the page
 355+ $wgOut->addHTML( '<td></td>
 356+ <td id="mw-license-preview"></td>
 357+ </tr>
 358+ <tr>' );
 359+ }
 360+
 361+ if ( $wgUseCopyrightUpload ) {
 362+ global $wgRequest;
 363+ $filestatus = wfMsgHtml( 'filestatus' );
 364+ $copystatus = htmlspecialchars( $this->mUploadCopyStatus );
 365+ $filesource = wfMsgHtml( 'filesource' );
 366+ $uploadsource = htmlspecialchars( $this->mUploadSource );
 367+
 368+ $wgOut->addHTML( "
 369+ <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus</label></td>
 370+ <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td>
 371+ </tr>
 372+ <tr>
 373+ <td align='right'><label for='wpUploadCopyStatus'>$filesource</label></td>
 374+ <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td>
 375+ </tr>
 376+ <tr>" );
 377+ // For license selector
 378+ $wgOut->addHTML( Xml::hidden( 'wpLicense', $wgRequest->getText( 'wpLicense' ) ) . "\n" );
 379+ }
 380+
 381+ $wgOut->addHTML( "
 382+ <td>
 383+ <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
 384+ <label for='wpWatchthis'>" . wfMsgHtml( 'watchthis' ) . "</label>
 385+ <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' />
 386+ <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
 387+ </td>
 388+ </tr>
 389+ <tr>
 390+
 391+ </tr>
 392+ <tr>
 393+ <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
 394+ </tr>
 395+
 396+ </table>
 397+ </form>" );
 398+ }
 399+
 400+}
\ No newline at end of file
Property changes on: trunk/extensions/MultiUpload/SpecialMultipleUpload.body.php
___________________________________________________________________
Added: svn:eol-style
1401 + native
Index: trunk/extensions/MultiUpload/SpecialMultipleUpload.i18n.php
@@ -1,20 +1,24 @@
22 <?php
33 /**
4 - * Internationalisation file for extension MultiUpload.
 4+ * Internationalisation file for MultiUpload extension.
55 *
6 - * @addtogroup Extensions
 6+ * @file
 7+ * @ingroup Extensions
78 */
89
910 $messages = array();
1011
 12+/** English
 13+ * @author Travis Derouin
 14+ */
1115 $messages['en'] = array(
12 - 'multipleupload' => "Upload files",
13 - 'multipleupload-desc' => 'Allows users to [[Special:MultipleUpload|upload several files at once]]',
 16+ 'multipleupload' => 'Upload files',
 17+ 'multipleupload-desc' => 'Allows users to [[Special:MultipleUpload|upload several files at once]]',
1418 'multipleupload-ignoreallwarnings' => "Ignore '''all warnings''' and save the files anyway.",
15 - 'multipleupload-saveallfiles' => "Save all files",
16 - 'multipleupload-addresswarnings' => "Please address any warnings before reuploading files.",
17 - 'multipleupload-page' => "{{ns:project}}:File deletion policy",
18 - 'multipleupload-text' => "Upload multiple files here.
 19+ 'multipleupload-saveallfiles' => 'Save all files',
 20+ 'multipleupload-addresswarnings' => 'Please address any warnings before reuploading files.',
 21+ 'multipleupload-page' => "{{ns:project}}:File deletion policy",
 22+ 'multipleupload-text' => "Upload multiple files here.
1923
2024 Choose 'Browse' and select each file you wish to upload.
2125 You can upload from 1 to $1 files at a time.
@@ -22,8 +26,8 @@
2327 You can enter an optional '''Destination filename''' and provide a '''Summary''' describing your file.
2428
2529 Inappropriate files will be deleted immediately, see the [[{{MediaWiki:Multipleupload-page}}|file deletion policy]].",
26 - 'multiupload-fileuploaded' => "File uploaded.",
27 - 'multiupload-toolbox' => "Upload multiple files",
 30+ 'multiupload-fileuploaded' => 'File uploaded.',
 31+ 'multiupload-toolbox' => 'Upload multiple files',
2832 );
2933
3034 /** Message documentation (Message documentation)
Index: trunk/extensions/MultiUpload/SpecialMultipleUpload.php
@@ -2,466 +2,81 @@
33 if ( ! defined( 'MEDIAWIKI' ) )
44 die();
55
6 -/**#@+
 6+/**
77 * An extension that allows users to upload multiple files at once.
88 *
9 - * @addtogroup Extensions
10 - *
11 - * @link http://www.mediawiki.org/wiki/Extension:MultiUpload
12 - *
 9+ * @file
 10+ * @ingroup Extensions
1311 * @author Travis Derouin <travis@wikihow.com>
1412 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 13+ * @link http://www.mediawiki.org/wiki/Extension:MultiUpload Documentation
1514 */
1615
1716 // change this parameter to limit the # of files one can upload
18 -$wgMaxUploadFiles = isset( $wgMaxUploadFiles ) ? $wgMaxUploadFiles : 5;
 17+$wgMaxUploadFiles = isset( $wgMaxUploadFiles ) ? intval( $wgMaxUploadFiles ) : 5;
1918
20 -$wgExtensionFunctions[] = 'wfMultipleUpload';
21 -
 19+// Extension credits that will show up on Special:Version
2220 $wgExtensionCredits['specialpage'][] = array(
23 - 'name' => 'MultipleUpload',
24 - 'author' => 'Travis Derouin',
25 - 'version' => '1.0',
26 - 'description' => 'Allows users to upload several files at once.',
 21+ 'name' => 'MultipleUpload',
 22+ 'author' => 'Travis Derouin',
 23+ 'version' => '1.0',
 24+ 'description' => 'Allows users to upload several files at once.',
2725 'descriptionmsg' => 'multipleupload-desc',
28 - 'url' => 'http://www.mediawiki.org/wiki/Extension:MultiUpload',
 26+ 'url' => 'http://www.mediawiki.org/wiki/Extension:MultiUpload',
2927 );
3028
 29+// Set up the new special page
3130 $dir = dirname(__FILE__) . '/';
 31+$wgAutoloadClasses['MultipleUpload'] = $dir . 'SpecialMultipleUpload.body.php';
 32+$wgAutoloadClasses['MultipleUploadForm'] = $dir . 'SpecialMultipleUpload.body.php';
3233 $wgExtensionMessagesFiles['MultiUpload'] = $dir . 'SpecialMultipleUpload.i18n.php';
3334 $wgExtensionAliasesFiles['MultiUpload'] = $dir . 'SpecialMultipleUpload.alias.php';
 35+$wgSpecialPages['MultipleUpload'] = 'MultipleUpload';
3436
35 -function wfMultipleUpload() {
36 - SpecialPage::AddPage(new SpecialPage('MultipleUpload'));
 37+// Hooked functions
 38+$wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfMultiUploadToolbox';
 39+$wgHooks['UploadComplete'][] = 'wfMultiUploadShowSuccess';
 40+$wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'wfSpecialMultiUploadNav';
3741
38 - global $wgMaxUploadFiles, $wgHooks;
39 - $wgMaxUploadFiles = intval( $wgMaxUploadFiles );
 42+// Add the link to Special:MultipleUpload to all SkinTemplate-based skins for users with the 'upload' user right
 43+function wfSpecialMultiUploadNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
 44+ global $wgUser;
4045 wfLoadExtensionMessages( 'MultiUpload' );
 46+ if( $wgUser->isAllowed( 'upload' ) )
 47+ $nav_urls['multiupload'] = array(
 48+ 'text' => wfMsg( 'multiupload_link' ),
 49+ 'href' => $skintemplate->makeSpecialUrl( 'MultipleUpload' )
 50+ );
4151
42 - $wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfMultiUploadToolbox';
43 - $wgHooks['UploadComplete'][] = 'wfMultiUploadShowSuccess';
44 - $wgHooks['SkinTemplateBuildNavUrlsNav_urlsAfterPermalink'][] = 'wfSpecialMultiUploadNav';
45 -
 52+ return true;
4653 }
4754
48 -/**
49 - * Entry point
50 - */
51 -function wfSpecialMultipleUpload() {
52 - global $wgRequest;
53 - $form = new MultipleUploadForm( $wgRequest );
54 - $form->execute();
55 -}
56 -
57 -/**
58 - *
59 - * @addtogroup SpecialPage
60 - */
61 -class MultipleUploadForm extends UploadForm {
62 -
63 - // extra goodies
64 - // access private
65 - var $mUploadTempNameArray, $mUploadSizeArray, $mOnameArray, $mUploadError, $mDestFileArray;
66 - var $mUploadDescriptionArray;
67 - var $mShowUploadForm, $mHasWarning, $mFileIndex;
68 - /**
69 - * Constructor : initialise object
70 - * Get data POSTed through the form and assign them to the object
71 - * @param $request Data posted.
72 - */
73 - function MultipleUploadForm( &$request ) {
74 - global $wgMaxUploadFiles;
75 - // call the parent constructor
76 - parent::UploadForm($request);
77 -
78 - //initialize
79 - $this->mUploadTempNameArray= $this->mUploadSizeArray= $this->mOnameArray= $this->mUploadError= $this->mDestFileArray = $this->mUploadDescriptionArray = array();
80 - $this->mShowUploadForm = true;
81 - $this->mFileIndex = 0;
82 -
83 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) $this->mDestFileArray[$x] = $request->getText( "wpDestFile_$x" );
84 -
85 - if( !$request->wasPosted() ) {
86 - # GET requests just give the main form; no data except wpDestfile.
87 - return ;
88 - }
89 -
90 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
91 - $this->mDestFile[$x] = $request->getText( "wpDestFile_$x" );
92 - $this->mUploadDescriptionArray[$x] = $request->getText( "wpUploadDescription_$x" );
93 - }
94 - $this->mSessionKey = $request->getInt( 'wpSessionKey' );
95 -
96 - if( !empty( $this->mSessionKey ) ) {
97 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
98 - //if (!isset($_SESSION["wsUploadData_$x"][$this->mSessionKey])) continue;
99 - $data = $_SESSION["wsUploadData_$x"][$this->mSessionKey];
100 - $this->mUploadTempNameArray[$x] = $data["mUploadTempName"];
101 - $this->mUploadSizeArray[$x] = $data["mUploadSize"];
102 - $this->mOnameArray[$x] = $data["mOname"];
103 - }
 55+// Add the link to Special:MultipleUpload to the Monobook skin
 56+function wfMultiUploadToolbox( &$monobook ) {
 57+ wfLoadExtensionMessages( 'MultiUpload' );
 58+ if ( isset( $monobook->data['nav_urls']['multiupload'] ) ) {
 59+ if ( $monobook->data['nav_urls']['multiupload']['href'] == '' ) {
 60+ ?><li id="t-ismultiupload"><?php echo $monobook->msg( 'multiupload-toolbox' ); ?></li><?php
10461 } else {
105 - /**
106 - *Check for a newly uploaded file.
107 - */
108 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
109 - $this->mUploadTempNameArray[$x] = $request->getFileTempName( "wpUploadFile_$x" );
110 - $this->mUploadSizeArray [$x] = $request->getFileSize( "wpUploadFile_$x" );
111 - $this->mOnameArray[$x] = $request->getFileName( "wpUploadFile_$x" );
112 - $this->mUploadErrorArray[$x] = $request->getUploadError( "wpUploadFile_$x" );
113 - $this->mUploadDescriptionArray [$x] = $request->getVal("wpUploadDescription_$x");
114 - }
 62+ ?><li id="t-multiupload"><?php
 63+ ?><a href="<?php echo htmlspecialchars( $monobook->data['nav_urls']['multiupload']['href'] ) ?>"><?php
 64+ echo $monobook->msg( 'multiupload-toolbox' );
 65+ ?></a><?php
 66+ ?></li><?php
11567 }
116 -
11768 }
 69+ return true;
 70+}
11871
119 - /* -------------------------------------------------------------- */
120 -
121 - /**
122 - * Really do the upload
123 - * Checks are made in SpecialUpload::execute()
124 - * @access private
125 - */
126 - function processUpload() {
127 - global $wgMaxUploadFiles, $wgOut;
128 -
129 - $wgOut->addHTML("<table>");
130 - $this->mShowUploadForm = false;
131 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
132 - $this->mFileIndex = $x;
133 - if (!isset ($this->mUploadTempNameArray[$x]) || $this->mUploadTempNameArray[$x] == null) continue;
134 -
135 - $this->mTempPath = $this->mUploadTempNameArray[$x];
136 - $this->mFileSize = $this->mUploadSizeArray[$x];
137 - $this->mSrcName = $this->mOnameArray[$x]; // for mw > 1.9
138 - $this->mRemoveTempFile = true;
139 - $this->mIgnoreWarning = true;
140 -
141 - $this->mUploadError = $this->mUploadErrorArray [$x];
142 - $this->mDesiredDestName = $this->mDestFileArray [$x];
143 - $this->mComment = $this->mUploadDescriptionArray [$x];
144 - $wgOut->addHTML("<tr><td>");
145 - parent::processUpload();
146 - $wgOut->addHTML("</td></tr>");
147 - }
148 -
149 - $wgOut->addHTML("</table>");
150 - $this->mShowUploadForm = false;
151 - $wgOut->redirect(''); // clear the redirect, we want to show a nice page of images
152 - $this->mShowUploadForm = true;
153 - if ($this->mHasWarning) {
154 - $this->showWarningOptions();
155 - }
156 - }
157 -
158 - /* -------------------------------------------------------------- */
159 -
160 - /**
161 - * Show some text and linkage on successful upload.
162 - * @access private
163 - */
164 - function showSuccess() {
165 - global $wgUser, $wgOut, $wgContLang;
166 -
167 - $sk = $wgUser->getSkin();
168 - $ilink = $sk->makeMediaLink( $this->mUploadSaveName, Image::imageUrl( $this->mUploadSaveName ) );
169 - $dname = $wgContLang->getNsText( NS_IMAGE ) . ':'.$this->mUploadSaveName;
170 - $dlink = $sk->makeKnownLink( $dname, $dname );
171 -
172 - $wgOut->addWikiText( "[[$dname|left|thumb]]" );
173 - $text = wfMsgWikiHtml( 'fileuploaded', $ilink, $dlink );
 72+// Show thumbnails of the images on MultipleUpload page after uploading them
 73+function wfMultiUploadShowSuccess( $uploadForm ) {
 74+ global $wgOut, $wgTitle;
 75+ wfLoadExtensionMessages( 'MultiUpload' );
 76+ if( $wgTitle->getText() == "MultipleUpload" ) {
 77+ $imgTitle = $uploadForm->mLocalFile->getTitle();
 78+ $wgOut->addWikiText( "[[{$imgTitle->getFullText()}|left|thumb]]" );
 79+ $text = wfMsgWikiHtml( 'multiupload-fileuploaded' );
17480 $wgOut->addHTML( $text );
17581 }
176 -
177 - /**
178 - * @param string $error as HTML
179 - * @access private
180 - */
181 - function uploadError( $error ) {
182 - global $wgOut;
183 - $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n" );
184 - $wgOut->addHTML( "<span class='error'>{$error}</span>\n" );
185 - }
186 -
187 - /**
188 - * There's something wrong with this file, not enough to reject it
189 - * totally but we require manual intervention to save it for real.
190 - * Stash it away, then present a form asking to confirm or cancel.
191 - *
192 - * @param string $warning as HTML
193 - * @access private
194 - */
195 - function uploadWarning( $warning ) {
196 - global $wgOut;
197 -
198 - if (!$this->mHasWarning) {
199 - $titleObj = Title::makeTitle( NS_SPECIAL, 'MultipleUpload' );
200 - $action = $titleObj->escapeLocalURL( 'action=submit' );
201 - $wgOut->addHTML( "<h2>" . wfMsgHtml( 'uploadwarning' ) . "</h2>\n
202 - <form id='uploadwarning' method='post' enctype='multipart/form-data' action='$action'>");
203 - }
204 - $this->mHasWarning = true;
205 - $this->mSessionKey = $this->stashSession();
206 - if( !$this->mSessionKey ) {
207 - # Couldn't save file; an error has been displayed so let's go.
208 - return;
209 - }
210 -
211 - $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n" );
212 - $wgOut->addHTML( "<ul class='warning'>{$warning}</ul><br />\n" );
213 - $wgOut->addHTML(" <input type='hidden' name='wpUploadDescription_{$this->mFileIndex}' value=\"" . htmlspecialchars( $this->mUploadDescription ) . "\" />");
214 -
215 - }
216 - function stashSession() {
217 - $stash = $this->saveTempUploadedFile(
218 - $this->mUploadSaveName, $this->mUploadTempName );
219 -
220 - if( !$stash ) {
221 - # Couldn't save the file.
222 - return false;
223 - }
224 -
225 - if ($this->mSessionKey == null)
226 - $key = mt_rand( 0, 0x7fffffff );
227 - else
228 - $key = $this->mSessionKey;
229 - $_SESSION["wsUploadData_" . $this->mFileIndex][$key] = array(
230 - 'mUploadTempName' => $stash,
231 - 'mUploadSize' => $this->mUploadSize,
232 - 'mOname' => $this->mOname
233 - );
234 - return $key;
235 - }
236 -
237 - function showWarningOptions() {
238 - global $wgOut, $wgMaxUploadFiles, $wgUseCopyrightUpload;
239 - $save = wfMsgHtml( 'multipleupload-saveallfiles' );
240 - $reupload = wfMsgHtml( 'reupload' );
241 - $iw = wfMsgWikiHtml( 'multipleupload-ignoreallwarnings' );
242 - $reup = wfMsgWikiHtml( 'reuploaddesc' );
243 - if ( $wgUseCopyrightUpload ) {
244 - $copyright = "
245 - <input type='hidden' name='wpUploadCopyStatus' value=\"" . htmlspecialchars( $this->mUploadCopyStatus ) . "\" />
246 - <input type='hidden' name='wpUploadSource' value=\"" . htmlspecialchars( $this->mUploadSource ) . "\" />
247 - ";
248 - } else {
249 - $copyright = "";
250 - }
251 - $wgOut->addHTML( "
252 - <input type='hidden' name='wpIgnoreWarning' value='1' />
253 - <input type='hidden' name='wpSessionKey' value=\"" . htmlspecialchars( $this->mSessionKey ) . "\" />
254 - <input type='hidden' name='wpLicense' value=\"" . htmlspecialchars( $this->mLicense ) . "\" />
255 - ");
256 - for ($x = 0; $x < $wgMaxUploadFiles; $x++) {
257 - $wgOut->addHTML("<input type='hidden' name='wpDestFile_$x' value=\"" . htmlspecialchars( $this->mDestFileArray[$x] ) . "\" />");
258 - }
259 - $wgOut->addHTML("<input type='hidden' name='wpWatchthis' value=\"" . htmlspecialchars( intval( $this->mWatchthis ) ) . "\" />
260 - {$copyright}
261 - <table border='0'>
262 - <tr>
263 - <tr>
264 - <td align='right'>
265 - <input tabindex='2' type='submit' name='wpUpload' value='$save' />
266 - </td>
267 - <td align='left'>$iw</td>
268 - </tr>
269 - <tr>
270 - <td align='right'>
271 - <input tabindex='2' type='submit' name='wpReUpload' value='{$reupload}' />
272 - </td>
273 - <td align='left'>$reup</td>
274 - </tr>
275 - </tr>
276 - </table></form>\n" );
277 -
278 - }
279 -
280 - /**
281 - * Displays the main upload form, optionally with a highlighted
282 - * error message up at the top.
283 - *
284 - * @param string $msg as HTML
285 - * @access private
286 - */
287 - function mainUploadForm( $msg='' ) {
288 - global $wgOut, $wgUser;
289 - global $wgUseCopyrightUpload, $wgMaxUploadFiles;
290 -
291 - if ($msg == '' && !$this->mShowUploadForm) return;
292 - $cols = intval($wgUser->getOption( 'cols' ));
293 - $ew = $wgUser->getOption( 'editwidth' );
294 - if ( $ew ) $ew = " style=\"width:100%\"";
295 - else $ew = '';
296 -
297 - if ( '' != $msg ) {
298 - $wgOut->addHTML( "<b>{$this->mUploadSaveName}</b>\n<br />" );
299 - $sub = wfMsgHtml( 'multipleupload-addresswarnings' );
300 - $wgOut->addHTML( "<b>{$sub}</b><br /><span class='error'>{$msg}</span>\n" );
301 - }
302 - $wgOut->addHTML( '<div id="uploadtext">' );
303 - $wgOut->addWikiText( wfMsg('multipleupload-text', $wgMaxUploadFiles) );
304 - $wgOut->addHTML( '</div>' );
305 - $sk = $wgUser->getSkin();
306 -
307 - $sourcefilename = wfMsgHtml( 'sourcefilename' );
308 - $destfilename = wfMsgHtml( 'destfilename' );
309 - $summary = wfMsg( 'fileuploadsummary' );
310 - $licenses = new Licenses();
311 - $license = wfMsgHtml( 'license' );
312 - $nolicense = wfMsgHtml( 'nolicense' );
313 - $licenseshtml = $licenses->getHtml();
314 - $ulb = wfMsgHtml( 'uploadbtn' );
315 -
316 - $titleObj = Title::makeTitle( NS_SPECIAL, 'MultipleUpload' );
317 - $action = $titleObj->escapeLocalURL();
318 -
319 - $watchChecked = $wgUser->getOption( 'watchdefault' )
320 - ? 'checked="checked"'
321 - : '';
322 -
323 - $wgOut->addHTML( "
324 -<script type=\"text/javascript\">
325 -function fillDestFilenameMulti(i) {
326 - if (!document.getElementById)
327 - return;
328 - var path = document.getElementById('wpUploadFile_' + i).value;
329 - // Find trailing part
330 - var slash = path.lastIndexOf('/');
331 - var backslash = path.lastIndexOf('\\\\');
332 - var fname;
333 - if (slash == -1 && backslash == -1) {
334 - fname = path;
335 - } else if (slash > backslash) {
336 - fname = path.substring(slash+1, 10000);
337 - } else {
338 - fname = path.substring(backslash+1, 10000);
339 - }
340 -
341 - // Capitalise first letter and replace spaces by underscores
342 - fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
343 -
344 - // Output result
345 - var destFile = document.getElementById('wpDestFile_' + i);
346 - if (destFile)
347 - destFile.value = fname;
348 -}
349 -</script>
350 -
351 - <form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
352 - <table border='0'>
353 - <tr>
354 - <td align='left'><label for='wpUploadFile'><b>{$sourcefilename}</b></label></td>
355 - <td align='left'><label for='wpDestFile'><b>{$destfilename}</b></label></td>
356 - <td align='left' valign='middle'><b>{$summary}</b></td>
357 - </tr>");
358 - for ($i = 0; $i < $wgMaxUploadFiles; $i++) {
359 - $encDestFile = htmlspecialchars( $this->mDestFileArray[$i] );
360 - $wgOut->addHTML("
361 - <tr>
362 - <td align='left'>
363 - <input tabindex='1' type='file' name='wpUploadFile_$i' id='wpUploadFile_$i' " . ($this->mDestName?"":"onchange='fillDestFilenameMulti($i)' ") . "size='25' />
364 - </td>
365 - <td align='left'>
366 - <input tabindex='2' type='text' name='wpDestFile_$i' id='wpDestFile_$i' size='25' value=\"$encDestFile\" />
367 - </td>
368 - <td align='left'>
369 - <input tabindex='3' name='wpUploadDescription_$i' id='wpUploadDescription' value=\"". htmlspecialchars( $this->mComment ) . "\" size=25>
370 - </td>
371 - </tr>
372 - <tr>" );
373 - }
374 -
375 - if ( $licenseshtml != '' ) {
376 - global $wgStylePath;
377 - $wgOut->addHTML( "
378 - <td align='left' colspan=3>
379 - <label for='wpLicense'>$license:</label>
380 - <script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script>
381 - <select name='wpLicense' id='wpLicense' tabindex='4' style='font-size: xx-small;'
382 - onchange='licenseSelectorCheck()'>
383 - <option value=''>$nolicense</option>
384 - $licenseshtml
385 - </select>
386 - </td>
387 - </tr>
388 - <tr>
389 - ");
390 - }
391 -
392 - if ( $wgUseCopyrightUpload ) {
393 - $filestatus = wfMsgHtml ( 'filestatus' );
394 - $copystatus = htmlspecialchars( $this->mUploadCopyStatus );
395 - $filesource = wfMsgHtml ( 'filesource' );
396 - $uploadsource = htmlspecialchars( $this->mUploadSource );
397 -
398 - $wgOut->addHTML( "
399 - <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus</label></td>
400 - <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td>
401 - </tr>
402 - <tr>
403 - <td align='right'><label for='wpUploadCopyStatus'>$filesource</label></td>
404 - <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td>
405 - </tr>
406 - <tr>
407 - ");
408 - }
409 -
410 - $wgOut->addHTML( "
411 - <td>
412 - <input tabindex='7' type='checkbox' name='wpWatchthis' id='wpWatchthis' $watchChecked value='true' />
413 - <label for='wpWatchthis'>" . wfMsgHtml( 'watchthis' ) . "</label>
414 - <input tabindex='8' type='checkbox' name='wpIgnoreWarning' id='wpIgnoreWarning' value='true' />
415 - <label for='wpIgnoreWarning'>" . wfMsgHtml( 'ignorewarnings' ) . "</label>
416 - </td>
417 - </tr>
418 - <tr>
419 -
420 - </tr>
421 - <tr>
422 - <td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
423 - </tr>
424 -
425 - </table>
426 - </form>" );
427 - }
428 -
429 - /* -------------------------------------------------------------- */
430 -
431 -}
432 -
433 -function wfSpecialMultiUploadNav( &$skintemplate, &$nav_urls, &$oldid, &$revid ) {
434 - global $wgUser;
435 - if ($wgUser->isAllowed( 'upload' ))
436 - $nav_urls['multiupload'] = array(
437 - 'text' => wfMsg( 'multiupload_link' ),
438 - 'href' => $skintemplate->makeSpecialUrl( 'MultipleUpload')
439 - );
440 -
441 - return true;
442 -}
443 -function wfMultiUploadToolbox( &$monobook ) {
444 - if ( isset( $monobook->data['nav_urls']['multiupload'] ) ) {
445 - if ( $monobook->data['nav_urls']['multiupload']['href'] == '' ) {
446 - ?><li id="t-ismultiupload"><?php echo $monobook->msg( 'multiupload-toolbox' ); ?></li><?php
447 - } else {
448 - ?><li id="t-multiupload"><?php
449 - ?><a href="<?php echo htmlspecialchars( $monobook->data['nav_urls']['multiupload']['href'] ) ?>"><?php
450 - echo $monobook->msg( 'multiupload-toolbox' );
451 - ?></a><?php
452 - ?></li><?php
453 - }
454 - }
455 - return true;
456 -}
457 -
458 -function wfMultiUploadShowSuccess($uploadForm) {
459 - global $wgOut, $wgTitle;
460 - if ($wgTitle->getText() == "MultipleUpload") {
461 - //debug_print_backtrace();
462 - $imgTitle = $uploadForm->mLocalFile->getTitle();
463 - $wgOut->addWikiText( "[[{$imgTitle->getFullText()}|left|thumb]]" );
464 - $text = wfMsgWikiHtml( 'multiupload-fileuploaded');
465 - $wgOut->addHTML( $text );
466 - }
467 - return true;
468 -}
 82+ return true;
 83+}
\ No newline at end of file
Index: trunk/extensions/MultiUpload/multiupload.js
@@ -0,0 +1,27 @@
 2+/**
 3+ * JavaScript helper function for MultiUpload extension
 4+ */
 5+function fillDestFilenameMulti( i ) {
 6+ if( !document.getElementById )
 7+ return;
 8+ var path = document.getElementById('wpUploadFile_' + i).value;
 9+ // Find trailing part
 10+ var slash = path.lastIndexOf('/');
 11+ var backslash = path.lastIndexOf('\\');
 12+ var fname;
 13+ if( slash == -1 && backslash == -1 ) {
 14+ fname = path;
 15+ } else if( slash > backslash ) {
 16+ fname = path.substring(slash+1, 10000);
 17+ } else {
 18+ fname = path.substring(backslash+1, 10000);
 19+ }
 20+
 21+ // Capitalise first letter and replace spaces by underscores
 22+ fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
 23+
 24+ // Output result
 25+ var destFile = document.getElementById('wpDestFile_' + i);
 26+ if( destFile )
 27+ destFile.value = fname;
 28+}
\ No newline at end of file
Property changes on: trunk/extensions/MultiUpload/multiupload.js
___________________________________________________________________
Added: svn:eol-style
129 + native

Status & tagging log