Introduce property: and itemprop: support for addMeta to add RDFa <meta property...
authorDaniel Friesen <dantman@users.mediawiki.org>
Tue, 14 Feb 2012 02:22:02 +0000 (02:22 +0000)
committerDaniel Friesen <dantman@users.mediawiki.org>
Tue, 14 Feb 2012 02:22:02 +0000 (02:22 +0000)
This is done in a way that can also be feature tested, and technically could be expanded by extensions.

includes/OutputPage.php

index ae55d3f..b0a8784 100644 (file)
@@ -231,6 +231,15 @@ class OutputPage extends ContextSource {
         */
        private $mRedirectedFrom = null;
 
+       /**
+        * Name prefixes that can be used in addMeta
+        */
+       public static $metaAttrPrefixes = array(
+               'http' => 'http-equiv',
+               'itemprop' => 'itemprop',
+               'property' => 'property',
+       );
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
@@ -278,6 +287,12 @@ class OutputPage extends ContextSource {
        /**
         * Add a new <meta> tag
         * To add an http-equiv meta tag, precede the name with "http:"
+        * To add a Microdata itemprop meta tag, precede the name with "itemprop:"
+        * To add a RDFa property meta tag, precede the name with "property:"
+        *
+        * itemprop: and property: were introduced in 1.20, you can feature
+        * test for them by checking for the key in the new
+        * OutputPage::$metaAttrPrefixes variable.
         *
         * @param $name String tag name
         * @param $val String tag value
@@ -2995,11 +3010,16 @@ $templates
                }
 
                foreach ( $this->mMetatags as $tag ) {
-                       if ( 0 == strcasecmp( 'http:', substr( $tag[0], 0, 5 ) ) ) {
-                               $a = 'http-equiv';
-                               $tag[0] = substr( $tag[0], 5 );
-                       } else {
-                               $a = 'name';
+                       $a = 'name'; // default attribute
+                       foreach ( self::$metaAttrPrefixes as $prefix => $attribute ) {
+                               // Check if the name starts with the prefix
+                               if ( strpos( $tag[0], "$prefix:" ) === 0 ) {
+                                       // Set the attribute name we're using
+                                       $a = $attribute;
+                                       // Strip the prefix from the name
+                                       $tag[0] = substr( $tag[0], strlen( $prefix ) + 1 );
+                                       break;
+                               }
                        }
                        $tags[] = Html::element( 'meta',
                                array(