r102924 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102923‎ | r102924 | r102925 >
Date:23:19, 13 November 2011
Author:aaron
Status:deferred
Tags:
Comment:
Factored out a UserAccountRequest::relPathFromKey() function and killed ugly duplication
Modified paths:
  • /trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/backend/UserAccountRequest.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/business/AccountConfirmSubmission.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/frontend/specialpages/actions/ConfirmAccount_body.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/frontend/specialpages/actions/UserCredentials_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/frontend/specialpages/actions/UserCredentials_body.php
@@ -202,8 +202,8 @@
203203 $request->response()->header( 'Pragma: no-cache' );
204204
205205 $repo = new FSRepo( $wgConfirmAccountFSRepos['accountcreds'] );
206 - $path = $repo->getZonePath( 'public' ).'/'.
207 - $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 206+ $path = $repo->getZonePath( 'public' ) . '/' .
 207+ UserAccountRequest::relPathFromKey( $key );
208208 StreamFile::stream( $path );
209209 }
210210
Index: trunk/extensions/ConfirmAccount/frontend/specialpages/actions/ConfirmAccount_body.php
@@ -430,8 +430,8 @@
431431 $request->response()->header( 'Pragma: no-cache' );
432432
433433 $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
434 - $path = $repo->getZonePath( 'public' ).'/'.
435 - $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 434+ $path = $repo->getZonePath( 'public' ) . '/' .
 435+ UserAccountRequest::relPathFromKey( $key );
436436
437437 StreamFile::stream( $path );
438438 }
Index: trunk/extensions/ConfirmAccount/backend/ConfirmAccount.class.php
@@ -21,8 +21,8 @@
2222 foreach ( $res as $row ) {
2323 $key = $row->acr_storage_key;
2424 if ( $key ) {
25 - $path = $repo->getZonePath( 'public' ).'/'.
26 - $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 25+ $path = $repo->getZonePath( 'public' ) . '/' .
 26+ UserAccountRequest::relPathFromKey( $key );
2727 if ( $path && file_exists($path) ) {
2828 unlink($path);
2929 }
Index: trunk/extensions/ConfirmAccount/backend/UserAccountRequest.php
@@ -452,4 +452,14 @@
453453 unset( $list[count( $list ) - 1] );
454454 return $list;
455455 }
 456+
 457+ /**
 458+ * Get path relative to zone for an account request attachment file.
 459+ * This assures compatibility with the old FileStore sytem.
 460+ * @param $key string File storage key
 461+ * @return string
 462+ */
 463+ public static function relPathFromKey( $key ) {
 464+ return "{$key[0]}/{$key[0]}{$key[1]}/{$key[0]}{$key[1]}{$key[2]}/{$key}";
 465+ }
456466 }
Index: trunk/extensions/ConfirmAccount/business/AccountRequestSubmission.php
@@ -164,7 +164,7 @@
165165 # Start a transaction, move file from temp to account request directory.
166166 $repo = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
167167 $key = sha1_file( $this->attachmentTempPath ) . '.' . $finalExt;
168 - $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 168+ $pathRel = UserAccountRequest::relPathFromKey( $key );
169169 $triplet = array( $this->attachmentTempPath, 'public', $pathRel );
170170 $status = $repo->storeBatch( array( $triplet ), FSRepo::OVERWRITE_SAME ); // save!
171171 if ( !$status->isOk() ) {
Index: trunk/extensions/ConfirmAccount/business/AccountConfirmSubmission.php
@@ -190,7 +190,7 @@
191191 $repoOld = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
192192 $repoNew = new FSRepo( $wgConfirmAccountFSRepos['accountcreds'] );
193193
194 - $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 194+ $pathRel = UserAccountRequest::relPathFromKey( $key );
195195 $oldPath = $repoOld->getZonePath( 'public' ) . '/' . $pathRel;
196196
197197 $triplet = array( $oldPath, 'public', $pathRel );
@@ -299,7 +299,7 @@
300300 $key = $accReq->getFileStorageKey();
301301 if ( $key ) {
302302 $repoOld = new FSRepo( $wgConfirmAccountFSRepos['accountreqs'] );
303 - $pathRel = $key[0].'/'.$key[0].$key[1].'/'.$key[0].$key[1].$key[2].'/'.$key;
 303+ $pathRel = UserAccountRequest::relPathFromKey( $key );
304304 $oldPath = $repoOld->getZonePath( 'public' ) . '/' . $pathRel;
305305 if ( file_exists( $oldPath ) ) {
306306 unlink( $oldPath ); // delete!

Status & tagging log