WikiFile::delete PHP Method

delete() public method

Delete the file, or only an older revision of it.
public delete ( string $reason = null, string $archivename = null ) : boolean
$reason string Reason for the deletion
$archivename string The archive name of the older revision
return boolean True if file (revision) was deleted successfully
    public function delete($reason = null, $archivename = null)
    {
        $data = array('title' => 'File:' . $this->filename, 'token' => $this->edittoken);
        // Set options from arguments
        if (!is_null($reason)) {
            $data['reason'] = $reason;
        }
        if (!is_null($archivename)) {
            $data['oldimage'] = $archivename;
        }
        $r = $this->wikimate->delete($data);
        // The delete query
        // Check if it worked
        if (isset($r['delete'])) {
            if (is_null($archivename)) {
                $this->exists = false;
                // The file was deleted altogether
            }
            $this->error = null;
            // Reset the error status
            return true;
        }
        $this->error = $r['error'];
        // Return error response
        return false;
    }