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, $wgUser;
79 $sk = $wgUser->getSkin();
81 $term = trim( $term );
82 $term = str_replace( ' ', '_', $wgContLang->ucfirst(
83 $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
85 $term_title = Title
::newFromText( $term );
89 if( $term_title && $term_title->getNamespace() != NS_SPECIAL
) {
90 $db = wfGetDB( DB_SLAVE
);
91 $res = $db->select( 'page', array( 'page_title', 'page_namespace' ),
92 array( 'page_namespace' => $term_title->getNamespace(),
93 "page_title LIKE '". $db->strencode( $term_title->getDBKey() ) ."%'" ),
95 array( 'LIMIT' => $limit+
1 )
99 while ( ( $row = $db->fetchObject( $res ) ) && ( ++
$i <= $limit ) ) {
100 $nt = Title
::newFromText( $row->page_title
, $row->page_namespace
);
101 $r .= '<li>' . $sk->makeKnownLinkObj( $nt ) . "</li>\n";
104 $more = '<i>' . $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
105 wfMsg('moredotdotdot'),
106 "namespace=0&from=" . wfUrlEncode ( $term ) ) .
109 } else if( $term_title && $term_title->getNamespace() == NS_SPECIAL
) {
110 SpecialPage
::initList();
111 SpecialPage
::initAliasList();
112 $specialPages = array_merge(
113 array_keys( SpecialPage
::$mList ),
114 array_keys( SpecialPage
::$mAliases )
117 foreach( $specialPages as $page ) {
118 if( $wgContLang->uc( $page ) != $page && strpos( $page, $term_title->getText() ) === 0 ) {
119 $r .= '<li>' . $sk->makeKnownLinkObj( Title
::newFromText( $page, NS_SPECIAL
) ) . '</li>';
126 $valid = (bool) $term_title;
127 $term_url = urlencode( $term );
128 $term_diplay = htmlspecialchars( $valid ?
$term_title->getFullText() : str_replace( '_', ' ', $term ) );
129 $subtitlemsg = ( $valid ?
'searchsubtitle' : 'searchsubtitleinvalid' );
130 $subtitle = wfMsgWikiHtml( $subtitlemsg, $term_diplay );
131 $html = '<div id="searchTargetHide"><a onclick="Searching_Hide_Results();">'
132 . wfMsgHtml( 'hideresults' ) . '</a></div>'
133 . '<h1 class="firstHeading">'.wfMsgHtml('search')
134 . '</h1><div id="contentSub">'. $subtitle . '</div>';
137 . $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
138 wfMsgHtml( 'searchcontaining', $term_diplay ),
139 "search={$term_url}&fulltext=Search" )
140 . '</li><li>' . $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
141 wfMsgHtml( 'searchnamed', $term_diplay ) ,
142 "search={$term_url}&go=Go" )
146 $html .= "<h2>" . wfMsgHtml( 'articletitles', $term_diplay ) . "</h2>"
147 . '<ul>' .$r .'</ul>' . $more;
150 $response = new AjaxResponse( $html );
152 $response->setCacheDuration( 30*60 );
158 * Called for AJAX watch/unwatch requests.
159 * @param $pagename Prefixed title string for page to watch/unwatch
160 * @param $watch String 'w' to watch, 'u' to unwatch
161 * @return String '<w#>' or '<u#>' on successful watch or unwatch,
162 * respectively, followed by an HTML message to display in the alert box; or
165 function wfAjaxWatch($pagename = "", $watch = "") {
167 // redirect to action=(un)watch, which will display the database lock
172 if('w' !== $watch && 'u' !== $watch) {
175 $watch = 'w' === $watch;
177 $title = Title
::newFromText($pagename);
182 $article = new Article($title);
183 $watching = $title->userIsWatching();
187 $dbw = wfGetDB(DB_MASTER
);
194 $dbw = wfGetDB(DB_MASTER
);
196 $article->doUnwatch();
201 return '<w#>'.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() );
203 return '<u#>'.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() );