remove a whole load of event->user variables that weren't used -- things should be using global user

This commit is contained in:
Shish 2012-08-18 19:45:39 +01:00
parent f3aad43fa3
commit 7dd929e5a8
10 changed files with 23 additions and 25 deletions

View file

@ -140,6 +140,8 @@ abstract class FormatterExtension extends Extension {
*/
abstract class DataHandlerExtension extends Extension {
public function onDataUpload(DataUploadEvent $event) {
global $user;
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
if(!move_upload_to_archive($event)) return;
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
@ -178,15 +180,14 @@ abstract class DataHandlerExtension extends Extension {
if(is_null($image)) {
throw new UploadException("Data handler failed to create image object from data");
}
$iae = new ImageAdditionEvent($event->user, $image);
$iae = new ImageAdditionEvent($image);
send_event($iae);
$event->image_id = $iae->image->id;
// Rating Stuff.
if(!empty($event->metadata['rating'])){
global $user;
$rating = $event->metadata['rating'];
send_event(new RatingSetEvent($image, $user, $rating));
send_event(new RatingSetEvent($image, $rating));
}
// Locked Stuff.

View file

@ -49,7 +49,6 @@ class BulkAdd extends Extension {
private function add_image($tmpname, $filename, $tags) {
assert(file_exists($tmpname));
global $user;
$pathinfo = pathinfo($filename);
if(!array_key_exists('extension', $pathinfo)) {
throw new UploadException("File has no extension");
@ -58,7 +57,7 @@ class BulkAdd extends Extension {
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags;
$metadata['source'] = null;
$event = new DataUploadEvent($user, $tmpname, $metadata);
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
if($event->image_id == -1) {
throw new UploadException("File type not recognised");

View file

@ -227,7 +227,7 @@ class DanbooruApi extends Extension {
//log_debug("danbooru_api", "upload($filename): fileinfo(".var_export($fileinfo,TRUE)."), metadata(".var_export($metadata,TRUE).")...");
try {
$nevent = new DataUploadEvent($user, $file, $metadata);
$nevent = new DataUploadEvent($file, $metadata);
//log_debug("danbooru_api", "send_event(".var_export($nevent,TRUE).")");
send_event($nevent);
// If it went ok, grab the id for the newly uploaded image and pass it in the header

View file

@ -16,7 +16,7 @@ class IcoFileHandler extends Extension {
if(is_null($image)) {
throw new UploadException("Icon handler failed to create image object from data");
}
$iae = new ImageAdditionEvent($event->user, $image);
$iae = new ImageAdditionEvent($image);
send_event($iae);
$event->image_id = $iae->image->id;
}

View file

@ -17,7 +17,7 @@ class SVGFileHandler extends Extension {
if(is_null($image)) {
throw new UploadException("SVG handler failed to create image object from data");
}
$iae = new ImageAdditionEvent($event->user, $image);
$iae = new ImageAdditionEvent($image);
send_event($iae);
$event->image_id = $iae->image->id;
}

View file

@ -20,12 +20,10 @@ class ImageAdditionEvent extends Event {
* this new image.
*
* @sa TagSetEvent
* @param $user The user adding the image
* @param $image The new image to add.
*/
public function ImageAdditionEvent(User $user, Image $image) {
public function ImageAdditionEvent(Image $image) {
$this->image = $image;
$this->user = $user;
}
}
@ -296,7 +294,7 @@ class ImageIO extends Extension {
$merged = array_merge($image->get_tag_array(), $existing->get_tag_array());
send_event(new TagSetEvent($existing, $merged));
if(isset($_GET['rating']) && isset($_GET['update']) && class_exists("Ratings")){
send_event(new RatingSetEvent($existing, $user, $_GET['rating']));
send_event(new RatingSetEvent($existing, $_GET['rating']));
}
if(isset($_GET['source']) && isset($_GET['update'])){
send_event(new SourceSetEvent($existing, $_GET['source']));

View file

@ -20,9 +20,10 @@ class LiveFeed extends Extension {
}
public function onImageAddition($event) {
global $user;
$this->msg(
make_http(make_link("post/view/".$event->image->id))." - ".
"new post by ".$event->user->name
"new post by ".$user->name
);
}
@ -34,9 +35,10 @@ class LiveFeed extends Extension {
}
public function onCommentPosting($event) {
global $user;
$this->msg(
make_http(make_link("post/view/".$event->image_id))." - ".
$event->user->name . ": " . str_replace("\n", " ", $event->comment)
$user->name . ": " . str_replace("\n", " ", $event->comment)
);
}

View file

@ -32,7 +32,7 @@ class Oekaki extends Extension {
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = 'oekaki tagme';
$metadata['source'] = null;
$event = new DataUploadEvent($user, $tmpname, $metadata);
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
if($event->image_id == -1) {
throw new UploadException("File type not recognised");

View file

@ -8,12 +8,11 @@
*/
class RatingSetEvent extends Event {
var $image, $user, $rating;
var $image, $rating;
public function RatingSetEvent(Image $image, User $user, $rating) {
public function RatingSetEvent(Image $image, /*char*/ $rating) {
assert(in_array($rating, array("s", "q", "e", "u")));
$this->image = $image;
$this->user = $user;
$this->rating = $rating;
}
}
@ -89,7 +88,7 @@ class Ratings extends Extension {
global $user;
if($this->can_rate() && isset($_POST["rating"])) {
send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
send_event(new RatingSetEvent($event->image, $_POST['rating']));
}
}
@ -138,7 +137,7 @@ class Ratings extends Extension {
reset($images); // rewind to first element in array.
foreach($images as $image) {
send_event(new RatingSetEvent($image, $user, $_POST['rating']));
send_event(new RatingSetEvent($image, $_POST['rating']));
}
$n += 100;
}

View file

@ -10,7 +10,7 @@
* Occurs when some data is being uploaded.
*/
class DataUploadEvent extends Event {
var $user, $tmpname, $metadata, $hash, $type, $image_id = -1;
var $tmpname, $metadata, $hash, $type, $image_id = -1;
/**
* Some data is being uploaded.
@ -19,10 +19,9 @@ class DataUploadEvent extends Event {
* @param $tmpname The temporary file used for upload.
* @param $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source".
*/
public function DataUploadEvent(User $user, /*string*/ $tmpname, /*array*/ $metadata) {
public function DataUploadEvent(/*string*/ $tmpname, /*array*/ $metadata) {
assert(file_exists($tmpname));
$this->user = $user;
$this->tmpname = $tmpname;
$this->metadata = $metadata;
@ -289,7 +288,7 @@ class Upload extends Extension {
$metadata['replace'] = $replace;
}
$event = new DataUploadEvent($user, $file['tmp_name'], $metadata);
$event = new DataUploadEvent($file['tmp_name'], $metadata);
send_event($event);
if($event->image_id == -1) {
throw new UploadException("File type not recognised");
@ -376,7 +375,7 @@ class Upload extends Extension {
$metadata['replace'] = $replace;
}
$event = new DataUploadEvent($user, $tmp_filename, $metadata);
$event = new DataUploadEvent($tmp_filename, $metadata);
try {
send_event($event);
}