5 var $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType;
6 var $mTitle = false, $mTitleError = 0;
7 var $mFilteredName, $mFinalExtension;
11 const BEFORE_PROCESSING
= 1;
12 const LARGE_FILE_SERVER
= 2;
14 const MIN_LENGHT_PARTNAME
= 4;
15 const ILLEGAL_FILENAME
= 5;
16 const PROTECTED_PAGE
= 6;
17 const OVERWRITE_EXISTING_FILE
= 7;
18 const FILETYPE_MISSING
= 8;
19 const FILETYPE_BADTYPE
= 9;
20 const VERIFICATION_ERROR
= 10;
21 const UPLOAD_VERIFICATION_ERROR
= 11;
22 const UPLOAD_WARNING
= 12;
23 const INTERNAL_ERROR
= 13;
25 const SESSION_VERSION
= 2;
27 static function isEnabled() {
28 global $wgEnableUploads;
29 return $wgEnableUploads;
32 function __construct( $name ) {
33 $this->mDesiredDestName
= $name;
37 function verifyUpload( &$resultDetails ) {
41 * If there was no filename or a zero size given, give up quick.
43 if( empty( $this->mFileSize
) ) {
44 return self
::EMPTY_FILE
;
47 $nt = $this->getTitle();
48 if( is_null( $nt ) ) {
49 if( $this->mTitleError
== self
::ILLEGAL_FILENAME
)
50 $resultDetails = array( 'filtered' => $this->mFilteredName
);
51 if ( $this->mTitleError
== self
::FILETYPE_BADTYPE
)
52 $resultDetails = array( 'finalExt' => $this->mFinalExtension
);
53 return $this->mTitleError
;
55 $this->mLocalFile
= wfLocalFile( $nt );
56 $this->mDestName
= $this->mLocalFile
->getName();
59 * In some cases we may forbid overwriting of existing files.
61 $overwrite = $this->checkOverwrite( $this->mDestName
);
62 if( $overwrite !== true ) {
63 $resultDetails = array( 'overwrite' => $overwrite );
64 return self
::OVERWRITE_EXISTING_FILE
;
68 * Look at the contents of the file; if we can recognize the
69 * type but it's corrupt or data of the wrong type, we should
70 * probably not accept it.
72 $veri = $this->verifyFile( $this->mTempPath
);
74 if( $veri !== true ) {
75 if( !is_array( $veri ) )
76 $veri = array( $veri );
77 $resultDetails = array( 'veri' => $veri );
78 return self
::VERIFICATION_ERROR
;
82 if( !wfRunHooks( 'UploadVerification',
83 array( $this->mDestName
, $this->mTempPath
, &$error ) ) ) {
84 $resultDetails = array( 'error' => $error );
85 return self
::UPLOAD_VERIFICATION_ERROR
;
92 * Verifies that it's ok to include the uploaded file
94 * @param string $tmpfile the full path of the temporary file to verify
95 * @param string $extension The filename extension that the file is to be served with
96 * @return mixed true of the file is verified, a WikiError object otherwise.
98 protected function verifyFile( $tmpfile ) {
99 $this->mFileProps
= File
::getPropsFromPath( $this->mTempPath
,
100 $this->mFinalExtension
);
101 $this->checkMacBinary();
103 #magically determine mime type
104 $magic = MimeMagic
::singleton();
105 $mime = $magic->guessMimeType( $tmpfile, false );
107 #check mime type, if desired
108 global $wgVerifyMimeType;
109 if ( $wgVerifyMimeType ) {
111 wfDebug ( "\n\nmime: <$mime> extension: <{$this->mFinalExtension}>\n\n");
112 #check mime type against file extension
113 if( !self
::verifyExtension( $mime, $this->mFinalExtension
) ) {
114 return 'uploadcorrupt';
117 #check mime type blacklist
118 global $wgMimeTypeBlacklist;
119 if( isset($wgMimeTypeBlacklist) && !is_null($wgMimeTypeBlacklist)
120 && $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
121 return array( 'filetype-badmime', $mime );
125 #check for htmlish code and javascript
126 if( $this->detectScript ( $tmpfile, $mime, $this->mFinalExtension
) ) {
127 return 'uploadscripted';
131 * Scan the uploaded file for viruses
133 $virus = $this->detectVirus($tmpfile);
135 return array( 'uploadvirus', $virus );
138 wfDebug( __METHOD__
.": all clear; passing.\n" );
142 function verifyPermissions( $user ) {
144 * If the image is protected, non-sysop users won't be able
145 * to modify it by uploading a new revision.
147 $nt = $this->getTitle();
150 $permErrors = $nt->getUserPermissionsErrors( 'edit', $user );
151 $permErrorsUpload = $nt->getUserPermissionsErrors( 'upload', $user );
152 $permErrorsCreate = ( $nt->exists() ?
array() : $nt->getUserPermissionsErrors( 'create', $user ) );
153 if( $permErrors ||
$permErrorsUpload ||
$permErrorsCreate ) {
154 $permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsUpload, $permErrors ) );
155 $permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsCreate, $permErrors ) );
161 function checkWarnings() {
164 $filename = $this->mLocalFile
->getName();
165 $n = strrpos( $filename, '.' );
166 $partname = $n ?
substr( $filename, 0, $n ) : $filename;
168 global $wgCapitalLinks;
169 if( $this->mDesiredDestName
!= $filename )
170 // Use mFilteredName so that we don't have to bother about spaces
171 $warning['badfilename'] = $filename;
173 global $wgCheckFileExtensions, $wgFileExtensions;
174 if ( $wgCheckFileExtensions ) {
175 if ( !$this->checkFileExtension( $this->mFinalExtension
, $wgFileExtensions ) )
176 $warning['filetype-unwanted-type'] = $this->mFinalExtension
;
179 global $wgUploadSizeWarning;
180 if ( $wgUploadSizeWarning && ( $this->mFileSize
> $wgUploadSizeWarning ) )
181 $warning['large-file'] = $wgUploadSizeWarning;
183 if ( $this->mFileSize
== 0 )
184 $warning['emptyfile'] = true;
186 $exists = self
::getExistsWarning( $this->mLocalFile
);
187 if( $exists !== false )
188 $warning['exists'] = $exists;
191 if( $exists !== false && $exists[0] != 'thumb'
192 && self
::isThumbName( $this->mLocalFile
->getName() ) )
193 $warning['file-thumbnail-no'] = substr( $filename , 0,
194 strpos( $nt->getText() , '-' ) +
1 );
196 $hash = File
::sha1Base36( $this->mTempPath
);
197 $dupes = RepoGroup
::singleton()->findBySha1( $hash );
199 $warning['duplicate'] = $dupes;
201 $filenamePrefixBlacklist = self
::getFilenamePrefixBlacklist();
202 foreach( $filenamePrefixBlacklist as $prefix ) {
203 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
204 $warning['filename-bad-prefix'] = $prefix;
209 # If the file existed before and was deleted, warn the user of this
210 # Don't bother doing so if the file exists now, however
211 if( $this->mLocalFile
->wasDeleted() && !$file->exists() )
212 $warning['filewasdeleted'] = true;
217 function performUpload( $comment, $pageText, $watch, $user ) {
218 $status = $this->mLocalFile
->upload( $this->mTempPath
, $comment, $pageText,
219 File
::DELETE_SOURCE
, $this->mFileProps
, false, $user );
221 if( $status->isGood() && $watch ) {
222 $user->addWatch( $this->mLocalFile
->getTitle() );
225 if( $status->isGood() )
226 wfRunHooks( 'UploadComplete', array( &$this ) );
232 * Returns a title or null
234 function getTitle() {
235 if ( $this->mTitle
!== false )
236 return $this->mTitle
;
239 * Chop off any directories in the given filename. Then
240 * filter out illegal characters, and try to make a legible name
241 * out of it. We'll strip some silently that Title would die on.
244 $basename = $this->mDesiredDestName
;
246 $this->mFilteredName
= wfStripIllegalFilenameChars( $basename );
249 * We'll want to blacklist against *any* 'extension', and use
250 * only the final one for the whitelist.
252 list( $partname, $ext ) = $this->splitExtensions( $this->mFilteredName
);
254 if( count( $ext ) ) {
255 $this->mFinalExtension
= $ext[count( $ext ) - 1];
257 $this->mFinalExtension
= '';
260 /* Don't allow users to override the blacklist (check file extension) */
261 global $wgCheckFileExtensions, $wgStrictFileExtensions;
262 global $wgFileExtensions, $wgFileBlacklist;
263 if ( $this->mFinalExtension
== '' ) {
264 $this->mTitleError
= self
::FILETYPE_MISSING
;
265 return $this->mTitle
= null;
266 } elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
267 ( $wgCheckFileExtensions && $wgStrictFileExtensions &&
268 !$this->checkFileExtension( $this->mFinalExtension
, $wgFileExtensions ) ) ) {
269 $this->mTitleError
= self
::FILETYPE_BADTYPE
;
270 return $this->mTitle
= null;
273 # If there was more than one "extension", reassemble the base
274 # filename to prevent bogus complaints about length
275 if( count( $ext ) > 1 ) {
276 for( $i = 0; $i < count( $ext ) - 1; $i++
)
277 $partname .= '.' . $ext[$i];
280 if( strlen( $partname ) < 1 ) {
281 $this->mTitleError
= self
::MIN_LENGHT_PARTNAME
;
282 return $this->mTitle
= null;
285 $nt = Title
::makeTitleSafe( NS_IMAGE
, $this->mFilteredName
);
286 if( is_null( $nt ) ) {
287 $this->mTitleError
= self
::ILLEGAL_FILENAME
;
288 return $this->mTitle
= null;
290 return $this->mTitle
= $nt;
293 function getLocalFile() {
294 if( is_null( $this->mLocalFile
) ) {
295 $nt = $this->getTitle();
296 $this->mLocalFile
= is_null( $nt ) ?
null : wfLocalFile( $nt );
298 return $this->mLocalFile
;
302 * Stash a file in a temporary directory for later processing
303 * after the user has confirmed it.
305 * If the user doesn't explicitly cancel or accept, these files
306 * can accumulate in the temp directory.
308 * @param string $saveName - the destination filename
309 * @param string $tempName - the source temporary file to save
310 * @return string - full path the stashed file, or false on failure
313 function saveTempUploadedFile( $saveName, $tempName ) {
315 $repo = RepoGroup
::singleton()->getLocalRepo();
316 $status = $repo->storeTemp( $saveName, $tempName );
317 if ( !$status->isGood() ) {
318 $this->showError( $status->getWikiText() );
321 return $status->value
;
326 * Stash a file in a temporary directory for later processing,
327 * and save the necessary descriptive info into the session.
328 * Returns a key value which will be passed through a form
329 * to pick up the path info on a later invocation.
334 function stashSession() {
335 $stash = $this->saveTempUploadedFile( $this->mDestName
, $this->mTempPath
);
338 # Couldn't save the file.
342 $key = mt_rand( 0, 0x7fffffff );
343 $_SESSION['wsUploadData'][$key] = array(
344 'mTempPath' => $stash,
345 'mFileSize' => $this->mFileSize
,
346 'mSrcName' => $this->mSrcName
,
347 'mFileProps' => $this->mFileProps
,
348 'version' => self
::SESSION_VERSION
,
354 * Remove a temporarily kept file stashed by saveTempUploadedFile().
357 function unsaveUploadedFile() {
358 $repo = RepoGroup
::singleton()->getLocalRepo();
359 $success = $repo->freeTemp( $this->mTempPath
);
364 * If we've modified the upload file we need to manually remove it
365 * on exit to clean up.
368 function cleanupTempFile() {
369 if ( $this->mRemoveTempFile
&& file_exists( $this->mTempPath
) ) {
370 wfDebug( __METHOD__
.": Removing temporary file {$this->mTempPath}\n" );
371 unlink( $this->mTempPath
);
375 function getTempPath() {
376 return $this->mTempPath
;
381 * Split a file into a base name and all dot-delimited 'extensions'
382 * on the end. Some web server configurations will fall back to
383 * earlier pseudo-'extensions' to determine type and execute
384 * scripts, so the blacklist needs to check them all.
388 function splitExtensions( $filename ) {
389 $bits = explode( '.', $filename );
390 $basename = array_shift( $bits );
391 return array( $basename, $bits );
395 * Perform case-insensitive match against a list of file extensions.
396 * Returns true if the extension is in the list.
402 function checkFileExtension( $ext, $list ) {
403 return in_array( strtolower( $ext ), $list );
407 * Perform case-insensitive match against a list of file extensions.
408 * Returns true if any of the extensions are in the list.
414 function checkFileExtensionList( $ext, $list ) {
415 foreach( $ext as $e ) {
416 if( in_array( strtolower( $e ), $list ) ) {
425 * Checks if the mime type of the uploaded file matches the file extension.
427 * @param string $mime the mime type of the uploaded file
428 * @param string $extension The filename extension that the file is to be served with
431 public static function verifyExtension( $mime, $extension ) {
432 $magic = MimeMagic
::singleton();
434 if ( ! $mime ||
$mime == 'unknown' ||
$mime == 'unknown/unknown' )
435 if ( ! $magic->isRecognizableExtension( $extension ) ) {
436 wfDebug( __METHOD__
.": passing file with unknown detected mime type; " .
437 "unrecognized extension '$extension', can't verify\n" );
440 wfDebug( __METHOD__
.": rejecting file with unknown detected mime type; ".
441 "recognized extension '$extension', so probably invalid file\n" );
445 $match= $magic->isMatchingExtension($extension,$mime);
448 wfDebug( __METHOD__
.": no file extension known for mime type $mime, passing file\n" );
450 } elseif ($match===true) {
451 wfDebug( __METHOD__
.": mime type $mime matches extension $extension, passing file\n" );
453 #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it!
457 wfDebug( __METHOD__
.": mime type $mime mismatches file extension $extension, rejecting file\n" );
463 * Heuristic for detecting files that *could* contain JavaScript instructions or
464 * things that may look like HTML to a browser and are thus
465 * potentially harmful. The present implementation will produce false positives in some situations.
467 * @param string $file Pathname to the temporary upload file
468 * @param string $mime The mime type of the file
469 * @param string $extension The extension of the file
470 * @return bool true if the file contains something looking like embedded scripts
472 function detectScript($file, $mime, $extension) {
473 global $wgAllowTitlesInSVG;
475 #ugly hack: for text files, always look at the entire file.
476 #For binary field, just check the first K.
478 if (strpos($mime,'text/')===0) $chunk = file_get_contents( $file );
480 $fp = fopen( $file, 'rb' );
481 $chunk = fread( $fp, 1024 );
485 $chunk= strtolower( $chunk );
487 if (!$chunk) return false;
489 #decode from UTF-16 if needed (could be used for obfuscation).
490 if (substr($chunk,0,2)=="\xfe\xff") $enc= "UTF-16BE";
491 elseif (substr($chunk,0,2)=="\xff\xfe") $enc= "UTF-16LE";
494 if ($enc) $chunk= iconv($enc,"ASCII//IGNORE",$chunk);
496 $chunk= trim($chunk);
498 #FIXME: convert from UTF-16 if necessarry!
500 wfDebug("SpecialUpload::detectScript: checking for embedded scripts and HTML stuff\n");
502 #check for HTML doctype
503 if (eregi("<!DOCTYPE *X?HTML",$chunk)) return true;
506 * Internet Explorer for Windows performs some really stupid file type
507 * autodetection which can cause it to interpret valid image files as HTML
508 * and potentially execute JavaScript, creating a cross-site scripting
511 * Apple's Safari browser also performs some unsafe file type autodetection
512 * which can cause legitimate files to be interpreted as HTML if the
513 * web server is not correctly configured to send the right content-type
514 * (or if you're really uploading plain text and octet streams!)
516 * Returns true if IE is likely to mistake the given file for HTML.
517 * Also returns true if Safari would mistake the given file for HTML
518 * when served with a generic content-type.
524 '<html', #also in safari
527 '<script', #also in safari
530 if( ! $wgAllowTitlesInSVG && $extension !== 'svg' && $mime !== 'image/svg' ) {
534 foreach( $tags as $tag ) {
535 if( false !== strpos( $chunk, $tag ) ) {
541 * look for javascript
544 #resolve entity-refs to look at attributes. may be harsh on big files... cache result?
545 $chunk = Sanitizer
::decodeCharReferences( $chunk );
547 #look for script-types
548 if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim',$chunk)) return true;
550 #look for html-style script-urls
551 if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
553 #look for css-style script-urls
554 if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) return true;
556 wfDebug("SpecialUpload::detectScript: no scripts found\n");
561 * Generic wrapper function for a virus scanner program.
562 * This relies on the $wgAntivirus and $wgAntivirusSetup variables.
563 * $wgAntivirusRequired may be used to deny upload if the scan fails.
565 * @param string $file Pathname to the temporary upload file
566 * @return mixed false if not virus is found, NULL if the scan fails or is disabled,
567 * or a string containing feedback from the virus scanner if a virus was found.
568 * If textual feedback is missing but a virus was found, this function returns true.
570 function detectVirus($file) {
571 global $wgAntivirus, $wgAntivirusSetup, $wgAntivirusRequired, $wgOut;
573 if ( !$wgAntivirus ) {
574 wfDebug( __METHOD__
.": virus scanner disabled\n");
578 if ( !$wgAntivirusSetup[$wgAntivirus] ) {
579 wfDebug( __METHOD__
.": unknown virus scanner: $wgAntivirus\n" );
580 $wgOut->wrapWikiMsg( '<div class="error">$1</div>', array( 'virus-badscanner', $wgAntivirus ) );
581 return wfMsg('virus-unknownscanner') . " $wgAntivirus";
584 # look up scanner configuration
585 $command = $wgAntivirusSetup[$wgAntivirus]["command"];
586 $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]["codemap"];
587 $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]["messagepattern"] ) ?
588 $wgAntivirusSetup[$wgAntivirus]["messagepattern"] : null;
590 if ( strpos( $command,"%f" ) === false ) {
591 # simple pattern: append file to scan
592 $command .= " " . wfEscapeShellArg( $file );
594 # complex pattern: replace "%f" with file to scan
595 $command = str_replace( "%f", wfEscapeShellArg( $file ), $command );
598 wfDebug( __METHOD__
.": running virus scan: $command \n" );
600 # execute virus scanner
603 #NOTE: there's a 50 line workaround to make stderr redirection work on windows, too.
604 # that does not seem to be worth the pain.
605 # Ask me (Duesentrieb) about it if it's ever needed.
607 if ( wfIsWindows() ) {
608 exec( "$command", $output, $exitCode );
610 exec( "$command 2>&1", $output, $exitCode );
613 # map exit code to AV_xxx constants.
614 $mappedCode = $exitCode;
615 if ( $exitCodeMap ) {
616 if ( isset( $exitCodeMap[$exitCode] ) ) {
617 $mappedCode = $exitCodeMap[$exitCode];
618 } elseif ( isset( $exitCodeMap["*"] ) ) {
619 $mappedCode = $exitCodeMap["*"];
623 if ( $mappedCode === AV_SCAN_FAILED
) {
624 # scan failed (code was mapped to false by $exitCodeMap)
625 wfDebug( __METHOD__
.": failed to scan $file (code $exitCode).\n" );
627 if ( $wgAntivirusRequired ) {
628 return wfMsg('virus-scanfailed', array( $exitCode ) );
632 } else if ( $mappedCode === AV_SCAN_ABORTED
) {
633 # scan failed because filetype is unknown (probably imune)
634 wfDebug( __METHOD__
.": unsupported file type $file (code $exitCode).\n" );
636 } else if ( $mappedCode === AV_NO_VIRUS
) {
638 wfDebug( __METHOD__
.": file passed virus scan.\n" );
641 $output = join( "\n", $output );
642 $output = trim( $output );
645 $output = true; #if there's no output, return true
646 } elseif ( $msgPattern ) {
648 if ( preg_match( $msgPattern, $output, $groups ) ) {
650 $output = $groups[1];
655 wfDebug( __METHOD__
.": FOUND VIRUS! scanner feedback: $output" );
661 * Check if the temporary file is MacBinary-encoded, as some uploads
662 * from Internet Explorer on Mac OS Classic and Mac OS X will be.
663 * If so, the data fork will be extracted to a second temporary file,
664 * which will then be checked for validity and either kept or discarded.
668 function checkMacBinary() {
669 $macbin = new MacBinary( $this->mTempPath
);
670 if( $macbin->isValid() ) {
671 $dataFile = tempnam( wfTempDir(), "WikiMacBinary" );
672 $dataHandle = fopen( $dataFile, 'wb' );
674 wfDebug( "SpecialUpload::checkMacBinary: Extracting MacBinary data fork to $dataFile\n" );
675 $macbin->extractData( $dataHandle );
677 $this->mTempPath
= $dataFile;
678 $this->mFileSize
= $macbin->dataForkLength();
680 // We'll have to manually remove the new file if it's not kept.
681 $this->mRemoveTempFile
= true;
687 * Check if there's an overwrite conflict and, if so, if restrictions
688 * forbid this user from performing the upload.
690 * @return mixed true on success, WikiError on failure
693 function checkOverwrite() {
695 // First check whether the local file can be overwritten
696 if( $this->mLocalFile
->exists() )
697 if( !self
::userCanReUpload( $wgUser, $this->mLocalFile
) )
698 return 'fileexists-forbidden';
700 // Check shared conflicts
701 $file = wfFindFile( $this->mLocalFile
->getName() );
702 if ( $file && ( !$wgUser->isAllowed( 'reupload' ) ||
703 !$wgUser->isAllowed( 'reupload-shared' ) ) )
704 return 'fileexists-shared-forbidden';
711 * Check if a user is the last uploader
714 * @param string $img, image name
717 public static function userCanReUpload( User
$user, $img ) {
718 if( $user->isAllowed( 'reupload' ) )
719 return true; // non-conditional
720 if( !$user->isAllowed( 'reupload-own' ) )
722 if( is_string( $img ) )
723 $img = wfLocalFile( $img );
724 if ( !( $img instanceof LocalFile
) )
727 return $user->getId() == $img->getUser( 'id' );
730 public static function getExistsWarning( $file ) {
731 if( $file->exists() )
732 return array( 'exists', $file );
734 if( $file->getTitle()->getArticleID() )
735 return array( 'page-exists', false );
737 if( strpos( $file->getName(), '.' ) == false ) {
738 $partname = $file->getName();
741 $n = strrpos( $file->getName(), '.' );
742 $rawExtension = substr( $file->getName(), $n +
1 );
743 $partname = substr( $file->getName(), 0, $n );
746 if ( $rawExtension != $file->getExtension() ) {
747 // We're not using the normalized form of the extension.
748 // Normal form is lowercase, using most common of alternate
749 // extensions (eg 'jpg' rather than 'JPEG').
751 // Check for another file using the normalized form...
752 $nt_lc = Title
::makeTitle( NS_IMAGE
, $partname . '.' . $file->getExtension() );
753 $file_lc = wfLocalFile( $nt_lc );
755 if( $file_lc->exists() )
756 return array( 'exists-normalized', $file_lc );
759 if ( self
::isThumbName( $file->getName() ) ) {
760 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
761 $nt_thb = Title
::newFromText( substr( $partname , strpos( $partname , '-' ) +
1 ) . '.' . $rawExtension );
762 $file_thb = wfLocalFile( $nt_thb );
763 if( $file_thb->exists() )
764 return array( 'thumb', $file_thb );
770 public static function isThumbName( $filename ) {
771 $n = strrpos( $filename, '.' );
772 $partname = $n ?
substr( $filename, 0, $n ) : $filename;
774 substr( $partname , 3, 3 ) == 'px-' ||
775 substr( $partname , 2, 3 ) == 'px-'
777 ereg( "[0-9]{2}" , substr( $partname , 0, 2) );
781 * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]]
783 * @return array list of prefixes
785 public static function getFilenamePrefixBlacklist() {
786 $blacklist = array();
787 $message = wfMsgForContent( 'filename-prefix-blacklist' );
788 if( $message && !( wfEmptyMsg( 'filename-prefix-blacklist', $message ) ||
$message == '-' ) ) {
789 $lines = explode( "\n", $message );
790 foreach( $lines as $line ) {
791 // Remove comment lines
792 $comment = substr( trim( $line ), 0, 1 );
793 if ( $comment == '#' ||
$comment == '' ) {
796 // Remove additional comments after a prefix
797 $comment = strpos( $line, '#' );
798 if ( $comment > 0 ) {
799 $line = substr( $line, 0, $comment-1 );
801 $blacklist[] = trim( $line );