r55411 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55410‎ | r55411 | r55412 >
Date:12:54, 21 August 2009
Author:werdna
Status:deferred
Tags:
Comment:
Delete replies to a top-level thread when deleting it.
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/DeletionController.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -187,6 +187,11 @@
188188 'lqt-split-submit' => 'Split',
189189 'lqt_split_badsubject' => 'The subject you entered is invalid.',
190190 'lqt-no-threads' => 'There are no threads on this page yet.',
 191+ 'lqt-delete-parent-warning'=> 'This is a top-level thread with replies.
 192+Its replies will also be deleted automatically.
 193+To avoid this, split them from this thread before deleting it.',
 194+ 'lqt-delete-parent-deleted'=> 'Parent thread deleted ($1)',
 195+ 'lqt-delete-replies-done' => 'All replies to this thread have also been deleted.',
191196
192197 // Rights
193198 'right-lqt-split' => 'Split threads',
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -72,7 +72,7 @@
7373 $wgHooks['ArticleDeleteComplete'][] = 'LqtDeletionController::onArticleDeleteComplete';
7474 $wgHooks['ArticleRevisionUndeleted'][] = 'LqtDeletionController::onArticleRevisionUndeleted';
7575 $wgHooks['ArticleUndelete'][] = 'LqtDeletionController::onArticleUndelete';
76 -$wgHooks['ArticleDelete'][] = 'LqtDeletionController::onArticleDelete';
 76+$wgHooks['ArticleConfirmDelete'][] = 'LqtDeletionController::onArticleConfirmDelete';
7777
7878 // Search
7979 $wgHooks['ShowSearchHitTitle'][] = 'LqtHooks::customiseSearchResultTitle';
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -584,16 +584,6 @@
585585 'enabled' => true );
586586 }
587587
588 - if ( $this->user->isAllowed( 'delete' ) ) {
589 - $delete_title = SpecialPage::getTitleFor( 'DeleteThread',
590 - $thread->title()->getPrefixedText() );
591 - $delete_href = $delete_title->getFullURL();
592 -
593 - $commands['delete'] = array( 'label' => wfMsg( 'delete' ),
594 - 'href' => $delete_href,
595 - 'enabled' => true );
596 - }
597 -
598588 $summarizeUrl = self::permalinkUrl( $thread, 'summarize', $thread->id() );
599589 $commands['summarize'] = array(
600590 'label' => wfMsgExt( 'lqt_summarize_link', 'parseinline' ),
Index: trunk/extensions/LiquidThreads/classes/DeletionController.php
@@ -23,25 +23,24 @@
2424 $thread->delete($reason);
2525
2626 // Avoid orphaning subthreads, update their parentage.
27 - foreach( $thread->replies() as $reply ) {
28 - $reply->setSuperthread( $thread->superthread() );
29 - $reply->save( );
 27+ wfLoadExtensionMessages( 'LiquidThreads' );
 28+ if ( $thread->replies() && $thread->isTopmostThread() ) {
 29+ $reason = wfMsg('lqt-delete-parent-deleted', $reason );
 30+ foreach( $thread->replies() as $reply ) {
 31+ $reply->root()->doDeleteArticle( $reason, false, $reply->root()->getId() );
 32+ }
 33+ global $wgOut;
 34+ $wgOut->addWikiMsg( 'lqt-delete-replies-done' );
 35+ } elseif ( $thread->replies() ) {
 36+ foreach( $thread->replies() as $reply ) {
 37+ $reply->setSuperthread( $thread->superthread() );
 38+ $reply->save( );
 39+ }
3040 }
3141
3242 return true;
3343 }
3444
35 - static function onArticleDelete( &$article, &$user, &$reason, &$error ) {
36 - $thread = Threads::withRoot( $article );
37 -
38 - if ( is_object( $thread ) && $thread->isTopmostThread() && count($thread->replies())) {
39 - $error = wfMsgExt( 'lqt-delete-has-subthreads', 'parse' );
40 - return false;
41 - }
42 -
43 - return true;
44 - }
45 -
4645 static function onArticleRevisionUndeleted( &$title, $revision, $page_id ) {
4746 if ( $title->getNamespace() == NS_LQT_THREAD ) {
4847 self::$pageids_to_revive[$page_id] = $title;
@@ -68,7 +67,7 @@
6968 $threads = Threads::loadFromResult( $res, $dbw );
7069
7170 if ( count($threads) ) {
72 - $thread = $threads[0];
 71+ $thread = array_pop($threads);
7372 $thread->setRoot( new Article( $title ) );
7473 $thread->undelete( $comment );
7574 } else {
@@ -78,4 +77,18 @@
7978
8079 return true;
8180 }
 81+
 82+ static function onArticleConfirmDelete( $article, $out, &$reason ) {
 83+ if ($article->getTitle()->getNamespace() != NS_LQT_THREAD) return true;
 84+
 85+ $thread = Threads::withRoot( $article );
 86+
 87+ if ( $thread->isTopmostThread() && count($thread->replies()) ) {
 88+ wfLoadExtensionMessages( 'LiquidThreads' );
 89+ $out->wrapWikiMsg( '<strong>$1</strong>',
 90+ 'lqt-delete-parent-warning' );
 91+ }
 92+
 93+ return true;
 94+ }
8295 }

Status & tagging log