/** * @param File $file * @param bool $dumpContents * @return string */ function writeUpload($file, $dumpContents = false) { if ($file->isOld()) { $archiveName = " " . Xml::element('archivename', null, $file->getArchiveName()) . "\n"; } else { $archiveName = ''; } if ($dumpContents) { $be = $file->getRepo()->getBackend(); # Dump file as base64 # Uses only XML-safe characters, so does not need escaping # @todo Too bad this loads the contents into memory (script might swap) $contents = ' <contents encoding="base64">' . chunk_split(base64_encode($be->getFileContents(array('src' => $file->getPath())))) . " </contents>\n"; } else { $contents = ''; } if ($file->isDeleted(File::DELETED_COMMENT)) { $comment = Xml::element('comment', array('deleted' => 'deleted')); } else { $comment = Xml::elementClean('comment', null, $file->getDescription()); } return " <upload>\n" . $this->writeTimestamp($file->getTimestamp()) . $this->writeContributor($file->getUser('id'), $file->getUser('text')) . " " . $comment . "\n" . " " . Xml::element('filename', null, $file->getName()) . "\n" . $archiveName . " " . Xml::element('src', null, $file->getCanonicalURL()) . "\n" . " " . Xml::element('size', null, $file->getSize()) . "\n" . " " . Xml::element('sha1base36', null, $file->getSha1()) . "\n" . " " . Xml::element('rel', null, $file->getRel()) . "\n" . $contents . " </upload>\n"; }
public static function addToFileHistLine($hist, File $file, &$s, &$rowClass) { if (!$file->isVisible()) { return true; // Don't bother showing notice for deleted revs } # Quality level for old versions selected all at once. # Commons queries cannot be done all at once... if (!$file->isOld() || !$file->isLocal()) { $dbr = wfGetDB(DB_SLAVE); $quality = $dbr->selectField('flaggedrevs', 'fr_quality', array('fr_img_sha1' => $file->getSha1(), 'fr_img_timestamp' => $dbr->timestamp($file->getTimestamp())), __METHOD__); } else { $quality = is_null($file->quality) ? false : $file->quality; } # If reviewed, class the line if ($quality !== false) { $rowClass = FlaggedRevsXML::getQualityColor($quality); } return true; }