Make WordPress Core

Ticket #10170: 10170.2.patch

File 10170.2.patch, 6.1 KB (added by hakre, 15 years ago)

Extended Patch.

  • wp-admin/includes/class-wp-filesystem-direct.php

     
    1717class WP_Filesystem_Direct extends WP_Filesystem_Base {
    1818        var $permission = null;
    1919        var $errors = null;
     20        /**
     21         * constructor
     22         *
     23         * @param $arg mixed ingored argument
     24         */
    2025        function WP_Filesystem_Direct($arg) {
    2126                $this->method = 'direct';
    2227                $this->errors = new WP_Error();
    23                 $this->permission = umask();
     28                $this->permission = 0777;
    2429        }
     30        /**
     31         * connect filesystem.
     32         *
     33         * @return bool Returns true on success or false on failure (always true for WP_Filesystem_Direct).
     34         */
    2535        function connect() {
    2636                return true;
    2737        }
     38        /**
     39         * default permission setter
     40         *
     41         * @param $perm int default permission mask (octal).
     42         * @return void
     43         */
    2844        function setDefaultPermissions($perm) {
    2945                $this->permission = $perm;
    3046        }
     47        /**
     48         * Reads entire file into a string
     49         *
     50         * @param $file string Name of the file to read.
     51         * @return string|bool The function returns the read data or false on failure.
     52         */
    3153        function get_contents($file) {
    3254                return @file_get_contents($file);
    3355        }
     56        /**
     57         * Reads entire file into an array
     58         *
     59         * @param $file string Path to the file.
     60         * @return array|bool the file in an array. Each element of the array corresponds to a line in the file, with the newline still attached. Upon failure, get_contents_array returns false.
     61         */
    3462        function get_contents_array($file) {
    3563                return @file($file);
    3664        }
     65        /**
     66         * Write a string to a file
     67         *
     68         * @param $file string Path to the file where to write the data.
     69         * @param $contents string The data to write.
     70         * @param $mode int (optional) The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'.
     71         * @param $type string (optional) The type parameter specifies an additional type of access you require to the file. It may be any of the following: +
     72         * @return bool False upon failure.
     73         */
    3774        function put_contents($file, $contents, $mode = false, $type = '') {
    3875                if ( ! ($fp = @fopen($file, 'w' . $type)) )
    3976                        return false;
    4077                @fwrite($fp, $contents);
    4178                @fclose($fp);
    42                 $this->chmod($file,$mode);
     79                $this->chmod($file, $mode);
    4380                return true;
    4481        }
     82        /**
     83         * Gets the current working directory
     84         *
     85         * @return string|bool the current working directory on success, or false on failure.
     86         */
    4587        function cwd() {
    4688                return @getcwd();
    4789        }
     90        /**
     91         * Change directory
     92         *
     93         * @param $dir string The new current directory.
     94         * @return bool Returns true on success or false on failure.
     95         */
    4896        function chdir($dir) {
    4997                return @chdir($dir);
    5098        }
     99        /**
     100         * Changes file group
     101         *
     102         * @param $file string Path to the file.
     103         * @param $group mixed A group name or number.
     104         * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False.
     105         * @return bool Returns true on success or false on failure.
     106         */
    51107        function chgrp($file, $group, $recursive = false) {
    52108                if ( ! $this->exists($file) )
    53109                        return false;
     
    63119
    64120                return true;
    65121        }
     122        /**
     123         * Changes file mode
     124         *
     125         * @param $file string Path to the file.
     126         * @param $mode int (optional) The mode parameter consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order. One component can be computed by adding up the needed permissions for that target user base. Number 1 means that you grant execute rights, number 2 means that you make the file writeable, number 4 means that you make the file readable. Add up these numbers to specify needed rights. You can also read more about modes on Unix systems with 'man 1 chmod' and 'man 2 chmod'.
     127         * @param $recursive bool (optional) If set True changes file group recursivly. Defaults to False.
     128         * @return bool Returns true on success or false on failure.
     129         */
    66130        function chmod($file, $mode = false, $recursive = false) {
    67131                if ( ! $mode )
    68132                        $mode = $this->permission;
    69133                if ( ! $this->exists($file) )
    70134                        return false;
    71135                if ( ! $recursive )
    72                         return @chmod($file,$mode);
     136                        return @chmod($file, $mode);
    73137                if ( ! $this->is_dir($file) )
    74138                        return @chmod($file, $mode);
    75139                //Is a directory, and we want recursive
     
    80144
    81145                return true;
    82146        }
     147        /**
     148         * Changes file owner
     149         *
     150         * @param $file string Path to the file.
     151         * @param $owner mixed A user name or number.
     152         * @param $recursive bool (optional) If set True changes file owner recursivly. Defaults to False.
     153         * @return bool Returns true on success or false on failure.
     154         */
    83155        function chown($file, $owner, $recursive = false) {
    84156                if ( ! $this->exists($file) )
    85157                        return false;
     
    94166                }
    95167                return true;
    96168        }
     169        /**
     170         * Gets file owner
     171         *
     172         * @param $file string Path to the file.
     173         * @return string Username of the user. This is a short, usually less than 16 character "handle" of the user, not the real, full name.
     174         */
    97175        function owner($file) {
    98176                $owneruid = @fileowner($file);
    99177                if ( ! $owneruid )
     
    103181                $ownerarray = posix_getpwuid($owneruid);
    104182                return $ownerarray['name'];
    105183        }
     184        /**
     185         * Gets file permissions
     186         *
     187         * FIXME does not handle errors in fileperms()
     188         *
     189         * @param $file string Path to the file.
     190         * @return string Mode of the file (3 chars).
     191         */
    106192        function getchmod($file) {
    107193                return substr(decoct(@fileperms($file)),3);
    108194        }
     
    202288
    203289                if ( ! @mkdir($path, $chmod) )
    204290                        return false;
     291                chmod($path, $chmod); // chmod $path because mkdir applies umask to $chmod
    205292                if ( $chown )
    206293                        $this->chown($path, $chown);
    207294                if ( $chgrp )