r62289 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62288‎ | r62289 | r62290 >
Date:05:02, 11 February 2010
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads: Re-implement AJAX post editing, it works correctly now.
Modified paths:
  • /trunk/extensions/LiquidThreads/api/ApiQueryLQTThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/api/ApiThreadAction.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -539,17 +539,6 @@
540540 $this->output->setArticleFlag( false );
541541
542542 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 -
554543 $bump = $this->request->getBool( 'wpBumpThread' );
555544
556545 $thread = self::postEditUpdates(
@@ -614,13 +603,23 @@
615604 $type = strlen( trim( $new_text ) )
616605 ? Threads::CHANGE_EDITED_ROOT
617606 : Threads::CHANGE_ROOT_BLANKED;
618 -
 607+
619608 if ( $signature && !$noSignature ) {
620609 $thread->setSignature( $signature );
621610 }
622611
623612 // Add the history entry.
624613 $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+ }
625624 } else {
626625 $thread = Thread::create(
627626 $edit_page, $article, null,
Index: trunk/extensions/LiquidThreads/api/ApiQueryLQTThreads.php
@@ -82,7 +82,7 @@
8383 'thread_article_title', 'thread_summary_page', 'thread_ancestor',
8484 'thread_parent', 'thread_modified', 'thread_created', 'thread_type',
8585 'thread_editedness', 'thread_subject', 'thread_author_id',
86 - 'thread_author_name',
 86+ 'thread_author_name', 'thread_signature'
8787 );
8888
8989 $this->addFields( $allFields );
Index: trunk/extensions/LiquidThreads/api/ApiThreadAction.php
@@ -15,6 +15,7 @@
1616 'newthread' => 'actionNewThread',
1717 'setsubject' => 'actionSetSubject',
1818 'setsortkey' => 'actionSetSortkey',
 19+ 'edit' => 'actionEdit',
1920 );
2021 }
2122
@@ -419,7 +420,119 @@
420421
421422 $this->getResult()->addValue( null, $this->getModuleName(), $result );
422423 }
 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;
423440
 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+
424537 public function actionReply( $threads, $params ) {
425538 global $wgUser;
426539
Index: trunk/extensions/LiquidThreads/lqt.js
@@ -99,9 +99,13 @@
100100 e.preventDefault();
101101
102102 // 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');
105104
 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+
106110 liquidThreads.injectEditForm( query, container );
107111 },
108112
@@ -242,6 +246,11 @@
243247 function() {
244248 $j(this).empty();
245249
 250+ if ( $j(this).parent().is('.lqt-post-wrapper') ) {
 251+ $j(this).parent().contents().fadeIn();
 252+ $j(this).remove();
 253+ }
 254+
246255 liquidThreads.checkEmptyReplies( repliesElement );
247256 } )
248257 } );
@@ -866,7 +875,7 @@
867876 var newPost = $j('#lqt_thread_id_'+newPostID);
868877 var targetOffset = $j(newPost).offset().top;
869878 $j('html,body').animate({scrollTop: targetOffset}, 'slow');
870 - }
 879+ };
871880
872881 var newCallback = function( data ) {
873882 // Grab the thread ID
@@ -892,6 +901,12 @@
893902 'slow');
894903 }
895904 );
 905+ };
 906+
 907+ var editCallback = function( data ) {
 908+ var thread = editform.closest('.lqt-thread-topmost');
 909+
 910+ liquidThreads.doReloadThread( thread );
896911 }
897912
898913 var doneCallback = function(data) {
@@ -926,6 +941,10 @@
927942 callback = newCallback;
928943 }
929944
 945+ if ( type == 'edit' ) {
 946+ callback = editCallback;
 947+ }
 948+
930949 editform.empty().hide();
931950
932951 callback(data);
@@ -944,6 +963,10 @@
945964 doneCallback, bump, signature );
946965
947966 e.preventDefault();
 967+ } else if ( type == 'edit' ) {
 968+ liquidThreads.doEditThread( replyThread, subject, text, summary,
 969+ doneCallback, bump, signature );
 970+ e.preventDefault();
948971 }
949972 },
950973
@@ -1017,6 +1040,28 @@
10181041 } );
10191042 },
10201043
 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+
10211066 'onTextboxKeyUp' : function(e) {
10221067 // Check if a user has signed their post, and if so, tell them they don't have to.
10231068 var text = $j(this).val().trim();
@@ -1567,6 +1612,9 @@
15681613 // "Show more posts" link
15691614 $j('a.lqt-show-more-posts').live( 'click', liquidThreads.showMore );
15701615
 1616+ // Edit link handler
 1617+ $j('.lqt-command-edit > a').live( 'click', liquidThreads.handleEditLink );
 1618+
15711619 // Save handlers
15721620 $j('#wpSave').live( 'click', liquidThreads.handleAJAXSave );
15731621 $j('#wpTextbox1').live( 'keyup', liquidThreads.onTextboxKeyUp );

Status & tagging log