Difference between revisions of "File Link Extension"

From assela Pathirana
Jump to navigationJump to search
m (Text replace - '<pre>' to ' <pre>')
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Image:DSC_0194.JPG|Thumb|200px|right]]
{{hbox|There had been some requests to make the extension work for "preview" mode also. This can be done [[#To_make_buttons_appear_in_.27preview.27_mode|easily]].}}
==Context and Purpose==
==Context and Purpose==
When mediawiki is used as an [[Mediawiki as an internal collborating platform|internal collaborating platform ]] or a [[PIM|Personal Information Management]] tool, its access is mostly limited to a single computer or a single subnet (shared network environment). In such situations, it is sometimes useful to have the "file://" protocol enabled, so that links to files that can be normally accessed can be made in the documents. Mediawiki FAQ explains [[metawikipedia:MediaWiki_FAQ#Is_it_somehow_possible_to_use_a_.22file.22_URI-qualifier_for_local_intranets_e.g._.5Bfile:.2F.2Flocalhost.2FC:_C-Drive.5D.3F how to do this]]. (Needs to enable the functionality in Mediawiki AND all the client browsers. Once both those change sare made, it is possible to make links like
When mediawiki is used as an [[Mediawiki as an internal collborating platform|internal collaborating platform ]] or a [[PIM|Personal Information Management]] tool, its access is mostly limited to a single computer or a single subnet (shared network environment). In such situations, it is sometimes useful to have the "file://" protocol enabled, so that links to files that can be normally accessed can be made in the documents. Mediawiki FAQ explains [[metawikipedia:MediaWiki_FAQ#Is_it_somehow_possible_to_use_a_.22file.22_URI-qualifier_for_local_intranets_e.g._.5Bfile:.2F.2Flocalhost.2FC:_C-Drive.5D.3F |how to do this]]. (Needs to enable the functionality in Mediawiki AND all the client browsers. Once both those change sare made, it is possible to make links like
{{subs:pns|[[file://data6/manual.pdf]]}} in wikitext and clicking on them will open (or download) the respective link.  
<nowiki>
</nowiki>
<pre><nowiki>[[file://data6/manual.pdf]]</nowiki></pre> in wikitext and clicking on them will open (or download) the respective link.  


On of the issues in this approach  is that the users need to make the {{subs:pns|file://}} link themselves. This can sometimes be an tedious and error-prone process (particularly in windows environment). This extensions adds a editor toolbar button which will trigger a file open dialog so that the user can simply select the file to be linked. The extension places the correctly formatted file:// protocol link in the current position of the edit box.  
On of the issues in this approach  is that the users need to make the <nowiki>
</nowiki>
<pre><nowiki>file://</nowiki></pre> link themselves. This can sometimes be an tedious and error-prone process (particularly in windows environment). This extensions adds a editor toolbar button which will trigger a file open dialog so that the user can simply select the file to be linked. The extension places the correctly formatted file:// protocol link in the current position of the edit box.


==Warning==
==Warning==
Line 9: Line 15:


==How to use==
==How to use==
* Download the source code: [[Image:FileLinkExtension.tar.gz]]
* Download the source code: [[:Image:FileLinkExtension.0.2.tar.gz|FileLinkExtension.0.2.tar.gz]]. ([[:Image:FileLinkExtension.tar.gz|FileLinkExtension.tar.gz]] is no longer valid.)
* Expand it at the mediawiki extensions folder
* Expand it at the mediawiki extensions folder
* Add the following to the LocalSettings.php <nowiki>
* Add the following to the LocalSettings.php  
</nowiki><pre><nowiki>
<nowiki>
</nowiki>
<pre><nowiki>
#settings for fileLinkExtension
#settings for fileLinkExtension
$wgFilelinkExtensionPath = "extensions/FilelinkExtension";
$wgFilelinkExtensionPath = "extensions/FileLinkExtension";
include("$IP/$wgFilelinkExtensionPath/FilelinkExtension.php");
include("$IP/$wgFilelinkExtensionPath/FileLinkExtension.php");
#end settings for fileLinkExtension
#end settings for fileLinkExtension
</nowiki></pre>
</nowiki></pre>
==To be done==
* Consider this as an alpha version. Not tested for many OS/browser environments yet.
* Conversion of filenames to urls (e.g. escaping the spaces, converting \ to / in windows, etc.) are done in an ad-hoc fasion. Have to find a better way to do this.
==Update==
Sometimes the edit button of the extension appear several times on the toolbar. In order to avoid this problem. the following changes were done:
Change
<pre>
function addbuttonDo (&$parser, &$text){
  global $wgRequest;
  global $wgAddButtonExtensionPath;
</pre>
to
<pre>
function addbuttonDo (&$parser, &$text){
#########new part###########
  static $done=0;
  if ( $done ) {
    return;
  }
  $done=1;
############################
  global $wgRequest;
  global $wgAddButtonExtensionPath;
</pre>
Thanks to all who pointed this out by mail (and on the discussion page.)! 
==To make buttons appear in 'preview' mode==
If you need to have the Filelink extension button in preview mode as well, just do the following mod.
Replace
<pre>
if(strtolower($action) == "edit" && $wgUser->isAllowed('edit')){
</pre> with
<pre>
if((strtolower($action) == "submit" || strtolower($action) == "edit" )
                                && $wgUser->isAllowed('edit')){
</pre>
[[Category:Mediawiki Extensions]]

Latest revision as of 19:10, 2 October 2009

Thumb
Bulb additional.png

There had been some requests to make the extension work for "preview" mode also. This can be done easily.

Context and Purpose

When mediawiki is used as an internal collaborating platform or a Personal Information Management tool, its access is mostly limited to a single computer or a single subnet (shared network environment). In such situations, it is sometimes useful to have the "file://" protocol enabled, so that links to files that can be normally accessed can be made in the documents. Mediawiki FAQ explains how to do this. (Needs to enable the functionality in Mediawiki AND all the client browsers. Once both those change sare made, it is possible to make links like

[[file://data6/manual.pdf]]

in wikitext and clicking on them will open (or download) the respective link.

On of the issues in this approach is that the users need to make the

file://

link themselves. This can sometimes be an tedious and error-prone process (particularly in windows environment). This extensions adds a editor toolbar button which will trigger a file open dialog so that the user can simply select the file to be linked. The extension places the correctly formatted file:// protocol link in the current position of the edit box.

Warning

Using fileprotocol links, even in a intranet environment can kill the integrity wiki, unless it is very carefully controlled. For example, one should never link files that will be later moved to some other place, or the are not shared (with the same path) among all the client computers.

How to use

#settings for fileLinkExtension
$wgFilelinkExtensionPath = "extensions/FileLinkExtension";
include("$IP/$wgFilelinkExtensionPath/FileLinkExtension.php");
#end settings for fileLinkExtension

To be done

  • Consider this as an alpha version. Not tested for many OS/browser environments yet.
  • Conversion of filenames to urls (e.g. escaping the spaces, converting \ to / in windows, etc.) are done in an ad-hoc fasion. Have to find a better way to do this.


Update

Sometimes the edit button of the extension appear several times on the toolbar. In order to avoid this problem. the following changes were done: Change

 
function addbuttonDo (&$parser, &$text){ 
  global $wgRequest;
  global $wgAddButtonExtensionPath;

to

 
function addbuttonDo (&$parser, &$text){ 
#########new part###########
  static $done=0;
  if ( $done ) { 
    return;
  }
  $done=1;
############################
  global $wgRequest;
  global $wgAddButtonExtensionPath;

Thanks to all who pointed this out by mail (and on the discussion page.)!

To make buttons appear in 'preview' mode

If you need to have the Filelink extension button in preview mode as well, just do the following mod.

Replace

 
 if(strtolower($action) == "edit" && $wgUser->isAllowed('edit')){

with

 
 if((strtolower($action) == "submit" || strtolower($action) == "edit" )
                                 && $wgUser->isAllowed('edit')){