Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php |
— | — | @@ -271,6 +271,8 @@ |
272 | 272 | 'lqt-drag-save' => 'Confirm', |
273 | 273 | 'lqt-drag-reason' => 'Reason:', |
274 | 274 | 'lqt-drag-subject' => 'Subject for new thread:', |
| 275 | + 'lqt-edit-signature' => '(edit signature)', |
| 276 | + 'lqt-preview-signature' => '(preview)', |
275 | 277 | |
276 | 278 | // Feeds |
277 | 279 | 'lqt-feed-title-all' => '{{SITENAME}} — New posts', |
Index: trunk/extensions/LiquidThreads/classes/View.php |
— | — | @@ -27,9 +27,6 @@ |
28 | 28 | protected $sort_order = LQT_NEWEST_CHANGES; |
29 | 29 | |
30 | 30 | static $stylesAndScriptsDone = false; |
31 | | - |
32 | | - static $userSignatureCache = array(); |
33 | | - static $boringSignatureCache = array(); |
34 | 31 | |
35 | 32 | function __construct( &$output, &$article, &$title, &$user, &$request ) { |
36 | 33 | $this->article = $article; |
— | — | @@ -460,10 +457,32 @@ |
461 | 458 | Xml::hidden( 'lqt_nonce', wfGenerateToken() ) . |
462 | 459 | Xml::hidden( 'offset', $offset ); |
463 | 460 | |
| 461 | + $signatureText = $this->request->getVal( 'wpLqtSignature', null ); |
| 462 | + |
| 463 | + if ( is_null($signatureText) ) { |
| 464 | + if ( !$thread && $edit_type != 'summarize' ) { |
| 465 | + $signatureText = LqtView::getUserSignature( $this->user ); |
| 466 | + } else { |
| 467 | + $signatureText = $thread->signature(); |
| 468 | + } |
| 469 | + } |
| 470 | + |
| 471 | + $signatureHTML = LqtView::parseSignature( $signatureText ); |
| 472 | + |
| 473 | + // Signature edit box |
| 474 | + $signaturePreview = Xml::tags( 'span', |
| 475 | + array( 'class' => 'lqt-signature-preview', |
| 476 | + 'style' => 'display: none;' ), |
| 477 | + $signatureHTML ); |
| 478 | + $signatureEditBox = Xml::input( 'wpLqtSignature', 45, $signatureText, |
| 479 | + array( 'class' => 'lqt-signature-edit' ) ); |
| 480 | + |
| 481 | + $signatureEditor = $signaturePreview . $signatureEditBox; |
| 482 | + |
464 | 483 | $e->editFormTextAfterContent .= |
465 | | - Xml::tags( 'p', null, $this->getSignature( $this->user ) ); |
| 484 | + $signatureEditor; |
466 | 485 | $e->previewTextAfterContent .= |
467 | | - Xml::tags( 'p', null, $this->getSignature( $this->user ) ); |
| 486 | + Xml::tags( 'p', null, $signatureHTML ); |
468 | 487 | |
469 | 488 | // Add a one-time random string to a hidden field. Store the random string |
470 | 489 | // in memcached on submit and don't allow the edit to go ahead if it's already |
— | — | @@ -517,7 +536,7 @@ |
518 | 537 | $thread = self::postEditUpdates( |
519 | 538 | $edit_type, $edit_applies_to, $article, |
520 | 539 | $this->article, $subject, $e->summary, $thread, |
521 | | - $e->textbox1, $bump |
| 540 | + $e->textbox1, $bump, $signatureText |
522 | 541 | ); |
523 | 542 | |
524 | 543 | if ( $submitted_nonce && $nonce_key ) { |
— | — | @@ -542,16 +561,23 @@ |
543 | 562 | |
544 | 563 | static function postEditUpdates( $edit_type, $edit_applies_to, $edit_page, $article, |
545 | 564 | $subject, $edit_summary, $thread, $new_text, |
546 | | - $bump = null ) { |
| 565 | + $bump = null, $signature = null ) { |
547 | 566 | // Update metadata - create and update thread and thread revision objects as |
548 | 567 | // appropriate. |
| 568 | + |
| 569 | + $noSignature = false; |
| 570 | + if ( is_null($signature) ) { |
| 571 | + global $wgUser; |
| 572 | + $signature = LqtView::getUserSignature( $wgUser ); |
| 573 | + $noSignature = true; |
| 574 | + } |
549 | 575 | |
550 | 576 | if ( $edit_type == 'reply' ) { |
551 | 577 | $subject = $edit_applies_to->subject(); |
552 | 578 | |
553 | 579 | $thread = Thread::create( $edit_page, $article, $edit_applies_to, |
554 | 580 | Threads::TYPE_NORMAL, $subject, |
555 | | - $edit_summary, $bump ); |
| 581 | + $edit_summary, $bump, $signature ); |
556 | 582 | |
557 | 583 | global $wgUser; |
558 | 584 | NewMessages::markThreadAsReadByUser( $edit_applies_to, $wgUser ); |
— | — | @@ -566,12 +592,16 @@ |
567 | 593 | ? Threads::CHANGE_EDITED_ROOT |
568 | 594 | : Threads::CHANGE_ROOT_BLANKED; |
569 | 595 | |
| 596 | + if ( $signature && !$noSignature ) { |
| 597 | + $thread->setSignature( $signature ); |
| 598 | + } |
| 599 | + |
570 | 600 | // Add the history entry. |
571 | 601 | $thread->commitRevision( $type, $thread, $edit_summary, $bump ); |
572 | 602 | } else { |
573 | 603 | $thread = Thread::create( $edit_page, $article, null, |
574 | 604 | Threads::TYPE_NORMAL, $subject, |
575 | | - $edit_summary ); |
| 605 | + $edit_summary, null, $signature ); |
576 | 606 | } |
577 | 607 | |
578 | 608 | return $thread; |
— | — | @@ -865,6 +895,8 @@ |
866 | 896 | 'lqt-drag-save', |
867 | 897 | 'lqt-drag-reason', |
868 | 898 | 'lqt-drag-subject', |
| 899 | + 'lqt-edit-signature', |
| 900 | + 'lqt-preview-signature', |
869 | 901 | ); |
870 | 902 | |
871 | 903 | $data = array(); |
— | — | @@ -1042,9 +1074,9 @@ |
1043 | 1075 | global $wgUser, $wgLang; |
1044 | 1076 | $sk = $wgUser->getSkin(); |
1045 | 1077 | |
1046 | | - $author = $thread->author(); |
1047 | | - |
1048 | | - $signature = $this->getSignature( $author ); |
| 1078 | + $signature = $thread->signature(); |
| 1079 | + $signature = LqtView::parseSignature( $signature ); |
| 1080 | + |
1049 | 1081 | $signature = Xml::tags( 'span', array( 'class' => 'lqt-thread-user-signature' ), |
1050 | 1082 | $signature ); |
1051 | 1083 | |
— | — | @@ -1643,29 +1675,40 @@ |
1644 | 1676 | } |
1645 | 1677 | } |
1646 | 1678 | |
1647 | | - function getBoringSignature( $user, $uid, $name ) { |
1648 | | - if ( isset( self::$boringSignatureCache[$name] ) ) { |
1649 | | - return self::$boringSignatureCache[$name]; |
| 1679 | + static function getUserSignature( $user, $uid = null ) { |
| 1680 | + global $wgParser, $wgOut, $wgTitle; |
| 1681 | + if ( !$user ) { |
| 1682 | + $user = User::newFromId( $uid ); |
1650 | 1683 | } |
1651 | 1684 | |
1652 | | - $msg = ( $uid > 0 ) ? 'signature' : 'signature-anon'; |
| 1685 | + $sig = $wgParser->getUserSig( $user ); |
1653 | 1686 | |
1654 | | - $sig = wfMsgExt( $msg, 'parseinline', array( $name, $name ) ); |
1655 | | - |
1656 | | - self::$boringSignatureCache[$name] = $sig; |
1657 | | - |
1658 | 1687 | return $sig; |
1659 | 1688 | } |
1660 | 1689 | |
1661 | | - function getUserSignature( $user, $uid, $name ) { |
1662 | | - if ( isset( self::$userSignatureCache[$name] ) ) { |
1663 | | - return self::$userSignatureCache[$name]; |
1664 | | - } |
| 1690 | + static function parseSignature( $sig ) { |
| 1691 | + global $wgParser, $wgOut, $wgTitle; |
1665 | 1692 | |
1666 | | - if ( !$user ) { |
1667 | | - $user = User::newFromId( $uid ); |
| 1693 | + static $parseCache = array(); |
| 1694 | + $sigKey = md5($sig); |
| 1695 | + |
| 1696 | + if ( isset( $parseCache[$sigKey] ) ) { |
| 1697 | + return $parseCache[$sigKey]; |
1668 | 1698 | } |
1669 | 1699 | |
| 1700 | + // Parser gets antsy about parser options here if it hasn't parsed anything before. |
| 1701 | + $wgParser->clearState(); |
| 1702 | + $wgParser->setTitle( $wgTitle ); |
| 1703 | + $wgParser->mOptions = new ParserOptions; |
| 1704 | + |
| 1705 | + $sig = $wgOut->parseInline( $sig ); |
| 1706 | + |
| 1707 | + $parseCache[$sigKey] = $sig; |
| 1708 | + |
| 1709 | + return $sig; |
| 1710 | + } |
| 1711 | + |
| 1712 | + static function signaturePST( $sig, $user ) { |
1670 | 1713 | global $wgParser, $wgOut, $wgTitle; |
1671 | 1714 | |
1672 | 1715 | // Parser gets antsy about parser options here if it hasn't parsed anything before. |
— | — | @@ -1673,13 +1716,9 @@ |
1674 | 1717 | $wgParser->setTitle( $wgTitle ); |
1675 | 1718 | $wgParser->mOptions = new ParserOptions; |
1676 | 1719 | |
1677 | | - $sig = $wgParser->getUserSig( $user ); |
1678 | | - $sig = $wgParser->preSaveTransform( $sig, $this->title, $user, |
| 1720 | + $sig = $wgParser->preSaveTransform( $sig, $wgTitle, $user, |
1679 | 1721 | $wgParser->mOptions, false ); |
1680 | | - $sig = $wgOut->parseInline( $sig ); |
1681 | 1722 | |
1682 | | - self::$userSignatureCache[$name] = $sig; |
1683 | | - |
1684 | 1723 | return $sig; |
1685 | 1724 | } |
1686 | 1725 | |
Index: trunk/extensions/LiquidThreads/classes/Hooks.php |
— | — | @@ -7,81 +7,7 @@ |
8 | 8 | public static $editAppliesTo = null; |
9 | 9 | public static $editArticle = null; |
10 | 10 | public static $editTalkpage = null; |
11 | | - |
12 | | - static function customizeOldChangesList( &$changeslist, &$s, $rc ) { |
13 | | - if ( $rc->getTitle()->getNamespace() != NS_LQT_THREAD ) |
14 | | - return true; |
15 | | - |
16 | | - $thread = Threads::withRoot( new Article( $rc->getTitle() ) ); |
17 | | - if ( !$thread ) return true; |
18 | 11 | |
19 | | - LqtView::addJSandCSS(); |
20 | | - wfLoadExtensionMessages( 'LiquidThreads' ); |
21 | | - |
22 | | - if ( $rc->mAttribs['rc_new'] ) { |
23 | | - global $wgOut; |
24 | | - |
25 | | - $sig = ""; |
26 | | - $changeslist->insertUserRelatedLinks( $sig, $rc ); |
27 | | - |
28 | | - // This should be stored in RC. |
29 | | - $rev = Revision::newFromId( $rc->mAttribs['rc_this_oldid'] ); |
30 | | - $quote = $rev->getText(); |
31 | | - $link = ''; |
32 | | - if ( strlen( $quote ) > 230 ) { |
33 | | - $sk = $changeslist->skin; |
34 | | - $quote = substr( $quote, 0, 200 ); |
35 | | - $link = $sk->link( $thread->title(), wfMsg( 'lqt_rc_ellipsis' ), |
36 | | - array( 'class' => 'lqt_rc_ellipsis' ), array(), array( 'known' ) ); |
37 | | - } |
38 | | - |
39 | | - $quote = htmlspecialchars( $quote ) . $link; |
40 | | - |
41 | | - if ( $thread->isTopmostThread() ) { |
42 | | - $message_name = 'lqt_rc_new_discussion'; |
43 | | - } else { |
44 | | - $message_name = 'lqt_rc_new_reply'; |
45 | | - } |
46 | | - |
47 | | - $tmp_title = $thread->article()->getTitle(); |
48 | | - $tmp_title->setFragment( '#' . LqtView::anchorName( $thread ) ); |
49 | | - |
50 | | - // Make sure it points to the right page. The Pager seems to use the DB |
51 | | - // representation of a timestamp for its offset field, odd. |
52 | | - $dbr = wfGetDB( DB_SLAVE ); |
53 | | - $offset = wfTimestamp( TS_UNIX, $thread->topmostThread()->sortkey() ) + 1; |
54 | | - $offset = $dbr->timestamp( $offset ); |
55 | | - |
56 | | - $thread_link = $changeslist->skin->link( $tmp_title, |
57 | | - htmlspecialchars( $thread->subjectWithoutIncrement() ), |
58 | | - array(), array( 'offset' => $offset ), array( 'known' ) ); |
59 | | - |
60 | | - $talkpage_link = $changeslist->skin->link( |
61 | | - $thread->article()->getTitle(), |
62 | | - null, |
63 | | - array(), array(), array( 'known' ) ); |
64 | | - |
65 | | - $s = wfMsg( $message_name, $thread_link, $talkpage_link, $sig ) |
66 | | - . Xml::tags( 'blockquote', array( 'class' => 'lqt_rc_blockquote' ), $quote ); |
67 | | - |
68 | | - $classes = array(); |
69 | | - $changeslist->insertTags( $s, $rc, $classes ); |
70 | | - $changeslist->insertExtra( $s, $rc, $classes ); |
71 | | - } else { |
72 | | - // Add whether it was original author. |
73 | | - if ( $thread->author()->getName() != $rc->mAttribs['rc_user_text'] ) { |
74 | | - $appendix = Xml::tags( 'span', |
75 | | - array( 'class' => 'lqt_rc_author_notice ' . |
76 | | - 'lqt_rc_author_notice_others' ), |
77 | | - wfMsgExt( 'lqt_rc_author_others', 'parseinline' ) |
78 | | - ); |
79 | | - |
80 | | - $s .= ' ' . $appendix; |
81 | | - } |
82 | | - } |
83 | | - return true; |
84 | | - } |
85 | | - |
86 | 12 | static function setNewtalkHTML( $skintemplate, $tpl ) { |
87 | 13 | global $wgUser, $wgTitle, $wgOut; |
88 | 14 | |
— | — | @@ -147,14 +73,6 @@ |
148 | 74 | global $wgEnableEmail; |
149 | 75 | wfLoadExtensionMessages( 'LiquidThreads' ); |
150 | 76 | |
151 | | - // Whether or not to show user signatures |
152 | | - $preferences['lqtcustomsignatures'] = |
153 | | - array( |
154 | | - 'type' => 'toggle', |
155 | | - 'label-message' => 'lqt-preference-custom-signatures', |
156 | | - 'section' => 'lqt', |
157 | | - ); |
158 | | - |
159 | 77 | if ( $wgEnableEmail ) { |
160 | 78 | $preferences['lqtnotifytalk'] = |
161 | 79 | array( |
— | — | @@ -351,7 +269,6 @@ |
352 | 270 | $wgExtNewTables[] = array( 'user_message_state', "$dir/lqt.sql" ); |
353 | 271 | $wgExtNewTables[] = array( 'thread_history', "$dir/schema-changes/thread_history_table.sql" ); |
354 | 272 | |
355 | | - |
356 | 273 | $wgExtNewFields[] = array( "thread", "thread_article_namespace", "$dir/schema-changes/split-thread_article.sql" ); |
357 | 274 | $wgExtNewFields[] = array( "thread", "thread_article_title", "$dir/schema-changes/split-thread_article.sql" ); |
358 | 275 | $wgExtNewFields[] = array( "thread", "thread_ancestor", "$dir/schema-changes/normalise-ancestry.sql" ); |
— | — | @@ -365,6 +282,7 @@ |
366 | 283 | $wgExtNewFields[] = array( "thread", "thread_sortkey", "$dir/schema-changes/new-sortkey.sql" ); |
367 | 284 | $wgExtNewFields[] = array( 'thread', 'thread_replies', "$dir/schema-changes/store_reply_count.sql" ); |
368 | 285 | $wgExtNewFields[] = array( 'thread', 'thread_article_id', "$dir/schema-changes/store_article_id.sql" ); |
| 286 | + $wgExtNewFields[] = array( 'thread', 'thread_signature', "$dir/schema-changes/thread_signature.sql" ); |
369 | 287 | |
370 | 288 | $wgExtNewIndexes[] = array( 'thread', 'thread_summary_page', '(thread_summary_page)' ); |
371 | 289 | |
Index: trunk/extensions/LiquidThreads/classes/Thread.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | protected $subject; |
34 | 34 | protected $authorId; |
35 | 35 | protected $authorName; |
| 36 | + protected $signature; |
36 | 37 | |
37 | 38 | protected $allDataLoaded; |
38 | 39 | |
— | — | @@ -56,7 +57,7 @@ |
57 | 58 | |
58 | 59 | static function create( $root, $article, $superthread = null, |
59 | 60 | $type = Threads::TYPE_NORMAL, $subject = '', |
60 | | - $summary = '', $bump = null ) { |
| 61 | + $summary = '', $bump = null, $signature = null ) { |
61 | 62 | |
62 | 63 | $dbw = wfGetDB( DB_MASTER ); |
63 | 64 | |
— | — | @@ -87,6 +88,10 @@ |
88 | 89 | $thread->setSubject( $subject ); |
89 | 90 | $thread->setType( $type ); |
90 | 91 | |
| 92 | + if ( !is_null($signature) ) { |
| 93 | + $thread->setSignature( $signature ); |
| 94 | + } |
| 95 | + |
91 | 96 | $thread->insert(); |
92 | 97 | |
93 | 98 | if ( $superthread ) { |
— | — | @@ -242,6 +247,7 @@ |
243 | 248 | 'thread_editedness' => $this->editedness, |
244 | 249 | 'thread_sortkey' => $this->sortkey, |
245 | 250 | 'thread_replies' => $this->replyCount, |
| 251 | + 'thread_signature' => $this->signature, |
246 | 252 | ); |
247 | 253 | } |
248 | 254 | |
— | — | @@ -439,6 +445,7 @@ |
440 | 446 | 'thread_author_name' => 'authorName', |
441 | 447 | 'thread_sortkey' => 'sortkey', |
442 | 448 | 'thread_replies' => 'replyCount', |
| 449 | + 'thread_signature' => 'signature', |
443 | 450 | ); |
444 | 451 | |
445 | 452 | foreach ( $dataLoads as $db_field => $member_field ) { |
— | — | @@ -582,64 +589,6 @@ |
583 | 590 | |
584 | 591 | $userIds = array_keys( $userIds ); |
585 | 592 | |
586 | | - // Pull signature data and pre-cache in View object. |
587 | | - if ( count( $userIds ) ) { |
588 | | - $signatureDataCache = array_fill_keys( $userIds, array() ); |
589 | | - $res = $dbr->select( 'user_properties', |
590 | | - array( 'up_user', 'up_property', 'up_value' ), |
591 | | - array( 'up_property' => array( 'nickname', 'fancysig' ), |
592 | | - 'up_user' => $userIds ), |
593 | | - __METHOD__ ); |
594 | | - |
595 | | - foreach ( $res as $row ) { |
596 | | - $signatureDataCache[$row->up_user][$row->up_property] = $row->up_value; |
597 | | - } |
598 | | - |
599 | | - global $wgParser, $wgOut, $wgTitle; |
600 | | - |
601 | | - $setTitle = false; |
602 | | - if ( !$wgOut->getTitle() ) { |
603 | | - $setTitle = true; |
604 | | - } |
605 | | - |
606 | | - // Parser gets antsy about parser options here if it hasn't parsed anything before. |
607 | | - $wgParser->clearState(); |
608 | | - $wgParser->setTitle( $wgTitle ); |
609 | | - $wgParser->mOptions = new ParserOptions; |
610 | | - |
611 | | - foreach ( $userIds as $uid ) { |
612 | | - $user = User::newFromId( $uid ); // Should pull from UID cache. |
613 | | - $name = $user->getName(); |
614 | | - |
615 | | - // Grab sig data |
616 | | - $nickname = null; |
617 | | - $fancysig = (bool)User::getDefaultOption( 'fancysig' ); |
618 | | - |
619 | | - if ( isset( $signatureDataCache[$uid]['nickname'] ) ) |
620 | | - $nickname = $signatureDataCache[$uid]['nickname']; |
621 | | - if ( isset( $signatureDataCache[$uid]['fancysig'] ) ) |
622 | | - $fancysig = $signatureDataCache[$uid]['fancysig']; |
623 | | - |
624 | | - // Generate signature from Parser |
625 | | - |
626 | | - if ( $setTitle ) { |
627 | | - $user_t = Title::makeTitleSafe( NS_USER, $name ); |
628 | | - $wgOut->setTitle( $user_t ); |
629 | | - } |
630 | | - |
631 | | - $title = Title::newFromText( 'Main Page' ); |
632 | | - |
633 | | - $sig = $wgParser->preSaveTransform( $nickname, $title, |
634 | | - $user, $wgParser->mOptions, |
635 | | - false ); |
636 | | - $sig = $wgParser->getUserSig( $user, $nickname, $fancysig ); |
637 | | - $sig = $wgOut->parseInline( $sig ); |
638 | | - |
639 | | - // Save into LqtView for later use. |
640 | | - LqtView::$userSignatureCache[$name] = $sig; |
641 | | - } |
642 | | - } |
643 | | - |
644 | 593 | // Pull link batch data. |
645 | 594 | $linkBatch->execute(); |
646 | 595 | |
— | — | @@ -823,6 +772,16 @@ |
824 | 773 | Threads::synchroniseArticleData( $this->article, 100, 'cascade' ); |
825 | 774 | } |
826 | 775 | |
| 776 | + // Check for unfilled signature field. This field hasn't existed until |
| 777 | + // recently. |
| 778 | + if ( is_null( $this->signature ) ) { |
| 779 | + // Grab our signature. |
| 780 | + $sig = LqtView::getUserSignature( $this->author() ); |
| 781 | + |
| 782 | + $set['thread_signature'] = $sig; |
| 783 | + $this->setSignature( $sig ); |
| 784 | + } |
| 785 | + |
827 | 786 | if ( count( $set ) ) { |
828 | 787 | $dbw = wfGetDB( DB_MASTER ); |
829 | 788 | |
— | — | @@ -1438,4 +1397,13 @@ |
1439 | 1398 | |
1440 | 1399 | return true; |
1441 | 1400 | } |
| 1401 | + |
| 1402 | + public function signature() { |
| 1403 | + return $this->signature; |
| 1404 | + } |
| 1405 | + |
| 1406 | + public function setSignature($sig) { |
| 1407 | + $sig = LqtView::signaturePST( $sig, $this->author() ); |
| 1408 | + $this->signature = $sig; |
| 1409 | + } |
1442 | 1410 | } |
Index: trunk/extensions/LiquidThreads/lqt.sql |
— | — | @@ -25,6 +25,9 @@ |
26 | 26 | |
27 | 27 | -- Reply count, -1 means uninitialised. |
28 | 28 | thread_replies int(8) DEFAULT -1, |
| 29 | + |
| 30 | + -- Signature |
| 31 | + thread_signature TINYBLOB NULL, |
29 | 32 | |
30 | 33 | PRIMARY KEY thread_id (thread_id), |
31 | 34 | UNIQUE INDEX thread_root_page (thread_root), |
Index: trunk/extensions/LiquidThreads/api/ApiThreadAction.php |
— | — | @@ -39,6 +39,8 @@ |
40 | 40 | 'sortkey' => "Specifies the timestamp to which to set a thread's ". |
41 | 41 | "sort key. Must be in the form YYYYMMddhhmmss, ". |
42 | 42 | "a unix timestamp or 'now'.", |
| 43 | + 'signature' => 'Specifies the signature to use for that post. Can be '. |
| 44 | + 'NULL to specify the default signature', |
43 | 45 | ); |
44 | 46 | } |
45 | 47 | |
— | — | @@ -65,6 +67,7 @@ |
66 | 68 | 'render' => null, |
67 | 69 | 'bump' => null, |
68 | 70 | 'sortkey' => null, |
| 71 | + 'signature' => null, |
69 | 72 | ); |
70 | 73 | } |
71 | 74 | |
— | — | @@ -341,6 +344,11 @@ |
342 | 345 | $summary = $params['reason']; |
343 | 346 | } |
344 | 347 | |
| 348 | + $signature = null; |
| 349 | + if ( isset( $params['signature'] ) ) { |
| 350 | + $signature = $params['signature']; |
| 351 | + } |
| 352 | + |
345 | 353 | // Inform hooks what we're doing |
346 | 354 | LqtHooks::$editTalkpage = $talkpage; |
347 | 355 | LqtHooks::$editArticle = $article; |
— | — | @@ -379,7 +387,7 @@ |
380 | 388 | $title->resetArticleID( $articleId ); |
381 | 389 | |
382 | 390 | $thread = LqtView::postEditUpdates( 'new', null, $article, $talkpage, |
383 | | - $subject, $summary, null, $text, $bump ); |
| 391 | + $subject, $summary, null, $text, $bump, $signature ); |
384 | 392 | |
385 | 393 | $maxLag = wfGetLB()->getMaxLag(); |
386 | 394 | $maxLag = $maxLag[1]; |
— | — | @@ -446,6 +454,11 @@ |
447 | 455 | $summary = $params['reason']; |
448 | 456 | } |
449 | 457 | |
| 458 | + $signature = null; |
| 459 | + if ( isset( $params['signature'] ) ) { |
| 460 | + $signature = $params['signature']; |
| 461 | + } |
| 462 | + |
450 | 463 | // Grab data from parent |
451 | 464 | $talkpage = $replyTo->article(); |
452 | 465 | $subject = $replyTo->subject(); |
— | — | @@ -492,7 +505,7 @@ |
493 | 506 | $title->resetArticleID( $articleId ); |
494 | 507 | |
495 | 508 | $thread = LqtView::postEditUpdates( 'reply', $replyTo, $article, $talkpage, |
496 | | - $subject, $summary, null, $text, $bump ); |
| 509 | + $subject, $summary, null, $text, $bump, $signature ); |
497 | 510 | |
498 | 511 | $maxLag = wfGetLB()->getMaxLag(); |
499 | 512 | $maxLag = $maxLag[1]; |
Index: trunk/extensions/LiquidThreads/lqt.js |
— | — | @@ -125,6 +125,16 @@ |
126 | 126 | $j(container).find('#wpTextbox1').focus();//.autogrow(); |
127 | 127 | // Focus the subject field if there is one. Overrides previous line. |
128 | 128 | $j(container).find('#lqt_subject_field').focus(); |
| 129 | + |
| 130 | + // Update signature editor |
| 131 | + $j(container).find('input[name=wpLqtSignature]').hide(); |
| 132 | + $j(container).find('.lqt-signature-preview').show(); |
| 133 | + var editLink = $j('<a class="lqt-signature-edit-button"/>' ); |
| 134 | + editLink.text( wgLqtMessages['lqt-edit-signature'] ); |
| 135 | + editLink.click( liquidThreads.handleEditSignature ); |
| 136 | + editLink.attr('href', '#'); |
| 137 | + $j(container).find('.lqt-signature-preview').after(editLink); |
| 138 | + editLink.before(' '); |
129 | 139 | } |
130 | 140 | |
131 | 141 | var finishSetup = function() { |
— | — | @@ -158,7 +168,7 @@ |
159 | 169 | // Check for live preview |
160 | 170 | if ( $j('#wpLivePreview').length ) { |
161 | 171 | $j.getScript( stylepath+'/common/preview.js', |
162 | | - function() { setupLivePreview(); } ); |
| 172 | + function() { setupLivePreview(); } ); |
163 | 173 | } |
164 | 174 | }; |
165 | 175 | |
— | — | @@ -845,12 +855,20 @@ |
846 | 856 | }, |
847 | 857 | |
848 | 858 | 'handleAJAXSave' : function( e ) { |
| 859 | + e.preventDefault(); |
849 | 860 | var editform = $j(this).closest('.lqt-edit-form'); |
850 | 861 | var type = editform.find('input[name=lqt_method]').val(); |
851 | 862 | |
852 | 863 | var text = editform.find('#wpTextbox1').val(); |
853 | 864 | var summary = editform.find('#wpSummary').val(); |
854 | 865 | |
| 866 | + var signature; |
| 867 | + if ( editform.find('input[name=wpLqtSignature]').length ) { |
| 868 | + signature = editform.find('input[name=wpLqtSignature]').val(); |
| 869 | + } else { |
| 870 | + signature = undefined |
| 871 | + } |
| 872 | + |
855 | 873 | // Check if summary is undefined |
856 | 874 | if (summary === undefined) { |
857 | 875 | summary = ''; |
— | — | @@ -963,12 +981,12 @@ |
964 | 982 | |
965 | 983 | if ( type == 'reply' ) { |
966 | 984 | liquidThreads.doReply( replyThread, text, summary, |
967 | | - doneCallback, bump ); |
| 985 | + doneCallback, bump, signature ); |
968 | 986 | |
969 | 987 | e.preventDefault(); |
970 | 988 | } else if ( type == 'talkpage_new_thread' ) { |
971 | 989 | liquidThreads.doNewThread( wgPageName, subject, text, summary, |
972 | | - doneCallback, bump ); |
| 990 | + doneCallback, bump, signature ); |
973 | 991 | |
974 | 992 | e.preventDefault(); |
975 | 993 | } |
— | — | @@ -985,7 +1003,7 @@ |
986 | 1004 | } ); |
987 | 1005 | }, |
988 | 1006 | |
989 | | - 'doNewThread' : function( talkpage, subject, text, summary, callback, bump ) { |
| 1007 | + 'doNewThread' : function( talkpage, subject, text, summary, callback, bump, signature ) { |
990 | 1008 | liquidThreads.getToken( |
991 | 1009 | function(token) { |
992 | 1010 | var newTopicParams = |
— | — | @@ -1002,6 +1020,10 @@ |
1003 | 1021 | 'bump' : bump |
1004 | 1022 | }; |
1005 | 1023 | |
| 1024 | + if ( typeof signature != 'undefined' ) { |
| 1025 | + newTopicParams.signature = signature; |
| 1026 | + } |
| 1027 | + |
1006 | 1028 | $j.post( wgScriptPath+'/api'+wgScriptExtension, newTopicParams, |
1007 | 1029 | function(data) { |
1008 | 1030 | if (callback) { |
— | — | @@ -1011,7 +1033,7 @@ |
1012 | 1034 | } ); |
1013 | 1035 | }, |
1014 | 1036 | |
1015 | | - 'doReply' : function( thread, text, summary, callback, bump ) { |
| 1037 | + 'doReply' : function( thread, text, summary, callback, bump, signature ) { |
1016 | 1038 | liquidThreads.getToken( |
1017 | 1039 | function(token) { |
1018 | 1040 | var replyParams = |
— | — | @@ -1027,6 +1049,10 @@ |
1028 | 1050 | 'bump' : bump |
1029 | 1051 | }; |
1030 | 1052 | |
| 1053 | + if ( typeof signature != 'undefined' ) { |
| 1054 | + replyParams.signature = signature; |
| 1055 | + } |
| 1056 | + |
1031 | 1057 | $j.post( wgScriptPath+'/api'+wgScriptExtension, replyParams, |
1032 | 1058 | function(data) { |
1033 | 1059 | if (callback) { |
— | — | @@ -1459,6 +1485,60 @@ |
1460 | 1486 | |
1461 | 1487 | liquidThreads.apiRequest( apiRequest, doneCallback ); |
1462 | 1488 | } |
| 1489 | + }, |
| 1490 | + |
| 1491 | + 'handleEditSignature' : function(e) { |
| 1492 | + e.preventDefault(); |
| 1493 | + |
| 1494 | + var container = $j(this).parent(); |
| 1495 | + |
| 1496 | + container.find('.lqt-signature-preview').hide(); |
| 1497 | + container.find('input[name=wpLqtSignature]').show(); |
| 1498 | + $j(this).hide(); |
| 1499 | + |
| 1500 | + // Add a save button |
| 1501 | + var saveButton = $j('<a href="#"/>'); |
| 1502 | + saveButton.text( wgLqtMessages['lqt-preview-signature'] ); |
| 1503 | + saveButton.click( liquidThreads.handlePreviewSignature ); |
| 1504 | + |
| 1505 | + container.find('input[name=wpLqtSignature]').after(saveButton); |
| 1506 | + }, |
| 1507 | + |
| 1508 | + 'handlePreviewSignature' : function(e) { |
| 1509 | + e.preventDefault(); |
| 1510 | + |
| 1511 | + var container = $j(this).parent(); |
| 1512 | + |
| 1513 | + var spinner = $j('<span class="mw-small-spinner"/>'); |
| 1514 | + $j(this).replaceWith(spinner); |
| 1515 | + |
| 1516 | + var textbox = container.find('input[name=wpLqtSignature]'); |
| 1517 | + var preview = container.find('.lqt-signature-preview'); |
| 1518 | + |
| 1519 | + textbox.hide(); |
| 1520 | + var text = textbox.val(); |
| 1521 | + |
| 1522 | + var apiReq = |
| 1523 | + { |
| 1524 | + 'action' : 'parse', |
| 1525 | + 'text' : text, |
| 1526 | + 'pst' : '1', |
| 1527 | + 'prop' : 'text' |
| 1528 | + }; |
| 1529 | + |
| 1530 | + liquidThreads.apiRequest( function() { return apiReq; }, |
| 1531 | + function(data) { |
| 1532 | + var html = $j(data.parse.text['*'].trim()); |
| 1533 | + |
| 1534 | + if (html.length == 2) { // Not 1, because of the NewPP report |
| 1535 | + html = html.contents(); |
| 1536 | + } |
| 1537 | + |
| 1538 | + preview.empty().append(html); |
| 1539 | + preview.show(); |
| 1540 | + spinner.remove(); |
| 1541 | + container.find('.lqt-signature-edit-button').show(); |
| 1542 | + } ); |
1463 | 1543 | } |
1464 | 1544 | } |
1465 | 1545 | |