Extension:Document UNCified
From MediaWiki.org
Check usage(experimental)
|
Document_UNCified Release status: beta |
|||
|---|---|---|---|
| Implementation | Tag | ||
| Description | Use one just tag for link any document's type on your article using UNC o URI format. Very useful for Wikis on LAN arquitecture. | ||
| Author(s) | Secundino Garcia Jmz (secundinogarciaTalk) | ||
| Last version | 0.1 | ||
| MediaWiki | 1.15.1 -> 1.16.5 | ||
| PHP | 5.2.14 -> 5.3.6 | ||
| License | GPL | ||
| Download | See http://www.mediawiki.org/w/index.php/Extension:Document_UNCified#Code | ||
|
|||
|
tested on Mediawiki
|
|||
Contents |
[edit] What can this extension do?
This extension has this purposes:
-
- Allow URI linking to files that are uploaded into your wiki
- Allow UNC linking to files stored on your intranet "\\servername\path\filename.ext"
The link can be for documents of type:
-
- image
- simple link
- as embeded documents
The very useful if your wiki is housed internally and used for as an intranet for your company.
[edit] Usage
[edit] Syntax
This extension get us a new tag, with it,we can insert links (on URI or UNC format) to documents not incorporated at your wiki. <document_unc></document_unc>
Syntax:
<document_unc
width=['100%'|'300px']
heigth=['20%'|'300px']
type=['embeded'|'image'|'link']
link='unc|uri'
margin='units'
>
[unc|uri]|label]
</document_unc>
Where:
-
- width : It's the width for the object into the page, use pixels or percent units.
- height : It's the height for the object into the page, use pixels or percent units.
- type : It's the way for interpreting you URI, you have three choices:
-
- link: Default, the tag it's intepreted like simple link. Its can use in combitation with label.
- image: The tag it's intepreted like an URI to an image whose default link is to itself (if you not especify link). Its can use in combitation with label and link.
- embeded: The tag it's intepreted like an URI to a document embeded. It works with PDF files!.
- link : With this, you can specify an alternate URI at witch the navegator it go when press click over the image. Obviously only functions in combination with type='image'.
- margin: With this, you can specify an margin to apply at the object to be incrusted, the margin to be added it's vía styles (CSS); from here that the format for units it's the same that supports the tag margin from CSS. Into the string value don't specify ';'.
On tag value exists two options:
-
- uri or unc : Its about the path at your resource. You can specify the format UNC(\\server\ruta\file.ext) o URI (/ruta/file.ext)
- label : Its the text to be displayed... this operates of any of the following forms:
-
- Like Alternative tag (ALT="") when it is used in combinaciòn with type='image'
- Like Link-text when it is used in combinaciòn with type='link'
[edit] Like image
-
- Sintax 1:
-
- <document_unc width="100px" type="link">{{SERVER}}\wiki\docs\example.jpg|Mi example image<document_unc>
-
- On this case you get a image with three properties:
-
- width: 100px
- A caption: Mi example image
- A URI destination on click: A new page with just the full image.
-
- Sintax 2:
-
- <document_unc width="100px" type="link" link="http://www.mediawiki.org">{{SERVER}}\wiki\docs\example.jpg|Mi example image<document_unc>
-
- On this case you get a image with three properties:
-
- width: 100px
- A caption: Mi example image
- A URI destination on click: The MediaWiki.org principal page. It's very important put http:// otherwise the URI will be interpreted like relative on your site.
[edit] Download instructions
Please cut and paste the code found below and place it in $IP/extensions/ExtensionName/ExtensionName.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.
[edit] Installation
To install this extension, add the following to LocalSettings.php:
#add configuration parameters here require_once("$IP/extensions/DocumentUNCified/document_uncified.php");
[edit] Code
<?php /** * MediaWiki. This code is released under the GNU General Public License. * * @author Secundino Garcia Jimenez <secundinogarcia@yahoo.com.mx> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @package MediaWikiExtensions * @version 0.3 */ if( !defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } $wgHooks['ParserFirstCallInit'][] = 'DocumentUNCfied_Setup'; function DocumentUNCfied_Setup( &$parser ) { $parser->setHook( 'document_unc', 'DocumentUNCfied_Render' ); return true; } function DocumentUNCfied_Render( $input, $args, $parser, $frame ) { /* The following lines can be used to get the variable values directly: $to = $args['to'] ; $email = $args['email'] ; */ //---------------[ Initialization ]------------------------------------------ $ah = "center"; $type = "link"; $link = ""; $linktext = "[1]"; $margin = "0"; foreach( $args as $name => $value ) { if ($name == 'width') $w = $value; if ($name == 'height') $h = $value; if ($name == 'type') $type =$value; if ($name == 'link') $link =$value; if ($name == 'margin') $margin =$value; } if (strpos( $margin, ";") > 0){ $margin = substr( $margin, 0, strpos( $margin, ";") ); } //---------------[ exploding ]------------------------------------------ $exploded = explode('|', $input); if (!(!isset($exploded[0]) || empty($exploded[0]))) { $uri = htmlentities($exploded[0], ENT_QUOTES, "UTF-8"); $uri_old = $uri; $uri = getMagic( $parser, $uri, $uri_old, $type ); } if (!(!isset($link) || empty($link))) { $link = htmlentities($link, ENT_QUOTES, "UTF-8"); $link_old = $link; $link = getMagic( $parser, $link, $link_old, $type ); } //---------------[ getting the path ]------------------------------------------ $result = ""; if ($type == 'link'){ $result = getInstructionForLink($w, $h, $type, $link, $margin, $uri, $exploded, $parser); } if ($type == 'embeded') { $result = getInstructionForEmbed($w, $h, $type, $link, $margin, $uri, $exploded, $parser); } if ($type == 'image') { $result = getInstructionForImage($w, $h, $type, $link, $margin, $uri, $exploded, $parser); } //---------------[ returning results ]------------------------------------------ return $result; //return $w . "|" . $h . "|" . $type . "|" . $margin . "|" . $link . "|" . $uri; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function getMagic( $parser, $uri, $uri_old, $type ) { $result = $uri; if (preg_match_all("/(\{){2}(.*)(\}){2}/", $uri, $matchfounded)) { foreach ($matchfounded[0] as $match) { $matched = $parser->recursiveTagParse( $match ); $matched = preg_replace("/((<)(.*)(rel=\"nofollow\">))|(<\/a>)/", "", $matched); $regexp_match = preg_replace("/\{/", "\{", $match); $regexp_match = preg_replace("/\}/", "\}", $regexp_match); $result = preg_replace( "/" . $regexp_match . "/", $matched, $uri); } } //Deleting bad commands.... if (preg_match_all("/(?i:on(blur|c(hange|lick)|dblclick|focus|keypress|(key|mouse)(down|up)|(un)?load|mouse(move|o(ut|ver))|reset|s(elect|ubmit)))|(?i:((<|<)[\/]?script(>|>)))/", $result, $matchfounded)){ $result = "[ Here was detected & eliminated a possible hijack attack instruction ]"; } else { $result = getNewURI($result, $uri_old, $type); } return $result; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function getNewURI($uri, $uri_old, $type){ $result = $uri; if (strpos($uri, "/") === false) { $uri = str_replace(" ", "%20", $uri); $uri = str_replace("\\", "/", $uri); if ( $type == 'link'){ if (strpos($uri_old, "{{") === false) { $uri = "file:///" . $uri; } else { $uri = "file:////" . $uri; } } if ( $type == 'embeded'){ if (strpos($uri_old, "{{") === false) { $uri = "file:///" . $uri; } else { $uri = "file:////" . $uri; } } if ( $type == 'image'){ if (strpos($uri_old, "{{") === false) { $uri = "file:///" . $uri; } else { $uri = "file:////" . $uri; } } } return $uri; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function getInstructionForLink($w, $h, $type, $link, $margin, $uri, $exploded, $parser){ $result = ""; if ( !isset($link) || empty($link) ){ if ( !isset($exploded[0]) || empty($exploded[0]) ){ return $result; } if ( !isset($exploded[1]) || empty($exploded[1]) ){ $linktext = $uri; } else { $linktext = htmlentities($exploded[1], ENT_QUOTES, "UTF-8"); } $link = $uri; } else { if ( !isset($exploded[0]) || empty($exploded[0]) ){ $uri = $link; $linktext = $link; } else { if ( !isset($exploded[1]) || empty($exploded[1]) ){ $linktext = htmlentities($exploded[0], ENT_QUOTES, "UTF-8"); $uri = $link; } else { $linktext = htmlentities($exploded[1], ENT_QUOTES, "UTF-8"); } } } $result = "<a href=\"" . $uri . "\" class=\"external autonumber\" style=\"margin:" . $margin . ";\" rel=\"nofollow\" title=\"" . $uri . "\" target=\"_blank\">" . $linktext . "</a>"; return $result; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function getInstructionForEmbed($w, $h, $type, $link, $margin, $uri, $exploded, $parser){ $result = ""; if (!isset($w) || empty($w)) { $w = '100%'; } if (!isset($h) || empty($h)) { $h = '560px'; } if ( !isset($link) || empty($link) ){ if ( !isset($exploded[0]) || empty($exploded[0]) ){ return $result; } $link = $uri; } else { if ( !isset($exploded[0]) || empty($exploded[0]) ){ $uri = htmlentities($link, ENT_QUOTES, "UTF-8"); } } $result = "<div style=\"width:" . $w . "; height:" . $h . ";margin:" . $margin . ";\"><iframe style=\"background-color:none; padding: 0; margin: " . $margin . ";\" width=" . $w . " height=" . $h . " src=\"" . $uri . "\" frameborder=0 framebordercolor=#00000></iframe></div>"; return $result; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ function getInstructionForImage($w, $h, $type, $link, $margin, $uri, $exploded, $parser){ $result = ""; if (!isset($w) || empty($w)) { $w = 'auto'; } if (!isset($h) || empty($h)) { } if ( !isset($link) || empty($link) ){ if ( !isset($exploded[0]) || empty($exploded[0]) ){ return $result; } $link = $uri; if ( !isset($exploded[1]) || empty($exploded[1]) ){ $linktext = $uri; } } else { $linktext = $link; if ( !isset($exploded[0]) || empty($exploded[0]) ){ $uri = $link; } } $result = "<a href=\"" . $link . "\" title=\"" . $linktext . "\" target=\"_blank\"><img src=\"" . $uri . "\" alt=\"" . $linktext . "\" width=\"" . $w . "\" height=\"" . $h . "\" style=\"margin:" . $margin . "\";/></a>"; // return $result; } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ $wgExtensionCredits['parserhook'][] = array( 'name' => 'DocumentUNCified', 'author' => '[[User:CQ|Secundino Garcia Jimenez]]', 'description' => 'Embed documents PDF, Sounds and images in your pages, link another documents on easy way; use URL or UNC format for path!.', 'url' => 'http://www.mediawiki.org/wiki/Extension:Document_UNCified'); ?>
