Hooks! Hoooooks!
[lhc/web/wiklou.git] / includes / Article.php
index 563191c..792fd7e 100644 (file)
@@ -300,8 +300,7 @@ class Article {
         * @access private
         */
        function pageData( &$dbr, $conditions ) {
-               return $dbr->selectRow( 'page',
-                       array(
+               $fields = array(
                                'page_id',
                                'page_namespace',
                                'page_title',
@@ -312,9 +311,14 @@ class Article {
                                'page_random',
                                'page_touched',
                                'page_latest',
-                               'page_len' ),
+                               'page_len' ) ;
+               wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) )       ;
+               $row = $dbr->selectRow( 'page',
+                       $fields,
                        $conditions,
                        'Article::pageData' );
+               wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) )   ;
+               return $row ;
        }
 
        function pageDataFromTitle( &$dbr, $title ) {
@@ -676,9 +680,9 @@ class Article {
         * the given title.
        */
        function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang, $wgContLang;
-               global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
-               global $wgEnotif, $wgParser, $wgParserCache, $wgUseTrackbacks;
+               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgContLang;
+               global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
+               global $wgParserCache, $wgUseTrackbacks;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
@@ -782,6 +786,7 @@ class Article {
                        }
                }
                if( !$outputDone ) {
+                       wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
                        # wrap user css and user js in pre and don't parse
                        # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
                        if (
@@ -854,9 +859,6 @@ class Article {
                if ($wgUseTrackbacks)
                        $this->addTrackbacks();
 
-               # Put link titles into the link cache
-               $wgOut->transformBuffer();
-
                # Add link titles as META keywords
                $wgOut->addMetaTags() ;
 
@@ -1077,8 +1079,7 @@ class Article {
         * @private
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
-               global $wgOut, $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
+               global $wgOut, $wgUser, $wgUseSquid;
 
                $fname = 'Article::insertNewArticle';
                wfProfileIn( $fname );
@@ -1263,9 +1264,8 @@ class Article {
         * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               global $wgOut, $wgUser;
-               global $wgDBtransactions, $wgMwRedir;
-               global $wgUseSquid, $wgInternalServer, $wgPostCommitUpdateList, $wgUseFileCache;
+               global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+               global $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
                wfProfileIn( $fname );
@@ -1309,6 +1309,7 @@ class Article {
                $oldsize = strlen( $oldtext );
                $newsize = strlen( $text );
                $lastRevision = 0;
+               $revisionId = 0;
 
                if ( 0 != strcmp( $text, $oldtext ) ) {
                        $this->mGoodAdjustment = $this->isCountable( $text )
@@ -1343,8 +1344,10 @@ class Article {
                                RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
                                        $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                        $revisionId );
-                               Article::onArticleEdit( $this->mTitle );
                                $dbw->commit();
+                               
+                               // Update caches outside the main transaction
+                               Article::onArticleEdit( $this->mTitle );
                        }
                }
 
@@ -1372,32 +1375,6 @@ class Article {
                        $this->editUpdates( $text, $summary, $minor, $now );
 
 
-                       $urls = array();
-                       # Template namespace
-                       # Purge all articles linking here
-                       if ( $this->mTitle->getNamespace() == NS_TEMPLATE) {
-                               $titles = $this->mTitle->getLinksTo();
-                               Title::touchArray( $titles );
-                               if ( $wgUseSquid ) {
-                                               foreach ( $titles as $title ) {
-                                                       $urls[] = $title->getInternalURL();
-                                               }
-                               }
-                       }
-
-                       # Squid updates
-                       if ( $wgUseSquid ) {
-                               $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
-                               $u = new SquidUpdate( $urls );
-                               array_push( $wgPostCommitUpdateList, $u );
-                       }
-
-                       # File cache
-                       if ( $wgUseFileCache ) {
-                               $cm = new CacheManager($this->mTitle);
-                               @unlink($cm->fileCacheName());
-                       }
-
                        $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
                wfRunHooks( 'ArticleSaveComplete',
@@ -1413,7 +1390,7 @@ class Article {
         * the link tables and redirect to the new page.
         */
        function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
-               global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
+               global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache;
                global $wgUseEnotif;
 
                $fname = 'Article::showArticle';
@@ -1453,13 +1430,7 @@ class Article {
                else
                        $r = '';
                $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
-
-               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 );
-               }
+               
                wfProfileOut( $fname );
        }
 
@@ -1747,7 +1718,7 @@ class Article {
         * UI entry point for page deletion
         */
        function delete() {
-               global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
+               global $wgUser, $wgOut, $wgRequest;
                $fname = 'Article::delete';
                $confirm = $wgRequest->wasPosted() &&
                        $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
@@ -1935,9 +1906,8 @@ class Article {
         * Returns success
         */
        function doDeleteArticle( $reason ) {
-               global $wgUser;
-               global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer, $wgPostCommitUpdateList;
-               global $wgUseTrackbacks;
+               global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+               global $wgPostCommitUpdateList, $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
                wfDebug( $fname."\n" );
@@ -2119,15 +2089,17 @@ class Article {
                        );
                }
 
-               # Save it!
+               # Get the edit summary
                $target = Revision::newFromId( $s->rev_id );
-               $newcomment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
+               $newComment = $wgRequest->getText( 'summary', $newComment );
 
+               # Save it!
                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
-               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
+               $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
 
-               $this->updateArticle( $target->getText(), $newcomment, 1, $this->mTitle->userIsWatching(), $bot );
+               $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
                Article::onArticleEdit( $this->mTitle );
 
                $dbw->commit();
@@ -2140,7 +2112,7 @@ class Article {
         * @private
         */
        function viewUpdates() {
-               global $wgDeferredUpdateList, $wgUseEnotif;
+               global $wgDeferredUpdateList;
 
                if ( 0 != $this->getID() ) {
                        global $wgDisableCounters;
@@ -2151,24 +2123,9 @@ class Article {
                        }
                }
 
-               # Update newtalk status if user is reading their own
-               # talk page
-
+               # Update newtalk / watchlist notification status
                global $wgUser;
-               if ($this->mTitle->getNamespace() == NS_USER_TALK &&
-                       $this->mTitle->getText() == $wgUser->getName())
-               {
-                       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 );
-               }
-
+               $wgUser->clearNotification( $this->mTitle );
        }
 
        /**
@@ -2178,10 +2135,9 @@ class Article {
         * @param string $text
         */
        function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
-               global $wgDeferredUpdateList, $wgDBname, $wgMemc;
-               global $wgMessageCache, $wgUser, $wgUseEnotif;
+               global $wgDeferredUpdateList, $wgMessageCache, $wgUser;
 
-               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', &$this ) ) {
+               if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
                        wfSeedRandom();
                        if ( 0 == mt_rand( 0, 999 ) ) {
                                # Periodically flush old entries from the recentchanges table.
@@ -2210,21 +2166,14 @@ class Article {
                        # If this is another user's talk page, update newtalk
 
                        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 );
-                                       if( is_null( $other ) && User::isIP( $shortTitle ) ) {
-                                               // An anonymous user
-                                               $other = new User();
-                                               $other->setName( $shortTitle );
-                                       }
-                                       if( $other ) {
-                                               $other->setNewtalk(1);
-                                               $other->saveNewtalk();
-                                       }
+                               $other = User::newFromName( $shortTitle );
+                               if( is_null( $other ) && User::isIP( $shortTitle ) ) {
+                                       // An anonymous user
+                                       $other = new User();
+                                       $other->setName( $shortTitle );
+                               }
+                               if( $other ) {
+                                       $other->setNewtalk( true );
                                }
                        }
 
@@ -2458,9 +2407,38 @@ class Article {
                }
        }
 
-       function onArticleEdit($title_obj) {
-               // This would be an appropriate place to purge caches.
-               // Why's this not in here now?
+       /**
+        * Purge caches on page update etc
+        */
+       function onArticleEdit( $title ) {
+               global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
+               
+               $urls = array();
+               
+               // Template namespace? Purge all articles linking here.
+               // FIXME: When a templatelinks table arrives, use it for all includes.
+               if ( $title->getNamespace() == NS_TEMPLATE) {
+                       $titles = $title->getLinksTo();
+                       Title::touchArray( $titles );
+                       if ( $wgUseSquid ) {
+                               foreach ( $titles as $link ) {
+                                       $urls[] = $link->getInternalURL();
+                               }
+                       }
+               }
+
+               # Squid updates
+               if ( $wgUseSquid ) {
+                       $urls = array_merge( $urls, $title->getSquidURLs() );
+                       $u = new SquidUpdate( $urls );
+                       array_push( $wgPostCommitUpdateList, $u );
+               }
+
+               # File cache
+               if ( $wgUseFileCache ) {
+                       $cm = new CacheManager( $title );
+                       @unlink( $cm->fileCacheName() );
+               }
        }
 
        /**#@-*/