Update the WikiPage object with the new ID when undeleting
[lhc/web/wiklou.git] / includes / page / WikiPage.php
index f290db8..7bd87f7 100644 (file)
@@ -1158,6 +1158,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                return true;
        }
+
        /**
         * Insert a new empty page record for this article.
         * This *must* be followed up by creating a revision
@@ -1166,13 +1167,16 @@ class WikiPage implements Page, IDBAccessObject {
         * Best if all done inside a transaction.
         *
         * @param IDatabase $dbw
-        * @return int|bool The newly created page_id key; false if the title already existed
+        * @param int|null $pageId Custom page ID that will be used for the insert statement
+        *
+        * @return bool|int The newly created page_id key; false if the title already existed
         */
-       public function insertOn( $dbw ) {
+       public function insertOn( $dbw, $pageId = null ) {
+               $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' );
                $dbw->insert(
                        'page',
                        array(
-                               'page_id'           => $dbw->nextSequenceValue( 'page_page_id_seq' ),
+                               'page_id'           => $pageIdForInsert,
                                'page_namespace'    => $this->mTitle->getNamespace(),
                                'page_title'        => $this->mTitle->getDBkey(),
                                'page_restrictions' => '',
@@ -1188,7 +1192,7 @@ class WikiPage implements Page, IDBAccessObject {
                );
 
                if ( $dbw->affectedRows() > 0 ) {
-                       $newid = $dbw->insertId();
+                       $newid = $pageId ?: $dbw->insertId();
                        $this->mId = $newid;
                        $this->mTitle->resetArticleID( $newid );
 
@@ -1737,13 +1741,6 @@ class WikiPage implements Page, IDBAccessObject {
                        $status = $this->doCreate( $pstContent, $flags, $user, $summary, $meta );
                }
 
-               // Trigger post-save hook
-               $revision = $status->value['revision']; // new revision
-               $hook_args = array( &$this, &$user, $pstContent, $summary,
-                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
-               ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
-               Hooks::run( 'PageContentSaveComplete', $hook_args );
-
                // Promote user to any groups they meet the criteria for
                DeferredUpdates::addCallableUpdate( function () use ( $user ) {
                        $user->addAutopromoteOnceGroups( 'onEdit' );
@@ -1899,6 +1896,12 @@ class WikiPage implements Page, IDBAccessObject {
                        $this->mTitle->invalidateCache( $now );
                }
 
+               // Trigger post-save hook
+               $hook_args = array( &$this, &$user, $content, $summary,
+                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $meta['baseRevId'] );
+               ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
+               Hooks::run( 'PageContentSaveComplete', $hook_args );
+
                return $status;
        }
 
@@ -2007,6 +2010,12 @@ class WikiPage implements Page, IDBAccessObject {
                // Return the new revision to the caller
                $status->value['revision'] = $revision;
 
+               // Trigger post-save hook
+               $hook_args = array( &$this, &$user, $content, $summary,
+                       $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $meta['baseRevId'] );
+               ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
+               Hooks::run( 'PageContentSaveComplete', $hook_args );
+
                return $status;
        }
 
@@ -3554,64 +3563,6 @@ class WikiPage implements Page, IDBAccessObject {
                }
        }
 
-       /**
-        * Return a list of templates used by this article.
-        * Uses the templatelinks table
-        *
-        * @deprecated since 1.19; use Title::getTemplateLinksFrom()
-        * @return array Array of Title objects
-        */
-       public function getUsedTemplates() {
-               return $this->mTitle->getTemplateLinksFrom();
-       }
-
-       /**
-        * This function is called right before saving the wikitext,
-        * so we can do things like signatures and links-in-context.
-        *
-        * @deprecated since 1.19; use Parser::preSaveTransform() instead
-        * @param string $text Article contents
-        * @param User $user User doing the edit
-        * @param ParserOptions $popts Parser options, default options for
-        *   the user loaded if null given
-        * @return string Article contents with altered wikitext markup (signatures
-        *      converted, {{subst:}}, templates, etc.)
-        */
-       public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
-               global $wgParser, $wgUser;
-
-               wfDeprecated( __METHOD__, '1.19' );
-
-               $user = is_null( $user ) ? $wgUser : $user;
-
-               if ( $popts === null ) {
-                       $popts = ParserOptions::newFromUser( $user );
-               }
-
-               return $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
-       }
-
-       /**
-        * Update the article's restriction field, and leave a log entry.
-        *
-        * @deprecated since 1.19
-        * @param array $limit Set of restriction keys
-        * @param string $reason
-        * @param int &$cascade Set to false if cascading protection isn't allowed.
-        * @param array $expiry Per restriction type expiration
-        * @param User $user The user updating the restrictions
-        * @return bool True on success
-        */
-       public function updateRestrictions(
-               $limit = array(), $reason = '', &$cascade = 0, $expiry = array(), User $user = null
-       ) {
-               global $wgUser;
-
-               $user = is_null( $user ) ? $wgUser : $user;
-
-               return $this->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $user )->isOK();
-       }
-
        /**
         * Returns a list of updates to be performed when this page is deleted. The
         * updates should remove any information about this page from secondary data