diff options
author | 2014-12-23 17:49:26 +0100 | |
---|---|---|
committer | 2014-12-23 17:49:26 +0100 | |
commit | e352fff59842ca14fbfd81ee1c4a64297bb598c5 (patch) | |
tree | 153f268484aa5cc41cacf912bdce8c4847df222d /LinkAttributes | |
download | extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.tar.gz extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.tar.bz2 extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.zip |
Add initial set of additional extensions
Diffstat (limited to 'LinkAttributes')
-rw-r--r-- | LinkAttributes/LinkAttributes.body.php | 64 | ||||
-rw-r--r-- | LinkAttributes/LinkAttributes.i18n.php | 18 | ||||
-rw-r--r-- | LinkAttributes/LinkAttributes.php | 22 | ||||
-rw-r--r-- | LinkAttributes/README.mediawiki | 43 |
4 files changed, 147 insertions, 0 deletions
diff --git a/LinkAttributes/LinkAttributes.body.php b/LinkAttributes/LinkAttributes.body.php new file mode 100644 index 00000000..8599ee56 --- /dev/null +++ b/LinkAttributes/LinkAttributes.body.php @@ -0,0 +1,64 @@ +<?php + +class LinkAttributes { + + private function attributeIsAllowed ( $str ) { + + if ( in_array( $str, array( 'rel', 'rev', 'charset ', 'type', 'hreflang', 'itemprop', 'media', 'title', 'accesskey', 'target', 'class' ) ) ) + return true; + else + return false; + + } + + private function doExtractAttributes ( &$text, &$attribs ) { + + global $wgRequest; + if ( $wgRequest->getText( 'action' ) == 'edit' ) { + return false; + } + + /* No user input */ + if ( null === $text ) + return false; + + /* Extract attributes, separated by | or ¦. /u is for unicode, to recognize the ¦.*/ + $arr = preg_split( '/[|¦]/u', $text ); + $text = array_shift( $arr ); + + foreach ( $arr as $a ) { + + $pair = explode( '=', $a ); + + /* Only go ahead if we have a aaa=bbb pattern, and aaa i an allowed attribute */ + if ( isset( $pair[1] ) && self::attributeIsAllowed( $pair[0] ) ) { + + /* Add to existing attribute, or create a new */ + if ( isset( $attribs[$pair[0]] ) ) { + $attribs[$pair[0]] = $attribs[$pair[0]] . ' ' . $pair[1]; + } else { + $attribs[$pair[0]] = $pair[1]; + } + } + + } + + return true; + + } + + public function ExternalLink ( &$url, &$text, &$link, &$attribs ) { + + self::doExtractAttributes ( $text, $attribs ); + return true; + } + + public function InternalLink ( $skin, $target, &$text, &$customAttribs, &$query, &$options, &$ret ) { + + self::doExtractAttributes ( $text, $customAttribs ); + return true; + + } + + +} diff --git a/LinkAttributes/LinkAttributes.i18n.php b/LinkAttributes/LinkAttributes.i18n.php new file mode 100644 index 00000000..196f7811 --- /dev/null +++ b/LinkAttributes/LinkAttributes.i18n.php @@ -0,0 +1,18 @@ +<?php +/** + * Internationalisation file for extension Link Attributes + * + * @file LinkAttributes.i18n.php + * @ingroup Extensions + */ + +$messages = array(); + + +/** Swedish (Svenska) + * @author Rotsee + */ +$messages['sv'] = array( + 'linkattr-desc' => 'Gör det möjligt att sätta vissa html-attribut på länkar.', +); + diff --git a/LinkAttributes/LinkAttributes.php b/LinkAttributes/LinkAttributes.php new file mode 100644 index 00000000..ce49ded4 --- /dev/null +++ b/LinkAttributes/LinkAttributes.php @@ -0,0 +1,22 @@ +<?php + +if ( !defined( 'MEDIAWIKI' ) ) { + die( 'This file is a MediaWiki extension, it is not a valid entry point' ); +} + +$wgExtensionCredits['parserhook'][] = array( + 'path' => __FILE__, + 'name' => 'LinksAttributes', + 'version' => '0.1', + 'url' => 'http://www.mediawiki.org/wiki/Extension:LinkAttributes', + 'author' => array( 'Leo Wallentin' ), + 'descriptionmsg' => 'linkattr-desc', +); + +$wgAutoloadClasses['LinkAttributes'] = dirname( __FILE__ ) . '/LinkAttributes.body.php'; +$wgExtensionMessagesFiles['ParserFunctions'] = dirname( __FILE__ ) . '/LinkAttributes.i18n.php'; + +global $wgHooks; +$wgHooks['LinkerMakeExternalLink'][] = 'LinkAttributes::ExternalLink'; +$wgHooks['LinkBegin'][] = 'LinkAttributes::InternalLink'; + diff --git a/LinkAttributes/README.mediawiki b/LinkAttributes/README.mediawiki new file mode 100644 index 00000000..ac719de1 --- /dev/null +++ b/LinkAttributes/README.mediawiki @@ -0,0 +1,43 @@ +A MediaWiki extension which extends the link syntax to allow custom attributes, such as rel="author". + +==Release == +[https://github.com/rotsee/LinkAttributes/tags 0.1] + +==Dependencies== +MediaWiki 1.19 + +==Installation== +Upload to your extensions folder, and add the following settings to LocalSettings.php: +require_once("$IP/extensions/LinkAttributes/LinkAttributes.php"); + +==Usage== +Extra attributes are added at the end of a link, separated with a pipe (|) or a broken pipe (¦), like this: + +[[User:James|my page|rel=author]] + +[http://twitter.com/leo_wallentin my Twitter account|rel=me] + +Allowed properties are: rel, rev, charset, type, hreflang and itemprop. + +In some places (such as inside templates with tables) the pipe can be hard to use, as it has special meanings to MediaWiki. Therefore a broken pipe (¦) will also work with this extension: [[Oranges|Oranges¦itemprop=fruit]]. +Note that the following will NOT work: [[User:James|rel=author]], as this extension has no way of knowing if rel=author is supposed to be an attribute or the actual text to be linked. The link would have to be written like this: [[User:James|James|rel=author]]. Also note that after installing this extension, pipes will not work in link texts. + + +==Changelog== +* 0.1 +** First version + +==Credits == +The extension was originally written for http://säsongsmat.nu. + +Leo Wallentin +leo_wallentin (at) hotmail.com +@leo_wallentin +http://xn--ssongsmat-v2a.nu + +== License == +BSD + +== Disclaimer == +The source code is provided as-is, without warranty and does not warrant or endorse and does not assume and will not have any liability or responsibility for any damage or loss. +__NOTOC__ |