r25376 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25375‎ | r25376 | r25377 >
Date:20:19, 31 August 2007
Author:david
Status:old
Tags:
Comment:
can no longer reply to protected threads. also, spliced applicableThreadCommands() out from LqtView::showThreadFooter
Modified paths:
  • /branches/liquidthreads/extensions/LqtBaseView.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtBaseView.php
@@ -248,6 +248,13 @@
249249 }
250250 }
251251
 252+ function showReplyProtectedNotice($thread) {
 253+ // http://localhost:8000/lqt07/index.php?title=Special%3ALog&type=protect&user=&page=Thread%3ADiscussion+noveu+%281%29
 254+ $log_url = SpecialPage::getPage('Log')->getTitle()->getFullURL(
 255+ "type=protect&user=&page={$thread->title()->getPrefixedURL()}");
 256+ $this->output->addHTML("<p>This thread has been <a href=\"$log_url\">protected</a> from being replied to.");
 257+ }
 258+
252259 function showNewThreadForm() {
253260 $this->showEditingFormInGeneral( null, 'new', null );
254261 }
@@ -257,7 +264,11 @@
258265 }
259266
260267 function showReplyForm( $thread ) {
261 - $this->showEditingFormInGeneral( null, 'reply', $thread );
 268+ if( $thread->root()->getTitle()->userCan( 'edit' ) ) {
 269+ $this->showEditingFormInGeneral( null, 'reply', $thread );
 270+ } else {
 271+ $this->showReplyProtectedNotice($thread);
 272+ }
262273 }
263274
264275 function showSummarizeForm( $thread ) {
@@ -411,6 +422,51 @@
412423 return true;
413424 }
414425
 426+ /**
 427+ * Example return value:
 428+ * array (
 429+ * 0 => array( 'label' => 'Edit',
 430+ * 'href' => 'http...',
 431+ * 'enabled' => false ),
 432+ * 1 => array( 'label' => 'Reply',
 433+ * 'href' => 'http...',
 434+ * 'enabled' => true )
 435+ * )
 436+ */
 437+ function applicableThreadCommands($thread) {
 438+ $commands = array();
 439+
 440+ $user_can_edit = $thread->root()->getTitle()->quickUserCan( 'edit' );
 441+
 442+ $commands[] = array( 'label' => $user_can_edit ? 'Edit' : 'View source',
 443+ 'href' => $this->talkpageUrl( $this->title, 'edit', $thread ),
 444+ 'enabled' => true );
 445+
 446+ $commands[] = array( 'label' => 'Reply',
 447+ 'href' => $this->talkpageUrl( $this->title, 'reply', $thread ),
 448+ 'enabled' => $user_can_edit );
 449+
 450+ $commands[] = array( 'label' => 'Permalink',
 451+ 'href' => $this->permalinkUrl( $thread ),
 452+ 'enabled' => true );
 453+
 454+ if( !$thread->hasSuperthread() ) {
 455+ $commands[] = array( 'label' => 'History',
 456+ 'href' => $this->permalinkUrlWithQuery($thread, 'action=history'),
 457+ 'enabled' => true );
 458+ }
 459+
 460+ if ( in_array('delete', $this->user->getRights()) ) {
 461+ $delete_url = SpecialPage::getPage('Deletethread')->getTitle()->getFullURL()
 462+ . '/' . $thread->title()->getPrefixedURL();
 463+ $commands[] = array( 'label' => $thread->type() == Threads::TYPE_DELETED ? 'Undelete' : 'Delete',
 464+ 'href' => $delete_url,
 465+ 'enabled' => true );
 466+ }
 467+
 468+ return $commands;
 469+ }
 470+
415471 /*************************
416472 * Output methods *
417473 *************************/
@@ -464,29 +520,16 @@
465521 $this->output->addHTML( $wgLang->timeanddate($thread->timestamp()) );
466522 $this->output->addHTML( wfCloseElement( 'li' ) );
467523
468 - $edit_label = $thread->root()->getTitle()->quickUserCan( 'edit' ) ? 'Edit' : 'View source';
469 -
470 - $commands = array( $edit_label => $this->talkpageUrl( $this->title, 'edit', $thread ),
471 - 'Reply' => $this->talkpageUrl( $this->title, 'reply', $thread ),
472 - 'Permalink' => $this->permalinkUrl( $thread ) );
473 -
474 - if( !$thread->hasSuperthread() ) {
475 - $commands['History'] = $this->permalinkUrlWithQuery($thread, 'action=history');
476 - }
477 -
478 - if ( in_array('delete', $this->user->getRights()) ) {
479 - if( $thread->type() == Threads::TYPE_DELETED )
480 - $delete_command_label = 'Undelete';
481 - else
482 - $delete_command_label = 'Delete';
483 -
484 - $commands[$delete_command_label] = SpecialPage::getPage('Deletethread')->getTitle()->getFullURL()
485 - . '/' . $thread->title()->getPrefixedURL();
486 - }
487 -
488 - foreach( $commands as $label => $href ) {
 524+ foreach( $this->applicableThreadCommands($thread) as $command ) {
 525+ $label = $command['label'];
 526+ $href = $command['href'];
 527+ $enabled = $command['enabled'];
489528 $this->output->addHTML( wfOpenElement( 'li' ) );
490 - $this->output->addHTML( wfElement('a', array('href'=>$href), $label) );
 529+ if( $enabled ) {
 530+ $this->output->addHTML( wfElement('a', array('href'=>$href), $label) );
 531+ } else {
 532+ $this->output->addHTML( wfElement('span', array('class'=>'lqt_footer_disabled'), $label) );
 533+ }
491534 $this->output->addHTML( wfCloseElement( 'li' ) );
492535 }
493536

Status & tagging log