66use wcf \data \attachment \AdministrativeAttachment ;
77use wcf \data \attachment \AdministrativeAttachmentList ;
88use wcf \data \DatabaseObject ;
9+ use wcf \data \object \type \ObjectTypeCache ;
910use wcf \event \gridView \admin \AttachmentGridViewInitialized ;
11+ use wcf \system \database \util \PreparedStatementConditionBuilder ;
1012use wcf \system \gridView \AbstractGridView ;
1113use wcf \system \gridView \GridViewColumn ;
1214use wcf \system \gridView \GridViewRowLink ;
1315use wcf \system \gridView \renderer \AbstractColumnRenderer ;
16+ use wcf \system \gridView \renderer \DefaultColumnRenderer ;
1417use wcf \system \gridView \renderer \FilesizeColumnRenderer ;
1518use wcf \system \gridView \renderer \ILinkColumnRenderer ;
1619use wcf \system \gridView \renderer \NumberColumnRenderer ;
@@ -92,6 +95,27 @@ public function getClasses(): string
9295 ->unsafeDisableEncoding ()
9396 ->renderer (new TruncatedTextColumnRenderer ())
9497 ->sortable (sortByDatabaseColumn: 'file_table.filename ' ),
98+ GridViewColumn::for ('container ' )
99+ ->label ('wcf.acp.attachment.content ' )
100+ ->renderer (
101+ new class extends DefaultColumnRenderer implements ILinkColumnRenderer {
102+ #[\Override]
103+ public function render (mixed $ value , DatabaseObject $ row ): string
104+ {
105+ \assert ($ row instanceof AdministrativeAttachment);
106+
107+ if ($ row ->getContainerObject () === null ) {
108+ return '' ;
109+ }
110+
111+ return \sprintf (
112+ '<a href="%s">%s</a> ' ,
113+ StringUtil::encodeHTML ($ row ->getContainerObject ()->getLink ()),
114+ StringUtil::encodeHTML ($ row ->getContainerObject ()->getTitle ())
115+ );
116+ }
117+ }
118+ ),
95119 GridViewColumn::for ('username ' )
96120 ->label ('wcf.user.username ' )
97121 ->filter (new UserFilter ('username ' , 'wcf.user.username ' , 'user_table.userID ' ))
@@ -168,13 +192,23 @@ public function render(mixed $value, DatabaseObject $row): string
168192 */
169193 private function getAvailableFileTypes (): array
170194 {
195+ $ objectTypeIDs = $ this ->getAvailableObjectTypeIDs ();
196+ if ($ objectTypeIDs === []) {
197+ return [];
198+ }
199+
200+ $ conditionBuilder = new PreparedStatementConditionBuilder ();
201+ $ conditionBuilder ->add ('attachment.fileID IS NOT NULL ' );
202+ $ conditionBuilder ->add ('attachment.objectTypeID IN (?) ' , [$ objectTypeIDs ]);
203+ $ conditionBuilder ->add ('attachment.tmpHash = ? ' , ['' ]);
204+
171205 $ sql = "SELECT DISTINCT file_table.mimeType
172206 FROM wcf1_attachment attachment
173207 LEFT JOIN wcf1_file file_table
174208 ON (file_table.fileID = attachment.fileID)
175- WHERE attachment.fileID IS NOT NULL " ;
209+ " . $ conditionBuilder ;
176210 $ statement = WCF ::getDB ()->prepare ($ sql );
177- $ statement ->execute ();
211+ $ statement ->execute ($ conditionBuilder -> getParameters () );
178212 $ fileTypes = $ statement ->fetchAll (\PDO ::FETCH_COLUMN );
179213
180214 \sort ($ fileTypes );
@@ -191,12 +225,37 @@ public function isAccessible(): bool
191225 #[\Override]
192226 protected function createObjectList (): AdministrativeAttachmentList
193227 {
194- return new AdministrativeAttachmentList ();
228+ $ list = new AdministrativeAttachmentList ();
229+
230+ $ objectTypeIDs = $ this ->getAvailableObjectTypeIDs ();
231+ if ($ objectTypeIDs !== []) {
232+ $ list ->getConditionBuilder ()->add ('attachment.objectTypeID IN (?) ' , [$ objectTypeIDs ]);
233+ } else {
234+ $ list ->getConditionBuilder ()->add ('1=0 ' );
235+ }
236+ $ list ->getConditionBuilder ()->add ('attachment.tmpHash = ? ' , ['' ]);
237+
238+ return $ list ;
195239 }
196240
197241 #[\Override]
198242 protected function getInitializedEvent (): AttachmentGridViewInitialized
199243 {
200244 return new AttachmentGridViewInitialized ($ this );
201245 }
246+
247+ /**
248+ * @return list<int>
249+ */
250+ private function getAvailableObjectTypeIDs (): array
251+ {
252+ $ objectTypeIDs = [];
253+ foreach (ObjectTypeCache::getInstance ()->getObjectTypes ('com.woltlab.wcf.attachment.objectType ' ) as $ objectType ) {
254+ if (!$ objectType ->private ) {
255+ $ objectTypeIDs [] = $ objectType ->objectTypeID ;
256+ }
257+ }
258+
259+ return $ objectTypeIDs ;
260+ }
202261}
0 commit comments