r25326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25325‎ | r25326 | r25327 >
Date:20:27, 30 August 2007
Author:david
Status:old
Tags:
Comment:
Protection of talk pages and parent threads cascades to children.
Modified paths:
  • /branches/liquidthreads/extensions/LqtBaseView.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtPages.php (modified) (history)
  • /branches/liquidthreads/includes/Title.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtBaseView.php
@@ -13,6 +13,10 @@
1414 }
1515
1616 function efVarDump($output, $value) {
 17+ if ($output == null) {
 18+ global $wgOut;
 19+ $output = $wgOut;
 20+ }
1721 ob_start();
1822 var_dump($value);
1923 $tmp=ob_get_contents();
@@ -53,13 +57,15 @@
5458 /* Certain actions apply to the "header", which is stored in the actual talkpage
5559 in the database. Drop everything and behave like a normal page if those
5660 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 ) ) {
6166 $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' ) {
6470 $viewname = self::$views['TalkpageArchiveView'];
6571 } else {
6672 $viewname = self::$views['TalkpageView'];
@@ -457,9 +463,9 @@
458464 $this->output->addHTML( wfOpenElement( 'li' ) );
459465 $this->output->addHTML( $wgLang->timeanddate($thread->timestamp()) );
460466 $this->output->addHTML( wfCloseElement( 'li' ) );
 467+
 468+ $edit_label = $thread->root()->getTitle()->quickUserCan( 'edit' ) ? 'Edit' : 'View source';
461469
462 - $edit_label = $thread->root()->getTitle()->isProtected('edit') ? 'View source' : 'Edit';
463 -
464470 $commands = array( $edit_label => $this->talkpageUrl( $this->title, 'edit', $thread ),
465471 'Reply' => $this->talkpageUrl( $this->title, 'reply', $thread ),
466472 'Permalink' => $this->permalinkUrl( $thread ) );
Index: branches/liquidthreads/extensions/LqtPages.php
@@ -19,6 +19,7 @@
2020 function customizeTabs( $skintemplate, $content_actions ) {
2121 // The arguments are passed in by reference.
2222 unset($content_actions['edit']);
 23+ unset($content_actions['viewsource']);
2324 unset($content_actions['addsection']);
2425 unset($content_actions['history']);
2526 unset($content_actions['watch']);
@@ -489,6 +490,7 @@
490491 class ThreadProtectionFormView {
491492 function customizeTabs( $skintemplate, $content_actions ) {
492493 unset($content_actions['edit']);
 494+ unset($content_actions['addsection']);
493495 unset($content_actions['viewsource']);
494496 unset($content_actions['talk']);
495497
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -2,6 +2,8 @@
33
44 require_once('Article.php');
55
 6+$wgHooks['TitleGetRestrictions'][] = array('Thread::getRestrictionsForTitle');
 7+
68 // TODO if we're gonna have a Date class we should really do it.
79 class Date {
810 public $year, $month, $day, $hour, $minute, $second;
@@ -509,7 +511,7 @@
510512 function replies() {
511513 return $this->replies;
512514 }
513 -
 515+
514516 function setSuperthread($thread) {
515517 $this->path = $thread->path . '.' . $this->id;
516518 }
@@ -699,6 +701,36 @@
700702 function changeComment() {
701703 return $this->changeComment;
702704 }
 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+ }
703735 }
704736
705737
Index: branches/liquidthreads/includes/Title.php
@@ -1605,7 +1605,12 @@
16061606 * @param string $action action that permission needs to be checked for
16071607 * @return array the array of groups allowed to edit this article
16081608 */
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+
16101615 if( $this->exists() ) {
16111616 if( !$this->mRestrictionsLoaded ) {
16121617 $this->loadRestrictions();

Status & tagging log