示例#1
0
function wfSpecialRestrictUser($par = null)
{
    global $wgOut, $wgRequest;
    $user = $userOrig = null;
    if ($par) {
        $userOrig = $par;
    } elseif ($wgRequest->getVal('user')) {
        $userOrig = $wgRequest->getVal('user');
    } else {
        $wgOut->addHTML(RestrictUserForm::selectUserForm());
        return;
    }
    $isIP = User::isIP($userOrig);
    $user = $isIP ? $userOrig : User::getCanonicalName($userOrig);
    $uid = User::idFromName($user);
    if (!$uid && !$isIP) {
        $err = '<strong class="error">' . wfMsgHtml('restrictuser-notfound') . '</strong>';
        $wgOut->addHTML(RestrictUserForm::selectUserForm($userOrig, $err));
        return;
    }
    $wgOut->addHTML(RestrictUserForm::selectUserForm($user));
    UserRestriction::purgeExpired();
    $old = UserRestriction::fetchForUser($user, true);
    RestrictUserForm::pageRestrictionForm($uid, $user, $old);
    RestrictUserForm::namespaceRestrictionForm($uid, $user, $old);
    // Renew it after possible changes in previous two functions
    $old = UserRestriction::fetchForUser($user, true);
    if ($old) {
        $wgOut->addHTML(RestrictUserForm::existingRestrictions($old));
    }
}
function wfSpecialListUserRestrictions()
{
    global $wgOut, $wgRequest;
    $wgOut->addWikiMsg('listuserrestrictions-intro');
    $f = new SpecialListUserRestrictionsForm();
    $wgOut->addHTML($f->getHTML());
    if (!mt_rand(0, 10)) {
        UserRestriction::purgeExpired();
    }
    $pager = new UserRestrictionsPager($f->getConds());
    if ($pager->getNumRows()) {
        $wgOut->addHTML($pager->getNavigationBar() . Xml::tags('ul', null, $pager->getBody()) . $pager->getNavigationBar());
    } elseif ($f->getConds()) {
        $wgOut->addWikiMsg('listuserrestrictions-notfound');
    } else {
        $wgOut->addWikiMsg('listuserrestrictions-empty');
    }
}
function wfSpecialRemoveRestrictions()
{
    global $wgOut, $wgRequest, $wgUser, $wgLang;
    $sk = $wgUser->getSkin();
    $title = SpecialPage::getTitleFor('RemoveRestrictions');
    $id = $wgRequest->getVal('id');
    if (!is_numeric($id)) {
        $wgOut->addWikiMsg('removerestrictions-noid');
        return;
    }
    UserRestriction::purgeExpired();
    $r = UserRestriction::newFromId($id, true);
    if (!$r) {
        $wgOut->addWikiMsg('removerestrictions-wrongid');
        return;
    }
    $form = array();
    $form['removerestrictions-user'] = $sk->userLink($r->getSubjectId(), $r->getSubjectText()) . $sk->userToolLinks($r->getSubjectId(), $r->getSubjectText());
    $form['removerestrictions-type'] = UserRestriction::formatType($r->getType());
    if ($r->isPage()) {
        $form['removerestrictions-page'] = $sk->link($r->getPage());
    }
    if ($r->isNamespace()) {
        $form['removerestrictions-namespace'] = $wgLang->getDisplayNsText($r->getNamespace());
    }
    $form['removerestrictions-reason'] = Xml::input('reason');
    $result = null;
    if ($wgRequest->wasPosted() && $wgUser->matchEditToken($wgRequest->getVal('edittoken'))) {
        $result = wfSpecialRemoveRestrictionsProcess($r);
    }
    $wgOut->addWikiMsg('removerestrictions-intro');
    $wgOut->addHTML(Xml::fieldset(wfMsgHtml('removerestrictions-legend')));
    if ($result) {
        $wgOut->addHTML('<strong class="success">' . wfMsgExt('removerestrictions-success', 'parseinline', $r->getSubjectText()) . '</strong>');
    }
    $wgOut->addHTML(Xml::openElement('form', array('action' => $title->getLocalUrl(array('id' => $id)), 'method' => 'post')));
    $wgOut->addHTML(Xml::buildForm($form, 'removerestrictions-submit'));
    $wgOut->addHTML(Xml::hidden('id', $r->getId()));
    $wgOut->addHTML(Xml::hidden('title', $title->getPrefixedDbKey()));
    $wgOut->addHTML(Xml::hidden('edittoken', $wgUser->editToken()));
    $wgOut->addHTML("</form></fieldset>");
}