r81033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81032‎ | r81033 | r81034 >
Date:16:52, 26 January 2011
Author:reedy
Status:ok
Tags:
Comment:
Split CodeView and SvnTablePager out of SpecialCode into own file
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeView.php (added) (history)
  • /trunk/extensions/CodeReview/ui/SpecialCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -74,7 +74,7 @@
7575 $wgAutoloadClasses['CodeReleaseNotes'] = $dir . 'ui/CodeReleaseNotes.php';
7676 $wgAutoloadClasses['CodeStatusChangeListView'] = $dir . 'ui/CodeStatusChangeListView.php';
7777 $wgAutoloadClasses['SpecialCode'] = $dir . 'ui/SpecialCode.php';
78 -$wgAutoloadClasses['CodeView'] = $dir . 'ui/SpecialCode.php';
 78+$wgAutoloadClasses['CodeView'] = $dir . 'ui/CodeView.php';
7979 $wgAutoloadClasses['SpecialRepoAdmin'] = $dir . 'ui/SpecialRepoAdmin.php';
8080 $wgAutoloadClasses['WordCloud'] = $dir . 'ui/WordCloud.php';
8181
Index: trunk/extensions/CodeReview/ui/CodeView.php
@@ -0,0 +1,134 @@
 2+<?php
 3+
 4+/**
 5+ * Extended by CodeRevisionListView and CodeRevisionView
 6+ */
 7+abstract class CodeView {
 8+ /**
 9+ * @var CodeRepository
 10+ */
 11+ var $mRepo;
 12+
 13+ function __construct() {
 14+ global $wgUser;
 15+ $this->skin = $wgUser->getSkin();
 16+ }
 17+
 18+ function validPost( $permission ) {
 19+ global $wgRequest, $wgUser;
 20+ return $wgRequest->wasPosted()
 21+ && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
 22+ && $wgUser->isAllowed( $permission );
 23+ }
 24+
 25+ abstract function execute();
 26+
 27+ function authorLink( $author, $extraParams = array() ) {
 28+ $repo = $this->mRepo->getName();
 29+ $special = SpecialPage::getTitleFor( 'Code', "$repo/author/$author" );
 30+ return $this->skin->link( $special, htmlspecialchars( $author ), array(), $extraParams );
 31+ }
 32+
 33+ function statusDesc( $status ) {
 34+ return wfMsg( "code-status-$status" );
 35+ }
 36+
 37+ function formatMessage( $text ) {
 38+ $text = nl2br( htmlspecialchars( $text ) );
 39+ $linker = new CodeCommentLinkerHtml( $this->mRepo );
 40+ return $linker->link( $text );
 41+ }
 42+
 43+ function messageFragment( $value ) {
 44+ global $wgLang;
 45+ $message = trim( $value );
 46+ $lines = explode( "\n", $message, 2 );
 47+ $first = $lines[0];
 48+
 49+ $html = $this->formatMessage( $first );
 50+ $truncated = $wgLang->truncateHtml( $html, 80 );
 51+
 52+ if ( count( $lines ) > 1 ) { // If multiline, we might want to add an ellipse
 53+ $ellipse = wfMsgExt( 'ellipsis', array() );
 54+
 55+ $len = strlen( $truncated );
 56+ if ( substr( $truncated, $len ) !== $ellipse ) { // Don't add if the end is already an ellipse
 57+ $truncated .= $ellipse;
 58+ }
 59+ }
 60+
 61+ return $truncated;
 62+ }
 63+ /*
 64+ * Formatted HTML array for properties display
 65+ * @param array fields : 'propname' => HTML data
 66+ */
 67+ function formatMetaData( $fields ) {
 68+ $html = '<table class="mw-codereview-meta">';
 69+ foreach ( $fields as $label => $data ) {
 70+ $html .= "<tr><td>" . wfMsgHtml( $label ) . "</td><td>$data</td></tr>\n";
 71+ }
 72+ return $html . "</table>\n";
 73+ }
 74+
 75+ function getRepo() {
 76+ if ( $this->mRepo ) {
 77+ return $this->mRepo;
 78+ }
 79+ return false;
 80+ }
 81+}
 82+
 83+abstract class SvnTablePager extends TablePager {
 84+
 85+ /**
 86+ * @var CodeRepository
 87+ */
 88+ protected $mRepo;
 89+
 90+ /**
 91+ * @var CodeView
 92+ */
 93+ protected $mView;
 94+
 95+ /**
 96+ * @param $view CodeView
 97+ *
 98+ */
 99+ function __construct( $view ) {
 100+ global $IP;
 101+ $this->mView = $view;
 102+ $this->mRepo = $view->mRepo;
 103+ $this->mDefaultDirection = true;
 104+ $this->mCurSVN = SpecialVersion::getSvnRevision( $IP );
 105+ parent::__construct();
 106+ }
 107+
 108+ function isFieldSortable( $field ) {
 109+ return $field == $this->getDefaultSort();
 110+ }
 111+
 112+ function formatRevValue( $name, $value, $row ) {
 113+ return $this->formatValue( $name, $value );
 114+ }
 115+
 116+ // Note: this function is poorly factored in the parent class
 117+ function formatRow( $row ) {
 118+ $css = "mw-codereview-status-{$row->cr_status}";
 119+ $s = "<tr class=\"$css\">\n";
 120+ // Some of this stolen from Pager.php...sigh
 121+ $fieldNames = $this->getFieldNames();
 122+ $this->mCurrentRow = $row; # In case formatValue needs to know
 123+ foreach ( $fieldNames as $field => $name ) {
 124+ $value = isset( $row->$field ) ? $row->$field : null;
 125+ $formatted = strval( $this->formatRevValue( $field, $value, $row ) );
 126+ if ( $formatted == '' ) {
 127+ $formatted = '&#160;';
 128+ }
 129+ $class = 'TablePager_col_' . htmlspecialchars( $field );
 130+ $s .= "<td class=\"$class\">$formatted</td>\n";
 131+ }
 132+ $s .= "</tr>\n";
 133+ return $s;
 134+ }
 135+}
Property changes on: trunk/extensions/CodeReview/ui/CodeView.php
___________________________________________________________________
Added: svn:eol-style
1136 + native
Index: trunk/extensions/CodeReview/ui/SpecialCode.php
@@ -139,135 +139,3 @@
140140 }
141141 }
142142
143 -/**
144 - * Extended by CodeRevisionListView and CodeRevisionView
145 - */
146 -abstract class CodeView {
147 - /**
148 - * @var CodeRepository
149 - */
150 - var $mRepo;
151 -
152 - function __construct() {
153 - global $wgUser;
154 - $this->skin = $wgUser->getSkin();
155 - }
156 -
157 - function validPost( $permission ) {
158 - global $wgRequest, $wgUser;
159 - return $wgRequest->wasPosted()
160 - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
161 - && $wgUser->isAllowed( $permission );
162 - }
163 -
164 - abstract function execute();
165 -
166 - function authorLink( $author, $extraParams = array() ) {
167 - $repo = $this->mRepo->getName();
168 - $special = SpecialPage::getTitleFor( 'Code', "$repo/author/$author" );
169 - return $this->skin->link( $special, htmlspecialchars( $author ), array(), $extraParams );
170 - }
171 -
172 - function statusDesc( $status ) {
173 - return wfMsg( "code-status-$status" );
174 - }
175 -
176 - function formatMessage( $text ) {
177 - $text = nl2br( htmlspecialchars( $text ) );
178 - $linker = new CodeCommentLinkerHtml( $this->mRepo );
179 - return $linker->link( $text );
180 - }
181 -
182 - function messageFragment( $value ) {
183 - global $wgLang;
184 - $message = trim( $value );
185 - $lines = explode( "\n", $message, 2 );
186 - $first = $lines[0];
187 -
188 - $html = $this->formatMessage( $first );
189 - $truncated = $wgLang->truncateHtml( $html, 80 );
190 -
191 - if ( count( $lines ) > 1 ) { // If multiline, we might want to add an ellipse
192 - $ellipse = wfMsgExt( 'ellipsis', array() );
193 -
194 - $len = strlen( $truncated );
195 - if ( substr( $truncated, $len ) !== $ellipse ) { // Don't add if the end is already an ellipse
196 - $truncated .= $ellipse;
197 - }
198 - }
199 -
200 - return $truncated;
201 - }
202 - /*
203 - * Formatted HTML array for properties display
204 - * @param array fields : 'propname' => HTML data
205 - */
206 - function formatMetaData( $fields ) {
207 - $html = '<table class="mw-codereview-meta">';
208 - foreach ( $fields as $label => $data ) {
209 - $html .= "<tr><td>" . wfMsgHtml( $label ) . "</td><td>$data</td></tr>\n";
210 - }
211 - return $html . "</table>\n";
212 - }
213 -
214 - function getRepo() {
215 - if ( $this->mRepo ) {
216 - return $this->mRepo;
217 - }
218 - return false;
219 - }
220 -}
221 -
222 -abstract class SvnTablePager extends TablePager {
223 -
224 - /**
225 - * @var CodeRepository
226 - */
227 - protected $mRepo;
228 -
229 - /**
230 - * @var CodeView
231 - */
232 - protected $mView;
233 -
234 - /**
235 - * @param $view CodeView
236 - *
237 - */
238 - function __construct( $view ) {
239 - global $IP;
240 - $this->mView = $view;
241 - $this->mRepo = $view->mRepo;
242 - $this->mDefaultDirection = true;
243 - $this->mCurSVN = SpecialVersion::getSvnRevision( $IP );
244 - parent::__construct();
245 - }
246 -
247 - function isFieldSortable( $field ) {
248 - return $field == $this->getDefaultSort();
249 - }
250 -
251 - function formatRevValue( $name, $value, $row ) {
252 - return $this->formatValue( $name, $value );
253 - }
254 -
255 - // Note: this function is poorly factored in the parent class
256 - function formatRow( $row ) {
257 - $css = "mw-codereview-status-{$row->cr_status}";
258 - $s = "<tr class=\"$css\">\n";
259 - // Some of this stolen from Pager.php...sigh
260 - $fieldNames = $this->getFieldNames();
261 - $this->mCurrentRow = $row; # In case formatValue needs to know
262 - foreach ( $fieldNames as $field => $name ) {
263 - $value = isset( $row->$field ) ? $row->$field : null;
264 - $formatted = strval( $this->formatRevValue( $field, $value, $row ) );
265 - if ( $formatted == '' ) {
266 - $formatted = '&#160;';
267 - }
268 - $class = 'TablePager_col_' . htmlspecialchars( $field );
269 - $s .= "<td class=\"$class\">$formatted</td>\n";
270 - }
271 - $s .= "</tr>\n";
272 - return $s;
273 - }
274 -}

Status & tagging log