Index: branches/liquidthreads/extensions/LqtBaseView.php |
— | — | @@ -248,6 +248,13 @@ |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
| 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 | + |
252 | 259 | function showNewThreadForm() { |
253 | 260 | $this->showEditingFormInGeneral( null, 'new', null ); |
254 | 261 | } |
— | — | @@ -257,7 +264,11 @@ |
258 | 265 | } |
259 | 266 | |
260 | 267 | 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 | + } |
262 | 273 | } |
263 | 274 | |
264 | 275 | function showSummarizeForm( $thread ) { |
— | — | @@ -411,6 +422,51 @@ |
412 | 423 | return true; |
413 | 424 | } |
414 | 425 | |
| 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 | + |
415 | 471 | /************************* |
416 | 472 | * Output methods * |
417 | 473 | *************************/ |
— | — | @@ -464,29 +520,16 @@ |
465 | 521 | $this->output->addHTML( $wgLang->timeanddate($thread->timestamp()) ); |
466 | 522 | $this->output->addHTML( wfCloseElement( 'li' ) ); |
467 | 523 | |
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']; |
489 | 528 | $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 | + } |
491 | 534 | $this->output->addHTML( wfCloseElement( 'li' ) ); |
492 | 535 | } |
493 | 536 | |