Index: trunk/extensions/LiquidThreads/classes/View.php |
— | — | @@ -539,17 +539,6 @@ |
540 | 540 | $this->output->setArticleFlag( false ); |
541 | 541 | |
542 | 542 | if ( $e->didSave ) { |
543 | | - // Move the thread and replies if subject changed. |
544 | | - if ( $edit_type == 'editExisting' && $subject && |
545 | | - $subject != $thread->subject() ) { |
546 | | - $thread->setSubject( $subject ); |
547 | | - $thread->commitRevision( Threads::CHANGE_EDITED_SUBJECT, |
548 | | - $thread, $e->summary ); |
549 | | - |
550 | | - // Disabled page-moving for now. |
551 | | - // $this->renameThread( $thread, $subject, $e->summary ); |
552 | | - } |
553 | | - |
554 | 543 | $bump = $this->request->getBool( 'wpBumpThread' ); |
555 | 544 | |
556 | 545 | $thread = self::postEditUpdates( |
— | — | @@ -614,13 +603,23 @@ |
615 | 604 | $type = strlen( trim( $new_text ) ) |
616 | 605 | ? Threads::CHANGE_EDITED_ROOT |
617 | 606 | : Threads::CHANGE_ROOT_BLANKED; |
618 | | - |
| 607 | + |
619 | 608 | if ( $signature && !$noSignature ) { |
620 | 609 | $thread->setSignature( $signature ); |
621 | 610 | } |
622 | 611 | |
623 | 612 | // Add the history entry. |
624 | 613 | $thread->commitRevision( $type, $thread, $edit_summary, $bump ); |
| 614 | + |
| 615 | + // Update subject if applicable. |
| 616 | + if ( $subject && $subject != $thread->subject() ) { |
| 617 | + $thread->setSubject( $subject ); |
| 618 | + $thread->commitRevision( Threads::CHANGE_EDITED_SUBJECT, |
| 619 | + $thread, $e->summary ); |
| 620 | + |
| 621 | + // Disabled page-moving for now. |
| 622 | + // $this->renameThread( $thread, $subject, $e->summary ); |
| 623 | + } |
625 | 624 | } else { |
626 | 625 | $thread = Thread::create( |
627 | 626 | $edit_page, $article, null, |
Index: trunk/extensions/LiquidThreads/api/ApiQueryLQTThreads.php |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | 'thread_article_title', 'thread_summary_page', 'thread_ancestor', |
84 | 84 | 'thread_parent', 'thread_modified', 'thread_created', 'thread_type', |
85 | 85 | 'thread_editedness', 'thread_subject', 'thread_author_id', |
86 | | - 'thread_author_name', |
| 86 | + 'thread_author_name', 'thread_signature' |
87 | 87 | ); |
88 | 88 | |
89 | 89 | $this->addFields( $allFields ); |
Index: trunk/extensions/LiquidThreads/api/ApiThreadAction.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | 'newthread' => 'actionNewThread', |
17 | 17 | 'setsubject' => 'actionSetSubject', |
18 | 18 | 'setsortkey' => 'actionSetSortkey', |
| 19 | + 'edit' => 'actionEdit', |
19 | 20 | ); |
20 | 21 | } |
21 | 22 | |
— | — | @@ -419,7 +420,119 @@ |
420 | 421 | |
421 | 422 | $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
422 | 423 | } |
| 424 | + |
| 425 | + public function actionEdit( $threads, $params ) { |
| 426 | + if ( count($threads) > 1 ) { |
| 427 | + $this->dieUsage( 'You may only edit one thread at a time', |
| 428 | + 'too-many-threads' ); |
| 429 | + return; |
| 430 | + } elseif ( count($threads) < 1 ) { |
| 431 | + $this->dieUsage( 'You must specify a thread to edit', |
| 432 | + 'no-specified-threads' ); |
| 433 | + return; |
| 434 | + } |
| 435 | + |
| 436 | + $thread = array_pop( $threads ); |
| 437 | + $talkpage = $thread->article(); |
| 438 | + |
| 439 | + $bump = isset( $params['bump'] ) ? $params['bump'] : null; |
423 | 440 | |
| 441 | + // Validate subject |
| 442 | + $subjectOk = true; |
| 443 | + if ( !empty($params['subject']) ) { |
| 444 | + $subject = $params['subject']; |
| 445 | + $title = null; |
| 446 | + $subjectOk = empty($subject) || |
| 447 | + Thread::validateSubject( $subject, $title, null, $talkpage ); |
| 448 | + } else { |
| 449 | + $subject = $thread->subject(); |
| 450 | + } |
| 451 | + |
| 452 | + if ( !$subjectOk ) { |
| 453 | + $this->dieUsage( 'The subject you specified is not valid', |
| 454 | + 'invalid-subject' ); |
| 455 | + |
| 456 | + return; |
| 457 | + } |
| 458 | + |
| 459 | + // Check for text |
| 460 | + if ( empty( $params['text'] ) ) { |
| 461 | + $this->dieUsage( 'You must include text in your post', 'no-text' ); |
| 462 | + return; |
| 463 | + } |
| 464 | + $text = $params['text']; |
| 465 | + |
| 466 | + $summary = ''; |
| 467 | + if ( !empty( $params['reason'] ) ) { |
| 468 | + $summary = $params['reason']; |
| 469 | + } |
| 470 | + |
| 471 | + $article = $thread->root(); |
| 472 | + $title = $article->getTitle(); |
| 473 | + |
| 474 | + $signature = null; |
| 475 | + if ( isset( $params['signature'] ) ) { |
| 476 | + $signature = $params['signature']; |
| 477 | + } |
| 478 | + |
| 479 | + // Inform hooks what we're doing |
| 480 | + LqtHooks::$editTalkpage = $talkpage; |
| 481 | + LqtHooks::$editArticle = $article; |
| 482 | + LqtHooks::$editThread = $thread; |
| 483 | + LqtHooks::$editType = 'edit'; |
| 484 | + LqtHooks::$editAppliesTo = null; |
| 485 | + |
| 486 | + $token = $params['token']; |
| 487 | + |
| 488 | + // All seems in order. Construct an API edit request |
| 489 | + $requestData = array( |
| 490 | + 'action' => 'edit', |
| 491 | + 'title' => $title->getPrefixedText(), |
| 492 | + 'text' => $text, |
| 493 | + 'summary' => $summary, |
| 494 | + 'token' => $token, |
| 495 | + 'basetimestamp' => wfTimestampNow(), |
| 496 | + 'format' => 'json', |
| 497 | + ); |
| 498 | + |
| 499 | + $editReq = new FauxRequest( $requestData, true ); |
| 500 | + $internalApi = new ApiMain( $editReq, true ); |
| 501 | + $internalApi->execute(); |
| 502 | + |
| 503 | + $editResult = $internalApi->getResultData(); |
| 504 | + |
| 505 | + if ( $editResult['edit']['result'] != 'Success' ) { |
| 506 | + $result = array( 'result' => 'EditFailure', 'details' => $editResult ); |
| 507 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 508 | + return; |
| 509 | + } |
| 510 | + |
| 511 | + $thread = LqtView::postEditUpdates( 'editExisting', null, $article, $talkpage, |
| 512 | + $subject, $summary, $thread, $text, $bump, $signature ); |
| 513 | + |
| 514 | + $maxLag = wfGetLB()->getMaxLag(); |
| 515 | + $maxLag = $maxLag[1]; |
| 516 | + |
| 517 | + if ( $maxLag == - 1 ) { |
| 518 | + $maxLag = 0; |
| 519 | + } |
| 520 | + |
| 521 | + $result = array( |
| 522 | + 'result' => 'Success', |
| 523 | + 'thread-id' => $thread->id(), |
| 524 | + 'thread-title' => $title->getPrefixedText(), |
| 525 | + 'max-lag' => $maxLag, |
| 526 | + ); |
| 527 | + |
| 528 | + if ( !empty( $params['render'] ) ) { |
| 529 | + $result['html'] = self::renderThreadPostAction( $thread ); |
| 530 | + } |
| 531 | + |
| 532 | + $result = array( 'thread' => $result ); |
| 533 | + |
| 534 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 535 | + } |
| 536 | + |
424 | 537 | public function actionReply( $threads, $params ) { |
425 | 538 | global $wgUser; |
426 | 539 | |
Index: trunk/extensions/LiquidThreads/lqt.js |
— | — | @@ -99,9 +99,13 @@ |
100 | 100 | e.preventDefault(); |
101 | 101 | |
102 | 102 | // Grab the container. |
103 | | - var container = $j(this).closest('.lqt-post-wrapper'); |
104 | | - var query='&lqt_method=edit&lqt_operand='+container.data('thread-id'); |
| 103 | + var parent = $j(this).closest('.lqt-post-wrapper'); |
105 | 104 | |
| 105 | + var container = $j('<div/>').addClass('lqt-edit-form'); |
| 106 | + parent.contents().fadeOut(); |
| 107 | + parent.append(container); |
| 108 | + var query='&lqt_method=edit&lqt_operand='+parent.data('thread-id'); |
| 109 | + |
106 | 110 | liquidThreads.injectEditForm( query, container ); |
107 | 111 | }, |
108 | 112 | |
— | — | @@ -242,6 +246,11 @@ |
243 | 247 | function() { |
244 | 248 | $j(this).empty(); |
245 | 249 | |
| 250 | + if ( $j(this).parent().is('.lqt-post-wrapper') ) { |
| 251 | + $j(this).parent().contents().fadeIn(); |
| 252 | + $j(this).remove(); |
| 253 | + } |
| 254 | + |
246 | 255 | liquidThreads.checkEmptyReplies( repliesElement ); |
247 | 256 | } ) |
248 | 257 | } ); |
— | — | @@ -866,7 +875,7 @@ |
867 | 876 | var newPost = $j('#lqt_thread_id_'+newPostID); |
868 | 877 | var targetOffset = $j(newPost).offset().top; |
869 | 878 | $j('html,body').animate({scrollTop: targetOffset}, 'slow'); |
870 | | - } |
| 879 | + }; |
871 | 880 | |
872 | 881 | var newCallback = function( data ) { |
873 | 882 | // Grab the thread ID |
— | — | @@ -892,6 +901,12 @@ |
893 | 902 | 'slow'); |
894 | 903 | } |
895 | 904 | ); |
| 905 | + }; |
| 906 | + |
| 907 | + var editCallback = function( data ) { |
| 908 | + var thread = editform.closest('.lqt-thread-topmost'); |
| 909 | + |
| 910 | + liquidThreads.doReloadThread( thread ); |
896 | 911 | } |
897 | 912 | |
898 | 913 | var doneCallback = function(data) { |
— | — | @@ -926,6 +941,10 @@ |
927 | 942 | callback = newCallback; |
928 | 943 | } |
929 | 944 | |
| 945 | + if ( type == 'edit' ) { |
| 946 | + callback = editCallback; |
| 947 | + } |
| 948 | + |
930 | 949 | editform.empty().hide(); |
931 | 950 | |
932 | 951 | callback(data); |
— | — | @@ -944,6 +963,10 @@ |
945 | 964 | doneCallback, bump, signature ); |
946 | 965 | |
947 | 966 | e.preventDefault(); |
| 967 | + } else if ( type == 'edit' ) { |
| 968 | + liquidThreads.doEditThread( replyThread, subject, text, summary, |
| 969 | + doneCallback, bump, signature ); |
| 970 | + e.preventDefault(); |
948 | 971 | } |
949 | 972 | }, |
950 | 973 | |
— | — | @@ -1017,6 +1040,28 @@ |
1018 | 1041 | } ); |
1019 | 1042 | }, |
1020 | 1043 | |
| 1044 | + 'doEditThread' : function( thread, subject, text, summary, |
| 1045 | + callback, bump, signature ) { |
| 1046 | + var request = |
| 1047 | + { |
| 1048 | + 'action' : 'threadaction', |
| 1049 | + 'threadaction' : 'edit', |
| 1050 | + 'thread' : thread, |
| 1051 | + 'text' : text, |
| 1052 | + 'format' : 'json', |
| 1053 | + 'render' : 1, |
| 1054 | + 'reason' : summary, |
| 1055 | + 'bump' : bump, |
| 1056 | + 'subject':subject |
| 1057 | + }; |
| 1058 | + |
| 1059 | + if ( typeof signature != 'undefined' ) { |
| 1060 | + request.signature = signature; |
| 1061 | + } |
| 1062 | + |
| 1063 | + liquidThreads.apiRequest( request, callback ); |
| 1064 | + }, |
| 1065 | + |
1021 | 1066 | 'onTextboxKeyUp' : function(e) { |
1022 | 1067 | // Check if a user has signed their post, and if so, tell them they don't have to. |
1023 | 1068 | var text = $j(this).val().trim(); |
— | — | @@ -1567,6 +1612,9 @@ |
1568 | 1613 | // "Show more posts" link |
1569 | 1614 | $j('a.lqt-show-more-posts').live( 'click', liquidThreads.showMore ); |
1570 | 1615 | |
| 1616 | + // Edit link handler |
| 1617 | + $j('.lqt-command-edit > a').live( 'click', liquidThreads.handleEditLink ); |
| 1618 | + |
1571 | 1619 | // Save handlers |
1572 | 1620 | $j('#wpSave').live( 'click', liquidThreads.handleAJAXSave ); |
1573 | 1621 | $j('#wpTextbox1').live( 'keyup', liquidThreads.onTextboxKeyUp ); |