merged master (2012-09-11)
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index 4db1f5f..449cc45 100644 (file)
@@ -1043,7 +1043,7 @@ class LocalFile extends File {
                if ( !$props ) {
                        wfProfileIn( __METHOD__ . '-getProps' );
                        $props = $this->repo->getFileProps( $this->getVirtualUrl() );
-                       wfProfileOut( __METHOD__ . -'getProps' );
+                       wfProfileOut( __METHOD__ . '-getProps' );
                }
 
                if ( $timestamp === false ) {
@@ -1151,10 +1151,12 @@ class LocalFile extends File {
                # Add the log entry
                $log = new LogPage( 'upload' );
                $action = $reupload ? 'overwrite' : 'upload';
-               $log->addEntry( $action, $descTitle, $comment, array(), $user );
+               $logId = $log->addEntry( $action, $descTitle, $comment, array(), $user );
 
                wfProfileIn( __METHOD__ . '-edit' );
-               if ( $descTitle->exists() ) {
+               $exists = $descTitle->exists();
+
+               if ( $exists ) {
                        # Create a null revision
                        $latest = $descTitle->getLatestRevID();
                        $nullRevision = Revision::newNullRevision(
@@ -1169,21 +1171,37 @@ class LocalFile extends File {
                                wfRunHooks( 'NewRevisionFromEditComplete', array( $wikiPage, $nullRevision, $latest, $user ) );
                                $wikiPage->updateRevisionOn( $dbw, $nullRevision );
                        }
+               }
+
+               # Commit the transaction now, in case something goes wrong later
+               # The most important thing is that files don't get lost, especially archives
+               # NOTE: once we have support for nested transactions, the commit may be moved
+               #       to after $wikiPage->doEdit has been called.
+               $dbw->commit( __METHOD__ );
+
+               if ( $exists ) {
                        # Invalidate the cache for the description page
                        $descTitle->invalidateCache();
                        $descTitle->purgeSquid();
                } else {
                        # New file; create the description page.
                        # There's already a log entry, so don't make a second RC entry
-                       # Squid and file cache for the description page are purged by doEdit.
-                       $wikiPage->doEdit( $pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user );
+                       # Squid and file cache for the description page are purged by doEditContent.
+                       $content = ContentHandler::makeContent( $pageText, $descTitle );
+                       $status = $wikiPage->doEditContent( $content, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user );
+
+                       if ( isset( $status->value['revision'] ) ) { // XXX; doEdit() uses a transaction
+                               $dbw->begin();
+                               $dbw->update( 'logging',
+                                       array( 'log_page' => $status->value['revision']->getPage() ),
+                                       array( 'log_id' => $logId ),
+                                       __METHOD__
+                               );
+                               $dbw->commit(); // commit before anything bad can happen
+                       }
                }
                wfProfileOut( __METHOD__ . '-edit' );
 
-               # Commit the transaction now, in case something goes wrong later
-               # The most important thing is that files don't get lost, especially archives
-               $dbw->commit( __METHOD__ );
-
                # Save to cache and purge the squid
                # We shall not saveToCache before the commit since otherwise
                # in case of a rollback there is an usable file from memcached
@@ -1456,11 +1474,11 @@ class LocalFile extends File {
         */
        function getDescriptionText() {
                global $wgParser;
-               $revision = Revision::newFromTitle( $this->title, false, Revision::AVOID_MASTER );
+               $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
                if ( !$revision ) return false;
-               $text = $revision->getText();
-               if ( !$text ) return false;
-               $pout = $wgParser->parse( $text, $this->title, new ParserOptions() );
+               $content = $revision->getContent();
+               if ( !$content ) return false;
+               $pout = $content->getParserOutput( $this->title, null, new ParserOptions() );
                return $pout->getText();
        }