r58066 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58065‎ | r58066 | r58067 >
Date:20:05, 23 October 2009
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
* Updated upload hooks documentation
* Allow users to submit a modified file description without ignoring warnings
Modified paths:
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromStash.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadFromUrl.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1448,7 +1448,7 @@
14491449
14501450 'SpecialUploadComplete': Called after successfully uploading a file from
14511451 Special:Upload
1452 -$form: The UploadForm object
 1452+$form: The SpecialUpload object
14531453
14541454 'SpecialVersionExtensionTypes': called when generating the extensions credits,
14551455 use this to change the tables headers
@@ -1493,17 +1493,21 @@
14941494 $user: user that watched
14951495 $article: article object that was watched
14961496
1497 -'UploadForm:initial': before the upload form is generated
1498 -$form: UploadForm object
1499 -You might set the member-variables $uploadFormTextTop and
1500 -$uploadFormTextAfterSummary to inject text (HTML) either before
1501 -or after the editform.
 1497+'UploadCreateFromRequest': when UploadBase::createFromRequest has been called
 1498+string $type: the requested upload type
 1499+&$className: the class name of the Upload instance to be created
15021500
1503 -'UploadForm:BeforeProcessing': at the beginning of processUpload()
1504 -$form: UploadForm object
1505 -Lets you poke at member variables like $mUploadDescription before the
1506 -file is saved.
 1501+'UploadComplete': when Upload completes an upload
 1502+&$upload: an UploadBase child instance
15071503
 1504+'UploadFormInitDescriptor': after the descriptor for the upload form as been
 1505+assembled
 1506+array $descriptor: the HTMLForm descriptor
 1507+
 1508+'UploadFormSourceDescriptors': after the standard source inputs have been
 1509+added to the descriptor
 1510+array $descriptor: the HTMLForm descriptor
 1511+
15081512 'UploadVerification': additional chances to reject an uploaded file
15091513 string $saveName: destination file name
15101514 string $tempName: filesystem path to the temporary file for checks
Index: trunk/phase3/includes/upload/UploadFromStash.php
@@ -46,13 +46,13 @@
4747 }
4848
4949 public function initializeFromRequest( &$request ) {
50 - $sessionKey = $request->getInt( 'wpSessionKey' );
 50+ $this->mSessionKey = $request->getInt( 'wpSessionKey' );
5151 $sessionData = $request->getSessionData('wsUploadData');
5252
5353 $desiredDestName = $request->getText( 'wpDestFile' );
5454 if( !$desiredDestName )
5555 $desiredDestName = $request->getText( 'wpUploadFile' );
56 - return $this->initialize( $desiredDestName, $sessionData[$sessionKey], false );
 56+ return $this->initialize( $desiredDestName, $sessionData[$this->mSessionKey], false );
5757 }
5858
5959 /**
@@ -62,11 +62,14 @@
6363 return true;
6464 }
6565
 66+
6667 /**
67 - * We're here from "ignore warnings anyway" so return just OK
 68+ * There is no need to stash the image twice
6869 */
69 - public function checkWarnings() {
70 - return array();
 70+ public function stashSession() {
 71+ if ( !empty( $this->mSessionKey ) )
 72+ return $this->mSessionKey;
 73+ return parent::stashSession();
7174 }
7275
7376 /**
Index: trunk/phase3/includes/upload/UploadFromUrl.php
@@ -64,7 +64,7 @@
6565 public function initializeFromRequest( &$request ) {
6666 $desiredDestName = $request->getText( 'wpDestFile' );
6767 if( !$desiredDestName )
68 - $desiredDestName = $request->getText( 'wpUploadFile' );
 68+ $desiredDestName = $request->getText( 'wpUploadFileURL' );
6969 return $this->initialize(
7070 $desiredDestName,
7171 $request->getVal( 'wpUploadFileURL' ),
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -76,10 +76,16 @@
7777
7878 // Get the upload class
7979 $type = ucfirst( $type );
80 - $className = 'UploadFrom' . $type;
81 - wfDebug( __METHOD__ . ": class name: $className\n" );
82 - if( !in_array( $type, self::$uploadHandlers ) )
83 - return null;
 80+
 81+ // Give hooks the chance to handle this request
 82+ $className = null;
 83+ wfRunHooks( 'UploadCreateFromRequest', array( $type, &$className ) );
 84+ if ( is_null( $className ) ) {
 85+ $className = 'UploadFrom' . $type;
 86+ wfDebug( __METHOD__ . ": class name: $className\n" );
 87+ if( !in_array( $type, self::$uploadHandlers ) )
 88+ return null;
 89+ }
8490
8591 // Check whether this upload class is enabled
8692 if( !call_user_func( array( $className, 'isEnabled' ) ) )
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -56,7 +56,9 @@
5757 $this->mRequest = $request;
5858 $this->mSourceType = $request->getVal( 'wpSourceType', 'file' );
5959 $this->mUpload = UploadBase::createFromRequest( $request );
60 - $this->mUploadClicked = $request->getCheck( 'wpUpload' ) && $request->wasPosted();
 60+ $this->mUploadClicked = $request->wasPosted()
 61+ && ( $request->getCheck( 'wpUpload' )
 62+ || $request->getCheck( 'wpUploadIgnoreWarning' ) );
6163
6264 // Guess the desired name from the filename if not provided
6365 $this->mDesiredDestName = $request->getText( 'wpDestFile' );
@@ -66,7 +68,8 @@
6769 $this->mLicense = $request->getText( 'wpLicense' );
6870
6971
70 - $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' );
 72+ $this->mIgnoreWarning = $request->getCheck( 'wpIgnoreWarning' )
 73+ || $request->getCheck( 'wpUploadIgnoreWarning' );
7174 $this->mWatchthis = $request->getBool( 'wpWatchthis' );
7275 $this->mCopyrightStatus = $request->getText( 'wpUploadCopyStatus' );
7376 $this->mCopyrightSource = $request->getText( 'wpUploadSource' );
@@ -182,11 +185,16 @@
183186 * @param string $sessionKey Session key in case this is a stashed upload
184187 * @return UploadForm
185188 */
186 - protected function getUploadForm( $message = '', $sessionKey = '' ) {
 189+ protected function getUploadForm( $message = '', $sessionKey = '', $hideIgnoreWarning = false ) {
187190 global $wgOut;
188191
189192 # Initialize form
190 - $form = new UploadForm( $this->watchCheck(), $this->mForReUpload, $sessionKey );
 193+ $form = new UploadForm( array(
 194+ 'watch' => $this->watchCheck(),
 195+ 'forreupload' => $this->mForReUpload,
 196+ 'sessionkey' => $sessionKey,
 197+ 'hideignorewarning' => $hideIgnoreWarning,
 198+ ) );
191199 $form->setTitle( $this->getTitle() );
192200
193201 # Check the token, but only if necessary
@@ -251,7 +259,10 @@
252260 $sessionKey = $this->mUpload->stashSession();
253261 $message = '<h2>' . wfMsgHtml( 'uploadwarning' ) . "</h2>\n" .
254262 '<div class="error">' . $message . "</div>\n";
255 - $this->showUploadForm( $this->getUploadForm( $message, $sessionKey ) );
 263+
 264+ $form = $this->getUploadForm( $message, $sessionKey );
 265+ $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
 266+ $this->showUploadForm( $form );
256267 }
257268 /**
258269 * Stashes the upload, shows the main form, but adds an "continue anyway button"
@@ -286,10 +297,12 @@
287298 }
288299 $warningHtml .= $msg;
289300 }
290 - $warningHtml .= '</ul>';
 301+ $warningHtml .= "</ul>\n";
 302+ $warningHtml .= wfMsgExt( 'uploadwarning-text', 'parse' );
291303
292 - $form = $this->getUploadForm( $warningHtml, $sessionKey );
293 - $form->setSubmitText( wfMsg( 'ignorewarning' ) );
 304+ $form = $this->getUploadForm( $warningHtml, $sessionKey, /* $hideIgnoreWarning */ true );
 305+ $form->setSubmitText( wfMsg( 'upload-tryagain' ) );
 306+ $form->addButton( 'wpUploadIgnoreWarning', wfMsg( 'ignorewarning' ) );
294307 $form->addButton( 'wpCancelUpload', wfMsg( 'reuploaddesc' ) );
295308
296309 $this->showUploadForm( $form );
@@ -621,14 +634,18 @@
622635 protected $mWatch;
623636 protected $mForReUpload;
624637 protected $mSessionKey;
 638+ protected $mHideIgnoreWarning;
 639+
625640 protected $mSourceIds;
626641
627 - public function __construct( $watch, $forReUpload = false, $sessionKey = '' ) {
 642+ public function __construct( $options = array() ) {
628643 global $wgLang;
629644
630 - $this->mWatch = $watch;
631 - $this->mForReUpload = $forReUpload;
632 - $this->mSessionKey = $sessionKey;
 645+ $this->mWatch = !empty( $options['watch'] );
 646+ $this->mForReUpload = !empty( $options['forreupload'] );
 647+ $this->mSessionKey = isset( $options['sessionkey'] )
 648+ ? $options['sessionkey'] : '';
 649+ $this->mHideIgnoreWarning = !empty( $options['hideignorewarning'] );
633650
634651 $sourceDescriptor = $this->getSourceSection();
635652 $descriptor = $sourceDescriptor
@@ -841,14 +858,16 @@
842859 'id' => 'wpWatchthis',
843860 'label-message' => 'watchthisupload',
844861 'section' => 'options',
845 - ),
846 - 'IgnoreWarning' => array(
 862+ )
 863+ );
 864+ if ( !$this->mHideIgnoreWarning ) {
 865+ $descriptor['IgnoreWarning'] = array(
847866 'type' => 'check',
848867 'id' => 'wpIgnoreWarning',
849868 'label-message' => 'ignorewarnings',
850869 'section' => 'options',
851 - ),
852 - );
 870+ );
 871+ }
853872
854873 return $descriptor;
855874
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2040,6 +2040,7 @@
20412041 'upload' => 'Upload file',
20422042 'uploadbtn' => 'Upload file',
20432043 'reuploaddesc' => 'Cancel upload and return to the upload form',
 2044+'upload-tryagain' => 'Submit modified file description',
20442045 'uploadnologin' => 'Not logged in',
20452046 'uploadnologintext' => 'You must be [[Special:UserLogin|logged in]] to upload files.',
20462047 'upload_directory_missing' => 'The upload directory ($1) is missing and could not be created by the webserver.',
@@ -2115,6 +2116,7 @@
21162117 You should check that file's deletion history before proceeding to re-upload it.",
21172118 'successfulupload' => 'Successful upload',
21182119 'uploadwarning' => 'Upload warning',
 2120+'uploadwarning-text' => 'Please modify the file description below and try again.',
21192121 'savefile' => 'Save file',
21202122 'uploadedimage' => 'uploaded "[[$1]]"',
21212123 'overwroteimage' => 'uploaded a new version of "[[$1]]"',

Follow-up revisions

RevisionCommit summaryAuthorDate
r58067Follow-up r58066: Add new messages to maintenance scriptsraymond20:13, 23 October 2009

Comments

#Comment by Raymond (talk | contribs)   20:20, 23 October 2009

Hmmm missing the option 'Upload a new version of this file': http://translatewiki.net/wiki/File:Wildkatze2.jpg

#Comment by Bryan (talk | contribs)   20:27, 23 October 2009

uh.. strange.. can't reproduce.

#Comment by Bryan (talk | contribs)   22:16, 17 January 2010

Remove fixme, I can't reproduce it and I really can't see anything that could have caused this.

Status & tagging log