r86991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86990‎ | r86991 | r86992 >
Date:22:20, 26 April 2011
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Finished rendering methods, added styling, and i18n/L10n (which also resolves issues in r86742).
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.dashboard.css (modified) (history)
  • /trunk/extensions/ArticleFeedback/sql/ArticleFeedback.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -34,12 +34,14 @@
3535 * @param $attribs Array: List of HTML attributes to apply to the table
3636 * @return String: HTML table code
3737 */
38 - protected function renderTable( array $headings, array $rows, $id = null ) {
 38+ protected function renderTable( $caption, array $headings, array $rows, $id = null ) {
3939 global $wgOut;
4040
4141 $table = Html::openElement( 'table', array(
4242 'class' => 'articleFeedback-table sortable', 'id' => $id
4343 ) );
 44+ // Caption
 45+ $table .= Html::element( 'caption', array(), $caption );
4446 // Head
4547 $table .= Html::openElement( 'thead' );
4648 $table .= Html::openElement( 'tr' );
@@ -52,8 +54,10 @@
5355 $table .= Html::openElement( 'tbody' );
5456 foreach ( $rows as $row ) {
5557 $table .= Html::openElement( 'tr' );
56 - foreach ( $row as $column ) {
57 - $table .= Html::rawElement( 'td', array(), $column );
 58+ foreach ( $row as $class => $column ) {
 59+ $attr = is_string( $class )
 60+ ? array( 'class' => 'articleFeedback-table-column-' . $class ) : array();
 61+ $table .= Html::rawElement( 'td', $attr, $column );
5862 }
5963 $table .= Html::closeElement( 'tr' );
6064 }
@@ -68,14 +72,26 @@
6973 * @return String: HTML table of daily highs and lows
7074 */
7175 protected function renderDailyHighsAndLows() {
72 - global $wgOut;
 76+ global $wgOut, $wgArticleFeedbackRatings;
7377
74 - $data = $this->getDailyHighsAndLows();
75 -
76 - $wgOut->addHtml( Html::element( 'h2', array(), 'Daily Highs and Lows' ) );
 78+ $rows = array();
 79+ foreach ( $this->getDailyHighsAndLows() as $page ) {
 80+ $row = array();
 81+ $row['page'] = $page['page'];
 82+ foreach ( $page['ratings'] as $id => $value ) {
 83+ $row['rating-' . $id] = $value;
 84+ }
 85+ $row['average'] = $page['average'];
 86+ $rows[] = $row;
 87+ }
7788 $this->renderTable(
78 - array( 'Article Title', 'Ratings', 'Average' ),
79 - array( /* rendered data */ ),
 89+ wfMsg( 'articleFeedback-table-caption-dailyhighsandlows' ),
 90+ array_merge(
 91+ array( wfMsg( 'articleFeedback-table-heading-page' ) ),
 92+ self::getCategories(),
 93+ array( wfMsg( 'articleFeedback-table-heading-average' ) )
 94+ ),
 95+ $rows,
8096 'articleFeedback-table-highsandlows'
8197 );
8298 }
@@ -88,12 +104,22 @@
89105 protected function renderWeeklyMostChanged() {
90106 global $wgOut;
91107
92 - $data = $this->getWeeklyMostChanged();
93 -
94 - $wgOut->addHtml( Html::element( 'h2', array(), 'Weekly Most Changed' ) );
 108+ $rows = array();
 109+ foreach ( $this->getWeeklyMostChanged() as $page ) {
 110+ $row = array();
 111+ $row['page'] = $page['page'];
 112+ foreach ( $page['changes'] as $id => $value ) {
 113+ $row['rating-' . $id] = $value;
 114+ }
 115+ $rows[] = $row;
 116+ }
95117 $this->renderTable(
96 - array( 'Article Title', 'Category', 'Difference' ),
97 - array( /* rendered data */ ),
 118+ wfMsg( 'articleFeedback-table-caption-weeklymostchanged' ),
 119+ array_merge(
 120+ array( wfMsg( 'articleFeedback-table-heading-page' ) ),
 121+ self::getCategories()
 122+ ),
 123+ $rows,
98124 'articleFeedback-table-weeklymostchanged'
99125 );
100126 }
@@ -104,14 +130,30 @@
105131 * @return String: HTML table of recent lows
106132 */
107133 protected function renderRecentLows() {
108 - global $wgOut;
 134+ global $wgOut, $wgArticleFeedbackRatings;
109135
110 - $data = $this->getRecentLows();
111 -
112 - $wgOut->addHtml( Html::element( 'h2', array(), 'Recent Lows' ) );
 136+ $rows = array();
 137+ foreach ( $this->getRecentLows() as $page ) {
 138+ $row = array();
 139+ $row['page'] = $page['page'];
 140+ foreach ( $wgArticleFeedbackRatings as $category ) {
 141+ $row[] = in_array( $category, $page['categories'] )
 142+ ? Html::element(
 143+ 'span', array( 'class' => 'articleFeedback-table-cell-bad' ), 0
 144+ )
 145+ : Html::element(
 146+ 'span', array( 'class' => 'articleFeedback-table-cell-good' ), 1
 147+ );
 148+ }
 149+ $rows[] = $row;
 150+ }
113151 $this->renderTable(
114 - array( 'Article Title', 'Category', 'Rating' ),
115 - array( /* rendered data */ ),
 152+ wfMsg( 'articleFeedback-table-caption-recentlows' ),
 153+ array_merge(
 154+ array( wfMsg( 'articleFeedback-table-heading-page' ) ),
 155+ self::getCategories()
 156+ ),
 157+ $rows,
116158 'articleFeedback-table-recentlows'
117159 );
118160 }
@@ -128,11 +170,16 @@
129171 protected function getDailyHighsAndLows() {
130172 return array(
131173 array(
132 - 'title' => 'Main Page',
 174+ 'page' => 'Main Page',
133175 // List of ratings as the currently stand
134 - 'values' => array( 4, 3, 2, 1 ),
 176+ 'ratings' => array( 1 => 4, 2 => 3, 3 => 2, 4 => 1 ),
135177 // Current average (considering historic averages of each rating)
136 - 'average' => 1.925
 178+ 'average' => 2.5
 179+ ),
 180+ array(
 181+ 'page' => 'Test Article',
 182+ 'ratings' => array( 1 => 1, 2 => 2, 3 => 3, 4 => 4 ),
 183+ 'average' => 2.5
137184 )
138185 );
139186 }
@@ -149,9 +196,13 @@
150197 protected function getWeeklyMostChanged() {
151198 return array(
152199 array(
153 - 'title' => 'Main Page',
 200+ 'page' => 'Main Page',
154201 // List of differences for each rating in the past 7 days
155 - 'differences' => array( 1, -2, 0, 0 ),
 202+ 'changes' => array( 1 => 1, 2 => -2, 3 => 0, 4 => 0 ),
 203+ ),
 204+ array(
 205+ 'page' => 'Test Article',
 206+ 'changes' => array( 1 => 0, 2 => 0, 3 => 1, 4 => 2 ),
156207 )
157208 );
158209 }
@@ -168,10 +219,38 @@
169220 protected function getRecentLows() {
170221 return array(
171222 array(
172 - 'title' => 'Main Page',
 223+ 'page' => 'Main Page',
173224 // List of rating IDs that qualify as recent lows
174 - 'lows' => array( 0, 3 ),
 225+ 'categories' => array( 1, 4 ),
 226+ ),
 227+ array(
 228+ 'page' => 'Test Article',
 229+ 'categories' => array( 1, 3 ),
175230 )
176231 );
177232 }
 233+
 234+ /* Protected Static Members */
 235+
 236+ protected static $categories;
 237+
 238+ /* Protected Static Methods */
 239+
 240+ protected function getCategories() {
 241+ global $wgArticleFeedbackRatings;
 242+
 243+ if ( !isset( self::$categories ) ) {
 244+ $dbr = wfGetDB( DB_SLAVE );
 245+ $res = $dbr->select(
 246+ 'article_feedback_ratings',
 247+ array( 'aar_id', 'aar_rating' ),
 248+ array( 'aar_id' => $wgArticleFeedbackRatings )
 249+ );
 250+ self::$categories = array();
 251+ foreach ( $res as $row ) {
 252+ self::$categories[$row->aar_id] = wfMsg( $row->aar_rating );
 253+ }
 254+ }
 255+ return self::$categories;
 256+ }
178257 }
Index: trunk/extensions/ArticleFeedback/sql/ArticleFeedback.sql
@@ -8,8 +8,8 @@
99
1010 -- Default article feedback ratings for the pilot
1111 INSERT INTO /*_*/article_feedback_ratings (aar_rating) VALUES
12 -('articlefeedback-rating-trustworthy'), ('articlefeedback-rating-objective'),
13 -('articlefeedback-rating-complete'), ('articlefeedback-rating-wellwritten');
 12+('articlefeedback-field-trustworthy-label'), ('articlefeedback-field-objective-label'),
 13+('articlefeedback-field-complete-label'), ('articlefeedback-field-wellwritten-label');
1414
1515 -- Store article feedbacks (user rating per revision)
1616 CREATE TABLE IF NOT EXISTS /*_*/article_feedback (
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.dashboard.css
@@ -1,8 +1,44 @@
22 .articleFeedback-table {
33 border: solid 1px #cccccc;
 4+ margin-bottom: 2em;
45 }
56
 7+.articleFeedback-table caption {
 8+ text-align: left;
 9+ font-size: 1.6em;
 10+ margin-bottom: 0.5em;
 11+}
 12+
613 .articleFeedback-table th {
714 text-align: left;
8 - border-bottom: solid 1px #eeeeee;
9 -}
\ No newline at end of file
 15+}
 16+
 17+.articleFeedback-table td {
 18+ border-top: solid 1px #eeeeee;
 19+}
 20+
 21+.articleFeedback-table td.articleFeedback-table-column-page,
 22+.articleFeedback-table td.articleFeedback-table-column-category {
 23+ text-align: left;
 24+}
 25+
 26+.articleFeedback-table td.articleFeedback-table-column-rating-1,
 27+.articleFeedback-table td.articleFeedback-table-column-rating-2,
 28+.articleFeedback-table td.articleFeedback-table-column-rating-3,
 29+.articleFeedback-table td.articleFeedback-table-column-rating-4,
 30+.articleFeedback-table td.articleFeedback-table-column-rating,
 31+.articleFeedback-table td.articleFeedback-table-column-average {
 32+ text-align: right;
 33+}
 34+
 35+.articleFeedback-table-cell-bad {
 36+ display: block;
 37+ background-color: #ffaa99;
 38+ color: #ffaa99;
 39+}
 40+
 41+.articleFeedback-table-cell-good {
 42+ display: block;
 43+ background-color: #99ff99;
 44+ color: #99ff99;
 45+}
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.i18n.php
@@ -10,7 +10,7 @@
1111 $messages['en'] = array(
1212 'articlefeedback' => 'Article feedback',
1313 'articlefeedback-desc' => 'Article feedback',
14 - /* Survey Messages */
 14+ /* ArticleFeedback survey */
1515 'articlefeedback-survey-question-origin' => 'What page were you on when you started this survey?',
1616 'articlefeedback-survey-question-whyrated' => 'Please let us know why you rated this page today (check all that apply):',
1717 'articlefeedback-survey-answer-whyrated-contribute-rating' => 'I wanted to contribute to the overall rating of the page',
@@ -25,7 +25,7 @@
2626 'articlefeedback-survey-submit' => 'Submit',
2727 'articlefeedback-survey-title' => 'Please answer a few questions',
2828 'articlefeedback-survey-thanks' => 'Thanks for filling out the survey.',
29 - /* Beta Messages */
 29+ /* ext.articleFeedback and jquery.articleFeedback */
3030 'articlefeedback-error' => 'An error has occured. Please try again later.',
3131 'articlefeedback-form-switch-label' => 'Rate this page',
3232 'articlefeedback-form-panel-title' => 'Rate this page',
@@ -74,6 +74,12 @@
7575 'articlefeedback-survey-message-success' => 'Thanks for filling out the survey.',
7676 'articlefeedback-survey-message-error' => 'An error has occurred.
7777 Please try again later.',
 78+ /* Special:ArticleFeedback */
 79+ 'articleFeedback-table-caption-dailyhighsandlows' => 'Today\'s highs and lows',
 80+ 'articleFeedback-table-caption-weeklymostchanged' => 'This week\'s most changed',
 81+ 'articleFeedback-table-caption-recentlows' => 'Recent lows',
 82+ 'articleFeedback-table-heading-page' => 'Page',
 83+ 'articleFeedback-table-heading-average' => 'Average',
7884 );
7985
8086 /** Message documentation (Message documentation)

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86742Added more functionality to the ArticleFeedback special page.tparscal23:05, 22 April 2011

Comments

#Comment by Krinkle (talk | contribs)   16:24, 27 April 2011
--- revision 86990
+++ revision 86991

-	protected function renderTable( array $headings, array $rows, $id = null ) {
+	protected function renderTable( $caption, array $headings, array $rows, $id = null ) {
 		global $wgOut;
 
 		$table = Html::openElement( 'table', array(
 			'class' => 'articleFeedback-table sortable', 'id' => $id
 		) );
+		// Caption
+		$table .= Html::element( 'caption', array(), $caption );
 		// Head

Not all tables have a caption right ? This seems to uncondionally add an (empty) caption..

#Comment by Krinkle (talk | contribs)   16:24, 27 April 2011

Nevermind, I looked too fast (thought it was the core parser). It's ArticleFeedback!

Status & tagging log