X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FAjaxFunctions.php;h=9e892f1abc52c8211d104c8bf5e42d1a1ab5fe7c;hb=28eff43b1de94d08677fab98b9c757c52aa0618c;hp=3580a293c5bb43f763c6f87b750ea960a75cb08e;hpb=698d8d66a7652660aa234811c153348ffc8b4907;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/AjaxFunctions.php b/includes/AjaxFunctions.php index 3580a293c5..9e892f1abc 100644 --- a/includes/AjaxFunctions.php +++ b/includes/AjaxFunctions.php @@ -1,9 +1,12 @@ policy = $policy; +/** + * 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 ''; } - function setPolicy( $policy ) { - $this->policy = $policy; + if('w' !== $watch && 'u' !== $watch) { + return ''; } + $watch = 'w' === $watch; - function writeHeader() { - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - if ( is_null( $this->policy ) ) { - // Bust cache in the head - header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past - // always modified - header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header ("Pragma: no-cache"); // HTTP/1.0 - } else { - header ("Expires: " . gmdate( "D, d M Y H:i:s", time() + $this->policy ) . " GMT"); - header ("Cache-Control: s-max-age={$this->policy},public,max-age={$this->policy}"); + $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(); + $ok = $article->doWatch(); + $dbw->commit(); + } + } else { + if($watching) { + $dbw = wfGetDB(DB_MASTER); + $dbw->begin(); + $ok = $article->doUnwatch(); + $dbw->commit(); } } -} - - -function wfSajaxSearch( $term ) { - global $wgContLang, $wgAjaxCachePolicy; - $limit = 16; - - $l = new Linker; - - $term = str_replace( ' ', '_', $wgContLang->ucfirst( - $wgContLang->checkTitleEncoding( $wgContLang->recodeInput( js_unescape( $term ) ) ) - ) ); - - if ( strlen( str_replace( '_', '', $term ) )<3 ) - return; - - $wgAjaxCachePolicy->setPolicy( 30*60 ); - - $db =& wfGetDB( DB_SLAVE ); - $res = $db->select( 'page', 'page_title', - array( 'page_namespace' => 0, - "page_title LIKE '". $db->strencode( $term) ."%'" ), - "wfSajaxSearch", - array( 'LIMIT' => $limit+1 ) - ); - - $r = ""; - - $i=0; - while ( ( $row = $db->fetchObject( $res ) ) && ( ++$i <= $limit ) ) { - $nt = Title::newFromDBkey( $row->page_title ); - $r .= '
  • ' . $l->makeKnownLinkObj( $nt ) . "
  • \n"; + // Something stopped the change + if( isset($ok) && !$ok ) { + return ''; } - if ( $i > $limit ) { - $more = '' . $l->makeKnownLink( $wgContLang->specialPage( "Allpages" ), - wfMsg('moredotdotdot'), - "namespace=0&from=" . wfUrlEncode ( $term ) ) . - ''; + if( $watch ) { + return ''.wfMsgExt( 'addedwatchtext', array( 'parse' ), $title->getPrefixedText() ); } else { - $more = ''; + return ''.wfMsgExt( 'removedwatchtext', array( 'parse' ), $title->getPrefixedText() ); } - - $term = htmlspecialchars( $term ); - return '' - . '

    '.wfMsg('search') - . '

    '.wfMsg('searchquery', $term) . '
    • ' - . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ), - wfMsg( 'searchcontaining', $term ), - "search=$term&fulltext=Search" ) - . '
    • ' . $l->makeKnownLink( $wgContLang->specialPage( 'Search' ), - wfMsg( 'searchnamed', $term ) , - "search=$term&go=Go" ) - . "

    " . wfMsg( 'articletitles', $term ) . "

    " - . '
      ' .$r .'
    '.$more; } - -?>