/**
  * Applies HTTP content negotiation.
  * If the negotiation is successfull, this method will set the appropriate redirect
  * in the OutputPage object and return. Otherwise, an HttpError is thrown.
  *
  * @param WebRequest $request
  * @param OutputPage $output
  * @param EntityId $id The ID of the entity to show
  * @param int      $revision The desired revision
  *
  * @throws HttpError
  */
 public function httpContentNegotiation(WebRequest $request, OutputPage $output, EntityId $id, $revision = 0)
 {
     $headers = $request->getAllHeaders();
     if (isset($headers['ACCEPT'])) {
         $parser = new HttpAcceptParser();
         $accept = $parser->parseWeights($headers['ACCEPT']);
     } else {
         // anything goes
         $accept = array('*' => 0.1);
         $defaultFormat = $this->entityDataFormatProvider->getFormatName($this->defaultFormat);
         $defaultMime = $this->entityDataFormatProvider->getMimeType($defaultFormat);
         // prefer the default
         if ($defaultMime != null) {
             $accept[$defaultMime] = 1;
         }
     }
     $mimeTypes = $this->entityDataFormatProvider->getSupportedMimeTypes();
     $mimeTypes[] = 'text/html';
     // HTML is handled by the normal page URL
     $negotiator = new HttpAcceptNegotiator($mimeTypes);
     $format = $negotiator->getBestSupportedKey($accept, null);
     if ($format === null) {
         $mimeTypes = implode(', ', $this->entityDataFormatProvider->getSupportedMimeTypes());
         throw new HttpError(406, wfMessage('wikibase-entitydata-not-acceptable')->params($mimeTypes));
     }
     $format = $this->getCanonicalFormat($format);
     $url = $this->uriManager->getDocUrl($id, $format, $revision);
     $output->redirect($url, 303);
 }
 /**
  * Output entity data.
  *
  * @param string $format The name (mime type of file extension) of the format to use
  * @param EntityRevision $entityRevision The entity
  * @param RedirectRevision|null $followedRedirect The redirect that led to the entity, or null
  * @param EntityId[] $incomingRedirects Incoming redirects to include in the output
  * @param string|null $flavor The type of the output provided by serializer
  *
  * @return array tuple of ( $data, $contentType )
  * @throws MWException
  */
 public function getSerializedData($format, EntityRevision $entityRevision, RedirectRevision $followedRedirect = null, array $incomingRedirects = array(), $flavor = null)
 {
     $formatName = $this->entityDataFormatProvider->getFormatName($format);
     if ($formatName === null) {
         throw new MWException("Unsupported format: {$format}");
     }
     $serializer = $this->createApiSerializer($formatName);
     if ($serializer !== null) {
         $data = $this->getApiSerialization($entityRevision, $serializer);
         $contentType = $serializer->getIsHtml() ? 'text/html' : $serializer->getMimeType();
     } else {
         $rdfBuilder = $this->createRdfBuilder($formatName, $flavor);
         if ($rdfBuilder === null) {
             throw new MWException("Could not create serializer for {$formatName}");
         }
         $data = $this->rdfSerialize($entityRevision, $followedRedirect, $incomingRedirects, $rdfBuilder, $flavor);
         $mimeTypes = $this->rdfWriterFactory->getMimeTypes($formatName);
         $contentType = reset($mimeTypes);
     }
     return array($data, $contentType);
 }