Index: branches/liquidthreads/extensions/LqtBaseView.php |
— | — | @@ -13,6 +13,10 @@ |
14 | 14 | } |
15 | 15 | |
16 | 16 | function efVarDump($output, $value) { |
| 17 | + if ($output == null) { |
| 18 | + global $wgOut; |
| 19 | + $output = $wgOut; |
| 20 | + } |
17 | 21 | ob_start(); |
18 | 22 | var_dump($value); |
19 | 23 | $tmp=ob_get_contents(); |
— | — | @@ -53,13 +57,15 @@ |
54 | 58 | /* Certain actions apply to the "header", which is stored in the actual talkpage |
55 | 59 | in the database. Drop everything and behave like a normal page if those |
56 | 60 | actions come up, to avoid hacking the various history, editing, etc. code. */ |
57 | | - $header_actions = array('history', 'edit', 'submit', 'protect'); |
58 | | - if ($request->getVal('lqt_method', null) === null && ( |
59 | | - in_array( $request->getVal('action'), $header_actions ) || |
60 | | - $request->getVal('diff', null) !== null ) ) { |
| 61 | + $action = $request->getVal('action'); |
| 62 | + $header_actions = array('history', 'edit', 'submit'); |
| 63 | + if ($request->getVal('lqt_method', null) === null && |
| 64 | + ( in_array( $action, $header_actions ) || |
| 65 | + $request->getVal('diff', null) !== null ) ) { |
61 | 66 | $viewname = self::$views['TalkpageHeaderView']; |
62 | | - } |
63 | | - else if ( $request->getVal('lqt_method') == 'talkpage_archive' ) { |
| 67 | + } else if ( $action == 'protect' || $action == 'unprotect' ) { |
| 68 | + $viewname = self::$views['ThreadProtectionFormView']; |
| 69 | + } else if ( $request->getVal('lqt_method') == 'talkpage_archive' ) { |
64 | 70 | $viewname = self::$views['TalkpageArchiveView']; |
65 | 71 | } else { |
66 | 72 | $viewname = self::$views['TalkpageView']; |
— | — | @@ -457,9 +463,9 @@ |
458 | 464 | $this->output->addHTML( wfOpenElement( 'li' ) ); |
459 | 465 | $this->output->addHTML( $wgLang->timeanddate($thread->timestamp()) ); |
460 | 466 | $this->output->addHTML( wfCloseElement( 'li' ) ); |
| 467 | + |
| 468 | + $edit_label = $thread->root()->getTitle()->quickUserCan( 'edit' ) ? 'Edit' : 'View source'; |
461 | 469 | |
462 | | - $edit_label = $thread->root()->getTitle()->isProtected('edit') ? 'View source' : 'Edit'; |
463 | | - |
464 | 470 | $commands = array( $edit_label => $this->talkpageUrl( $this->title, 'edit', $thread ), |
465 | 471 | 'Reply' => $this->talkpageUrl( $this->title, 'reply', $thread ), |
466 | 472 | 'Permalink' => $this->permalinkUrl( $thread ) ); |
Index: branches/liquidthreads/extensions/LqtPages.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | function customizeTabs( $skintemplate, $content_actions ) { |
21 | 21 | // The arguments are passed in by reference. |
22 | 22 | unset($content_actions['edit']); |
| 23 | + unset($content_actions['viewsource']); |
23 | 24 | unset($content_actions['addsection']); |
24 | 25 | unset($content_actions['history']); |
25 | 26 | unset($content_actions['watch']); |
— | — | @@ -489,6 +490,7 @@ |
490 | 491 | class ThreadProtectionFormView { |
491 | 492 | function customizeTabs( $skintemplate, $content_actions ) { |
492 | 493 | unset($content_actions['edit']); |
| 494 | + unset($content_actions['addsection']); |
493 | 495 | unset($content_actions['viewsource']); |
494 | 496 | unset($content_actions['talk']); |
495 | 497 | |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -2,6 +2,8 @@ |
3 | 3 | |
4 | 4 | require_once('Article.php'); |
5 | 5 | |
| 6 | +$wgHooks['TitleGetRestrictions'][] = array('Thread::getRestrictionsForTitle'); |
| 7 | + |
6 | 8 | // TODO if we're gonna have a Date class we should really do it. |
7 | 9 | class Date { |
8 | 10 | public $year, $month, $day, $hour, $minute, $second; |
— | — | @@ -509,7 +511,7 @@ |
510 | 512 | function replies() { |
511 | 513 | return $this->replies; |
512 | 514 | } |
513 | | - |
| 515 | + |
514 | 516 | function setSuperthread($thread) { |
515 | 517 | $this->path = $thread->path . '.' . $this->id; |
516 | 518 | } |
— | — | @@ -699,6 +701,36 @@ |
700 | 702 | function changeComment() { |
701 | 703 | return $this->changeComment; |
702 | 704 | } |
| 705 | + |
| 706 | + // Called from hook in Title::isProtected. |
| 707 | + static function getRestrictionsForTitle($title, $action, &$result) { |
| 708 | + $thread = Threads::withRoot(new Post($title)); |
| 709 | + if ($thread) |
| 710 | + return $thread->getRestrictions($action, $result); |
| 711 | + else |
| 712 | + return true; // not a thread; do normal protection check. |
| 713 | + } |
| 714 | + |
| 715 | + // This only makes sense when called from the hook, because it uses the hook's |
| 716 | + // default behavior to check whether this thread itself is protected, so you'll |
| 717 | + // get false negatives if you use it from some other context. |
| 718 | + function getRestrictions($action, &$result) { |
| 719 | + if( $this->hasSuperthread() ) { |
| 720 | + $parent_restrictions = $this->superthread()->root()->getTitle()->getRestrictions($action); |
| 721 | + } else { |
| 722 | + $parent_restrictions = $this->article()->getTitle()->getTalkPage()->getRestrictions($action); |
| 723 | + } |
| 724 | + |
| 725 | + // TODO this may not be the same as asking "are the parent restrictions more restrictive than |
| 726 | + // our own restrictions?", which is what we really want. |
| 727 | + if( count($parent_restrictions) == 0 ) { |
| 728 | + return true; // go to normal protection check. |
| 729 | + } else { |
| 730 | + $result = $parent_restrictions; |
| 731 | + return false; |
| 732 | + } |
| 733 | + |
| 734 | + } |
703 | 735 | } |
704 | 736 | |
705 | 737 | |
Index: branches/liquidthreads/includes/Title.php |
— | — | @@ -1605,7 +1605,12 @@ |
1606 | 1606 | * @param string $action action that permission needs to be checked for |
1607 | 1607 | * @return array the array of groups allowed to edit this article |
1608 | 1608 | */ |
1609 | | - public function getRestrictions( $action ) { |
| 1609 | + public function getRestrictions( $action ) { |
| 1610 | + // LQT HACK. |
| 1611 | + $result = array(); |
| 1612 | + if( !wfRunHooks('TitleGetRestrictions', array($this, $action, &$result)) ) |
| 1613 | + return $result; |
| 1614 | + |
1610 | 1615 | if( $this->exists() ) { |
1611 | 1616 | if( !$this->mRestrictionsLoaded ) { |
1612 | 1617 | $this->loadRestrictions(); |