-
- // Recentlinkchanges constants
- const INSERTION = 1;
- const DELETION = 2;
- private static $rlcFields = array(
- 'rlc_type',
- 'rlc_timestamp',
- 'rlc_action',
- 'rlc_from',
- 'rlc_to_namespace',
- 'rlc_to_title',
- 'rlc_to_blob'
- );
- /*
- * Insert items to recentlinkchanges
- */
- function makeRecentlinkchanges() {
- $insert = array();
- $now = $this->mDb->timestamp();
-
- // Category changes
- $existing = array_keys( $this->getExistingCategories() );
- $current = array_keys( $this->mCategories );
- $this->simpleAddToLinkchanges( $insert, 'category', $now, $existing, $current, NS_CATEGORY );
-
- // External links
- $existing = array_keys( $this->getExistingExternals() );
- $current = array_keys( $this->mExternals );
- $insertions = array_diff( $current, $existing );
- foreach ( $insertions as $item )
- $insert[] = array(
- 'external', $now, self::INSERTION,
- $this->mId, null, null, $item );
- $deletions = array_diff( $existing, $current );
- foreach ( $deletions as $item )
- $insert[] = array(
- 'external', $now, self::DELETION,
- $this->mId, null, null, $item );
-
- // Image changes
- $existing = array_keys( $this->getExistingImages() );
- $current = array_keys( $this->mImages );
- $this->simpleAddToLinkchanges( $insert, 'image', $now, $existing, $current, NS_IMAGE );
-
- // Interlangs
- $existing = $this->getExistingInterlangs();
- $current = $this->mInterlangs;
- $this->assocAddToLinkchanges( $insert, 'interlang', $existing, $current );
-
- // Page links
- $existing = $this->getExistingLinks();
- $current = $this->mLinks;
- $this->addToLinkChangesByNamespace( $insert, 'page', $now, $existing, $current);
-
- // Properties
- $existing = $this->getExistingProperties();
- $current = $this->mProperties;
- $this->assocAddToLinkchanges( $insert, 'property', $existing, $current );
-
- // Templates
- $existing = $this->getExistingTemplates();
- $current = $this->mTemplates;
- $this->addToLinkChangesByNamespace( $insert, 'template', $now, $existing, $current);
-
- $this->mDb->insert( 'recentlinkchanges', $insert, __METHOD__ );
-
- }
-
- /*
- * Compute the difference for arrays of titles with namespace $ns and add
- * them to $insert.
- */
- private function simpleAddToLinkchanges( &$insert, $type, $now, $existing, $current, $ns ) {
-
- $insertions = array_diff( $current, $existing );
- foreach ( $insertions as $item )
- $insert[] = array_combine(self::$rlcFields, array(
- $type, $now, self::INSERTION,
- $this->mId, $ns, $item, null
- ) );
- $deletions = array_diff( $existing, $current );
- foreach ( $deletions as $item )
- $insert[] = array_combine(self::$rlcFields, array(
- $type, $now, self::DELETION,
- $this->mId, $ns, $item, null
- ) );
-
- }
-
- /*
- * Compute the difference for associative arrays and insert them to
- * $insert as title => blob.
- */
- function assocAddToLinkChanges( &$insert, $type, $now, $existing, $current ) {
- $insertions = array_diff_assoc( $current, $existing );
- foreach ( $insertions as $key => $value )
- $insert[] = array_combine(self::$rlcFields, array(
- $type, $now, self::INSERTION,
- $this->mId, null, $key, $value
- ) );
- $deletions = array_diff_assoc( $existing, $current );
- foreach ( $deletions as $key => $value )
- $insert[] = array_combine(self::$rlcFields, array(
- $type, $now, self::DELETION,
- $this->mId, null, $key, $value
- ) );
- }
-
- /*
- * Format arrays in the form $namespace => $titleArray for use in
- * simpleAddLinkLinkChanges
- */
- function addToLinkChangesByNamespace( &$insert, $type, $now, $existing, $current ) {
- $namespaces = array_merge( array_keys( $existing ), array_keys( $current ) );
- foreach ( $namespaces as $ns )
- $this->simpleAddToLinkchanges( $insert, $type, $now,
- isset( $existing[$ns] ) ? array_keys( $existing[$ns] ) : array(),
- isset( $current[$ns] ) ? array_keys( $current[$ns] ) : array(),
- $ns );
- }