Consistently use '@deprecated since <version>'
[lhc/web/wiklou.git] / includes / WikiPage.php
index b4aa303..0dec766 100644 (file)
@@ -104,9 +104,10 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Create a WikiPage object of the appropriate class for the given title.
         *
-        * @param $title Title
+        * @param Title $title
+        *
         * @throws MWException
-        * @return WikiPage object of the appropriate type
+        * @return WikiPage Object of the appropriate type
         */
        public static function factory( Title $title ) {
                $ns = $title->getNamespace();
@@ -686,7 +687,7 @@ class WikiPage implements Page, IDBAccessObject {
         * @param $user User object to check for, only if FOR_THIS_USER is passed
         *              to the $audience parameter
         * @return String|false The text of the current revision
-        * @deprecated as of 1.21, getContent() should be used instead.
+        * @deprecated since 1.21, getContent() should be used instead.
         */
        public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { // @todo deprecated, replace usage!
                ContentHandler::deprecated( __METHOD__, '1.21' );
@@ -702,7 +703,7 @@ class WikiPage implements Page, IDBAccessObject {
         * Get the text of the current revision. No side-effects...
         *
         * @return String|bool The text of the current revision. False on failure
-        * @deprecated as of 1.21, getContent() should be used instead.
+        * @deprecated since 1.21, getContent() should be used instead.
         */
        public function getRawText() {
                ContentHandler::deprecated( __METHOD__, '1.21' );
@@ -1468,12 +1469,13 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
-        * @param string $text new text of the section
-        * @param string $sectionTitle new section's subject, only if $section is 'new'
-        * @param string $edittime revision timestamp or null to use the current revision
+        * @param mixed $section Null/false, a section number (0, 1, 2, T1, T2, ...) or "new".
+        * @param string $text New text of the section.
+        * @param string $sectionTitle New section's subject, only if $section is "new".
+        * @param string $edittime Revision timestamp or null to use the current revision.
+        *
         * @throws MWException
-        * @return String new complete article text, or null if error
+        * @return string New complete article text, or null if error.
         *
         * @deprecated since 1.21, use replaceSectionContent() instead
         */
@@ -1486,13 +1488,15 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( !$this->supportsSections() ) {
-                       throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() );
+                       throw new MWException( "sections not supported for content model " .
+                               $this->getContentHandler()->getModelID() );
                }
 
                // could even make section title, but that's not required.
                $sectionContent = ContentHandler::makeContent( $text, $this->getTitle() );
 
-               $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle, $edittime );
+               $newContent = $this->replaceSectionContent( $section, $sectionContent, $sectionTitle,
+                       $edittime );
 
                return ContentHandler::getContentText( $newContent );
        }
@@ -1500,7 +1504,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Returns true if this page's content model supports sections.
         *
-        * @return boolean whether sections are supported.
+        * @return bool
         *
         * @todo The skin should check this and not offer section functionality if sections are not supported.
         * @todo The EditPage should check this and not offer section functionality if sections are not supported.
@@ -1510,17 +1514,18 @@ class WikiPage implements Page, IDBAccessObject {
        }
 
        /**
-        * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
-        * @param $sectionContent Content: new content of the section
-        * @param string $sectionTitle new section's subject, only if $section is 'new'
-        * @param string $edittime revision timestamp or null to use the current revision
+        * @param mixed $section Null/false, a section number (0, 1, 2, T1, T2, ...) or "new".
+        * @param Content $sectionContent New content of the section.
+        * @param string $sectionTitle New section's subject, only if $section is "new".
+        * @param string $edittime Revision timestamp or null to use the current revision.
         *
         * @throws MWException
-        * @return Content new complete article content, or null if error
+        * @return Content New complete article content, or null if error.
         *
         * @since 1.21
         */
-       public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '', $edittime = null ) {
+       public function replaceSectionContent( $section, Content $sectionContent, $sectionTitle = '',
+               $edittime = null ) {
                wfProfileIn( __METHOD__ );
 
                if ( strval( $section ) == '' ) {
@@ -1529,7 +1534,8 @@ class WikiPage implements Page, IDBAccessObject {
                } else {
                        if ( !$this->supportsSections() ) {
                                wfProfileOut( __METHOD__ );
-                               throw new MWException( "sections not supported for content model " . $this->getContentHandler()->getModelID() );
+                               throw new MWException( "sections not supported for content model " .
+                                       $this->getContentHandler()->getModelID() );
                        }
 
                        // Bug 30711: always use current version when adding a new section
@@ -1806,56 +1812,62 @@ class WikiPage implements Page, IDBAccessObject {
                                }
 
                                $dbw->begin( __METHOD__ );
+                               try {
 
-                               $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
-                               $status->merge( $prepStatus );
+                                       $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+                                       $status->merge( $prepStatus );
 
-                               if ( !$status->isOK() ) {
-                                       $dbw->rollback( __METHOD__ );
+                                       if ( !$status->isOK() ) {
+                                               $dbw->rollback( __METHOD__ );
 
-                                       wfProfileOut( __METHOD__ );
-                                       return $status;
-                               }
+                                               wfProfileOut( __METHOD__ );
+                                               return $status;
+                                       }
+                                       $revisionId = $revision->insertOn( $dbw );
 
-                               $revisionId = $revision->insertOn( $dbw );
+                                       // Update page
+                                       //
+                                       // Note that we use $this->mLatest instead of fetching a value from the master DB
+                                       // during the course of this function. This makes sure that EditPage can detect
+                                       // edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
+                                       // before this function is called. A previous function used a separate query, this
+                                       // creates a window where concurrent edits can cause an ignored edit conflict.
+                                       $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );
 
-                               // Update page
-                               //
-                               // Note that we use $this->mLatest instead of fetching a value from the master DB
-                               // during the course of this function. This makes sure that EditPage can detect
-                               // edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
-                               // before this function is called. A previous function used a separate query, this
-                               // creates a window where concurrent edits can cause an ignored edit conflict.
-                               $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );
+                                       if ( !$ok ) {
+                                               // Belated edit conflict! Run away!!
+                                               $status->fatal( 'edit-conflict' );
 
-                               if ( !$ok ) {
-                                       // Belated edit conflict! Run away!!
-                                       $status->fatal( 'edit-conflict' );
-
-                                       $dbw->rollback( __METHOD__ );
+                                               $dbw->rollback( __METHOD__ );
 
-                                       wfProfileOut( __METHOD__ );
-                                       return $status;
-                               }
+                                               wfProfileOut( __METHOD__ );
+                                               return $status;
+                                       }
 
-                               wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
-                               // Update recentchanges
-                               if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                                       // Mark as patrolled if the user can do so
-                                       $patrolled = $wgUseRCPatrol && !count(
+                                       wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+                                       // Update recentchanges
+                                       if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+                                               // Mark as patrolled if the user can do so
+                                               $patrolled = $wgUseRCPatrol && !count(
                                                $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
-                                       // Add RC row to the DB
-                                       $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
-                                               $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
-                                               $revisionId, $patrolled
-                                       );
+                                               // Add RC row to the DB
+                                               $rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
+                                                       $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+                                                       $revisionId, $patrolled
+                                               );
 
-                                       // Log auto-patrolled edits
-                                       if ( $patrolled ) {
-                                               PatrolLog::record( $rc, true, $user );
+                                               // Log auto-patrolled edits
+                                               if ( $patrolled ) {
+                                                       PatrolLog::record( $rc, true, $user );
+                                               }
                                        }
+                                       $user->incEditCount();
+                               } catch ( MWException $e ) {
+                                       $dbw->rollback( __METHOD__ );
+                                       // Question: Would it perhaps be better if this method turned all
+                                       // exceptions into $status's?
+                                       throw $e;
                                }
-                               $user->incEditCount();
                                $dbw->commit( __METHOD__ );
                        } else {
                                // Bug 32948: revision ID must be set to page {{REVISIONID}} and
@@ -1885,74 +1897,80 @@ class WikiPage implements Page, IDBAccessObject {
                        $status->value['new'] = true;
 
                        $dbw->begin( __METHOD__ );
+                       try {
 
-                       $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
-                       $status->merge( $prepStatus );
+                               $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+                               $status->merge( $prepStatus );
 
-                       if ( !$status->isOK() ) {
-                               $dbw->rollback( __METHOD__ );
+                               if ( !$status->isOK() ) {
+                                       $dbw->rollback( __METHOD__ );
 
-                               wfProfileOut( __METHOD__ );
-                               return $status;
-                       }
+                                       wfProfileOut( __METHOD__ );
+                                       return $status;
+                               }
 
-                       $status->merge( $prepStatus );
+                               $status->merge( $prepStatus );
 
-                       // Add the page record; stake our claim on this title!
-                       // This will return false if the article already exists
-                       $newid = $this->insertOn( $dbw );
+                               // Add the page record; stake our claim on this title!
+                               // This will return false if the article already exists
+                               $newid = $this->insertOn( $dbw );
 
-                       if ( $newid === false ) {
-                               $dbw->rollback( __METHOD__ );
-                               $status->fatal( 'edit-already-exists' );
+                               if ( $newid === false ) {
+                                       $dbw->rollback( __METHOD__ );
+                                       $status->fatal( 'edit-already-exists' );
 
-                               wfProfileOut( __METHOD__ );
-                               return $status;
-                       }
+                                       wfProfileOut( __METHOD__ );
+                                       return $status;
+                               }
 
-                       // Save the revision text...
-                       $revision = new Revision( array(
-                               'page'       => $newid,
-                               'title'      => $this->getTitle(), // for determining the default content model
-                               'comment'    => $summary,
-                               'minor_edit' => $isminor,
-                               'text'       => $serialized,
-                               'len'        => $newsize,
-                               'user'       => $user->getId(),
-                               'user_text'  => $user->getName(),
-                               'timestamp'  => $now,
-                               'content_model' => $content->getModel(),
-                               'content_format' => $serialisation_format,
-                       ) );
-                       $revisionId = $revision->insertOn( $dbw );
+                               // Save the revision text...
+                               $revision = new Revision( array(
+                                       'page'       => $newid,
+                                       'title'      => $this->getTitle(), // for determining the default content model
+                                       'comment'    => $summary,
+                                       'minor_edit' => $isminor,
+                                       'text'       => $serialized,
+                                       'len'        => $newsize,
+                                       'user'       => $user->getId(),
+                                       'user_text'  => $user->getName(),
+                                       'timestamp'  => $now,
+                                       'content_model' => $content->getModel(),
+                                       'content_format' => $serialisation_format,
+                               ) );
+                               $revisionId = $revision->insertOn( $dbw );
 
-                       // Bug 37225: use accessor to get the text as Revision may trim it
-                       $content = $revision->getContent(); // sanity; get normalized version
+                               // Bug 37225: use accessor to get the text as Revision may trim it
+                               $content = $revision->getContent(); // sanity; get normalized version
 
-                       if ( $content ) {
-                               $newsize = $content->getSize();
-                       }
+                               if ( $content ) {
+                                       $newsize = $content->getSize();
+                               }
 
-                       // Update the page record with revision data
-                       $this->updateRevisionOn( $dbw, $revision, 0 );
+                               // Update the page record with revision data
+                               $this->updateRevisionOn( $dbw, $revision, 0 );
 
-                       wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+                               wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
 
-                       // Update recentchanges
-                       if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
-                               // Mark as patrolled if the user can do so
-                               $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
-                                       $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
-                               // Add RC row to the DB
-                               $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
-                                       '', $newsize, $revisionId, $patrolled );
+                               // Update recentchanges
+                               if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
+                                       // Mark as patrolled if the user can do so
+                                       $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) && !count(
+                                               $this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
+                                       // Add RC row to the DB
+                                       $rc = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $user, $summary, $bot,
+                                               '', $newsize, $revisionId, $patrolled );
 
-                               // Log auto-patrolled edits
-                               if ( $patrolled ) {
-                                       PatrolLog::record( $rc, true, $user );
+                                       // Log auto-patrolled edits
+                                       if ( $patrolled ) {
+                                               PatrolLog::record( $rc, true, $user );
+                                       }
                                }
+                               $user->incEditCount();
+
+                       } catch ( MWException $e ) {
+                               $dbw->rollback( __METHOD__ );
+                               throw $e;
                        }
-                       $user->incEditCount();
                        $dbw->commit( __METHOD__ );
 
                        // Update links, etc.
@@ -2015,7 +2033,7 @@ class WikiPage implements Page, IDBAccessObject {
         * Prepare text which is about to be saved.
         * Returns a stdclass with source, pst and output members
         *
-        * @deprecated in 1.21: use prepareContentForEdit instead.
+        * @deprecated since 1.21: use prepareContentForEdit instead.
         */
        public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
                ContentHandler::deprecated( __METHOD__, '1.21' );
@@ -2064,6 +2082,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                $edit = (object)array();
                $edit->revid = $revid;
+               $edit->timestamp = wfTimestampNow();
 
                $edit->pstContent = $content ? $content->preSaveTransform( $this->mTitle, $user, $popts ) : null;
 
@@ -2121,7 +2140,9 @@ class WikiPage implements Page, IDBAccessObject {
                // Save it to the parser cache
                if ( $wgEnableParserCache ) {
                        $parserCache = ParserCache::singleton();
-                       $parserCache->save( $editInfo->output, $this, $editInfo->popts );
+                       $parserCache->save(
+                               $editInfo->output, $this, $editInfo->popts, $editInfo->timestamp, $editInfo->revid
+                       );
                }
 
                // Update the links tables and other secondary data
@@ -2612,9 +2633,11 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Take an array of page restrictions and flatten it to a string
         * suitable for insertion into the page_restrictions field.
-        * @param $limit Array
+        *
+        * @param string[] $limit
+        *
         * @throws MWException
-        * @return String
+        * @return string
         */
        protected static function flattenRestrictions( $limit ) {
                if ( !is_array( $limit ) ) {
@@ -3357,7 +3380,7 @@ class WikiPage implements Page, IDBAccessObject {
         * Return a list of templates used by this article.
         * Uses the templatelinks table
         *
-        * @deprecated in 1.19; use Title::getTemplateLinksFrom()
+        * @deprecated since 1.19; use Title::getTemplateLinksFrom()
         * @return Array of Title objects
         */
        public function getUsedTemplates() {
@@ -3368,7 +3391,7 @@ class WikiPage implements Page, IDBAccessObject {
         * This function is called right before saving the wikitext,
         * so we can do things like signatures and links-in-context.
         *
-        * @deprecated in 1.19; use Parser::preSaveTransform() instead
+        * @deprecated since 1.19; use Parser::preSaveTransform() instead
         * @param string $text article contents
         * @param $user User object: user doing the edit
         * @param $popts ParserOptions object: parser options, default options for
@@ -3393,7 +3416,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Check whether the number of revisions of this page surpasses $wgDeleteRevisionsLimit
         *
-        * @deprecated in 1.19; use Title::isBigDeletion() instead.
+        * @deprecated since 1.19; use Title::isBigDeletion() instead.
         * @return bool
         */
        public function isBigDeletion() {
@@ -3404,7 +3427,7 @@ class WikiPage implements Page, IDBAccessObject {
        /**
         * Get the  approximate revision count of this page.
         *
-        * @deprecated in 1.19; use Title::estimateRevisionCount() instead.
+        * @deprecated since 1.19; use Title::estimateRevisionCount() instead.
         * @return int
         */
        public function estimateRevisionCount() {
@@ -3597,9 +3620,9 @@ class PoolWorkArticleView extends PoolCounterWork {
                                $this->page->getTitle()->getPrefixedDBkey() ) );
                }
 
-               if ( $this->cacheable && $this->parserOutput->isCacheable() ) {
+               if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
                        ParserCache::singleton()->save(
-                               $this->parserOutput, $this->page, $this->parserOptions, $cacheTime );
+                               $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
                }
 
                // Make sure file cache is not used on uncacheable content.