Browse Source

Abspeichern des Namen funktioniert

master
root 2 years ago
parent
commit
f103b057aa

+ 5
- 0
includes/.htaccess View File

@@ -0,0 +1,5 @@
1
+## Default .htaccess file
2
+# Displaying PHP errors
3
+php_flag display_errors on
4
+php_value error_reporting 6143
5
+

+ 873
- 858
includes/Comment.class.php
File diff suppressed because it is too large
View File


+ 614
- 608
includes/CommentsPage.class.php
File diff suppressed because it is too large
View File


+ 56
- 52
includes/api/CommentBlock.api.php View File

@@ -1,52 +1,56 @@
1
-<?php
2
-
3
-class CommentBlockAPI extends ApiBase {
4
-
5
-	public function execute() {
6
-		// Do nothing when the database is in read-only mode
7
-		if ( wfReadOnly() ) {
8
-			return true;
9
-		}
10
-
11
-		// Load user_name and user_id for person we want to block from the comment it originated from
12
-		$dbr = wfGetDB( DB_SLAVE );
13
-		$s = $dbr->selectRow(
14
-			'Comments',
15
-			array( 'comment_username', 'comment_user_id' ),
16
-			array( 'CommentID' => $this->getMain()->getVal( 'commentID' ) ),
17
-			__METHOD__
18
-		);
19
-		if ( $s !== false ) {
20
-			$userID = $s->comment_user_id;
21
-			$username = $s->comment_username;
22
-		}
23
-
24
-		CommentFunctions::blockUser( $this->getUser(), $userID, $username );
25
-
26
-		if ( class_exists( 'UserStatsTrack' ) ) {
27
-			$stats = new UserStatsTrack( $userID, $username );
28
-			$stats->incStatField( 'comment_ignored' );
29
-		}
30
-
31
-		$result = $this->getResult();
32
-		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
33
-		return true;
34
-	}
35
-
36
-	public function needsToken() {
37
-		return 'csrf';
38
-	}
39
-
40
-	public function isWriteMode() {
41
-		return true;
42
-	}
43
-
44
-	public function getAllowedParams() {
45
-		return array(
46
-			'commentID' => array(
47
-				ApiBase::PARAM_REQUIRED => true,
48
-				ApiBase::PARAM_TYPE => 'integer'
49
-			)
50
-		);
51
-	}
52
-}
1
+<?php
2
+
3
+class CommentBlockAPI extends ApiBase {
4
+
5
+	public function execute() {
6
+		// Do nothing when the database is in read-only mode
7
+		if ( wfReadOnly() ) {
8
+			return true;
9
+		}
10
+
11
+		// Load user_name and user_id for person we want to block from the comment it originated from
12
+		$dbr = wfGetDB( DB_SLAVE );
13
+		$s = $dbr->selectRow(
14
+			'Comments',
15
+			array( 'comment_username', 'comment_user_id' ),
16
+			array( 'CommentID' => $this->getMain()->getVal( 'commentID' ) ),
17
+			__METHOD__
18
+		);
19
+		if ( $s !== false ) {
20
+			$userID = $s->comment_user_id;
21
+			$username = $s->comment_username;
22
+		}
23
+
24
+		CommentFunctions::blockUser( $this->getUser(), $userID, $username );
25
+
26
+		if ( class_exists( 'UserStatsTrack' ) ) {
27
+			$stats = new UserStatsTrack( $userID, $username );
28
+			$stats->incStatField( 'comment_ignored' );
29
+		}
30
+
31
+		$result = $this->getResult();
32
+		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
33
+		return true;
34
+	}
35
+
36
+	public function needsToken() {
37
+		return 'csrf';
38
+	}
39
+
40
+	public function isWriteMode() {
41
+		return true;
42
+	}
43
+
44
+	public function getAllowedParams() {
45
+		return array(
46
+			'commentID' => array(
47
+				ApiBase::PARAM_REQUIRED => true,
48
+				ApiBase::PARAM_TYPE => 'integer'
49
+			),
50
+			'UsernameKOK' => array(
51
+				ApiBase::PARAM_REQUIRED => false,
52
+				ApiBase::PARAM_TYPE => 'string'
53
+			)
54
+		);
55
+	}
56
+}

+ 79
- 73
includes/api/CommentSubmit.api.php View File

@@ -1,73 +1,79 @@
1
-<?php
2
-
3
-class CommentSubmitAPI extends ApiBase {
4
-
5
-	public function execute() {
6
-		$user = $this->getUser();
7
-		// Blocked users cannot submit new comments, and neither can those users
8
-		// without the necessary privileges. Also prevent obvious cross-site request
9
-		// forgeries (CSRF)
10
-		if (
11
-			$user->isBlocked() ||
12
-			!$user->isAllowed( 'comment' ) ||
13
-			wfReadOnly()
14
-		) {
15
-			return true;
16
-		}
17
-
18
-		$commentText = $this->getMain()->getVal( 'commentText' );
19
-
20
-		if ( $commentText != '' ) {
21
-			// To protect against spam, it's necessary to check the supplied text
22
-			// against spam filters (but comment admins are allowed to bypass the
23
-			// spam filters)
24
-			if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
25
-				$this->dieUsage( wfMessage( 'comments-is-spam' )->plain(), 'comments-is-spam' );
26
-			}
27
-
28
-			// If the comment contains links but the user isn't allowed to post
29
-			// links, reject the submission
30
-			if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
31
-				$this->dieUsage( wfMessage( 'comments-links-are-forbidden' )->plain(), 'comments-links-are-forbidden' );
32
-			}
33
-
34
-			$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
35
-
36
-			Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
37
-
38
-			if ( class_exists( 'UserStatsTrack' ) ) {
39
-				$stats = new UserStatsTrack( $user->getID(), $user->getName() );
40
-				$stats->incStatField( 'comment' );
41
-			}
42
-		}
43
-
44
-		$result = $this->getResult();
45
-		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
46
-		return true;
47
-	}
48
-
49
-	public function needsToken() {
50
-		return 'csrf';
51
-	}
52
-
53
-	public function isWriteMode() {
54
-		return true;
55
-	}
56
-
57
-	public function getAllowedParams() {
58
-		return array(
59
-			'pageID' => array(
60
-				ApiBase::PARAM_REQUIRED => true,
61
-				ApiBase::PARAM_TYPE => 'integer'
62
-			),
63
-			'parentID' => array(
64
-				ApiBase::PARAM_REQUIRED => false,
65
-				ApiBase::PARAM_TYPE => 'integer'
66
-			),
67
-			'commentText' => array(
68
-				ApiBase::PARAM_REQUIRED => true,
69
-				ApiBase::PARAM_TYPE => 'string'
70
-			)
71
-		);
72
-	}
73
-}
1
+<?php
2
+
3
+class CommentSubmitAPI extends ApiBase {
4
+
5
+	public function execute() {
6
+		$user = $this->getUser();
7
+		// Blocked users cannot submit new comments, and neither can those users
8
+		// without the necessary privileges. Also prevent obvious cross-site request
9
+		// forgeries (CSRF)
10
+		if (
11
+			$user->isBlocked() ||
12
+			!$user->isAllowed( 'comment' ) ||
13
+			wfReadOnly()
14
+		) {
15
+			return true;
16
+		}
17
+
18
+		$commentText = $this->getMain()->getVal( 'commentText' );
19
+
20
+		if ( $commentText != '' ) {
21
+			// To protect against spam, it's necessary to check the supplied text
22
+			// against spam filters (but comment admins are allowed to bypass the
23
+			// spam filters)
24
+			if ( !$user->isAllowed( 'commentadmin' ) && CommentFunctions::isSpam( $commentText ) ) {
25
+				$this->dieUsage( wfMessage( 'comments-is-spam' )->plain(), 'comments-is-spam' );
26
+			}
27
+
28
+			// If the comment contains links but the user isn't allowed to post
29
+			// links, reject the submission
30
+			if ( !$user->isAllowed( 'commentlinks' ) && CommentFunctions::haveLinks( $commentText ) ) {
31
+				$this->dieUsage( wfMessage( 'comments-links-are-forbidden' )->plain(), 'comments-links-are-forbidden' );
32
+			}
33
+
34
+			$page = new CommentsPage( $this->getMain()->getVal( 'pageID' ), $this->getContext() );
35
+
36
+			Comment::add( $commentText, $page, $user, $this->getMain()->getVal( 'parentID' ) );
37
+
38
+			if ( class_exists( 'UserStatsTrack' ) ) {
39
+				$stats = new UserStatsTrack( $user->getID(), $user->getName() );
40
+				$stats->incStatField( 'comment' );
41
+			}
42
+		}
43
+
44
+        $kok_username = $this->getMain()->getVal( 'UsernameKOK' );
45
+
46
+		$result = $this->getResult();
47
+		$result->addValue( $this->getModuleName(), 'ok', 'ok' );
48
+		return true;
49
+	}
50
+
51
+	public function needsToken() {
52
+		return 'csrf';
53
+	}
54
+
55
+	public function isWriteMode() {
56
+		return true;
57
+	}
58
+
59
+	public function getAllowedParams() {
60
+		return array(
61
+			'pageID' => array(
62
+				ApiBase::PARAM_REQUIRED => true,
63
+				ApiBase::PARAM_TYPE => 'integer'
64
+			),
65
+			'parentID' => array(
66
+				ApiBase::PARAM_REQUIRED => false,
67
+				ApiBase::PARAM_TYPE => 'integer'
68
+			),
69
+			'commentText' => array(
70
+				ApiBase::PARAM_REQUIRED => true,
71
+				ApiBase::PARAM_TYPE => 'string'
72
+			),
73
+			'UsernameKOK' => array(
74
+				ApiBase::PARAM_REQUIRED => false,
75
+				ApiBase::PARAM_TYPE => 'string'
76
+			)
77
+		);
78
+	}
79
+}

+ 358
- 347
resources/js/Comment.js View File

@@ -1,347 +1,358 @@
1
-/**
2
- * JavaScript for the Comments extension.
3
- * Rewritten by Jack Phoenix <jack@countervandalism.net> to be more
4
- * object-oriented.
5
- *
6
- * @file
7
- * @date 6 December 2013
8
- */
9
-( function ( $, mw ) {
10
-var Comment = {
11
-	submitted: 0,
12
-	isBusy: false,
13
-	timer: '', // has to have an initial value...
14
-	updateDelay: 7000,
15
-	LatestCommentID: '',
16
-	CurLatestCommentID: '',
17
-	pause: 0,
18
-
19
-	/**
20
-	 * When a comment's author is ignored, "Show Comment" link will be
21
-	 * presented to the user.
22
-	 * If the user clicks on it, this function is called to show the hidden
23
-	 * comment.
24
-	 */
25
-	show: function( id ) {
26
-		$( '#ignore-' + id ).hide( 300 );
27
-		$( '#comment-' + id ).show( 300 );
28
-	},
29
-
30
-	/**
31
-	 * This function is called whenever a user clicks on the "block" image to
32
-	 * block another user's comments.
33
-	 *
34
-	 * @param username String: name of the user whose comments we want to block
35
-	 * @param userID Integer: user ID number of the user whose comments we
36
-	 *                         want to block (or 0 for anonymous users)
37
-	 * @param commentID Integer: comment ID number
38
-	 */
39
-	blockUser: function( username, userID, commentID ) {
40
-		var message;
41
-
42
-		// Display a different message depending on whether we're blocking an
43
-		// anonymous user or a registered one.
44
-		if ( !userID || userID === 0 ) {
45
-			message = mw.msg( 'comments-block-warning-anon' );
46
-		} else {
47
-			message = mw.msg( 'comments-block-warning-user', username );
48
-		}
49
-
50
-		if ( window.confirm( message ) ) {
51
-			( new mw.Api() ).postWithToken( 'csrf', {
52
-				action: 'commentblock',
53
-				commentID: commentID
54
-			} ).done( function( response ) {
55
-				if ( response.commentblock.ok ) {
56
-					$( 'a.comments-block-user[data-comments-user-id=' + userID + ']' )
57
-						.parents( '.c-item' ).hide( 300 )
58
-						.prev().show( 300 );
59
-				}
60
-			} );
61
-		}
62
-	},
63
-
64
-	/**
65
-	 * This function is called whenever a user clicks on the "Delete Comment"
66
-	 * link to delete a comment.
67
-	 *
68
-	 * @param commentID Integer: comment ID number
69
-	 */
70
-	deleteComment: function( commentID ) {
71
-		if ( window.confirm( mw.msg( 'comments-delete-warning' ) ) ) {
72
-			( new mw.Api() ).postWithToken( 'csrf', {
73
-				action: 'commentdelete',
74
-				commentID: commentID
75
-			} ).done( function( response ) {
76
-				if ( response.commentdelete.ok ) {
77
-					$( '#comment-' + commentID ).hide( 2000 );
78
-				}
79
-			} );
80
-		}
81
-	},
82
-
83
-	/**
84
-	 * Vote for a comment.
85
-	 *
86
-	 * @param commentID Integer: comment ID number
87
-	 * @param voteValue Integer: vote value
88
-	 */
89
-	vote: function( commentID, voteValue ) {
90
-		( new mw.Api() ).postWithToken( 'csrf', {
91
-			action: 'commentvote',
92
-			commentID: commentID,
93
-			voteValue: voteValue
94
-		} ).done( function( response ) {
95
-			$( '#comment-' + commentID + ' .c-score' )
96
-				.html( response.commentvote.html ) // this will still be escaped
97
-				.html( $( '#comment-' + commentID + ' .c-score' ).text() ); // unescape
98
-		} );
99
-	},
100
-
101
-	/**
102
-	 * @param pageID Integer: page ID
103
-	 * @param order Sorting order
104
-	 * @param end Scroll to bottom after?
105
-	 * @param cpage Integer: comment page number (used for pagination)
106
-	 */
107
-	viewComments: function( pageID, order, end, cpage ) {
108
-		document.commentForm.cpage.value = cpage;
109
-		document.getElementById( 'allcomments' ).innerHTML = mw.msg( 'comments-loading' ) + '<br /><br />';
110
-
111
-		$.ajax( {
112
-			url: mw.config.get( 'wgScriptPath' ) + '/api.php',
113
-			data: { 'action': 'commentlist', 'format': 'json', 'pageID': pageID, 'order': order, 'pagerPage': cpage },
114
-			cache: false
115
-		} ).done( function( response ) {
116
-			document.getElementById( 'allcomments' ).innerHTML = response.commentlist.html;
117
-			Comment.submitted = 0;
118
-			if ( end ) {
119
-				window.location.hash = 'end';
120
-			}
121
-		} );
122
-	},
123
-
124
-	/**
125
-	 * Submit a new comment.
126
-	 */
127
-	submit: function() {
128
-		if ( Comment.submitted === 0 ) {
129
-			Comment.submitted = 1;
130
-
131
-			var pageID = document.commentForm.pageId.value;
132
-			var parentID;
133
-			if ( !document.commentForm.commentParentId.value ) {
134
-				parentID = 0;
135
-			} else {
136
-				parentID = document.commentForm.commentParentId.value;
137
-			}
138
-			var commentText = document.commentForm.commentText.value;
139
-
140
-			( new mw.Api() ).postWithToken( 'csrf', {
141
-				action: 'commentsubmit',
142
-				pageID: pageID,
143
-				parentID: parentID,
144
-				commentText: commentText
145
-			} ).done( function( response ) {
146
-				if ( response.commentsubmit && response.commentsubmit.ok ) {
147
-					document.commentForm.commentText.value = '';
148
-					var end = 1;
149
-					if ( mw.config.get( 'wgCommentsSortDescending' ) ) {
150
-						end = 0;
151
-					}
152
-					Comment.viewComments( document.commentForm.pageId.value, 0, end, document.commentForm.cpage.value );
153
-				} else {
154
-					window.alert( response.error.info );
155
-					Comment.submitted = 0;
156
-				}
157
-			} );
158
-
159
-			Comment.cancelReply();
160
-		}
161
-	},
162
-
163
-	/**
164
-	 * Toggle comment auto-refreshing on or off
165
-	 *
166
-	 * @param status
167
-	 */
168
-	toggleLiveComments: function( status ) {
169
-		if ( status ) {
170
-			Comment.pause = 0;
171
-		} else {
172
-			Comment.pause = 1;
173
-		}
174
-		var msg;
175
-		if ( status ) {
176
-			msg = mw.msg( 'comments-auto-refresher-pause' );
177
-		} else {
178
-			msg = mw.msg( 'comments-auto-refresher-enable' );
179
-		}
180
-
181
-		$( 'body' ).on( 'click', 'div#spy a', function() {
182
-			Comment.toggleLiveComments( ( status ) ? 0 : 1 );
183
-		} );
184
-		$( 'div#spy a' ).css( 'font-size', '10px' ).text( msg );
185
-
186
-		if ( !Comment.pause ) {
187
-			Comment.LatestCommentID = document.commentForm.lastCommentId.value;
188
-			Comment.timer = setTimeout(
189
-				function() { Comment.checkUpdate(); },
190
-				Comment.updateDelay
191
-			);
192
-		}
193
-	},
194
-
195
-	checkUpdate: function() {
196
-		if ( Comment.isBusy ) {
197
-			return;
198
-		}
199
-		var pageID = document.commentForm.pageId.value;
200
-
201
-		$.ajax( {
202
-			url: mw.config.get( 'wgScriptPath' ) + '/api.php',
203
-			data: { 'action': 'commentlatestid', 'format': 'json', 'pageID': pageID },
204
-			cache: false
205
-		} ).done( function( response ) {
206
-			if ( response.commentlatestid.id ) {
207
-				// Get last new ID
208
-				Comment.CurLatestCommentID = response.commentlatestid.id;
209
-				if ( Comment.CurLatestCommentID !== Comment.LatestCommentID ) {
210
-					Comment.viewComments( document.commentForm.pageId.value, 0, 1, document.commentForm.cpage.value );
211
-					Comment.LatestCommentID = Comment.CurLatestCommentID;
212
-				}
213
-			}
214
-
215
-			Comment.isBusy = false;
216
-			if ( !Comment.pause ) {
217
-				clearTimeout( Comment.timer );
218
-				Comment.timer = setTimeout(
219
-					function() { Comment.checkUpdate(); },
220
-					Comment.updateDelay
221
-				);
222
-			}
223
-		} );
224
-
225
-		Comment.isBusy = true;
226
-		return false;
227
-	},
228
-
229
-	/**
230
-	 * Show the "reply to user X" form
231
-	 *
232
-	 * @param parentId Integer: parent comment (the one we're replying to) ID
233
-	 * @param poster String: name of the person whom we're replying to
234
-	 * @param posterGender String: gender of the person whom we're replying to
235
-	 */
236
-	reply: function( parentId, poster, posterGender ) {
237
-		$( '#replyto' ).text(
238
-			mw.msg( 'comments-reply-to', poster, posterGender ) + ' ('
239
-		);
240
-		$( '<a>', {
241
-			class: 'comments-cancel-reply-link',
242
-			style: 'cursor:pointer',
243
-			text: mw.msg( 'comments-cancel-reply' )
244
-		} ).appendTo( '#replyto' );
245
-		$( '#replyto' ).append( ') <br />' );
246
-
247
-		document.commentForm.commentParentId.value = parentId;
248
-	},
249
-
250
-	cancelReply: function() {
251
-		document.getElementById( 'replyto' ).innerHTML = '';
252
-		document.commentForm.commentParentId.value = '';
253
-	}
254
-};
255
-
256
-$( function() {
257
-	// Important note: these are all using $( 'body' ) as the selector
258
-	// instead of the class/ID/whatever so that they work after viewComments()
259
-	// has been called (i.e. so that "Delete comment", reply, etc. links
260
-	// continue working after you've submitted a comment yourself)
261
-
262
-	// "Sort by X" feature
263
-	$( 'body' ).on( 'change', 'select[name="TheOrder"]', function() {
264
-		Comment.viewComments(
265
-			mw.config.get( 'wgArticleId' ), // or we could use $( 'input[name="pid"]' ).val(), too
266
-			$( this ).val(),
267
-			0,
268
-			document.commentForm.cpage.value
269
-		);
270
-	} )
271
-
272
-	// Comment auto-refresher
273
-	.on( 'click', 'div#spy a', function() {
274
-		Comment.toggleLiveComments( 1 );
275
-	} )
276
-
277
-	// Voting links
278
-	.on( 'click', 'a#comment-vote-link', function() {
279
-		var that = $( this );
280
-		Comment.vote(
281
-			that.data( 'comment-id' ),
282
-			that.data( 'vote-type' )
283
-		);
284
-	} )
285
-
286
-	// "Block this user" links
287
-	.on( 'click', 'a.comments-block-user', function() {
288
-		var that = $( this );
289
-		Comment.blockUser(
290
-			that.data( 'comments-safe-username' ),
291
-			that.data( 'comments-user-id' ),
292
-			that.data( 'comments-comment-id' )
293
-		);
294
-	} )
295
-
296
-	// "Delete Comment" links
297
-	.on( 'click', 'a.comment-delete-link', function() {
298
-		Comment.deleteComment( $( this ).data( 'comment-id' ) );
299
-	} )
300
-
301
-	// "Show this hidden comment" -- comments made by people on the user's
302
-	// personal block list
303
-	.on( 'click', 'div.c-ignored-links a', function() {
304
-		Comment.show( $( this ).data( 'comment-id' ) );
305
-	} )
306
-
307
-	// Reply links
308
-	.on( 'click', 'a.comments-reply-to', function() {
309
-		Comment.reply(
310
-			$( this ).data( 'comment-id' ),
311
-			$( this ).data( 'comments-safe-username' ),
312
-			$( this ).data( 'comments-user-gender' )
313
-		);
314
-	} )
315
-
316
-	// "Reply to <username>" links
317
-	.on( 'click', 'a.comments-cancel-reply-link', function() {
318
-		Comment.cancelReply();
319
-	} )
320
-
321
-	// Handle clicks on the submit button (previously this was an onclick attr)
322
-	.on( 'click', 'div.c-form-button input[type="button"]', function() {
323
-		Comment.submit();
324
-	} )
325
-
326
-	// Change page
327
-	.on( 'click', 'li.c-pager-item a.c-pager-link', function() {
328
-		var ord = 0,
329
-			commentsBody = $( this ).parents( 'div.comments-body:first' );
330
-
331
-		if ( commentsBody.length > 0 ) {
332
-			var ordCrtl = commentsBody.first().find( 'select[name="TheOrder"]:first' );
333
-			if ( ordCrtl.length > 0 ) {
334
-				ord = ordCrtl.val();
335
-			}
336
-		}
337
-
338
-		Comment.viewComments(
339
-			mw.config.get( 'wgArticleId' ), // or we could use $( 'input[name="pid"]' ).val(), too
340
-			ord,
341
-			0,
342
-			$( this ).data( 'cpage' )
343
-		);
344
-	} );
345
-} );
346
-
347
-}( jQuery, mediaWiki ) );
1
+/**
2
+ * JavaScript for the Comments extension.
3
+ * Rewritten by Jack Phoenix <jack@countervandalism.net> to be more
4
+ * object-oriented.
5
+ *
6
+ * @file
7
+ * @date 6 December 2013
8
+ */
9
+( function ( $, mw ) {
10
+var Comment = {
11
+	submitted: 0,
12
+	isBusy: false,
13
+	timer: '', // has to have an initial value...
14
+	updateDelay: 7000,
15
+	LatestCommentID: '',
16
+	CurLatestCommentID: '',
17
+	pause: 0,
18
+
19
+	/**
20
+	 * When a comment's author is ignored, "Show Comment" link will be
21
+	 * presented to the user.
22
+	 * If the user clicks on it, this function is called to show the hidden
23
+	 * comment.
24
+	 */
25
+	show: function( id ) {
26
+		$( '#ignore-' + id ).hide( 300 );
27
+		$( '#comment-' + id ).show( 300 );
28
+	},
29
+
30
+	/**
31
+	 * This function is called whenever a user clicks on the "block" image to
32
+	 * block another user's comments.
33
+	 *
34
+	 * @param username String: name of the user whose comments we want to block
35
+	 * @param userID Integer: user ID number of the user whose comments we
36
+	 *                         want to block (or 0 for anonymous users)
37
+	 * @param commentID Integer: comment ID number
38
+	 */
39
+	blockUser: function( username, userID, commentID ) {
40
+		var message;
41
+
42
+		// Display a different message depending on whether we're blocking an
43
+		// anonymous user or a registered one.
44
+		if ( !userID || userID === 0 ) {
45
+			message = mw.msg( 'comments-block-warning-anon' );
46
+		} else {
47
+			message = mw.msg( 'comments-block-warning-user', username );
48
+		}
49
+
50
+		if ( window.confirm( message ) ) {
51
+			( new mw.Api() ).postWithToken( 'csrf', {
52
+				action: 'commentblock',
53
+				commentID: commentID
54
+			} ).done( function( response ) {
55
+				if ( response.commentblock.ok ) {
56
+					$( 'a.comments-block-user[data-comments-user-id=' + userID + ']' )
57
+						.parents( '.c-item' ).hide( 300 )
58
+						.prev().show( 300 );
59
+				}
60
+			} );
61
+		}
62
+	},
63
+
64
+	/**
65
+	 * This function is called whenever a user clicks on the "Delete Comment"
66
+	 * link to delete a comment.
67
+	 *
68
+	 * @param commentID Integer: comment ID number
69
+	 */
70
+	deleteComment: function( commentID ) {
71
+		if ( window.confirm( mw.msg( 'comments-delete-warning' ) ) ) {
72
+			( new mw.Api() ).postWithToken( 'csrf', {
73
+				action: 'commentdelete',
74
+				commentID: commentID
75
+			} ).done( function( response ) {
76
+				if ( response.commentdelete.ok ) {
77
+					$( '#comment-' + commentID ).hide( 2000 );
78
+				}
79
+			} );
80
+		}
81
+	},
82
+
83
+	/**
84
+	 * Vote for a comment.
85
+	 *
86
+	 * @param commentID Integer: comment ID number
87
+	 * @param voteValue Integer: vote value
88
+	 */
89
+	vote: function( commentID, voteValue ) {
90
+		( new mw.Api() ).postWithToken( 'csrf', {
91
+			action: 'commentvote',
92
+			commentID: commentID,
93
+			voteValue: voteValue
94
+		} ).done( function( response ) {
95
+			$( '#comment-' + commentID + ' .c-score' )
96
+				.html( response.commentvote.html ) // this will still be escaped
97
+				.html( $( '#comment-' + commentID + ' .c-score' ).text() ); // unescape
98
+		} );
99
+	},
100
+
101
+	/**
102
+	 * @param pageID Integer: page ID
103
+	 * @param order Sorting order
104
+	 * @param end Scroll to bottom after?
105
+	 * @param cpage Integer: comment page number (used for pagination)
106
+	 */
107
+	viewComments: function( pageID, order, end, cpage ) {
108
+		document.commentForm.cpage.value = cpage;
109
+		document.getElementById( 'allcomments' ).innerHTML = mw.msg( 'comments-loading' ) + '<br /><br />';
110
+
111
+		$.ajax( {
112
+			url: mw.config.get( 'wgScriptPath' ) + '/api.php',
113
+			data: { 'action': 'commentlist', 'format': 'json', 'pageID': pageID, 'order': order, 'pagerPage': cpage },
114
+			cache: false
115
+		} ).done( function( response ) {
116
+			document.getElementById( 'allcomments' ).innerHTML = response.commentlist.html;
117
+			Comment.submitted = 0;
118
+			if ( end ) {
119
+				window.location.hash = 'end';
120
+			}
121
+		} );
122
+	},
123
+
124
+	/**
125
+	 * Submit a new comment.
126
+	 */
127
+	submit: function() {
128
+		if ( Comment.submitted === 0 ) {
129
+			Comment.submitted = 1;
130
+
131
+			var pageID = document.commentForm.pageId.value;
132
+			var parentID;
133
+			if ( !document.commentForm.commentParentId.value ) {
134
+				parentID = 0;
135
+			} else {
136
+				parentID = document.commentForm.commentParentId.value;
137
+			}
138
+			var commentText = document.commentForm.commentText.value;
139
+			/* ## START ## 27.09.2017 von Bernhard Linz: Prüfen ob txt_username einen Wert enthält. wenn nicht, ignorieren */
140
+			var UsernameKOK;
141
+			if (document.getElementById('txt_username')) {
142
+				// UsernameKOK = document.commentform.txt_username.value; /* Wert aus txt_username in die Variable übergeben, welche später an Comments_AjaxFunctions.php übergeben wird */
143
+                UsernameKOK = document.getElementById('txt_username').value;
144
+			} else {
145
+				UsernameKOK = "none"; /* Wenn Feld nicht existiert Variable auf "none" setzen */
146
+			}
147
+            commentText = commentText + "#START#" + UsernameKOK + "#ENDE#";
148
+            //window.alert( UsernameKOK );
149
+			/* ## ENDE ## 27.09.2017 von Bernhard Linz */
150
+			( new mw.Api() ).postWithToken( 'csrf', {
151
+				action: 'commentsubmit',
152
+				pageID: pageID,
153
+				parentID: parentID,
154
+				commentText: commentText
155
+                //UsernameKOK: UsernameKOK
156
+			} ).done( function( response ) {
157
+				if ( response.commentsubmit && response.commentsubmit.ok ) {
158
+					document.commentForm.commentText.value = '';
159
+					var end = 1;
160
+					if ( mw.config.get( 'wgCommentsSortDescending' ) ) {
161
+						end = 0;
162
+					}
163
+					Comment.viewComments( document.commentForm.pageId.value, 0, end, document.commentForm.cpage.value );
164
+				} else {
165
+					window.alert( response.error.info );
166
+					Comment.submitted = 0;
167
+				}
168
+			} );
169
+
170
+			Comment.cancelReply();
171
+		}
172
+	},
173
+
174
+	/**
175
+	 * Toggle comment auto-refreshing on or off
176
+	 *
177
+	 * @param status
178
+	 */
179
+	toggleLiveComments: function( status ) {
180
+		if ( status ) {
181
+			Comment.pause = 0;
182
+		} else {
183
+			Comment.pause = 1;
184
+		}
185
+		var msg;
186
+		if ( status ) {
187
+			msg = mw.msg( 'comments-auto-refresher-pause' );
188
+		} else {
189
+			msg = mw.msg( 'comments-auto-refresher-enable' );
190
+		}
191
+
192
+		$( 'body' ).on( 'click', 'div#spy a', function() {
193
+			Comment.toggleLiveComments( ( status ) ? 0 : 1 );
194
+		} );
195
+		$( 'div#spy a' ).css( 'font-size', '10px' ).text( msg );
196
+
197
+		if ( !Comment.pause ) {
198
+			Comment.LatestCommentID = document.commentForm.lastCommentId.value;
199
+			Comment.timer = setTimeout(
200
+				function() { Comment.checkUpdate(); },
201
+				Comment.updateDelay
202
+			);
203
+		}
204
+	},
205
+
206
+	checkUpdate: function() {
207
+		if ( Comment.isBusy ) {
208
+			return;
209
+		}
210
+		var pageID = document.commentForm.pageId.value;
211
+
212
+		$.ajax( {
213
+			url: mw.config.get( 'wgScriptPath' ) + '/api.php',
214
+			data: { 'action': 'commentlatestid', 'format': 'json', 'pageID': pageID },
215
+			cache: false
216
+		} ).done( function( response ) {
217
+			if ( response.commentlatestid.id ) {
218
+				// Get last new ID
219
+				Comment.CurLatestCommentID = response.commentlatestid.id;
220
+				if ( Comment.CurLatestCommentID !== Comment.LatestCommentID ) {
221
+					Comment.viewComments( document.commentForm.pageId.value, 0, 1, document.commentForm.cpage.value );
222
+					Comment.LatestCommentID = Comment.CurLatestCommentID;
223
+				}
224
+			}
225
+
226
+			Comment.isBusy = false;
227
+			if ( !Comment.pause ) {
228
+				clearTimeout( Comment.timer );
229
+				Comment.timer = setTimeout(
230
+					function() { Comment.checkUpdate(); },
231
+					Comment.updateDelay
232
+				);
233
+			}
234
+		} );
235
+
236
+		Comment.isBusy = true;
237
+		return false;
238
+	},
239
+
240
+	/**
241
+	 * Show the "reply to user X" form
242
+	 *
243
+	 * @param parentId Integer: parent comment (the one we're replying to) ID
244
+	 * @param poster String: name of the person whom we're replying to
245
+	 * @param posterGender String: gender of the person whom we're replying to
246
+	 */
247
+	reply: function( parentId, poster, posterGender ) {
248
+		$( '#replyto' ).text(
249
+			mw.msg( 'comments-reply-to', poster, posterGender ) + ' ('
250
+		);
251
+		$( '<a>', {
252
+			class: 'comments-cancel-reply-link',
253
+			style: 'cursor:pointer',
254
+			text: mw.msg( 'comments-cancel-reply' )
255
+		} ).appendTo( '#replyto' );
256
+		$( '#replyto' ).append( ') <br />' );
257
+
258
+		document.commentForm.commentParentId.value = parentId;
259
+	},
260
+
261
+	cancelReply: function() {
262
+		document.getElementById( 'replyto' ).innerHTML = '';
263
+		document.commentForm.commentParentId.value = '';
264
+	}
265
+};
266
+
267
+$( function() {
268
+	// Important note: these are all using $( 'body' ) as the selector
269
+	// instead of the class/ID/whatever so that they work after viewComments()
270
+	// has been called (i.e. so that "Delete comment", reply, etc. links
271
+	// continue working after you've submitted a comment yourself)
272
+
273
+	// "Sort by X" feature
274
+	$( 'body' ).on( 'change', 'select[name="TheOrder"]', function() {
275
+		Comment.viewComments(
276
+			mw.config.get( 'wgArticleId' ), // or we could use $( 'input[name="pid"]' ).val(), too
277
+			$( this ).val(),
278
+			0,
279
+			document.commentForm.cpage.value
280
+		);
281
+	} )
282
+
283
+	// Comment auto-refresher
284
+	.on( 'click', 'div#spy a', function() {
285
+		Comment.toggleLiveComments( 1 );
286
+	} )
287
+
288
+	// Voting links
289
+	.on( 'click', 'a#comment-vote-link', function() {
290
+		var that = $( this );
291
+		Comment.vote(
292
+			that.data( 'comment-id' ),
293
+			that.data( 'vote-type' )
294
+		);
295
+	} )
296
+
297
+	// "Block this user" links
298
+	.on( 'click', 'a.comments-block-user', function() {
299
+		var that = $( this );
300
+		Comment.blockUser(
301
+			that.data( 'comments-safe-username' ),
302
+			that.data( 'comments-user-id' ),
303
+			that.data( 'comments-comment-id' )
304
+		);
305
+	} )
306
+
307
+	// "Delete Comment" links
308
+	.on( 'click', 'a.comment-delete-link', function() {
309
+		Comment.deleteComment( $( this ).data( 'comment-id' ) );
310
+	} )
311
+
312
+	// "Show this hidden comment" -- comments made by people on the user's
313
+	// personal block list
314
+	.on( 'click', 'div.c-ignored-links a', function() {
315
+		Comment.show( $( this ).data( 'comment-id' ) );
316
+	} )
317
+
318
+	// Reply links
319
+	.on( 'click', 'a.comments-reply-to', function() {
320
+		Comment.reply(
321
+			$( this ).data( 'comment-id' ),
322
+			$( this ).data( 'comments-safe-username' ),
323
+			$( this ).data( 'comments-user-gender' )
324
+		);
325
+	} )
326
+
327
+	// "Reply to <username>" links
328
+	.on( 'click', 'a.comments-cancel-reply-link', function() {
329
+		Comment.cancelReply();
330
+	} )
331
+
332
+	// Handle clicks on the submit button (previously this was an onclick attr)
333
+	.on( 'click', 'div.c-form-button input[type="button"]', function() {
334
+		Comment.submit();
335
+	} )
336
+
337
+	// Change page
338
+	.on( 'click', 'li.c-pager-item a.c-pager-link', function() {
339
+		var ord = 0,
340
+			commentsBody = $( this ).parents( 'div.comments-body:first' );
341
+
342
+		if ( commentsBody.length > 0 ) {
343
+			var ordCrtl = commentsBody.first().find( 'select[name="TheOrder"]:first' );
344
+			if ( ordCrtl.length > 0 ) {
345
+				ord = ordCrtl.val();
346
+			}
347
+		}
348
+
349
+		Comment.viewComments(
350
+			mw.config.get( 'wgArticleId' ), // or we could use $( 'input[name="pid"]' ).val(), too
351
+			ord,
352
+			0,
353
+			$( this ).data( 'cpage' )
354
+		);
355
+	} );
356
+} );
357
+
358
+}( jQuery, mediaWiki ) );

Loading…
Cancel
Save