-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.php
More file actions
executable file
·997 lines (862 loc) · 27 KB
/
Copy pathThread.php
File metadata and controls
executable file
·997 lines (862 loc) · 27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
<?php
class WFThread extends ContextSource {
private $data;
public $forum;
private $replies;
public $preloadText;
private function __construct( $sql ) {
$this->data = $sql;
}
/**
* Get the WFThread object for the thread with the given ID number
*
* @param int $id: ID to find
* @return WFThread
*/
public static function newFromID( $id ) {
$dbr = wfGetDB( DB_SLAVE );
$data = $dbr->selectRow(
'wikiforum_threads',
'*',
array( 'wft_thread' => $id ),
__METHOD__
);
if ( $data ) {
return new WFThread( $data );
} else {
return false;
}
}
/**
* Get the WFThread object from a row from the DB
*
* @param stdClass $sql: the row. Not a ResultWrapper! (Either use $dbr->fetchObject(), or loop through the resultWrapper!)
* @return WFThread
*/
public static function newFromSQL( $sql ) {
return new WFThread( $sql );
}
/**
* Find a thread when you know the title.
*
* @param $titleText String: thread title
* @return boolean|WFThread: Thread, or false on failure
*/
public static function newFromName( $titleText ) {
// Titles are stored with spaces in the DB but the query will otherwise
// use friggin' underscores...
$titleText = str_replace( '_', ' ', $titleText );
$dbr = wfGetDB( DB_SLAVE );
$data = $dbr->selectRow(
'wikiforum_threads',
'*',
array( 'wft_thread_name' => $titleText ),
__METHOD__
);
if ( $data ) {
return new WFThread( $data );
} else {
return false;
}
}
/**
* Whether or not the thread is sticky
*
* @return boolean
*/
function isSticky() {
return $this->data->wft_sticky == true;
}
/**
* Whether or not the thread is closed
*
* @return boolean
*/
function isClosed() {
return $this->data->wft_closed == true;
}
/**
* Show the user and time of the last post in the thread, if there is a post
*
* @return string
*/
function showLastPostInfo() {
if ( $this->getReplyCount() > 0 ) {
return WikiForumGui::showByInfo(
$this->data->wft_last_post_timestamp,
WikiForumClass::getUserFromDB( $this->data->wft_last_post_user, $this->data->wft_last_post_user_ip )
);
} else {
return '';
}
}
/**
* Show the user and time of when this thread was first posted
*
* @return string
*/
function showPostedInfo() {
return WikiForumGui::showPostedInfo(
$this->data->wft_posted_timestamp,
$this->getPostedBy()
);
}
/**
* Show the user and time of when this thread was first posted, without the link. (Apparently needed for quoting)
*
* @return string
*/
function showPlainPostedInfo() {
return WikiForumGui::showPlainPostedInfo( $this->data->wft_posted_timestamp, $this->getPostedBy() );
}
/**
* Show the user and time of when this thread was edited
*
* @return string
*/
function showEditedInfo() {
return WikiForumGui::showEditedInfo(
$this->data->wft_edit_timestamp,
$this->getEditedBy()
);
}
/**
* Get the URL to this thread
*
* @param int $reply: auto scroll to reply, optional
* @return string
*/
function getURL( $reply = false ) {
$fragment = '';
if ( $reply ) {
$fragment = 'reply_' . $reply;
}
return htmlspecialchars( SpecialPage::getTitleFor( 'WikiForum', $this->getName(), $fragment )->getFullURL() );
}
/**
* Get the HTML for a link to this thread
*
* @param int|boolean $reply: Optional: Reply to scroll to (through url #fragment)
* @return string: HTML the link
*/
function showLink( $reply = false ) {
return '<a href="' . $this->getURL() . '">' . $this->getName() . '</a>';
}
/**
* Get the number of replies this thread has
*
* @return int
*/
function getReplyCount() {
return $this->data->wft_reply_count;
}
/**
* Get the number of times this thread has been viewed
*
* @return int
*/
function getViewCount() {
return $this->data->wft_view_count;
}
/**
* Get the ID of the user who originally posted this thread
*
* @return string
*/
function getPostedById() {
return $this->data->wft_user;
}
/**
* Get the user who's edited this thread
*
* @return User
*/
function getEditedBy() {
return WikiForumClass::getUserFromDB( $this->data->wft_edit_user, $this->data->wft_edit_user_ip );
}
/**
* Get the user who originally posted this thread
*
* @return User
*/
function getPostedBy() {
return WikiForumClass::getUserFromDB( $this->data->wft_user, $this->data->wft_user_ip );
}
/**
* Get the name/title of this thread
*
* @return string
*/
function getName() {
return $this->data->wft_thread_name;
}
/**
* Get the actual text of this thread
*
* @return string
*/
function getText() {
return $this->data->wft_text;
}
/**
* Get this thread's parent forum
*
* @return WFForum
*/
function getForum() {
if ( !$this->forum ) {
$this->forum = WFForum::newFromID( $this->data->wft_forum );
}
return $this->forum;
}
/**
* Get this thread's ID number
*
* @return int: id
*/
function getId() {
return $this->data->wft_thread;
}
/**
* Get the timestamp of when this thread was originally posted
*
* @return string
*/
function getPostedTimestamp() {
return $this->data->wft_posted_timestamp;
}
/**
* Get the timestamp of when this thread was edited
*
* @return string
*/
function getEditedTimestamp() {
return $this->data->wft_edit_timestamp;
}
/**
* Gets an array of this thread's replies
*
* @return multitype:WFReply: array of replies
*/
function getReplies() {
if ( !$this->replies ) {
$dbr = wfGetDB( DB_SLAVE );
$sqlReplies = $dbr->select(
'wikiforum_replies',
'*',
array( 'wfr_thread' => $this->getId() ),
__METHOD__,
array( 'ORDER BY' => 'wfr_posted_timestamp ASC' )
);
$replies = array();
foreach( $sqlReplies as $sql ) {
$reply = WFReply::newFromSQL( $sql );
$reply->thread = $this; // saves thread making DB query to find
$replies[] = $reply;
}
$this->replies = $replies;
}
return $this->replies;
}
/**
* Add a reply to this thread
*
* @param string $text: user-supplied reply text
* @return boolean: true if success, or false on failure
*/
function addReply( $text ) {
return WFReply::add( $this, $text );
}
/**
* Deletes the thread
*
* @param $threadId Integer: ID number of the thread to delete
* @return string: HTML
*/
function delete() {
$user = $this->getUser();
if (
$user->isAnon() ||
( $user->getId() != $this->getPostedBy() && !$user->isAllowed( 'wikiforum-moderator' ) )
) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-delete', 'wikiforum-error-general' );
return $error . $this->show();
}
$dbw = wfGetDB( DB_MASTER );
$dbw->delete(
'wikiforum_threads',
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
// Update threads/replies counters
$replyCount = $this->getReplyCount();
// When the thread we're about to delete is deleted, we also need
// to update the information about the latest post & its author
$row = $dbw->selectRow(
'wikiforum_threads',
array(
'wft_last_post_user',
'wft_last_post_user_ip',
'wft_last_post_timestamp',
),
array('wft_forum' => $this->getForum()->getId() ),
__METHOD__,
array( 'LIMIT' => 1 )
);
// Update the forum table so that the data shown on Special:WikiForum is up to date
$dbw->update(
'wikiforum_forums',
array(
"wff_reply_count = wff_reply_count - $replyCount",
'wff_thread_count = wff_thread_count - 1',
'wff_last_post_user' => $row->wft_last_post_user,
'wff_last_post_user_ip' => $row->wft_last_post_user_ip,
'wff_last_post_timestamp' => $row->wft_last_post_timestamp
),
array( 'wff_forum' => $this->getForum()->getId() ),
__METHOD__
);
return $this->getForum()->show();
}
/**
* Reopens the thread
*
* @return string: HTML
*/
function reopen() {
if ( !$this->getUser()->isAllowed( 'wikiforum-moderator' ) ) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-thread-reopen', 'wikiforum-error-general' );
return $error . $this->show();
}
$dbw = wfGetDB( DB_MASTER );
$result = $dbw->update(
'wikiforum_threads',
array(
'wft_closed' => 0,
'wft_closed_user' => 0
),
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
$this->data->wft_closed = 0;
$this->data->wft_closed_user = 0;
return $this->show();
}
/**
* Closes the thread
*
* @return string: HTML
*/
function close() {
$user = $this->getUser();
if ( !$user->isAllowed( 'wikiforum-moderator' ) ) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-thread-close', 'wikiforum-error-general' );
return $error . $this->show();
}
$dbw = wfGetDB( DB_MASTER );
$result = $dbw->update(
'wikiforum_threads',
array(
'wft_closed' => wfTimestampNow(),
'wft_closed_user' => $user->getId(),
'wft_closed_user_ip' => $this->getRequest()->getIP()
),
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
$this->data->wft_closed = wfTimestampNow();
$this->data->wft_closed_user = $user->getId();
$this->data->wft_closed_user_ip = $this->getRequest()->getIP();
return $this->show();
}
/**
* Make the thread sticky
*
* @return boolean: success?
*/
function makeSticky() {
return $this->sticky( 1 );
}
/**
* Stop the thread being sticky
*
* @return boolean: success?
*/
function removeSticky() {
return $this->sticky( 0 );
}
/**
* Changes the thread's sticky value. Do not use, use makeSticky() and removeSticky() instead
*
* @param int $value: 0/1 (for db)
* @return string: HTML
*/
private function sticky( $value ) {
if ( !$this->getUser()->isAllowed( 'wikiforum-admin' ) ) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-sticky', 'wikiforum-error-general' );
return $error . $this->show();
}
$dbw = wfGetDB( DB_MASTER );
$result = $dbw->update(
'wikiforum_threads',
array( 'wft_sticky' => $value ),
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
$this->data->wft_sticky = $value;
return $this->show();
}
/**
* Edit the title and/or text of the thread
*
* @param string $title: user supplied new title
* @param string $text: user supplied new text
* @return string: HTML
*/
function edit( $title, $text ) {
$user = $this->getUser();
if (
$text && $title && strlen( $text ) == 1 ||
strlen( $title ) == 1
) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-edit', 'wikiforum-error-no-text-or-title' );
return $error . $this->showEditor();
}
if ( $this->getName() == $title && $this->getText() == $text ) {
return $this->show(); // nothing to do
}
if (
$user->isAnon() ||
(
$user->getId() != $this->getPostedById() &&
!$user->isAllowed( 'wikiforum-moderator' )
)
) {
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-general-title', 'wikiforum-error-no-rights' );
return $error . $this->show();
}
$dbw = wfGetDB( DB_MASTER );
$result = $dbw->update(
'wikiforum_threads',
array(
'wft_thread_name' => $title,
'wft_text' => $text,
'wft_edit_timestamp' => wfTimestampNow(),
'wft_edit_user' => $user->getId(),
'wft_edit_user_ip' => $this->getRequest()->getIP(),
),
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
$this->data->wft_thread_name = $title;
$this->data->wft_text = $text;
$this->data->wft_edit_timestamp = wfTimestampNow();
$this->data->wft_edit_user = $user->getId();
$this->data->wft_edit_user_ip = $this->getRequest()->getIP();
return $this->show();
}
/**
* Get a descriptive icon for the current thread.
* "New" icon for new threads (threads that are not over $dayDefinitionNew
* days old), sticky icon for stickied threads,
* locked icon for locked threads and an ordinary thread icon for
* everything else.
*
* @return HTML: img tag
*/
function getIcon() {
global $wgExtensionAssetsPath;
// Threads that are this many days old or newer are considered "new"
$dayDefinitionNew = intval( wfMessage( 'wikiforum-day-definition-new' )->inContentLanguage()->plain() );
$olderTimestamp = wfTimestamp( TS_MW, strtotime( '-' . $dayDefinitionNew . ' days' ) );
$imagePath = $wgExtensionAssetsPath . '/WikiForum/icons';
if ( $this->isSticky() ) {
return '<img src="' . $imagePath . '/tag_blue.png" title="' . wfMessage( 'wikiforum-sticky' )->text() . '" /> ';
} elseif ( $this->isClosed() ) {
return '<img src="' . $imagePath . '/lock.png" title="' . wfMessage( 'wikiforum-thread-closed' )->text() . '" /> ';
} elseif ( $this->getPostedTimestamp() > $olderTimestamp ) {
return '<img src="' . $imagePath . '/new.png" title="' . wfMessage( 'wikiforum-new-thread' )->text() . '" /> ';
} else {
return '<img src="' . $imagePath . '/note.png" title="' . wfMessage( 'wikiforum-thread' )->text() . '" /> ';
}
}
/**
* Show this thread, with headers, replies, frames, et al.
*
* @return string: HTML of thread
*/
function show() {
global $wgExtensionAssetsPath;
$request = $this->getRequest();
$out = $this->getOutput();
$output = '';
$specialPage = SpecialPage::getTitleFor( 'WikiForum' );
$menuLink = '';
if ( $this->getUser()->isAllowed( 'wikiforum-admin' ) ) {
if ( $this->isSticky() ) {
$icon = '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/tag_blue_delete.png" title="' . wfMessage( 'wikiforum-remove-sticky' )->text() . '" /> ';
$menuLink = $icon . '<a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'removesticky', 'thread' => $this->getId() ) ) ) . '">' .
wfMessage( 'wikiforum-remove-sticky' )->text() . '</a> ';
} else {
$icon = '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/tag_blue_add.png" title="' . wfMessage( 'wikiforum-make-sticky' )->text() . '" /> ';
$menuLink = $icon . '<a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'makesticky', 'thread' => $this->getId() ) ) ) . '">' .
wfMessage( 'wikiforum-make-sticky' )->text() . '</a> ';
}
}
$icon = '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/comment_add.png" title="' . wfMessage( 'wikiforum-write-reply' )->text() . '" /> ';
// Replying is only possible to open threads
if ( !$this->isClosed() ) {
$menuLink .= $icon . '<a href="#writereply">' . wfMessage( 'wikiforum-write-reply' )->text() . '</a>';
}
$output .= WikiForumGui::showSearchbox();
if ( $this->isClosed() ) {
$output .= WikiForumClass::showErrorMessage( 'wikiforum-thread-closed', 'wikiforum-error-thread-closed', 'lock.png' );
}
$output .= WikiForumGui::showHeaderRow( $this->showHeaderLinks(), $menuLink );
// Add topic name to the title
$out->setPageTitle( wfMessage( 'wikiforum-topic-name', $this->getName() )->text() );
$out->setHTMLTitle( wfMessage( 'wikiforum-topic-name', $this->getName() )->text() );
$output .= $this->showHeader();
// limiting
$maxPerPage = intval( wfMessage( 'wikiforum-max-replies-per-page' )->inContentLanguage()->plain() );
if ( is_numeric( $request->getVal( 'page' ) ) ) {
$limit_page = $request->getVal( 'page' ) - 1;
} else {
$limit_page = 0;
}
$replies = $this->getReplies();
if ( $maxPerPage > 0 ) {
$replies = array_slice( $replies, $limit_page * $maxPerPage, $maxPerPage );
}
foreach ( $replies as $reply ) {
$output .= $reply->show();
}
$output .= $this->showFooter();
if ( $maxPerPage > 0 ) {
$dbr = wfGetDB( DB_SLAVE );
$countReplies = $dbr->selectRow(
'wikiforum_replies',
'COUNT(*) AS count',
array( 'wfr_thread' => $this->getId() ),
__METHOD__
);
$output .= WikiForumGui::showFooterRow(
$limit_page,
$countReplies->count,
$maxPerPage,
array( 'thread' => $this->getId() )
);
}
if ( !$this->isClosed() ) {
$quoteReply = $request->getInt( 'quotereply', 0 );
$quoteThread = $request->getBool( 'quotethread', false );
$output .= $this->showNewReplyForm( $quoteReply, $quoteThread );
}
if ( !wfReadOnly() ) {
$dbw = wfGetDB( DB_MASTER );
$dbw->update(
'wikiforum_threads',
array( 'wft_view_count = wft_view_count + 1' ),
array( 'wft_thread' => $this->getId() ),
__METHOD__
);
}
return $output;
}
/**
* Show an item (row) for a list (table), for this thread. Used on forum pages and the <WikiForumList> tag
* Do not use. Use showListItem() and showTagListItem() below.
*
* @param extraInfo string: any extra information to show after the posted info
* @return string
*/
private function showListItemMain( $class, $extraInfo = '' ) {
$output = '<tr class="mw-wikiforum-';
if ( $this->isSticky() ) {
$output .= 'sticky';
} else {
$output .= 'normal';
}
$desc = '<p class="mw-wikiforum-thread">' . $this->getIcon() . $this->showLink() .
'<p class="mw-wikiforum-descr">' . $this->showPostedInfo() . $extraInfo . '</p></p>';
$output .= '">
<td class="mw-wikiforum-title">' . $desc . '</td>
<td class="mw-wikiforum-value">' . $this->getReplyCount() . '</td>
<td class="mw-wikiforum-value">' . $this->getViewCount() . '</td>
<td class="mw-wikiforum-value">' . $this->showLastPostInfo() . '</td>
</tr>';
return $output;
}
/**
* Show a row for this thread, for a forum page
*
* @return string
*/
function showListItem() {
if ( $this->isSticky() ) {
$class = 'sticky';
} else {
$class = 'normal';
}
return $this->showListItemMain( $class );
}
/**
* Show a row for this thread, for the <WikiForumList> tag
*
* @return string
*/
function showTagListItem() {
$categoryLink = $this->getForum()->getCategory()->showLink();
$forumLink = $this->getForum()->showPlainLink();
$extraInfo = '<br />' . wfMessage( 'wikiforum-forum', $categoryLink, $forumLink )->text();
return $this->showListItemMain( 'normal', $extraInfo );
}
/**
* Shows the edit/delete buttons for the topic author, moderators and also
* close (lock) and reopen (unlock) buttons for moderators.
*
* @return HTML
*/
function showButtons() {
global $wgExtensionAssetsPath;
$user = $this->getUser();
$editButtons = '';
$specialPage = SpecialPage::getTitleFor( 'WikiForum' );
$editButtons .= '<a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'thread' => $this->getId(), 'quotethread' => $this->getId() ) ) ) . '#writereply">';
$editButtons .= '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/comments_add.png" title="' . wfMessage( 'wikiforum-quote' )->text() . '" />';
$editButtons .= '</a>';
$forum = $this->getForum();
if (
$user->getId() == $this->getPostedById() ||
$user->isAllowed( 'wikiforum-moderator' )
) {
$editButtons .= ' <a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'editthread', 'thread' => $this->getId() ) ) ) . '">';
$editButtons .= '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/note_edit.png" title="' . wfMessage( 'wikiforum-edit-thread' )->text() . '" />';
$editButtons .= '</a> <a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'deletethread', 'thread' => $this->getId() ) ) ) . '">';
$editButtons .= '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/note_delete.png" title="' . wfMessage( 'wikiforum-delete-thread' )->text() . '" />';
$editButtons .= '</a> ';
// Only moderators can lock and reopen threads
if ( $user->isAllowed( 'wikiforum-moderator' ) ) {
if ( !$this->isClosed() ) {
$editButtons .= ' <a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'closethread', 'thread' => $this->getId() ) ) ) . '">';
$editButtons .= '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/lock_add.png" title="' . wfMessage( 'wikiforum-close-thread' )->text() . '" />';
$editButtons .= '</a>';
} else {
$editButtons .= ' <a href="' . htmlspecialchars( $specialPage->getFullURL( array( 'wfaction' => 'reopenthread', 'thread' => $this->getId() ) ) ) . '">';
$editButtons .= '<img src="' . $wgExtensionAssetsPath . '/WikiForum/icons/lock_open.png" title="' . wfMessage( 'wikiforum-reopen-thread' )->text() . '" />';
$editButtons .= '</a>';
}
}
}
return $editButtons;
}
/**
* Check whether a thread with the given title exists
*
* @param string $title
* @return boolean
*/
static function titleExists( $title ) {
return WFThread::newFromName( $title ) == true;
}
/**
* Add a new thread
*
* @param WFForum $forum: forum to add thread to
* @param string $title: thread title
* @param string $text: thread text
* @return boolean|WFThread: WFThread of new thread if success, otherwise false
*/
static function add( WFForum $forum, $title, $text ) {
global $wgRequest, $wgUser, $wgWikiForumAllowAnonymous, $wgWikiForumLogInRC, $wgLang;
if ( !$wgWikiForumAllowAnonymous && $wgUser->isAnon() ) {
return WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-no-rights' );
}
if ( strlen( $text ) == 0 || strlen( $title ) == 0 ) { // show form again, return it
$error = WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-no-text-or-title' );
return $error . $forum->showNewThreadForm( $title, $text );
}
if ( WFThread::titleExists( $title ) ) {
return WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-title-already-exists' );
}
$title = trim( $title );
if ( preg_replace( '/[' . Title::legalChars() . ']/', '', $title ) ) { // removes all legal chars, then sees if string has length
return WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-bad-title' );
}
if ( $forum->isAnnouncement() && !$wgUser->isAllowed( 'wikiforum-moderator' ) ) {
return WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-no-rights' );
}
if ( WikiForumClass::useCaptcha() ) {
$captcha = ConfirmEditHooks::getInstance();
$captcha->trigger = 'wikiforum';
if ( !ConfirmEditHooks::getInstance()->passCaptcha() ) {
$output = WikiForumClass::showErrorMessage('wikiforum-error-add', 'wikiforum-error-captcha');
$output .= WFThread::showGeneralEditor(
$title,
'',
$text,
array(
'wfaction' => 'savenewthread',
'forum' => $forum->getId()
)
);
return $output;
}
}
$dbw = wfGetDB( DB_MASTER );
$timestamp = wfTimestampNow();
$result = $dbw->insert(
'wikiforum_threads',
array(
'wft_thread_name' => $title,
'wft_text' => $text,
'wft_posted_timestamp' => $timestamp,
'wft_user' => $wgUser->getId(),
'wft_user_ip' => $wgRequest->getIP(),
'wft_forum' => $forum->getId(),
'wft_last_post_timestamp' => $timestamp
),
__METHOD__
);
$thread = WFThread::newFromName( $title );
$thread->forum = $forum; // saves an extra DB query
$dbw->update( // update thread counters
'wikiforum_forums',
array(
'wff_thread_count = wff_thread_count + 1',
'wff_last_post_user' => $wgUser->getId(),
'wff_last_post_user_ip' => $wgRequest->getIP(),
'wff_last_post_timestamp' => $timestamp
),
array( 'wff_forum' => $forum->getId() ),
__METHOD__
);
$logEntry = new ManualLogEntry( 'forum', 'add-thread' );
$logEntry->setPerformer( $wgUser );
$logEntry->setTarget( SpeciaLPage::getTitleFor( 'wikiforum' ) );
$shortText = $wgLang->truncate( $text, 50 );
$logEntry->setComment( $shortText );
$logEntry->setParameters( array(
'4::thread-name' => $title
) );
$logid = $logEntry->insert();
if ( $wgWikiForumLogInRC ) {
$logEntry->publish( $logid );
}
if ( $result ) {
return $thread->show();
} else {
return WikiForumClass::showErrorMessage( 'wikiforum-error-add', 'wikiforum-error-general' );
}
}
// GUI METHODS
/**
* Show the header row links - the breadcrumb navigation
* (Overview > Category name > Forum > Thread)
*
* @return string
*/
function showHeaderLinks() {
$specialPageObj = SpecialPage::getTitleFor( 'WikiForum' );
$output = $this->getForum()->showHeaderLinks();
return $output . ' > ' . $this->showLink();
}
/**
* Get the thread header. This is used only for the starting post.
*
* @return string
*/
function showHeader() {
$posted = $this->showPostedInfo();
if ( $this->getEditedTimestamp() > 0 ) {
$posted .= '<br /><i>' . $this->showEditedInfo() . '</i>';
}
return WikiForumGui::showFrameHeader() . '
<table style="width:100%">
<tr>
<th class="mw-wikiforum-thread-top" style="text-align: right;">[#' . $this->getId() . ']</th>
</tr>
<tr>
<td class="mw-wikiforum-thread-main" colspan="2">' . WikiForumClass::showAvatar( $this->getPostedBy() ) .
WikiForumClass::parseIt( $this->getText() ) . WikiForumGui::showBottomLine( $posted, $this->showButtons() ) . '
</td>
</tr>';
}
function showHeaderForSearch() {
$posted = $this->showPostedInfo();
$posted .= '<br />' . wfMessage( 'wikiforum-search-thread', $this->showLink() )->text();
return '<tr>
<td class="mw-wikiforum-thread-main" colspan="2">' . WikiForumClass::showAvatar( $this->getPostedBy() ) .
WikiForumClass::parseIt( $this->getText() ) . WikiForumGui::showBottomLine( $posted ) . '
</td>
</tr>';
}
/**
* Show the thread's footer
*
* @return string
*/
function showFooter() {
return '</table>' . WikiForumGui::showFrameFooter();
}
/**
* Show the editor for this thread
*
* @return string
*/
function showEditForm() {
return WFThread::showGeneralEditor(
$this->getName(),
'',
$this->getText(),
array(
'wfaction' => 'savethread',
'thread' => $this->getId()
)
);
}
/**
* Show the editor for adding a thread/editing one
*
* @param string $titleValue: value to preload the title input with
* @param string $titlePlaceholder: the placeholder element of the title input
* @param string $textValue: value to preload the text field with
* @param array $params: array of URL params to pass to the form
* @return string
*/
static function showGeneralEditor( $titleValue, $titlePlaceholder, $textValue, $params ) {
$titleValue = str_replace( '"', '"', $titleValue );
$titlePlaceholder = str_replace( '"', '"', $titlePlaceholder );
$input = '<tr><td><input type="text" name="name" style="width:100%" placeholder="' . $titlePlaceholder . '" value="' . $titleValue . '" /></td></tr>';
return WikiForumGui::showWriteForm( true, $params, $input, '25em', $textValue, wfMessage( 'wikiforum-save-thread' )->text() );
}
/**
* Show the editor for adding a new reply to this thread
*
* @param $quoteReply int: the ID of the reply to quote in the editor. 0 for not quoting a reply
* @param $quoteThread boolean: true-quote this thread in the editor. false-don't
* @return string: HTML the editor
*/
function showNewReplyForm( $quoteReply, $quoteThread ) {
$textValue = '';
if ( $quoteReply ) {
$reply = WFReply::newFromID( $quoteReply );
if ( $reply ) {
$posted = $reply->showPlainPostedInfo();
$textValue = '[quote=' . $posted . ']' . $reply->getText() . '[/quote]';
}
} elseif ( $quoteThread ) {
$posted = $this->showPlainPostedInfo();
$textValue = '[quote=' . $posted . ']' . $this->getText() . '[/quote]';
} elseif ( $this->preloadText ) {
$textValue = $this->preloadText;
}
return WFReply::showGeneralEditor(
array(
'wfaction' => 'savenewreply',
'thread' => $this->getId()
),
$textValue
);
}
}