r58000 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57999‎ | r58000 | r58001 >
Date:13:34, 22 October 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads: Add a per-talkpage history page, just joins on thread/page.
Modified paths:
  • /trunk/extensions/LiquidThreads/LiquidThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Dispatch.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/ThreadHistoryPager.php (added) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php (added) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -168,6 +168,7 @@
169169 'lqt-history-user' => 'User',
170170 'lqt-history-action' => 'Activity',
171171 'lqt-history-comment' => 'Comment',
 172+ 'lqt-history-thread' => 'Thread',
172173 'lqt-thread-edited-author' => 'Edited by author',
173174 'lqt-thread-edited-others' => 'Edited by other users',
174175 'lqt-header-actions' => 'Actions',
@@ -266,6 +267,10 @@
267268 // Automatic summaries
268269 'lqt-newpost-summary' => 'New thread: $1',
269270 'lqt-reply-summary' => 'Reply to [[$2|$1]]',
 271+
 272+ // Talk page history
 273+ 'lqt-talkpage-history-title' => 'Discussion page history',
 274+ 'lqt-talkpage-history-subtitle' => 'For $1',
270275 );
271276
272277 /** Message documentation (Message documentation)
Index: trunk/extensions/LiquidThreads/LiquidThreads.php
@@ -112,6 +112,8 @@
113113 $wgAutoloadClasses['LqtHooks'] = $dir . 'classes/Hooks.php';
114114 $wgAutoloadClasses['ThreadRevision'] = $dir . "/classes/ThreadRevision.php";
115115 $wgAutoloadClasses['SynchroniseThreadArticleDataJob'] = "$dir/classes/SynchroniseThreadArticleDataJob.php";
 116+$wgAutoloadClasses['ThreadHistoryPager'] = "$dir/classes/ThreadHistoryPager.php";
 117+$wgAutoloadClasses['TalkpageHistoryView'] = "$dir/pages/TalkpageHistoryView.php";
116118
117119 // View classes
118120 $wgAutoloadClasses['TalkpageView'] = $dir . 'pages/TalkpageView.php';
Index: trunk/extensions/LiquidThreads/classes/Dispatch.php
@@ -1,20 +1,6 @@
22 <?php
33
44 class LqtDispatch {
5 - public static $views = array(
6 - 'TalkpageArchiveView' => 'TalkpageArchiveView',
7 - 'TalkpageHeaderView' => 'TalkpageHeaderView',
8 - 'TalkpageView' => 'TalkpageView',
9 - 'ThreadHistoryListingView' => 'ThreadHistoryListingView',
10 - 'ThreadHistoricalRevisionView' => 'ThreadHistoricalRevisionView',
11 - 'IndividualThreadHistoryView' => 'IndividualThreadHistoryView',
12 - 'ThreadDiffView' => 'ThreadDiffView',
13 - 'ThreadPermalinkView' => 'ThreadPermalinkView',
14 - 'ThreadProtectionFormView' => 'ThreadProtectionFormView',
15 - 'ThreadWatchView' => 'ThreadWatchView',
16 - 'SummaryPageView' => 'SummaryPageView'
17 - );
18 -
195 /** static cache of per-page LiquidThreads activation setting */
206 static $userLQTActivated;
217
@@ -41,23 +27,26 @@
4228 $action = $request->getVal( 'action' );
4329 $header_actions = array( 'history', 'edit', 'submit', 'delete' );
4430 global $wgRequest;
 31+
 32+ $lqt_action = $request->getVal( 'lqt_method' );
4533 if ( $action == 'edit' && $request->getVal( 'section' ) == 'new' ) {
4634 // Hijack section=new for "new thread".
4735 $request->setVal( 'lqt_method', 'talkpage_new_thread' );
4836 $request->setVal( 'section', '' );
4937
50 - $viewname = self::$views['TalkpageView'];
 38+ $viewname = 'TalkpageView';
5139
52 - } elseif ( $request->getVal( 'lqt_method', null ) === null &&
53 - ( in_array( $action, $header_actions ) ||
54 - $request->getVal( 'diff', null ) !== null ) ) {
 40+ } elseif ( !$lqt_action && ( in_array( $action, $header_actions ) ||
 41+ $request->getVal( 'diff', null ) !== null ) ) {
5542 // Pass through wrapper
56 - $viewname = self::$views['TalkpageHeaderView'];
57 - } else if ( $action == 'protect' || $action == 'unprotect' ) {
 43+ $viewname = 'TalkpageHeaderView';
 44+ } elseif ( $action == 'protect' || $action == 'unprotect' ) {
5845 // Pass through wrapper
59 - $viewname = self::$views['ThreadProtectionFormView'];
 46+ $viewname = 'ThreadProtectionFormView';
 47+ } elseif ( $lqt_action == 'talkpage_history' ) {
 48+ $viewname = 'TalkpageHistoryView';
6049 } else {
61 - $viewname = self::$views['TalkpageView'];
 50+ $viewname = 'TalkpageView';
6251 }
6352 $view = new $viewname( $output, $article, $title, $user, $request );
6453 return $view->show();
@@ -69,24 +58,24 @@
7059 $lqt_method = $request->getVal( 'lqt_method' );
7160
7261 if ( $lqt_method == 'thread_history' ) {
73 - $viewname = self::$views['ThreadHistoryListingView'];
 62+ $viewname = 'ThreadHistoryListingView';
7463 } else if ( $lqt_method == 'diff' ) {
7564 // this clause and the next must be in this order.
76 - $viewname = self::$views['ThreadDiffView'];
 65+ $viewname = 'ThreadDiffView';
7766 } else if ( $action == 'history'
7867 || $request->getVal( 'diff', null ) !== null
7968 || $request->getVal( 'oldid', null ) !== null ) {
80 - $viewname = self::$views['IndividualThreadHistoryView'];
 69+ $viewname = 'IndividualThreadHistoryView';
8170 } else if ( $action == 'protect' || $action == 'unprotect' ) {
82 - $viewname = self::$views['ThreadProtectionFormView'];
 71+ $viewname = 'ThreadProtectionFormView';
8372 } else if ( $request->getVal( 'lqt_oldid', null ) !== null ) {
84 - $viewname = self::$views['ThreadHistoricalRevisionView'];
 73+ $viewname = 'ThreadHistoricalRevisionView';
8574 } else if ( $action == 'watch' || $action == 'unwatch' ) {
86 - $viewname = self::$views['ThreadWatchView'];
 75+ $viewname = 'ThreadWatchView';
8776 } elseif ( $action == 'delete' ) {
8877 return true;
8978 } else {
90 - $viewname = self::$views['ThreadPermalinkView'];
 79+ $viewname = 'ThreadPermalinkView';
9180 }
9281
9382 $view = new $viewname( $output, $article, $title, $user, $request );
@@ -94,7 +83,7 @@
9584 }
9685
9786 static function threadSummaryMain( &$output, &$article, &$title, &$user, &$request ) {
98 - $viewname = self::$views['SummaryPageView'];
 87+ $viewname = 'SummaryPageView';
9988 $view = new $viewname( $output, $article, $title, $user, $request );
10089 return $view->show();
10190 }
Index: trunk/extensions/LiquidThreads/classes/ThreadHistoryPager.php
@@ -0,0 +1,114 @@
 2+<?php
 3+
 4+class ThreadHistoryPager extends TablePager {
 5+ static $change_names;
 6+
 7+
 8+ function __construct( $view, $thread ) {
 9+ parent::__construct();
 10+
 11+ $this->thread = $thread;
 12+ $this->view = $view;
 13+
 14+ self::$change_names =
 15+ array(
 16+ Threads::CHANGE_EDITED_ROOT => wfMsgNoTrans( 'lqt_hist_comment_edited' ),
 17+ Threads::CHANGE_EDITED_SUMMARY => wfMsgNoTrans( 'lqt_hist_summary_changed' ),
 18+ Threads::CHANGE_REPLY_CREATED => wfMsgNoTrans( 'lqt_hist_reply_created' ),
 19+ Threads::CHANGE_NEW_THREAD => wfMsgNoTrans( 'lqt_hist_thread_created' ),
 20+ Threads::CHANGE_DELETED => wfMsgNoTrans( 'lqt_hist_deleted' ),
 21+ Threads::CHANGE_UNDELETED => wfMsgNoTrans( 'lqt_hist_undeleted' ),
 22+ Threads::CHANGE_MOVED_TALKPAGE => wfMsgNoTrans( 'lqt_hist_moved_talkpage' ),
 23+ Threads::CHANGE_EDITED_SUBJECT => wfMsgNoTrans( 'lqt_hist_edited_subject' ),
 24+ Threads::CHANGE_SPLIT => wfMsgNoTrans( 'lqt_hist_split' ),
 25+ Threads::CHANGE_MERGED_FROM => wfMsgNoTrans( 'lqt_hist_merged_from' ),
 26+ Threads::CHANGE_MERGED_TO => wfMsgNoTrans( 'lqt_hist_merged_to' ),
 27+ Threads::CHANGE_SPLIT_FROM => wfMsgNoTrans( 'lqt_hist_split_from' ),
 28+ Threads::CHANGE_ROOT_BLANKED => wfMsgNoTrans( 'lqt_hist_root_blanked' ),
 29+ );
 30+ }
 31+
 32+ function getQueryInfo() {
 33+ $queryInfo =
 34+ array(
 35+ 'tables' => array( 'thread_history' ),
 36+ 'fields' => '*',
 37+ 'conds' => array( 'th_thread' => $this->thread->id() ),
 38+ 'options' => array( 'order by' => 'th_timestamp desc' ),
 39+ );
 40+
 41+ return $queryInfo;
 42+ }
 43+
 44+ function getFieldMessages() {
 45+ $headers = array(
 46+ 'th_timestamp' => 'lqt-history-time',
 47+ 'th_user_text' => 'lqt-history-user',
 48+ 'th_change_type' => 'lqt-history-action',
 49+ 'th_change_comment' => 'lqt-history-comment',
 50+ );
 51+
 52+ return $headers;
 53+ }
 54+
 55+ function getFieldNames() {
 56+ static $headers = null;
 57+
 58+ if ( !empty( $headers ) ) {
 59+ return $headers;
 60+ }
 61+
 62+ $headers = $this->getFieldMessages();
 63+
 64+ $headers = array_map( 'wfMsg', $headers );
 65+
 66+ return $headers;
 67+ }
 68+
 69+ function formatValue( $name, $value ) {
 70+ global $wgOut, $wgLang, $wgTitle;
 71+
 72+ static $sk = null;
 73+
 74+ if ( empty( $sk ) ) {
 75+ global $wgUser;
 76+ $sk = $wgUser->getSkin();
 77+ }
 78+
 79+ $row = $this->mCurrentRow;
 80+
 81+ $formatted = '';
 82+
 83+ switch( $name ) {
 84+ case 'th_timestamp':
 85+ $formatted = $wgLang->timeanddate( $value );
 86+ return $sk->link( $wgTitle, $formatted, array(),
 87+ array( 'lqt_oldid' => $row->th_id ) );
 88+ case 'th_user_text':
 89+ return $sk->userLink( $row->th_user, $row->th_user_text ) . ' ' .
 90+ $sk->userToolLinks( $row->th_user, $row->th_user_text );
 91+ case 'th_change_type':
 92+ return $wgOut->parseInline( self::$change_names[$value] );
 93+ case 'th_change_comment':
 94+ return $sk->commentBlock( $value );
 95+ default:
 96+ return "Unable to format $name";
 97+ break;
 98+ }
 99+ }
 100+
 101+ function getIndexField() {
 102+ return 'th_timestamp';
 103+ }
 104+
 105+ function getDefaultSort() {
 106+ return 'th_timestamp';
 107+ }
 108+
 109+ function isFieldSortable( $name ) {
 110+ $sortable_fields = array( 'th_timestamp', 'th_user_text', 'th_change_type' );
 111+ return in_array( $name, $sortable_fields );
 112+ }
 113+
 114+ function getDefaultDirections() { return true; /* descending */ }
 115+}
Index: trunk/extensions/LiquidThreads/pages/TalkpageHistoryView.php
@@ -0,0 +1,97 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) die;
 5+
 6+class TalkpageHistoryView extends TalkpageView {
 7+ function show() {
 8+ global $wgHooks, $wgUser;
 9+ $wgHooks['SkinTemplateTabs'][] = array( $this, 'customizeTabs' );
 10+
 11+ self::addJSandCSS();
 12+ wfLoadExtensionMessages( 'LiquidThreads' );
 13+
 14+ $sk = $wgUser->getSkin();
 15+
 16+ $talkpageTitle = $this->article->getTitle();
 17+ $talkpageLink = $sk->link( $talkpageTitle );
 18+
 19+ $this->output->setPageTitle( wfMsg( 'lqt-talkpage-history-title' ) );
 20+ $this->output->setSubtitle(
 21+ wfMsgExt( 'lqt-talkpage-history-subtitle',
 22+ array( 'replaceafter', 'parseinline' ),
 23+ $talkpageLink )
 24+ );
 25+
 26+ $pager = new TalkpageHistoryPager( $this, $this->article );
 27+
 28+ $html = $pager->getNavigationBar() .
 29+ $pager->getBody() .
 30+ $pager->getNavigationBar();
 31+
 32+ $this->output->addHTML( $html );
 33+
 34+ return false;
 35+ }
 36+}
 37+
 38+class TalkpageHistoryPager extends ThreadHistoryPager {
 39+ function __construct( $view, $talkpage ) {
 40+ $this->talkpage = $talkpage;
 41+
 42+ parent::__construct( $view, null );
 43+ }
 44+
 45+ function getFieldMessages() {
 46+ $headers = array(
 47+ 'th_timestamp' => 'lqt-history-time',
 48+ 'thread_subject' => 'lqt-history-thread',
 49+ 'th_user_text' => 'lqt-history-user',
 50+ 'th_change_type' => 'lqt-history-action',
 51+ 'th_change_comment' => 'lqt-history-comment',
 52+ );
 53+
 54+ return $headers;
 55+ }
 56+
 57+ function getQueryInfo() {
 58+ $queryInfo =
 59+ array(
 60+ 'tables' => array( 'thread_history', 'thread', 'page' ),
 61+ 'fields' => '*',
 62+ 'conds' => Threads::articleClause( $this->talkpage ),
 63+ 'options' => array( 'order by' => 'th_timestamp desc' ),
 64+ 'join_conds' => array(
 65+ 'thread' => array( 'LEFT JOIN', 'thread_id=th_thread' ),
 66+ 'page' => array( 'LEFT JOIN', 'thread_root=page_id' ),
 67+ ),
 68+ );
 69+
 70+ return $queryInfo;
 71+ }
 72+
 73+ function formatValue( $name, $value ) {
 74+ global $wgOut, $wgLang, $wgTitle;
 75+
 76+ static $sk = null;
 77+
 78+ if ( empty( $sk ) ) {
 79+ global $wgUser;
 80+ $sk = $wgUser->getSkin();
 81+ }
 82+
 83+ $row = $this->mCurrentRow;
 84+
 85+ switch( $name ) {
 86+ case 'thread_subject':
 87+ $title = Title::makeTitleSafe( $row->page_namespace,
 88+ $row->page_title );
 89+
 90+ $link = $sk->link( $title, $value, array(), array(),
 91+ array( 'known' ) );
 92+
 93+ return $link;
 94+ default:
 95+ return parent::formatValue( $name, $value );
 96+ }
 97+ }
 98+}
Index: trunk/extensions/LiquidThreads/pages/ThreadHistoryListingView.php
@@ -35,110 +35,3 @@
3636 }
3737 }
3838
39 -class ThreadHistoryPager extends TablePager {
40 - static $change_names;
41 -
42 -
43 - function __construct( $view, $thread ) {
44 - parent::__construct();
45 -
46 - $this->thread = $thread;
47 - $this->view = $view;
48 -
49 - self::$change_names =
50 - array(
51 - Threads::CHANGE_EDITED_ROOT => wfMsgNoTrans( 'lqt_hist_comment_edited' ),
52 - Threads::CHANGE_EDITED_SUMMARY => wfMsgNoTrans( 'lqt_hist_summary_changed' ),
53 - Threads::CHANGE_REPLY_CREATED => wfMsgNoTrans( 'lqt_hist_reply_created' ),
54 - Threads::CHANGE_NEW_THREAD => wfMsgNoTrans( 'lqt_hist_thread_created' ),
55 - Threads::CHANGE_DELETED => wfMsgNoTrans( 'lqt_hist_deleted' ),
56 - Threads::CHANGE_UNDELETED => wfMsgNoTrans( 'lqt_hist_undeleted' ),
57 - Threads::CHANGE_MOVED_TALKPAGE => wfMsgNoTrans( 'lqt_hist_moved_talkpage' ),
58 - Threads::CHANGE_EDITED_SUBJECT => wfMsgNoTrans( 'lqt_hist_edited_subject' ),
59 - Threads::CHANGE_SPLIT => wfMsgNoTrans( 'lqt_hist_split' ),
60 - Threads::CHANGE_MERGED_FROM => wfMsgNoTrans( 'lqt_hist_merged_from' ),
61 - Threads::CHANGE_MERGED_TO => wfMsgNoTrans( 'lqt_hist_merged_to' ),
62 - Threads::CHANGE_SPLIT_FROM => wfMsgNoTrans( 'lqt_hist_split_from' ),
63 - Threads::CHANGE_ROOT_BLANKED => wfMsgNoTrans( 'lqt_hist_root_blanked' ),
64 - );
65 - }
66 -
67 - function getQueryInfo() {
68 - $queryInfo =
69 - array(
70 - 'tables' => array( 'thread_history' ),
71 - 'fields' => '*',
72 - 'conds' => array( 'th_thread' => $this->thread->id() ),
73 - 'options' => array( 'order by' => 'th_timestamp desc' ),
74 - );
75 -
76 - return $queryInfo;
77 - }
78 -
79 - function getFieldNames() {
80 - static $headers = null;
81 -
82 - if ( !empty( $headers ) ) {
83 - return $headers;
84 - }
85 -
86 - $headers = array(
87 - 'th_timestamp' => 'lqt-history-time',
88 - 'th_user_text' => 'lqt-history-user',
89 - 'th_change_type' => 'lqt-history-action',
90 - 'th_change_comment' => 'lqt-history-comment',
91 - );
92 -
93 - $headers = array_map( 'wfMsg', $headers );
94 -
95 - return $headers;
96 - }
97 -
98 - function formatValue( $name, $value ) {
99 - global $wgOut, $wgLang, $wgTitle;
100 -
101 - static $sk = null;
102 -
103 - if ( empty( $sk ) ) {
104 - global $wgUser;
105 - $sk = $wgUser->getSkin();
106 - }
107 -
108 - $row = $this->mCurrentRow;
109 -
110 - $formatted = '';
111 -
112 - switch( $name ) {
113 - case 'th_timestamp':
114 - $formatted = $wgLang->timeanddate( $value );
115 - return $sk->link( $wgTitle, $formatted, array(),
116 - array( 'lqt_oldid' => $row->th_id ) );
117 - case 'th_user_text':
118 - return $sk->userLink( $row->th_user, $row->th_user_text ) . ' ' .
119 - $sk->userToolLinks( $row->th_user, $row->th_user_text );
120 - case 'th_change_type':
121 - return $wgOut->parseInline( self::$change_names[$value] );
122 - case 'th_change_comment':
123 - return $sk->commentBlock( $value );
124 - default:
125 - return "Unable to format $name";
126 - break;
127 - }
128 - }
129 -
130 - function getIndexField() {
131 - return 'th_timestamp';
132 - }
133 -
134 - function getDefaultSort() {
135 - return 'th_timestamp';
136 - }
137 -
138 - function isFieldSortable( $name ) {
139 - $sortable_fields = array( 'th_timestamp', 'th_user_text', 'th_change_type' );
140 - return in_array( $name, $sortable_fields );
141 - }
142 -
143 - function getDefaultDirections() { return true; /* descending */ }
144 -}
145 -
Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -8,8 +8,11 @@
99 // The arguments are passed in by reference.
1010 unset( $content_actions['edit'] );
1111 unset( $content_actions['viewsource'] );
12 - unset( $content_actions['history'] );
1312 unset( $content_actions['delete'] );
 13+
 14+ $thisTitle = $this->article->getTitle();
 15+ $history_url = $thisTitle->getFullURL( 'lqt_method=talkpage_history' );
 16+ $content_actions['history']['href'] = $history_url;
1417
1518 return true;
1619 }

Status & tagging log