'QuickLink', 'authors'=> 'Fran Rodríguez', 'version'=> '0.6', 'url' => 'http://www.mediawiki.org/wiki/Extension:QuickLink', 'description'=> 'Edit page built-in search box which provides a very quick and efficient way of inserting internal links.' ); function wfAjaxLink() { global $wgUseAjax, $wgOut, $wgTitle; if (!$wgUseAjax) { wfDebug('wfAjaxLink: $wgUseAjax is not enabled, aborting extension setup.'); return; } } function wfQuickLink_NSSearch($str, $arr) { $len = strlen($str); foreach ($arr as $k => $v) if (!strcasecmp($str, substr($v, 0, $len))) return $k; return FALSE; } function wfAjaxQuickLink( $term ) { //configure the following to change settings $limit = 10; //number of results to spit back $location = 1; //set to 1 to search anywhere in the article name, set to 0 to search only at the begining global $wgCanonicalNamespaceNames, $wgNamespaceAliases; $response = new AjaxResponse(); $db = wfGetDB( DB_SLAVE ); $term = str_replace(' ', '_', $term); $use_ns = strstr($term, ':', true); $search_ns = "TRUE"; if ($use_ns) { $ns_number = wfQuickLink_NSSearch($use_ns, $wgCanonicalNamespaceNames); if ($ns_number === FALSE) $ns_number = wfQuickLink_NSSearch($use_ns, $wgNamespaceAliases); if ($ns_number !== FALSE) { $ons_number = $ns_number; if ($ns_number == NS_MEDIA) $ns_number = NS_FILE; $search_ns = "page_namespace=".$ns_number; $term = preg_replace('/^[^:]+:/', '', $term); } } if($location == 1){ $res = $db->select( 'page', array('page_namespace', 'page_title', 'page_is_redirect'), array( "UPPER(CONVERT(page_title USING utf8)) LIKE '%" .$db->strencode( strtoupper ($term)). "%'", $search_ns ), "wfSajaxSearch", array( 'LIMIT' => $limit ) ); }else{ $res = $db->select( 'page', array('page_namespace', 'page_title', 'page_is_redirect'), array( "UPPER(CONVERT(page_title USING utf8)) LIKE '". $db->strencode( strtoupper ($term)) ."%'", $search_ns ), "wfSajaxSearch", array( 'LIMIT' => $limit ) ); } $r = ""; $i = 0; while ($row = $db->fetchObject( $res ) ){ if ($row->page_is_redirect) $redir = ''; else $redir = ''; if($row->page_namespace > 0) { $pns = $row->page_namespace; if ($ons_number == NS_MEDIA) $pns = $ons_number; // For all namespaces except main, add 'namespace:' to link. $tmp_link = $wgCanonicalNamespaceNames[$pns].":"; } else { // For main namespace, just add page name. $tmp_link = ""; } $r .= '
  • '.$redir.$tmp_link.str_replace('_', ' ', $row->page_title). ($row->page_is_redirect ? '' : '') . "
  • \n"; $i++; } if ($r == "") { $html = "

    No results found with the term '$term'"; $html .= "

    Edit to search again

    "; } else $html = ""; return $html; } function wfAjaxQuickLinkHeaders(){ global $wgOut; wfAjaxSetQuickLinkHeaders($wgOut); return true; } function wfAjaxSetQuickLinkHeaders($outputPage) { global $wgJsMimeType, $wgStylePath, $wgScriptPath; $outputPage->addLink( array( 'rel' => 'stylesheet', 'type' => 'text/css', 'href' => $wgScriptPath.'/extensions/QuickLink/QuickLink.css' ) ); $outputPage->addScript( "\n"); $outputPage->addScript( "\n" ); }