Google Search

From Meta, a Wikimedia project coordination wiki

Google search free

Also check out Google Search-2 to see how I integrated a Google search appliance into Intuit's baseline wikis. --MHart 16:41, 4 August 2006 (UTC)[reply]

Insert after:[edit]

	<div id="p-search" class="portlet">
		<h5><label for="searchInput">Google Search</label></h5>
		<div class="pBody">
			<!-- SiteSearch Google -->
			<form method="get" action="http://www.google.com/custom" target="_top">
			<table border="0" bgcolor="#ffffff">
				<tr><td nowrap="nowrap" valign="top" align="center" height="32">
					<a href="http://www.google.com/" title="Google">
						<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google"></img>
					</a><br/>
					<input type="hidden" name="domains" value="noblood.org"></input>
					<input type="text" name="q" size="16" maxlength="255" value=""></input>
				</td></tr>
				<tr><td nowrap="nowrap" align="center">
					<table>
						<tr><td>
							<input type="radio" name="sitesearch" value="noblood.org" checked="checked"></input>
							<font size="-2" color="#000000">Site</font>
						</td>
						<td>
							<input type="radio" name="sitesearch" value="wikipedia.org"></input>
							<font size="-2" color="#000000"><a href="http://en.wikipedia.org/">Wikipedia</a></font>
						</td>
						<td>
							<input type="radio" name="sitesearch" value=""></input>
							<font size="-2" color="#000000">Web</font>
						</td></tr>
					</table>
					<input type="submit" name="sa" value="Search"></input>
					<input type="hidden" name="ie" value="UTF-8"></input>
					<input type="hidden" name="oe" value="UTF-8"></input>
					<input type="hidden" name="hl" value="en"></input>
				</td></tr>
			</table>
			</form>
			<!-- SiteSearch Google --> 
		</div>
	</div>

A Slightly Different Example[edit]

This change is very much in the mode of the one above, for which I am grateful for the head start on the code. My version does not have the radio buttons, but does have the option to have the original search, the google search, or both. I have not yet tested this with the latest version. But it does work with 1.4 and I have every expectation that it will work with 1.5 as soon as I get done with the install ...

You can see the working example at the "Unofficial BOINC Wiki!" where, at least for the moment, I have both searches turned on.

As of April 2006 the URL of the Unofficial BOINC Wiki has changed to http://boinc-wiki.ath.cx/ 203.218.86.162 03:40, 4 June 2006 (UTC)[reply]

What To Do[edit]

As above, go into your current skin file (mine was/is Monobook). You need to find the code shown above and you are going to cut it out, and instert the new code as provided.

    <?php
    global $wgSearchTypeEnabled; // pull in the externally declared "Global"
    global $wgSearchSiteURL;
    global $wgSearchDomain;

    if ((strtolower($wgSearchTypeEnabled) == strtolower("Google")) ||
        (strtolower($wgSearchTypeEnabled) == strtolower("Both"  ))) {
      echo "    <div id=\"p-search\" class=\"portlet\">\r\n";
      echo "      <h5><label for=\"searchInput\">Google Search</label></h5>\r\n";
      echo "      <div class=\"pBody\">\r\n";
      echo "        <!-- SiteSearch Google -->\r\n";
      echo "        <form method=\"get\" \r\n";
      echo "              action=\"http://www.google.com/custom\" \r\n";
      echo "              target=\"_top\">\r\n";
      echo "          <table border=\"0\" bgcolor=\"#ffffff\">\r\n";
      echo "          <tr>\r\n";
      echo "              <td nowrap=\"nowrap\" valign=\"top\" align=\"center\" height=\"32\">\r\n";
      echo "                <a href=\"http://www.google.com/\" title=\"Google Logo\">\r\n";
      echo "                  <img src=\"http://www.google.com/logos/Logo_25wht.gif\"\r\n";
      echo "                    border=\"0\" \r\n";
      echo "                       alt=\"Google\">\r\n";
      echo "                  </img>\r\n";
      echo "                </a><br/>\r\n";
      echo "                 <input type=\"hidden\" \r\n";
      echo "                        name=\"domains\"\r\n";
      echo "                       value=\"" . $wgSearchDomain . "\" />\r\n";
      echo "                 <input type=\"hidden\" \r\n";
      echo "                        name=\"sitesearch\" \r\n";
      echo "                       value=\"" . $wgSearchSiteURL . "\" />\r\n";
      echo "                 <input   id=\"searchInput\"\r\n";
      echo "                        type=\"text\" \r\n";
      echo "                        name=\"q\" \r\n";
      echo "                       value=\"\"></input>\r\n";
      echo "              </td>\r\n";
      echo "            </tr>\r\n";
      echo "            <tr>\r\n";
      echo "              <td nowrap=\"nowrap\" align=\"center\">\r\n";
      echo "                <input type=\"submit\" name=\"sa\" value=\"Google Search\" class=\"searchButton\" />\r\n";
      echo "                <input type=\"hidden\" name=\"ie\" value=\"UTF-8\"></input>\r\n";
      echo "                <input type=\"hidden\" name=\"oe\" value=\"UTF-8\"></input>\r\n";
      echo "                <input type=\"hidden\" name=\"hl\" value=\"en\"></input>\r\n";
      echo "              </td>\r\n";
      echo "            </tr>\r\n";
      echo "          </table>\r\n";
      echo "        </form>\r\n";
      echo "        <!-- SiteSearch Google --> \r\n";
      echo "      </div>\r\n";
      echo "    </div>\r\n";
    } 
    
    if ((strtolower($wgSearchTypeEnabled) == strtolower("WikiDefault")) ||
        (strtolower($wgSearchTypeEnabled) == strtolower("Both"  ))     ) {
      echo "    <div id=\"p-search\" class=\"portlet\">\r\n";
      echo "      <h5><label for=\"searchInput\">";
      $this->msg('search');
      echo "</label></h5>\r\n";
      echo "      <div class=\"pBody\">\r\n";
      echo "        <!-- SiteSearch WikiDefault --> \r\n";
      echo "        <form    name=\"searchform\" \r\n";
      echo "               action=\"";
      $this->text('searchaction');
      echo "\"\r\n";
      echo "                   id=\"searchform\">\r\n";
      echo "          <input   id=\"searchInput\" \r\n";
      echo "                 name=\"search\"\r\n";
      echo "                 type=\"text\"\r\n";
      if ($this->haveMsg('accesskey-search')) {
        echo "            accesskey=\"";
        $this->msg('accesskey-search'); 
        echo "\"\r\n";
      }
      if (isset($this->data['search']) ) {
        echo "                value=\"";
        $this->text('search');
        echo "\""; // don't end with line feed, need end of control
      }
      echo " />\r\n";
      echo "          <input type=\"submit\"\r\n";
      echo "                 name=\"go\"\r\n";
      echo "                class=\"searchButton\"\r\n";
      echo "                   id=\"searchGoButton\"\r\n";
      echo "                value=\"";
      $this->msg('go');
      echo "\" /> \r\n";
      echo "          <input type=\"submit\"\r\n";
      echo "                 name=\"fulltext\"\r\n";
      echo "                class=\"searchButton\"\r\n";
      echo "                value=\"";
      $this->msg('Search');
      echo "\" />\r\n";
      echo "        </form>\r\n";
      echo "        <!-- SiteSearch WikiDefault --> \r\n";
      echo "	  </div>\r\n";
      echo "	</div>\r\n";
    
    }

    ?>

The important part of the "Page Source" output by all that "muck" above looks like:

        <div id="p-search" class="portlet">
      <h5><label for="searchInput">Google Search</label></h5>
      <div class="pBody">
        <!-- SiteSearch Google -->
        <form method="get" 
              action="http://www.google.com/custom" 
              target="_top">
          <table border="0" bgcolor="#ffffff">

          <tr>
              <td nowrap="nowrap" valign="top" align="center" height="32">
                <a href="http://www.google.com/" title="Google Logo">
                  <img src="http://www.google.com/logos/Logo_25wht.gif"
                    border="0" 
                       alt="Google">
                  </img>
                </a><br/>
                 <input type="hidden" 
                        name="domains"
                       value="http://boinc-doc.net/boinc-wiki/" />
                 <input type="hidden" 
                        name="sitesearch" 
                       value="http://boinc-doc.net/boinc-wiki/" />
                 <input   id="searchInput"
                        type="text" 
                        name="q" 
                       value=""></input>

              </td>
            </tr>
            <tr>
              <td nowrap="nowrap" align="center">
                <input type="submit" name="sa" value="Google Search" class="searchButton" />
                <input type="hidden" name="ie" value="UTF-8"></input>
                <input type="hidden" name="oe" value="UTF-8"></input>
                <input type="hidden" name="hl" value="en"></input>
              </td>

            </tr>
          </table>
        </form>
        <!-- SiteSearch Google --> 
      </div>
    </div>
    <div id="p-search" class="portlet">
      <h5><label for="searchInput">Search</label></h5>
      <div class="pBody">

        <!-- SiteSearch WikiDefault --> 
        <form    name="searchform" 
               action="/~paulbuck/boinc-wiki/index.php/Special:Search"
                   id="searchform">
          <input   id="searchInput" 
                 name="search"
                 type="text"
            accesskey="f"
                value="" />
          <input type="submit"
                 name="go"
                class="searchButton"
                   id="searchGoButton"
                value="Go" /> 
          <input type="submit"
                 name="fulltext"
                class="searchButton"
                value="Search" />
        </form>
        <!-- SiteSearch WikiDefault --> 
	  </div>
	</div>

This shows what you SHOULD be getting. I know a lot of programmers do not spend that much time on the output formatting, but, a clue from Paul, it helps to troubleshoot the code if you can see what the heck is being output.

Configuration[edit]

In your LocalSettings.php you need to add the configuration lines:

# The type, or types of searches allowed. Values are: "Google", "WikiDefault", "Both"
$wgSearchTypeEnabled = "Both";

# The site and/or to which the search should be restricted
$wgSearchSiteURL = "http://boinc-doc.net/boinc-wiki/";
$wgSearchDomain  = "http://boinc-doc.net/boinc-wiki/";

Obviously, you may want to consider changing the values there to make them suit your site.

I hope to expand to an advanced page, but, have not finished this one. If anyone tries it and has a suggestion for improvement, I can be reached at home.