Skip to content
Permalink
Browse files
Merge pull request #4 from ikasty/master
Echo 연동
  • Loading branch information
wiki-chan-server committed Feb 15, 2016
2 parents d46eabc + ab890a5 commit bb932d15d36bcb4ee076bdcf0e8494496eb0906b
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 140 deletions.
@@ -0,0 +1,78 @@
<?php

class SocialFormatter extends EchoBasicFormatter {
/**
* @param EchoEvent $event
* @param string $param
* @param Message $message
* @param User $user
*/
protected function processParam( $event, $param, $message, $user ) {
switch ( $param ) {
case 'user':
$target_id = $event->getExtra()['from'];
$target_user = User::newFromId($target_id);
$target_title = $target_user->getUserPage();

$link = $this->buildLinkParam($target_title, array(
'linkText' => $target_user->getName()
));
$message->params($link);
break;

case 'relationship':
$title = Title::newFromText('ViewRelationshipRequests', NS_SPECIAL);
$link = $this->buildLinkParam($title, array(
'linkText' => $this->getMessage( 'echo-show-social-rel-add-link' )->text()
));
$message->params($link);
break;


case 'bundle-user-count':
$user_count = $this->bundleData['agent-other-count'] + 1; // 나 빼고 다른 사람 + 나
$message->params($user_count);
break;

case 'bundle-noti-count':
$noti_count = $this->bundleData['raw-data-count'];
$message->params($noti_count);
break;

default:
parent::processParam( $event, $param, $message, $user );
}
}

protected function formatPayload( $payload, $event, $user ) {
switch ( $payload ) {
case 'relationship-add':
$extra = $event->getExtra();
return $extra['message'];
break;
case 'send-message':
global $wgParser, $wgTitle, $wgOut;

$extra = $event->getExtra();
$message = $this->truncate($extra['message']);
return $message;
//return $wgParser->getFreshParser()->parse($message, $wgTitle, $wgOut->parserOptions())->getText();
break;
default:
return parent::formatPayload( $payload, $event, $user );
break;
}
}

private function truncate($string, $length = 100, $append="&hellip;") {
$string = trim($string);

if (strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}

return $string;
}
}
@@ -5,61 +5,31 @@
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die(
'This is the setup file for the Social extension to MediaWiki.' .
'Please see https://github.com/wiki-chan/Social for' .
' more information about this extension.'
'This is the setup file for the Social extension to MediaWiki. ' .
'Please see https://github.com/wiki-chan/Social for ' .
'more information about this extension.'
);
}

//$wgNamespacesWithSubpages[NS_USER] = false;

# 가상의 권한인 disabled라는 권한이 있어야만 편집이 가능함 = 편집 불가
$wgNamespaceProtection[NS_USER_TALK] = array( 'disabled' );
//$wgNamespaceProtection[NS_USER_TALK] = array( 'disabled' );

/**
* This is the loader file for the SocialProfile extension. You should include
* this file in your wiki's LocalSettings.php to activate SocialProfile.
* This is the loader file for the Social extension.
*
* If you want to use the UserWelcome extension (bundled with SocialProfile),
* the <topusers /> tag or the user levels feature, there are some other files
* you will need to include in LocalSettings.php. The online manual has more
* details about this.
*
* For more info about SocialProfile, please see https://www.mediawiki.org/wiki/Extension:SocialProfile.
* For more info about SocialProfile, please see https://github.com/wiki-chan/Social
*/

// Internationalization files
$wgMessagesDirs['SocialProfile'] = __DIR__ . '/i18n';
$wgExtensionMessagesFiles['SocialProfileAlias'] = __DIR__ . '/SocialProfile.alias.php';

$wgMessagesDirs['SocialProfileUserStats'] = __DIR__ . '/UserStats/i18n';
$wgExtensionMessagesFiles['SocialProfileNamespaces'] = __DIR__ . '/SocialProfile.namespaces.php';

// Classes to be autoloaded
$wgAutoloadClasses['SocialProfileInitClass'] = __DIR__ . '/SocialProfileInitClass.php';

$wgAutoloadClasses['GenerateTopUsersReport'] = __DIR__ . '/UserStats/GenerateTopUsersReport.php';

$wgAutoloadClasses['UpdateEditCounts'] = __DIR__ . '/UserStats/SpecialUpdateEditCounts.php';

$wgAutoloadClasses['UserLevel'] = __DIR__ . '/UserStats/UserStatsClass.php';
$wgAutoloadClasses['UserStats'] = __DIR__ . '/UserStats/UserStatsClass.php';
$wgAutoloadClasses['UserStatsTrack'] = __DIR__ . '/UserStats/UserStatsClass.php';
$wgAutoloadClasses['UserEmailTrack'] = __DIR__ . '/UserStats/UserStatsClass.php';
$wgAutoloadClasses['UserSystemMessage'] = __DIR__ . '/UserSystemMessages/UserSystemMessagesClass.php';
$wgAutoloadClasses['TopFansByStat'] = __DIR__ . '/UserStats/TopFansByStat.php';
$wgAutoloadClasses['TopFansRecent'] = __DIR__ . '/UserStats/TopFansRecent.php';
$wgAutoloadClasses['TopUsersPoints'] = __DIR__ . '/UserStats/TopUsers.php';


// New special pages

$wgSpecialPages['GenerateTopUsersReport'] = 'GenerateTopUsersReport';
$wgSpecialPages['TopFansByStatistic'] = 'TopFansByStat';
$wgSpecialPages['TopUsers'] = 'TopUsersPoints';
$wgSpecialPages['TopUsersRecent'] = 'TopFansRecent';
$wgSpecialPages['UpdateEditCounts'] = 'UpdateEditCounts';

$wgAutoloadClasses['SocialFormatter'] = __DIR__ . '/SocialFormatter.php';

// Necessary AJAX functions
// TODO: 별도 클래스로 각각 분리할 것
@@ -80,15 +50,9 @@
'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix', '페네트-' ),
'version' => '1.7.4',
'url' => 'https://github.com/wiki-chan/Social',
'license-name' => 'GPL-2.0',
'descriptionmsg' => 'socialprofile-desc',
);
$wgExtensionCredits['specialpage'][] = array(
'path' => __FILE__,
'name' => 'TopUsers',
'author' => 'David Pean',
'url' => 'https://github.com/wiki-chan/Social',
'description' => 'Adds a special page for viewing the list of users with the most points.',
);

// Hooked functions
$wgAutoloadClasses['SocialProfileHooks'] = __DIR__ . '/SocialProfileHooks.php';
@@ -124,14 +88,6 @@
'remoteExtPath' => 'SocialProfile/shared',
);

/*
function efUserBoardOnUserRename( $renameUserSQL ) {
$renameUserSQL->tables['{multi}'][] = array( 'user_board', 'ub_user_name', 'ub_user_id' );
$renameUserSQL->tables['{multi}'][] = array( 'user_board', 'ub_user_name_from', 'ub_user_id_from' );
// <fixme> 여기도 column 바꿀 곳이 한 곳 더 있음. 확인 요망. </fixme>
return true;
}
*/
// General/shared JS modules -- not (necessarily) directly used by SocialProfile,
// but rather by other social tools which depend on SP
// @see https://phabricator.wikimedia.org/T100025
@@ -149,24 +105,4 @@ function efUserBoardOnUserRename( $renameUserSQL ) {
'remoteExtPath' => 'SocialProfile/shared',
);

// UserBoard
$wgResourceModules['ext.socialprofile.userboard.js'] = array(
'scripts' => 'UserBoard.js',
'messages' => array( 'userboard_confirmdelete' ),
'localBasePath' => __DIR__ . '/UserBoard',
'remoteExtPath' => 'SocialProfile/UserBoard',
);





// UserStats
$wgResourceModules['ext.socialprofile.userstats.css'] = array(
'styles' => 'TopList.css',
'localBasePath' => __DIR__ . '/UserStats',
'remoteExtPath' => 'SocialProfile/UserStats',
'position' => 'top' // just in case
);

// End ResourceLoader stuff
// End ResourceLoader stuff
@@ -16,6 +16,10 @@ public function __construct() {
parent::__construct( 'SystemGiftManager'/*class*/, 'awardsmanage'/*restriction*/ );
}

public function doesWrites() {
return true;
}

/**
* Show the special page
*
@@ -95,7 +95,7 @@ public function sendGiftNotificationEmail( $user_id_to, $gift_id ) {
$sender = new MailAddress( $wgPasswordSender,
wfMessage( 'emailsender' )->inContentLanguage()->text() );
$to = new MailAddress( $user );
UserMailer::send( $to, $sender, $subject, $body, null, 'text/html; charset=UTF-8' );
UserMailer::send( $to, $sender, $subject, $body, array( 'contentType' => 'text/html; charset=UTF-8' ) );
}
}

@@ -33,34 +33,35 @@ function wfRegisterDisplayNewMessage( OutputPage &$out, Skin &$skin ) {
}
*/


$wgExtensionCredits['profile'][] = array(
'path' => __FILE__,
'name' => 'Message Board',
'author' => array('David Pean', '페네트-'),
'url' => 'https://github.com/wiki-chan/SocialProfile',
'url' => 'https://github.com/wiki-chan/Social',
'license-name' => 'GPL-2.0',
'description' => 'Display User Board messages for a user',
);


// resource modules
$wgResourceModules['ext.socialprofile.userboard.js'] = array(
'scripts' => 'UserBoard.js',
'messages' => array( 'userboard_confirmdelete' ),
'localBasePath' => __DIR__,
'remoteExtPath' => 'SocialProfile/UserBoard',
'remoteExtPath' => 'Social/UserBoard',
);

$wgResourceModules['ext.socialprofile.userboard.css'] = array(
'styles' => 'UserBoard.css',
'localBasePath' => __DIR__,
'remoteExtPath' => 'SocialProfile/UserBoard',
'remoteExtPath' => 'Social/UserBoard',
'position' => 'top' // just in case
);

$wgResourceModules['ext.socialprofile.userboard.boardblast.css'] = array(
'styles' => 'BoardBlast.css',
'localBasePath' => __DIR__,
'remoteExtPath' => 'SocialProfile/UserBoard',
'remoteExtPath' => 'Social/UserBoard',
'position' => 'top' // just in case
);

@@ -71,7 +72,7 @@ function wfRegisterDisplayNewMessage( OutputPage &$out, Skin &$skin ) {
'boardblast-js-error-missing-user'
),
'localBasePath' => __DIR__,
'remoteExtPath' => 'SocialProfile/UserBoard',
'remoteExtPath' => 'Social/UserBoard',
);

// Should we display UserBoard-related things on social profile pages?
@@ -85,21 +86,25 @@ function wfRegisterDisplayNewMessage( OutputPage &$out, Skin &$skin ) {
$wgAutoloadClasses['UserBoard'] = __DIR__ . '/UserBoardClass.php'; // class for control user board messages
$wgAutoloadClasses['SpecialViewUserBoard'] = __DIR__ . '/SpecialUserBoard.php'; // special page for user board view
$wgAutoloadClasses['SpecialBoardBlast'] = __DIR__ . '/SpecialSendBoardBlast.php'; // special page for send 'mass board message'
$wgAutoloadClasses['UserBoardAjaxFunctions'] = __DIR__ . '/UserBoardAjaxFunctions.php'; // static functions for ajax
$wgAutoloadClasses['SendUserBoardMessage'] = __DIR__ . '/APISendUserBoardMessage.php'; // API for send message
$wgAutoloadClasses['UserBoardHooks'] = __DIR__ . '/UserBoardHooks.php'; // Hook functions

// New special pages
$wgSpecialPages['UserBoard'] = 'SpecialViewUserBoard';
$wgSpecialPages['SendBoardBlast'] = 'SpecialBoardBlast';

// For the Echo extension
$wgHooks['BeforeCreateEchoEvent'][] = 'UserBoardHooks::onBeforeCreateEchoEvent';
$wgHooks['EchoGetDefaultNotifiedUsers'][] = 'UserBoardHooks::onEchoGetDefaultNotifiedUsers';
$wgHooks['EchoGetBundleRules'][] = 'UserBoardHooks::onEchoGetBundleRules';

$wgDefaultUserOptions['echo-subscriptions-web-social-msg'] = true;
$wgDefaultUserOptions['echo-subscriptions-email-social-msg'] = false;

/**
* AJAX functions used by UserBoard.
*/
$wgAjaxExportList[] = 'UserBoardAjaxFunctions::wfDeleteBoardMessage';

/*
// 새로운 알림 출력 by 페네트
$wgAjaxExportList[] = 'UserBoardAjaxFunctions::wfGetNewMessage';
$wgAjaxExportList[] = 'UserBoardAjaxFunctions::wfGetResetNewMessageCount';
*/

//$wgHooks['GetAlarmMessage'][] = 'UserBoard::AlarmMessage';
// API module
$wgAPIModules['social-send-message'] = 'SendUserBoardMessage';
@@ -9,7 +9,7 @@ class UserBoard {
*/
public function __construct() {}

// TODO: Alarm check
// DEPRECATED
public static function AlarmMessage($type, $sender, $data, $date, &$message, &$link) {
if ($type != "usermesg") return true;

@@ -87,8 +87,21 @@ public function sendBoardMessage( $user_id_from, $user_name_from, $user_id_to, $
$stats = new UserStatsTrack( $user_id_from, $user_name_from );
$stats->incStatField( 'user_board_sent' );

if ( class_exists('Alarm') )
Alarm::addAlarmMessage($user_id_to, 'usermesg', $id, $user_id_from);
if (class_exists('EchoEvent')) {
$userFrom = User::newFromId($user_id_from);

EchoEvent::create(array(
'type' => 'social-msg-send',
'agent' => $userFrom,
// 'title' => $userFrom->getUserPage(),
'extra' => array(
'target' => $user_id_to,
'from' => $user_id_from,
'type' => $message_type,
'message' => $message
)
));
}

return $id;
}
@@ -122,7 +135,7 @@ public function sendBoardNotificationEmail( $user_id_to, $user_from ) {
$sender = new MailAddress( $wgPasswordSender,
wfMessage( 'emailsender' )->inContentLanguage()->text() );
$to = new MailAddress( $user );
UserMailer::send( $to, $sender, $subject, $body, null, 'text/html; charset=UTF-8' );
UserMailer::send( $to, $sender, $subject, $body, array( 'contentType' => 'text/html; charset=UTF-8' ) );
}
}

0 comments on commit bb932d1

Please sign in to comment.