r109783 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109782‎ | r109783 | r109784 >
Date:23:32, 22 January 2012
Author:yaron
Status:ok
Tags:
Comment:
Removed support for SMW < 1.5 (it was no longer supported anyway), improved some spacing
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php
@@ -21,7 +21,7 @@
2222
2323 $this->mTemplate = trim( $params['template'] );
2424 $this->mUserParam = trim( $params['userparam'] );
25 -
 25+
2626 if ( $params['lang'] !== false ) {
2727 global $wgLang;
2828 // Store the actual user's language, so we can revert
@@ -52,7 +52,7 @@
5353 */
5454 protected function getResultText( SMWQueryResult $res, $outputmode ) {
5555 $events = array();
56 -
 56+
5757 // Print all result rows.
5858 while ( $row = $res->getNext() ) {
5959 $dates = array();
@@ -61,15 +61,15 @@
6262 if ( $this->mTemplate != '' ) {
6363 // Build template code
6464 $this->hasTemplates = true;
65 -
 65+
6666 if ( $this->mUserParam ) {
6767 $text = "|userparam=$this->mUserParam";
6868 }
69 -
 69+
7070 foreach ( $row as $i => $field ) {
7171 $pr = $field->getPrintRequest();
7272 $text .= '|' . ( $i + 1 ) . '=';
73 -
 73+
7474 while ( ( $object = $field->getNextDataValue() ) !== false ) {
7575 if ( $object->getTypeID() == '_dat' ) {
7676 $text .= $object->getLongWikiText();
@@ -83,7 +83,7 @@
8484 } else {
8585 $text .= $object->getShortText( $outputmode, null );
8686 }
87 -
 87+
8888 if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat' ) {
8989 $dates[] = $this->formatDateStr( $object );
9090 }
@@ -101,7 +101,7 @@
102102 // value - cycle through all the values
103103 // for this property.
104104 $textForProperty = '';
105 -
 105+
106106 while ( ( $object = $field->getNextDataValue() ) !== false ) {
107107 if ( $object->getTypeID() == '_dat' ) {
108108 // Don't add date values to the display.
@@ -110,14 +110,14 @@
111111 $title = Title::newFromText( $object->getShortWikiText( false ) );
112112 } else {
113113 $numNonDateProperties++;
114 -
 114+
115115 // handling of "headers=" param
116116 if ( $this->mShowHeaders == SMW_HEADERS_SHOW ) {
117117 $textForProperty .= $pr->getHTMLText( smwfGetLinker() ) . ' ';
118118 } elseif ( $this->mShowHeaders == SMW_HEADERS_PLAIN ) {
119119 $textForProperty .= $pr->getLabel() . ' ';
120120 }
121 -
 121+
122122 // If $this->mShowHeaders == SMW_HEADERS_HIDE, print nothing.
123123 // handling of "link=" param
124124 if ( $this->mLinkOthers ) {
@@ -134,7 +134,7 @@
135135 $dates[] = $this->formatDateStr( $object );
136136 }
137137 }
138 -
 138+
139139 // Add the text for this property to
140140 // the main text, adding on parentheses
141141 // or commas as needed.
@@ -149,27 +149,17 @@
150150 $text .= ')';
151151 }
152152 }
153 -
 153+
154154 if ( count( $dates ) > 0 ) {
155155 // Handle the 'color=' value, whether it came
156156 // from a compound query or a regular one.
157 - // handling is different for SMW 1.5+
158 - $realFunction = array( $field, 'getResultSubject' );
159 - if ( is_callable( $realFunction ) ) {
160 - $res_subject = $field->getResultSubject();
161 - if ( isset( $res_subject->display_options )
162 - && is_array( $res_subject->display_options )
163 - && array_key_exists( 'color', $res_subject->display_options ) ) {
164 - $color = $res_subject->display_options['color'];
165 - }
166 - } elseif ( property_exists( $row[0], 'display_options' ) ) {
167 - if ( is_array( $row[0]->display_options ) && array_key_exists( 'color', $row[0]->display_options ) ) {
168 - $color = $row[0]->display_options['color'];
169 - }
170 - } elseif ( array_key_exists( 'color', $this->m_params ) ) {
171 - $color = $this->m_params['color'];
 157+ $res_subject = $field->getResultSubject();
 158+ if ( isset( $res_subject->display_options )
 159+ && is_array( $res_subject->display_options )
 160+ && array_key_exists( 'color', $res_subject->display_options ) ) {
 161+ $color = $res_subject->display_options['color'];
172162 }
173 -
 163+
174164 foreach ( $dates as $date ) {
175165 $events[] = array( $title, $text, $date, $color );
176166 }
@@ -177,16 +167,16 @@
178168 }
179169
180170 $result = $this->displayCalendar( $events );
181 -
 171+
182172 // Go back to the actual user's language, in case a different
183173 // language had been specified for this calendar.
184174 if ( ! is_null( $this->mRealUserLang ) ) {
185175 global $wgLang;
186176 $wgLang = $this->mRealUserLang;
187177 }
188 -
 178+
189179 global $wgParser;
190 -
 180+
191181 if ( is_null( $wgParser->getTitle() ) ) {
192182 return $result;
193183 } else {
@@ -205,11 +195,11 @@
206196 '7' => 'july',
207197 '8' => 'august',
208198 '9' => 'september',
209 - '10' => 'october',
 199+ '10' => 'october',
210200 '11' => 'november',
211201 '12' => 'december',
212202 );
213 -
 203+
214204 return wfMsgForContent( array_key_exists( $int, $months ) ? $months[$int] : 'january' );
215205 }
216206
@@ -240,7 +230,7 @@
241231 $additional_query_string = '';
242232 $hidden_inputs = '';
243233 $in_special_page = is_null( $page_title ) || $page_title->isSpecialPage();
244 -
 234+
245235 if ( $in_special_page ) {
246236 global $wgTitle;
247237 $page_title = $wgTitle;
@@ -259,7 +249,7 @@
260250 }
261251 }
262252 }
263 -
 253+
264254 foreach ( $request_values as $key => $value ) {
265255 if ( $key != 'month' && $key != 'year'
266256 // values from 'RunQuery'
@@ -321,7 +311,7 @@
322312 $cur_month_num = $wgRequest->getVal( 'month' );
323313 }
324314 }
325 -
 315+
326316 $cur_month = self::intToMonth( $cur_month_num );
327317 $cur_year = date( 'Y', time() );
328318 if ( $wgRequest->getCheck( 'year' ) ) {
@@ -330,7 +320,7 @@
331321 $cur_year = $wgRequest->getVal( 'year' );
332322 }
333323 }
334 -
 324+
335325 if ( $cur_month_num == '1' ) {
336326 $prev_month_num = '12';
337327 $prev_year = $cur_year - 1;
@@ -338,7 +328,7 @@
339329 $prev_month_num = $cur_month_num - 1;
340330 $prev_year = $cur_year;
341331 }
342 -
 332+
343333 if ( $cur_month_num == '12' ) {
344334 $next_month_num = '1';
345335 $next_year = $cur_year + 1;
@@ -346,16 +336,16 @@
347337 $next_month_num = $cur_month_num + 1;
348338 $next_year = $cur_year;
349339 }
350 -
 340+
351341 // There's no year '0' - change it to '1' or '-1'.
352342 if ( $cur_year == '0' ) { $cur_year = '1'; }
353343 if ( $next_year == '0' ) { $next_year = '1'; }
354344 if ( $prev_year == '0' ) { $prev_year = '-1'; }
355 -
 345+
356346 $prev_month_url = $page_title->getLocalURL( "month=$prev_month_num&year=$prev_year" . $additional_query_string );
357347 $next_month_url = $page_title->getLocalURL( "month=$next_month_num&year=$next_year" . $additional_query_string );
358348 $today_url = $page_title->getLocalURL( $additional_query_string );
359 -
 349+
360350 $today_text = wfMsg( 'srfc_today' );
361351 $prev_month_text = wfMsg( 'srfc_previousmonth' );
362352 $next_month_text = wfMsg( 'srfc_nextmonth' );
@@ -502,20 +492,20 @@
503493 */
504494 public function getParameters() {
505495 $params = parent::getParameters();
506 -
 496+
507497 $params['lang'] = new Parameter( 'lang' );
508498 $params['lang']->setMessage( 'srf_paramdesc_calendarlang' );
509499 $params['lang']->setDefault( false, false );
510 -
 500+
511501 $params['template'] = new Parameter( 'template' );
512502 $params['template']->setDefault( '' );
513 -
 503+
514504 $params['userparam'] = new Parameter( 'userparam' );
515505 $params['userparam']->setDefault( '' );
516 -
 506+
517507 $params['color'] = new Parameter( 'color' );
518508 $params['color']->setDefault( '' );
519 -
 509+
520510 return $params;
521511 }
522512

Status & tagging log