Menu

FindPage doesn't work (phpwiki1.3.3)

Help
2002-07-11
2012-10-11
  • Jean-Francois Declercq

    When I try to do a search in my wiki 1.3.3, I'm rooted to the  HomePage with this URL :
    http://localhost:8001/phpwiki/index.php?s=test

    instead of going to

    http://localhost:8001/phpwiki/index.php?pagename=TitleSearch&s=test

    When I look into the generated HTML, the actions seem ok ?

    <form action="index.php?pagename=TitleSearch"
    method="get" class="wikiaction" accept-charset="iso-
    8859-1">
    <div class="wikiaction"><input name="s" value=""
    type="text" size="30" title="Title Search"
    onmouseover="window.status=&quot;Title
    Search&quot;; return true;"
    onmouseout="window.status='';return true;" /><input
    type="submit" class="button"
    value="TitleSearch" /></div>
    </for

    Do you have a solution ?

    My config
    - Win2000 Pro
    - Apache 1.3.14
    - PHP 4.1.2
    - mysql

    JF

     
    • Wade Johnson

      Wade Johnson - 2002-07-18

      I am experiencing the same problem.  The search works fine if you manually type in the URL like:

      http://domain.de/phpwiki/index.php?pagename=FullTextSearch&s=Keyword

      If, however, you click on the FullTextSearch button, the generated URL looks like this:

      http://domain.de/phpwiki/index.php?s=Keyword

      I am also looking for a fix.

      Regards,

      Wade Johnson

       
    • Wade Johnson

      Wade Johnson - 2002-07-19

      Hello All!

      I found out why the fix isn't working.  Wikiplugin forms use the get method.  The action URL is something like:
      http://domain.de/phpwiki/index.php?pagename=FullTextSearch

      There is a search parm in the form "s" containing the value of the search phrase.  When the FullTextSearch button is pressed, the browser generates the URL to call from the action URL and the input parms.  Unfortunately, the browser chops off anything after the question mark "?" in the action URL.  Note that this behavior only happens when there is at least one field in the form to be passed.  If there are no fields, then the action URL is not changed.  In my case, if I am looking for the word "shore", then the URL is built like:

      http://domain.de/phpwiki/index.php?s=shore

      It should be:

      http://domain.de/phpwiki/index.php?pagename=FullTextSearch&s=shore

      I have created a hack in the WikiPlugin.php file that appears to correct this.

      Here is the code.  My hacks are commented with my initials "wtj"...

      <?php //-*-php-*-
      rcs_id('$Id: WikiPlugin.php,v 1.20 2002/02/15 05:34:49 carstenklapp Exp $');

      class WikiPlugin
      {
          function getDefaultArguments() {
              return array();
          }

          // FIXME: args?
          function run ($argstr, $request) {
              trigger_error("WikiPlugin::run: pure virtual function",
                            E_USER_ERROR);
          }

          /**
           * Get name of plugin.
           *
           * This is used (by default) by getDefaultLinkArguments and
           * getDefaultFormArguments to compute the default link/form
           * targets.
           *
           * If you want to gettextify the name (probably a good idea),
           * override this method in your plugin class, like:
           * <pre>
           *   function getName() { return _("MyPlugin"); }
           * </pre>
           *
           * @return string plugin name/target.
           */
          function getName() {
              return preg_replace('/^.*_/', '',  get_class($this));
          }

          function getDescription() {
              return $this->getName();
          }

          function getArgs($argstr, $request, $defaults = false) {
              if ($defaults === false)
                  $defaults = $this->getDefaultArguments();

              list ($argstr_args, $argstr_defaults) = $this->parseArgStr($argstr);

              foreach ($defaults as $arg => $default_val) {
                  if (isset($argstr_args[$arg]))
                      $args[$arg] = $argstr_args[$arg];
                  elseif ( ($argval = $request->getArg($arg)) !== false )
                      $args[$arg] = $argval;
                  elseif (isset($argstr_defaults[$arg]))
                      $args[$arg] = (string) $argstr_defaults[$arg];
                  else
                      $args[$arg] = $default_val;

                  $args[$arg] = $this->expandArg($args[$arg], $request);

                  unset($argstr_args[$arg]);
                  unset($argstr_defaults[$arg]);
              }

              foreach (array_merge($argstr_args, $argstr_defaults) as $arg => $val) {
                  trigger_error(sprintf(_("argument '%s' not declared by plugin"),
                                        $arg), E_USER_NOTICE);
              }

              return $args;
          }

          function expandArg($argval, $request) {
              return preg_replace('/\[(\w[\w\d]*)\]/e', '$request->getArg("$1")',
                                  $argval);
          }

          function parseArgStr($argstr) {
              $arg_p = '\w+';
              $op_p = '(?:||)?=';
              $word_p = '\S+';
              $opt_ws = '\s*';
              $qq_p = '" ( (?:[^"\\\\]|\\\\.)* ) "';
              //"<--kludge for brain-dead syntax coloring
              $q_p  = "' ( (?:[^'\\\\]|\\\\.)* ) '";
              $gt_p = "_\\( $opt_ws $qq_p $opt_ws \\)";
              $argspec_p = "($arg_p) $opt_ws ($op_p) $opt_ws (?: $qq_p|$q_p|$gt_p|($word_p))";

              $args = array();
              $defaults = array();

              while (preg_match("/^$opt_ws $argspec_p $opt_ws/x", $argstr, $m)) {
                  @ list(,$arg,$op,$qq_val,$q_val,$gt_val,$word_val) = $m;
                  $argstr = substr($argstr, strlen($m[0]));

                  // Remove quotes from string values.
                  if ($qq_val)
                      $val = stripslashes($qq_val);
                  elseif ($q_val)
                      $val = stripslashes($q_val);
                  elseif ($gt_val)
                      $val = _(stripslashes($gt_val));
                  else
                      $val = $word_val;

                  if ($op == '=') {
                      $args[$arg] = $val;
                  }
                  else {
                      // NOTE: This does work for multiple args. Use the
                      // separator character defined in your webserver
                      // configuration, usually & or &amp; (See
                      // http://www.htmlhelp.com/faq/cgifaq.4.html\)
                      // e.g. <plugin RecentChanges days||=1 show_all||=0 show_minor||=0>
                      // url: RecentChanges?days=1&show_all=1&show_minor=0
                      assert($op == '||=');
                      $defaults[$arg] = $val;
                  }
              }

              if ($argstr) {
                  trigger_error(sprintf(_("trailing cruft in plugin args: '%s'"),
                                          $argstr), E_USER_NOTICE);
              }

              return array($args, $defaults);
          }

          function getDefaultLinkArguments() {
              return array('targetpage' => $this->getName(),
                           'linktext' => $this->getName(),
                           'description' => $this->getDescription(),
                           'class' => 'wikiaction');
          }
         
          function makeLink($argstr, $request) {
              $defaults = $this->getDefaultArguments();
              $link_defaults = $this->getDefaultLinkArguments();
              $defaults = array_merge($defaults, $link_defaults);
         
              $args = $this->getArgs($argstr, $request, $defaults);
              $plugin = $this->getName();
         
              $query_args = array();
              foreach ($args as $arg => $val) {
                  if (isset($link_defaults[$arg]))
                      continue;
                  if ($val != $defaults[$arg])
                      $query_args[$arg] = $val;
              }
         
              $link = Button($query_args, $args['linktext'], $args['targetpage']);
              if (!empty($args['description']))
                  $link->addTooltip($args['description']);
         
              return $link;
          }
         
          function getDefaultFormArguments() {
              return array('targetpage' => $this->getName(),
                          'buttontext' => $this->getName(),
                          'class' => 'wikiaction',
                          'method' => 'get',
                          'textinput' => 's',
                          'description' => $this->getDescription(),
                          'formsize' => 30);
          }
         
          function makeForm($argstr, $request) {
              $form_defaults = $this->getDefaultFormArguments();
              $defaults = array_merge($this->getDefaultArguments(),
                                      $form_defaults);
         
              $args = $this->getArgs($argstr, $request, $defaults);
              $plugin = $this->getName();
              $textinput = $args['textinput'];
              assert(!empty($textinput) && isset($args['textinput']));

              //wtj beg hack for search issues
              $lar_url = parse_url(WikiURL($args['targetpage']));
              list ($ls_pagename, $ls_value) = split ('[=]', $lar_url['query']);
              //wtj end hack
         
              $form = HTML::form(array('action' => WikiURL($args['targetpage']),
                                      'method' => $args['method'],
                                      'class' => $args['class'],
                                      'accept-charset' => CHARSET));
              $contents = HTML::div();
              $contents->setAttr('class', $args['class']);

              //wtj beg hack for search issues
              $ls_counter = 0;
              //wtj end hack
             
              foreach ($args as $arg => $val) {
                  if (isset($form_defaults[$arg]))
                      continue;
                  if ($arg != $textinput && $val == $defaults[$arg])
                      continue;

              //wtj beg hack for search issues
                  $ls_counter += 1;
              //wtj end hack
             
                  $i = HTML::input(array('name' => $arg, 'value' => $val));
         
                  if ($arg == $textinput) {
                      //if ($inputs[$arg] == 'file')
                      //    $attr['type'] = 'file';
                      //else
                      $i->setAttr('type', 'text');
                      $i->setAttr('size', $args['formsize']);
                      if ($args['description'])
                          $i->addTooltip($args['description']);
                  }
                  else {
                      $i->setAttr('type', 'hidden');
                  }
                  $contents->pushContent($i);
         
                  // FIXME: hackage
                  if ($i->getAttr('type') == 'file') {
                      $form->setAttr('enctype', 'multipart/form-data');
                      $form->setAttr('method', 'post');
                      $contents->pushContent(HTML::input(array('name' => 'MAX_FILE_SIZE',
                                                               'value' => MAX_UPLOAD_SIZE,
                                                               'type' => 'hidden')));
                  }
              }

              //wtj beg hack for search issues
                  if ($ls_counter > 0) {
                      $i = HTML::input(array('name' => $ls_pagename, 'value' => $ls_value));
                      $i->setAttr('type', 'hidden');
                      $contents->pushContent($i);
                  }
              //wtj end hack
             
              if (!empty($args['buttontext']))
                  $contents->pushContent(HTML::input(array('type' => 'submit',
                                                           'class' => 'button',
                                                           'value' => $args['buttontext'])));
         
              $form->pushContent($contents);
              return $form;
          }
         
          function error ($message) {
              return HTML::div(array('class' => 'errors'),
                              HTML::strong(fmt("Plugin %s failed.", $this->getName())), ' ',
                              $message);
          }
      }

      class WikiPluginLoader {
          var $_errors;

          function expandPI($pi, $request) {
              if (!preg_match('/^\s*<\?(plugin(?:-form|-link)?)\s+(\w+)\s*(.*?)\s*\?>\s*$/s', $pi, $m))
                  return $this->_error(sprintf("Bad %s", 'PI'));

              list(, $pi_name, $plugin_name, $plugin_args) = $m;
              $plugin = $this->getPlugin($plugin_name);
              if (!is_object($plugin)) {
                  return new HtmlElement($pi_name == 'plugin-link' ? 'span' : 'p',
                                         array('class' => 'plugin-error'),
                                         $this->getErrorDetail());
              }
              switch ($pi_name) {
                  case 'plugin':
                      // FIXME: change API for run() (no $dbi needed).
                      $dbi = $request->getDbh();
                      return $plugin->run($dbi, $plugin_args, $request);
                  case 'plugin-link':
                      return $plugin->makeLink($plugin_args, $request);
                  case 'plugin-form':
                      return $plugin->makeForm($plugin_args, $request);
              }
          }

          function getPlugin($plugin_name) {
              global $ErrorManager;

              // Note that there seems to be no way to trap parse errors
              // from this include.  (At least not via set_error_handler().)
              $plugin_source = "lib/plugin/$plugin_name.php";

              $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_plugin_error_filter'));
              $include_failed = !include_once("lib/plugin/$plugin_name.php");
              $ErrorManager->popErrorHandler();

              $plugin_class = "WikiPlugin_$plugin_name";
              if (!class_exists($plugin_class)) {
                  if ($include_failed)
                      return $this->_error(sprintf(_("Include of '%s' failed"),
                                                   $plugin_source));
                  return $this->_error(sprintf("%s: no such class", $plugin_class));
              }

              $plugin = new $plugin_class;
              if (!is_subclass_of($plugin, "WikiPlugin"))
                  return $this->_error(sprintf("%s: not a subclass of WikiPlugin",
                                               $plugin_class));

              return $plugin;
          }

          function _plugin_error_filter ($err) {
              if (preg_match("/Failed opening '.*' for inclusion/", $err->errstr))
                  return true;        // Ignore this error --- it's expected.
              return false;
          }

          function getErrorDetail() {
              return $this->_errors;
          }

          function _error($message) {
              $this->_errors = $message;
              return false;
          }

      };

      // (c-file-style: "gnu")
      // Local Variables:
      // mode: php
      // tab-width: 8
      // c-basic-offset: 4
      // c-hanging-comment-ender-p: nil
      // indent-tabs-mode: nil
      // End:
      ?>

      Basically, I take the pagename parameter out of the target URL and make a hidden field in the form.  When the target URL is generated by the browser, it then still overwrites the original pagename variable, but it appends the new hidden field in the form (which is the same anyway).

      Regards,

      Wade Johnson
      wade@wadejohnson.de

       
    • nate parsons

      nate parsons - 2002-08-26

      Wade you the man, your fixes worked for me too, you should get some props from these developers up in here

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.