Code housekeeping stuff (and barring any stuff-ups on my behalf, there should be...
[lhc/web/wiklou.git] / includes / Article.php
index 402bced..d85a24b 100644 (file)
@@ -4,17 +4,12 @@
  * @package MediaWiki
  */
 
-/**
- * Need the CacheManager to be loaded
- */
-require_once( 'CacheManager.php' );
-
 /**
  * Class representing a MediaWiki article and history.
  *
  * See design.txt for an overview.
  * Note: edit user interface and cache support functions have been
- * moved to separate EditPage and CacheManager classes.
+ * moved to separate EditPage and HTMLFileCache classes.
  *
  * @package MediaWiki
  */
@@ -53,7 +48,7 @@ class Article {
                $this->mOldId = $oldId;
                $this->clear();
        }
-       
+
        /**
         * Tell the page view functions that this view was redirected
         * from another page on the wiki.
@@ -84,13 +79,13 @@ class Article {
                                }
                        } else {
                                if( $rt->getNamespace() == NS_SPECIAL ) {
-                                       // Gotta hand redirects to special pages differently:
+                                       // Gotta handle redirects to special pages differently:
                                        // Fill the HTTP response "Location" header and ignore
                                        // the rest of the page we're on.
                                        //
                                        // This can be hard to reverse, so they may be disabled.
                                        
-                                       if( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) {
+                                       if( $rt->isSpecial( 'Userlogout' ) ) {
                                                // rolleyes
                                        } else {
                                                return $rt->getFullURL();
@@ -144,27 +139,11 @@ class Article {
         * @return Return the text of this revision
        */
        function getContent() {
-               global $wgRequest, $wgUser, $wgOut;
-
-               # Get variables from query string :P
-               $action = $wgRequest->getText( 'action', 'view' );
-               $section = $wgRequest->getText( 'section' );
-               $preload = $wgRequest->getText( 'preload' );
+               global $wgUser, $wgOut;
 
                wfProfileIn( __METHOD__ );
 
                if ( 0 == $this->getID() ) {
-                       if ( 'edit' == $action ) {
-                               wfProfileOut( __METHOD__ );
-
-                               # If requested, preload some text.
-                               $text=$this->getPreloadedText($preload);
-
-                               # We used to put MediaWiki:Newarticletext here if
-                               # $text was empty at this point.
-                               # This is now shown above the edit box instead.
-                               return $text;
-                       }
                        wfProfileOut( __METHOD__ );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
@@ -177,51 +156,11 @@ class Article {
                        return "<div class='noarticletext'>$ret</div>";
                } else {
                        $this->loadContent();
-                       if($action=='edit') {
-                               if($section!='') {
-                                       if($section=='new') {
-                                               wfProfileOut( __METHOD__ );
-                                               $text=$this->getPreloadedText($preload);
-                                               return $text;
-                                       }
-
-                                       # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
-                                       # comments to be stripped as well)
-                                       $rv=$this->getSection($this->mContent,$section);
-                                       wfProfileOut( __METHOD__ );
-                                       return $rv;
-                               }
-                       }
                        wfProfileOut( __METHOD__ );
                        return $this->mContent;
                }
        }
 
-       /**
-        * Get the contents of a page from its title and remove includeonly tags
-        *
-        * @param $preload String: the title of the page.
-        * @return string The contents of the page.
-        */
-       function getPreloadedText($preload) {
-               if ( $preload === '' )
-                       return '';
-               else {
-                       $preloadTitle = Title::newFromText( $preload );
-                       if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
-                               $rev=Revision::newFromTitle($preloadTitle);
-                               if ( is_object( $rev ) ) {
-                                       $text = $rev->getText();
-                                       // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
-                                       // its own mini-parser! -ævar
-                                       $text = preg_replace( '~</?includeonly>~', '', $text );
-                                       return $text;
-                               } else
-                                       return '';
-                       }
-               }
-       }
-
        /**
         * This function returns the text of a section, specified by a number ($section).
         * A section is text under a heading like == Heading == or \<h1\>Heading\</h1\>, or
@@ -232,6 +171,7 @@ class Article {
         * @param $text String: text to look in
         * @param $section Integer: section number
         * @return string text of the requested section
+        * @deprecated
         */
        function getSection($text,$section) {
                global $wgParser;
@@ -278,6 +218,7 @@ class Article {
                        # unused:
                        # $lastid = $oldid;
                }
+
                if ( !$oldid ) {
                        $oldid = 0;
                }
@@ -295,9 +236,6 @@ class Article {
 
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
-
-               $t = $this->mTitle->getPrefixedText();
-
                $this->mOldId = $oldid;
                $this->fetchContent( $oldid );
        }
@@ -634,13 +572,10 @@ class Article {
        function getContributors($limit = 0, $offset = 0) {
                # XXX: this is expensive; cache this info somewhere.
 
-               $title = $this->mTitle;
                $contribs = array();
                $dbr =& wfGetDB( DB_SLAVE );
                $revTable = $dbr->tableName( 'revision' );
                $userTable = $dbr->tableName( 'user' );
-               $encDBkey = $dbr->addQuotes( $title->getDBkey() );
-               $ns = $title->getNamespace();
                $user = $this->getUser();
                $pageId = $this->getId();
 
@@ -705,15 +640,16 @@ class Article {
                # diff page instead of the article.
 
                if ( !is_null( $diff ) ) {
-                       require_once( 'DifferenceEngine.php' );
                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
 
                        $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
                        // DifferenceEngine directly fetched the revision:
                        $this->mRevIdFetched = $de->mNewid;
                        $de->showDiffPage();
-
-                       if( $diff == 0 ) {
+                       
+                       // Needed to get the page's current revision
+                       $this->loadPageData();
+                       if( $diff == 0 || $diff == $this->mLatest ) {
                                # Run view updates for current revision only
                                $this->viewUpdates();
                        }
@@ -735,6 +671,7 @@ class Article {
                                return;
                        }
                }
+
                # Should the parser cache be used?
                $pcache = $wgEnableParserCache &&
                        intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
@@ -772,6 +709,7 @@ class Article {
                $outputDone = false;
                if ( $pcache ) {
                        if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
+                               wfRunHooks( 'ArticleViewHeader', array( &$this ) );
                                $outputDone = true;
                        }
                }
@@ -840,9 +778,6 @@ class Article {
                                if( !$wasRedirected && $this->isCurrent() ) {
                                        $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
                                }
-                               $targetUrl = $rt->escapeLocalURL();
-                               # fixme unused $titleText :
-                               $titleText = htmlspecialchars( $rt->getPrefixedText() );
                                $link = $sk->makeLinkObj( $rt );
 
                                $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
@@ -857,13 +792,13 @@ class Article {
                                # Display content, don't attempt to save to parser cache
                                # Don't show section-edit links on old revisions... this way lies madness.
                                if( !$this->isCurrent() ) {
-                                       $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
+                                       $oldEditSectionSetting = $wgOut->parserOptions()->setEditSection( false );
                                }
                                # Display content and don't save to parser cache
                                $wgOut->addPrimaryWikiText( $text, $this, false );
 
                                if( !$this->isCurrent() ) {
-                                       $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting );
+                                       $wgOut->parserOptions()->setEditSection( $oldEditSectionSetting );
                                }
                        }
                }
@@ -939,7 +874,7 @@ class Article {
                }
 
                if ((!$wgUser->isAllowed('delete'))) {
-                       $wgOut->sysopRequired();
+                       $wgOut->permissionRequired( 'delete' );
                        return;
                }
 
@@ -1053,32 +988,87 @@ class Article {
         *                          when different from the currently set value.
         *                          Giving 0 indicates the new page flag should
         *                          be set on.
+        * @param bool $lastRevIsRedirect If given, will optimize adding and 
+        *                                                      removing rows in redirect table.
         * @return bool true on success, false on failure
         * @private
         */
-       function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
+       function updateRevisionOn( &$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null ) {
                wfProfileIn( __METHOD__ );
 
+               $text = $revision->getText();
+               $rt = Title::newFromRedirect( $text );
+               
                $conditions = array( 'page_id' => $this->getId() );
                if( !is_null( $lastRevision ) ) {
                        # An extra check against threads stepping on each other
                        $conditions['page_latest'] = $lastRevision;
                }
 
-               $text = $revision->getText();
                $dbw->update( 'page',
                        array( /* SET */
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
                                'page_is_new'      => ($lastRevision === 0) ? 1 : 0,
-                               'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
+                               'page_is_redirect' => $rt !== NULL ? 1 : 0,
                                'page_len'         => strlen( $text ),
                        ),
                        $conditions,
                        __METHOD__ );
 
+               $result = $dbw->affectedRows() != 0;
+
+               if ($result) {
+                       // FIXME: Should the result from updateRedirectOn() be returned instead?
+                       $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect ); 
+               }
+               
                wfProfileOut( __METHOD__ );
-               return ( $dbw->affectedRows() != 0 );
+               return $result;
+       }
+
+       /**
+        * Add row to the redirect table if this is a redirect, remove otherwise. 
+        *
+        * @param Database $dbw
+        * @param $redirectTitle a title object pointing to the redirect target,
+        *                                                      or NULL if this is not a redirect  
+        * @param bool $lastRevIsRedirect If given, will optimize adding and 
+        *                                                      removing rows in redirect table.
+        * @return bool true on success, false on failure
+        * @private
+        */
+       function updateRedirectOn( &$dbw, $redirectTitle, $lastRevIsRedirect = null ) {
+
+               // Always update redirects (target link might have changed)
+               // Update/Insert if we don't know if the last revision was a redirect or not
+               // Delete if changing from redirect to non-redirect
+               $isRedirect = !is_null($redirectTitle);
+               if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
+
+                       wfProfileIn( __METHOD__ );
+
+                       if ($isRedirect) {
+
+                               // This title is a redirect, Add/Update row in the redirect table
+                               $set = array( /* SET */
+                                       'rd_namespace' => $redirectTitle->getNamespace(),
+                                       'rd_title'     => $redirectTitle->getDBkey(),
+                                       'rd_from'      => $this->getId(),
+                               );
+
+                               $dbw->replace( 'redirect', array( 'rd_from' ), $set, __METHOD__ );
+                       } else {
+                               // This is not a redirect, remove row from redirect table 
+                               $where = array( 'rd_from' => $this->getId() );
+                               $dbw->delete( 'redirect', $where, __METHOD__);
+                       }
+
+                       wfProfileOut( __METHOD__ );
+                       return ( $dbw->affectedRows() != 0 );
+               }
+               
+               return true;
        }
 
        /**
@@ -1093,7 +1083,7 @@ class Article {
 
                $row = $dbw->selectRow(
                        array( 'revision', 'page' ),
-                       array( 'rev_id', 'rev_timestamp' ),
+                       array( 'rev_id', 'rev_timestamp', 'page_is_redirect' ),
                        array(
                                'page_id' => $this->getId(),
                                'page_latest=rev_id' ),
@@ -1104,12 +1094,14 @@ class Article {
                                return false;
                        }
                        $prev = $row->rev_id;
+                       $lastRevIsRedirect = (bool)$row->page_is_redirect;
                } else {
                        # No or missing previous revision; mark the page as new
                        $prev = 0;
+                       $lastRevIsRedirect = null;
                }
 
-               $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
+               $ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
                wfProfileOut( __METHOD__ );
                return $ret;
        }
@@ -1153,7 +1145,7 @@ class Article {
         * @deprecated use Article::doEdit()
         */
        function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
-               $flags = EDIT_NEW | EDIT_DEFER_UPDATES |
+               $flags = EDIT_NEW | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $isminor ? EDIT_MINOR : 0 ) |
                        ( $suppressRC ? EDIT_SUPPRESS_RC : 0 );
 
@@ -1185,7 +1177,7 @@ class Article {
         * @deprecated use Article::doEdit()
         */
        function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
-               $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES |
+               $flags = EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY |
                        ( $minor ? EDIT_MINOR : 0 ) |
                        ( $forceBot ? EDIT_FORCE_BOT : 0 );
 
@@ -1234,6 +1226,8 @@ class Article {
         *          Mark the edit a "bot" edit regardless of user rights
         *      EDIT_DEFER_UPDATES
         *          Defer some of the updates until the end of index.php
+        *      EDIT_AUTOSUMMARY
+        *          Fill in blank summaries with generated text where possible
         * 
         * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected. 
         * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If 
@@ -1269,7 +1263,15 @@ class Article {
 
                # Silently ignore EDIT_MINOR if not allowed
                $isminor = ( $flags & EDIT_MINOR ) && $wgUser->isAllowed('minoredit');
-               $bot = $wgUser->isBot() || ( $flags & EDIT_FORCE_BOT );
+               $bot = $wgUser->isAllowed( 'bot' ) || ( $flags & EDIT_FORCE_BOT );
+
+               $oldtext = $this->getContent();
+               $oldsize = strlen( $oldtext );
+               $newsize = strlen( $text );
+
+               # Provide autosummaries if one is not provided.
+               if ($flags & EDIT_AUTOSUMMARY && $summary == '')
+                       $summary = $this->getAutosummary( $oldtext, $text, $flags );
 
                $text = $this->preSaveTransform( $text );
 
@@ -1284,9 +1286,6 @@ class Article {
                                $userAbort = ignore_user_abort( true );
                        }
 
-                       $oldtext = $this->getContent();
-                       $oldsize = strlen( $oldtext );
-                       $newsize = strlen( $text );
                        $lastRevision = 0;
                        $revisionId = 0;
 
@@ -1354,7 +1353,8 @@ class Article {
                                Article::onArticleEdit( $this->mTitle );
                                
                                # Update links tables, site stats, etc.
-                               $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
+                               $changed = ( strcmp( $oldtext, $text ) != 0 );
+                               $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, $changed );
                        }
                } else {
                        # Create new article
@@ -1396,7 +1396,7 @@ class Article {
                        $dbw->commit();
 
                        # Update links, etc.
-                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
+                       $this->editUpdates( $text, $summary, $isminor, $now, $revisionId, true );
 
                        # Clear caches
                        Article::onArticleCreate( $this->mTitle );
@@ -1470,7 +1470,7 @@ class Article {
                                $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
                                $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
                        }
-                       $rcTitle = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
+                       $rcTitle = SpecialPage::getTitleFor( 'Recentchanges' );
                        $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
                }
                else {
@@ -1499,7 +1499,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = $this->mTitle->getPrefixedText();
+                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
                        $text = wfMsg( 'addedwatchtext', $link );
                        $wgOut->addWikiText( $text );
                }
@@ -1519,7 +1519,6 @@ class Article {
                
                if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
                        $wgUser->addWatch( $this->mTitle );
-                       $wgUser->saveSettings();
 
                        return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
                }
@@ -1547,7 +1546,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = $this->mTitle->getPrefixedText();
+                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
                        $text = wfMsg( 'removedwatchtext', $link );
                        $wgOut->addWikiText( $text );
                }
@@ -1567,7 +1566,6 @@ class Article {
 
                if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
                        $wgUser->removeWatch( $this->mTitle );
-                       $wgUser->saveSettings();
 
                        return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
                }
@@ -1579,7 +1577,6 @@ class Article {
         * action=protect handler
         */
        function protect() {
-               require_once 'ProtectionForm.php';
                $form = new ProtectionForm( $this );
                $form->show();
        }
@@ -1693,7 +1690,7 @@ class Article {
 
                # Check permissions
                if( $wgUser->isAllowed( 'delete' ) ) {
-                       if( $wgUser->isBlocked() ) {
+                       if( $wgUser->isBlocked( !$confirm ) ) {
                                $wgOut->blockedPage();
                                return;
                        }
@@ -1874,7 +1871,7 @@ class Article {
                <tr>
                        <td>&nbsp;</td>
                        <td>
-                               <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
+                               <input type='submit' name='wpConfirmB' id='wpConfirmB' value=\"{$confirm}\" />
                        </td>
                </tr>
        </table>
@@ -1894,7 +1891,7 @@ class Article {
 
                if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
                        if ( $this->doDeleteArticle( $reason ) ) {
-                               $deleted = $this->mTitle->getPrefixedText();
+                               $deleted = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
 
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                                $wgOut->setRobotpolicy( 'noindex,nofollow' );
@@ -1918,7 +1915,7 @@ class Article {
         */
        function doDeleteArticle( $reason ) {
                global $wgUseSquid, $wgDeferredUpdateList;
-               global $wgPostCommitUpdateList, $wgUseTrackbacks;
+               global $wgUseTrackbacks;
 
                wfDebug( __METHOD__."\n" );
 
@@ -1962,29 +1959,36 @@ class Article {
                );
 
                # Now that it's safely backed up, delete it
-               $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
                $dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
 
-               if ($wgUseTrackbacks)
-                       $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+               # If using cascading deletes, we can skip some explicit deletes
+               if ( !$dbw->cascadingDeletes() ) {
 
-               # Clean up recentchanges entries...
-               $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+                       $dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
 
-               # Finally, clean up the link tables
-               $t = $this->mTitle->getPrefixedDBkey();
+                       if ($wgUseTrackbacks)
+                               $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
+
+                       # Delete outgoing links
+                       $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
+                       $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
+                       $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
+                       $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
+                       $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
+                       $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
+                       $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
+               }
+
+               # If using cleanup triggers, we can skip some manual deletes
+               if ( !$dbw->cleanupTriggers() ) {
+
+                       # Clean up recentchanges entries...
+                       $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
+               }
 
                # Clear caches
                Article::onArticleDelete( $this->mTitle );
 
-               # Delete outgoing links
-               $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
-               $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
-               $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
-               $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
-               $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
-               $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
-
                # Log the deletion
                $log = new LogPage( 'delete' );
                $log->addEntry( 'delete', $this->mTitle, $reason );
@@ -2028,8 +2032,6 @@ class Article {
                $bot = $wgRequest->getBool( 'bot' );
 
                # Replace all this user's current edits with the next one down
-               $tt = $this->mTitle->getDBKey();
-               $n = $this->mTitle->getNamespace();
 
                # Get the last editor
                $current = Revision::newFromTitle( $this->mTitle );
@@ -2137,9 +2139,14 @@ class Article {
         * Every 1000th edit, prune the recent changes table.
         * 
         * @private
-        * @param string $text
-        */
-       function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
+        * @param $text New text of the article
+        * @param $summary Edit summary
+        * @param $minoredit Minor edit
+        * @param $timestamp_of_pagechange Timestamp associated with the page change
+        * @param $newid rev_id value of the new revision
+        * @param $changed Whether or not the content actually changed
+        */
+       function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true ) {
                global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
 
                wfProfileIn( __METHOD__ );
@@ -2186,8 +2193,11 @@ class Article {
                array_push( $wgDeferredUpdateList, $u );
 
                # If this is another user's talk page, update newtalk
-
-               if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
+               # Don't do this if $changed = false otherwise some idiot can null-edit a
+               # load of user talk pages and piss people off, nor if it's a minor edit
+               # by a properly-flagged bot.
+               if( $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed
+                       && !($minoredit && $wgUser->isAllowed('nominornewtalk') ) ) {
                        if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
                                $other = User::newFromName( $shortTitle );
                                if( is_null( $other ) && User::isIP( $shortTitle ) ) {
@@ -2207,6 +2217,22 @@ class Article {
 
                wfProfileOut( __METHOD__ );
        }
+       
+       /**
+        * Perform article updates on a special page creation.
+        *
+        * @param Revision $rev
+        *
+        * @fixme This is a shitty interface function. Kill it and replace the
+        * other shitty functions like editUpdates and such so it's not needed
+        * anymore.
+        */
+       function createUpdates( $rev ) {
+               $this->mGoodAdjustment = $this->isCountable( $rev->getText() );
+               $this->mTotalAdjustment = 1;
+               $this->editUpdates( $rev->getText(), $rev->getComment(),
+                       $rev->isMinor(), wfTimestamp(), $rev->getId(), true );
+       }
 
        /**
         * Generate the navigation links when browsing through an article revisions
@@ -2220,6 +2246,10 @@ class Article {
        function setOldSubtitle( $oldid=0 ) {
                global $wgLang, $wgOut, $wgUser;
 
+               if ( !wfRunHooks( 'DisplayOldSubtitle', array(&$this, &$oldid) ) ) {
+                               return; 
+               }       
+
                $revision = Revision::newFromId( $oldid );
 
                $current = ( $oldid == $this->mLatest );
@@ -2228,18 +2258,28 @@ class Article {
                $lnk = $current
                        ? wfMsg( 'currentrevisionlink' )
                        : $lnk = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
+               $curdiff = $current
+                       ? wfMsg( 'diff' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=cur&oldid='.$oldid );
                $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
                $prevlink = $prev
                        ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
                        : wfMsg( 'previousrevision' );
+               $prevdiff = $prev
+                       ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=prev&oldid='.$oldid )
+                       : wfMsg( 'diff' );
                $nextlink = $current
                        ? wfMsg( 'nextrevision' )
                        : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
+               $nextdiff = $current
+                       ? wfMsg( 'diff' )
+                       : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'diff' ), 'diff=next&oldid='.$oldid );
                
                $userlinks = $sk->userLink( $revision->getUser(), $revision->getUserText() )
                                                . $sk->userToolLinks( $revision->getUser(), $revision->getUserText() );
                
-               $r = wfMsg( 'oldrevisionnavigation', $td, $lnk, $prevlink, $nextlink, $userlinks );
+               $r = "\n\t\t\t\t<div id=\"mw-revision-info\">" . wfMsg( 'revision-info', $td, $userlinks ) . "</div>\n" .
+                    "\n\t\t\t\t<div id=\"mw-revision-nav\">" . wfMsg( 'revision-nav', $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "</div>\n\t\t\t";
                $wgOut->setSubtitle( $r );
        }
 
@@ -2264,23 +2304,23 @@ class Article {
        function tryFileCache() {
                static $called = false;
                if( $called ) {
-                       wfDebug( " tryFileCache() -- called twice!?\n" );
+                       wfDebug( "Article::tryFileCache(): called twice!?\n" );
                        return;
                }
                $called = true;
                if($this->isFileCacheable()) {
                        $touched = $this->mTouched;
-                       $cache = new CacheManager( $this->mTitle );
+                       $cache = new HTMLFileCache( $this->mTitle );
                        if($cache->isFileCacheGood( $touched )) {
-                               wfDebug( " tryFileCache() - about to load\n" );
+                               wfDebug( "Article::tryFileCache(): about to load file\n" );
                                $cache->loadFromFileCache();
                                return true;
                        } else {
-                               wfDebug( " tryFileCache() - starting buffer\n" );
+                               wfDebug( "Article::tryFileCache(): starting buffer\n" );
                                ob_start( array(&$cache, 'saveToFileCache' ) );
                        }
                } else {
-                       wfDebug( " tryFileCache() - not cacheable\n" );
+                       wfDebug( "Article::tryFileCache(): not cacheable\n" );
                }
        }
 
@@ -2358,8 +2398,7 @@ class Article {
                        'comment'    => $comment,
                        'minor_edit' => $minor ? 1 : 0,
                        ) );
-               # fixme : $revisionId never used
-               $revisionId = $revision->insertOn( $dbw );
+               $revision->insertOn( $dbw );
                $this->updateRevisionOn( $dbw, $revision );
                $dbw->commit();
 
@@ -2408,7 +2447,7 @@ class Article {
                        if ($wgDBtype == 'mysql')
                                $dbw->query("LOCK TABLES $hitcounterTable WRITE");
                        $tabletype = $wgDBtype == 'mysql' ? "ENGINE=HEAP " : '';
-                       $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype".
+                       $dbw->query("CREATE TEMPORARY TABLE $acchitsTable $tabletype AS".
                                "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
                                'GROUP BY hc_id');
                        $dbw->query("DELETE FROM $hitcounterTable");
@@ -2458,7 +2497,7 @@ class Article {
                
                # File cache
                if ( $wgUseFileCache ) {
-                       $cm = new CacheManager( $title );
+                       $cm = new HTMLFileCache( $title );
                        @unlink( $cm->fileCacheName() );
                }
 
@@ -2473,8 +2512,6 @@ class Article {
        static function onArticleEdit( $title ) {
                global $wgDeferredUpdateList, $wgUseFileCache;
 
-               $urls = array();
-
                // Invalidate caches of articles which include this page
                $update = new HTMLCacheUpdate( $title, 'templatelinks' );
                $wgDeferredUpdateList[] = $update;
@@ -2484,7 +2521,7 @@ class Article {
 
                # Clear file cache
                if ( $wgUseFileCache ) {
-                       $cm = new CacheManager( $title );
+                       $cm = new HTMLFileCache( $title );
                        @unlink( $cm->fileCacheName() );
                }
        }
@@ -2610,6 +2647,85 @@ class Article {
                $dbr->freeResult( $res );
                return $result;
        }
+       
+       /**
+        * Return an auto-generated summary if the text provided is a redirect.
+        *
+        * @param  string $text The wikitext to check
+        * @return string '' or an appropriate summary
+        */
+       public static function getRedirectAutosummary( $text ) {
+               $rt = Title::newFromRedirect( $text );
+               if( is_object( $rt ) )
+                       return wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );
+               else
+                       return '';
+       }
+
+       /**
+        * Return an auto-generated summary if the new text is much shorter than
+        * the old text.
+        *
+        * @param  string $oldtext The previous text of the page
+        * @param  string $text    The submitted text of the page
+        * @return string An appropriate autosummary, or an empty string.
+        */
+       public static function getBlankingAutosummary( $oldtext, $text ) {
+               if ($oldtext!='' && $text=='') {
+                       return wfMsgForContent('autosumm-blank');
+               } elseif (strlen($oldtext) > 10 * strlen($text) && strlen($text) < 500) {
+                       #Removing more than 90% of the article
+                       global $wgContLang;
+                       $truncatedtext = $wgContLang->truncate($text, max(0, 200 - strlen(wfMsgForContent('autosumm-replace'))), '...');
+                       return wfMsgForContent('autosumm-replace', $truncatedtext);
+               } else {
+                       return '';
+               }
+       }
+
+       /**
+       * Return an applicable autosummary if one exists for the given edit.
+       * @param string $oldtext The previous text of the page.
+       * @param string $newtext The submitted text of the page.
+       * @param bitmask $flags A bitmask of flags submitted for the edit.
+       * @return string An appropriate autosummary, or an empty string.
+       */
+       public static function getAutosummary( $oldtext, $newtext, $flags ) {
+
+               # This code is UGLY UGLY UGLY.
+               # Somebody PLEASE come up with a more elegant way to do it.
+
+               $summary = '';
+
+               #Blanking autosummaries
+               if (!($flags & EDIT_NEW))
+                       $summary = self::getBlankingAutosummary( $oldtext, $newtext );
+
+               if ($summary)
+                       return $summary;
+
+               #New redirect autosummaries.
+               if ( $flags & EDIT_NEW ) {
+                       $summary = self::getRedirectAutosummary( $newtext );
+               }
+
+               if ($summary)
+                       return $summary;
+
+               #New page autosummaries
+               if ($flags & EDIT_NEW && strlen($newtext) <= 500) {
+                       #If they're making a new short article, give its text in the summary.
+                       global $wgContLang;
+                       $truncatedtext = $wgContLang->truncate( $newtext, max( 0, 200 - 
+                               strlen( wfMsgForContent( 'autosumm-shortnew') ) ), '...' );
+                       $summary = wfMsgForContent( 'autosumm-shortnew', $truncatedtext );
+               }
+
+               if ($summary)
+                       return $summary;
+
+               return $summary;
+       }
 }
 
 ?>