/**
 * @todo document
 */
function wfSpecialIpblocklist()
{
    global $wgUser, $wgOut, $wgRequest;
    $ip = $wgRequest->getVal('wpUnblockAddress', $wgRequest->getVal('ip'));
    $reason = $wgRequest->getText('wpUnblockReason');
    $action = $wgRequest->getText('action');
    $ipu = new IPUnblockForm($ip, $reason);
    if ("success" == $action) {
        $ipu->showList(wfMsgWikiHtml('unblocked', htmlspecialchars($ip)));
    } else {
        if ("submit" == $action && $wgRequest->wasPosted() && $wgUser->matchEditToken($wgRequest->getVal('wpEditToken'))) {
            if (!$wgUser->isAllowed('block')) {
                $wgOut->sysopRequired();
                return;
            }
            $ipu->doSubmit();
        } else {
            if ("unblock" == $action) {
                $ipu->showForm("");
            } else {
                $ipu->showList("");
            }
        }
    }
}
/**
 * @param $ip part of title: Special:Ipblocklist/<ip>.
 * @todo document
 */
function wfSpecialIpblocklist($ip = '')
{
    global $wgUser, $wgOut, $wgRequest;
    $ip = $wgRequest->getVal('ip', $ip);
    $ip = trim($wgRequest->getVal('wpUnblockAddress', $ip));
    $id = $wgRequest->getVal('id');
    $reason = $wgRequest->getText('wpUnblockReason');
    $action = $wgRequest->getText('action');
    $successip = $wgRequest->getVal('successip');
    $ipu = new IPUnblockForm($ip, $id, $reason);
    if ($action == 'unblock') {
        # Check permissions
        if (!$wgUser->isAllowed('block')) {
            $wgOut->permissionRequired('block');
            return;
        }
        # Check for database lock
        if (wfReadOnly()) {
            $wgOut->readOnlyPage();
            return;
        }
        # Show unblock form
        $ipu->showForm('');
    } elseif ($action == 'submit' && $wgRequest->wasPosted() && $wgUser->matchEditToken($wgRequest->getVal('wpEditToken'))) {
        # Check permissions
        if (!$wgUser->isAllowed('block')) {
            $wgOut->permissionRequired('block');
            return;
        }
        # Check for database lock
        if (wfReadOnly()) {
            $wgOut->readOnlyPage();
            return;
        }
        # Remove blocks and redirect user to success page
        $ipu->doSubmit();
    } elseif ($action == 'success') {
        # Inform the user of a successful unblock
        # (No need to check permissions or locks here,
        # if something was done, then it's too late!)
        if (substr($successip, 0, 1) == '#') {
            // A block ID was unblocked
            $ipu->showList($wgOut->parse(wfMsg('unblocked-id', $successip)));
        } else {
            // A username/IP was unblocked
            $ipu->showList($wgOut->parse(wfMsg('unblocked', $successip)));
        }
    } else {
        # Just show the block list
        $ipu->showList('');
    }
}