8 if( !defined( 'MEDIAWIKI' ) ) {
13 * Function converts an Javascript escaped string back into a string with
14 * specified charset (default is UTF-8).
15 * Modified function from http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
17 * @param $source String escaped with Javascript's escape() function
18 * @param $iconv_to String destination character set will be used as second paramether in the iconv function. Default is UTF-8.
21 function js_unescape($source, $iconv_to = 'UTF-8') {
24 $len = strlen ($source);
27 $charAt = substr ($source, $pos, 1);
30 $charAt = substr ($source, $pos, 1);
32 // we got a unicode character
34 $unicodeHexVal = substr ($source, $pos, 4);
35 $unicode = hexdec ($unicodeHexVal);
36 $decodedStr .= code2utf($unicode);
39 // we have an escaped ascii character
40 $hexVal = substr ($source, $pos, 2);
41 $decodedStr .= chr (hexdec ($hexVal));
45 $decodedStr .= $charAt;
50 if ($iconv_to != "UTF-8") {
51 $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
58 * Function coverts number of utf char into that character.
59 * Function taken from: http://sk2.php.net/manual/en/function.utf8-encode.php#49336
64 function code2utf($num){
68 return chr(($num>>6)+
192).chr(($num&63)+
128);
70 return chr(($num>>12)+
224).chr((($num>>6)&63)+
128).chr(($num&63)+
128);
72 return chr(($num>>18)+
240).chr((($num>>12)&63)+
128).chr((($num>>6)&63)+
128) .chr(($num&63)+
128);
76 function wfSajaxSearch( $term ) {
77 global $wgContLang, $wgOut;
82 $term = trim( $term );
83 $term = str_replace( ' ', '_', $wgContLang->ucfirst(
84 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
87 if ( strlen( str_replace( '_', '', $term ) )<3 )
90 $db = wfGetDB( DB_SLAVE
);
91 $res = $db->select( 'page', 'page_title',
92 array( 'page_namespace' => 0,
93 "page_title LIKE '". $db->strencode( $term) ."%'" ),
95 array( 'LIMIT' => $limit+
1 )
101 while ( ( $row = $db->fetchObject( $res ) ) && ( ++
$i <= $limit ) ) {
102 $nt = Title
::newFromDBkey( $row->page_title
);
103 $r .= '<li>' . $l->makeKnownLinkObj( $nt ) . "</li>\n";
106 $more = '<i>' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
107 wfMsg('moredotdotdot'),
108 "namespace=0&from=" . wfUrlEncode ( $term ) ) .
114 $subtitlemsg = ( Title
::newFromText($term) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
115 $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle !
117 $term_url = urlencode( $term );
118 $term_diplay = htmlspecialchars( str_replace( '_', ' ', $term ) );
119 $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">'
120 . wfMsgHtml( 'hideresults' ) . '</a></div>'
121 . '<h1 class="firstHeading">'.wfMsgHtml('search')
122 . '</h1><div id="contentSub">'. $subtitle . '</div><ul><li>'
123 . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
124 wfMsgHtml( 'searchcontaining', $term_diplay ),
125 "search={$term_url}&fulltext=Search" )
126 . '</li><li>' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
127 wfMsgHtml( 'searchnamed', $term_diplay ) ,
128 "search={$term_url}&go=Go" )
129 . "</li></ul><h2>" . wfMsgHtml( 'articletitles', $term_diplay ) . "</h2>"
130 . '<ul>' .$r .'</ul>'.$more;
132 $response = new AjaxResponse( $html );
134 $response->setCacheDuration( 30*60 );
140 * Called for AJAX watch/unwatch requests.
141 * @param $pagename Prefixed title string for page to watch/unwatch
142 * @param $watch String 'w' to watch, 'u' to unwatch
143 * @return String '<w#>' or '<u#>' on successful watch or unwatch,
144 * respectively, followed by an HTML message to display in the alert box; or
147 function wfAjaxWatch($pagename = "", $watch = "") {
149 // redirect to action=(un)watch, which will display the database lock
154 if('w' !== $watch && 'u' !== $watch) {
157 $watch = 'w' === $watch;
159 $title = Title
::newFromText($pagename);
164 $article = new Article($title);
165 $watching = $title->userIsWatching();
169 $dbw = wfGetDB(DB_MASTER
);
176 $dbw = wfGetDB(DB_MASTER
);
178 $article->doUnwatch();
183 return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
185 return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );