Beispiel #1
0
 static function daysInMonth($year, $month)
 {
     if ($month == 4 || $month == 6 || $month == 9 || $month == 11) {
         return 30;
     }
     if ($month == 2) {
         return SRFCHistoricalDate::leap_jul_greg($year) ? 29 : 28;
     }
     return 31;
 }
    function displayCalendar($events)
    {
        global $wgParser;
        global $srfgFirstDayOfWeek;
        global $srfgScriptPath;
        $context = RequestContext::getMain();
        $request = $context->getRequest();
        if (!$wgParser->mFirstCall) {
            $wgParser->disableCache();
        }
        $context->getOutput()->addLink(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen, print', 'href' => $srfgScriptPath . '/formats/calendar/resources/ext.srf.calendar.css'));
        // Set variables differently depending on whether this is
        // being called from a regular page, via #ask, or from a
        // special page: most likely either Special:Ask or
        // Special:RunQuery.
        $pageTitle = $context->getTitle();
        if (!$pageTitle) {
            $pageTitle = $wgParser->getTitle();
        }
        $additionalQueryString = '';
        $hiddenInputs = '';
        if ($pageTitle->isSpecialPage()) {
            $requestValues = $request->getValues();
            // Also go through the predefined PHP variable
            // $_REQUEST, because $request->getValues() for
            // some reason doesn't return array values - is
            // there a better (less hacky) way to do this?
            foreach ($_REQUEST as $key => $value) {
                if (is_array($value)) {
                    foreach ($value as $k2 => $v2) {
                        $newKey = $key . '[' . $k2 . ']';
                        $requestValues[$newKey] = $v2;
                    }
                }
            }
            foreach ($requestValues as $key => $value) {
                if ($key != 'month' && $key != 'year' && $key != 'query' && $key != 'free_text') {
                    $additionalQueryString .= "&{$key}={$value}";
                    $hiddenInputs .= "<input type=\"hidden\" " . "name=\"{$key}\" value=\"{$value}\" />";
                }
            }
        }
        // Set days of the week.
        $weekDayNames = array(1 => wfMessage('sunday')->text(), 2 => wfMessage('monday')->text(), 3 => wfMessage('tuesday')->text(), 4 => wfMessage('wednesday')->text(), 5 => wfMessage('thursday')->text(), 6 => wfMessage('friday')->text(), 7 => wfMessage('saturday')->text());
        if (empty($srfgFirstDayOfWeek)) {
            $firstDayOfWeek = 1;
            $lastDayOfWeek = 7;
        } else {
            $firstDayOfWeek = array_search($srfgFirstDayOfWeek, $weekDayNames);
            if ($firstDayOfWeek === false) {
                // Bad value for $srfgFirstDayOfWeek!
                print 'Warning: Bad value for $srfgFirstDayOfWeek "' . '(' . $srfgFirstDayOfWeek . '")';
                $firstDayOfWeek = 1;
            }
            if ($firstDayOfWeek == 1) {
                $lastDayOfWeek = 7;
            } else {
                $lastDayOfWeek = $firstDayOfWeek - 1;
            }
        }
        // Now create the actual array of days of the week, based on
        // the start day
        $weekDays = array();
        for ($i = 1; $i <= 7; $i++) {
            $curDay = ($firstDayOfWeek + $i - 2) % 7 + 1;
            $weekDays[$i] = $weekDayNames[$curDay];
        }
        // Get all the date-based values we need - the current month
        // and year (i.e., the one the user is looking at - not
        // necessarily the "current" ones), the previous and next months
        // and years (same - note that the previous or next month could
        // be in a different year), the number of days in the current,
        // previous and next months, etc.
        if (is_numeric($this->mStartMonth) && intval($this->mStartMonth) == $this->mStartMonth && $this->mStartMonth >= 1 && $this->mStartMonth <= 12) {
            $curMonthNum = $this->mStartMonth;
        } else {
            $curMonthNum = date('n');
        }
        if ($request->getCheck('month')) {
            $queryMonth = $request->getVal('month');
            if (is_numeric($queryMonth) && intval($queryMonth) == $queryMonth && $queryMonth >= 1 && $queryMonth <= 12) {
                $curMonthNum = $request->getVal('month');
            }
        }
        $curMonth = self::intToMonth($curMonthNum);
        if (is_numeric($this->mStartYear) && intval($this->mStartYear) == $this->mStartYear) {
            $curYear = $this->mStartYear;
        } else {
            $curYear = date('Y');
        }
        if ($request->getCheck('year')) {
            $queryYear = $request->getVal('year');
            if (is_numeric($queryYear) && intval($queryYear) == $queryYear) {
                $curYear = $request->getVal('year');
            }
        }
        if ($curMonthNum == '1') {
            $prevMonthNum = '12';
            $prevYear = $curYear - 1;
        } else {
            $prevMonthNum = $curMonthNum - 1;
            $prevYear = $curYear;
        }
        if ($curMonthNum == '12') {
            $nextMonthNum = '1';
            $nextYear = $curYear + 1;
        } else {
            $nextMonthNum = $curMonthNum + 1;
            $nextYear = $curYear;
        }
        // There's no year '0' - change it to '1' or '-1'.
        if ($curYear == '0') {
            $curYear = '1';
        }
        if ($nextYear == '0') {
            $nextYear = '1';
        }
        if ($prevYear == '0') {
            $prevYear = '-1';
        }
        $prevMonthUrl = $pageTitle->getLocalURL("month={$prevMonthNum}&year={$prevYear}" . $additionalQueryString);
        $nextMonthUrl = $pageTitle->getLocalURL("month={$nextMonthNum}&year={$nextYear}" . $additionalQueryString);
        $todayUrl = $pageTitle->getLocalURL($additionalQueryString);
        $pageName = $pageTitle->getPrefixedDbKey();
        $todayText = wfMessage('srfc_today')->text();
        $prevMonthText = wfMessage('srfc_previousmonth')->text();
        $nextMonthText = wfMessage('srfc_nextmonth')->text();
        $goToMonthText = wfMessage('srfc_gotomonth')->text();
        // Get day of the week that the first of this month falls on.
        $firstDay = new SRFCHistoricalDate();
        $firstDay->create($curYear, $curMonthNum, 1);
        $startDay = $firstDayOfWeek - $firstDay->getDayOfWeek();
        if ($startDay > 0) {
            $startDay -= 7;
        }
        $daysInPrevMonth = SRFCHistoricalDate::daysInMonth($prevYear, $prevMonthNum);
        $daysInCurMonth = SRFCHistoricalDate::daysInMonth($curYear, $curMonthNum);
        $todayString = date('Y n j', time());
        $pageName = $pageTitle->getPrefixedDbKey();
        // Create table for holding title and navigation information.
        $text = <<<END
<table class="navigation_table">
<tr><td class="month_name">{$curMonth} {$curYear}</td>
<td class="nav_links"><a href="{$prevMonthUrl}" title="{$prevMonthText}">
<img src="{$srfgScriptPath}/formats/calendar/resources/images/left-arrow.png" border="0" />
</a>&#160;<a href="{$todayUrl}">{$todayText}</a>&#160;
<a href="{$nextMonthUrl}" title="{$nextMonthText}">
<img src="{$srfgScriptPath}/formats/calendar/resources/images/right-arrow.png" border="0" />
</a></td><td class="nav_form"><form>
<input type="hidden" name="title" value="{$pageName}">
<select name="month">

END;
        for ($i = 1; $i <= 12; $i++) {
            $monthName = self::intToMonth($i);
            $selectedStr = $i == $curMonthNum ? "selected" : "";
            $text .= "<option value=\"{$i}\" {$selectedStr}>\n\t\t\t\t{$monthName}</option>\n";
        }
        $text .= <<<END
</select>
<input name="year" type="text" value="{$curYear}" size="4">
{$hiddenInputs}
<input type="submit" value="{$goToMonthText}">
</form>
</td>
</tr>
</table>

<table class="month_calendar">
<tr class="weekdays">

END;
        // First row of the main table holds the days of the week
        foreach ($weekDays as $weekDay) {
            $text .= "<td>{$weekDay}</td>";
        }
        $text .= "</tr>\n";
        // Now, create the calendar itself -
        // loop through a set of weeks, from a "Sunday" (which might be
        // before the beginning of the month) to a "Saturday" (which
        // might be after the end of the month).
        // "Sunday" and "Saturday" are in quotes because the actual
        // start and end days of the week can be set by the admin.
        $dayOfTheWeek = $firstDayOfWeek;
        $isLastWeek = false;
        for ($day = $startDay; !$isLastWeek || $dayOfTheWeek != $firstDayOfWeek; $day++) {
            if ($dayOfTheWeek == $firstDayOfWeek) {
                $text .= "<tr>\n";
            }
            if ("{$curYear} {$curMonthNum} {$day}" == $todayString) {
                $text .= "<td class=\"today\">\n";
            } elseif ($dayOfTheWeek == 1 || $dayOfTheWeek == 7) {
                $text .= "<td class=\"weekend_day\">\n";
            } else {
                $text .= "<td>\n";
            }
            if ($day == $daysInCurMonth || $day > 50) {
                $isLastWeek = true;
            }
            // If this day is before or after the current month,
            // set a "display day" to show on the calendar, and
            // use a different CSS style for it.
            if ($day > $daysInCurMonth || $day < 1) {
                if ($day < 1) {
                    $displayDay = $day + $daysInPrevMonth;
                    $dateStr = $prevYear . '-' . $prevMonthNum . '-' . $displayDay;
                }
                if ($day > $daysInCurMonth) {
                    $displayDay = $day - $daysInCurMonth;
                    $dateStr = $nextYear . '-' . $nextMonthNum . '-' . $displayDay;
                }
                $text .= "<div class=\"day day_other_month\">{$displayDay}</div>\n";
            } else {
                $dateStr = $curYear . '-' . $curMonthNum . '-' . $day;
                $text .= "<div class=\"day\">{$day}</div>\n";
            }
            // Finally, the most important step - get the events
            // that match this date, and the given set of criteria,
            // and display them in this date's box.
            $text .= "<div class=\"main\">\n";
            if ($events == null) {
                $events = array();
            }
            foreach ($events as $event) {
                list($eventTitle, $otherText, $eventDate, $color) = $event;
                if ($eventDate == $dateStr) {
                    if ($this->mTemplate != '') {
                        $templatetext = '{{' . $this->mTemplate . $otherText . '|thisdate=' . $dateStr . '}}';
                        $templatetext = $wgParser->replaceVariables($templatetext);
                        $templatetext = $wgParser->recursiveTagParse($templatetext);
                        $text .= $templatetext;
                    } else {
                        $eventStr = Linker::link($eventTitle);
                        if ($color != '') {
                            $text .= "<div class=\"colored-entry\">\n\t\t\t\t\t\t\t\t<p style=\"border-left: 7px {$color} solid;\">\n\t\t\t\t\t\t\t\t{$eventStr} {$otherText}</p></div>\n";
                        } else {
                            $text .= "{$eventStr} {$otherText}\n\n";
                        }
                    }
                }
            }
            $text .= <<<END
</div>
</td>

END;
            if ($dayOfTheWeek == $lastDayOfWeek) {
                $text .= "</tr>\n";
            }
            if ($dayOfTheWeek == 7) {
                $dayOfTheWeek = 1;
            } else {
                $dayOfTheWeek++;
            }
        }
        $text .= "</table>\n";
        return $text;
    }
	function displayCalendar( $events ) {
		global $wgOut, $srfgScriptPath, $wgParser, $wgRequest;
		global $srfgFirstDayOfWeek;

		$wgParser->disableCache();

		$wgOut->addLink( array(
			'rel' => 'stylesheet',
			'type' => 'text/css',
			'media' => 'screen, print',
			'href' => $srfgScriptPath . '/Calendar/skins/SRFC_main.css'
		) );

		// Set variables differently depending on whether this is
		// being called from a regular page, via #ask, or from a
		// special page: most likely either Special:Ask or
		// Special:RunQuery.
		$page_title = $wgParser->getTitle();
		$additional_query_string = '';
		$hidden_inputs = '';
		$in_special_page = is_null( $page_title ) || $page_title->isSpecialPage();
		
		if ( $in_special_page ) {
			global $wgTitle;
			$page_title = $wgTitle;
			global $wgUser;
			$skin = $wgUser->getSkin();
			$request_values = $wgRequest->getValues();
			// Also go through the predefined PHP variable
			// $_REQUEST, because $wgRequest->getValues() for
			// some reason doesn't return array values - is
			// there a better (less hacky) way to do this?
			foreach ( $_REQUEST as $key => $value ) {
				if ( is_array( $value ) ) {
					foreach ($value as $k2 => $v2 ) {
						$new_key = $key . '[' . $k2 . ']';
						$request_values[$new_key] = $v2;
					}
				}
			}
			
			foreach ( $request_values as $key => $value ) {
				if ( $key != 'month' && $key != 'year'
					// values from 'RunQuery'
			       		&& $key != 'query' && $key != 'free_text'
				) {
					$additional_query_string .= "&$key=$value";
					$hidden_inputs .= "<input type=\"hidden\" name=\"$key\" value=\"$value\" />";
				}
			}
		} else {
			$skin = $wgParser->getOptions()->getSkin();
		}

		// Set days of the week.
		$week_day_names = array(
			1 => wfMsg( 'sunday' ),
			2 => wfMsg( 'monday' ),
			3 => wfMsg( 'tuesday' ),
			4 => wfMsg( 'wednesday' ),
			5 => wfMsg( 'thursday' ),
			6 => wfMsg( 'friday' ),
			7 => wfMsg( 'saturday' )
		);
		if ( empty( $srfgFirstDayOfWeek ) ) {
			$firstDayOfWeek = 1;
			$lastDayOfWeek = 7;
		} else {
			$firstDayOfWeek = array_search( $srfgFirstDayOfWeek, $week_day_names );
			if ( $firstDayOfWeek === false ) {
				// Bad value for $srfgFirstDayOfWeek!
				print 'Warning: Bad value for $srfgFirstDayOfWeek ("' . $srfgFirstDayOfWeek . '")';
				$firstDayOfWeek = 1;
			}
			if ( $firstDayOfWeek == 1 ) {
				$lastDayOfWeek = 7;
			} else {
				$lastDayOfWeek = $firstDayOfWeek - 1;
			}
		}

		// Now create the actual array of days of the week, based on
		// the start day
		$week_days = array();
		for ( $i = 1; $i <= 7; $i++ ) {
			$curDay = ( ( $firstDayOfWeek + $i - 2 ) % 7 ) + 1;
			$week_days[$i] = $week_day_names[$curDay];
		}

		// Get all the date-based values we need - the current month
		// and year (i.e., the one the user is looking at - not
		// necessarily the "current" ones), the previous and next months
		// and years (same - note that the previous or next month could
		// be in a different year), the number of days in the current,
		// previous and next months, etc.
		$cur_month_num = date( 'n', time() );
		if ( $wgRequest->getCheck( 'month' ) ) {
			$query_month = $wgRequest->getVal( 'month' );
			if ( is_numeric( $query_month ) && ( intval( $query_month ) == $query_month ) && $query_month >= 1 && $query_month <= 12 ) {
				$cur_month_num = $wgRequest->getVal( 'month' );
			}
		}
		
		$cur_month = self::intToMonth( $cur_month_num );
		$cur_year = date( 'Y', time() );
		if ( $wgRequest->getCheck( 'year' ) ) {
			$query_year = $wgRequest->getVal( 'year' );
			if ( is_numeric( $query_year ) && intval( $query_year ) == $query_year ) {
				$cur_year = $wgRequest->getVal( 'year' );
			}
		}
		
		if ( $cur_month_num == '1' ) {
			$prev_month_num = '12';
			$prev_year = $cur_year - 1;
		} else {
			$prev_month_num = $cur_month_num - 1;
			$prev_year = $cur_year;
		}
		
		if ( $cur_month_num == '12' ) {
			$next_month_num = '1';
			$next_year = $cur_year + 1;
		} else {
			$next_month_num = $cur_month_num + 1;
			$next_year = $cur_year;
		}
		
		// There's no year '0' - change it to '1' or '-1'.
		if ( $cur_year == '0' ) { $cur_year = '1'; }
		if ( $next_year == '0' ) { $next_year = '1'; }
		if ( $prev_year == '0' ) { $prev_year = '-1'; }
		
		$prev_month_url = $page_title->getLocalURL( "month=$prev_month_num&year=$prev_year" . $additional_query_string );
		$next_month_url = $page_title->getLocalURL( "month=$next_month_num&year=$next_year" . $additional_query_string );
		$today_url = $page_title->getLocalURL( $additional_query_string );
		
		$today_text = wfMsg( 'srfc_today' );
		$prev_month_text = wfMsg( 'srfc_previousmonth' );
		$next_month_text = wfMsg( 'srfc_nextmonth' );
		$go_to_month_text = wfMsg( 'srfc_gotomonth' );

		// Get day of the week that the first of this month falls on.
		$first_day = new SRFCHistoricalDate();
		$first_day->create( $cur_year, $cur_month_num, 1 );
		$day_of_week_of_1 = $first_day->getDayOfWeek();
		$start_day = $firstDayOfWeek - $day_of_week_of_1;
		if ( $start_day > 0 ) { $start_day -= 7; }
		$days_in_prev_month = SRFCHistoricalDate::daysInMonth( $prev_year, $prev_month_num );
		$days_in_cur_month = SRFCHistoricalDate::daysInMonth( $cur_year, $cur_month_num );
		$today_string = date( 'Y n j', time() );
		$page_name = $page_title->getPrefixedDbKey();

		// Create table for holding title and navigation information.
		$text = <<<END
<table class="navigation_table">
<tr>
<td class="month_name">$cur_month $cur_year</td>
<td class="nav_links">
<a href="$prev_month_url" title="$prev_month_text"><img src="$srfgScriptPath/Calendar/skins/left-arrow.png" border="0" /></a>
&#160;
<a href="$today_url">$today_text</a>
&#160;
<a href="$next_month_url" title="$next_month_text"><img src="$srfgScriptPath/Calendar/skins/right-arrow.png" border="0" /></a>
</td>
<td class="nav_form">
<form>
<input type="hidden" name="title" value="$page_name">
<select name="month">

END;
		for ( $i = 1; $i <= 12; $i++ ) {
			$month_name = self::intToMonth( $i );
			$selected_str = ( $i == $cur_month_num ) ? "selected" : "";
			$text .= "<option value=\"$i\" $selected_str>$month_name</option>\n";
		}
		$text .= <<<END
</select>
<input name="year" type="text" value="$cur_year" size="4">
$hidden_inputs
<input type="submit" value="$go_to_month_text">
</form>
</td>
</tr>
</table>

<table class="month_calendar">
<tr class="weekdays">

END;
		// First row of the main table holds the days of the week
		foreach ( $week_days as $week_day ) {
			$text .= "<td>$week_day</td>";
		}
		$text .= "</tr>\n";

		// Now, create the calendar itself -
		// loop through a set of weeks, from a "Sunday" (which might be
		// before the beginning of the month) to a "Saturday" (which
		// might be after the end of the month).
		// "Sunday" and "Saturday" are in quotes because the actual
		// start and end days of the week can be set by the admin.
		$day_of_the_week = $firstDayOfWeek;
		$is_last_week = false;
		for ( $day = $start_day; ( ! $is_last_week || $day_of_the_week != $firstDayOfWeek ); $day++ ) {
			if ( $day_of_the_week == $firstDayOfWeek ) {
				$text .= "<tr>\n";
			}
			if ( "$cur_year $cur_month_num $day" == $today_string ) {
				$text .= "<td class=\"today\">\n";
			} elseif ( $day_of_the_week == 1 || $day_of_the_week == 7 ) {
				$text .= "<td class=\"weekend_day\">\n";
			} else {
				$text .= "<td>\n";
			}
			if ( $day == $days_in_cur_month || $day > 50 ) { $is_last_week = true; }
			// If this day is before or after the current month,
			// set a "display day" to show on the calendar, and
			// use a different CSS style for it.
			if ( $day > $days_in_cur_month || $day < 1 ) {
				if ( $day < 1 ) {
					$display_day = $day + $days_in_prev_month;
					$date_str = $prev_year . '-' . $prev_month_num . '-' . $display_day;
				}
				if ( $day > $days_in_cur_month ) {
					$display_day = $day - $days_in_cur_month;
					$date_str = $next_year . '-' . $next_month_num . '-' . $display_day;
				}
				$text .= "<div class=\"day day_other_month\">$display_day</div>\n";
			} else {
				$date_str = $cur_year . '-' . $cur_month_num . '-' . $day;
				$text .= "<div class=\"day\">$day</div>\n";
			}
			// Finally, the most important step - get the events
			// that match this date, and the given set of criteria,
			// and display them in this date's box.
			$text .= "<div class=\"main\">\n";
			if ( $events == null ) {
				$events = array();
			}
			foreach ( $events as $event ) {
				list( $event_title, $other_text, $event_date, $color ) = $event;
				if ( $event_date == $date_str ) {
					if ( $this->mTemplate != '' ) {
						$templatetext = '{{' . $this->mTemplate . $other_text . '|thisdate=' . $date_str . '}}';
						$templatetext = $wgParser->replaceVariables( $templatetext );
						$templatetext = $wgParser->recursiveTagParse( $templatetext );
						$text .= $templatetext;
					} else {
						$event_str = $skin->makeLinkObj( $event_title );
						if ( $color != '' ) {
							$text .= "<p class=\"colored-entry\" style=\"border-left: 7px $color solid;\">$event_str $other_text</p>\n";
						} else {
							$text .= "$event_str $other_text\n\n";
						}
					}
				}
			}
			$text .= <<<END
</div>
</td>

END;
			if ( $day_of_the_week == $lastDayOfWeek ) {
				$text .= "</tr>\n";
			}
			if ( $day_of_the_week == 7 ) {
				$day_of_the_week = 1;
			} else {
				$day_of_the_week++;
			}
		}
		$text .= "</table>\n";

		return $text;
	}