Jump to content

Extension talk:FileLink

Add topic
From mediawiki.org
Latest comment: 13 years ago by JackPotte in topic Bug with MediaWiki 1.11.0

Bug with MediaWiki 1.19.2, FireFox & Safari

[edit]

I've installed the extension, given the full rights for all files but I'm afraid I can't get this magic button when I edit a wikipage.

Here is a copy of the last lines of my LocalSettings.php file

#Settings for FileLinkExtension
$wgFilelinkExtensionPath = "extensions/FileLinkExtension";
include("/var/www/html/GINwiki/extensions/FileLinkExtension/FileLinkExtension.php");
# end

FileLinkExtension.php file:

<?php 
  ## I removed the commented part here only
$wgExtensionFunctions[] = "wfFilelinkExtension";
function wfFilelinkExtension () {
  global $wgParser;
  global $wgHooks; 
  $wgHooks['ParserBeforeTidy'][] = 'filelinkDo' ;
}
function filelinkDo (&$parser, &$text){
#########new part###########
  static $done=0;
  if ( $done ) { 
    return true;
  }
  $done=1;
############################
  global $wgRequest;
  global $wgFilelinkExtensionPath;
  global $wgScriptPath;
  global $wgUser;
  global $IP;
  global $wgServer;
 $sk=$wgUser->getSkin();
  $action =  $wgRequest->getVal( 'action', false );
  //Are we in a edit page AND are we allowed to edit
 $action_preview =  $wgRequest->getVal( 'wpPreview', false );
  // Are we in a edit page AND are we allowed to edit
  if( ((strtolower($action) == "submit" && $action_preview!="") 
        || strtolower($action) == "edit" ) 
        && $wgUser->isAllowed('edit')){  
  //strtolower^^ is not needed, but to  be safe
  //now we know that we are in the  edit dialog so add some javascript code to add a new button
  // This is done by mainfile.js
  //However, dynamic variables must be given externally. 
  //So here are the neede variables for mainfile.js
  $vars= "
  <script type='text/javascript' language='JavaScript'> ; 
  var filelinkextension_iconimage='/var/www/html/GINwiki/extensions/FileLinkExtension/filelinkbutton.jpg' //global variable
  var filelinkextension_childfile='/var/www/html/GINwiki/extension/FileLinkExtension/childfile.html' //global variable
  </script>";
  //Read in the mainfile.js
  $jscript=file_get_contents("/var/www/html/GINwiki/extensions/FileLinkExtension/mainfile.js");
  $text="
  <script type='text/javascript' language='JavaScript'> "
        .$jscript.
        "
         //Just an entry point for the child window to call insertTags() function in wikibits
          function insertTagsInMe(one,two,three){
              insertTags(one,two,three);
          }
        </script>".$text;	
  $text=$vars.$text;
  }else{
    //Either not an edit attempt, or not logged in 
    //Do nothing be silent without bothering innocent visitors. 
   return false;
  }
   return true;
}
?>


Childfile.html:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en' dir='ltr'> 
<head><body>
  <script type='text/javascript' language='JavaScript'> 
    function updateParent() {
      var txt=document.fileselectform.filename.value;
      var temp = replaceAll(replaceAll(txt,'\\','/'),' ','%20');
      var solution = "<ext>file:///"+temp+" ::";
    opener.insertTagsInMe(solution, "</ext>","descriptive name here");
// opener.document.parentForm.pf2.value = document.childForm.cf2.value;
    self.close();
    return false;
    }
 // This function replaces all instances of findStr in oldStr with repStr.
  function replaceAll(oldStr,findStr,repStr) {
    var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                        // of oldStr are we searching.
    var newStr = "";  // newStr will hold the altered version of oldStr.
    while (oldStr.indexOf(findStr,srchNdx) != -1)  
// As long as there are strings to replace, this loop will run.
    {
     newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
// Put it all the unaltered text from one findStr to the next findStr into newStr.
     newStr += repStr;
// Instead of putting the old string, put in the new string instead. 
     srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
// Now jump to the next chunk of text till the next findStr.           
    }
    newStr += oldStr.substring(srchNdx,oldStr.length);
// Put whatever's left into newStr.             
            return newStr;
}
 </script>
  <form method="post" enctype="multipart/form-data" onsubmit="javascript:updateParent();"id="fileselectform" name="fileselectform" action="">
  <input id="filename" name="filename" type="file" accesskey="f" value="" />
  <input tabindex="2" id="subclose" value="OK" name="subclose" accesskey="s" title="Link this file" type="submit"> 
  </form>
  </body>

NB : the extension LaunchExternal v1.1 is up and running.

The first problem I see (but I fail to solve it) is that the extension is not mentionned in my Special:Version page.

The script doesn't bug any page but I can't get the button...

If anyone has a clue, it would be great. Many thanks in advance!

Gleroux_Bdx2 07 January 2013 (MediaWiki 1.19.2, PHP 5.3.6 (apache2handler), MySQL 5.1.58)


Bug with MediaWiki 1.11.0

[edit]

I installed and used the FileLink-Extension with mediawiki version 1.10.0 without problem, but after upgrading to version 1.11.0 I get the following error message whenever I try to edit a page.

Detected bug in an extension! Hook filelinkDo failed to return a value; should return true to continue hook processing or false to abort.

Backtrace:

#0 /opt/lampp/htdocs/_fhbwiki/includes/Parser.php(332): wfRunHooks('ParserBeforeTid...', Array)
#1 /opt/lampp/htdocs/_fhbwiki/includes/OutputPage.php(474): Parser->parse('Abbrechen', Object(Title), Object(ParserOptions), true, true, NULL)
#2 /opt/lampp/htdocs/_fhbwiki/includes/GlobalFunctions.php(593): OutputPage->parse('Abbrechen', true, true)
#3 /opt/lampp/htdocs/_fhbwiki/includes/EditPage.php(1065): wfMsgExt('cancel', Array)
#4 /opt/lampp/htdocs/_fhbwiki/includes/EditPage.php(433): EditPage->showEditForm()
#5 /opt/lampp/htdocs/_fhbwiki/includes/EditPage.php(285): EditPage->edit()
#6 /opt/lampp/htdocs/_fhbwiki/includes/Wiki.php(437): EditPage->submit()
#7 /opt/lampp/htdocs/_fhbwiki/includes/Wiki.php(48): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest))
#8 /opt/lampp/htdocs/_fhbwiki/index.php(89): MediaWiki->initialize(Object(Title), Object(OutputPage), Object(User), Object(WebRequest))
#9 {main}
I also have it with MediaWiki 1.16.5, but by replacing the FileLinkExtension.php content by the one below it's better. However, when I submit a page:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/Wiki/extensions/FileLinkExtension/FileLinkExtension.php:81) in /var/www/Wiki/includes/WebResponse.php on line 16

JackPotte 20:51, 3 July 2011 (UTC) (MediaWiki 1.16.5, PHP 5.3.2-1ubuntu4.9 (apache2handler), MySQL 5.1.41-3ubuntu12.10)Reply

Fix for 1.11.0 +

[edit]

Every function which is registered as a MediaWiki hook must return something so just add TRUE to any Return ;

function wfDataLanguageGetMagic( &$magicWords, $langCode ) {
    switch ( $langCode ) {
        default:
            $magicWords['data']          = array( 0, 'data' );
            $magicWords['sort']          = array( 0, 'sort' );
    }
    return true;
} 
and at the end
    //Either not an edit attempt, or not logged in 
    //Do nothing be silent without bothering innocent visitors. 
  }
return TRUE;
}
?>
Thanks for the tipp - after I added a true to the one and only return I could find in extensions/FileLinkExtension.0.2/FileLinkExtension.php and also added a return true; to the end of the file/function I don't get the errors anymore, but neither do I get the filelink-button in the edit mode. :(
Does anybody have an idea how to fix this?
--Katwol 10:46, 30 January 2008 (UTC)Reply

Fix for 1.12.0 +

[edit]

This version of FileLinkExtension.php works with mediawiki 1.12

--Mitchelln 11:45, 28 March 2008 (UTC)Reply
<?php 
  ##_____________________________________________________________________
  ##    copyright 2006 Assela Pathirana
  ##    UNDER GNU GPL
  ##    Version 0.2 (2006 Sept)
  ##_____________________________________________________________________
  ##
  ##    This program is free software; you can redistribute it and/or modify
  ##    it under the terms of the GNU General Public License as published by
  ##    the Free Software Foundation; either version 2 of the License, or
  ##    (at your option) any later version.
  ##
  ##    This program is distributed in the hope that it will be useful,
  ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ##    GNU General Public License for more details.
  ##
  ##    You should have received a copy of the GNU General Public License
  ##    along with this program; if not, write to the Free Software
  ##    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  ##
  ##    Inspired by gallery2wiki by Andres Obrero <andres.obrero@transarte.com> 
  ##

$wgExtensionFunctions[] = "wfFilelinkExtension";

function wfFilelinkExtension () {
  global $wgParser;
  global $wgHooks; 
  $wgHooks['ParserBeforeTidy'][] = 'filelinkDo' ;
}
function filelinkDo (&$parser, &$text){
#########new part###########
  static $done=0;
  if ( $done ) { 
    return TRUE;
  }
  $done=1;
############################
  global $wgRequest;
  global $wgFilelinkExtensionPath;
  global $wgScriptPath;
  global $wgUser;
  global $IP;
  $sk=$wgUser->getSkin();
  $action =  $wgRequest->getVal( 'action', false );
  //Are we in a edit page AND are we allowed to edit
  if(strtolower($action) == "edit" && $wgUser->isAllowed('edit') && $wgUser->isAllowed('edit')){  
  //strtolower^^ is not needed, but to  be safe
  //now we know that we are in the  edit dialog so add some javascript code to add a new button
  // This is done by mainfile.js
  //However, dynamic variables must be given externally. 
  //So here are the neede variables for mainfile.js
  $vars= "
  <script type='text/javascript' language='JavaScript'> ; 
  var filelinkextension_iconimage='"."$wgScriptPath/$wgFilelinkExtensionPath"."/filelinkbutton.jpg' //global variable
  var filelinkextension_childfile='"."$wgScriptPath/$wgFilelinkExtensionPath"."/childfile.html' //global variable
  </script>";
  //Read in the mainfile.js
  $jscript=file_get_contents("$IP/$wgFilelinkExtensionPath/mainfile.js");
  $text="
  <script type='text/javascript' language='JavaScript'> "
        .$jscript.
        "
         //Just an entry point for the child window to call insertTags() function in wikibits
          function insertTagsInMe(one,two,three){
              insertTags(one,two,three);
          }
        </script>".$text;	
  $text=$vars.$text;
 
  }else{
    //Either not an edit attempt, or not logged in 
    //Do nothing be silent without bothering innocent visitors. 
    return false;
  }
return true;
}
?>
Hi Mitchelln,
thanks for posting the adapted version for mediawiki 1.12.0!
After installing it I get no error-messages, but I do not get the extra-button for starting the file-link-"GUI". :-(
Can you (or anybody else) give me a tipp how to debug this? Thanks!
--Katwol 07:37, 2 April 2008 (UTC)Reply
Hi again,
I don't know why (or how in detail), but I managed to solve the missing-button-problem myself:
I added a line
alert("FileLinkExtension wird gestartet");
right at the beginning of the function addFilelinkButton() in mainfile.js and when I started to edit an article the alert-box and(!!!) the button appeared!
And - curiouser and curiouser - the button still appears, even though I commentet the line out, so the alert-box doesn't appear anymore. :)
--Katwol 10:17, 2 April 2008 (UTC)Reply
Very odd. It just worked for me!
--Mitchelln 09:17, 3 April 2008 (UTC)Reply

firefox 3 issues

[edit]

Inside the updateParent() function, you must have:

 netscape.security.PrivilegeManager.enablePrivilege('UniversalFileRead');

as the first line. Then inside Firefox, you must edit user.js or go to about:config and set

 signed.applets.codebase_principal_support

to 'true'. Then when the form is presented, the user will be presented with the option of denying or allowing access to this script. One must allow it for this extension to work right. --Otheus 09:46, 10 July 2008 (UTC)Reply

Help! Where exactly do I find the updateParent() function?
I hope your fix is going to make the full path's reappear, when I use the FileLink-Extension, because with Firefox3 I suddenly only get [file:///example.txt descriptive name here] without any path at all. :-(
--Katwol 14:15, 10 July 2008 (UTC)Reply
I've found it myself - it's in [...]/extensions/FileLinkExtension.0.2/childfile.html
and the fix works on the missing file-path. :-)
But now I've got another problem: without the fix the extension won't work with FF3, but with it, the extension won't work with FF2 anymore. :-(
I need it to work with both FF-versions simultaniously. Is there a way to make the fix sensitive to the firefox-version in use?
--Katwol 13:03, 17 July 2008 (UTC)Reply
I've "solved" my FF-problem by updating all PCs to Firefox 3. ;-)
--Katwol 13:26, 8 August 2008 (UTC)Reply

(RESOLVED) button not displayed

[edit]

I have mw 1.12 and have run the firefox 3 update. However the button does not display on new pages. You have to save the page and then edit it again for the filelink button to show.. it's rather annoying, does anyone else have that problem, or know how to fix it? Thanks, Matt 13:19, 1 August 2008 (UTC)Reply

Answer: see extension page section on preview button

Error 405

[edit]

Does anybody get a 405 error when clicking on "OK" button? The error message is

405 - HTTP verb used to access this page is not allowed.
The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

I get it with Firefox and IIS. The browse button works fine without a hitch. I have it working with Firefox and a couple of changes in the about:config but I cant remember how I did it. But all my users are using IE anyway. So i need it to work in IE. I know that I dont need to do anything on server side because it works with my browser with extnsion ant the changes in the about:config. I'm looking for a setting change in IE.

Thanks, --abrillon 20:20, 24 March 2009 (UTC)Reply

My approach (involves LaunchExernal)

[edit]

I have been able to get it to almost work. The remaining problem appears to be a browser issue. Specifically, some browsers other than Internet Explorer (probably for security reasons) don't like to provide local filepaths to javascripts when the user selects a file; also, although Internet Explorer and other browsers will accept a path such as file:///C:/xampp/xampp/htdocs/mw/extensions/launchExternal/Readme.txt if you type it into the address bar, it evidently won't let you proceed via a weblink to such a location (again, probably for security reasons). So, although I have managed to create such a link, it does no good without a compatible browser. Make sure that you put the extension in /extensions/FileLinkExtension.0.2, or it won't work at all. For a demonstration of the results on a wiki that has this revised extension installed, go to http://rped.org/testwiki/index.php?title=Sandbox

I installed Extension:LaunchExternal and changed a couple files in FileLink so that instead of bracketing the link, it surrounds it with <ext> and </ext>. Specifically, I changed FileLinkExtension.php as follows:

<?php
  ##_____________________________________________________________________
  ##    copyright 2006 Assela Pathirana
  ##    UNDER GNU GPL
  ##    Version 0.2 (2006 Sept)
  ##_____________________________________________________________________
  ##
  ##    This program is free software; you can redistribute it and/or modify
  ##    it under the terms of the GNU General Public License as published by
  ##    the Free Software Foundation; either version 2 of the License, or
  ##    (at your option) any later version.
  ##
  ##    This program is distributed in the hope that it will be useful,
  ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ##    GNU General Public License for more details.
  ##
  ##    You should have received a copy of the GNU General Public License
  ##    along with this program; if not, write to the Free Software
  ##    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  ##
  ##    Inspired by gallery2wiki by Andres Obrero <andres.obrero@transarte.com> 
  ##

$wgExtensionFunctions[] = "wfFilelinkExtension";

function wfFilelinkExtension () {
  global $wgParser;
  global $wgHooks; 
  $wgHooks['ParserBeforeTidy'][] = 'filelinkDo' ;
}
function filelinkDo (&$parser, &$text){
#########new part###########
  static $done=0;
  if ( $done ) { 
    return TRUE;
  }
  $done=1;
############################
  global $wgRequest;
  global $wgFilelinkExtensionPath;
  global $wgScriptPath;
  global $wgUser;
  global $IP;
  global $wgServer;
  $sk=$wgUser->getSkin();
  $action =  $wgRequest->getVal( 'action', false );
  //Are we in a edit page AND are we allowed to edit
  $action_preview =  $wgRequest->getVal( 'wpPreview', false );
  //Are we in a edit page AND are we allowed to edit
  if( ((strtolower($action) == "submit" && $action_preview!="")
        || strtolower($action) == "edit" )
      && $wgUser->isAllowed('edit')){
  //strtolower^^ is not needed, but to  be safe
  //now we know that we are in the  edit dialog so add some javascript code to add a new button
  // This is done by mainfile.js
  //However, dynamic variables must be given externally. 
  //So here are the neede variables for mainfile.js
  $vars= "
  <script type='text/javascript' language='JavaScript'> ; 
  var filelinkextension_iconimage='".$wgServer.$wgScriptPath."/extensions/FileLinkExtension.0.2/filelinkbutton.jpg' //global variable
  var filelinkextension_childfile='".$wgServer.$wgScriptPath."/extensions/FileLinkExtension.0.2/childfile.html' //global variable
  </script>";
  //Read in the mainfile.js
  $jscript=file_get_contents($wgServer.$wgScriptPath."/extensions/FileLinkExtension.0.2/mainfile.js");
  $text="
  <script type='text/javascript' language='JavaScript'> "
        .$jscript.
        "
         //Just an entry point for the child window to call insertTags() function in wikibits
          function insertTagsInMe(one,two,three){
              insertTags(one,two,three);
          }
        </script>".$text;	
  $text=$vars.$text;
 
  }else{
    //Either not an edit attempt, or not logged in 
    //Do nothing be silent without bothering innocent visitors. 
    return false;
  }
return true;
}
?>

Then I changed childfile.html to read as follows:

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en' dir='ltr'> <head><body>
  <script type='text/javascript' language='JavaScript'> 
    function updateParent() {
	
	var strFile = document.fileselectform.filename.value;
	intPos = strFile.lastIndexOf("\\");
	//var strDirectory = strFile.substring(0, intPos);
	//alert(strDirectory);
	//document.fileselectform.Directory.value = strDirectory;
	
	var txt=strFile;
    //var txt=document.fileselectform.filename.value;
    var temp = replaceAll(replaceAll(txt,'\\','/'),' ','%20');
    var solution = "<ext>file:///"+temp+" ::";
    opener.insertTagsInMe(solution, "</ext>","descriptive name here");
    // opener.document.parentForm.pf2.value = document.childForm.cf2.value;
    self.close();
    return false;
    }
 // This function replaces all instances of findStr in oldStr with repStr.

  function replaceAll(oldStr,findStr,repStr) {
    var srchNdx = 0;  // srchNdx will keep track of where in the whole line
                        // of oldStr are we searching.
    var newStr = "";  // newStr will hold the altered version of oldStr.
    while (oldStr.indexOf(findStr,srchNdx) != -1)  
    // As long as there are strings to replace, this loop
    // will run. 
    {
     newStr += oldStr.substring(srchNdx,oldStr.indexOf(findStr,srchNdx));
     // Put it all the unaltered text from one findStr to
     // the next findStr into newStr.
     newStr += repStr;
     // Instead of putting the old string, put in the
     // new string instead. 
     srchNdx = (oldStr.indexOf(findStr,srchNdx) + findStr.length);
     // Now jump to the next chunk of text till the next findStr.           
    }
    newStr += oldStr.substring(srchNdx,oldStr.length);
    // Put whatever's left into newStr.             
            return newStr;
	
	// This was removed from the HTML:
	// <input type="hidden" id="Directory" name="Directory" value="">
}

 </script>
  <form method="post" enctype="multipart/form-data" onsubmit="javascript:updateParent();"id="fileselectform" name="fileselectform" action="">
  <input id="filename" name="filename" type="file" accesskey="f" value="" />
  <input tabindex="2" id="subclose" value="OK" name="subclose" accesskey="s" title="Link this file" type="submit">
  </form>
  </body>

Tisane 00:13, 12 March 2010 (UTC)Reply

Fix for button does not appear issue

[edit]

I found that I had to rename the directory of the extension from 'FileLinkExtension.0.2' to just 'FileLinkExtension'

-Paul Casper

Is this extension usable...

[edit]

...because browsers refuse to pass full path of file to server ?

With a "directory name" hack it would be possible to get it work with IE but not with FireFox or Chrome. Or have I understood it wrong?

Or is there a way to enable passing of directory name to server with IE, FireFox and Chrome?