├── README.md ├── raw.php ├── AllowAnchorTags.php ├── RelWebmention.php ├── LassoAuth.php └── Calendar.php /README.md: -------------------------------------------------------------------------------- 1 | IndieWeb Wiki Extensions 2 | ======================== 3 | 4 | These are some simple extensions in use on https://indieweb.org that seemed too small to put in their own repositories. 5 | -------------------------------------------------------------------------------- /raw.php: -------------------------------------------------------------------------------- 1 | 'Raw HTML', 5 | 'author' => 'Aaron Parecki', 6 | 'version' => '0.1', 7 | 'description' => 'Adds tag to include arbitrary html', 8 | 'url' => 'https://github.com/indieweb/mediawiki-extensions' 9 | ); 10 | 11 | $wgHooks['ParserFirstCallInit'][] = function( Parser &$parser ) { 12 | $parser->setHook("raw", function($input, $args) { 13 | return $input; 14 | }); 15 | return true; 16 | }; 17 | -------------------------------------------------------------------------------- /AllowAnchorTags.php: -------------------------------------------------------------------------------- 1 | anchor tags into wikitext 4 | */ 5 | 6 | // Extension credits that will show up on Special:Version 7 | $wgExtensionCredits['parserhook'][] = array( 8 | 'name' => 'AllowAnchorTags', 9 | 'version' => '0.1', 10 | 'author' => 'Aaron Parecki', 11 | 'url' => 'https://github.com/indieweb/mediawiki-extensions', 12 | 'description' => 'Allows inserting anchor tags into wikitext', 13 | ); 14 | 15 | $wgHooks['ParserFirstCallInit'][] = function(Parser &$parser) { 16 | $parser->setHook('a', function($text, array $args, Parser $parser, PPFrame $frame) { 17 | $text = $parser->recursiveTagParse($text, $frame); 18 | $href = $parser->recursivePreProcess($args['href'], $frame); 19 | 20 | $output = Linker::makeExternalLink( $href, $text, false, '', $args ); 21 | unset( $args['href'] ); 22 | 23 | return $output; 24 | }); 25 | return true; 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /RelWebmention.php: -------------------------------------------------------------------------------- 1 | 'RelWebmention', 4 | 'author' => 'Aaron Parecki', 5 | 'description' => 'Adds tag to advertise a Webmention endpoint on every page', 6 | 'url' => 'https://github.com/indieweb/mediawiki-extensions' 7 | ); 8 | 9 | $wgHooks['OutputPageBeforeHTML'][] = function(OutputPage &$out, &$text) { 10 | global $wgWebmentionEndpoint, $wgPingbackEndpoint; 11 | 12 | $out->addHeadItem('webmention', ''."\n"); 13 | $out->addHeadItem('pingback', ''."\n"); 14 | 15 | if($_SERVER['REQUEST_URI'] == '/Special:RecentChanges') { 16 | $out->addHeadItem('websub', ''."\n".''); 17 | } 18 | 19 | $ga = << 21 | EOF; 22 | $out->addHeadItem('googleanalytics', $ga); 23 | 24 | return true; 25 | }; 26 | -------------------------------------------------------------------------------- /LassoAuth.php: -------------------------------------------------------------------------------- 1 | '', # remove http prefix 14 | '/\/$/' => '', # remove trailing slash 15 | '/' => ' ', # convert other slashes to spaces 16 | ]; 17 | 18 | 19 | #$wgAuthRemoteuserUserNameBlacklistFilter = [ 20 | $iwBlockedDomains = [ 21 | '/commentpara\.de/', 22 | '/github\.io/', 23 | '/wordpress\.com/', 24 | '/blogspot\.com/', 25 | '/livejournal\.com/', 26 | '/indiewebcamp\.com/', 27 | '/indieweb\.org/', 28 | '/herokuapp\.com/', 29 | '/jsbin\.com/', 30 | ]; 31 | 32 | // Recreated this hook from the Auth_Remoteuser extension in order to add a custom error message 33 | $wgHooks['AuthRemoteuserFilterUserName'][] = function ( &$username ) use ( $iwBlockedDomains ) { 34 | foreach ( $iwBlockedDomains as $pattern ) { 35 | # If $pattern is no regex, create one from it. 36 | if ( @preg_match( $pattern, null ) === false ) { 37 | $pattern = str_replace( '\\', '\\\\', $pattern ); 38 | $pattern = str_replace( '/', '\\/', $pattern ); 39 | $pattern = "/$pattern/"; 40 | } 41 | if ( preg_match( $pattern, $username ) ) { 42 | return "This domain name is not allowed as a wiki username. See blocked subdomains for more info.

Try Again "; 43 | } 44 | } 45 | }; 46 | 47 | 48 | $wgAuthRemoteuserUserUrls = [ 49 | 'logout' => function($metadata) { 50 | return LassoAuth::$auth.'logout?url='.urlencode(LassoAuth::$wiki); 51 | } 52 | ]; 53 | $wgHooks['PersonalUrls'][] = function( array &$personal_urls, Title $title, SkinTemplate $skin ) { 54 | if(isset($personal_urls['login'])) { 55 | if(preg_match('/returnto=([^&]+)/', $personal_urls['login']['href'], $match)) { 56 | $page = str_replace('+','_',$match[1]); 57 | } else { 58 | $page = ''; 59 | } 60 | $personal_urls['login']['href'] = LassoAuth::$auth.'login?url='.urlencode(LassoAuth::$wiki.$page); 61 | } 62 | if(isset($personal_urls['logout'])) { 63 | $personal_urls['logout']['text'] = 'Log Out'; 64 | } 65 | return true; 66 | }; 67 | 68 | -------------------------------------------------------------------------------- /Calendar.php: -------------------------------------------------------------------------------- 1 | 'Calendar', 5 | 'author' => 'Aaron Parecki', 6 | 'description' => 'Adds tag for creation of a single month calendar', 7 | 'url' => 'https://github.com/indieweb/mediawiki-extensions' 8 | ); 9 | 10 | $wgHooks['ParserFirstCallInit'][] = function(Parser &$parser) { 11 | $parser->setHook("calendar", function($input, $config) { 12 | $lines = explode("\n", $input); 13 | 14 | $month = isset($config['month']) ? $config['month'] : date('m'); 15 | $year = isset($config['year']) ? $config['year'] : date('Y'); 16 | 17 | $mwCalendar = new mwMonthCalendar($month, $year); 18 | 19 | foreach( $config as $key=>$val ) 20 | { 21 | $mwCalendar->setConfig($key, $val); 22 | } 23 | 24 | foreach($lines as $line) 25 | { 26 | if( trim($line) != '' ) 27 | { 28 | $eventDay = substr($line,0,strpos($line,' ')); 29 | $eventText = substr($line,strpos($line,' ')+1); 30 | $mwCalendar->addEvent($eventDay, $eventText); 31 | } 32 | } 33 | 34 | return $mwCalendar->show(); 35 | }); 36 | return true; 37 | }; 38 | 39 | 40 | class mwMonthCalendar 41 | { 42 | private $year; 43 | private $month; 44 | private $timestamp; 45 | private $config; 46 | private $events; 47 | 48 | function __construct($month, $year) 49 | { 50 | $this->year = $year; 51 | $this->month = $month; 52 | $this->timestamp = mktime(0,0,0,$month,1,$year); 53 | $this->config['tableWidth'] = '100%'; 54 | $this->config['showHeader'] = 1; 55 | $this->config['cellHeight'] = 90; 56 | $this->config['weekStart'] = 'Monday'; 57 | $this->config['highlightToday'] = 1; 58 | } 59 | 60 | function addEvent($eventDate, $eventText) 61 | { 62 | $this->events[$eventDate] = $eventText; 63 | } 64 | 65 | function setConfig($key, $val) 66 | { 67 | $this->config[$key] = $val; 68 | } 69 | 70 | function show() 71 | { 72 | global $wgOut, $wgParser, $wgLocalTZoffset; 73 | 74 | $s = ($this->config['weekStart'] == 'Monday' ? 1 : 0); 75 | $o = ''; 76 | 77 | ob_start(); 78 | ?> 79 | 89 | addInlineStyle($css); 93 | 94 | $o .= $css; 95 | $o .= '
'; 96 | $o .= ''; 97 | if( $this->config['showHeader'] ) { $o .= ''; } 98 | $o .= ''; 99 | for( $i=0; $i<7; $i++ ) 100 | { 101 | $o .= ''; 102 | } 103 | $o .= ''; 104 | 105 | $firstDayOfWeek = strftime('%u', $this->timestamp); 106 | 107 | $lastDayOfWeek = strftime(($s==1?'%u':'%w'),mktime(0,0,0,$this->month,date('t',$this->timestamp),$this->year)); 108 | if( $firstDayOfWeek > $s ) 109 | { 110 | $o .= ''; 111 | for( $i=$s; $i<$firstDayOfWeek; $i++ ) 112 | { 113 | $o .= ''; 114 | } 115 | } 116 | for( $i=1; $i<=date('t',$this->timestamp); $i++ ) 117 | { 118 | $thisDay = mktime(0,0,0,$this->month,$i,$this->year); 119 | if( strftime('%w',$thisDay) == $s ) 120 | { 121 | $o .= ''; 122 | } 123 | 124 | $o .= ''; 131 | 132 | if( strftime(($s==1?'%u':'%w'),$thisDay) == ($s==1?7:6) ) 133 | { 134 | $o .= ''; 135 | } 136 | } 137 | if( $lastDayOfWeek < ($s==1?7:6) ) 138 | { 139 | for( $i=$lastDayOfWeek; $i<($s==1?7:6); $i++ ) 140 | { 141 | $o .= ''; 142 | } 143 | $o .= ''; 144 | } 145 | 146 | $o .= '

'.strftime('%B %Y', $this->timestamp).'

'.strftime('%A',strtotime(sprintf(($s==1?'2007-10':'2008-06').'-%02d',$i+1))).'
 
'; 128 | $o .= '
'.$i.'
'; 129 | $o .= '

'.(array_key_exists($i,$this->events)?$wgParser->recursiveTagParse($this->events[$i]):' ').'

'; 130 | $o .= '
 
'; 147 | $o .= '
'; 148 | return $o; 149 | } 150 | 151 | } 152 | 153 | ?> 154 | --------------------------------------------------------------------------------