Extension:GWToolset/Technical Implementation/Handlers/MetadataDetectHandler

GWToolset MetadataDetectHandler.png

Step 1: Metadata DetectionEdit

This handler is used between step 1: metadata detection, and step 2: metadata mapping, in the upload process.


  1. Validates the POST’ed edit token
    1. if invalid, a user error message is displayed.
    2. if valid, calls processRequest()


The expected outcome of POST’ing the metadata detection form is that the extension will receive four items from the form:

  1. A record-element-name that identifies the root element in the metadatafile, which contains the mediafile’s metadata.
  2. A mediawiki-template-name that will be used when mapping the metadata found in the metadatafile.
  3. A metadata-mapping-url to a wiki title previously saved as a metadata mapping ( optional ).
  4. A mediafile-throttle that indicates the number of mediafiles that will be added to the job queue each time a batch upload job is run ( optional, default is 10 ).
  5. A metadata-file-upload, which is a reference to a local metadatafile that will be uploaded and used during the rest of the upload process.

The following describes what happens within the processRequest() method:

  1. UploadHandler->saveMetadataToFileBackend() attempts to save the metadata file provided and returns the relative path to the stored file.
    • if an exception is thrown a user message is displayed.
  2. GWTFileBackend->retrieveFileFromRelativePath() retrieves a FileBackend file based on the relative path provided in step 1.
    • if an exception is thrown a user message is displayed.
  3. XmlDetectHandler->processXml() is sent:
    • the POST’ed form variables as $user_options
    • the FS path to the uploaded stash file
  4. XmlHandler->readXmlAsFile() is sent:
    • the POST’ed form variables as $user_options
    • the FS path to the uploaded stash file
    • a callback method in the XmlDetecHandler
  5. XmlHandler->readXmlAsFile() starts a read process that will:
    • use the callback method provided to process the metadata records found during the read process.
    • continue to the end of the metadata file or stop reading if $read_result['stop-reading'] is set to true.
  6. XmlDetectHandler->findExampleDOMElement(), the callback passed to XmlHandler->processXml() will:
    • use XmlDetectHandler->createExampleDOMElement() to create an example metadata record, the first record found in the metadata file, to display to the user for reference while they map the metadata to the MediaWiki template in step 2.
    • use XmlDetectHandler->findExampleDOMNodes() to find additional XML nodes that may not exist in the example metadata record and add them to it. e.g., the second record contains a node, dc:spatial, which does not exist in the first record; this node is added to the example record.
  7. MediawikiTemplate->getMediaWikiTemplate() attempts to retrieve the MediaWiki template schema via TemplateData. If no TemplateData schema exists it falls back to a hard coded version stored in Config::$mediawiki_templates.
  8. Mapping->retrieve() attempts to retrieve a metadata mapping schema provided as a wiki title in step 1. The expected schema format is a valid JSON.
    • If no wiki title was provided none is used.
    • if a wiki title was provided, but does not exist, a user error message is displayed.
    • if a wiki title was provided, exists, but the schema is invalid, a user error message is displayed.
  9. MetadataMappingForm::getForm() sets up the HTML form and returns it to SpecialGWToolset to be displayed.