/**
 * Send the message if the UserBoard class exists (duh!) and the welcome
 * message has some content.
 *
 * @param $user User: the new User object being created
 * @param $byEmail Boolean: true if the account was created by e-mail
 * @return Boolean: true
 */
function wfSendUserBoardMessageOnRegistration($user, $byEmail)
{
    if (class_exists('UserBoard') && $user instanceof User) {
        $message = trim(wfMsgForContent('user-board-welcome-message'));
        // If the welcome message is empty, short-circuit right away.
        if (wfEmptyMsg('user-board-welcome-message', $message)) {
            return true;
        }
        // Just quit if we're in read-only mode
        if (wfReadOnly()) {
            return true;
        }
        $dbr = wfGetDB(DB_SLAVE);
        // Get all users who are in the 'sysop' group and aren't blocked from
        // the database
        $res = $dbr->select(array('user_groups', 'ipblocks'), array('ug_group', 'ug_user'), array('ug_group' => 'sysop', 'ipb_user' => null), __METHOD__, array(), array('ipblocks' => array('LEFT JOIN', 'ipb_user = ug_user')));
        $adminUids = array();
        foreach ($res as $row) {
            $adminUids[] = $row->ug_user;
        }
        // Pick one UID from the array of admin user IDs
        $random = array_rand(array_flip($adminUids), 1);
        $sender = User::newFromId($random);
        $senderUid = $sender->getId();
        $senderName = $sender->getName();
        // Send the message
        $b = new UserBoard();
        $b->sendBoardMessage($senderUid, $senderName, $user->getId(), $user->getName(), wfMsgForContent('user-board-welcome-message', $senderName));
    }
    return true;
}
Example #2
0
 /**
  * Execute the job
  *
  * @return bool
  */
 public function run()
 {
     // Load data from $this->params and $this->title
     $article = new WikiPage($this->title);
     $user_ids_to = $this->params['user_ids_to'];
     $message = $this->params['message'];
     $sender = $this->params['sender'];
     $user = User::newFromId($sender);
     $b = new UserBoard();
     $count = 0;
     $i = count($user_ids_to);
     $per_num = 100;
     $num = $i / $per_num;
     $int_num = ceil($num);
     for ($k = 1; $k <= $int_num; $k++) {
         $star = $per_num * ($k - 1);
         $res_arr = array_slice($user_ids_to, $star, $per_num);
         foreach ($res_arr as $user_id) {
             $user_to = User::newFromId($user_id);
             $user->loadFromId();
             $user_name = $user_to->getName();
             $b->sendBoardMessage($user->getID(), $user->getName(), $user_id, $user_name, $message, 1);
             // $count++;
         }
         wfDebug('Sending Board Blast batch ' . $k . '............................................');
         // ob_flush();
         //    flush();
     }
     return true;
 }
 /**
  * Show the special page
  *
  * @param $params Mixed: parameter(s) passed to the page or null
  */
 public function execute($params)
 {
     global $wgRequest, $wgOut, $wgUser, $wgUserBoardScripts;
     // Add CSS & JS
     $wgOut->addExtensionStyle($wgUserBoardScripts . '/BoardBlast.css');
     $wgOut->addScriptFile($wgUserBoardScripts . '/BoardBlast.js');
     $output = '';
     // This feature is available only to logged-in users.
     if (!$wgUser->isLoggedIn()) {
         $wgOut->setPageTitle(wfMsg('boardblastlogintitle'));
         $wgOut->addWikiMsg('boardblastlogintext');
         return '';
     }
     if ($wgRequest->wasPosted()) {
         $wgOut->setPageTitle(wfMsg('messagesenttitle'));
         $b = new UserBoard();
         $count = 0;
         $user_ids_to = explode(',', $wgRequest->getVal('ids'));
         foreach ($user_ids_to as $user_id) {
             $user = User::newFromId($user_id);
             $user->loadFromId();
             $user_name = $user->getName();
             $b->sendBoardMessage($wgUser->getID(), $wgUser->getName(), $user_id, $user_name, $wgRequest->getVal('message'), 1);
             $count++;
         }
         $output .= wfMsg('messagesentsuccess');
     } else {
         $wgOut->setPageTitle(wfMsg('boardblasttitle'));
         $output .= $this->displayForm();
     }
     $wgOut->addHTML($output);
 }
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);
}
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);
}