Skip to content

Commit

Permalink
Merge pull request #9 from nbdd0121/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
nbdd0121 committed Jan 27, 2016
2 parents 608658c + 54cff3f commit 327c47b
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 363 deletions.
13 changes: 9 additions & 4 deletions FlowThread_body.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ public static function onBeforePageDisplay(OutputPage &$output, Skin &$skin) {
$output->addJsConfigVars(array('commentadmin' => ''));
}

global $wgFlowThreadConfig;
$config = array(
'Avatar' => $wgFlowThreadConfig['Avatar'],
'AnonymousAvatar' => $wgFlowThreadConfig['AnonymousAvatar'],
);

if (\FlowThread\Post::canPost($output->getUser())) {
$output->addJsConfigVars(array('canpost' => ''));
} else {
$config['CantPostNotice'] = wfMessage('flowthread-ui-cantpost')->toString();
}

global $wgFlowThreadConfig;
$output->addJsConfigVars(array('wgFlowThreadConfig' => array(
'Avatar' => $wgFlowThreadConfig['Avatar'],
'AnonymousAvatar' => $wgFlowThreadConfig['AnonymousAvatar'],
)));
$output->addJsConfigVars(array('wgFlowThreadConfig' => $config));
$output->addModules('ext.flowthread');
return true;
}
Expand Down
164 changes: 164 additions & 0 deletions assets/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
var config = mw.config.get('wgFlowThreadConfig');

/* Get avatar by user name */
function getAvatar(id, username) {
if(id===0) {
return config.AnonymousAvatar;
}else{
return config.Avatar.replace(/\$\{username\}/g, username);
}
}

/* Get user friendly time string (such as 1 hour age) */
function getTimeString(time) {
var m = moment(time).locale(mw.config.get('wgUserLanguage'));
var diff = Date.now() - time;
if (0 < diff && diff < 24 * 3600 * 1000) {
return m.fromNow();
} else {
return m.format('LL, HH:mm:ss');
}
}

function Thread() {
var template = '<div class="comment-thread"><div class="comment-post">'
+ '<div class="comment-avatar">'
+ '<img src=""></img>'
+ '</div>'
+ '<div class="comment-body">'
+ '<div class="comment-user"></div>'
+ '<div class="comment-text"></div>'
+ '<div class="comment-footer">'
+ '<span class="comment-time"></span>'
+ '</div>'
+ '</div></div></div>';

var object = $(template);

this.post = null;
this.object = object;
$.data(object[0], 'thread', this);
}

Thread.fromId = function(id) {
return $.data($('[comment-id=' + id + ']')[0], 'thread');
}

Thread.prototype.init = function(post) {
var object = this.object;
this.post = post;
object.attr('comment-id', post.id);

var userlink;
if (post.userid !== 0) {
userlink = wrapPageLink('User:' + post.username, post.username);
} else {
userlink = wrapText(post.username);
}
object.find('.comment-user').html(userlink);
object.find('.comment-avatar img').attr('src', getAvatar(post.userid, post.username));
object.find('.comment-text').html(post.text);
object.find('.comment-time')
.text(getTimeString(post.timestamp * 1000))
.siblings().remove(); // Remove all button after init
}

Thread.prototype.addButton = function(type, text, listener) {
return $('<span>')
.addClass('comment-' + type)
.text(text)
.click(listener)
.appendTo(this.object.find('.comment-footer'));
}

Thread.prototype.appendChild = function(thread) {
this.object.append(thread.object);
}

Thread.prototype.prependChild = function(thread) {
this.object.children('.comment-post').after(thread.object);
}
function wrapText(text) {
var span = $('<span/>');
span.text(text);
return span.wrapAll('<div/>').parent().html();
}

function wrapPageLink(page, name) {
var link = $('<a/>');
link.attr('href', mw.util.getUrl(page));
link.text(name);
return link.wrapAll('<div/>').parent().html();
}

Thread.prototype.like = function() {
var api = new mw.Api();
api.get({
action: 'flowthread',
type: 'like',
postid: this.post.id
});
this.object.find('.comment-like').first().attr('liked', '');
this.object.find('.comment-report').first().removeAttr('reported');
}

Thread.prototype.dislike = function() {
var api = new mw.Api();
api.get({
action: 'flowthread',
type: 'dislike',
postid: this.post.id
});
this.object.find('.comment-like').first().removeAttr('liked');
this.object.find('.comment-report').first().removeAttr('reported');
}

Thread.prototype.report = function() {
var api = new mw.Api();
api.get({
action: 'flowthread',
type: 'report',
postid: this.post.id
});
this.object.find('.comment-like').first().removeAttr('liked');
this.object.find('.comment-report').first().attr('reported', '');
}

Thread.prototype.delete = function() {
var api = new mw.Api();
api.get({
action: 'flowthread',
type: 'delete',
postid: this.post.id
});
this.object.remove();
}

function ReplyBox() {
var template = '<div class="comment-replybox">'
+ '<div class="comment-avatar">'
+ '<img src="' + getAvatar(mw.user.getId(), mw.user.id()) + '"></img>'
+ '</div>'
+ '<div class="comment-body">'
+ '<textarea placeholder="' + mw.msg('flowthread-ui-placeholder') + '"></textarea>'
+ '<div class="comment-toolbar">'
+ '<input type="checkbox" name="wikitext" value="" />'
+ mw.msg('flowthread-ui-usewikitext')
+ '<button class="comment-submit">' + mw.msg('flowthread-ui-submit') + '</button>'
+ '</div>'
+ '</div></div>';

var self = this;
var object = $(template);
this.object = object;

object.find('textarea').keyup(function(e) {
if (e.ctrlKey && e.which === 13) object.find('.comment-submit').click();
self.pack();
});
}

ReplyBox.prototype.pack = function() {
var textarea = this.object.find('textarea');
textarea.height(1).height(textarea[0].scrollHeight);
}
14 changes: 11 additions & 3 deletions css/flowthread.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@
display: none;
}

.comment-post:hover .comment-report, .comment-report[reported], .comment-post:hover .comment-delete[enabled] {
.comment-post:hover .comment-report, .comment-report[reported], .comment-post:hover .comment-delete {
display: initial;
}

.comment-thread .comment-replybox:not(:first-child) {
margin-left: 70px;
margin-left: 50px;
}

.comment-thread .comment-thread {
Expand Down Expand Up @@ -226,4 +226,12 @@
color: #d32;
border: 1px solid #ccc;
background-color: rgba(0,0,0,0.03);
}
}

.comment-bannotice {
border-top: 1px solid rgba(0,0,0,0.13);
font-size: 13px;
text-align: center;
padding: 1em;
color: #777;
}
2 changes: 1 addition & 1 deletion css/manage.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@
}

.comment-selected {
padding-left: 2em;
padding-left: 1em;
background: lightblue;
}
15 changes: 10 additions & 5 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Gary Guo",
"url": "https://github.com/nbdd0121/MW-FlowThread",
"descriptionmsg": "flowthread_desc",
"version": "1.1.1",
"version": "1.1.2",
"license-name": "BSD-2-Clause",
"type": "specialpage",
"ExtensionMessagesFiles": {
Expand All @@ -25,7 +25,8 @@
"FlowThread\\UUID": "includes/UUID.php",
"FlowThread\\SpamFilter": "includes/SpamFilter.php",
"FlowThread\\EchoHook": "/includes/Echo.php",
"FlowThread\\EchoReplyFormatter": "/includes/Echo.php"
"FlowThread\\EchoReplyFormatter": "/includes/Echo.php",
"FlowThread\\Helper": "/includes/Helper.php"
},
"Hooks": {
"BeforePageDisplay": [
Expand Down Expand Up @@ -60,9 +61,11 @@
"ResourceModules": {
"ext.flowthread": {
"dependencies": [
"moment"
"moment",
"mediawiki.user"
],
"scripts":[
"assets/common.js",
"js/flowthread.js"
],
"styles":[
Expand All @@ -81,9 +84,11 @@
},
"ext.flowthread.manage": {
"dependencies": [
"moment"
"moment",
"mediawiki.user"
],
"scripts": [
"assets/common.js",
"js/manage.js"
],
"styles": [
Expand Down Expand Up @@ -152,4 +157,4 @@
"echo-subscriptions-email-flowthread": false
},
"manifest_version": 1
}
}
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"flowthread-ui-placeholder": "Say Something...",
"flowthread-ui-submit": "Submit",
"flowthread-ui-nocontent": "Content cannot be empty",
"flowthread-ui-cantpost": "You do not have right to post. Please check site's policy about commenting.",

"echo-category-title-flowthread": "FlowThread comment",
"echo-pref-tooltip-flowthread": "Notify me when my comment is replyed.",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"flowthread-ui-placeholder": "说点什么吧...",
"flowthread-ui-submit": "提交",
"flowthread-ui-nocontent": "内容不能为空",
"flowthread-ui-cantpost": "您没有权限发表评论,请查看站点关于评论的政策。",

"echo-category-title-flowthread": "FlowThread评论",
"echo-pref-tooltip-flowthread": "当我的评论被回复时提醒我。",
Expand Down
Loading

0 comments on commit 327c47b

Please sign in to comment.