/** @var string MEDIATYPE_xxx (bitmap, drawing, audio...) */
protected $media_type;
- /** @var string MIME type, determined by MimeMagic::guessMimeType */
+ /** @var string MIME type, determined by MimeAnalyzer::guessMimeType */
protected $mime;
/** @var int Size in bytes (loadFromXxx) */
# This avoids race conditions by locking the row until the commit, and also
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
$commentStore = MediaWikiServices::getInstance()->getCommentStore();
- list( $commentFields, $commentCallback ) =
- $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
+ $commentFields = $commentStore->insert( $dbw, 'img_description', $comment );
$actorMigration = ActorMigration::newMigration();
$actorFields = $actorMigration->getInsertValues( $dbw, 'img_user', $user );
$dbw->insert( 'image',
}
if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
$tables[] = 'image_comment_temp';
- $fields['oi_description_id'] = 'imgcomment_description_id';
+ $fields['oi_description_id'] =
+ 'CASE WHEN img_description_id = 0 THEN imgcomment_description_id ELSE img_description_id END';
$joins['image_comment_temp'] = [
$wgCommentTableSchemaMigrationStage === MIGRATION_NEW ? 'JOIN' : 'LEFT JOIN',
[ 'imgcomment_name = img_name' ]
$res = $dbw->select(
[ 'image', 'image_comment_temp' ],
[ 'img_name', 'img_description' ],
- [ 'img_name' => $this->getName(), 'imgcomment_name' => null ],
+ [
+ 'img_name' => $this->getName(),
+ 'imgcomment_name' => null,
+ 'img_description_id' => 0,
+ ],
__METHOD__,
[],
[ 'image_comment_temp' => [ 'LEFT JOIN', [ 'imgcomment_name = img_name' ] ] ]
);
foreach ( $res as $row ) {
- list( , $callback ) = $commentStore->insertWithTempTable(
- $dbw, 'img_description', $row->img_description
- );
- $callback( $row->img_name );
+ $commentStore->insert( $dbw, 'img_description', $row->img_description );
}
}
__METHOD__
);
if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) {
- // So $commentCallback can insert the new row
+ // Clear deprecated table row
$dbw->delete( 'image_comment_temp', [ 'imgcomment_name' => $this->getName() ], __METHOD__ );
}
}
- $commentCallback( $this->getName() );
$descTitle = $this->getTitle();
$descId = $descTitle->getArticleID();
# Defer purges, page creation, and link updates in case they error out.
# The most important thing is that files and the DB registry stay synced.
$dbw->endAtomic( __METHOD__ );
+ $fname = __METHOD__;
# Do some cache purges after final commit so that:
# a) Changes are more likely to be seen post-purge
__METHOD__,
function () use (
$reupload, $wikiPage, $newPageContent, $comment, $user,
- $logEntry, $logId, $descId, $tags
+ $logEntry, $logId, $descId, $tags, $fname
) {
# Update memcache after the commit
$this->invalidateCache();
'logging',
$update,
[ 'log_id' => $logId ],
- __METHOD__
+ $fname
);
$this->getRepo()->getMasterDB()->insert(
'log_search',
'ls_value' => $logEntry->getAssociatedRevId(),
'ls_log_id' => $logId,
],
- __METHOD__
+ $fname
);
# Add change tags, if any
* @return string|false
*/
function getDescriptionText( Language $lang = null ) {
- $revision = Revision::newFromTitle( $this->title, false, Revision::READ_NORMAL );
+ $store = MediaWikiServices::getInstance()->getRevisionStore();
+ $revision = $store->getRevisionByTitle( $this->title, 0, Revision::READ_NORMAL );
if ( !$revision ) {
return false;
}
- $content = $revision->getContent();
- if ( !$content ) {
+
+ $renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
+ $rendered = $renderer->getRenderedRevision( $revision, new ParserOptions( null, $lang ) );
+
+ if ( !$rendered ) {
+ // audience check failed
return false;
}
- $pout = $content->getParserOutput( $this->title, null, new ParserOptions( null, $lang ) );
+ $pout = $rendered->getRevisionParserOutput();
return $pout->getText();
}
}
if ( $wgCommentTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH ) {
$tables[] = 'image_comment_temp';
- $fields['fa_description_id'] = 'imgcomment_description_id';
+ $fields['fa_description_id'] =
+ 'CASE WHEN img_description_id = 0 THEN imgcomment_description_id ELSE img_description_id END';
$joins['image_comment_temp'] = [
$wgCommentTableSchemaMigrationStage === MIGRATION_NEW ? 'JOIN' : 'LEFT JOIN',
[ 'imgcomment_name = img_name' ]
$res = $dbw->select(
[ 'image', 'image_comment_temp' ],
[ 'img_name', 'img_description' ],
- [ 'img_name' => $this->file->getName(), 'imgcomment_name' => null ],
+ [
+ 'img_name' => $this->file->getName(),
+ 'imgcomment_name' => null,
+ 'img_description_id' => 0,
+ ],
__METHOD__,
[],
[ 'image_comment_temp' => [ 'LEFT JOIN', [ 'imgcomment_name = img_name' ] ] ]
);
foreach ( $res as $row ) {
- list( , $callback ) = $commentStore->insertWithTempTable(
- $dbw, 'img_description', $row->img_description
- );
- $callback( $row->img_name );
+ $commentStore->insert( $dbw, 'img_description', $row->img_description );
}
}
if ( $deleteCurrent ) {
$dbw->delete( 'image', [ 'img_name' => $this->file->getName() ], __METHOD__ );
if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) {
+ // Clear deprecated table row
$dbw->delete(
'image_comment_temp', [ 'imgcomment_name' => $this->file->getName() ], __METHOD__
);
if ( $first && !$exists ) {
// This revision will be published as the new current version
$destRel = $this->file->getRel();
- list( $commentFields, $commentCallback ) =
- $commentStore->insertWithTempTable( $dbw, 'img_description', $comment );
+ $commentFields = $commentStore->insert( $dbw, 'img_description', $comment );
$actorFields = $actorMigration->getInsertValues( $dbw, 'img_user', $user );
$insertCurrent = [
'img_name' => $row->fa_name,
// This is not ideal, which is why it's important to lock the image row.
if ( $insertCurrent ) {
$dbw->insert( 'image', $insertCurrent, __METHOD__ );
- $commentCallback( $insertCurrent['img_name'] );
}
if ( $insertBatch ) {