Project:PEAR Wiki Filter
Version:6.x-1.0-beta1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Currently only images from image nodes using the image module are allowed for including using the [[Image:name]] syntax.

The attached patch allows images attached to a node to be included using the [[Image:name]] syntax.

AttachmentSize
Use_Attached_Images.patch1.65 KB

Comments

#1

Title:Alloow attached images to be used» Allow attached images to be used

(corrected title of the issue)

#2

Hi how do I apply this patch?

Running this patch from /var/www/sites/all/modules/pearwiki_filter/pear_override/parse_mediawiki results in:

# patch < Use_Attached_Images.patch
patching file Image.php
Hunk #1 FAILED at 54.
Hunk #2 FAILED at 73.
2 out of 2 hunks FAILED -- saving rejects to file Image.php.rej

# cat Image.php.rej
*************** class Text_Wiki_Render_Xhtml_Image exten
*** 54,61 ****
          $src = $options['src'];

          if (pearwiki_filter_use_image($pearwiki_current_format)) {
            // check if image node exists for this name
-           $image = db_fetch_object(db_query("SELECT n.nid, n.title, f.filename, f.filepath FROM {node} n LEFT JOIN {files} f ON n.nid = f.nid WHERE n.status = 1 AND n.type = 'image' AND LOWER(n.title) = LOWER('%s') LIMIT 1", $src));
            if ($image) {
              $src = file_create_url($image->filepath);
              if (!isset($options['attr']['alt'])) {
--- 54,70 ----
          $src = $options['src'];

          if (pearwiki_filter_use_image($pearwiki_current_format)) {
+           $image = false;
+
            // check if image node exists for this name
+           if (module_exists('image')) {
+             $image = db_fetch_object(db_query("SELECT n.nid, n.title, f.filename, f.filepath FROM {node} n LEFT JOIN {files} f ON n.nid = f.nid WHERE n.status = 1 AND n.type = 'image' AND LOWER(n.title) = LOWER('%s') LIMIT 1", $src));
+           }
+
+           // Look for attached images otherwise
+           if (!$image) {
+             $image = db_fetch_object(db_query("SELECT filename as title, filepath FROM {files} WHERE LOWER(filename) = LOWER('%s') LIMIT 1", $src));
+           }
            if ($image) {
              $src = file_create_url($image->filepath);
              if (!isset($options['attr']['alt'])) {
*************** class Text_Wiki_Render_Xhtml_Image exten
*** 64,70 ****
              if (!isset($options['attr']['title'])) {
                $options['attr']['title'] = $image->title;
              }
-             if (!isset($options['attr']['link'])) {
                $options['attr']['link'] = url("node/$image->nid", null, null, true);
              }
            }
--- 73,79 ----
              if (!isset($options['attr']['title'])) {
                $options['attr']['title'] = $image->title;
              }
+             if (!isset($options['attr']['link']) AND !empty($image->nid)) {
                $options['attr']['link'] = url("node/$image->nid", null, null, true);
              }
            }

Running this patch from /var/www/sites/all/modules/pearwiki_filter/pear_override/render/Xhtml results in:

# patch < Use_Attached_Images.patch
patching file Image.php
Hunk #1 FAILED at 54.
Hunk #2 succeeded at 77 (offset 4 lines).
1 out of 2 hunks FAILED -- saving rejects to file Image.php.rej

# cat Image.php.rej
*************** class Text_Wiki_Render_Xhtml_Image exten
*** 54,61 ****
          $src = $options['src'];

          if (pearwiki_filter_use_image($pearwiki_current_format)) {
            // check if image node exists for this name
-           $image = db_fetch_object(db_query("SELECT n.nid, n.title, f.filename, f.filepath FROM {node} n LEFT JOIN {files} f ON n.nid = f.nid WHERE n.status = 1 AND n.type = 'image' AND LOWER(n.title) = LOWER('%s') LIMIT 1", $src));
            if ($image) {
              $src = file_create_url($image->filepath);
              if (!isset($options['attr']['alt'])) {
--- 54,70 ----
          $src = $options['src'];

          if (pearwiki_filter_use_image($pearwiki_current_format)) {
+           $image = false;
+
            // check if image node exists for this name
+           if (module_exists('image')) {
+             $image = db_fetch_object(db_query("SELECT n.nid, n.title, f.filename, f.filepath FROM {node} n LEFT JOIN {files} f ON n.nid = f.nid WHERE n.status = 1 AND n.type = 'image' AND LOWER(n.title) = LOWER('%s') LIMIT 1", $src));
+           }
+
+           // Look for attached images otherwise
+           if (!$image) {
+             $image = db_fetch_object(db_query("SELECT filename as title, filepath FROM {files} WHERE LOWER(filename) = LOWER('%s') LIMIT 1", $src));
+           }
            if ($image) {
              $src = file_create_url($image->filepath);
              if (!isset($options['attr']['alt'])) {

Thanks & greetings, -asb

#3

Using a plain vanilla 6.x-1.0-beta1 go to pearwiki_filter/pear_override/render/Xhtml and run patch < Use_Attached_Images.patch

#4

Isn't that exactly what I described in #2?

Confused, -asb

#5

Sorry - did not explain enough: I downloaded PEAR Wiki Filter 6.x-1.0-beta1 and the patch above, changed directory to pearwiki_filter/pear_override/render/Xhtml and run the path using the command patch < Use_Attached_Images.patch. The patch run through without any error.

This are the steps in detail:

wget http://ftp.drupal.org/files/projects/pearwiki_filter-6.x-1.0-beta1.tar.gz 
tar zxf pearwiki_filter-6.x-1.0-beta1.tar.gz
cd pearwiki_filter/pear_override/render/Xhtml
wget http://drupal.org/files/issues/Use_Attached_Images.patch 
patch < Use_Attached_Images.patch

Result of patch command was: patching file Image.php which means success.

I don't know why you got the error. Can only imagine you don't use PEAR Wiki Filter 6.x-1.0-beta1.

#6

Here is another patch that I think corrects the root cause of the problem in the pearwiki_filter/pearwiki_filter.module file. It fixes an issue that the drupal forms api was not being correctly used for the pearwiki_filter.

Here are the steps I used to fix things:

1. Apply this patch then go to Administer › Site configuration › Input formats and click configure the input format that you created for your wiki, then switch to the configure tab. (takes you to the "/admin/settings/filters/n/configure" page).

2. Scroll down to the bottom and in the "Images" group ensure that the "Use image module?" is unchecked. (note the "Base path for images" setting here is important too).

3. Click the "Save Configuration" button to save (yes, even though you havn't edited anything you should click this button because the setting may still be incorrect in the database due to the problem the patch fixes).

4. Attaching images and using the [[image:name.jpg|caption]] syntax should now work. You may want to check you "Base path for images" setting (go back to step 2 above) if not.

PS how can I/we get these patches incorporated into the core code and a new release? I'm happy to do it if someone is willing to give me the CVS access?

AttachmentSize
turn_off_image_module.patch 2.2 KB

#7

I thought I would also mention the attached patch above also fixes the following problem:

You have drupal setup without the image module. You configure a pear wikifilter and create a new node using it. You attach a file using the core upload module and attempt to include that file in your node using the wiki syntax [[image:name.jpg|caption]].

You get this error:

user warning: Unknown column 'f.nid' in 'on clause' query: SELECT n.nid, n.title, f.filename, f.filepath FROM node n LEFT JOIN files f ON n.nid = f.nid WHERE n.status = 1 AND n.type = 'image' AND LOWER(n.title) = LOWER('MWSnap013.jpg') LIMIT 1 in /opt/drupal-6.10/sites/all/modules/pearwiki_filter/pear_override/render/Xhtml/Image.php on line 58.

This is because without the image module installed the tables in the database are not setup for this query to work. The patch in #6 fixes it becuase once you unckeck "Use image module?" and save the setting the query above will not be executed and the problem will not occur.

#8

@adam-griffiths:

Please have a look at this issue: PEAR Wiki Filter appears to be abandoned.

Would you be willing to take over maintainership or co.-maintainership of the module?

Thanks & greetings,
-asb

#9

Status:active» fixed

I have applied the patch (http://drupal.org/node/455100#comment-1899124) to the latest code in CVS.

#10

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#11

I have applied the Patch. However, it has caused some side effect.. I could not see my ADMIN MODULE page .. when I click on ADMIN Module I get BLANK PAGE