r82198 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82197‎ | r82198 | r82199 >
Date:22:03, 15 February 2011
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Some cleanup
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/Gallery/SRF_Gallery.php (modified) (history)
  • /trunk/extensions/SemanticResultFormats/SemanticResultFormats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/SemanticResultFormats.php
@@ -20,7 +20,7 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -define( 'SRF_VERSION', '1.5.3' );
 24+define( 'SRF_VERSION', '1.5.4 alpha' );
2525
2626 // Require the settings file.
2727 require dirname( __FILE__ ) . '/SRF_Settings.php';
Index: trunk/extensions/SemanticResultFormats/Gallery/SRF_Gallery.php
@@ -1,19 +1,14 @@
22 <?php
 3+
34 /**
4 - * Print query results as a gallery.
 5+ * Result printer that prints query results as a gallery.
56 *
6 - * @file
 7+ * @file SRF_Gallery.php
78 * @ingroup SemanticResultFormats
89 *
910 * @author Rowan Rodrik van der Molen
1011 * @author Jeroen De Dauw
1112 */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) die();
14 -
15 -/**
16 - * Result printer that prints query results as a gallery.
17 - */
1813 class SRFGallery extends SMWResultPrinter {
1914
2015 public function getName() {
Index: trunk/extensions/SemanticResultFormats/Calendar/SRF_Calendar.php
@@ -1,14 +1,15 @@
22 <?php
33
 4+$wgAutoloadClasses['SRFCHistoricalDate'] = $srfgIP . '/Calendar/SRFC_HistoricalDate.php';
 5+
46 /**
5 - * A class to print query results in a monthly calendar.
 7+ * Result printer that prints query results as a monthly calendar.
 8+ *
 9+ * @file SRF_Calendar.php
 10+ * @ingroup SemanticResultFormats
 11+ *
 12+ * @author ...
613 */
7 -
8 -if ( !defined( 'MEDIAWIKI' ) ) die();
9 -
10 -global $srfgIP;
11 -$wgAutoloadClasses['SRFCHistoricalDate'] = $srfgIP . '/Calendar/SRFC_HistoricalDate.php';
12 -
1314 class SRFCalendar extends SMWResultPrinter {
1415
1516 protected $mTemplate = '';
@@ -16,14 +17,16 @@
1718 protected $mRealUserLang = null;
1819
1920 protected function readParameters( $params, $outputmode ) {
20 - SMWResultPrinter::readParameters( $params, $outputmode );
 21+ parent::readParameters( $params, $outputmode );
2122
2223 if ( array_key_exists( 'template', $params ) ) {
2324 $this->mTemplate = trim( $params['template'] );
2425 }
 26+
2527 if ( array_key_exists( 'userparam', $params ) ) {
2628 $this->mUserParam = trim( $params['userparam'] );
2729 }
 30+
2831 if ( array_key_exists( 'lang', $params ) ) {
2932 global $wgLang;
3033 // store the actual user's language, so we can revert
@@ -46,24 +49,34 @@
4750 return $this->getResultText( $results, SMW_OUTPUT_HTML );
4851 }
4952
 53+ /**
 54+ * (non-PHPdoc)
 55+ * @see SMWResultPrinter::getResultText()
 56+ *
 57+ * TODO: split up megamoth
 58+ */
5059 protected function getResultText( $res, $outputmode ) {
5160 global $smwgIQRunningNumber, $wgUser;
5261 $skin = $wgUser->getSkin();
53 - $result = "";
 62+ $result = '';
5463
5564 $events = array();
5665 // print all result rows
5766 while ( $row = $res->getNext() ) {
5867 $dates = array();
59 - $title = $text = $color = "";
 68+ $title = $text = $color = '';
6069
6170 if ( $this->mTemplate != '' ) { // build template code
6271 $this->hasTemplates = true;
63 - if ( $this->mUserParam )
 72+
 73+ if ( $this->mUserParam ) {
6474 $text = "|userparam=$this->mUserParam";
 75+ }
 76+
6577 foreach ( $row as $i => $field ) {
6678 $pr = $field->getPrintRequest();
6779 $text .= '|' . ( $i + 1 ) . '=';
 80+
6881 while ( ( $object = $field->getNextObject() ) !== false ) {
6982 if ( $object->getTypeID() == '_dat' ) {
7083 $text .= $object->getLongWikiText();
@@ -77,6 +90,7 @@
7891 } else {
7992 $text .= $object->getShortText( $outputmode, null );
8093 }
 94+
8195 if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat' ) {
8296 $dates[] = SRFCalendar::formatDateStr( $object );
8397 }
@@ -93,6 +107,7 @@
94108 // value - cycle through all the values
95109 // for this property
96110 $textForProperty = '';
 111+
97112 while ( ( $object = $field->getNextObject() ) !== false ) {
98113 if ( $object->getTypeID() == '_dat' ) {
99114 // don't add date values to the display
@@ -101,12 +116,14 @@
102117 $title = Title::newFromText( $object->getShortWikiText( false ) );
103118 } else {
104119 $numNonDateProperties++;
 120+
105121 // handling of "headers=" param
106122 if ( $this->mShowHeaders == SMW_HEADERS_SHOW ) {
107 - $textForProperty .= $pr->getHTMLText( $skin ) . " ";
 123+ $textForProperty .= $pr->getHTMLText( $skin ) . ' ';
108124 } elseif ( $this->mShowHeaders == SMW_HEADERS_PLAIN ) {
109 - $textForProperty .= $pr->getLabel() . " ";
 125+ $textForProperty .= $pr->getLabel() . ' ';
110126 }
 127+
111128 // if $this->mShowHeaders == SMW_HEADERS_HIDE, print nothing
112129 // handling of "link=" param
113130 if ( $this->mLinkOthers ) {
@@ -117,40 +134,47 @@
118135 }
119136 } else {
120137 $numNonDateProperties++;
121 - $textForProperty .= $pr->getHTMLText( $skin ) . " " . $object->getShortText( $outputmode, $skin );
 138+ $textForProperty .= $pr->getHTMLText( $skin ) . ' ' . $object->getShortText( $outputmode, $skin );
122139 }
123140 if ( $pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_dat' ) {
124141 $dates[] = SRFCalendar::formatDateStr( $object );
125142 }
126143 }
 144+
127145 // add the text for this property to
128146 // the main text, adding on parentheses
129147 // or commas as needed
130148 if ( $numNonDateProperties == 1 ) {
131 - $text .= " (";
 149+ $text .= ' (';
132150 } elseif ( $numNonDateProperties > 1 ) {
133 - $text .= ", ";
 151+ $text .= ', ';
134152 }
135153 $text .= $textForProperty;
136154 }
137155 if ( $numNonDateProperties > 0 ) {
138 - $text .= ")";
 156+ $text .= ')';
139157 }
140158 }
 159+
141160 if ( count( $dates ) > 0 ) {
142161 // handle the 'color=' value, whether it came
143162 // from a compound query or a regular one
144163 // handling is different for SMW 1.5+
145164 if ( method_exists( 'SMWQueryResult', 'getResults' ) ) {
146165 $res_subject = $field->getResultSubject();
147 - if ( isset( $res_subject->display_options ) && is_array( $res_subject->display_options ) && array_key_exists( 'color', $res_subject->display_options ) )
148 - $color = $res_subject->display_options['color'];
 166+ if ( isset( $res_subject->display_options )
 167+ && is_array( $res_subject->display_options )
 168+ && array_key_exists( 'color', $res_subject->display_options ) ) {
 169+ $color = $res_subject->display_options['color'];
 170+ }
149171 } elseif ( property_exists( $row[0], 'display_options' ) ) {
150 - if ( is_array( $row[0]->display_options ) && array_key_exists( 'color', $row[0]->display_options ) )
 172+ if ( is_array( $row[0]->display_options ) && array_key_exists( 'color', $row[0]->display_options ) ) {
151173 $color = $row[0]->display_options['color'];
 174+ }
152175 } elseif ( array_key_exists( 'color', $this->m_params ) ) {
153176 $color = $this->m_params['color'];
154177 }
 178+
155179 foreach ( $dates as $date ) {
156180 $events[] = array( $title, $text, $date, $color );
157181 }
@@ -158,37 +182,43 @@
159183 }
160184
161185 $result = SRFCalendar::displayCalendar( $events );
 186+
162187 // go back to the actual user's language, in case a different
163188 // language had been specified for this calendar
164189 if ( ! is_null( $this->mRealUserLang ) ) {
165190 global $wgLang;
166191 $wgLang = $this->mRealUserLang;
167192 }
 193+
168194 global $wgParser;
169 - if ( is_null( $wgParser->getTitle() ) )
 195+
 196+ if ( is_null( $wgParser->getTitle() ) ) {
170197 return $result;
171 - else
 198+ }
 199+ else {
172200 return array( $result, 'noparse' => 'true', 'isHTML' => 'true' );
 201+ }
173202 }
174203
175 -
176204 function intToMonth( $int ) {
177 - if ( $int == '2' ) { return wfMsg( 'february' ); }
178 - if ( $int == '3' ) { return wfMsg( 'march' ); }
179 - if ( $int == '4' ) { return wfMsg( 'april' ); }
180 - if ( $int == '5' ) { return wfMsg( 'may' ); }
181 - if ( $int == '6' ) { return wfMsg( 'june' ); }
182 - if ( $int == '7' ) { return wfMsg( 'july' ); }
183 - if ( $int == '8' ) { return wfMsg( 'august' ); }
184 - if ( $int == '9' ) { return wfMsg( 'september' ); }
185 - if ( $int == '10' ) { return wfMsg( 'october' ); }
186 - if ( $int == '11' ) { return wfMsg( 'november' ); }
187 - if ( $int == '12' ) { return wfMsg( 'december' ); }
188 - // keep it simple - if it's '1' or anything else, return January
189 - return wfMsg( 'january' );
 205+ $months = array(
 206+ '1' => 'january',
 207+ '2' => 'february',
 208+ '3' => 'march',
 209+ '4' => 'april',
 210+ '5' => 'may',
 211+ '6' => 'june',
 212+ '7' => 'july',
 213+ '8' => 'august',
 214+ '9' => 'september',
 215+ '10' => 'october',
 216+ '11' => 'november',
 217+ '12' => 'december',
 218+ );
 219+
 220+ return wfMsg( array_key_exists( $int, $months ) ? $months[$int] : 'january' );
190221 }
191222
192 -
193223 function formatDateStr( $object ) {
194224 // For some reason, getMonth() and getDay() sometimes return a
195225 // number with a leading zero - get rid of it using (int)
@@ -203,8 +233,8 @@
204234 $wgOut->addLink( array(
205235 'rel' => 'stylesheet',
206236 'type' => 'text/css',
207 - 'media' => "screen, print",
208 - 'href' => $srfgScriptPath . "/Calendar/skins/SRFC_main.css"
 237+ 'media' => 'screen, print',
 238+ 'href' => $srfgScriptPath . '/Calendar/skins/SRFC_main.css'
209239 ) );
210240
211241 // Set variables differently depending on whether this is
@@ -215,6 +245,7 @@
216246 $additional_query_string = '';
217247 $hidden_inputs = '';
218248 $in_special_page = is_null( $page_title ) || $page_title->isSpecialPage();
 249+
219250 if ( $in_special_page ) {
220251 global $wgTitle;
221252 $page_title = $wgTitle;
@@ -233,6 +264,7 @@
234265 }
235266 }
236267 }
 268+
237269 foreach ( $request_values as $key => $value ) {
238270 if ( $key != 'month' && $key != 'year'
239271 // values from 'RunQuery'
@@ -251,21 +283,23 @@
252284 // and years (same - note that the previous or next month could
253285 // be in a different year), the number of days in the current,
254286 // previous and next months, etc.
255 - $cur_month_num = date( "n", time() );
 287+ $cur_month_num = date( 'n', time() );
256288 if ( $wgRequest->getCheck( 'month' ) ) {
257289 $query_month = $wgRequest->getVal( 'month' );
258290 if ( is_numeric( $query_month ) && ( intval( $query_month ) == $query_month ) && $query_month >= 1 && $query_month <= 12 ) {
259291 $cur_month_num = $wgRequest->getVal( 'month' );
260292 }
261293 }
 294+
262295 $cur_month = SRFCalendar::intToMonth( $cur_month_num );
263 - $cur_year = date( "Y", time() );
 296+ $cur_year = date( 'Y', time() );
264297 if ( $wgRequest->getCheck( 'year' ) ) {
265298 $query_year = $wgRequest->getVal( 'year' );
266299 if ( is_numeric( $query_year ) && intval( $query_year ) == $query_year ) {
267300 $cur_year = $wgRequest->getVal( 'year' );
268301 }
269302 }
 303+
270304 if ( $cur_month_num == '1' ) {
271305 $prev_month_num = '12';
272306 $prev_year = $cur_year - 1;
@@ -273,6 +307,7 @@
274308 $prev_month_num = $cur_month_num - 1;
275309 $prev_year = $cur_year;
276310 }
 311+
277312 if ( $cur_month_num == '12' ) {
278313 $next_month_num = '1';
279314 $next_year = $cur_year + 1;
@@ -280,13 +315,16 @@
281316 $next_month_num = $cur_month_num + 1;
282317 $next_year = $cur_year;
283318 }
 319+
284320 // there's no year '0' - change it to '1' or '-1'
285 - if ( $cur_year == "0" ) { $cur_year = "1"; }
286 - if ( $next_year == "0" ) { $next_year = "1"; }
287 - if ( $prev_year == "0" ) { $prev_year = "-1"; }
 321+ if ( $cur_year == '0' ) { $cur_year = '1'; }
 322+ if ( $next_year == '0' ) { $next_year = '1'; }
 323+ if ( $prev_year == '0' ) { $prev_year = '-1'; }
 324+
288325 $prev_month_url = $page_title->getLocalURL( "month=$prev_month_num&year=$prev_year" . $additional_query_string );
289326 $next_month_url = $page_title->getLocalURL( "month=$next_month_num&year=$next_year" . $additional_query_string );
290327 $today_url = $page_title->getLocalURL( $additional_query_string );
 328+
291329 $today_text = wfMsg( 'srfc_today' );
292330 $prev_month_text = wfMsg( 'srfc_previousmonth' );
293331 $next_month_text = wfMsg( 'srfc_nextmonth' );
@@ -299,7 +337,7 @@
300338 $start_day = 1 - $day_of_week_of_1;
301339 $days_in_prev_month = SRFCHistoricalDate::daysInMonth( $prev_year, $prev_month_num );
302340 $days_in_cur_month = SRFCHistoricalDate::daysInMonth( $cur_year, $cur_month_num );
303 - $today_string = date( "Y n j", time() );
 341+ $today_string = date( 'Y n j', time() );
304342 $url_year = $wgRequest->getVal( 'year' );
305343 $page_name = $page_title->getPrefixedDbKey();
306344
@@ -424,10 +462,14 @@
425463 return $text;
426464 }
427465
428 - public function getParameters() {
429 - $params = parent::getParameters();
430 - $params[] = array( 'name' => 'lang', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_calendarlang' ) );
431 - return $params;
432 - }
 466+ /**
 467+ * (non-PHPdoc)
 468+ * @see SMWResultPrinter::getParameters()
 469+ */
 470+ public function getParameters() {
 471+ $params = parent::getParameters();
 472+ $params[] = array( 'name' => 'lang', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_calendarlang' ) );
 473+ return $params;
 474+ }
433475
434476 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r82239Follow up to r82198jeroendedauw13:16, 16 February 2011
r82241Follow up to r82198jeroendedauw13:28, 16 February 2011

Comments

#Comment by Reach Out to the Truth (talk | contribs)   06:08, 16 February 2011

$srfgIP is undefined.

#Comment by Jeroen De Dauw (talk | contribs)   13:17, 16 February 2011

Hmm, I also noticed this, but apparently forgot to commit the fix :)

#Comment by Nikerabbit (talk | contribs)   08:24, 16 February 2011

Shouldn't this be may_long?

+'5' => 'may',

Status & tagging log