1. 新建文件 extensions/googleCalendar.php
<?php # Google Calendars # # Tag : # <googlecalendar>calendar id</googlecalendar> # Ex : # from url http://www.google.com/calendar/embed?src=lvrhikf5hj035b7thmmaucvs7c%40group.calendar.google.com&ctz=Asia/Shanghai # <googlecalendar>lvrhikf5hj035b7thmmaucvs7c@group.calendar.google.com</googlecalendar> # # Enjoy ! $wgExtensionFunctions[] = 'wfGoogleCalendar'; $wgExtensionCredits['parserhook'][] = array ( 'name' => 'Google Calendar', 'description' => 'Display Google Calendar', 'author' => 'Kasper Souren', 'url' => 'http://wiki.couchsurfing.com/en/Google_Calendar_MediaWiki_plugin' ); function wfGoogleCalendar() { global $wgParser; $wgParser->setHook('googlecalendar', 'renderGoogleCalendar'); } # The callback function for converting the input text to HTML output function renderGoogleCalendar($input) { $input = htmlspecialchars($input); $output = '<iframe src="http://www.google.com/calendar/embed?src='.$input.'&ctz=Asia/Shanghai" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>'; return $output; } ?>
2. 修改LocalSettings.php
在这个文件的最后加入一行
require_once('extensions/googleCalendar.php');
3. 在MediaWiki中添加Google Calendar
<googlecalendar>lvrhikf5hj035b7thmmaucvs7c@group.calendar.google.com</googlecalendar>
4. 说明
从代码中可以看到,实现的功能实际上就是把一个输入转换成所需要的HTML代码输出,
不仅仅是对Google Calendar,对其他要在MediaWiki中添加复杂HTML代码的情况同样适用
以上路径都是相对于MediaWiki主目录,方法来自这里











