r63359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63358‎ | r63359 | r63360 >
Date:14:07, 7 March 2010
Author:ashley
Status:ok
Tags:
Comment:
cleanup to SpecialUpload.php:
*trimmed trailing spaces
*more braces
*indentation tweaks
*removed unused globals
*removed unused $sk variable from showUploadWarning()
*changed double quotes to single where appropriate
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -5,7 +5,6 @@
66 * @ingroup Upload
77 *
88 * Form for handling uploads and special page.
9 - *
109 */
1110
1211 class SpecialUpload extends SpecialPage {
@@ -33,7 +32,7 @@
3433 public $mDesiredDestName; // The requested target file name
3534 protected $mComment;
3635 protected $mLicense;
37 -
 36+
3837 /** User input variables from the root section **/
3938 protected $mIgnoreWarning;
4039 protected $mWatchThis;
@@ -46,11 +45,10 @@
4746 protected $mCancelUpload; // The user clicked "Cancel and return to upload form" button
4847 protected $mTokenOk;
4948 protected $mUploadSuccessful = false; // Subclasses can use this to determine whether a file was uploaded
50 -
 49+
5150 /** Text injection points for hooks not using HTMLForm **/
5251 public $uploadFormTextTop;
5352 public $uploadFormTextAfterSummary;
54 -
5553
5654 /**
5755 * Initialize instance variables from request and create an Upload handler
@@ -63,14 +61,15 @@
6462 $this->mRequest = $request;
6563 $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
6664 $this->mUpload = UploadBase::createFromRequest( $request );
67 - $this->mUploadClicked = $request->wasPosted()
68 - && ( $request->getCheck( 'wpUpload' )
 65+ $this->mUploadClicked = $request->wasPosted()
 66+ && ( $request->getCheck( 'wpUpload' )
6967 || $request->getCheck( 'wpUploadIgnoreWarning' ) );
7068
7169 // Guess the desired name from the filename if not provided
7270 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
73 - if( !$this->mDesiredDestName )
 71+ if( !$this->mDesiredDestName ) {
7472 $this->mDesiredDestName = $request->getText( 'wpUploadFile' );
 73+ }
7574 $this->mComment = $request->getText( 'wpUploadDescription' );
7675 $this->mLicense = $request->getText( 'wpLicense' );
7776
@@ -97,7 +96,7 @@
9897 } else {
9998 $this->mTokenOk = $wgUser->matchEditToken( $token );
10099 }
101 -
 100+
102101 $this->uploadFormTextTop = '';
103102 $this->uploadFormTextAfterSummary = '';
104103 }
@@ -156,33 +155,37 @@
157156
158157 # Unsave the temporary file in case this was a cancelled upload
159158 if ( $this->mCancelUpload ) {
160 - if ( !$this->unsaveUploadedFile() )
 159+ if ( !$this->unsaveUploadedFile() ) {
161160 # Something went wrong, so unsaveUploadedFile showed a warning
162161 return;
 162+ }
163163 }
164164
165165 # Process upload or show a form
166 - if ( $this->mTokenOk && !$this->mCancelUpload
167 - && ( $this->mUpload && $this->mUploadClicked ) ) {
 166+ if (
 167+ $this->mTokenOk && !$this->mCancelUpload &&
 168+ ( $this->mUpload && $this->mUploadClicked )
 169+ )
 170+ {
168171 $this->processUpload();
169172 } else {
170173 # Backwards compatibility hook
171 - if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) )
172 - {
 174+ if( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) {
173175 wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
174176 return;
175177 }
176 -
 178+
177179 $this->showUploadForm( $this->getUploadForm() );
178180 }
179181
180182 # Cleanup
181 - if ( $this->mUpload )
 183+ if ( $this->mUpload ) {
182184 $this->mUpload->cleanupTempFile();
 185+ }
183186 }
184187
185188 /**
186 - * Show the main upload form
 189+ * Show the main upload form
187190 *
188191 * @param mixed $form An HTMLForm instance or HTML string to show
189192 */
@@ -191,14 +194,14 @@
192195 if ( !$this->mDesiredDestName ) {
193196 $this->showViewDeletedLinks();
194197 }
195 -
 198+
196199 if ( $form instanceof HTMLForm ) {
197200 $form->show();
198201 } else {
199202 global $wgOut;
200203 $wgOut->addHTML( $form );
201204 }
202 -
 205+
203206 }
204207
205208 /**
@@ -210,23 +213,26 @@
211214 */
212215 protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
213216 global $wgOut;
214 -
 217+
215218 # Initialize form
216219 $form = new UploadForm( array(
217 - 'watch' => $this->getWatchCheck(),
218 - 'forreupload' => $this->mForReUpload,
 220+ 'watch' => $this->getWatchCheck(),
 221+ 'forreupload' => $this->mForReUpload,
219222 'sessionkey' => $sessionKey,
220223 'hideignorewarning' => $hideIgnoreWarning,
221224 'destwarningack' => (bool)$this->mDestWarningAck,
222 -
 225+
223226 'texttop' => $this->uploadFormTextTop,
224227 'textaftersummary' => $this->uploadFormTextAfterSummary,
225228 ) );
226229 $form->setTitle( $this->getTitle() );
227230
228231 # Check the token, but only if necessary
229 - if( !$this->mTokenOk && !$this->mCancelUpload
230 - && ( $this->mUpload && $this->mUploadClicked ) ) {
 232+ if(
 233+ !$this->mTokenOk && !$this->mCancelUpload &&
 234+ ( $this->mUpload && $this->mUploadClicked )
 235+ )
 236+ {
231237 $form->addPreText( wfMsgExt( 'session_fail_preview', 'parseinline' ) );
232238 }
233239
@@ -234,16 +240,16 @@
235241 $form->addPreText( '<div id="uploadtext">' . wfMsgExt( 'uploadtext', 'parse' ) . '</div>');
236242 # Add upload error message
237243 $form->addPreText( $message );
238 -
 244+
239245 # Add footer to form
240246 $uploadFooter = wfMsgNoTrans( 'uploadfooter' );
241247 if ( $uploadFooter != '-' && !wfEmptyMsg( 'uploadfooter', $uploadFooter ) ) {
242248 $form->addPostText( '<div id="mw-upload-footer-message">'
243249 . $wgOut->parse( $uploadFooter ) . "</div>\n" );
244250 }
245 -
246 - return $form;
247251
 252+ return $form;
 253+
248254 }
249255
250256 /**
@@ -290,7 +296,7 @@
291297 $sessionKey = $this->mUpload->stashSession();
292298 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
293299 '<div class="error">' . $message . "</div>\n";
294 -
 300+
295301 $form = $this->getUploadForm( $message, $sessionKey );
296302 $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
297303 $this->showUploadForm( $form );
@@ -300,42 +306,42 @@
301307 * Also checks whether there are actually warnings to display.
302308 *
303309 * @param array $warnings
304 - * @return boolean true if warnings were displayed, false if there are no
 310+ * @return boolean true if warnings were displayed, false if there are no
305311 * warnings and the should continue processing like there was no warning
306312 */
307313 protected function showUploadWarning( $warnings ) {
308 - global $wgUser;
309 -
310314 # If there are no warnings, or warnings we can ignore, return early
311 - if ( !$warnings || ( count( $warnings ) == 1 &&
312 - isset( $warnings['exists']) && $this->mDestWarningAck ) ) {
313 - return false;
 315+ if (
 316+ !$warnings || ( count( $warnings ) == 1 &&
 317+ isset( $warnings['exists']) && $this->mDestWarningAck )
 318+ )
 319+ {
 320+ return false;
314321 }
315322
316323 $sessionKey = $this->mUpload->stashSession();
317324
318 - $sk = $wgUser->getSkin();
319 -
320325 $warningHtml = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n"
321326 . '<ul class="warning">';
322327 foreach( $warnings as $warning => $args ) {
323 - $msg = '';
324 - if( $warning == 'exists' ) {
325 - $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
326 - } elseif( $warning == 'duplicate' ) {
327 - $msg = self::getDupeWarning( $args );
328 - } elseif( $warning == 'duplicate-archive' ) {
329 - $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
330 - array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) )
331 - . "</li>\n";
332 - } else {
333 - if ( $args === true )
334 - $args = array();
335 - elseif ( !is_array( $args ) )
336 - $args = array( $args );
337 - $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
 328+ $msg = '';
 329+ if( $warning == 'exists' ) {
 330+ $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
 331+ } elseif( $warning == 'duplicate' ) {
 332+ $msg = self::getDupeWarning( $args );
 333+ } elseif( $warning == 'duplicate-archive' ) {
 334+ $msg = "\t<li>" . wfMsgExt( 'file-deleted-duplicate', 'parseinline',
 335+ array( Title::makeTitle( NS_FILE, $args )->getPrefixedText() ) )
 336+ . "</li>\n";
 337+ } else {
 338+ if ( $args === true ) {
 339+ $args = array();
 340+ } elseif ( !is_array( $args ) ) {
 341+ $args = array( $args );
338342 }
339 - $warningHtml .= $msg;
 343+ $msg = "\t<li>" . wfMsgExt( $warning, 'parseinline', $args ) . "</li>\n";
 344+ }
 345+ $warningHtml .= $msg;
340346 }
341347 $warningHtml .= "</ul>\n";
342348 $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
@@ -346,7 +352,7 @@
347353 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
348354
349355 $this->showUploadForm( $form );
350 -
 356+
351357 # Indicate that we showed a form
352358 return true;
353359 }
@@ -384,8 +390,7 @@
385391 }
386392
387393 // Deprecated backwards compatibility hook
388 - if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) )
389 - {
 394+ if( !wfRunHooks( 'UploadForm:BeforeProcessing', array( &$this ) ) ) {
390395 wfDebug( "Hook 'UploadForm:BeforeProcessing' broke processing the file.\n" );
391396 return array( 'status' => UploadBase::BEFORE_PROCESSING );
392397 }
@@ -425,7 +430,6 @@
426431 $this->mUploadSuccessful = true;
427432 wfRunHooks( 'SpecialUploadComplete', array( &$this ) );
428433 $wgOut->redirect( $this->mLocalFile->getTitle()->getFullURL() );
429 -
430434 }
431435
432436 /**
@@ -438,15 +442,15 @@
439443 if ( $license != '' ) {
440444 $licensetxt = '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
441445 }
442 - $pageText = '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n" .
443 - '== ' . wfMsgForContent ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
444 - "$licensetxt" .
445 - '== ' . wfMsgForContent ( 'filesource' ) . " ==\n" . $source ;
 446+ $pageText = '== ' . wfMsgForContent( 'filedesc' ) . " ==\n" . $comment . "\n" .
 447+ '== ' . wfMsgForContent( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
 448+ "$licensetxt" .
 449+ '== ' . wfMsgForContent( 'filesource' ) . " ==\n" . $source;
446450 } else {
447451 if ( $license != '' ) {
448 - $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent ( 'filedesc' ) . " ==\n" . $comment . "\n";
449 - $pageText = $filedesc .
450 - '== ' . wfMsgForContent ( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
 452+ $filedesc = $comment == '' ? '' : '== ' . wfMsgForContent( 'filedesc' ) . " ==\n" . $comment . "\n";
 453+ $pageText = $filedesc .
 454+ '== ' . wfMsgForContent( 'license-header' ) . " ==\n" . '{{' . $license . '}}' . "\n";
451455 } else {
452456 $pageText = $comment;
453457 }
@@ -552,15 +556,15 @@
553557
554558 /**
555559 * Remove a temporarily kept file stashed by saveTempUploadedFile().
556 - * @access private
557560 * @return success
558561 */
559562 protected function unsaveUploadedFile() {
560563 global $wgOut;
561 - if ( !( $this->mUpload instanceof UploadFromStash ) )
 564+ if ( !( $this->mUpload instanceof UploadFromStash ) ) {
562565 return true;
 566+ }
563567 $success = $this->mUpload->unsaveUploadedFile();
564 - if ( ! $success ) {
 568+ if ( !$success ) {
565569 $wgOut->showFileDeleteError( $this->mUpload->getTempPath() );
566570 return false;
567571 } else {
@@ -580,8 +584,9 @@
581585 public static function getExistsWarning( $exists ) {
582586 global $wgUser, $wgContLang;
583587
584 - if ( !$exists )
 588+ if ( !$exists ) {
585589 return '';
 590+ }
586591
587592 $file = $exists['file'];
588593 $filename = $file->getTitle()->getPrefixedText();
@@ -657,15 +662,15 @@
658663 public static function getDupeWarning( $dupes ) {
659664 if( $dupes ) {
660665 global $wgOut;
661 - $msg = "<gallery>";
 666+ $msg = '<gallery>';
662667 foreach( $dupes as $file ) {
663668 $title = $file->getTitle();
664669 $msg .= $title->getPrefixedText() .
665 - "|" . $title->getText() . "\n";
 670+ '|' . $title->getText() . "\n";
666671 }
667 - $msg .= "</gallery>";
668 - return "<li>" .
669 - wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
 672+ $msg .= '</gallery>';
 673+ return '<li>' .
 674+ wfMsgExt( 'file-exists-duplicate', array( 'parse' ), count( $dupes ) ) .
670675 $wgOut->parse( $msg ) .
671676 "</li>\n";
672677 } else {
@@ -684,22 +689,20 @@
685690 protected $mSessionKey;
686691 protected $mHideIgnoreWarning;
687692 protected $mDestWarningAck;
688 -
 693+
689694 protected $mTextTop;
690695 protected $mTextAfterSummary;
691 -
 696+
692697 protected $mSourceIds;
693698
694699 public function __construct( $options = array() ) {
695 - global $wgLang;
696 -
697700 $this->mWatch = !empty( $options['watch'] );
698701 $this->mForReUpload = !empty( $options['forreupload'] );
699 - $this->mSessionKey = isset( $options['sessionkey'] )
 702+ $this->mSessionKey = isset( $options['sessionkey'] )
700703 ? $options['sessionkey'] : '';
701704 $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
702705 $this->mDestWarningAck = !empty( $options['destwarningack'] );
703 -
 706+
704707 $this->mTextTop = $options['texttop'];
705708 $this->mTextAfterSummary = $options['textaftersummary'];
706709
@@ -720,16 +723,17 @@
721724 # Build a list of IDs for javascript insertion
722725 $this->mSourceIds = array();
723726 foreach ( $sourceDescriptor as $key => $field ) {
724 - if ( !empty( $field['id'] ) )
 727+ if ( !empty( $field['id'] ) ) {
725728 $this->mSourceIds[] = $field['id'];
 729+ }
726730 }
727731
728732 }
729733
730734 /**
731 - * Get the descriptor of the fieldset that contains the file source
 735+ * Get the descriptor of the fieldset that contains the file source
732736 * selection. The section is 'source'
733 - *
 737+ *
734738 * @return array Descriptor array
735739 */
736740 protected function getSourceSection() {
@@ -761,22 +765,22 @@
762766 'raw' => true,
763767 );
764768 }
765 -
 769+
766770 $descriptor['UploadFile'] = array(
767 - 'class' => 'UploadSourceField',
768 - 'section' => 'source',
769 - 'type' => 'file',
770 - 'id' => 'wpUploadFile',
771 - 'label-message' => 'sourcefilename',
772 - 'upload-type' => 'File',
773 - 'radio' => &$radio,
774 - 'help' => wfMsgExt( 'upload-maxfilesize',
775 - array( 'parseinline', 'escapenoentities' ),
776 - $wgLang->formatSize(
777 - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
778 - )
779 - ) . ' ' . wfMsgHtml( 'upload_source_file' ),
780 - 'checked' => $selectedSourceType == 'file',
 771+ 'class' => 'UploadSourceField',
 772+ 'section' => 'source',
 773+ 'type' => 'file',
 774+ 'id' => 'wpUploadFile',
 775+ 'label-message' => 'sourcefilename',
 776+ 'upload-type' => 'File',
 777+ 'radio' => &$radio,
 778+ 'help' => wfMsgExt( 'upload-maxfilesize',
 779+ array( 'parseinline', 'escapenoentities' ),
 780+ $wgLang->formatSize(
 781+ wfShorthandToInteger( ini_get( 'upload_max_filesize' ) )
 782+ )
 783+ ) . ' ' . wfMsgHtml( 'upload_source_file' ),
 784+ 'checked' => $selectedSourceType == 'file',
781785 );
782786 if ( $canUploadByUrl ) {
783787 global $wgMaxUploadSize;
@@ -805,10 +809,9 @@
806810 return $descriptor;
807811 }
808812
809 -
810813 /**
811814 * Get the messages indicating which extensions are preferred and prohibitted.
812 - *
 815+ *
813816 * @return string HTML string containing the message
814817 */
815818 protected function getExtensionsMessage() {
@@ -845,7 +848,7 @@
846849 /**
847850 * Get the descriptor of the fieldset that contains the file description
848851 * input. The section is 'description'
849 - *
 852+ *
850853 * @return array Descriptor array
851854 */
852855 protected function getDescriptionSection() {
@@ -883,7 +886,7 @@
884887 'raw' => true,
885888 );
886889 }
887 -
 890+
888891 $descriptor += array(
889892 'EditTools' => array(
890893 'type' => 'edittools',
@@ -897,8 +900,9 @@
898901 'label-message' => 'license',
899902 ),
900903 );
901 - if ( $this->mForReUpload )
 904+ if ( $this->mForReUpload ) {
902905 $descriptor['DestFile']['readonly'] = true;
 906+ }
903907
904908 global $wgUseCopyrightUpload;
905909 if ( $wgUseCopyrightUpload ) {
@@ -920,13 +924,13 @@
921925 }
922926
923927 /**
924 - * Get the descriptor of the fieldset that contains the upload options,
 928+ * Get the descriptor of the fieldset that contains the upload options,
925929 * such as "watch this file". The section is 'options'
926 - *
 930+ *
927931 * @return array Descriptor array
928932 */
929933 protected function getOptionsSection() {
930 - global $wgUser, $wgOut;
 934+ global $wgUser;
931935
932936 if( $wgUser->isLoggedIn() ) {
933937 $descriptor = array(
@@ -954,7 +958,6 @@
955959 );
956960
957961 return $descriptor;
958 -
959962 }
960963
961964 /**
@@ -967,11 +970,11 @@
968971
969972 /**
970973 * Add upload JS to $wgOut
971 - *
972 - * @param bool $autofill Whether or not to autofill the destination
 974+ *
 975+ * @param $autofill Boolean: Whether or not to autofill the destination
973976 * filename text box
974977 */
975 - protected function addUploadJS( ) {
 978+ protected function addUploadJS() {
976979 global $wgUseAjax, $wgAjaxUploadDestCheck, $wgAjaxLicensePreview, $wgEnableAPI;
977980 global $wgOut;
978981
@@ -986,7 +989,7 @@
987990 );
988991
989992 $wgOut->addScript( Skin::makeVariablesScript( $scriptVars ) );
990 -
 993+
991994 // For <charinsert> support
992995 $wgOut->addScriptFile( 'edit.js' );
993996 $wgOut->addScriptFile( 'upload.js' );
@@ -994,7 +997,7 @@
995998
996999 /**
9971000 * Empty function; submission is handled elsewhere.
998 - *
 1001+ *
9991002 * @return bool false
10001003 */
10011004 function trySubmit() {
@@ -1009,7 +1012,7 @@
10101013 class UploadSourceField extends HTMLTextField {
10111014 function getLabelHtml() {
10121015 $id = "wpSourceType{$this->mParams['upload-type']}";
1013 - $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
 1016+ $label = Html::rawElement( 'label', array( 'for' => $id ), $this->mLabel );
10141017
10151018 if ( !empty( $this->mParams['radio'] ) ) {
10161019 $attribs = array(
@@ -1018,13 +1021,15 @@
10191022 'id' => $id,
10201023 'value' => $this->mParams['upload-type'],
10211024 );
1022 - if ( !empty( $this->mParams['checked'] ) )
 1025+ if ( !empty( $this->mParams['checked'] ) ) {
10231026 $attribs['checked'] = 'checked';
 1027+ }
10241028 $label .= Html::element( 'input', $attribs );
10251029 }
10261030
10271031 return Html::rawElement( 'td', array( 'class' => 'mw-label' ), $label );
10281032 }
 1033+
10291034 function getSize() {
10301035 return isset( $this->mParams['size'] )
10311036 ? $this->mParams['size']

Follow-up revisions

RevisionCommit summaryAuthorDate
r66941MFT r65025, bug 23176: fixed broken "upload new version" link. Skipped the wh...tstarling06:21, 27 May 2010

Status & tagging log