if an admin tries to use a banned tag (eg during a mass-revert), ignore it
This commit is contained in:
		
							parent
							
								
									8c713af952
								
							
						
					
					
						commit
						aeb9829c9a
					
				@ -55,8 +55,13 @@ class NotATag extends Extension
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function onTagSet(TagSetEvent $event)
 | 
					    public function onTagSet(TagSetEvent $event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        global $user;
 | 
				
			||||||
 | 
					        if ($user->can(Permissions::BAN_IMAGE)) {
 | 
				
			||||||
 | 
					            $event->tags = $this->strip($event->tags);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
            $this->scan($event->tags);
 | 
					            $this->scan($event->tags);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * #param string[] $tags_mixed
 | 
					     * #param string[] $tags_mixed
 | 
				
			||||||
@ -70,17 +75,36 @@ class NotATag extends Extension
 | 
				
			|||||||
            $tags[] = strtolower($tag);
 | 
					            $tags[] = strtolower($tag);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $pairs = $database->get_all("SELECT * FROM untags");
 | 
					        $pairs = $database->get_pairs("SELECT LOWER(tag), redirect FROM untags");
 | 
				
			||||||
        foreach ($pairs as $tag_url) {
 | 
					        foreach ($pairs as $tag => $url) {
 | 
				
			||||||
            $tag = strtolower($tag_url[0]);
 | 
					            if (in_array(strtolower($tag), $tags)) {
 | 
				
			||||||
            $url = $tag_url[1];
 | 
					                throw new TagSetException("Invalid tag used: $tag", $url);
 | 
				
			||||||
            if (in_array($tag, $tags)) {
 | 
					 | 
				
			||||||
                header("Location: $url");
 | 
					 | 
				
			||||||
                exit; # FIXME: need a better way of aborting the tag-set or upload
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * #param string[] $tags
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private function strip(array $tags): array
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        global $database;
 | 
				
			||||||
 | 
					        $untags = $database->get_col("SELECT LOWER(tag) FROM untags");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ok_tags = [];
 | 
				
			||||||
 | 
					        foreach ($tags as $tag) {
 | 
				
			||||||
 | 
					            if (!in_array(strtolower($tag), $untags)) {
 | 
				
			||||||
 | 
					                $ok_tags[] = $tag;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (count($ok_tags) == 0) {
 | 
				
			||||||
 | 
					            $ok_tags = ["tagme"];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $ok_tags;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
 | 
					    public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        global $user;
 | 
					        global $user;
 | 
				
			||||||
 | 
				
			|||||||
@ -38,6 +38,17 @@ class SourceSetEvent extends Event
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TagSetException extends SCoreException
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public $redirect;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function __construct(string $msg, ?string $redirect = null)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        parent::__construct($msg, null);
 | 
				
			||||||
 | 
					        $this->redirect = $redirect;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TagSetEvent extends Event
 | 
					class TagSetEvent extends Event
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /** @var Image */
 | 
					    /** @var Image */
 | 
				
			||||||
@ -162,7 +173,7 @@ class TagEdit extends Extension
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function onImageInfoSet(ImageInfoSetEvent $event)
 | 
					    public function onImageInfoSet(ImageInfoSetEvent $event)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        global $user;
 | 
					        global $page, $user;
 | 
				
			||||||
        if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($_POST['tag_edit__owner'])) {
 | 
					        if ($user->can(Permissions::EDIT_IMAGE_OWNER) && isset($_POST['tag_edit__owner'])) {
 | 
				
			||||||
            $owner = User::by_name($_POST['tag_edit__owner']);
 | 
					            $owner = User::by_name($_POST['tag_edit__owner']);
 | 
				
			||||||
            if ($owner instanceof User) {
 | 
					            if ($owner instanceof User) {
 | 
				
			||||||
@ -172,7 +183,15 @@ class TagEdit extends Extension
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if ($user->can(Permissions::EDIT_IMAGE_TAG) && isset($_POST['tag_edit__tags'])) {
 | 
					        if ($user->can(Permissions::EDIT_IMAGE_TAG) && isset($_POST['tag_edit__tags'])) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
                send_event(new TagSetEvent($event->image, Tag::explode($_POST['tag_edit__tags'])));
 | 
					                send_event(new TagSetEvent($event->image, Tag::explode($_POST['tag_edit__tags'])));
 | 
				
			||||||
 | 
					            } catch (TagSetException $e) {
 | 
				
			||||||
 | 
					                if ($e->redirect) {
 | 
				
			||||||
 | 
					                    $page->flash("{$e->getMessage()}, please see {$e->redirect}");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    $page->flash($e->getMessage());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if ($user->can(Permissions::EDIT_IMAGE_SOURCE) && isset($_POST['tag_edit__source'])) {
 | 
					        if ($user->can(Permissions::EDIT_IMAGE_SOURCE) && isset($_POST['tag_edit__source'])) {
 | 
				
			||||||
            if (isset($_POST['tag_edit__tags']) ? !preg_match('/source[=|:]/', $_POST["tag_edit__tags"]) : true) {
 | 
					            if (isset($_POST['tag_edit__tags']) ? !preg_match('/source[=|:]/', $_POST["tag_edit__tags"]) : true) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user