From f8b08732a741015862f61528dc969fb8438186e3 Mon Sep 17 00:00:00 2001 From: Andrew Otto Date: Thu, 14 Jul 2016 12:45:11 -0400 Subject: [PATCH] Clone WikiPage before delete and pass the cloned copy to ArticleDeleteComplete This allows the hook to examine the state of the WikiPage instance before the data is actually deleted from the page table. E.g. The hook can now do $wikiPage->isRedirect(); and get correct information. Bug: T134502 Change-Id: I715046dc8157047aff4d5bd03ea6b5a47aee58bb --- includes/page/WikiPage.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 8eba1ccf7b..f3cc26a507 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -90,6 +90,14 @@ class WikiPage implements Page, IDBAccessObject { $this->mTitle = $title; } + /** + * Makes sure that the mTitle object is cloned + * to the newly cloned WikiPage. + */ + public function __clone() { + $this->mTitle = clone $this->mTitle; + } + /** * Create a WikiPage object of the appropriate class for the given title. * @@ -1048,9 +1056,9 @@ class WikiPage implements Page, IDBAccessObject { * @param bool $forceParse Force reindexing, regardless of cache settings * @return bool|ParserOutput ParserOutput or false if the revision was not found */ - public function getParserOutput( ParserOptions $parserOptions, $oldid = null, - $forceParse = false ) { - + public function getParserOutput( + ParserOptions $parserOptions, $oldid = null, $forceParse = false + ) { $useParserCache = ( !$forceParse ) && $this->shouldCheckParserCache( $parserOptions, $oldid ); wfDebug( __METHOD__ . @@ -2934,6 +2942,11 @@ class WikiPage implements Page, IDBAccessObject { // Save this so we can pass it to the ArticleDeleteComplete hook. $archivedRevisionCount = $dbw->affectedRows(); + // Clone the title and wikiPage, so we have the information we need when + // we log and run the ArticleDeleteComplete hook. + $logTitle = clone $this->mTitle; + $wikiPageBeforeDelete = clone $this; + // Now that it's safely backed up, delete it $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ ); @@ -2941,9 +2954,6 @@ class WikiPage implements Page, IDBAccessObject { $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ ); } - // Clone the title, so we have the information we need when we log - $logTitle = clone $this->mTitle; - // Log the deletion, if the page was suppressed, put it in the suppression log instead $logtype = $suppress ? 'suppress' : 'delete'; @@ -2962,8 +2972,15 @@ class WikiPage implements Page, IDBAccessObject { $this->doDeleteUpdates( $id, $content ); - Hooks::run( 'ArticleDeleteComplete', - [ &$this, &$user, $reason, $id, $content, $logEntry, $archivedRevisionCount ] ); + Hooks::run( 'ArticleDeleteComplete', [ + &$wikiPageBeforeDelete, + &$user, + $reason, + $id, + $content, + $logEntry, + $archivedRevisionCount + ] ); $status->value = $logid; // Show log excerpt on 404 pages rather than just a link -- 2.20.1