* (bug 5228) Workaround for broken LanguageConverter title overrides; avoid
[lhc/web/wiklou.git] / includes / Article.php
index 54f3777..8b48d50 100644 (file)
@@ -205,11 +205,6 @@ class Article {
        /**
         * Get the contents of a page from its title and remove includeonly tags
         *
-        * TODO FIXME: This is only here because of the inputbox extension and
-        * should be moved there
-        *
-        * @deprecated
-        *
         * @param string The title of the page
         * @return string The contents of the page
         */
@@ -351,8 +346,6 @@ class Article {
         * Load the revision (including text) into this object
         */
        function loadContent() {
-               global $wgOut, $wgRequest;
-
                if ( $this->mContentLoaded ) return;
 
                # Query variables :P
@@ -621,8 +614,6 @@ class Article {
         * @access private
         */
        function loadLastEdit() {
-               global $wgOut;
-
                if ( -1 != $this->mUser )
                        return;
 
@@ -978,23 +969,16 @@ class Article {
                $this->view();
        }
 
+       /**
+        * Handle action=purge
+        */
        function purge() {
-               global $wgUser, $wgRequest, $wgOut, $wgUseSquid;
-
-               if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() || ! wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
-                       // Invalidate the cache
-                       $this->mTitle->invalidateCache();
+               global $wgUser, $wgRequest, $wgOut;
 
-                       if ( $wgUseSquid ) {
-                               // Commit the transaction before the purge is sent
-                               $dbw = wfGetDB( DB_MASTER );
-                               $dbw->immediateCommit();
-
-                               // Send purge
-                               $update = SquidUpdate::newSimplePurge( $this->mTitle );
-                               $update->doUpdate();
+               if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
+                       if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
+                               $this->doPurge();
                        }
-                       $this->view();
                } else {
                        $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
                        $action = $this->mTitle->escapeLocalURL( 'action=purge' );
@@ -1009,6 +993,26 @@ class Article {
                        $wgOut->addHTML( $msg );
                }
        }
+       
+       /**
+        * Perform the actions of a page purging
+        */
+       function doPurge() {
+               global $wgUseSquid;
+               // Invalidate the cache
+               $this->mTitle->invalidateCache();
+
+               if ( $wgUseSquid ) {
+                       // Commit the transaction before the purge is sent
+                       $dbw = wfGetDB( DB_MASTER );
+                       $dbw->immediateCommit();
+
+                       // Send purge
+                       $update = SquidUpdate::newSimplePurge( $this->mTitle );
+                       $update->doUpdate();
+               }
+               $this->view();
+       }
 
        /**
         * Insert a new empty page record for this article.
@@ -1126,7 +1130,7 @@ class Article {
         * @access private
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
-               global $wgOut, $wgUser, $wgUseSquid;
+               global $wgUser;
 
                $fname = 'Article::insertNewArticle';
                wfProfileIn( $fname );
@@ -1181,10 +1185,10 @@ class Article {
                }
 
                if ($watchthis) {
-                       if(!$this->mTitle->userIsWatching()) $this->watch();
+                       if(!$this->mTitle->userIsWatching()) $this->doWatch();
                } else {
                        if ( $this->mTitle->userIsWatching() ) {
-                               $this->unwatch();
+                               $this->doUnwatch();
                        }
                }
 
@@ -1317,7 +1321,7 @@ class Article {
         * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               global $wgOut, $wgUser, $wgDBtransactions, $wgMwRedir, $wgUseSquid;
+               global $wgUser, $wgDBtransactions, $wgUseSquid;
                global $wgPostCommitUpdateList, $wgUseFileCache;
 
                $fname = 'Article::updateArticle';
@@ -1407,14 +1411,14 @@ class Article {
                                if (!$this->mTitle->userIsWatching()) {
                                        $dbw->immediateCommit();
                                        $dbw->begin();
-                                       $this->watch();
+                                       $this->doWatch();
                                        $dbw->commit();
                                }
                        } else {
                                if ( $this->mTitle->userIsWatching() ) {
                                        $dbw->immediateCommit();
                                        $dbw->begin();
-                                       $this->unwatch();
+                                       $this->doUnwatch();
                                        $dbw->commit();
                                }
                        }
@@ -1463,8 +1467,7 @@ class Article {
         * the link tables and redirect to the new page.
         */
        function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
-               global $wgOut, $wgUser;
-               global $wgUseEnotif;
+               global $wgOut;
 
                $fname = 'Article::showArticle';
                wfProfileIn( $fname );
@@ -1523,7 +1526,7 @@ class Article {
        }
 
        /**
-        * Add this page to $wgUser's watchlist
+        * User-interface handler for the "watch" action
         */
 
        function watch() {
@@ -1538,14 +1541,8 @@ class Article {
                        $wgOut->readOnlyPage();
                        return;
                }
-
-               if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
-
-                       $wgUser->addWatch( $this->mTitle );
-                       $wgUser->saveSettings();
-
-                       wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
-
+               
+               if( $this->doWatch() ) {
                        $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,follow' );
 
@@ -1556,11 +1553,30 @@ class Article {
 
                $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
        }
-
+       
        /**
-        * Stop watching a page
+        * Add this page to $wgUser's watchlist
+        * @return bool true on successful watch operation
         */
+       function doWatch() {
+               global $wgUser;
+               if( $wgUser->isAnon() ) {
+                       return false;
+               }
+               
+               if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
+                       $wgUser->addWatch( $this->mTitle );
+                       $wgUser->saveSettings();
 
+                       return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
+               }
+               
+               return false;
+       }
+
+       /**
+        * User interface handler for the "unwatch" action.
+        */
        function unwatch() {
 
                global $wgUser, $wgOut;
@@ -1573,14 +1589,8 @@ class Article {
                        $wgOut->readOnlyPage();
                        return;
                }
-
-               if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
-
-                       $wgUser->removeWatch( $this->mTitle );
-                       $wgUser->saveSettings();
-
-                       wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
-
+               
+               if( $this->doUnwatch() ) {
                        $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,follow' );
 
@@ -1591,6 +1601,26 @@ class Article {
 
                $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
        }
+       
+       /**
+        * Stop watching a page
+        * @return bool true on successful unwatch
+        */
+       function doUnwatch() {
+               global $wgUser;
+               if( $wgUser->isAnon() ) {
+                       return false;
+               }
+
+               if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
+                       $wgUser->removeWatch( $this->mTitle );
+                       $wgUser->saveSettings();
+
+                       return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
+               }
+               
+               return false;
+       }
 
        /**
         * action=protect handler
@@ -1616,7 +1646,7 @@ class Article {
         * @return bool true on success
         */
        function updateRestrictions( $limit = array(), $reason = '' ) {
-               global $wgUser, $wgOut, $wgRequest;
+               global $wgUser;
 
                if ( !$wgUser->isAllowed( 'protect' ) ) {
                        return false;
@@ -1892,7 +1922,7 @@ class Article {
         * Perform a deletion and output success or failure messages
         */
        function doDelete( $reason ) {
-               global $wgOut, $wgUser, $wgContLang;
+               global $wgOut, $wgUser;
                $fname = 'Article::doDelete';
                wfDebug( $fname."\n" );
 
@@ -1921,7 +1951,7 @@ class Article {
         * Returns success
         */
        function doDeleteArticle( $reason ) {
-               global $wgUser, $wgUseSquid, $wgDeferredUpdateList;
+               global $wgUseSquid, $wgDeferredUpdateList;
                global $wgPostCommitUpdateList, $wgUseTrackbacks;
 
                $fname = 'Article::doDeleteArticle';
@@ -2172,7 +2202,7 @@ class Article {
 
                # Parse the text
                $options = new ParserOptions;
-                $options->setTidy(true);
+               $options->setTidy(true);
                $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
 
                # Save it to the parser cache
@@ -2214,14 +2244,16 @@ class Article {
                # If this is another user's talk page, update newtalk
 
                if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
-                       $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 );
+                       if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
+                               $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 );
+                               }
                        }
                }
 
@@ -2290,7 +2322,6 @@ class Article {
                        $touched = $this->mTouched;
                        $cache = new CacheManager( $this->mTitle );
                        if($cache->isFileCacheGood( $touched )) {
-                               global $wgOut;
                                wfDebug( " tryFileCache() - about to load\n" );
                                $cache->loadFromFileCache();
                                return true;
@@ -2616,6 +2647,9 @@ class Article {
        function getUsedTemplates() {
                $result = array();
                $id = $this->mTitle->getArticleID();
+               if( $id == 0 ) {
+                       return array();
+               }
 
                $dbr =& wfGetDB( DB_SLAVE );
                $res = $dbr->select( array( 'templatelinks' ),