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 = str_replace( ' ', '_', $wgContLang->ucfirst(
83 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
86 if ( strlen( str_replace( '_', '', $term ) )<3 )
89 $db = wfGetDB( DB_SLAVE
);
90 $res = $db->select( 'page', 'page_title',
91 array( 'page_namespace' => 0,
92 "page_title LIKE '". $db->strencode( $term) ."%'" ),
94 array( 'LIMIT' => $limit+
1 )
100 while ( ( $row = $db->fetchObject( $res ) ) && ( ++
$i <= $limit ) ) {
101 $nt = Title
::newFromDBkey( $row->page_title
);
102 $r .= '<li>' . $l->makeKnownLinkObj( $nt ) . "</li>\n";
105 $more = '<i>' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
106 wfMsg('moredotdotdot'),
107 "namespace=0&from=" . wfUrlEncode ( $term ) ) .
113 $subtitlemsg = ( Title
::newFromText($term) ?
'searchsubtitle' : 'searchsubtitleinvalid' );
114 $subtitle = $wgOut->parse( wfMsg( $subtitlemsg, wfEscapeWikiText($term) ) ); #FIXME: parser is missing mTitle !
116 $term = urlencode( $term );
117 $html = '<div style="float:right; border:solid 1px black;background:gainsboro;padding:2px;"><a onclick="Searching_Hide_Results();">'
118 . wfMsg( 'hideresults' ) . '</a></div>'
119 . '<h1 class="firstHeading">'.wfMsg('search')
120 . '</h1><div id="contentSub">'. $subtitle . '</div><ul><li>'
121 . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
122 wfMsg( 'searchcontaining', $term ),
123 "search=$term&fulltext=Search" )
124 . '</li><li>' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ),
125 wfMsg( 'searchnamed', $term ) ,
126 "search=$term&go=Go" )
127 . "</li></ul><h2>" . wfMsg( 'articletitles', $term ) . "</h2>"
128 . '<ul>' .$r .'</ul>'.$more;
130 $response = new AjaxResponse( $html );
132 $response->setCacheDuration( 30*60 );
138 * Called for AJAX watch/unwatch requests.
139 * @param $pageID Integer ID of the page to be watched/unwatched
140 * @param $watch String 'w' to watch, 'u' to unwatch
141 * @return String '<w#>' or '<u#>' on successful watch or unwatch, respectively, or '<err#>' on error (invalid XML in case we want to add HTML sometime)
143 function wfAjaxWatch($pageID = "", $watch = "") {
145 return '<err#>'; // redirect to action=(un)watch, which will display the database lock message
147 if(('w' !== $watch && 'u' !== $watch) ||
!is_numeric($pageID))
149 $watch = 'w' === $watch;
150 $pageID = intval($pageID);
152 $title = Title
::newFromID($pageID);
155 $article = new Article($title);
156 $watching = $title->userIsWatching();
160 $dbw = wfGetDB(DB_MASTER
);
167 $dbw = wfGetDB(DB_MASTER
);
169 $article->doUnwatch();
174 return $watch ?
'<w#>' : '<u#>';