├── SemanticHTML.i18n.php
├── README
├── SemanticHTML.php
└── SemanticHTML.class.php
/SemanticHTML.i18n.php:
--------------------------------------------------------------------------------
1 | 'Enables use of HTML4 phrase elements in MediaWiki'
16 | );
17 |
18 | ?>
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | MediaWiki Extension — SemanticHTML
2 |
3 | SemanticHTML is a simple MediaWiki extension to add support for HTML4 phrase elements
4 | plus the HTML5 time element to MediaWiki. By default, MediaWiki strips out these
5 | descriptive elements.
6 |
7 | This extension adds support for:
8 |
9 | * abbr
10 | * acronym
11 | * data
12 | * dfn
13 | * kbd
14 | * samp
15 | * time
16 | * var
17 |
18 | Originally written for microformats.org/wiki, by Ben Ward
19 |
20 | * http://microformats.org/wiki/
21 | * http://ben-ward.co.uk
22 |
23 | To Do:
24 | * support for object and/or video elements to enable embedding of videos -tç
25 |
--------------------------------------------------------------------------------
/SemanticHTML.php:
--------------------------------------------------------------------------------
1 | 'Semantic HTML',
22 | 'svn-date' => '$LastChangedDate: 2008-07-06 16:49:00 +0100 (Sun, 6 July 2008) $',
23 | 'svn-revision' => '$LastChangedRevision: $',
24 | 'author' => array( 'Ben Ward' ),
25 | 'description' => 'Enables use of HTML4 phrase elements in MediaWiki',
26 | 'descriptionmsg' => 'semantichtml-desc',
27 | 'url' => 'http://www.mediawiki.org/wiki/Extension:SemanticHTML',
28 | );
29 |
30 | $dir = dirname(__FILE__) . '/';
31 | $wgExtensionMessagesFiles['SemanticHTML'] = $dir . 'SemanticHTML.i18n.php';
32 | $wgAutoloadClasses['SemanticHTMLParser'] = $dir . 'SemanticHTML.class.php';
33 | $wgHooks['ParserFirstCallInit'][] = 'initSemanticHTML';
34 |
35 | /**
36 | * Register parser hook
37 | */
38 | function initSemanticHTML() {
39 | require_once('SemanticHTML.class.php');
40 | SemanticHTMLParser::registerHooks();
41 | return true;
42 | }
43 |
44 | ?>
--------------------------------------------------------------------------------
/SemanticHTML.class.php:
--------------------------------------------------------------------------------
1 | 'abbr',
21 | 'parseAcronym' => 'acronym',
22 | 'parseData' => 'data',
23 | 'parseDfn' => 'dfn',
24 | 'parseKbd' => 'kbd',
25 | 'parseSamp' => 'samp',
26 | 'parseTime' => 'time',
27 | 'parseVar' => 'var',
28 | );
29 |
30 | // __callStatic isn't implemented until 5.3, so need explicit methods:
31 | public static function parseAbbr($text, $attributes, $parser) {
32 | return SemanticHTMLParser::parseElement('abbr', $text, $attributes, $parser);
33 | }
34 | public static function parseAcronym($text, $attributes, $parser) {
35 | return SemanticHTMLParser::parseElement('acronym', $text, $attributes, $parser);
36 | }
37 | public static function parseData($text, $attributes, $parser) {
38 | return SemanticHTMLParser::parseElement('data', $text, $attributes, $parser);
39 | }
40 | public static function parseDfn($text, $attributes, $parser) {
41 | return SemanticHTMLParser::parseElement('dfn', $text, $attributes, $parser);
42 | }
43 | public static function parseKbd($text, $attributes, $parser) {
44 | return SemanticHTMLParser::parseElement('kbd', $text, $attributes, $parser);
45 | }
46 | public static function parseSamp($text, $attributes, $parser) {
47 | return SemanticHTMLParser::parseElement('samp', $text, $attributes, $parser);
48 | }
49 | public static function parseTime($text, $attributes, $parser) {
50 | return SemanticHTMLParser::parseElement('time', $text, $attributes, $parser);
51 | }
52 | public static function parseVar($text, $attributes, $parser) {
53 | return SemanticHTMLParser::parseElement('var', $text, $attributes, $parser);
54 | }
55 |
56 | private static function parseElement($element, $text, $attributes, $parser) {
57 | $return = "<$element";
58 | if(is_array($attributes)) {
59 | foreach($attributes as $name=>$value) {
60 | $return .= " $name=\"$value\"";
61 | }
62 | }
63 | $text = $parser->recursiveTagParse( $text );
64 | $return .= ">$text$element>";
65 | return $return;
66 | }
67 |
68 | public static function registerHooks() {
69 | global $wgParser;
70 | foreach(SemanticHTMLParser::$elements as $method=>$tag) {
71 | $wgParser->setHook($tag, array('SemanticHTMLParser', $method));
72 | }
73 | }
74 | }
75 | ?>
--------------------------------------------------------------------------------