WikiFile::uploadCommon PHP Method

uploadCommon() private method

$text is only used for the page contents of a new file, not an existing one (update that via WikiPage::setText()). If no $text is specified, $comment will be used as new page text.
private uploadCommon ( array $params, string $comment, string $text = null, boolean $overwrite = false ) : boolean
$params array The upload parameters
$comment string Upload comment for the file
$text string The article text for the file page
$overwrite boolean True to overwrite existing file
return boolean True if uploading was successful
    private function uploadCommon(array $params, $comment, $text = null, $overwrite = false)
    {
        // Check whether to overwrite existing file
        if ($this->exists && !$overwrite) {
            $this->error = array();
            $this->error['file'] = 'Cannot overwrite existing file';
            return false;
        }
        // Collect upload parameters
        $params['filename'] = $this->filename;
        $params['comment'] = $comment;
        $params['ignorewarnings'] = $overwrite;
        $params['token'] = $this->edittoken;
        if (!is_null($text)) {
            $params['text'] = $text;
        }
        // Upload file, or handle error
        $r = $this->wikimate->upload($params);
        if (isset($r['upload']['result']) && $r['upload']['result'] == 'Success') {
            // Update the file's properties
            $this->info = $r['upload']['imageinfo'];
            $this->error = null;
            // Reset the error status
            return true;
        }
        // Return error response
        if (isset($r['error'])) {
            $this->error = $r['error'];
        } else {
            $this->error = array();
            $this->error['file'] = 'Unexpected upload response: ' . $r['upload']['result'];
        }
        return false;
    }