+
+ /* static */ function incViewCount( $id )
+ {
+ $id = intval( $id );
+ global $wgHitcounterUpdateFreq;
+
+ if( $wgHitcounterUpdateFreq <= 1 ){ //
+ wfQuery("UPDATE cur SET cur_counter = cur_counter + 1 " .
+ "WHERE cur_id = $id", DB_WRITE);
+ return;
+ }
+
+ # Not important enough to warrant an error page in case of failure
+ $oldignore = wfIgnoreSQLErrors( true );
+
+ wfQuery("INSERT INTO hitcounter (hc_id) VALUES ({$id})", DB_WRITE);
+
+ $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
+ if( (rand() % $checkfreq != 0) or (wfLastErrno() != 0) ){
+ # Most of the time (or on SQL errors), skip row count check
+ wfIgnoreSQLErrors( $oldignore );
+ return;
+ }
+
+ $res = wfQuery("SELECT COUNT(*) as n FROM hitcounter", DB_WRITE);
+ $row = wfFetchObject( $res );
+ $rown = intval( $row->n );
+ if( $rown >= $wgHitcounterUpdateFreq ){
+ wfProfileIn( "Article::incViewCount-collect" );
+ $old_user_abort = ignore_user_abort( true );
+
+ wfQuery("LOCK TABLES hitcounter WRITE", DB_WRITE);
+ wfQuery("CREATE TEMPORARY TABLE acchits TYPE=HEAP ".
+ "SELECT hc_id,COUNT(*) AS hc_n FROM hitcounter ".
+ "GROUP BY hc_id", DB_WRITE);
+ wfQuery("DELETE FROM hitcounter", DB_WRITE);
+ wfQuery("UNLOCK TABLES", DB_WRITE);
+ wfQuery("UPDATE cur,acchits SET cur_counter=cur_counter + hc_n ".
+ "WHERE cur_id = hc_id", DB_WRITE);
+ wfQuery("DROP TABLE acchits", DB_WRITE);
+
+ ignore_user_abort( $old_user_abort );
+ wfProfileOut( "Article::incViewCount-collect" );
+ }
+ wfIgnoreSQLErrors( $oldignore );
+ }
+
+ # The onArticle*() functions are supposed to be a kind of hooks
+ # which should be called whenever any of the specified actions
+ # are done.
+ #
+ # This is a good place to put code to clear caches, for instance.
+
+ /* static */ function onArticleCreate($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+ # Do standard deferred updates after page edit.
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
+ $adj = $this->mCountAdjustment;
+
+ if ( 0 != $id ) {
+ $u = new LinksUpdate( $id, $title );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SiteStatsUpdate( 0, 1, $adj );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SearchUpdate( $id, $title, $text );
+ array_push( $wgDeferredUpdateList, $u );
+
+ $u = new UserTalkUpdate( 1, $title_obj->getNamespace(), $shortTitle );
+ array_push( $wgDeferredUpdateList, $u );
+
+ if ( $title_obj->getNamespace() == NS_MEDIAWIKI ) {
+ $wgMessageCache->replace( $shortTitle, $text );
+ }
+ }
+ if ( $wgEnablePersistentLC ) {
+ LinkCache::linksccClearBrokenLinksTo( $title );
+ }
+ if ( $wgEnableParserCache ) {
+ OutputPage::parsercacheClearBrokenLinksTo( $title );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
+ );
+ wfPurgeSquidServers($urlArr);
+ /* this needs to be done after LinksUpdate */
+ $u = new SquidUpdate($title_obj);
+ array_push( $wgDeferredUpdateList, $u );
+ }
+ }
+
+ /* static */ function onArticleDelete($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid, $wgDeferredUpdateList;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
+ if ( $wgEnablePersistentLC ) {
+ LinkCache::linksccClearLinksTo( $id );
+ }
+ if ( $wgEnableParserCache ) {
+ OutputPage::parsercacheClearLinksTo( $id );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL())
+ );
+ wfPurgeSquidServers($urlArr);
+
+ /* prepare the list of urls to purge */
+ $sql = "SELECT l_from FROM links WHERE l_to={$id}" ;
+ $res = wfQuery ( $sql, DB_READ ) ;
+ while ( $BL = wfFetchObject ( $res ) )
+ {
+ $t = Title::newFromDBkey( $BL->l_from) ;
+ $blurlArr[] = $wgInternalServer.wfLocalUrl( $t->getPrefixedURL() );
+ }
+ wfFreeResult ( $res ) ;
+ $u = new SquidUpdate( $title_obj, $blurlArr );
+ array_push( $wgDeferredUpdateList, $u );
+
+ }
+ }
+
+ /* static */ function onArticleEdit($title_obj,$text=''){
+ global $wgEnablePersistentLC, $wgEnableParserCache, $wgUseSquid;
+ global $wgDeferredUpdateList, $wgDBname, $wgMemc;
+ global $wgMessageCache, $wgInternalServer;
+
+ $id = $title_obj->getArticleID();
+ $title = $title_obj->getPrefixedDBkey();
+ $shortTitle = $title_obj->getDBkey();
+
+ $adj = $this->mCountAdjustment;
+
+ if ( 0 != $id ) {
+ $u = new LinksUpdate( $id, $title );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SiteStatsUpdate( 0, 1, $adj );
+ array_push( $wgDeferredUpdateList, $u );
+ $u = new SearchUpdate( $id, $title, $text );
+ array_push( $wgDeferredUpdateList, $u );
+
+ $u = new UserTalkUpdate( 1, $title_obj->getNamespace(), $shortTitle );
+ array_push( $wgDeferredUpdateList, $u );
+
+ if ( $title_obj->getNamespace() == NS_MEDIAWIKI ) {
+ $wgMessageCache->replace( $shortTitle, $text );
+ }
+ }
+ if ( $wgEnablePersistentLC ) {
+ LinkCache::linksccClearPage( $id );
+ }
+ if ( $wgEnableParserCache ) {
+ OutputPage::parsercacheClearPage( $id );
+ }
+ if ( $wgUseSquid ) {
+ $urlArr = Array(
+ $wgInternalServer.wfLocalUrl( $title_obj->getPrefixedURL()),
+ );
+ wfPurgeSquidServers($urlArr);
+ }
+ }