Extension talk:Calendar (Cdamian)

From MediaWiki.org

Jump to: navigation, search

Contents

The following discussion has been transferred from meta.wikimedia.org.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).

[edit] email me

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

[edit] Things I'd like to see...

  • 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)
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)
(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)

[edit] Cache problem

Today's date is always in the past. Freshly edited events do not appear. How do I keep calendar pages from being cached by viewers?

In Calendar.php, moving the clearCache() call in renderCalendar to the end after the $wgParser->parse line, right before the return, seems to fix the cache problem. --Austin 21:59, 17 February 2006 (UTC)
this fix is also in the 1.7 version, thanks go to [OpenWetWare:User:Austin|Austin]]. --Cdamian 14:58, 1 March 2006 (UTC)


[edit] Kudos

Just wanted to say thanks - this is a great extension!

[edit] Skipempty-Option

This option must be implemented as

skipempty=TRUE

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

[edit] Bug when including >1 Calendar by template

  • There seems to be a bug, when you have two template pages with each one having a ("threemonths"-calendars). When both pages are included in a single page, only one calendar shows up - the other one is filled with a lenghty UNIQ30293.... - 84.132.129.8 18:00, 7 May 2006 (UTC)
    • I think there is a problem with templates and extensions in general --Cdamian 10:07, 17 May 2006 (UTC)
      • This is easily fixed, well this has done it OK for me. Edit Calendar.php and change:
        • thats in 1.12 now. --Cdamian 09:15, 29 September 2006 (UTC)

[edit] Help translate to Russian

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 &&

[edit] Implementing PhpWiki's calendar's functions

  • 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.

[edit] Notes

  • 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)

[edit] Alternatives

Are there any alternatives to your approach? -- JanCK 19:05, 29 July 2006 (UTC)

[edit] Problems

  • Does anyone have a problem with </dt> </dd> being displayed before and after the calendar today function?
    • I do, using 1.10.0 and the latest calendar version (1.13?), and then only after dates in the "This Week" section of the full calendar view (at least so far). It seems that the < and > are converted to symbols in those closing tags, causing the tag to show up literally rather than usefully. Not sure why. Anyone? The removal of closing td and dd tags didn't help...
    • I have the same problem on MW 1.10.0 / Calendar 1.13 --Zabwung 19:39, 20 August 2007 (UTC)
      • Oops! Solution already provided under Requests in main airticle page :-) --Zabwung 23:02, 24 August 2007 (UTC)
  • 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.

[edit] Merge

The merge functionallity is great, but for some reason I get the chars: '[[]]' at the start of any listing coming from a merged calendar if there are no events from the name = calendar also. This is running on MW 1.6.8 - does anyone else have this issue? Also, merge seems to have no effect whatsoever in the month view. --OneSeven 08:36, 23 September 2006 (UTC)

Fixed!..
The problem described above can be fixed by editing the WikiCalendarClass.php file. In the function displayWeekday(), insert the line:

$r = str_replace( "{{:}}<br/>", "", $r );

just before the return $r; statement. --OneSeven 04:31, 28 September 2006 (UTC)

Great timing, glad someone's been working on this -- as I just started to wrestle with it today -- but your fix didn't work for me?? Ideas? what version of MW are you on? --Fizik aka Chris E 21:26, 28 September 2006 (UTC)

  • that is fixed in 1.12 now (though with a different solution) --Cdamian

[edit] Hack to hide events from Special:Wantedpages

(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 -

[edit] Method 1

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.

[edit] Method 2

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)----

[edit] Parser failure

I tried to install the extension with 1.7 I got all kinds of parser errors when trying to use your example calendar

version 1.13 now has a fix for one problem with mediawiki 1.7, please try that version --Cdamian 21:29, 9 October 2006 (UTC)

That seems to work, thanks. In week mode, how do you make it so that the dates aren't linked? --68.18.108.243 22:59, 10 October 2006 (UTC)

Never mind, I figured it out, just had to edit a php file. --68.18.108.243 00:48, 12 October 2006 (UTC)

[edit] Any way to preload templates?

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)

[edit] Template and year

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)

[edit] Method for alternate weekviews

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)

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)

[edit] Template:Extension cleanup

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)
that was my request, thanks --Zven 07:08, 19 September 2007 (UTC)

[edit] Beta or Stable?

In the Extension Matrix this Calendar is listed as "Beta". I've been using it for months (on a private wiki, sorry) and it's performed perfectly. Can we change this to "Stable"? --Gadlen 23:16, 21 January 2008 (UTC)

[edit] Next month's calendar

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)

Personal tools