>6)+192).chr(($num&63)+128); if ( $num<65536 ) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); if ( $num<2097152 ) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128); return ''; } define( 'AJAX_SEARCH_VERSION', 2 ); //AJAX search cache version function wfSajaxSearch( $term ) { global $wgContLang, $wgOut, $wgUser, $wgCapitalLinks, $wgMemc; $limit = 16; $sk = $wgUser->getSkin(); $output = ''; $term = trim( $term ); $term = $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ); if ( $wgCapitalLinks ) $term = $wgContLang->ucfirst( $term ); $term_title = Title::newFromText( $term ); $memckey = $term_title ? wfMemcKey( 'ajaxsearch', md5( $term_title->getFullText() ) ) : wfMemcKey( 'ajaxsearch', md5( $term ) ); $cached = $wgMemc->get($memckey); if( is_array( $cached ) && $cached['version'] == AJAX_SEARCH_VERSION ) { $response = new AjaxResponse( $cached['html'] ); $response->setCacheDuration( 30*60 ); return $response; } $r = $more = ''; $canSearch = true; $results = PrefixSearch::titleSearch( $term, $limit + 1 ); foreach( array_slice( $results, 0, $limit ) as $titleText ) { $r .= '
  • ' . $sk->makeKnownLink( $titleText ) . "
  • \n"; } // Hack to check for specials if( $results ) { $t = Title::newFromText( $results[0] ); if( $t && $t->getNamespace() == NS_SPECIAL ) { $canSearch = false; if( count( $results ) > $limit ) { $more = '' . $sk->makeKnownLinkObj( SpecialPage::getTitleFor( 'Specialpages' ), wfMsgHtml( 'moredotdotdot' ) ) . ''; } } else { if( count( $results ) > $limit ) { $more = '' . $sk->makeKnownLinkObj( SpecialPage::getTitleFor( "Allpages", $term ), wfMsgHtml( 'moredotdotdot' ) ) . ''; } } } $valid = (bool) $term_title; $term_url = urlencode( $term ); $term_diplay = htmlspecialchars( $valid ? $term_title->getFullText() : $term ); $subtitlemsg = ( $valid ? 'searchsubtitle' : 'searchsubtitleinvalid' ); $subtitle = wfMsgWikiHtml( $subtitlemsg, $term_diplay ); $html = '
    ' . wfMsgHtml( 'hideresults' ) . '
    ' . '

    '.wfMsgHtml('search') . '

    '. $subtitle . '
    '; if( $canSearch ) { $html .= '"; } if( $r ) { $html .= "

    " . wfMsgHtml( 'articletitles', $term_diplay ) . "

    " . '' . $more; } $wgMemc->set( $memckey, array( 'version' => AJAX_SEARCH_VERSION, 'html' => $html ), 30 * 60 ); $response = new AjaxResponse( $html ); $response->setCacheDuration( 30*60 ); return $response; } /** * Called for AJAX watch/unwatch requests. * @param $pagename Prefixed title string for page to watch/unwatch * @param $watch String 'w' to watch, 'u' to unwatch * @return String '' or '' on successful watch or unwatch, * respectively, followed by an HTML message to display in the alert box; or * '' on error */ function wfAjaxWatch($pagename = "", $watch = "") { if(wfReadOnly()) { // redirect to action=(un)watch, which will display the database lock // message return ''; } if('w' !== $watch && 'u' !== $watch) { return ''; } $watch = 'w' === $watch; $title = Title::newFromDBkey($pagename); if(!$title) { // Invalid title return ''; } $article = new Article($title); $watching = $title->userIsWatching(); if($watch) { if(!$watching) { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $article->doWatch(); $dbw->commit(); } } else { if($watching) { $dbw = wfGetDB(DB_MASTER); $dbw->begin(); $article->doUnwatch(); $dbw->commit(); } } if( $watch ) { return ''.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() ); } else { return ''.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() ); } }