Extension:FindTpl

=Form to search specified template in pages= Displays a search form for the template specified in the parameter. Search results are displayed below. Search results - a list of articles that caused a specific template given the input values of parameters.

Installation
To install this extension
 * Create file in your /extension directory: FindTpl.php (see section)
 * Add the following to :

Syntax


Code
";	}	$output = "";	$tt = Title::makeTitle( 10, $tpl_name );	$output .= "Find template : getFullURL."\">".$tpl_name." Parameters:     $form_inputs ";	if ($wgRequest->getVal("sender") == "findtpl") {		$output .= " Search results:";		$search_params = array;		foreach ($wgRequest->getValues as $key=>$value) {			if (strpos($key, "form_") === 0) {				if (strlen(strval($value)) > 0) {					$search_params[urldecode(substr($key, 5))] = strval($value);				}			}		}		$SQLQuery = " select p.`page_title`, p.`page_namespace`, t.`old_text` as page_text from `page` p			inner join `revision` r on p.`page_latest`=r.`rev_id` inner join `text` t on r.`rev_text_id`=t.`old_id` where p.`page_id` in 			(select distinct `tl_from` from `templatelinks` where `tl_title` = '$tpl_name') ";		$res = $dbr->query( $SQLQuery );		$search_res_output = '';		while ( $row = $dbr->fetchObject( $res ) ) {			$page_text = $row->page_text;			$nt = Title::makeTitle( $row->page_namespace, $row->page_title );			preg_match_all('/]*)}}/i', $page_text, $matches);			foreach ($matches[1] as $tpl_key=>$tpl_value) {				$arr_text = explode('|', $tpl_value);				$i = 1;				foreach ($arr_text as &$value) {					$value = explode('=', $value, 2);					if (isset($value[1])) {						$found_params[$value[0]] = trim($value[1]);					}					else {						$found_params[$i] = trim($value[0]);						$i++;					}				}				if (count($search_params)) {					$result = array_uintersect_uassoc($search_params, $found_params, "SearchCompare", "strcasecmp");					if ($result == $search_params) {						$search_res_output .= " getFullURL."\">".$nt->getPrefixedText."";						break;					}				}				else {					$search_res_output .= " getFullURL."\">".$nt->getPrefixedText.""; break; }			}		}		$dbr->freeResult( $res ); $wgHooks['ParserAfterTidy'][] = array('fnFindTplPositioning', urlencode($tpl_name)); }	if (strlen($search_res_output)) { $output .= $search_res_output; }	else if ($wgRequest->getInt("formsent")) { $output .= " Search result is empty."; }	$tpl_name_enc = urlencode($tpl_name); $output = "".str_replace("\n", "", $output)."</DIV>"; return $output; }

function SearchCompare($v1,$v2) { $v1 = strtolower($v1); $v2 = strtolower($v2); if ((stripos($v2, $v1) === 0) ||(stripos($v2, $v1) > 0)){ return 0; }	else { return 1; }	return -1; }

function fnFindTplPositioning ( $tpl_name_enc, &$parser, &$text) { $label = "FindTpl_$tpl_name_enc"; $text .= "<script language=\"Javascript\">document.getElementById(\"$label\").scrollIntoView(true); "; return true; } ?>