Extension talk:Calendar (Cdamian)

Latest comment: 16 years ago by 128.231.88.4 in topic Method for alternate weekviews

email me or use the github issue tracker

edit

you can also contact me at christof@damian.net that will be answered quicker. I don't check this page too often.

Since I moved the code to github you can also use the issue tracker there: https://github.com/christofdamian/wikicalendar/issues

Things I'd like to see...

edit
  • css (or css-like) stuff for customising the style of days which have entries (dependent on the categories of those entries, perhaps)
  • Ability to merge separate calendars - e.g. a group of friends have their own calendars, but would like to have all those calendars show on a single page - for arranging get-togethers, or just to have a single point of entry. (<calendar>name="john,bob,jules" view="year"</calendar> ?)
  • A way to show the first line of any calendar entry within a date range
  • A variant of the above - auto-generated summary by-month pages. e.g. CalName_2005_10 would have a summary of all the entries for October 2005

I'm not sure if any of these are possible, or whether they are possible but difficult...I'm just brainstorming a wishlist from my (limited) use of the extension :)

--MNJones

css: I can put some more css classes/ids in the next version to make this possible (without the categories though)
merge calendars: I thought about that too, it would be useful for my site, shouldn't be to difficult. There is a question about which, calendar will be edited though. Maybe editing will be disabled then.
first line: maybe a bit special -- or could this be done with css ?
month summary: I played with this too with full inclusion, but it didn't really work nicely
--Cdamian 22:29, 11 October 2005 (UTC)Reply
As far as the "first line" idea goes, you already do something similar with the week view. My idea was to remove any entries that had *no* corresponding pages - i.e. a list of "what's coming up".
→ Is there a way to determine whether a page has (relevant) content?
→ As tricky as (relevant) content determination may be, I can see a good use for this. ie: a recurring event has it's own wiki page. It would be very useful to be able to somehow show when the next scheduled occurance of that event will be (according to the calendar). More specifically, if we have chips and salsa for lunch together once a month, it would be neat to schedule it on the calendar and then have the next lunch date: automagically show up on the chips_and_salsa_for_lunch page. --68.93.222.34 21:08, 11 November 2005 (UTC)Reply
(One of) the applications I'm looking at using it for is a list of reenactment events - there are maybe one or two events per month, so listing *every* day's entry would be unwieldy. All I need is to list which days what events are on. Still not sure that this is the best medium for it, but it's what I'm currently playing with.
The CSS idea occurred when I was looking at a month-view, and thought "It would be nice if all the events had a coloured background to distinguish them from other entries..."
--Mnjones 10:04, 14 October 2005 (UTC)Reply

Skipempty-Option

edit

This option must be implemented as

skipempty=TRUE

to enable its function. --213.168.102.97 17:00, 7 March 2006 (UTC)Reply

Help translate to Russian

edit

Please point to plase in PHP code for transtation

 function WeekdayShort($dow) {
   $a = array('Пн','Вт','Ср','Чт','Пт','Сб','Вс');
   return $a[$dow-1];
 }
 function WeekdayLong($dow) {
   $a = array('Понедельник','Вторник','Среда','Четверг','Пятница','Субота','Воскресение');
   return $a[$dow-1];
 }
 function MonthName($month) {
   $a = array("Январь", "Февраль", "Март", "Апрель", 
              "Май", "Июнь", "Июль", "Август", 
              "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
   return $a[$month-1];
 }

After i`m translate this in CalendarClass.php calendar did`t display short day names properly without translation the same situation, but ?? symbols instead &&

Implementing PhpWiki's calendar's functions

edit
  • switching months
  • separate calendar for every page (well, besides discussion-pages etc.)

In Calendar.php replace:

    $calstr = $cal->displayMonth();

with:

    if (!is_null($_GET["CalendarDisplayMonth"])) {
      $month = (int)substr((string)$_GET["CalendarDisplayMonth"], 4);
      $year = (int)substr((string)$_GET["CalendarDisplayMonth"], 0, 4);
    } else {
      $month = 0;
      $year = 0;
    }
    $calstr .= $cal->displayMonth($month,$year);

In CalendarClass.php add functions:

  function prevMonth($month,$year) {
    return $month == 1 ? ($year - 1) . 12 : $year . ($month - 1 < 10 ? 0 : '') . ($month - 1);
  }

  function nextMonth($month,$year) {
    return $month == 12 ? ($year + 1) . 0 . 1 : $year . ($month + 1 < 10 ? 0 : '') . ($month + 1);
  }

and replace in function displayMonth():

    $r = '';
    
    $dim = $this->DaysInMonth($month, $year);
    $dow = $this->DayOfWeek(1,$month,$year);

    $r .= '<tr><td colspan="7" align="center" valign="top" class="calendarHeader">';
    $r .= $this->MonthName($month);
    $r .= '</td></tr>';

with:

    $query = ereg_replace("(\?|(\&))action=submit", "", ereg_replace("(\?|(\&))CalendarDisplayMonth=[0-9]*", "", $_SERVER["REQUEST_URI"]));
    $linkStart = '['.(!is_null($_SERVER["HTTPS"]) ? 'https' : 'http').'://'.$_SERVER["SERVER_NAME"].$query.(strpos($query, '?') ? '&' : '?').'CalendarDisplayMonth=';
    $prevMonthLink = $linkStart.$this->prevMonth($month,$year).' <<] ';
    $nextMonthLink = ' '.$linkStart.$this->nextMonth($month,$year).' >>]';
    $monthHeader = $prevMonthLink.$this->MonthName($month).", ".$year.$nextMonthLink;
    
    $r = '';
    
    $dim = $this->DaysInMonth($month, $year);
    $dow = $this->DayOfWeek(1,$month,$year);

    $r .= '<tr><td colspan="7" align="center" valign="top" class="calendarHeader">';
    $r .= $monthHeader;
    $r .= '</td></tr>';

In WikiCalendarClass.php replace:

    if ($title and $title->getArticleID()==0) {
      return '[['.$text.'|'.$day.']]';
    } else {
      return "[[$text|$day]]"; //"'''[[$text|$day]]'''";
    }

with:

    return "[[{{PAGENAME}}/$text|$day]]";

PS. replaced if() is useless (and will probably be removed in the future) as both returns are totally equivalent.

Notes

edit
  • If you'd like to change years, weeks etc also, you'd have to modify code like I did for months.
  • Does anybody happen to know how to pass Mediawiki's page GET-arguments? I did it with external links, but I suspect it's possible with wiki-links also.

Atrox 07:58, 25 July 2006 (UTC)Reply

Problems

edit
  • I am using the default skin in MediaWiki and can not seem to get a border around the calendars in the threemonth view. Any assistance would be greatly appreciated.

Thanks in advance.

Hack to hide events from Special:Wantedpages

edit

(works on MW 1.6.8, untested on anything else)

It seems that creating a calendar can flood the Special:Wantedpages with links to the the event pages that don't yet exist. With multiple calendars, this can easily equate to hundreds of unwanted 'wanted' pages. The only way that I've found to avoid this is to modify the includes/SpecialWantedpages.php getSQL() function to exclude calendar events. There are two ways to go about this -

Method 1

edit

This is the easier, but less flexible option. It's fine if you only have/need one or two different calendars. It is possible though to accidentally hide more than just the calendar events pages, depending on how you've named them.

Find the section of includes/SpecialWantedpages.php that has:

           WHERE pg1.page_namespace IS NULL
           AND pg2.page_namespace != 8
           GROUP BY pl_namespace, pl_title

And change it to:

           WHERE pg1.page_namespace IS NULL
           AND pg2.page_namespace != 8
           AND NOT pl_title LIKE 'calendar_name%'
           GROUP BY pl_namespace, pl_title

--replace calendar_name with the name of the calendar you want to exclude. You can add more AND NOT pl_title LIKE 'calendar_name%' lines if you have multiple calendars with different names, but keep in mind that this may impact performace as the SQL query gets more complicated.
NB. for those new to SQL - the '%' sign is a w:Wildcard_character in SQL, equivilant of the more common '*'. This means that any article that starts with calendar_name will not be shown on the wanted page list.

Method 2

edit

In this method we use a custom namespace for all calendar events so that we can filter the links out based on namespace, which is a much nicer solution IMO.

Step 1 - Create a custom namespace for your calendars to live in. The rest of this section assumes that the custom namespace are numbered and named as shown:
100 => "Calendar"
101 => "Calendar_Talk"

Step 2 - In extensions/WikiCalendar/Calendar.php change

  if (!isset($p['format'])) {
    $p['format'] = '%name_%year_%month_%day'; 
  };

to

  if (!isset($p['format'])) {
    $p['format'] = 'Calendar:%name_%year_%month_%day';
  };

This will ensure that calendars use the newly created namespace by default.

Step 3 - Finally, find the section of includes/SpecialWantedpages.php that has:

           WHERE pg1.page_namespace IS NULL
           AND pg2.page_namespace != 8
           GROUP BY pl_namespace, pl_title

And change it to:

           WHERE pg1.page_namespace IS NULL
           AND pg2.page_namespace != 8
           AND pl_namespace != 100
           GROUP BY pl_namespace, pl_title

This will prevent anything in the namespace that we just created from showing up on Special:Wantedpages.

--OneSeven 03:12, 27 September 2006 (UTC)----Reply

Any way to preload templates?

edit

Is there any way to make the calendar pre-load a template when clicking on a date that doesn't have an entry? (IE, action=edit&preload=template) Please let me know!! HotMonkeyAC 16:49, 17 October 2006 (UTC)Reply

Template and year

edit

The above question is also for me.... a template for each date of year that isn't edit yet. Also like to know if you can name a year instead of -1 year or -2 year... when doing that now its richt that year 2006 is -1 but when it is 2008 that page wil be 2007... so is there a soloution or anser?

greets Tom (dvine2000@gmail.com)

Method for alternate weekviews

edit

There's probably a better solution, but I implemented the following changes to Calendar.php and to allow for "wholemonth" week view option.
Changes to Calendar.php

  switch ($p["view"]
  case "wholemonth":
    $dim = $cal->DaysInMonth($p['month'],$p['year']);
    $calstr = $cal->displayDays($dim);
    break;

--Zerobeat 01:13, 21 May 2007 (UTC)Reply

Doesn't this just determine the number of days in the month and then show that number of days in a week view? For example, if its October with 31 days, wouldn't this just show 31 days of events even if it was October 15, thus showing events from October 15 through November 15th? This can be done by setting: view=days days=31 I'm looking for something that will show me the days left in the month, so if its October 20 I could see October 20 through October 31. I'm thinking of subtracting $dim (days in month) from the date. I'm not a PHP coder so if anyone knows how to do this I'd appreciate it. 128.231.88.4 13:57, 21 October 2008 (UTC)Reply

Template:Extension cleanup

edit

As per your request (Cdamian) I tried to do some cleanup. However, some things require the source code and yours is compressed and not so easy to view on line.

For future reference:

  • In the rendered template, the label next to any parameter links to documentation on the parameter. Although it takes you directly to the line for that particular parameter, you can scroll up and down to see the rest of the documentation.
  • The template is dumb: to handle fields with multiple values, you have to do them in order: e.g. type/type1= |type2= |type3, .... Your value for type wasn't showing up because it was assigned to parameter type2 but type1 (alias type) was missing.
  • The type field stores "how I did it", not "why use this" (so we can put together coding examples to help other developers). The value set only covers MediaWiki specific techniques - for a discussion see Template_talk:Extension#Type taxonomy. I assigned it tag. I hope that was OK. Note: To capture its purpose (i.e. a calendar), use category (as you have done) Egfrank 06:44, 19 September 2007 (UTC)Reply
that was my request, thanks --Zven 07:08, 19 September 2007 (UTC)Reply

Next month's calendar

edit

Dose anyone have a reliable way way get the calendar for next month?

Using this works most of the time:

<calendar>
date="+1 month"
view=month
weekstart=7
formattitle=""
format="Current events/calendar/%j.%n.%Y"
</calendar>

but on August 31st I get the calendar for October, not September as I would expect. I am fairly sure it has something to do with Sep 31 not being a valid date (thus rolling over to Oct 1st??)

I need to figure out a way to ask for "+1 month from the 1st of the current month" or something, but I just can not seem to figure out how to accomplish that. Tildar 21:48, 31 August 2008 (UTC)Reply

Return to "Calendar (Cdamian)" page.