1<?php 2require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/nav.class.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/menu.class.php"); $App = new App(); $Nav = new Nav(); $Menu = new Menu(); include($App->getProjectCommon()); 3ob_start(); 4 5include("includes/db.php"); 6 7$pagesize = 25; //results per page 8$scroll = 5; //+- pages to show in nav 9$days = 7; 10$page = (preg_match("/^\d+$/", $_GET["p"]) ? $_GET["p"] : 1); 11$offset = ($page - 1) * $pagesize; 12 13$where = "WHERE `date` >= DATE_SUB(CURDATE(), INTERVAL $days DAY)"; 14$order = "ORDER BY `date` DESC"; 15 16$extraf = array( 17 array("regex" => "/author: ?(\S+)/", "sql" => "`author` LIKE '%%%s%%'", "sqlpart" => "where"), 18 array("regex" => "/file: ?(\S+)/", "sql" => "`cvsname` LIKE '%%%s%%'", "sqlpart" => "where"), 19 array("regex" => "/days: ?(\d+)/", "sql" => "`date` >= DATE_SUB(CURDATE(), INTERVAL %d DAY)", "sqlpart" => "where"), 20 array("regex" => "/(?:project|module): ?(\S+)/", "sql" => "`project` LIKE '%s'", "sqlpart" => "where"), 21 array("regex" => "/branch: ?(\S+)/", "sql" => "`branch` LIKE '%%%s%%'", "sqlpart" => "having") //is a calculated value, won't work in WHERE 22); 23 24$q = (get_magic_quotes_gpc() ? $_GET["q"] : addslashes($_GET["q"])); 25$extra = array("where" => array(), "having" => array()); 26foreach ($extraf as $z) 27{ 28 while (preg_match($z["regex"], $q, $regs)) 29 { 30 array_push($extra[$z["sqlpart"]], sprintf($z["sql"], $regs[1])); 31 $q = preg_replace($z["regex"], "", $q); 32 } 33} 34 35$regs = array(); 36/* this *could* be put into $extraf, but it would change the semantics slightly, in that any number searched for would be treated as a bug #, which i think is undesirable */ 37if (preg_match("/^\s*\[?(\d+)\]?\s*$/", $_GET["q"], $regs)) 38{ 39 $_GET["q"] = $regs[1]; 40 $where = "WHERE `bugid` = $regs[1]"; 41 $et = "Bug #"; 42} 43else if (preg_match("/(\S)/", $q, $regs) || sizeof($extra["where"]) + sizeof($extra["having"]) > 0) 44{ 45 $match = "'1'"; 46 if (sizeof($regs) > 0) 47 { 48 $match = "MATCH(`message`) AGAINST('$q'" . (preg_match("/\".+\"/", $q) ? " IN BOOLEAN MODE" : "") . ")"; 49 } 50 $where = "WHERE " . ($match ? $match : "1"); 51 $where .= (sizeof($extra["where"]) > 0 ? " AND " . join($extra["where"], " AND ") : ""); 52 $having = (sizeof($extra["having"]) > 0 ? " HAVING " . join($extra["having"], " AND ") : ""); 53 $ec = ", $match AS `relevance`"; 54 $order = "ORDER BY `relevance` DESC, `date` DESC"; 55} 56?> 57<div id="midcolumn"> 58<div class="homeitem3col"> 59 <h3>Search</h3> 60 <div id="searchdiv"> 61 <form action="" method="get"> 62 <input type="text" size="60" id="q" name="q"<?php print ($_GET["q"] ? " value=\"" . sanitize($_GET["q"], "text") . "\"" : ""); ?>/> 63 <input type="submit" value="Go!"/> 64 </form> 65 </div> 66</div> 67<?php 68 69/* 1.1.2.x <- 1.1.0.2 = branch tag, likewise, 1.1.4.x <- 1.1.0.4 = branch tag, so dynamically rewrite a.b.c.d to a.b.0.c to find the branch tag */ 70$branch = "IF(`revision` LIKE '%.%.%.%', (SELECT `tagname` FROM `tags` NATURAL JOIN `filetags` WHERE `fid` = `ofid` AND `revision` = CONCAT(SUBSTRING_INDEX(`orev`, '.', 2), '.0.', SUBSTRING_INDEX(SUBSTRING_INDEX(`orev`, '.', -2), '.', 1))), 'HEAD')"; 71$sql = "SELECT SQL_CALC_FOUND_ROWS `cvsname`, `revision`, `date`, `author`, `message`, `keyword_subs`, `bugid`, `revision` AS `orev`, `fid` AS `ofid`, $branch AS `branch`$ec FROM `cvsfiles` NATURAL JOIN `commits` NATURAL LEFT JOIN `bugs` $where GROUP BY `fid`, `revision`, `bugid` $having $order LIMIT $offset, $pagesize"; 72$result = wmysql_query($sql); 73 74$count = wmysql_query("SELECT FOUND_ROWS()"); //mysql_num_rows() doesn't do what we want here 75$row = mysql_fetch_row($count); 76$rows = $row[0]; 77 78$title = "<span>$rows results total</span>Showing results " . ($offset + 1) . "-" . ($offset + $pagesize > $rows ? $rows : $offset + $pagesize) . " for " . ($_GET["q"] == "" ? "last $days days of commits" : "$et" . sanitize($_GET["q"], "text")); 79$title = ($rows == 0 ? "No results found for " . sanitize($_GET["q"], "text") . "" : $title); 80 81print "<div class=\"homeitem3col\">\n"; 82print "<h3>$title</h3>\n"; 83 84dopager($rows, $page, $pagesize); 85 86print "<ul>\n"; 87 88while ($row = mysql_fetch_assoc($result)) 89{ 90 $file = basename($row["cvsname"], ",v"); 91 $row["cvsname"] = preg_replace("#^/cvsroot/[^\/]+/(.+),v$#", "$1", $row["cvsname"]); 92 print "<li>\n"; 93 print "<div>{$row['date']}</div>"; 94 print ($row["bugid"] ? "[<a href=\"https://bugs.eclipse.org/bugs/show_bug.cgi?id={$row['bugid']}\">{$row['bugid']}</a>] " : ""); 95 print "<a href=\"" . cvsfile($row["cvsname"]) . "\"><abbr title=\"{$row['cvsname']}\">$file</abbr></a> ({$row['branch']} " . showrev($row['revision'], $row["cvsname"]) . ")"; 96 print "<ul>\n"; 97 print "<li><div>{$row['author']}</div>" . pretty_comment($row["message"], $q) . "</li>"; 98 print "</ul>\n"; 99 print "</li>\n"; 100} 101print "</ul>\n"; 102 103dopager($rows, $page, $pagesize); 104 105print "</div>\n"; 106print "</div>\n"; 107mysql_close($connect); 108?> 109<div id="rightcolumn"> 110 <div class="sideitem"> 111 <h6>Help</h6> 112 <p><a href="http://wiki.eclipse.org/index.php/Search_CVS">Consult the wiki</a>, or try these examples:</p> 113 <ul> 114 <li><a href="?q=%5B155286%5D">[155286]</a></li> 115 <li><a href="?q=98877+file%3A+ChangeAdapter">98877 file: ChangeAdapter</a></li> 116 <li><a href="?q=file%3A+org.eclipse.emf%2F+days%3A+7">file: org.eclipse.emf/ days: 7</a></li> 117 <li><a href="?q=days%3A200+author%3Amerks">days:200 author:merks</a></li> 118 <li><a href="?q=branch%3A+R2_1_+file%3A+.xml">branch: R2_1_ file: .xml</a></li> 119 <li><a href="?q=static+dynamic+project%3A+org.eclipse.emf">static dynamic project: org.eclipse.emf</a></li> 120 <li><a href="?q=%22package+protected%22">"package protected"</a></li> 121 <li><a href="?q=Neil+Skrypuch">Neil Skrypuch</a></li> 122 </ul> 123 <p>See also the complete <a href="http://wiki.eclipse.org/index.php/Search_CVS#Parameter_List">Parameter List</a>.</p> 124 </div> 125</div> 126<?php 127$html = ob_get_contents(); 128ob_end_clean(); 129 130$pageTitle = "Eclipse Tools - Search CVS"; 131$pageKeywords = ""; 132$pageAuthor = "Neil Skrypuch"; 133 134$App->AddExtraHtmlHeader('<link rel="stylesheet" type="text/css" href="/emf/includes/searchcvs.css"/>' . "\n"); 135if (!isset($_GET["totalonly"])) 136{ 137 ob_start(); 138 $App->generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html); 139 $html = ob_get_contents(); 140 ob_end_clean(); 141 print preg_replace("/<body>/", "<body onload=\"document.getElementById('q').focus()\">", $html); 142} 143else 144{ 145 header("Content-Type: text/plain"); 146 print $rows; 147} 148 149function pretty_comment($str, $hl) 150{ 151 $str = preg_replace("/\n/", "<br/>", $str); 152 $hl = words($hl); 153 154 for ($i = 0; $i < sizeof($hl); $i++) 155 { 156 $str = preg_replace("/\b(\Q$hl[$i]\E)\b([^=]|\Z)/i", "<span class=\"hl$i\">$1</span>$2", $str); 157 } 158 159 $str = preg_replace("/^(\Q*** empty log message ***\E)$/", "<span class=\"empty\">$1</span>", $str); 160 161 return $str; 162} 163 164function cvsminus($rev) 165{ 166 if (preg_match("/^1\.1$/", $rev)) // "1.10" == "1.1" returns true, curiously enough 167 { 168 return $rev; 169 } 170 else 171 { 172 if (preg_match("/\.1$/", $rev)) 173 { 174 return preg_replace("/^(\d+\.\d+)\..+$/", "$1", $rev); 175 } 176 else 177 { 178 return preg_replace("/^(.+\.)(\d+)$/e", "\"$1\" . ($2 - 1);", $rev); 179 } 180 } 181} 182 183function showrev($rev, $file) 184{ 185 $link = "<a href=\"" . cvsfile($file) . "\">$rev</a>"; 186 if (!preg_match("/^1\.1$/", $rev)) // "1.10" == "1.1" returns true, curiously enough 187 { 188 $oldrev = cvsminus($rev); 189 $link = "<a href=\"" . cvsfile($file, $rev, $oldrev) . "\">$rev > $oldrev</a>"; 190 } 191 192 return $link; 193} 194 195function cvsfile($file, $rev = "", $oldrev = "") 196{ 197 if ($rev && $oldrev) 198 { 199 $ext = ".diff"; 200 $params = "r1=$oldrev&r2=$rev&"; 201 } 202 $params .= (preg_match("/\.php$/", $file) && $ext != ".diff" ? "content-type=text/plain&" : ""); 203 204 if (preg_match("/^www/", $file)) 205 { 206 return "http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/$file$ext?${params}cvsroot=Eclipse_Website"; 207 } 208 else 209 { 210 return "http://dev.eclipse.org/viewcvs/indextools.cgi/~checkout~/$file$ext?$params"; 211 } 212} 213 214function sanitize($str, $type = "url") 215{ 216 $tmp = urlencode(urldecode((get_magic_quotes_gpc() ? stripslashes($str) : $str))); 217 return ($type == "url" ? $tmp : htmlspecialchars(urldecode($tmp))); 218} 219 220function pagelink($page, $selected, $linktext = "") 221{ 222 $innertext = ($linktext ? $linktext : $page); 223 $text = (!$selected ? "<a href=\"?q=" . sanitize($_GET["q"]) . "&p=$page\">$innertext</a>" : $innertext); 224 return "<span" . ($selected ? " class=\"selected\"" : "") . ">$text</span>"; 225} 226 227function dopager($rows, $page, $pagesize) 228{ 229 $startpage = ($page - 5 < 1 ? 1 : $page - 5); 230 $endpage = ($page + 5 > $rows/$pagesize ? ceil($rows/$pagesize) : $page + 5); 231 232 if ($rows > 0) 233 { 234 print "<div class=\"pager\">\n"; 235 print ($page > 1 ? pagelink($page - 1, false, "Previous") : ""); 236 for ($i = $startpage; $i <= $endpage; $i++) 237 { 238 print pagelink($i, $i == $page); 239 } 240 print ($page < ceil($rows/$pagesize) ? pagelink($page + 1, false, "Next") : ""); 241 print "</div>\n"; 242 } 243} 244 245function words($str) 246{ 247 $str = stripslashes($str); 248 $list = array(); 249 250 preg_match_all("/\"([^\"]+)\"/", $str, $regs); 251 foreach ($regs[1] as $word) 252 { 253 $word = addslashes($word); 254 $list[] = $word; 255 $str = preg_replace("/\Q$word\E/", "", $str); 256 } 257 258 $regs = null; 259 preg_match_all("/(\w+)/", $str, $regs); 260 foreach ($regs[1] as $word) 261 { 262 $list[] = addslashes($word); 263 } 264 265 return $list; 266} 267?> 268