r68951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68950‎ | r68951 | r68952 >
Date:16:01, 3 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on porting WP filesystem abstraction classes
Modified paths:
  • /trunk/extensions/Deployment/Deployment.i18n.php (modified) (history)
  • /trunk/extensions/Deployment/includes/Filesystem.php (modified) (history)
  • /trunk/extensions/Deployment/includes/filesystems/FtpFilesystem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Deployment/Deployment.i18n.php
@@ -17,4 +17,14 @@
1818 $messages['en'] = array(
1919 // General
2020 'deployment-desc' => 'Provides a way to install extensions via GUI and update them and the wiki itself via another GUI',
 21+
 22+ // Filesystem: Direct
 23+
 24+
 25+ // Filesystem: FTP
 26+ 'deploy-ftp-not-loaded' => 'The FTP PHP extension is not available',
 27+ 'deploy-ftp-ssl-not-loaded' => 'The loaded FTP PHP extension does not support SSL',
 28+ 'deploy-ftp-username-required' => 'FTP username is required',
 29+ 'deploy-ftp-password-required' => 'FTP password is required',
 30+ 'deploy-ftp-hostname-required' => 'FTP hostname is required',
2131 );
Index: trunk/extensions/Deployment/includes/filesystems/FtpFilesystem.php
@@ -18,16 +18,78 @@
1919 class FtpFilesystem extends Filesystem {
2020
2121 /**
 22+ * A list of options.
 23+ *
 24+ * @var array
 25+ */
 26+ protected $options = array();
 27+
 28+ /**
 29+ * The FTP connection link.
 30+ *
 31+ * @var unknown_type
 32+ */
 33+ protected $connection;
 34+
 35+ /**
2236 * Constructor.
2337 */
24 - public function __construct() {
 38+ public function __construct( $options ) {
 39+ $this->options = $options;
2540
 41+ // Check if possible to use ftp functions.
 42+ if ( !extension_loaded('ftp') ) {
 43+ $this->addError( 'deploy-ftp-not-loaded' );
 44+ return false;
 45+ }
 46+
 47+ // Check for missing required options.
 48+ if ( !array_key_exists( 'username', $options ) ) {
 49+ $this->addError( 'deploy-ftp-username-required' );
 50+ }
 51+
 52+ if ( !array_key_exists( 'password', $options ) ) {
 53+ $this->addError( 'deploy-ftp-password-required' );
 54+ }
 55+
 56+ if ( !array_key_exists( 'hostname', $options ) ) {
 57+ $this->addError( 'deploy-ftp-hostname-required' );
 58+ }
 59+
 60+ // Set default option values for those not provided.
 61+ if ( !array_key_exists( 'port', $options ) ) {
 62+ $options['port'] = 21;
 63+ }
 64+
 65+ if ( !array_key_exists( 'timeout', $options ) ) {
 66+ $options['timeout'] = 240;
 67+ }
 68+
 69+ // Other option handling.
 70+ $options['ssl'] = array_key_exists( 'connection_type', $options ) && $options['connection_type'] == 'ftps';
 71+
 72+ // Store the options.
 73+ $this->options = $options;
2674 }
2775
2876 /**
2977 * @see Filesystem::connect
3078 */
3179 public function connect() {
 80+ if ( $this->options['ssl'] && function_exists( 'ftp_ssl_connect' ) ) {
 81+ // TODO
 82+ }
 83+ else {
 84+ // If this is true, ftp_ssl_connect was not defined, so add an error.
 85+ if ( $this->options['ssl'] ) {
 86+ $this->addError( 'deploy-ftp-ssl-not-loaded' );
 87+ }
 88+
 89+ // TODO
 90+ }
 91+
 92+ // TODO
 93+
3294 return true;
3395 }
3496
Index: trunk/extensions/Deployment/includes/Filesystem.php
@@ -25,6 +25,13 @@
2626 abstract class Filesystem {
2727
2828 /**
 29+ * Array for storing error messages.
 30+ *
 31+ * @var array of string
 32+ */
 33+ protected $errors = array();
 34+
 35+ /**
2936 * Creates a connection to the filesystem.
3037 *
3138 * @return boolean Indicates whether the connection has been established.
@@ -265,7 +272,7 @@
266273 */
267274 public function __construct() {
268275 // TODO
269 - }
 276+ }
270277
271278 public static function findFolder() {
272279 // TODO
@@ -323,6 +330,34 @@
324331 */
325332 public function removeDir( $path, $recursive = false ) {
326333 $this->delete( $path, $recursive );
 334+ }
 335+
 336+ /**
 337+ * Returns an array with all errors.
 338+ *
 339+ * @return array
 340+ */
 341+ public function getErrors() {
 342+ return $this->errors;
327343 }
328344
 345+ /**
 346+ * Adds an error message created from a message key to the log file and stores it for further use.
 347+ *
 348+ * @param string $errorMessageKey
 349+ */
 350+ protected function addError( $errorMessageKey ) {
 351+ $this->addErrorMessage( wfMsg( $errorMessageKey ) );
 352+ }
 353+
 354+ /**
 355+ * Adds an error message to the log file and stores it for further use.
 356+ *
 357+ * @param string $error
 358+ */
 359+ protected function addErrorMessage( $error ) {
 360+ $this->errors[] = $error;
 361+ wfDebug( $error );
 362+ }
 363+
329364 }
\ No newline at end of file

Status & tagging log