Пример #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;
 }
Пример #2
0
 /**
  * Function to render the {{#siteavatar:Prefix}} function
  *
  * @param Parser $parser: MW parser object
  * @param string $username: Username of user to show avatar for
  * @param string $size: Size of avatar to return (s/m/ml/l), or px value (100px, 10px, etc)
  * @return array: output of function, and options for the parser
  */
 static function renderSiteAvatarParserFunction($parser, $prefix = '', $givenSize = 'm')
 {
     global $wgUploadPath;
     $sizes = array('s', 'm', 'ml', 'l');
     if (in_array($givenSize, $sizes)) {
         // if given size is a code,
         $size = $givenSize;
         // use code,
         $px = '';
         // and leave px value empty
     } elseif (substr($givenSize, -2) == 'px') {
         //given size is a value in px
         $givenPx = intval(substr($givenSize, 0, strlen($givenSize) - 2));
         //get int value of given px size
         if (!is_int($givenPx)) {
             // if px value is not int
             $size = 'm';
             // give default avatar
             $px = '';
             // with no px value
         }
         if ($givenPx <= 16) {
             // if given px value is smaller than small,
             $size = 's';
             // use the small avatar,
             $px = $givenSize;
             // and the given px value
         } elseif ($givenPx <= 30) {
             // if given px value is smaller than medium,
             $size = 'm';
             // use the medium avatar,
             $px = $givenSize;
             // and the given px value
         } elseif ($givenPx <= 50) {
             // if given px value is smaller than medium-large,
             $size = 'ml';
             // use the medium-large avatar,
             $px = $givenSize;
             // and the given px value
         } else {
             // if given px value is bigger then medium large,
             $size = 'l';
             // use the large avatar,
             $px = $givenSize;
             // and the given px value
         }
     } else {
         // size value is not code or px
         $size = 'm';
         // give default avatar
         $px = '';
         // with no px value
     }
     if (HuijiPrefix::hasPrefix($prefix)) {
         $id = $prefix;
         $avatar = new wSiteAvatar($id, $size);
     } else {
         // Fallback for the case where an invalid (nonexistent) user name
         // was supplied...
         $avatar = new wAvatar(-1, 'm');
         // not very nice, but -1 will get the default avatar
     }
     if ($px) {
         // if px value needed, set height to it
         $output = $avatar->getAvatarHtml(array('height' => $px));
     } else {
         // but if not needed, don't
         $output = $avatar->getAvatarHtml();
     }
     return array($output, 'noparse' => true, 'isHTML' => true);
 }
Пример #3
0
 /**
  * @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);
         }
     }
 }