/** * Add a new image file into the mediawiki infrastructure so that it can * be accessed as [[Image:filename.jpg]] */ public static function addMediawikiImage($articleID, &$image) { // Download the preview image and set the filename to the temporarary location $err = WikiVisualTranscoder::downloadImagePreview($image); if ($err) { return $err; } // check if we've already uploaded this image $dupTitle = DupImage::checkDupImage($image['filename']); // if we've already uploaded this image, just return that filename if ($dupTitle) { //$image['dupTitle'] = true; $image['mediawikiName'] = $dupTitle; return ''; } // find name for image; change filename to Filename 1.jpg if // Filename.jpg already existed $regexp = '/[^' . Title::legalChars() . ']+/'; $first = preg_replace($regexp, '', $image['first']); $ext = $image['ext']; $newName = $first . '-preview.' . $ext; $i = 1; do { $title = Title::newFromText($newName, NS_IMAGE); if ($title && !$title->exists()) { break; } $newName = $first . '-preview Version ' . ++$i . '.' . $ext; } while ($i <= 1000); // insert image into wikihow mediawiki repos $comment = '{{' . WikiVisualTranscoder::PHOTO_LICENSE . '}}'; // next 6 lines taken and modified from // extensions/wikihow/eiu/Easyimageupload.body.php $title = Title::makeTitleSafe(NS_IMAGE, $newName); if (!$title) { return "Couln't Make a title"; } $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo()); if (!$file) { return "Couldn't make a local file"; } $ret = $file->upload($image['filename'], $comment, $comment); if (!$ret->ok) { return "Couldn't upload file " . $image['filename']; } // instruct later processing about which mediawiki name was used $image['mediawikiName'] = $newName; // Add our uploaded image to the dup table so it's no uploaded again DupImage::addDupImage($image['filename'], $image['mediawikiName']); return ''; }