recovering previous behaviour when enotif is switched off
[lhc/web/wiklou.git] / includes / Article.php
index e22da0b..dd563ba 100644 (file)
@@ -28,7 +28,7 @@ class Article {
         */
        var $mContent, $mContentLoaded;
        var $mUser, $mTimestamp, $mUserText;
-       var $mCounter, $mComment, $mCountAdjustment;
+       var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
        var $mMinorEdit, $mRedirectedFrom;
        var $mTouched, $mFileCache, $mTitle;
        var $mId, $mTable;
@@ -65,7 +65,7 @@ class Article {
                $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
                $this->mRedirectedFrom = $this->mUserText =
                $this->mTimestamp = $this->mComment = $this->mFileCache = '';
-               $this->mCountAdjustment = 0;
+               $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
                $this->mTouched = '19700101000000';
                $this->mForUpdate = false;
                $this->mIsRedirect = false;
@@ -848,7 +848,7 @@ class Article {
                        array( /* SET */
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
-                               'page_is_new'      => ($lastRevision === 0) ? 0 : 1,
+                               'page_is_new'      => ($lastRevision === 0) ? 1 : 0,
                                'page_is_redirect' => Article::isRedirect( $text ),
                                'page_len'         => strlen( $text ),
                        ),
@@ -906,7 +906,8 @@ class Article {
 
                $fname = 'Article::insertNewArticle';
 
-               $this->mCountAdjustment = $this->isCountable( $text );
+               $this->mGoodAdjustment = $this->isCountable( $text );
+               $this->mTotalAdjustment = 1;
 
                $ns = $this->mTitle->getNamespace();
                $ttl = $this->mTitle->getDBkey();
@@ -1120,8 +1121,9 @@ class Article {
                $lastRevision = 0;
 
                if ( 0 != strcmp( $text, $oldtext ) ) {
-                       $this->mCountAdjustment = $this->isCountable( $text )
+                       $this->mGoodAdjustment = $this->isCountable( $text )
                          - $this->isCountable( $oldtext );
+                       $this->mTotalAdjustment = 0;
                        $now = wfTimestampNow();
 
                        $lastRevision = $dbw->selectField(
@@ -1197,6 +1199,7 @@ class Article {
         */
        function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
                global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
+               global $wgUseEnotif;
 
                $wgLinkCache = new LinkCache();
                
@@ -1249,12 +1252,12 @@ class Article {
                        $r = '';
                $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
 
-               # this call would better fit into RecentChange::notifyEdit and RecentChange::notifyNew .
-               # this will be improved later (to-do)
-
-               include_once( "UserMailer.php" );
-               $wgEnotif = new EmailNotification ();
-               $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
+               if ( $wgUseEnotif  ) {
+                       # this would be better as an extension hook
+                       include_once( "UserMailer.php" );
+                       $wgEnotif = new EmailNotification ();
+                       $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid );
+               }
        }
 
        /**
@@ -1470,7 +1473,7 @@ class Article {
 
                wfDebug( "Article::confirmProtect\n" );
 
-               $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
+               $sub = $this->mTitle->getPrefixedText();
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
                $check = '';
@@ -1551,24 +1554,23 @@ class Article {
                # This code desperately needs to be totally rewritten
 
                # Check permissions
-               if ( ( ! $wgUser->isAllowed('delete') ) ) {
+               if( ( !$wgUser->isAllowed( 'delete' ) ) ) {
                        $wgOut->sysopRequired();
                        return;
                }
-               if ( wfReadOnly() ) {
+               if( wfReadOnly() ) {
                        $wgOut->readOnlyPage();
                        return;
                }
 
                # Better double-check that it hasn't been deleted yet!
                $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
-               if ( ( '' == trim( $this->mTitle->getText() ) )
-                 or ( $this->mTitle->getArticleId() == 0 ) ) {
+               if( !$this->mTitle->exists() ) {
                        $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
                        return;
                }
 
-               if ( $confirm ) {
+               if( $confirm ) {
                        $this->doDelete( $reason );
                        return;
                }
@@ -1600,8 +1602,8 @@ class Article {
                # Fetch name(s) of contributors
                $rev_name = '';
                $all_same_user = true;
-               while ( $row = $dbr->fetchObject( $revisions ) ) {
-                       if ( $rev_name != '' && $rev_name != $row->rev_user_text ) {
+               while( $row = $dbr->fetchObject( $revisions ) ) {
+                       if( $rev_name != '' && $rev_name != $row->rev_user_text ) {
                                $all_same_user = false;
                        } else {
                                $rev_name = $row->rev_user_text;
@@ -1614,44 +1616,39 @@ class Article {
 
                        #if this is empty, an earlier revision may contain "useful" text
                        $blanked = false;
-                       if($text == '') {
-                               $prevId = $this->mTitle->getPreviousRevisionID( $rev->getId() );
-                               $rev = Revision::newFromId( $prevId );
-                               if ( $rev ) { 
-                                       $text = $rev->getText();
+                       if( $text == '' ) {
+                               $prev = $rev->getPrevious();
+                               if( $prev ) { 
+                                       $text = $prev->getText();
                                        $blanked = true;
                                }
                        }
 
-                       $length=strlen($text);
+                       $length = strlen( $text );
 
                        # this should not happen, since it is not possible to store an empty, new
                        # page. Let's insert a standard text in case it does, though
-                       if($length == 0 && $reason === '') {
-                               $reason = wfMsg('exblank');
+                       if( $length == 0 && $reason === '' ) {
+                               $reason = wfMsg( 'exblank' );
                        }
 
-                       if($length < 500 && $reason === '') {
-
+                       if( $length < 500 && $reason === '' ) {
                                # comment field=255, let's grep the first 150 to have some user
                                # space left
-                               $text=substr($text,0,150);
-                               # let's strip out newlines and HTML tags
-                               $text=preg_replace('/\"/',"'",$text);
-                               $text=preg_replace('/\</','&lt;',$text);
-                               $text=preg_replace('/\>/','&gt;',$text);
-                               $text=preg_replace("/[\n\r]/",'',$text);
+                               global $wgContLang;
+                               $text = $wgContLang->truncate( $text, 150, '...' );
                                
-                               if( $length > 150 ) { $text .= '...'; } # we've only pasted part of the text
+                               # let's strip out newlines
+                               $text = preg_replace( "/[\n\r]/", '', $text );
                                
-                               if(!$blanked) {
-                                       if(!$all_same_user) {
-                                               $reason = wfMsg ( 'excontent', $text );
+                               if( !$blanked ) {
+                                       if( !$all_same_user ) {
+                                               $reason = wfMsg( 'excontent', $text );
                                        } else {
-                                               $reason = wfMsg ( 'excontentauthor', $text, $rev_name );
+                                               $reason = wfMsg( 'excontentauthor', $text, $rev_name );
                                        }
                                } else {
-                                       $reason = wfMsg ( 'exbeforeblank', $text );
+                                       $reason = wfMsg( 'exbeforeblank', $text );
                                }
                        }
                }
@@ -1718,14 +1715,10 @@ class Article {
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                                $wgOut->setRobotpolicy( 'noindex,nofollow' );
                                
-                               $sk = $wgUser->getSkin();
-                               $loglink = $sk->makeKnownLink( $wgContLang->getNsText( NS_SPECIAL ) .
-                                                                                          ':Log/delete',
-                                                                                          wfMsg( 'deletionlog' ) );
-                               
+                               $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
                                $text = wfMsg( 'deletedtext', $deleted, $loglink );
                                
-                               $wgOut->addHTML( '<p>' . $text . "</p>\n" );
+                               $wgOut->addWikiText( $text );
                                $wgOut->returnToMain( false );
                                wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
                        } else {
@@ -1755,7 +1748,7 @@ class Article {
                        return false;
                }
 
-               $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
+               $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ), -1 );
                array_push( $wgDeferredUpdateList, $u );
 
                $linksTo = $this->mTitle->getLinksTo();
@@ -1941,7 +1934,7 @@ class Article {
         * @private
         */
        function viewUpdates() {
-               global $wgDeferredUpdateList;
+               global $wgDeferredUpdateList, $wgUseEnotif;
                
                if ( 0 != $this->getID() ) {
                        global $wgDisableCounters;
@@ -1959,9 +1952,14 @@ class Article {
                if ($this->mTitle->getNamespace() == NS_USER_TALK &&
                        $this->mTitle->getText() == $wgUser->getName()) 
                {
-                       require_once( 'UserTalkUpdate.php' );
-                       $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false );
-               } else {
+                       if ( $wgUseEnotif ) {
+                               require_once( 'UserTalkUpdate.php' );
+                               $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false );
+                       } else {
+                               $wgUser->setNewtalk(0);
+                               $wgUser->saveNewtalk();
+                       }
+               } elseif ( $wgUseEnotif ) {
                        $wgUser->clearNotification( $this->mTitle );
                }
 
@@ -1975,7 +1973,7 @@ class Article {
         */
        function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
                global $wgDeferredUpdateList, $wgDBname, $wgMemc;
-               global $wgMessageCache, $wgUser;
+               global $wgMessageCache, $wgUser, $wgUseEnotif;
 
                wfSeedRandom();
                if ( 0 == mt_rand( 0, 999 ) ) {
@@ -1991,22 +1989,26 @@ class Article {
                $title = $this->mTitle->getPrefixedDBkey();
                $shortTitle = $this->mTitle->getDBkey();
 
-               $adj = $this->mCountAdjustment;
                if ( 0 != $id ) {
                        $u = new LinksUpdate( $id, $title );
                        array_push( $wgDeferredUpdateList, $u );
-                       $u = new SiteStatsUpdate( 0, 1, $adj );
+                       $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
                        array_push( $wgDeferredUpdateList, $u );
                        $u = new SearchUpdate( $id, $title, $text );
                        array_push( $wgDeferredUpdateList, $u );
 
-                       # If this is another user's talk page,
-                       # create a watchlist entry for this page
+                       # If this is another user's talk page, update newtalk
                        
-                       if ($this->mTitle->getNamespace() == NS_USER_TALK &&
-                               $shortTitle != $wgUser->getName()) {
-                               require_once( 'UserTalkUpdate.php' );
-                               $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary, $minoredit, $timestamp_of_pagechange);
+                       if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
+                               if ( $wgUseEnotif ) {
+                                       require_once( 'UserTalkUpdate.php' );
+                                       $u = new UserTalkUpdate( 1, $this->mTitle->getNamespace(), $shortTitle, $summary, 
+                                         $minoredit, $timestamp_of_pagechange);
+                               } else {
+                                       $other = User::newFromName($shortTitle);
+                                       $other->setNewtalk(1);
+                                       $other->saveNewtalk();
+                               }
                        }
 
                        if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
@@ -2222,18 +2224,17 @@ class Article {
                        $u = new SquidUpdate( $urls );
                        array_push( $wgPostCommitUpdateList, $u );
                }
-
-               # Clear persistent link cache
-               LinkCache::linksccClearLinksTo( $title_obj );
        }
 
        function onArticleDelete($title_obj) {
                $title_obj->touchLinks();
-               LinkCache::linksccClearLinksTo( $title_obj );
        }
+       
        function onArticleEdit($title_obj) {
-               LinkCache::linksccClearPage( $title_obj->getArticleID() );
+               // This would be an appropriate place to purge caches.
+               // Why's this not in here now?
        }
+       
        /**#@-*/
 
        /**