Example #1
0
 public function execute()
 {
     $user = $this->getUser();
     // Blocked users cannot submit new comments, and neither can those users
     // without the necessary privileges. Also prevent obvious cross-site request
     // forgeries (CSRF)
     $id = $this->getMain()->getVal('userid');
     $name = $this->getMain()->getVal('username');
     $size = $this->getMain()->getVal('size');
     if ($id == '') {
         if ($name != '') {
             $id = User::idFromName($name);
         } else {
             $id = 0;
         }
     }
     if ($size = '') {
         $size = 'l';
     }
     $avatar = new wAvatar($id, $size);
     $responseBody = array('state' => 200, 'message' => '', 'html' => $avatar->getAvatarHtml(), 'url' => $avatar->getAvatarUrlPath());
     $result = $this->getResult();
     $result->addValue($this->getModuleName(), 'res', $responseBody);
     return true;
 }
Example #2
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));
    }
}
Example #3
0
 /**
  * Format a row, providing the timestamp, links to the page/history, size, user links, and a comment
  *
  * @param $skin Skin to use
  * @param $result Result row
  * @return string
  */
 function formatResult($skin, $result)
 {
     global $wgLang, $wgContLang;
     $dm = $wgContLang->getDirMark();
     $statusMsg = @FamilyTreeUtil::$STATUS_MESSAGES[$result->fg_status];
     if (!$statusMsg) {
         $statusMsg = "Error {$result->fg_status}";
     }
     $statusDate = $wgLang->timeAndDate($result->fg_status_date, true);
     $statusReason = $result->fg_status_reason ? htmlspecialchars(': ' . $result->fg_status_reason) : '';
     $userid = User::idFromName($result->ft_user);
     $ulink = $skin->userLink($userid, $result->ft_user) . $skin->userToolLinks($userid, $result->ft_user);
     if ($result->fg_status >= FG_STATUS_READY && $result->fg_status <= FG_STATUS_ADMIN_REVIEW || $result->fg_status == FG_STATUS_HOLD) {
         $filename = '<a href="/gedcom/index.php?gedcomId=' . $result->fg_id . '" rel="nofollow">' . htmlspecialchars($result->fg_gedcom_filename) . '</a>';
     } else {
         $filename = htmlspecialchars($result->fg_gedcom_filename);
     }
     $filesize = wfMsgHtml('nbytes', $wgLang->formatNum(htmlspecialchars($result->fg_file_size)));
     $reviewerid = User::idFromName($result->fg_reviewer);
     if ($result->fg_reviewer) {
         $rlink = " reviewer: " . $skin->userLink($reviewerid, $result->fg_reviewer) . $skin->userToolLinks($reviewerid, $result->fg_reviewer);
     } else {
         if ($result->fg_status == FG_STATUS_ADMIN_REVIEW) {
             $rlink = ' <b>needs admin review</b>';
         } else {
             $rlink = '';
         }
     }
     return "{$statusDate} <i>{$statusMsg}{$statusReason}</i> {$dm}{$filename} [{$filesize}] {$ulink} {$dm}{$rlink}";
 }
function SpecialGetStatusByName($user_name)
{
    $output = '';
    $user_id = User::idFromName($user_name);
    if (empty($user_id)) {
        $output .= '<div>Wrong name or user does not exist</div>';
    } else {
        $us_class = new UserStatusClass();
        $currentStatus = $us_class->getStatus($user_id);
        $output .= "<br /><div>USER ID: {$user_id}, USERNAME: {$user_name}</div><br>";
        if (!empty($currentStatus)) {
            $output .= "CURRENT STATUS:<br />\n\t\t\t\t\t\t<input id=\"ush_delete\" type=\"button\" value=\"Delete\"\n\t\t\t\t\t\tonclick=\"javascript:UserStatus.specialStatusDelete('" . $currentStatus['us_id'] . "');\">" . $currentStatus['us_status'] . '<br /><br />';
        }
        $output .= 'HISTORY:<br />';
        $userHistory = $us_class->useStatusHistory('select', $user_id);
        if (empty($userHistory)) {
            $output .= 'No history';
        } else {
            foreach ($userHistory as $row) {
                $output .= "<input id=\"ush_delete\" type=\"button\" value=\"Delete\"\n\t\t\t\t\t\t\tonclick=\"javascript:UserStatus.specialHistoryDelete('" . $row['ush_id'] . "');\">" . $row['ush_timestamp'] . ' - ' . $row['ush_status'] . ' <br />';
            }
        }
    }
    return $output;
}
 /**
  * main()
  */
 public function execute($par)
 {
     global $wgRequest, $wgOut, $wgContLang;
     wfLoadExtensionMessages('Editcount');
     $target = isset($par) ? $par : $wgRequest->getText('username');
     list($username, $namespace) = $this->extractParamaters($target);
     $username = Title::newFromText($username);
     $username = is_object($username) ? $username->getText() : '';
     $uid = User::idFromName($username);
     if ($this->including()) {
         if ($namespace === null) {
             if ($uid != 0) {
                 $out = $wgContLang->formatNum(User::edits($uid));
             } else {
                 $out = "";
             }
         } else {
             $out = $wgContLang->formatNum($this->editsInNs($uid, $namespace));
         }
         $wgOut->addHTML($out);
     } else {
         if ($uid != 0) {
             $total = $this->getTotal($nscount = $this->editsByNs($uid));
         }
         $html = new EditcountHTML();
         $html->outputHTML($username, $uid, @$nscount, @$total);
     }
 }
 /**
  * Transforms content to be mobile friendly version.
  * Filters out various elements and runs the MobileFormatter.
  * @param OutputPage $out
  * @param string $mode mobile mode, i.e. stable or beta
  *
  * @return string
  */
 public static function DOMParse(OutputPage $out, $text = null, $isBeta = false)
 {
     $html = $text ? $text : $out->getHTML();
     $context = MobileContext::singleton();
     $formatter = MobileFormatter::newFromContext($context, $html);
     Hooks::run('MobileFrontendBeforeDOM', array($context, $formatter));
     $title = $out->getTitle();
     $isSpecialPage = $title->isSpecialPage();
     $formatter->enableExpandableSections($out->canUseWikiPage() && $out->getWikiPage()->getContentModel() == CONTENT_MODEL_WIKITEXT && array_search($title->getNamespace(), $context->getMFConfig()->get('MFNamespacesWithoutCollapsibleSections')) === false && $context->getRequest()->getText('action', 'view') == 'view');
     if ($context->getContentTransformations()) {
         // Remove images if they're disabled from special pages, but don't transform otherwise
         $formatter->filterContent(!$isSpecialPage);
     }
     $contentHtml = $formatter->getText();
     // If the page is a user page which has not been created, then let the
     // user know about it with pretty graphics and different texts depending
     // on whether the user is the owner of the page or not.
     if ($isBeta && $title->inNamespace(NS_USER) && !$title->isSubpage()) {
         $pageUserId = User::idFromName($title->getText());
         if ($pageUserId && !$title->exists()) {
             $pageUser = User::newFromId($pageUserId);
             $contentHtml = ExtMobileFrontend::getUserPageContent($out, $pageUser);
         }
     }
     return $contentHtml;
 }
 /**
  * Adds the message into the database
  *
  * @param $userName Mixed: the name of the user who's receiving the message
  * @param $type Integer: 0 by default
  * @param $message Mixed: message to be sent out
  */
 public function addMessage($userName, $type, $message)
 {
     $userId = User::idFromName($userName);
     $dbw = wfGetDB(DB_MASTER);
     $dbw->insert('user_system_messages', array('um_user_id' => $userId, 'um_user_name' => $userName, 'um_type' => $type, 'um_message' => $message, 'um_date' => date('Y-m-d H:i:s')), __METHOD__);
     $dbw->commit();
 }
Example #8
0
/**
 * Given a username, returns one of several codes to indicate whether it is valid to be a NEW username or not.
 *
 * Codes:
 * - OK: A user with this username may be created.
 * - INVALID: This is not a valid username.  This may mean that it is too long or has characters that aren't permitted, etc.
 * - EXISTS: A user with this name, so you cannot create one with this name.
 *
 * TODO: Is this a duplicate of user::isCreatableName()? It is important to note that wgWikiaMaxNameChars may be less than wgMaxNameChars which
 * is intentional because there are some long usernames that were created when only wgMaxNameChars limited to 255 characters and we still want
 * those usernames to be valid (so that they can still login), but we just don't want NEW accounts to be created above the length of wgWikiaMaxNameChars.
 */
function wfValidateUserName($uName)
{
    wfProfileIn(__METHOD__);
    $result = true;
    #wfMsg ('username-valid');
    $nt = Title::newFromText($uName);
    if (!User::isNotMaxNameChars($uName)) {
        $result = 'userlogin-bad-username-length';
    } elseif (is_null($nt)) {
        $result = 'userlogin-bad-username-character';
    } else {
        $uName = $nt->getText();
        if (!User::isCreatableName($uName)) {
            $result = 'userlogin-bad-username-character';
        } else {
            $dbr = wfGetDB(DB_SLAVE);
            $uName = $dbr->strencode($uName);
            if ($uName == '') {
                $result = 'userlogin-bad-username-character';
            } else {
                if (User::idFromName($uName) != 0) {
                    $result = 'userlogin-bad-username-taken';
                }
                global $wgReservedUsernames;
                if (in_array($uName, $wgReservedUsernames)) {
                    $result = 'userlogin-bad-username-taken';
                    // if we returned 'invalid', that would be confusing once a user checked and found that the name already met the naming requirements.
                }
            }
        }
    }
    wfProfileOut(__METHOD__);
    return $result;
}
function wfRelationshipRequestResponse($response, $requestId)
{
    global $wgUser;
    $out = '';
    $rel = new UserRelationship($wgUser->getName());
    if ($rel->verifyRelationshipRequest($requestId) == true) {
        $request = $rel->getRequest($requestId);
        $user_name_from = $request[0]['user_name_from'];
        $user_id_from = User::idFromName($user_name_from);
        $rel_type = strtolower($request[0]['type']);
        $response = isset($_POST['response']) ? $_POST['response'] : $response;
        $rel->updateRelationshipRequestStatus($requestId, intval($response));
        $avatar = new wAvatar($user_id_from, 'l');
        $avatar_img = $avatar->getAvatarURL();
        if ($response == 1) {
            $rel->addRelationship($requestId);
            $out .= "<div class=\"relationship-action red-text\">\n\t\t\t\t{$avatar_img}" . wfMessage("ur-requests-added-message-{$rel_type}", $user_name_from)->escaped() . '<div class="cleared"></div>
			</div>';
        } else {
            $out .= "<div class=\"relationship-action red-text\">\n\t\t\t\t{$avatar_img}" . wfMessage("ur-requests-reject-message-{$rel_type}", $user_name_from)->escaped() . '<div class="cleared"></div>
			</div>';
        }
        $rel->deleteRequest($requestId);
    }
    return $out;
}
 function handlePostBack()
 {
     global $wgRequest, $wgOut;
     $pagename = $wgRequest->getText('par_pagename');
     $pageid = Title::newFromText($pagename)->getArticleId();
     $submit = $wgRequest->getText('submit');
     if ($submit == "Add") {
         $username = $wgRequest->getText('newowner');
         $userid = User::idFromName($username);
         $this->handleAddUser($pagename, $pageid, $username, $userid);
     } else {
         $method = $wgRequest->getText("par_method");
         $username = $wgRequest->getText("par_username");
         $userid = User::idFromName($username);
         if ($method == "remove") {
             $this->handleRemoveUser($pagename, $pageid, $username, $userid);
         } else {
             if ($method == "assign") {
                 $this->handleAddUser($pagename, $pageid, $username, $userid);
             }
         }
     }
     $href = Title::newFromText("Special:PageOwner/{$pagename}")->getFullURL();
     $back = wfMsg('peerreview-back');
     $wgOut->addHTML("<br><a href=\"{$href}\">{$back}</a>");
 }
 /**
  * Show the special page
  *
  * @param $params Mixed: parameter(s) passed to the page or null
  */
 public function execute($params)
 {
     global $wgOut, $wgUser;
     // Check permissions
     if (!in_array('staff', $wgUser->getEffectiveGroups())) {
         throw new ErrorPageError('error', 'badaccess');
     }
     // Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return;
     }
     // If user is blocked, they don't need to access this page
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select('page', array('page_title'), array('page_namespace' => NS_USER), __METHOD__);
     $count = 0;
     // To avoid an annoying PHP notice
     foreach ($res as $row) {
         $user_name_title = Title::newFromDBkey($row->page_title);
         $user_name = $user_name_title->getText();
         $user_id = User::idFromName($user_name);
         if ($user_id > 0) {
             $s = $dbw->selectRow('user_profile', array('up_user_id'), array('up_user_id' => $user_id), __METHOD__);
             if ($s === false) {
                 $dbw->insert('user_profile', array('up_user_id' => $user_id, 'up_type' => 0), __METHOD__);
                 $count++;
             }
         }
     }
     $wgOut->addHTML(wfMsgExt('populate-user-profile-done', 'parsemag', $count));
 }
 public function getMessageParameters()
 {
     $params = parent::getMessageParameters();
     $type = $this->entry->getSubtype();
     $entry_params = $this->entry->getParameters();
     if ($type === 'approve') {
         $revid = $entry_params['revid'];
         $link = Linker::linkKnown($this->entry->getTarget(), wfMessage('moderation-log-diff', $revid)->text(), array('title' => wfMessage('tooltip-moderation-approved-diff')), array('diff' => $revid));
         $params[4] = Message::rawParam($link);
     } elseif ($type === 'reject') {
         $modid = $entry_params['modid'];
         $link = Linker::linkKnown(Title::makeTitle(NS_SPECIAL, "Moderation"), wfMessage('moderation-log-change', $modid)->text(), array('title' => wfMessage('tooltip-moderation-rejected-change')), array('modaction' => 'show', 'modid' => $modid));
         $params[4] = Message::rawParam($link);
         $userlink = Linker::userLink($entry_params['user'], $entry_params['user_text']);
         $params[5] = Message::rawParam($userlink);
     } elseif ($type === 'merge') {
         $revid = $entry_params['revid'];
         $modid = $entry_params['modid'];
         $link = Linker::linkKnown(Title::makeTitle(NS_SPECIAL, "Moderation"), wfMessage('moderation-log-change', $modid)->text(), array('title' => wfMessage('tooltip-moderation-rejected-change')), array('modaction' => 'show', 'modid' => $modid));
         $params[4] = Message::rawParam($link);
         $link = Linker::linkKnown($this->entry->getTarget(), wfMessage('moderation-log-diff', $revid)->text(), array('title' => wfMessage('tooltip-moderation-approved-diff')), array('diff' => $revid));
         $params[5] = Message::rawParam($link);
     } elseif ($type === 'approveall' || $type === 'rejectall' || $type === 'block' || $type === 'unblock') {
         $title = $this->entry->getTarget();
         $user_id = User::idFromName($title->getText());
         $link = Linker::userLink($user_id, $title->getText());
         $params[2] = Message::rawParam($link);
     }
     return $params;
 }
function wfUserSiteFollowsDetailsResponse($user_name, $t_name)
{
    $user_id = User::idFromName($user_name);
    $t_id = User::idFromName($t_name);
    $sites = UserSiteFollow::getFullFollowedSites($user_id, $t_id);
    $ret = array('success' => true, 'result' => $sites);
    $out = json_encode($ret);
    return $out;
}
Example #14
0
 /**
  * This is the method previously used to load block info in CheckUser etc
  * passing an empty value (empty string, null, etc) as the ip parameter bypasses IP lookup checks.
  *
  * This stopped working with r84475 and friends: regression being fixed for bug 29116.
  *
  * @dataProvider dataBug29116
  */
 function testBug29116LoadWithEmptyIp($vagueTarget)
 {
     $uid = User::idFromName('UTBlockee');
     $this->assertTrue($uid > 0, 'Must be able to look up the target user during tests');
     $block = new Block();
     $ok = $block->load($vagueTarget, $uid);
     $this->assertTrue($ok, "Block->load() with empty IP and user ID '{$uid}' should return a block");
     $this->assertTrue($this->block->equals($block), "Block->load() returns the same block as the one that was made when given empty ip param " . var_export($vagueTarget, true));
 }
Example #15
0
function wfAutoPageCreateIsAnonUserpage($title)
{
    if (User::IsIP($title)) {
        if (!User::idFromName($title)) {
            return true;
        }
    }
    return false;
}
function wfSendBoardMessage($user_name, $message, $message_type, $count)
{
    global $wgUser;
    $user_name = stripslashes($user_name);
    $user_name = urldecode($user_name);
    $user_id_to = User::idFromName($user_name);
    $b = new UserBoard();
    $m = $b->sendBoardMessage($wgUser->getID(), $wgUser->getName(), $user_id_to, $user_name, urldecode($message), $message_type);
    return $b->displayMessages($user_id_to, 0, $count);
}
 /**
  * main()
  */
 function execute($par = null)
 {
     global $wgRequest, $wgContLang, $wgSpecialEditCountExludedUsernames;
     $target = isset($par) ? $par : $wgRequest->getText('username');
     if (isset($par) && $par == "User") {
         global $wgUser;
         $target = $wgUser->getName();
     }
     list($username, $namespace) = $this->extractParamaters($target);
     $username = Title::newFromText($username);
     $username = is_object($username) ? $username->getText() : '';
     //FB#1040: block requests for 'Default' username, using a configurable array, could be useful for further blocks
     if (in_array(strtolower($username), $wgSpecialEditCountExludedUsernames)) {
         $uid = 0;
     } else {
         $uid = User::idFromName($username);
     }
     /* take archived revisions count for current wiki into consideration */
     $arcount = 0;
     if ($uid != 0) {
         $arcount = $this->editsArchived($uid);
     }
     if ($this->including()) {
         if (!isset($namespace)) {
             if ($uid != 0) {
                 // ADi: can't do that, we need count per wiki
                 // $out = $wgContLang->formatNum( User::edits( $uid ) );
                 $out = $wgContLang->formatNum($this->getTotal($this->editsByNs($uid)) + $arcount);
             } else {
                 $out = "";
             }
         } else {
             if ($uid != 0) {
                 $out = $wgContLang->formatNum($this->editsInNs($uid, $namespace));
             } else {
                 $out = "";
             }
         }
         $this->getOutput()->addHTML($out);
     } else {
         $nscount = $nscountAll = array();
         $total = $totalAll = 0;
         if ($uid != 0) {
             /* show results for current wiki */
             $total = $this->getTotal($nscount = $this->editsByNs($uid));
             $total += $arcount;
             // Let archived revisions have their share in percentage
             /* show results for all wikis */
             $totalAll = $this->getTotal($nscountAll = $this->editsByNsAll($uid));
         }
         $html = new EditcountHTML();
         $html->outputHTML($username, $uid, $nscount, $arcount, $total, $nscountAll, $totalAll, $this->refreshTimestamps);
     }
 }
function wfGetUserAvatar($username)
{
    if ($username == true) {
        $user_id = User::idFromName($username);
        $avatar = new wAvatar($user_id, 'm');
        $useravatar = $avatar->getAvatarURL();
        $ret = array('success' => true, 'result' => $useravatar);
        $out = json_encode($ret);
        return $out;
    }
}
 /** @inheritdoc **/
 public function __construct()
 {
     $title = $this->getTitle();
     if ($title->inNamespace(NS_USER) && !$title->isSubpage()) {
         $pageUserId = User::idFromName($title->getText());
         if ($pageUserId) {
             $this->pageUser = User::newFromId($pageUserId);
             $this->isUserPage = true;
         }
     }
     parent::__construct();
 }
 /**
  * @todo document
  * @param string $action
  * @param integer $ns
  * @param $title
  * @param $summary
  * @param $minoredit
  * @param $timestamp
  */
 function UserTalkUpdate($action, $ns, $title, $summary, $minoredit, $timestamp)
 {
     global $wgUser, $wgLang, $wgMemc, $wgDBname;
     $fname = 'UserTalkUpdate::UserTalkUpdate';
     $this->mAction = $action;
     $this->mNamespace = $ns;
     $this->mTitle = $title;
     $this->mSummary = $summary;
     $this->mMinorEdit = $minoredit;
     $this->mTimestamp = $timestamp;
     # If namespace isn't User_talk:, do nothing.
     if ($this->mNamespace != NS_USER_TALK) {
         return;
     }
     # If the user talk page is our own, clear the flag
     # when we are reading it or writing it.
     if (0 == strcmp(str_replace('_', ' ', $this->mTitle), $wgUser->getName())) {
         $wgUser->setNewtalk(0);
         $wgUser->saveSettings();
     } else {
         # Not ours.  If writing, then mark it as modified.
         $sql = false;
         if (1 == $this->mAction) {
             $user = new User();
             $user->setID(User::idFromName($this->mTitle));
             if ($id = $user->getID()) {
                 $sql = true;
                 $wgMemc->delete("{$wgDBname}:user:id:{$id}");
             } else {
                 if ($wgUser->isIP($this->mTitle)) {
                     # anonymous
                     $dbw =& wfGetDB(DB_MASTER);
                     $dbw->replace('watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')), array('wl_user' => 0, 'wl_namespace' => NS_USER_TALK, 'wl_title' => $this->mTitle, 'wl_notificationtimestamp' => 1), 'UserTalkUpdate');
                     $sql = true;
                     $wgMemc->delete("{$wgDBname}:newtalk:ip:{$this->mTitle}");
                 }
             }
             if ($sql && !$user->getNewtalk()) {
                 # create an artificial watchlist table entry for the owner X of the user_talk page X
                 # only insert if X is a real user and the page is not yet watched
                 # mark the changed watch-listed page with a timestamp, so that the page is listed with
                 # an "updated since your last visit" icon in the watch list, ...
                 # ... no matter, if the watching user has or has not indicated an email address in his/her preferences.
                 # We memorise the event of sending out a notification and use this as a flag to suppress
                 # further mails for changes on the same page for that watching user
                 $dbw =& wfGetDB(DB_MASTER);
                 $dbw->replace('watchlist', array(array('wl_user', 'wl_namespace', 'wl_title', 'wl_notificationtimestamp')), array('wl_user' => $id, 'wl_namespace' => NS_USER_TALK, 'wl_title' => $this->mTitle, 'wl_notificationtimestamp' => 1), 'UserTalkUpdate');
             }
         }
     }
 }
Example #21
0
/**
 * Return a list of Editors currently editing the article.
 * Based on an idea by Tim Starling.
 *
 * @author Ashar Voultoiz <*****@*****.**>
 * @author Tim Starling
 */
function wfAjaxShowEditors($articleId, $username)
{
    $articleId = intval($articleId);
    // Validate request
    $title = Title::newFromID($articleId);
    if (!$title) {
        return wfMsg('ajax-se-pagedoesnotexist');
    }
    if (User::idFromName($username) === null) {
        return wfMsg('ajax-se-usernotfound');
    }
    // When did the user started editing ?
    $dbr = wfGetDB(DB_SLAVE);
    $userStarted = $dbr->selectField('editings', 'editings_started', array('editings_user' => $username, 'editings_page' => $title->getArticleID()), __METHOD__);
    // He just started editing, assume NOW
    if (!$userStarted) {
        $userStarted = $dbr->timestamp();
    }
    # Either create a new entry or update the touched timestamp.
    # This is done using a unique index on the database :
    # `editings_page_started` (`editings_page`,`editings_user`,`editings_started`)
    $dbw = wfGetDB(DB_MASTER);
    $dbw->replace('editings', array('editings_page', 'editings_user', 'editings_started'), array('editings_page' => $title->getArticleID(), 'editings_user' => $username, 'editings_started' => $userStarted, 'editings_touched' => $dbw->timestamp()), __METHOD__);
    // Now we get the list of all watching users
    $dbr =& wfGetDB(DB_SLAVE);
    $res = $dbr->select('editings', array('editings_user', 'editings_started', 'editings_touched'), array('editings_page' => $title->getArticleID()), __METHOD__);
    $l = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
    $wikitext = '';
    $unix_now = wfTimestamp(TS_UNIX);
    $first = 1;
    while ($editor = $dbr->fetchObject($res)) {
        // Check idling time
        $idle = $unix_now - wfTimestamp(TS_UNIX, $editor->editings_touched);
        global $wgAjaxShowEditorsTimeout;
        if ($idle >= $wgAjaxShowEditorsTimeout) {
            $dbw->delete('editings', array('editings_page' => $title->getArticleID(), 'editings_user' => $editor->editings_user), __METHOD__);
            continue;
            // we will not show the user
        }
        if ($first) {
            $first = 0;
        } else {
            $wikitext .= ' ~  ';
        }
        $since = wfTimestamp(TS_DB, $editor->editings_started);
        $wikitext .= $since;
        $wikitext .= ' ' . $l->makeLinkObj(Title::makeTitle(NS_USER, $editor->editings_user), htmlspecialchars($editor->editings_user));
        $wikitext .= ' ' . wfMsg('ajax-se-idling', '<span>' . $idle . '</span>');
    }
    return $wikitext;
}
 /**
  * main()
  */
 function execute($par = null)
 {
     global $wgVersion, $wgRequest, $wgOut, $wgContLang, $wgSpecialEditCountExludedUsernames;
     if (version_compare($wgVersion, '1.5beta4', '<')) {
         $wgOut->versionRequired('1.5beta4');
         return;
     }
     $target = isset($par) ? $par : $wgRequest->getText('username');
     if (isset($par) && $par == "User") {
         global $wgUser;
         $target = $wgUser->getName();
     }
     list($username, $namespace) = $this->extractParamaters($target);
     $username = Title::newFromText($username);
     $username = is_object($username) ? $username->getText() : '';
     //FB#1040: block requests for 'Default' username, using a configurable array, could be useful for further blocks
     if (in_array(strtolower($username), $wgSpecialEditCountExludedUsernames)) {
         $uid = 0;
     } else {
         $uid = User::idFromName($username);
     }
     if ($this->including()) {
         if (!isset($namespace)) {
             if ($uid != 0) {
                 // ADi: can't do that, we need count per wiki
                 // $out = $wgContLang->formatNum( User::edits( $uid ) );
                 $out = $wgContLang->formatNum($this->getTotal($this->editsByNs($uid)));
             } else {
                 $out = "";
             }
         } else {
             if ($uid != 0) {
                 $out = $wgContLang->formatNum($this->editsInNs($uid, $namespace));
             } else {
                 $out = "";
             }
         }
         $wgOut->addHTML($out);
     } else {
         $nscount = $nscountAll = array();
         if ($uid != 0) {
             /* show results for current wiki */
             $total = $this->getTotal($nscount = $this->editsByNs($uid));
             /* show results for all wikis */
             $totalAll = $this->getTotal($nscountAll = $this->editsByNsAll($uid));
         }
         $html = new EditcountHTML();
         $html->outputHTML($username, $uid, @$nscount, @$total, @$nscountAll, @$totalAll);
     }
 }
 /**
  * Does the web server authentication piece of the LDAP plugin.
  *
  * @param $user User
  * @param $result bool
  * @return bool
  */
 public static function Authenticate($user, &$result = null)
 {
     /**
      * @var $wgAuth LdapAuthenticationPlugin
      */
     global $wgAuth;
     $wgAuth->printDebug("Entering AutoAuthentication.", NONSENSITIVE);
     if ($user->isLoggedIn()) {
         $wgAuth->printDebug("User is already logged in.", NONSENSITIVE);
         return true;
     }
     $wgAuth->printDebug("User isn't logged in, calling setup.", NONSENSITIVE);
     // Let regular authentication plugins configure themselves for auto
     // authentication chaining
     $wgAuth->autoAuthSetup();
     $autoauthname = $wgAuth->getConf('AutoAuthUsername');
     $wgAuth->printDebug("Calling authenticate with username ({$autoauthname}).", NONSENSITIVE);
     // The user hasn't already been authenticated, let's check them
     $authenticated = $wgAuth->authenticate($autoauthname, '');
     if (!$authenticated) {
         // If the user doesn't exist in LDAP, there isn't much reason to
         // go any further.
         $wgAuth->printDebug("User wasn't found in LDAP, exiting.", NONSENSITIVE);
         return false;
     }
     // We need the username that MediaWiki will always use, not necessarily the one we
     // get from LDAP.
     $mungedUsername = $wgAuth->getCanonicalName($autoauthname);
     $wgAuth->printDebug("User exists in LDAP; finding the user by name ({$mungedUsername}) in MediaWiki.", NONSENSITIVE);
     $localId = User::idFromName($mungedUsername);
     $wgAuth->printDebug("Got id ({$localId}).", NONSENSITIVE);
     // Is the user already in the database?
     if (!$localId) {
         $userAdded = self::attemptAddUser($user, $mungedUsername);
         if (!$userAdded) {
             $result = false;
             return false;
         }
     } else {
         $wgAuth->printDebug("User exists in local database, logging in.", NONSENSITIVE);
         $user->setID($localId);
         $user->loadFromId();
         $user->setCookies();
         $wgAuth->updateUser($user);
         wfSetupSession();
         $result = true;
     }
     return true;
 }
 public function addDBData()
 {
     for ($i = 1; $i <= 4; $i++) {
         $user = User::newFromName("UTLocalIdLookup{$i}");
         if ($user->getId() == 0) {
             $user->addToDatabase();
         }
         $this->localUsers["UTLocalIdLookup{$i}"] = $user->getId();
     }
     User::newFromName('UTLocalIdLookup1')->addGroup('local-id-lookup-test');
     $block = new Block(array('address' => 'UTLocalIdLookup3', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => false));
     $block->insert();
     $block = new Block(array('address' => 'UTLocalIdLookup4', 'by' => User::idFromName('UTSysop'), 'reason' => __METHOD__, 'expiry' => '1 day', 'hideName' => true));
     $block->insert();
 }
function wfSendBoardMessage($user_name, $message, $message_type, $count)
{
    global $wgUser;
    // Don't allow blocked users to send messages and also don't allow message
    // sending when the database is locked for some reason
    if ($wgUser->isBlocked() || wfReadOnly()) {
        return '';
    }
    $user_name = stripslashes($user_name);
    $user_name = urldecode($user_name);
    $user_id_to = User::idFromName($user_name);
    $b = new UserBoard();
    $m = $b->sendBoardMessage($wgUser->getID(), $wgUser->getName(), $user_id_to, $user_name, urldecode($message), $message_type);
    return $b->displayMessages($user_id_to, 0, $count);
}
 /**
  * @since 1.0
  *
  * @param &$id
  * @param &$username
  * @param &$realname
  * @param &$email
  *
  * @SuppressWarnings("CamelCaseVariableName")
  * @SuppressWarnings("SuperGlobals")
  */
 public function authenticate(&$identity, &$username, &$realname, &$email)
 {
     $username = self::getUsername();
     \Hooks::run('PluggableSSOSetUserName', [&$username]);
     $identity = \User::idFromName("{$username}");
     $session_variable = wfWikiID() . "_userid";
     if (isset($_SESSION[$session_variable]) && $identity != $_SESSION[$session_variable]) {
         wfDebugLog(__CLASS__, "Username didn't match session");
         return false;
     }
     \Hooks::run('PluggableSSORealName', array(&$realname));
     \Hooks::run('PluggableSSOEmail', array(&$email));
     $_SESSION[$session_variable] = $identity;
     return true;
 }
 function buildNavUrls()
 {
     global $wgTitle, $wgUser, $wgRequest;
     global $wgSiteSupportPage;
     $action = $wgRequest->getText('action');
     $oldid = $wgRequest->getVal('oldid');
     $diff = $wgRequest->getVal('diff');
     // XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
     $nav_urls = array();
     $nav_urls['mainpage'] = array('href' => htmlspecialchars($this->makeI18nUrl('mainpage')));
     $nav_urls['randompage'] = wfMsgForContent('randompage') != '-' ? array('href' => htmlspecialchars($this->makeSpecialUrl('Randompage'))) : false;
     $nav_urls['recentchanges'] = wfMsgForContent('recentchanges') != '-' ? array('href' => htmlspecialchars($this->makeSpecialUrl('Recentchanges'))) : false;
     $nav_urls['whatlinkshere'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Whatlinkshere', 'target=' . urlencode($this->thispage))));
     $nav_urls['currentevents'] = wfMsgForContent('currentevents') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('currentevents'))) : false;
     $nav_urls['portal'] = wfMsgForContent('portal') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('portal-url'))) : false;
     $nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Recentchangeslinked', 'target=' . urlencode($this->thispage))));
     $nav_urls['bugreports'] = wfMsgForContent('bugreports') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('bugreportspage'))) : false;
     $nav_urls['sitesupport'] = array('href' => htmlspecialchars($wgSiteSupportPage));
     $nav_urls['help'] = array('href' => htmlspecialchars($this->makeI18nUrl('helppage')));
     $nav_urls['upload'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Upload')));
     $nav_urls['specialpages'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Specialpages')));
     # Specific for mediawiki.org menu
     $nav_urls['aboutmediawiki'] = wfMsgForContent('aboutmediawiki') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('aboutmediawiki-url'))) : false;
     $nav_urls['projects'] = wfMsgForContent('projects') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('projects-url'))) : false;
     $nav_urls['membership'] = wfMsgForContent('membership') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('membership-url'))) : false;
     $nav_urls['pressroom'] = wfMsgForContent('pressroom') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('pressroom-url'))) : false;
     $nav_urls['software'] = wfMsgForContent('software') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('software-url'))) : false;
     $nav_urls['localchapters'] = wfMsgForContent('localchapters') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('localchapters-url'))) : false;
     $nav_urls['contactus'] = wfMsgForContent('contactus') != '-' ? array('href' => htmlspecialchars($this->makeI18nUrl('contactus-url'))) : false;
     if ($wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK) {
         $id = User::idFromName($wgTitle->getText());
         $ip = User::isIP($wgTitle->getText());
     } else {
         $id = 0;
         $ip = false;
     }
     if (0 != $wgUser->getID()) {
         # show only to signed in users
         if ($id) {
             # can only email non-anons
             $nav_urls['emailuser'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL())));
             # only non-anons have contrib list
             $nav_urls['contributions'] = array('href' => htmlspecialchars($this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL())));
         }
     }
     return $nav_urls;
 }
 public function execute($par)
 {
     global $wgFlaggedRevsOversightAge;
     $out = $this->getOutput();
     $request = $this->getRequest();
     $this->setHeaders();
     $this->namespace = $request->getInt('namespace');
     $this->level = $request->getIntOrNull('level');
     $this->status = $request->getIntOrNull('status');
     $this->automatic = $request->getIntOrNull('automatic');
     $this->user = $request->getVal('user');
     # Check if the user exists
     $usertitle = Title::makeTitleSafe(NS_USER, $this->user);
     $u = $usertitle ? User::idFromName($this->user) : false;
     # Are the dropdown params given even valid?
     $actions = $this->getActions();
     if (empty($actions)) {
         $out->addWikiMsg('qualityoversight-list', 0);
         $out->addWikiMsg('logempty');
         return;
     }
     # Get extra query conds
     $conds = array('log_namespace' => $this->namespace, 'log_action' => $actions);
     # Get cutoff time (mainly for performance)
     if (!$u) {
         $dbr = wfGetDB(DB_SLAVE);
         $cutoff_unixtime = time() - $wgFlaggedRevsOversightAge;
         $cutoff = $dbr->addQuotes($dbr->timestamp($cutoff_unixtime));
         $conds[] = "log_timestamp >= {$cutoff}";
     }
     # Create a LogPager item to get the results and a LogEventsList item to format them...
     $loglist = new LogEventsList($this->getContext()->getSkin(), $out, 0);
     $pager = new LogPager($loglist, 'review', $this->user, '', '', $conds);
     # Explanatory text
     $out->addWikiMsg('qualityoversight-list', $this->getLanguage()->formatNum($pager->getNumRows()));
     # Show form options
     $this->showForm();
     # Insert list
     $logBody = $pager->getBody();
     if ($logBody) {
         $out->addHTML($pager->getNavigationBar() . $loglist->beginLogEventsList() . $logBody . $loglist->endLogEventsList() . $pager->getNavigationBar());
     } else {
         $out->addWikiMsg('logempty');
     }
 }
Example #29
0
function GforgeMWAuth(&$param = 'default')
{
    $s = session_check_session_cookie(getStringFromCookie('session_ser'));
    if ($s) {
        $u = user_get_object($s);
        // print "Logged in as ".$u->getUnixName()." (according to gforge) ";
        $mwu = User::newFromId(User::idFromName(ucfirst($u->getUnixName())));
        $mwu->loadFromDatabase();
        $mwu->SetupSession();
        $mwu->SetCookies();
    } else {
        // print "Not logged in (according to gforge) ";
        $mwu = User::loadFromSession();
        if ($mwu->isLoggedIn()) {
            $mwu->logout();
        }
    }
}
Example #30
0
 function incOpinionsPublished()
 {
     $dbr =& wfGetDB(DB_MASTER);
     $sql = "SELECT cl_to FROM " . $dbr->tableName('categorylinks') . "  WHERE cl_from=" . $this->PageID;
     $res = $dbr->query($sql);
     while ($row = $dbr->fetchObject($res)) {
         $ctg = Title::makeTitle(14, $row->cl_to);
         $ctgname = $ctg->getText();
         if (strpos(strtoupper($ctgname), 'OPINIONS BY USER') !== false) {
             $user_name = trim(str_replace("Opinions by User", "", $ctgname));
             $u = User::idFromName($user_name);
             if ($u) {
                 $stats = new UserStatsTrack(1, $u, $user_name);
                 $stats->incOpinionsPublished();
             }
         }
     }
 }