Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Store update when uploading a file (Bug 19487) #162

Closed
mwjames opened this issue Feb 6, 2014 · 4 comments
Closed

Fix Store update when uploading a file (Bug 19487) #162

mwjames opened this issue Feb 6, 2014 · 4 comments
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error
Milestone

Comments

@mwjames
Copy link
Contributor

mwjames commented Feb 6, 2014

[0] has been open and broken since 2009. The reason why the normal update hooks don't work is because there aren't executed in case of a file upload.

Investigate UploadVerifyFile (should be used as $mime is delivered by the interface) [1] or UploadComplete (doing $image->getLocalFile()->mime doesn't really work) [2].

Store update

$this->globals['wgHooks']['UploadVerifyFile'][] = function ( $upload, $mime, &$error ) use( $context ) {

    $title = $upload->getLocalFile()->getTitle();

    $contentParser = $context->getDependencyBuilder()->newObject( 'ContentParser', array(
        'Title' => $title
    ) );

    $contentParser->parse();

    $parserData = $context->getDependencyBuilder()->newObject( 'ParserData', array(
        'Title'        => $title,
        'ParserOutput' => $contentParser->getOutput()
    ) );

    $parserData->updateStore();

    return true;
};

Mime annotation

While resolving [0], the core should also add two new predefined properties _MIME and _MEDIA and annotate those for uploaded files with something like:

/**
 * @var PropertyAnnotator $propertyAnnotator
 */
$propertyAnnotator = $context->getDependencyBuilder()->newObject( 'FilePropertyAnnotator', array(
    'SemanticData'  => $parserData->getSemanticData(),
    'MimeType' => $mime
    'MediaType'   => $image->getLocalFile()->media_type
) );

$propertyAnnotator->attach( $parserData )->addAnnotation();

Reference

[0] https://bugzilla.wikimedia.org/show_bug.cgi?id=19487
[1] https://www.mediawiki.org/wiki/Manual:Hooks/UploadVerifyFile
[2] https://www.mediawiki.org/wiki/Manual:Hooks/UploadComplete
[3] https://gerrit.wikimedia.org/r/#/c/50943/

See also

#128

@kghbln kghbln added the bug label Feb 6, 2014
@mwjames
Copy link
Contributor Author

mwjames commented Feb 6, 2014

It took me some time to find the least intrusive implementation to ensure that data before and after the upload is correctly derived from the FilePage object. UploadVerifyFile and UploadComplete are inappropriate hooks therefore FileUpload is used instead.

Activating _MEDIA and _MIME annotation with $GLOBALS['smwgPageSpecialProperties'] = array( '_MEDIA', '_MIME' ); requires SMWAdmin to be executed once in order for the property tables to be initialized.

Checking table `smw_fpt_mime` ...
   Table not found, now creating...
   ... done.
Checking index structures for table `smw_fpt_mime` ...
   ... creating new index s_id ...done.
   ... creating new index o_hash ...done.
   ... done.
Checking table `smw_fpt_media` ...
   Table not found, now creating...
   ... done.
Checking index structures for table `smw_fpt_media` ...
   ... creating new index s_id ...done.
   ... creating new index o_hash ...done.
   ... done.

@mwjames mwjames removed the bug label Feb 7, 2014
@mwjames mwjames added this to the SMW 1.9.0.3 milestone Feb 7, 2014
@mwjames mwjames closed this as completed Feb 7, 2014
@kghbln
Copy link
Member

kghbln commented Feb 7, 2014

Just closed bug 19487 on bugzilla!

@mwjames
Copy link
Contributor Author

mwjames commented Feb 7, 2014

Just closed bug 19487 on bugzilla!

It just took 5 years ;-)

@JeroenDeDauw
Copy link
Member

It just took 5 years ;-)

Still fast compared to MW core review :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error
Projects
None yet
Development

No branches or pull requests

3 participants