Make WordPress Core

Ticket #18476: 18476.2.diff

File 18476.2.diff, 18.9 KB (added by DrewAPicture, 13 years ago)

Refresh at r25558

  • src/wp-admin/includes/class-wp-filesystem-base.php

     
    11<?php
    22/**
    3  * Base WordPress Filesystem.
     3 * Base WordPress Filesystem
    44 *
    55 * @package WordPress
    66 * @subpackage Filesystem
     
    99/**
    1010 * Base WordPress Filesystem class for which Filesystem implementations extend
    1111 *
    12  * @since 2.5
     12 * @since 2.5.0
    1313 */
    1414class WP_Filesystem_Base {
    1515        /**
    1616         * Whether to display debug data for the connection.
    1717         *
    18          * @since 2.5
    1918         * @access public
     19         * @since 2.5.0
    2020         * @var bool
    2121         */
    2222        var $verbose = false;
     
    2424        /**
    2525         * Cached list of local filepaths to mapped remote filepaths.
    2626         *
    27          * @since 2.7
    2827         * @access private
     28         * @since 2.7.0
    2929         * @var array
    3030         */
    3131        var $cache = array();
     
    3333        /**
    3434         * The Access method of the current connection, Set automatically.
    3535         *
    36          * @since 2.5
    3736         * @access public
     37         * @since 2.5.0
    3838         * @var string
    3939         */
    4040        var $method = '';
    4141
    4242        /**
    43          * Returns the path on the remote filesystem of ABSPATH
     43         * Constructor (empty).
     44         */
     45        function __construct() {}
     46
     47        /**
     48         * Return the path on the remote filesystem of ABSPATH.
    4449         *
    45          * @since 2.7
    4650         * @access public
     51         * @since 2.7.0
     52         *
    4753         * @return string The location of the remote path.
    4854         */
    4955        function abspath() {
     
    5561        }
    5662
    5763        /**
    58          * Returns the path on the remote filesystem of WP_CONTENT_DIR
     64         * Return the path on the remote filesystem of WP_CONTENT_DIR.
    5965         *
    60          * @since 2.7
    6166         * @access public
     67         * @since 2.7.0
    6268         * @return string The location of the remote path.
    6369         */
    6470        function wp_content_dir() {
     
    6672        }
    6773
    6874        /**
    69          * Returns the path on the remote filesystem of WP_PLUGIN_DIR
     75         * Return the path on the remote filesystem of WP_PLUGIN_DIR.
    7076         *
    71          * @since 2.7
    7277         * @access public
     78         * @since 2.7.0
    7379         *
    7480         * @return string The location of the remote path.
    7581         */
     
    7884        }
    7985
    8086        /**
    81          * Returns the path on the remote filesystem of the Themes Directory
     87         * Return the path on the remote filesystem of the Themes Directory.
    8288         *
    83          * @since 2.7
    8489         * @access public
     90         * @since 2.7.0
    8591         *
    86          * @param string $theme The Theme stylesheet or template for the directory
     92         * @param string $theme The Theme stylesheet or template for the directory.
    8793         * @return string The location of the remote path.
    8894         */
    8995        function wp_themes_dir( $theme = false ) {
     
    97103        }
    98104
    99105        /**
    100          * Returns the path on the remote filesystem of WP_LANG_DIR
     106         * Return the path on the remote filesystem of WP_LANG_DIR.
    101107         *
     108         * @access public
    102109         * @since 3.2.0
    103          * @access public
    104110         *
    105111         * @return string The location of the remote path.
    106112         */
     
    109115        }
    110116
    111117        /**
    112          * Locates a folder on the remote filesystem.
     118         * Locate a folder on the remote filesystem.
    113119         *
    114          * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
    115          *
    116          * @since 2.5
    117          * @deprecated 2.7
    118120         * @access public
     121         * @since 2.5.0
     122         * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() instead.
     123         * @see WP_Filesystem::abspath()
     124         * @see WP_Filesystem::wp_content_dir()
     125         * @see WP_Filesystem::wp_plugins_dir()
     126         * @see WP_Filesystem::wp_themes_dir()
     127         * @see WP_Filesystem::wp_lang_dir()
    119128         *
    120          * @param string $base The folder to start searching from
    121          * @param bool $echo True to display debug information
     129         * @param string $base The folder to start searching from.
     130         * @param bool   $echo True to display debug information.
     131         *                     Default false.
    122132         * @return string The location of the remote path.
    123133         */
    124         function find_base_dir($base = '.', $echo = false) {
     134        function find_base_dir( $base = '.', $echo = false ) {
    125135                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    126136                $this->verbose = $echo;
    127137                return $this->abspath();
    128138        }
    129139
    130140        /**
    131          * Locates a folder on the remote filesystem.
     141         * Locate a folder on the remote filesystem.
    132142         *
    133          * Deprecated; use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
    134          *
    135          * @since 2.5
    136          * @deprecated 2.7
    137143         * @access public
     144         * @since 2.5.0
     145         * @deprecated 2.7.0 use WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir() methods instead.
     146         * @see WP_Filesystem::abspath()
     147         * @see WP_Filesystem::wp_content_dir()
     148         * @see WP_Filesystem::wp_plugins_dir()
     149         * @see WP_Filesystem::wp_themes_dir()
     150         * @see WP_Filesystem::wp_lang_dir()
    138151         *
    139          * @param string $base The folder to start searching from
    140          * @param bool $echo True to display debug information
     152         * @param string $base The folder to start searching from.
     153         * @param bool   $echo True to display debug information.
    141154         * @return string The location of the remote path.
    142155         */
    143         function get_base_dir($base = '.', $echo = false) {
     156        function get_base_dir( $base = '.', $echo = false ) {
    144157                _deprecated_function(__FUNCTION__, '2.7', 'WP_Filesystem::abspath() or WP_Filesystem::wp_*_dir()' );
    145158                $this->verbose = $echo;
    146159                return $this->abspath();
    147160        }
    148161
    149162        /**
    150          * Locates a folder on the remote filesystem.
     163         * Locate a folder on the remote filesystem.
    151164         *
    152          * Assumes that on Windows systems, Stripping off the Drive letter is OK
    153          * Sanitizes \\ to / in windows filepaths.
     165         * Assumes that on Windows systems, Stripping off the Drive
     166         * letter is OK Sanitizes \\ to / in windows filepaths.
    154167         *
    155          * @since 2.7
    156168         * @access public
     169         * @since 2.7.0
    157170         *
    158          * @param string $folder the folder to locate
     171         * @param string $folder the folder to locate.
    159172         * @return string The location of the remote path.
    160173         */
    161         function find_folder($folder) {
     174        function find_folder( $folder ) {
    162175
    163176                if ( isset( $this->cache[ $folder ] ) )
    164177                        return $this->cache[ $folder ];
     
    215228        }
    216229
    217230        /**
    218          * Locates a folder on the remote filesystem.
     231         * Locate a folder on the remote filesystem.
    219232         *
    220          * Expects Windows sanitized path
     233         * Expects Windows sanitized path.
    221234         *
    222          * @since 2.7
    223235         * @access private
     236         * @since 2.7.0
    224237         *
    225          * @param string $folder the folder to locate
    226          * @param string $base the folder to start searching from
    227          * @param bool $loop if the function has recursed, Internal use only
     238         * @param string $folder The folder to locate.
     239         * @param string $base   The folder to start searching from.
     240         * @param bool   $loop   If the function has recursed, Internal use only.
    228241         * @return string The location of the remote path.
    229242         */
    230         function search_for_folder($folder, $base = '.', $loop = false ) {
     243        function search_for_folder( $folder, $base = '.', $loop = false ) {
    231244                if ( empty( $base ) || '.' == $base )
    232245                        $base = trailingslashit($this->cwd());
    233246
     
    282295        }
    283296
    284297        /**
    285          * Returns the *nix style file permissions for a file
     298         * Return the *nix-style file permissions for a file.
    286299         *
    287          * From the PHP documentation page for fileperms()
     300         * From the PHP documentation page for fileperms().
    288301         *
    289302         * @link http://docs.php.net/fileperms
    290          * @since 2.5
     303         *
    291304         * @access public
     305         * @since 2.5.0
    292306         *
    293          * @param string $file string filename
    294          * @return string *nix style representation of permissions
     307         * @param string $file String filename.
     308         * @return string The *nix-style representation of permissions.
    295309         */
    296         function gethchmod($file){
     310        function gethchmod( $file ){
    297311                $perms = $this->getchmod($file);
    298312                if (($perms & 0xC000) == 0xC000) // Socket
    299313                        $info = 's';
     
    336350        }
    337351
    338352        /**
    339          * Converts *nix style file permissions to a octal number.
     353         * Convert *nix-style file permissions to a octal number.
    340354         *
    341355         * Converts '-rw-r--r--' to 0644
    342356         * From "info at rvgate dot nl"'s comment on the PHP documentation for chmod()
    343357         *
    344358         * @link http://docs.php.net/manual/en/function.chmod.php#49614
    345          * @since 2.5
     359         *
    346360         * @access public
     361         * @since 2.5.0
    347362         *
    348          * @param string $mode string *nix style file permission
     363         * @param string $mode string The *nix-style file permission.
    349364         * @return int octal representation
    350365         */
    351366        function getnumchmodfromh($mode) {
     
    369384        }
    370385
    371386        /**
    372          * Determines if the string provided contains binary characters.
     387         * Determine if the string provided contains binary characters.
    373388         *
    374          * @since 2.7
    375389         * @access private
     390         * @since 2.7.0
    376391         *
    377          * @param string $text String to test against
    378          * @return bool true if string is binary, false otherwise
     392         * @param string $text String to test against.
     393         * @return bool true if string is binary, false otherwise.
    379394         */
    380395        function is_binary( $text ) {
    381396                return (bool) preg_match( '|[^\x20-\x7E]|', $text ); // chr(32)..chr(127)
    382397        }
    383 }
     398
     399        /**
     400         * Change the ownership of a file / folder.
     401         *
     402         * Default behavior is to do nothing, override this in your subclass, if desired.
     403         *
     404         * @since Unknown
     405         *
     406         * @param string $file      Path to the file.
     407         * @param mixed  $owner     A user name or number.
     408         * @param bool   $recursive (optional) If set True changes file owner recursivly. Defaults to False.
     409         * @return bool Returns true on success or false on failure.
     410         */
     411        function chown( $file, $owner, $recursive = false ) {
     412                return false;
     413        }
     414
     415        /**
     416         * Connect filesystem.
     417         *
     418         * @since Unknown
     419         *
     420         * @return bool True on success or false on failure (always true for WP_Filesystem_Direct).
     421         */
     422        function connect() {
     423                return true;
     424        }
     425
     426        /**
     427         * Read entire file into a string.
     428         *
     429         * @since Unknown
     430         *
     431         * @param string $file Name of the file to read.
     432         * @return string|bool Returns the read data or false on failure.
     433         */
     434        function get_contents( $file ) {
     435                return false;
     436        }
     437
     438        /**
     439         * Read entire file into an array.
     440         *
     441         * @since Unknown
     442         *
     443         * @param string $file Path to the file.
     444         * @return array|bool the file contents in an array or false on failure.
     445         */
     446        function get_contents_array( $file ) {
     447                return false;
     448        }
     449
     450        /**
     451         * Write a string to a file.
     452         *
     453         * @since Unknown
     454         *
     455         * @param string $file     Remote path to the file where to write the data.
     456         * @param string $contents The data to write.
     457         * @param int    $mode     (optional) The file permissions as octal number, usually 0644.
     458         * @return bool False on failure.
     459         */
     460        function put_contents( $file, $contents, $mode = false ) {
     461                return false;
     462        }
     463
     464        /**
     465         * Get the current working directory.
     466         *
     467         * @since Unknown
     468         *
     469         * @return string|bool The current working directory on success, or false on failure.
     470         */
     471        function cwd() {
     472                return false;
     473        }
     474
     475        /**
     476         * Change current directory.
     477         *
     478         * @since Unknown
     479         *
     480         * @param string $dir The new current directory.
     481         * @return bool Returns true on success or false on failure.
     482         */
     483        function chdir( $dir ) {
     484                return false;
     485        }
     486
     487        /**
     488         * Change the file group.
     489         *
     490         * @since Unknown
     491         *
     492         * @param string $file      Path to the file.
     493         * @param mixed  $group     A group name or number.
     494         * @param bool   $recursive (optional) If set True changes file group recursivly. Defaults to False.
     495         * @return bool Returns true on success or false on failure.
     496         */
     497        function chgrp( $file, $group, $recursive = false ) {
     498                return false;
     499        }
     500
     501        /**
     502         * Change filesystem permissions.
     503         *
     504         * @since Unknown
     505         *
     506         * @param string $file      Path to the file.
     507         * @param int    $mode      (optional) The permissions as octal number, usually 0644 for files, 0755 for dirs.
     508         * @param bool   $recursive (optional) If set True changes file group recursivly. Defaults to False.
     509         * @return bool Returns true on success or false on failure.
     510         */
     511        function chmod( $file, $mode = false, $recursive = false ) {
     512                return false;
     513        }
     514
     515        /**
     516         * Get the file owner.
     517         *
     518         * @since Unknown
     519         *
     520         * @param string $file Path to the file.
     521         * @return string|bool Username of the user or false on error.
     522         */
     523        function owner($file) {
     524                return false;
     525        }
     526
     527        /**
     528         * Get the file's group.
     529         *
     530         * @since Unknown
     531         *
     532         * @param string $file Path to the file.
     533         * @return string|bool The group or false on error.
     534         */
     535        function group($file) {
     536                return false;
     537        }
     538
     539        /**
     540         * Copy a file.
     541         *
     542         * @since Unknown
     543         *
     544         * @param string $source
     545         * @param string $destination
     546         * @param bool   $overwrite
     547         * @param int    $mode
     548         * @return bool
     549         */
     550        function copy( $source, $destination, $overwrite = false, $mode = false ) {
     551                return false;
     552        }
     553
     554        /**
     555         * Move a file.
     556         *
     557         * @since Unknown
     558         *
     559         * @param string $source
     560         * @param string $destination
     561         * @param bool   $overwrite
     562         * @return bool
     563         */
     564        function move( $source, $destination, $overwrite = false ) {
     565                return false;
     566        }
     567
     568        /**
     569         * Delete a file / directory.
     570         *
     571         * @since Unknown
     572         *
     573         * @param string $file
     574         * @param bool   $recursive
     575         * @param type   $type      (f = file, other values = directory).
     576         * @return bool
     577         */
     578        function delete( $file, $recursive = false, $type = false ) {
     579                return false;
     580        }
     581
     582        /**
     583         * Check if a file exists.
     584         *
     585         * @since Unknown
     586         *
     587         * @param string $file
     588         * @return bool
     589         */
     590        function exists($file) {
     591                return false;
     592        }
     593
     594        /**
     595         * Check if a file is a regular file.
     596         *
     597         * @since Unknown
     598         *
     599         * @param string $file
     600         * @return bool
     601         */
     602        function is_file( $file ) {
     603                return false;
     604        }
     605
     606        /**
     607         * Check if a path is a directory.
     608         *
     609         * @since Unknown
     610         *
     611         * @param string $path
     612         * @return bool
     613         */
     614        function is_dir( $path ) {
     615                return false;
     616        }
     617
     618        /**
     619         * Check if a file is readable.
     620         *
     621         * @since Unknown
     622         *
     623         * @param string $file
     624         * @return bool
     625         */
     626        function is_readable( $file ) {
     627                return false;
     628        }
     629
     630        /**
     631         * Check if a file is writable.
     632         *
     633         * @since Unknown
     634         *
     635         * @param string $file
     636         * @return bool
     637         */
     638        function is_writable( $file ) {
     639                return false;
     640        }
     641
     642        /**
     643         * Get a file's last access time.
     644         *
     645         * @since Unknown
     646         *
     647         * @param string $file
     648         * @return int|bool
     649         */
     650        function atime( $file ) {
     651                return false;
     652        }
     653
     654        /**
     655         * Get a file's last modified time.
     656         *
     657         * @since Unknown
     658         *
     659         * @param string $file
     660         * @return int|bool
     661         */
     662        function mtime( $file ) {
     663                return false;
     664        }
     665
     666        /**
     667         * Get a file's size.
     668         *
     669         * @since Unknown
     670         *
     671         * @param string $file
     672         * @return int|bool
     673         */
     674        function size( $file ) {
     675                return false;
     676        }
     677
     678        /**
     679         * Update a file's access time and modified time.
     680         *
     681         * @since Unknown
     682         *
     683         * @param string $file
     684         * @param int    $time
     685         * @param int    $atime
     686         * @return bool
     687         */
     688        function touch( $file, $time = 0, $atime = 0 ) {
     689                return false;
     690        }
     691
     692        /**
     693         * Create a directory.
     694         *
     695         * @since Unknown
     696         *
     697         * @param string           $path
     698         * @param string|int|false $chmod
     699         * @param string|int|false $chown
     700         * @param string|int|false $chgrp
     701         * @return bool
     702         */
     703        function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
     704                return false;
     705        }
     706
     707        /**
     708         * Delete a directory.
     709         *
     710         * @since Unknown
     711         *
     712         * @param string $path
     713         * @param bool   $recursive
     714         * @return bool
     715         */
     716        function rmdir( $path, $recursive = false ) {
     717                return false;
     718        }
     719
     720        /**
     721         * Get a recursive directory listing.
     722         *
     723         * @since Unknown
     724         *
     725         * @param string $path
     726         * @param bool   $include_hidden
     727         * @param bool   $recursive
     728         * @return array|bool
     729         */
     730        function dirlist( $path, $include_hidden = true, $recursive = false ) {
     731                return false;
     732        }
     733
     734} // WP_Filesystem_Base
  • src/wp-admin/includes/class-wp-filesystem-direct.php

     
    1515 * @uses WP_Filesystem_Base Extends class
    1616 */
    1717class WP_Filesystem_Direct extends WP_Filesystem_Base {
    18         var $errors = null;
     18
    1919        /**
    2020         * constructor
    2121         *
     
    2727        }
    2828
    2929        /**
    30          * connect filesystem.
    31          *
    32          * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct).
    33          */
    34         function connect() {
    35                 return true;
    36         }
    37 
    38         /**
    3930         * Reads entire file into a string
    4031         *
    4132         * @param string $file Name of the file to read.
     
    185176         * Gets file owner
    186177         *
    187178         * @param string $file Path to the file.
    188          * @return string Username of the user.
     179         * @return string|bool Username of the user or false on error.
    189180         */
    190181        function owner($file) {
    191182                $owneruid = @fileowner($file);
  • src/wp-admin/includes/class-wp-filesystem-ftpext.php

     
    181181                return (bool)@ftp_chmod($this->link, $mode, $file);
    182182        }
    183183
    184         function chown($file, $owner, $recursive = false ) {
    185                 return false;
    186         }
    187 
    188184        function owner($file) {
    189185                $dir = $this->dirlist($file);
    190186                return $dir[$file]['owner'];
  • src/wp-admin/includes/class-wp-filesystem-ftpsockets.php

     
    187187                return $this->ftp->chmod($file, $mode);
    188188        }
    189189
    190         function chown($file, $owner, $recursive = false ) {
    191                 return false;
    192         }
    193 
    194190        function owner($file) {
    195191                $dir = $this->dirlist($file);
    196192                return $dir[$file]['owner'];
  • src/wp-admin/includes/class-wp-filesystem-ssh2.php

     
    11<?php
    22/**
    3  * WordPress SSH2 Filesystem.
     3 * WordPress Filesystem Class for implementing SSH2
    44 *
    5  * @package WordPress
    6  * @subpackage Filesystem
    7  */
    8 
    9 /**
    10  * WordPress Filesystem Class for implementing SSH2.
    11  *
    125 * To use this class you must follow these steps for PHP 5.2.6+
    136 *
    147 * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes
     
    3528 *
    3629 * Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents'
    3730 *
    38  * @since 2.7
     31 * @since 2.7.0
     32 *
    3933 * @package WordPress
    4034 * @subpackage Filesystem
    41  * @uses WP_Filesystem_Base Extends class
    4235 */
    4336class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
    4437
     
    208201                return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true);
    209202        }
    210203
    211         function chown($file, $owner, $recursive = false ) {
     204        /**
     205         * Change the ownership of a file / folder.
     206         *
     207         * @since Unknown
     208         *
     209         * @param string $file    Path to the file.
     210         * @param mixed  $owner   A user name or number.
     211         * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False.
     212         * @return bool Returns true on success or false on failure.
     213         */
     214        function chown( $file, $owner, $recursive = false ) {
    212215                if ( ! $this->exists($file) )
    213216                        return false;
    214217                if ( ! $recursive || ! $this->is_dir($file) )