From: Aaron Schulz Date: Mon, 14 May 2012 22:20:04 +0000 (+0000) Subject: Merge "Generalizing LinksUpdate to allow extensions to add arbitrary update handlers." X-Git-Tag: 1.31.0-rc.0~23616 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=060ba3cb682d3aa1059895f6abda14b4dd842ad5;p=lhc%2Fweb%2Fwiklou.git Merge "Generalizing LinksUpdate to allow extensions to add arbitrary update handlers." --- 060ba3cb682d3aa1059895f6abda14b4dd842ad5 diff --cc includes/LinksUpdate.php index 4518421475,236d7e43eb..8b403fcd85 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@@ -17,20 -17,13 +17,19 @@@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file + */ + +/** + * See docs/deferred.txt + * * @todo document (e.g. one-sentence top-level class description). */ - class LinksUpdate { + class LinksUpdate extends SqlDataUpdate { - /**@{{ - * @private - */ - var $mId, //!< Page ID of the article linked from + // @todo: make members protected, but make sure extensions don't break + + public $mId, //!< Page ID of the article linked from $mTitle, //!< Title object of the article linked from $mParserOutput, //!< Parser output $mLinks, //!< Map of title strings to IDs for the links in the document @@@ -855,3 -801,74 +807,74 @@@ } } } + + /** + * Update object handling the cleanup of links tables after a page was deleted. + **/ + class LinksDeletionUpdate extends SqlDataUpdate { + + protected $mPage; //!< WikiPage the wikipage that was deleted + + /** + * Constructor + * + * @param $title Title of the page we're updating + * @param $parserOutput ParserOutput: output from a full parse of this page + * @param $recursive Boolean: queue jobs for recursive updates? + */ + function __construct( WikiPage $page ) { + parent::__construct( ); + + $this->mPage = $page; + } + + /** + * Do some database updates after deletion + */ + public function doUpdate() { + $title = $this->mPage->getTitle(); + $id = $this->mPage->getId(); + + # Delete restrictions for it + $this->mDb->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ ); + + # Fix category table counts + $cats = array(); + $res = $this->mDb->select( 'categorylinks', 'cl_to', array( 'cl_from' => $id ), __METHOD__ ); + + foreach ( $res as $row ) { + $cats [] = $row->cl_to; + } + + $this->mPage->updateCategoryCounts( array(), $cats ); + + # If using cascading deletes, we can skip some explicit deletes + if ( !$this->mDb->cascadingDeletes() ) { + $this->mDb->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ ); + + # Delete outgoing links + $this->mDb->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'categorylinks', array( 'cl_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'templatelinks', array( 'tl_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'externallinks', array( 'el_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'langlinks', array( 'll_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__ ); + $this->mDb->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__ ); + } + + # If using cleanup triggers, we can skip some manual deletes + if ( !$this->mDb->cleanupTriggers() ) { + # Clean up recentchanges entries... + $this->mDb->delete( 'recentchanges', + array( 'rc_type != ' . RC_LOG, + 'rc_namespace' => $title->getNamespace(), + 'rc_title' => $title->getDBkey() ), + __METHOD__ ); + $this->mDb->delete( 'recentchanges', + array( 'rc_type != ' . RC_LOG, 'rc_cur_id' => $id ), + __METHOD__ ); + } + } -} ++}