/**
  * Show the special page
  *
  * @param $par Mixed: parameter passed to the page or null
  */
 public function execute($par)
 {
     global $wgUploadPath, $wgUser, $wgHuijiPrefix;
     $templateParser = new TemplateParser(__DIR__ . '/pages');
     $out = $this->getOutput();
     $user = $this->getUser();
     if (!$user->isAllowed('AdminDashboard')) {
         $out->permissionRequired('AdminDashboard');
         return;
     }
     // Set the page title, robot policies, etc.
     $this->setHeaders();
     // Add CSS
     $out->addModules('ext.socialprofile.userprofile.css');
     $out->addModules('ext.socialprofile.admindashboard.css');
     // Add js and message
     // $out->addModules( 'skin.bootstrapmediawiki.huiji.getRecordsInterface.js' );
     $out->addModules('ext.socialprofile.admindashboard.js');
     $out->addModules('ext.socialprofile.userprofile.js');
     $output = '';
     // Prevent E_NOTICE
     $yesterday = date("Y-m-d", strtotime("-1 day"));
     $totaledit = SiteStats::edits();
     $ueb = new UserEditBox();
     $rankInfo = AllSitesInfo::getAllSitesRankData($wgHuijiPrefix, $yesterday);
     $usf = new UserSiteFollow();
     $follows = $usf->getSiteFollowers('', $wgHuijiPrefix);
     // print_r($follows);
     $followCount = count($follows);
     if ($followCount >= 8) {
         $follows = array_slice($follows, 0, 8);
         $display = '';
     } else {
         $display = 'none';
     }
     $newFollow = array();
     foreach ($follows as $value) {
         $arr['user_name'] = $value['user_name'];
         $userPage = Title::makeTitle(NS_USER, $value['user_name']);
         $arr['user_url'] = htmlspecialchars($userPage->getFullURL());
         $arr['follow_date'] = wfMessage('comments-time-ago', HuijiFunctions::getTimeAgo(strtotime($value['follow_date'])))->text();
         $newFollow[] = $arr;
     }
     $sentToAll = SpecialPage::getTitleFor('SendToFollowers')->getFullURL();
     $showMore = SpecialPage::getTitleFor('EditRank')->getFullURL();
     $rightsManage = SpecialPage::getTitleFor('用户权限')->getFullURL();
     $blockUsers = SpecialPage::getTitleFor('封禁')->getFullURL();
     $freezeUsers = SpecialPage::getTitleFor('解除封禁')->getFullURL();
     $replaceText = SpecialPage::getTitleFor('替换文本')->getFullURL();
     $siteRankPage = SpecialPage::getTitleFor('SiteRank')->getFullURL();
     $allSpecial = SpecialPage::getTitleFor('特殊页面')->getFullURL();
     $siteAvatar = (new wSiteAvatar($wgHuijiPrefix, 'l'))->getAvatarHtml();
     $token = $user->getEditToken();
     if (is_null($newFollow)) {
         $newFollow = false;
     }
     $output .= $templateParser->processTemplate('admin_index', array('siteRank' => isset($rankInfo[0]['site_rank']) ? $rankInfo[0]['site_rank'] : '暂无', 'siteScore' => isset($rankInfo[0]['site_score']) ? $rankInfo[0]['site_score'] : '暂无', 'yesterdayCount' => UserSiteFollow::getFollowerCountOneday($wgHuijiPrefix, $yesterday), 'totalCount' => UserSiteFollow::getFollowerCount($wgHuijiPrefix), 'yesterdayEdit' => $ueb->getSiteEditCount('', $wgHuijiPrefix, $yesterday, $yesterday), 'totalEdit' => $totaledit, 'totalView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, '', ''), 'yesterdayView' => $ueb->getSiteViewCount(-1, $wgHuijiPrefix, $yesterday, $yesterday), 'newFollow' => $newFollow, 'sendToAll' => $sentToAll, 'showMore' => $showMore, 'display' => $display, 'rightsManage' => $rightsManage, 'blockUsers' => $blockUsers, 'freezeUsers' => $freezeUsers, 'replaceText' => $replaceText, 'siteRankPage' => $siteRankPage, 'allSpecial' => $allSpecial, 'siteAvatar' => $siteAvatar, 'token' => $token));
     $out->addHtml($output);
 }
 public function execute()
 {
     $fb = $this->getMain()->getVal('feedback');
     $user = $this->getUser();
     $subject = "用户bug反馈";
     $body = json_decode($fb);
     if ($user != '') {
         if ($body->note != '') {
             $trueSubject = $user->getName() . ":" . $body->note;
         } else {
             $trueSubject = $user->getName() . ":" . $body->note;
         }
     } else {
         if ($body->note != '') {
             $trueSubject = $body->note;
         } else {
             $trueSubject = $subject;
         }
     }
     $fs = wfGetFS(FS_OSS);
     $time = microtime();
     $id = HuijiFunctions::getTradeNo('FB');
     $fs->put("Feedback/{$id}.html", $body->html);
     $data = str_replace('data:image/png;base64,', '', $body->img);
     $data = str_replace(' ', '+', $data);
     $data = base64_decode($data);
     $source_img = imagecreatefromstring($data);
     imagepng($source_img, "/tmp/{$id}.png", 3);
     $fs->put("Feedback/{$id}.png", file_get_contents("/tmp/{$id}.png"));
     imagedestroy($source_img);
     $trueBody = $this->getSection('Issue');
     $trueBody .= $body->note;
     $trueBody .= $this->getSection('Cookie');
     foreach ($_COOKIE as $key => $value) {
         $trueBody .= $key . ":" . $value . ";" . PHP_EOL;
     }
     $trueBody .= $this->getSection('URL');
     $trueBody .= $body->url;
     $trueBody .= $this->getSection('源代码');
     $trueBody .= "http://fs.huijiwiki.com/Feedback/{$id}.html";
     $trueBody .= $this->getSection('Agent');
     foreach ($body->browser as $key => $value) {
         if (is_array($value)) {
             $trueBody .= $key . ":" . implode(", ", $value) . ";" . PHP_EOL;
         } else {
             $trueBody .= $key . ":" . $value . ";" . PHP_EOL;
         }
     }
     $trueBody .= $this->getSection('来源');
     $trueBody .= $body->referer;
     $trueBody .= $this->getSection('分辨率');
     $trueBody .= $body->w . "X" . $body->h;
     $trueBody .= $this->getSection('截图');
     $trueBody .= "http://fs.huijiwiki.com/Feedback/{$id}.png";
     $res = UserMailer::send(new MailAddress('*****@*****.**', 'trello', 'trello'), new MailAddress("*****@*****.**"), $trueSubject, $trueBody);
     $this->getResult()->addValue(null, $this->getModuleName(), $res);
 }
 /**
  * Generate a trade number based on the given type.
  */
 public static function getTradeNo($type)
 {
     $cache = wfGetCache(CACHE_MEMCACHED);
     $key = wfForeignMemcKey('huiji', '', 'Huiji', 'getTradeNo', $type);
     if (HuijiFunctions::addLock($key, 1000, 1000)) {
         $no = $cache->get($key);
         if ($no != '') {
             ++$no;
             $cache->set($key, $no, 60);
             HuijiFunctions::releaseLock($key);
             return $type . $no;
         } else {
             $no = time() * 1000000;
             $cache->set($key, $no, 60);
             HuijiFunctions::releaseLock($key);
             return $type . $no;
         }
     }
     return false;
 }
 /**
  * @param $type String: activity type, such as 'friend' or 'foe' or 'edit'
  * @param $has_page Boolean: true by default
  */
 function simplifyPageActivity($type, $has_page = true)
 {
     global $wgLang, $wgMemc;
     if (!isset($this->items_grouped[$type]) || !is_array($this->items_grouped[$type])) {
         return '';
     }
     foreach ($this->items_grouped[$type] as $page_name => $page_data) {
         $timeago = HuijiFunctions::getTimeAgo($page_data['timestamp']) . '前';
         $key = wfForeignMemcKey('huiji', '', 'simplifyPageActivity', $type, $page_name, $page_data['timestamp'], count($page_data['users']), $this->show_following_sites);
         if (isset($this->displayed[$type][$page_name])) {
             continue;
         }
         $users = '';
         $pages = '';
         if ($type == 'friend' || $type == 'foe' || $type == 'user_message' || $type == 'user_user_follow') {
             $page_title = Title::newFromText($page_name, NS_USER);
         } elseif ($type == 'user_site_follow') {
             $page_title = Title::newFromText($page_name . ':');
         } elseif ($type == 'image_upload') {
             $page_title = Title::newFromText($page_name, NS_FILE);
         } else {
             $page_title = Title::newFromText($page_name);
         }
         $count_users = count($page_data['users']);
         $user_index = 0;
         $pages_count = 0;
         // Init empty variable to be used later on for GENDER processing
         // if the event is only for one user.
         $userNameForGender = '';
         foreach ($page_data['users'] as $user_name => $action) {
             /* get rid of same actions more than 1/2 day ago */
             // if ( $page_data['timestamp'] < $this->half_day_ago ) {
             // 	continue;
             // }
             $count_actions = count($action);
             if ($has_page && !isset($this->displayed[$type][$page_name])) {
                 $this->displayed[$type][$page_name] = 1;
                 $pages .= $this->fixPageTitle($page_title, $page_data);
                 /* get User Avatar for display */
                 if ($this->show_following_sites) {
                     $avatar = new wSiteAvatar($page_data['prefix'][0], 'ml');
                 } else {
                     $avatar = new wAvatar(User::idFromName($user_name), 'ml');
                 }
                 $avatarUrl = $avatar->getAvatarHtml();
                 if ($count_users == 1 && $count_actions > 1) {
                     $pages .= wfMessage('word-separator')->text();
                     $pages .= wfMessage('parentheses', wfMessage("useractivity-group-{$type}", $count_actions, $user_name)->text())->text();
                 }
                 $pages_count++;
             }
             // Single user on this action,
             // see if we can stack any other singles
             if ($count_users == 1) {
                 $userNameForGender = $user_name;
                 foreach ($this->items_grouped[$type] as $page_name2 => $page_data2) {
                     // if we find singles for this type, not displayed and not co-worked.
                     if (!isset($this->displayed[$type][$page_name2]) && count($page_data2['users']) == 1) {
                         //change since sept.7: only group pages with same prefix.
                         if (isset($page_data['prefix']) && $page_data['prefix'][0] != $page_data2['prefix'][0]) {
                             continue;
                         }
                         // don't stack the old ones.
                         /* get rid of same actions more than 1/2 day ago */
                         if ($page_data2['timestamp'] < $page_data['timestamp'] - $this->half_a_day || $page_data2['timestamp'] > $page_data['timestamp']) {
                             continue;
                         }
                         foreach ($page_data2['users'] as $user_name2 => $action2) {
                             if ($user_name2 == $user_name && $pages_count < $this->item_max) {
                                 $count_actions2 = count($action2);
                                 if ($type == 'friend' || $type == 'foe' || $type == 'user_message' || $type == 'user_user_follow') {
                                     $page_title2 = Title::newFromText($page_name2, NS_USER);
                                 } elseif ($type == 'user_site_follow') {
                                     $page_title2 = Title::newFromText($page_name2 . ':');
                                 } elseif ($type == 'image_upload') {
                                     $page_title2 = Title::newFromText($page_name2, NS_FILE);
                                 } else {
                                     $page_title2 = Title::newFromText($page_name2);
                                 }
                                 if ($pages) {
                                     $pages .= $page_title2->inNamespace(NS_FILE) ? '' : ',';
                                 }
                                 $pages .= $this->fixPageTitle($page_title2, $page_data2);
                                 if ($count_actions2 > 1) {
                                     $pages .= ' (' . wfMessage("useractivity-group-{$type}", $count_actions2)->text() . ')';
                                 }
                                 $pages_count++;
                                 // if (isset($page_data['prefix'])){
                                 // 	$page_data['prefix'] = array_merge($page_data['prefix'], $page_data2['prefix']);
                                 // }
                                 $this->displayed[$type][$page_name2] = 1;
                             }
                         }
                     }
                 }
             }
             $user_index++;
             if ($users && $count_users > 2) {
                 $users .= wfMessage('comma-separator')->text();
             }
             if ($user_index == $count_users && $count_users > 1) {
                 $users .= wfMessage('and')->text();
             }
             $user_title = Title::makeTitle(NS_USER, $user_name);
             $user_name_short = $wgLang->truncate($user_name, 15);
             $safeTitle = htmlspecialchars($user_title->getText());
             $users .= ' <b><a href="' . htmlspecialchars($user_title->getFullURL()) . "\" title=\"{$safeTitle}\">{$user_name_short}</a></b>";
         }
         /* memcache checking */
         $html = $wgMemc->get($key);
         if ($html != '') {
             $html = $this->updateTime($html, $timeago);
             $this->activityLines[] = array('type' => $type, 'timestamp' => $page_data['timestamp'], 'data' => $html);
             continue;
         }
         if ($pages || $has_page == false) {
             $prefixToName = '';
             if (isset($page_data['prefix'])) {
                 if (is_array($page_data['prefix'])) {
                     $page_data['prefix'] = array_unique($page_data['prefix']);
                     $prefixCount = count($page_data['prefix']);
                     $i = 0;
                     foreach ($page_data['prefix'] as $prefix) {
                         $prefixToName .= HuijiPrefix::prefixToSiteNameAnchor($prefix);
                         $i++;
                         if ($i < $prefixCount - 1) {
                             $prefixToName .= wfMessage('comma-separator')->text();
                         }
                         if ($i == $prefixCount - 1 && $prefixCount > 1) {
                             $prefixToName .= wfMessage('and')->text();
                         }
                     }
                 } elseif (is_string($page_data['prefix'])) {
                     $prefixToName .= HuijiPrefix::prefixToSiteNameAnchor($prefix);
                 }
             }
             /* prepare format */
             /* build html */
             $html = $this->templateParser->processTemplate('user-home-item', array('userAvatar' => $avatarUrl, 'userName' => $this->show_following_sites ? $prefixToName : $users, 'timestamp' => $timeago, 'description' => wfMessage("useractivity-{$type}", $users, $count_users, $pages, $pages_count, $userNameForGender, $prefixToName)->text(), 'hasShowcase' => false));
             $wgMemc->set($key, $html);
             $this->activityLines[] = array('type' => $type, 'timestamp' => $page_data['timestamp'], 'data' => $html);
         }
     }
 }
 /**
  * get site stats is $formatted is true, those number will be fortamtted
  * @param  boolean $formatted
  * @return array    the site stats
  */
 public function getStats($formatted = true)
 {
     $key = $this->getCustomKey('getStats');
     $data = $this->cache->get($key);
     if ($data != '') {
         $res = $data;
     } else {
         if ($this->mPrefix === '') {
             $res['followers'] = 0;
             $res['articles'] = 0;
             $res['users'] = 0;
             $res['pages'] = 0;
             $res['edits'] = 0;
             $res['files'] = 0;
         } else {
             $res = array();
             $res['followers'] = UserSiteFollow::getFollowerCount($this->mPrefix);
             $arr = AllSitesInfo::getPageInfoByPrefix($this->mPrefix);
             $res['articles'] = $arr['totalArticles'];
             $res['users'] = $arr['totalUsers'];
             $res['pages'] = $arr['totalPages'];
             $res['edits'] = $arr['totalEdits'];
             $res['files'] = $arr['totalImages'];
             $this->cache->set($key, $res, 24 * 60 * 60);
         }
     }
     if ($formatted) {
         foreach ($res as $key => $value) {
             $res[$key] = HuijiFunctions::format_nice_number($value);
         }
     }
     return $res;
 }
 /**
  * Gets the time how long ago the given board message was posted
  *
  * @param $time
  * @return $timeStr Mixed: time, such as "20 days" or "11 hours"
  */
 public function getTimeAgo($time)
 {
     return HuijiFunctions::getTimeAgo($time);
 }