>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 '';
}
function wfSajaxSearch( $term ) {
global $wgContLang, $wgOut, $wgUser;
$limit = 16;
$sk = $wgUser->getSkin();
$term = trim( $term );
$term = str_replace( ' ', '_', $wgContLang->ucfirst(
$wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) )
) );
$term_title = Title::newFromText( $term );
$r = $more = '';
$canSearch = true;
if( $term_title && $term_title->getNamespace() != NS_SPECIAL ) {
$db = wfGetDB( DB_SLAVE );
$res = $db->select( 'page', array( 'page_title', 'page_namespace' ),
array( 'page_namespace' => $term_title->getNamespace(),
"page_title LIKE '". $db->strencode( $term_title->getDBKey() ) ."%'" ),
"wfSajaxSearch",
array( 'LIMIT' => $limit+1 )
);
$i = 0;
while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) {
$nt = Title::newFromText( $row->page_title, $row->page_namespace );
$r .= '
' . $sk->makeKnownLinkObj( $nt ) . "\n";
}
if ( $i > $limit ) {
$more = '' . $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
wfMsg('moredotdotdot'),
"namespace=0&from=" . wfUrlEncode ( $term ) ) .
'';
}
} else if( $term_title && $term_title->getNamespace() == NS_SPECIAL ) {
SpecialPage::initList();
SpecialPage::initAliasList();
$specialPages = array_merge(
array_keys( SpecialPage::$mList ),
array_keys( SpecialPage::$mAliases )
);
foreach( $specialPages as $page ) {
if( $wgContLang->uc( $page ) != $page && strpos( $page, $term_title->getText() ) === 0 ) {
$r .= '' . $sk->makeKnownLinkObj( Title::newFromText( $page, NS_SPECIAL ) ) . '';
}
}
$canSearch = false;
}
$valid = (bool) $term_title;
$term_url = urlencode( $term );
$term_diplay = htmlspecialchars( $valid ? $term_title->getFullText() : str_replace( '_', ' ', $term ) );
$subtitlemsg = ( $valid ? 'searchsubtitle' : 'searchsubtitleinvalid' );
$subtitle = wfMsgWikiHtml( $subtitlemsg, $term_diplay );
$html = ''
. ''.wfMsgHtml('search')
. '
'. $subtitle . '
';
if( $canSearch ) {
$html .= '- '
. $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
wfMsgHtml( 'searchcontaining', $term_diplay ),
"search={$term_url}&fulltext=Search" )
. '
- ' . $sk->makeKnownLink( $wgContLang->specialPage( 'Search' ),
wfMsgHtml( 'searchnamed', $term_diplay ) ,
"search={$term_url}&go=Go" )
. "
";
}
if( $r ) {
$html .= "" . wfMsgHtml( 'articletitles', $term_diplay ) . "
"
. '' . $more;
}
$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::newFromText($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() );
}
}