private $config;
/** @var ImportTitleFactory */
private $importTitleFactory;
+ /** @var array */
+ private $countableCache = array();
/**
* Creates an ImportXMLReader drawing from the source provided
}
// Default callbacks
+ $this->setPageCallback( array( $this, 'beforeImportPage' ) );
$this->setRevisionCallback( array( $this, "importRevision" ) );
$this->setUploadCallback( array( $this, 'importUpload' ) );
$this->setLogItemCallback( array( $this, 'importLogItem' ) );
$this->mImportUploads = $import;
}
+ /**
+ * Default per-page callback. Sets up some things related to site statistics
+ * @param array $titleAndForeignTitle Two-element array, with Title object at
+ * index 0 and ForeignTitle object at index 1
+ * @return bool
+ */
+ public function beforeImportPage( $titleAndForeignTitle ) {
+ $title = $titleAndForeignTitle[0];
+ $page = WikiPage::factory( $title );
+ $this->countableCache['title_' . $title->getPrefixedText()] = $page->isCountable();
+ return true;
+ }
+
/**
* Default per-revision callback, performs the import.
* @param WikiRevision $revision
*/
public function finishImportPage( $title, $foreignTitle, $revCount,
$sRevCount, $pageInfo ) {
+
+ // Update article count statistics (T42009)
+ // The normal counting logic in WikiPage->doEditUpdates() is designed for
+ // one-revision-at-a-time editing, not bulk imports. In this situation it
+ // suffers from issues of slave lag. We let WikiPage handle the total page
+ // and revision count, and we implement our own custom logic for the
+ // article (content page) count.
+ $page = WikiPage::factory( $title );
+ $page->loadPageData( 'fromdbmaster' );
+ $content = $page->getContent();
+ $editInfo = $page->prepareContentForEdit( $content );
+
+ $countable = $page->isCountable( $editInfo );
+ $oldcountable = $this->countableCache['title_' . $title->getPrefixedText()];
+ if ( isset( $oldcountable ) && $countable != $oldcountable ) {
+ DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array(
+ 'articles' => ( (int)$countable - (int)$oldcountable )
+ ) ) );
+ }
+
$args = func_get_args();
return Hooks::run( 'AfterImportPage', $args );
}
$this->title->getPrefixedText() . "]], timestamp " . $this->timestamp . "\n" );
return false;
}
- $oldcountable = $page->isCountable();
}
# @todo FIXME: Use original rev_id optionally (better for backups)
if ( $changed !== false && !$this->mNoUpdates ) {
wfDebug( __METHOD__ . ": running updates\n" );
+ // countable/oldcountable stuff is handled in WikiImporter::finishImportPage
$page->doEditUpdates(
$revision,
$userObj,
- array( 'created' => $created, 'oldcountable' => $oldcountable )
+ array( 'created' => $created, 'oldcountable' => 'no-change' )
);
}
* - changed: boolean, whether the revision changed the content (default true)
* - created: boolean, whether the revision created the page (default false)
* - moved: boolean, whether the page was moved (default false)
- * - oldcountable: boolean or null (default null):
+ * - oldcountable: boolean, null, or string 'no-change' (default null):
* - boolean: whether the page was counted as an article before that
* revision, only used in changed is true and created is false
- * - null: don't change the article count
+ * - null: if created is false, don't update the article count; if created
+ * is true, do update the article count
+ * - 'no-change': don't update the article count, ever
*/
public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
global $wgEnableParserCache;
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
- if ( !$options['changed'] && !$options['moved'] ) {
+ if ( $options['oldcountable'] === 'no-change' ||
+ ( !$options['changed'] && !$options['moved'] )
+ ) {
$good = 0;
} elseif ( $options['created'] ) {
$good = (int)$this->isCountable( $editInfo );