Browser class

From Apibot
Revision as of 23:37, 20 April 2013 by Grigor Gatchev (talk | contribs) (some info)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Like any other MediaWiki bot, Apibot connects to the wiki over Internet, using the HTTP or HTTPS protocol. This exchange is done by an object of class called Browser.


Creating an object of this class requires one parameter - an array with the bot parameters. (These can be defaults for the browser settings, see below. The setting name is the array key, and the value is the array value.)

Public properties

Browser settings

  • $agent - the HTTP User-Agent string for the browser (default - "Mozilla/5.0 (Apibot Browser)")
  • $http_version - the HTTP protocol version supported (default - "HTTP/1.1")
  • $http_user - a HTTP authentication user (default - none)
  • $http_pass - a HTTP authentication password (default - none)
  • $conn_timeout - HTTP connection opening timeout, in seconds (default - 120)
  • $max_get_len - the maximal GET request length supported by the server (default - 2048 bytes)
  • $content_type - an array with the HTTP content MIME types for text (default - "application/x-www-form-urlencoded") and binary (default - "multipart/form-data") content
  • $mime_boundary - MIME boundary string for POST data (default - "Apibot-Browser-$1"); the "$1" parameter in it will be replaced with a random text string
  • $use_compression - whether to attempt using data compression, if the MW server supports it (default - true)
  • $speed_limits - an array with speed limits the bot should not exceed (default - array () )
  • $dump_level - how much info about the data exchange should be dumped to the standard output (default - 0)

Browser data

  • $last_postdata_size - size in bytes of the last postdata sent
  • $last_times - microtime timestamps of the last postdata sent. (Will have the keys 'open', 'beg', 'sent_headers', 'sent_data', 'got_headers', 'got_data', 'closed'.)
  • $last_compressed - the last data received were compressed by this method (NULL - none)
  • $headers - an array with the last headers received; each member is an array with the keys 'name' and 'value'
  • $cookies - an array with the cookies set; the cookie names are keys, and the values are arrays with keys 'content' and 'exp' (expiration time)
  • $content - the content returned by the server (uncompressed)
  • $bytecounters - an array with info how much data is transferred. Has two keys: 'total' (since starting the bot or resetting the counters) and 'last' (the last transfer only). Their values are arrays with two keys: 'DL' (download) and 'UL' (upload). Each of the values of these is an array with two keys: 'c' (compressed size, if the transfer is compressed) and 'u' (uncompressed size). The values of the sizes are in bytes.

Public methods

  • flush() - clears the $content property
  • last_time() - returns an average of the last transfer beginning and its end
  • reset_bytecounters() - resets (zeroes) the $bytecounters property
  • find_header ( $name ) - returns the first header with this name, false if no such header
  • get_cookie ( $name ) - returns the cookie with this name, false if no such cookie
  • set_cookie ( $name, $cookie ) - sets this cookie to the browser
  • del_cookie ( $name ) - deletes this cookie from the browser
  • set_cookie_expiration ( $name, $secs ) - set the expiration of this cookie to this value
  • modify_cookie_expiration ( $name, $secs ) - add (or subtract, if negative) this value to the expiration of this cookie
  • xfer ( $uri, $vars = array(), $files = array(), $mustbeposted = false ) - make a HTTP (HTTPS, if the URI starts with "https://") transfer with this URI, variables and files. If $mustbeposted is true, forces using POST method, otherwise uses POST if files are present or the request size is over $max_get_len, and GET otherwise