Skip to content
Mike.lifeguard edited this page Aug 13, 2011 · 1 revision

Logging in

$bot->login({
    username => $username,
    password => $password,
}) or die "Login failed";

Logs the use $username in, optionally using $password.

First, an attempt will be made to use cookies to log in. If this fails, an attempt will be made to use the password provided to log in, if any. If the login was successful, returns true; false otherwise.

It is usually more convenient to give login data to the constructor instead.

Once logged in, attempt to do some simple auto-configuration. At present, this consists of:

  • Warning if the account doesn't have the bot flag, and isn't a sysop account.
  • Setting the use of apihighlimits if the account has that userright.
  • Setting an appropriate default assert.

Set autoconfig => 0 to skip autoconfiguration.

If your wiki is protected by basic auth, provide credentials in the hash:

$bot->login({
    username => $username,
    password => $password,
    basic_auth => {
        netloc => "private.wiki.com:80",
        realm  => "Authentication Realm",
        uname  => "Basic auth username",
        pass   => "Basic auth password",
    }
}) or die "couldn't log in";

If you use login() without specifying a password, MediaWiki::Bot will automatically check to see whether a .perlwikipedia-$botUserName-cookies file exists in the working directory. If it does, the login cookies will automatically be loaded, essentially logging the script in without actually logging in. Note that using cookies saves a network round-trip!