def upload(url, filename = nil)
      params = {
        action: 'upload',
        url: url,
        token: get_token
      }

      filename = filename.nil? ? url.split('/')[-1] : filename.sub(/^File:/, '')

      ext = filename.split('.')[-1]
      allowed_extensions = get_allowed_file_extensions
      raise MediaWiki::Butt::UploadInvalidFileExtError.new unless allowed_extensions.include?(ext)

      params[:filename] = filename

      response = post(params)

      response.dig('upload', 'warnings')&.each do |warning|
        warn warning
      end

      return true if response.dig('upload', 'result') == 'Success'
      raise MediaWiki::Butt::EditError.new(response.dig('error', 'code') || 'Unknown error code')
    end
def upload(url, filename = nil)
      params = {
        action: 'upload',
        url: url,
        token: get_token
      }

      filename = filename.nil? ? url.split('/')[-1] : filename.sub(/^File:/, '')

      ext = filename.split('.')[-1]
      allowed_extensions = get_allowed_file_extensions
      raise MediaWiki::Butt::UploadInvalidFileExtError.new unless allowed_extensions.include?(ext)

      params[:filename] = filename

      response = post(params)

      response.dig('upload', 'warnings')&.each do |warning|
        warn warning
      end

      return true if response.dig('upload', 'result') == 'Success'
      raise MediaWiki::Butt::EditError.new(response.dig('error', 'code') || 'Unknown error code')
    end
Uploads a file from a URL.
 @param url [String] The URL to the file.
 @param filename [String] The preferred filename. This can include File: at the beginning, but it will be
   removed through regex. Optional. If omitted, it will be everything after the last slash in the URL.
 @return [Boolean] Whether the upload was successful. It is likely that if it returns false, it also raised a
   warning.
 @raise [UploadInvalidFileExtError] When the file extension provided is not valid for the wiki.
 @raise [EditError]
 @see https://www.mediawiki.org/wiki/API:Changing_wiki_content Changing wiki content on the MediaWiki API
   documentation
 @see https://www.mediawiki.org/wiki/API:Upload MediaWiki Upload API Docs
 @since 0.3.0