예제 #1
0
 /**
  * Add a new image file into the mediawiki infrastructure so that it can
  * be accessed as [[Image:filename.jpg]]
  */
 private static function addMediawikiImage($articleID, &$image)
 {
     // Download the preview image and set the filename to the temporarary location
     $err = self::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 = '{{' . self::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 '';
 }
 /**
  * Add a new image file into the mediawiki infrastructure so that it can
  * be accessed as [[Image:filename.jpg]]
  */
 private static function addMediawikiImage($articleID, &$image, $userIsScreenshotter)
 {
     // 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['mediawikiName'] = $dupTitle;
         return true;
     }
     // 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 . '.' . $ext;
     $i = 1;
     do {
         $title = Title::newFromText($newName, NS_IMAGE);
         if ($title && !$title->exists()) {
             break;
         }
         $newName = $first . ' Version ' . ++$i . '.' . $ext;
     } while ($i <= 1000);
     // insert image into wikihow mediawiki repos
     if (!$userIsScreenshotter) {
         $comment = '{{' . self::PHOTO_LICENSE . '}}';
     } else {
         $comment = '{{' . self::SCREENSHOT_LICENSE . '}}';
     }
     // next 6 lines taken and modified from
     // extensions/wikihow/eiu/Easyimageupload.body.php
     $title = Title::makeTitleSafe(NS_IMAGE, $newName);
     if (!$title) {
         return false;
     }
     $file = new LocalFile($title, RepoGroup::singleton()->getLocalRepo());
     if (!$file) {
         return false;
     }
     $ret = $file->upload($image['filename'], $comment, $comment);
     if (!$ret->ok) {
         return false;
     }
     // 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']);
     // Keep a log of where images were uploaded in wikiphoto_image_names table
     $dbw = self::getDB('write');
     $imgname = $articleID . '/' . $image['name'];
     $sql = 'INSERT INTO wikiphoto_image_names SET filename=' . $dbw->addQuotes($imgname) . ', wikiname=' . $dbw->addQuotes($image['mediawikiName']);
     $dbw->query($sql, __METHOD__);
     return true;
 }