Skip to content

Commit 79e7937

Browse files
committed
Remove error supression for file_exists()
In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost.
1 parent cb339ea commit 79e7937

35 files changed

+140
-140
lines changed

_test/core/DokuWikiTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function setUp() {
5454
foreach (array('default','local','protected') as $config_group) {
5555
if (empty($config_cascade['main'][$config_group])) continue;
5656
foreach ($config_cascade['main'][$config_group] as $config_file) {
57-
if (@file_exists($config_file)) {
57+
if (file_exists($config_file)) {
5858
include($config_file);
5959
}
6060
}
@@ -68,7 +68,7 @@ public function setUp() {
6868
foreach (array('default','local') as $config_group) {
6969
if (empty($config_cascade['license'][$config_group])) continue;
7070
foreach ($config_cascade['license'][$config_group] as $config_file) {
71-
if(@file_exists($config_file)){
71+
if(file_exists($config_file)){
7272
include($config_file);
7373
}
7474
}

feed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ function rss_buildItems(&$rss, &$data, $opt) {
218218
$date = $ditem['date'];
219219
} elseif ($ditem['media']) {
220220
$date = @filemtime(mediaFN($id));
221-
} elseif (@file_exists(wikiFN($id))) {
221+
} elseif (file_exists(wikiFN($id))) {
222222
$date = @filemtime(wikiFN($id));
223223
} elseif($meta['date']['modified']) {
224224
$date = $meta['date']['modified'];

inc/JpegMeta.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ function save($fileName = "") {
936936
if ($fileName == "") {
937937
$tmpName = tempnam(dirname($this->_fileName),'_metatemp_');
938938
$this->_writeJPEG($tmpName);
939-
if (@file_exists($tmpName)) {
939+
if (file_exists($tmpName)) {
940940
return io_rename($tmpName, $this->_fileName);
941941
}
942942
} else {

inc/Sitemapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function generate(){
3333

3434
$sitemap = Sitemapper::getFilePath();
3535

36-
if(@file_exists($sitemap)){
36+
if(file_exists($sitemap)){
3737
if(!is_writable($sitemap)) return false;
3838
}else{
3939
if(!is_writable(dirname($sitemap))) return false;

inc/auth.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ function act_resendpwd() {
11891189
// we're in token phase - get user info from token
11901190

11911191
$tfile = $conf['cachedir'].'/'.$token{0}.'/'.$token.'.pwauth';
1192-
if(!@file_exists($tfile)) {
1192+
if(!file_exists($tfile)) {
11931193
msg($lang['resendpwdbadauth'], -1);
11941194
$INPUT->remove('pwauth');
11951195
return false;

inc/cache.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function cache_parser($id, $file, $mode) {
203203
*/
204204
public function _useCache() {
205205

206-
if (!@file_exists($this->file)) return false; // source exists?
206+
if (!file_exists($this->file)) return false; // source exists?
207207
return parent::_useCache();
208208
}
209209

inc/changelog.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function _handleRecent($line,$ns,$flags,&$seen){
351351
// check existance
352352
if($flags & RECENTS_SKIP_DELETED){
353353
$fn = (($flags & RECENTS_MEDIA_CHANGES) ? mediaFN($recent['id']) : wikiFN($recent['id']));
354-
if(!@file_exists($fn)) return false;
354+
if(!file_exists($fn)) return false;
355355
}
356356

357357
return $recent;
@@ -498,14 +498,14 @@ public function getRevisions($first, $num) {
498498

499499
if($first < 0) {
500500
$first = 0;
501-
} else if(@file_exists($this->getFilename())) {
501+
} else if(file_exists($this->getFilename())) {
502502
// skip current revision if the page exists
503503
$first = max($first + 1, 0);
504504
}
505505

506506
$file = $this->getChangelogFilename();
507507

508-
if(!@file_exists($file)) {
508+
if(!file_exists($file)) {
509509
return $revs;
510510
}
511511
if(filesize($file) < $this->chunk_size || $this->chunk_size == 0) {
@@ -735,7 +735,7 @@ public function getRevisionsAround($rev1, $rev2, $max = 50) {
735735
protected function readloglines($rev) {
736736
$file = $this->getChangelogFilename();
737737

738-
if(!@file_exists($file)) {
738+
if(!file_exists($file)) {
739739
return false;
740740
}
741741

inc/common.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function pageinfo() {
188188

189189
$info['locked'] = checklock($ID);
190190
$info['filepath'] = fullpath(wikiFN($ID));
191-
$info['exists'] = @file_exists($info['filepath']);
191+
$info['exists'] = file_exists($info['filepath']);
192192
$info['currentrev'] = @filemtime($info['filepath']);
193193
if($REV) {
194194
//check if current revision was meant
@@ -202,7 +202,7 @@ function pageinfo() {
202202
} else {
203203
//really use old revision
204204
$info['filepath'] = fullpath(wikiFN($ID, $REV));
205-
$info['exists'] = @file_exists($info['filepath']);
205+
$info['exists'] = file_exists($info['filepath']);
206206
}
207207
}
208208
$info['rev'] = $REV;
@@ -256,7 +256,7 @@ function pageinfo() {
256256

257257
// draft
258258
$draft = getCacheName($info['client'].$ID, '.draft');
259-
if(@file_exists($draft)) {
259+
if(file_exists($draft)) {
260260
if(@filemtime($draft) < @filemtime(wikiFN($ID))) {
261261
// remove stale draft
262262
@unlink($draft);
@@ -352,7 +352,7 @@ function breadcrumbs() {
352352
$crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array();
353353
//we only save on show and existing wiki documents
354354
$file = wikiFN($ID);
355-
if($ACT != 'show' || !@file_exists($file)) {
355+
if($ACT != 'show' || !file_exists($file)) {
356356
$_SESSION[DOKU_COOKIE]['bc'] = $crumbs;
357357
return $crumbs;
358358
}
@@ -853,7 +853,7 @@ function checklock($id) {
853853
$lock = wikiLockFN($id);
854854

855855
//no lockfile
856-
if(!@file_exists($lock)) return false;
856+
if(!file_exists($lock)) return false;
857857

858858
//lockfile expired
859859
if((time() - filemtime($lock)) > $conf['locktime']) {
@@ -907,7 +907,7 @@ function unlock($id) {
907907
global $INPUT;
908908

909909
$lock = wikiLockFN($id);
910-
if(@file_exists($lock)) {
910+
if(file_exists($lock)) {
911911
@list($ip, $session) = explode("\n", io_readFile($lock));
912912
if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) {
913913
@unlink($lock);
@@ -1010,13 +1010,13 @@ function pageTemplate($id) {
10101010
// if the before event did not set a template file, try to find one
10111011
if(empty($data['tplfile'])) {
10121012
$path = dirname(wikiFN($id));
1013-
if(@file_exists($path.'/_template.txt')) {
1013+
if(file_exists($path.'/_template.txt')) {
10141014
$data['tplfile'] = $path.'/_template.txt';
10151015
} else {
10161016
// search upper namespaces for templates
10171017
$len = strlen(rtrim($conf['datadir'], '/'));
10181018
while(strlen($path) >= $len) {
1019-
if(@file_exists($path.'/__template.txt')) {
1019+
if(file_exists($path.'/__template.txt')) {
10201020
$data['tplfile'] = $path.'/__template.txt';
10211021
break;
10221022
}
@@ -1197,13 +1197,13 @@ function saveWikiText($id, $text, $summary, $minor = false) {
11971197
$file = wikiFN($id);
11981198
$old = @filemtime($file); // from page
11991199
$wasRemoved = (trim($text) == ''); // check for empty or whitespace only
1200-
$wasCreated = !@file_exists($file);
1200+
$wasCreated = !file_exists($file);
12011201
$wasReverted = ($REV == true);
12021202
$pagelog = new PageChangeLog($id, 1024);
12031203
$newRev = false;
12041204
$oldRev = $pagelog->getRevisions(-1, 1); // from changelog
12051205
$oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]);
1206-
if(!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) {
1206+
if(!file_exists(wikiFN($id, $old)) && file_exists($file) && $old >= $oldRev) {
12071207
// add old revision to the attic if missing
12081208
saveOldRevision($id);
12091209
// add a changelog entry if this edit came from outside dokuwiki
@@ -1285,7 +1285,7 @@ function saveWikiText($id, $text, $summary, $minor = false) {
12851285
*/
12861286
function saveOldRevision($id) {
12871287
$oldf = wikiFN($id);
1288-
if(!@file_exists($oldf)) return '';
1288+
if(!file_exists($oldf)) return '';
12891289
$date = filemtime($oldf);
12901290
$newf = wikiFN($id, $date);
12911291
io_writeWikiPage($newf, rawWiki($id), $id, $date);
@@ -1743,7 +1743,7 @@ function license_img($type) {
17431743
$try[] = 'lib/images/license/'.$type.'/cc.png';
17441744
}
17451745
foreach($try as $src) {
1746-
if(@file_exists(DOKU_INC.$src)) return $src;
1746+
if(file_exists(DOKU_INC.$src)) return $src;
17471747
}
17481748
return '';
17491749
}

inc/confutils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function retrieveConfig($type,$fn,$params=null) {
206206
foreach (array('default','local','protected') as $config_group) {
207207
if (empty($config_cascade[$type][$config_group])) continue;
208208
foreach ($config_cascade[$type][$config_group] as $file) {
209-
if (@file_exists($file)) {
209+
if (file_exists($file)) {
210210
$config = call_user_func_array($fn,array_merge(array($file),$params));
211211
$combined = array_merge($combined, $config);
212212
}

inc/fetch.functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) {
163163
}
164164

165165
//check file existance
166-
if(!@file_exists($file)) {
166+
if(!file_exists($file)) {
167167
return array(404, 'Not Found');
168168
}
169169

inc/html.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function html_revisions($first=0, $media_id = false){
501501
$form->addElement(form_makeOpenTag('ul'));
502502

503503
if (!$media_id) $exists = $INFO['exists'];
504-
else $exists = @file_exists(mediaFN($id));
504+
else $exists = file_exists(mediaFN($id));
505505

506506
$display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
507507
if (!$display_name) $display_name = $id;
@@ -568,7 +568,7 @@ function html_revisions($first=0, $media_id = false){
568568
$date = dformat($rev);
569569
$info = $changelog->getRevisionInfo($rev);
570570
if($media_id) {
571-
$exists = @file_exists(mediaFN($id, $rev));
571+
$exists = file_exists(mediaFN($id, $rev));
572572
} else {
573573
$exists = page_exists($id, $rev);
574574
}
@@ -765,7 +765,7 @@ function html_recent($first=0, $show_changes='both'){
765765
$href = '';
766766

767767
if (!empty($recent['media'])) {
768-
$diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
768+
$diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && file_exists(mediaFN($recent['id'])));
769769
if ($diff) {
770770
$href = media_managerURL(array('tab_details' => 'history',
771771
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');

inc/indexer.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ protected function unlock() {
10761076
protected function getIndex($idx, $suffix) {
10771077
global $conf;
10781078
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
1079-
if (!@file_exists($fn)) return array();
1079+
if (!file_exists($fn)) return array();
10801080
return file($fn, FILE_IGNORE_NEW_LINES);
10811081
}
10821082

@@ -1118,7 +1118,7 @@ protected function saveIndex($idx, $suffix, &$lines) {
11181118
protected function getIndexKey($idx, $suffix, $id) {
11191119
global $conf;
11201120
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
1121-
if (!@file_exists($fn)) return '';
1121+
if (!file_exists($fn)) return '';
11221122
$fh = @fopen($fn, 'r');
11231123
if (!$fh) return '';
11241124
$ln = -1;
@@ -1228,7 +1228,7 @@ protected function indexLengths($filter) {
12281228
// testing if index files exist only
12291229
$path = $conf['indexdir']."/i";
12301230
foreach ($filter as $key => $value) {
1231-
if (@file_exists($path.$key.'.idx'))
1231+
if (file_exists($path.$key.'.idx'))
12321232
$idx[] = $key;
12331233
}
12341234
} else {
@@ -1339,7 +1339,7 @@ function & idx_get_stopwords() {
13391339
if (is_null($stopwords)) {
13401340
global $conf;
13411341
$swfile = DOKU_INC.'inc/lang/'.$conf['lang'].'/stopwords.txt';
1342-
if(@file_exists($swfile)){
1342+
if(file_exists($swfile)){
13431343
$stopwords = file($swfile, FILE_IGNORE_NEW_LINES);
13441344
}else{
13451345
$stopwords = array();
@@ -1364,7 +1364,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
13641364
$idxtag = metaFN($page,'.indexed');
13651365
// check if page was deleted but is still in the index
13661366
if (!page_exists($page)) {
1367-
if (!@file_exists($idxtag)) {
1367+
if (!file_exists($idxtag)) {
13681368
if ($verbose) print("Indexer: $page does not exist, ignoring".DOKU_LF);
13691369
return false;
13701370
}
@@ -1379,7 +1379,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
13791379
}
13801380

13811381
// check if indexing needed
1382-
if(!$force && @file_exists($idxtag)){
1382+
if(!$force && file_exists($idxtag)){
13831383
if(trim(io_readFile($idxtag)) == idx_get_version()){
13841384
$last = @filemtime($idxtag);
13851385
if($last > @filemtime(wikiFN($page))){
@@ -1392,7 +1392,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
13921392
$indexenabled = p_get_metadata($page, 'internal index', METADATA_RENDER_UNLIMITED);
13931393
if ($indexenabled === false) {
13941394
$result = false;
1395-
if (@file_exists($idxtag)) {
1395+
if (file_exists($idxtag)) {
13961396
$Indexer = idx_get_indexer();
13971397
$result = $Indexer->deletePage($page);
13981398
if ($result === "locked") {
@@ -1494,7 +1494,7 @@ function idx_tokenizer($string, $wc=false) {
14941494
function idx_getIndex($idx, $suffix) {
14951495
global $conf;
14961496
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
1497-
if (!@file_exists($fn)) return array();
1497+
if (!file_exists($fn)) return array();
14981498
return file($fn);
14991499
}
15001500

@@ -1515,7 +1515,7 @@ function idx_listIndexLengths() {
15151515
$docache = false;
15161516
} else {
15171517
clearstatcache();
1518-
if (@file_exists($conf['indexdir'].'/lengths.idx')
1518+
if (file_exists($conf['indexdir'].'/lengths.idx')
15191519
&& (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) {
15201520
if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) !== false) {
15211521
$idx = array();
@@ -1572,7 +1572,7 @@ function idx_indexLengths($filter) {
15721572
// testing if index files exist only
15731573
$path = $conf['indexdir']."/i";
15741574
foreach ($filter as $key => $value) {
1575-
if (@file_exists($path.$key.'.idx'))
1575+
if (file_exists($path.$key.'.idx'))
15761576
$idx[] = $key;
15771577
}
15781578
} else {

inc/infoutils.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function checkUpdateMessages(){
5858
function getVersionData(){
5959
$version = array();
6060
//import version string
61-
if(@file_exists(DOKU_INC.'VERSION')){
61+
if(file_exists(DOKU_INC.'VERSION')){
6262
//official release
6363
$version['date'] = trim(io_readfile(DOKU_INC.'VERSION'));
6464
$version['type'] = 'Release';
@@ -141,20 +141,20 @@ function check(){
141141
if(is_writable($conf['changelog'])){
142142
msg('Changelog is writable',1);
143143
}else{
144-
if (@file_exists($conf['changelog'])) {
144+
if (file_exists($conf['changelog'])) {
145145
msg('Changelog is not writable',-1);
146146
}
147147
}
148148

149-
if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
149+
if (isset($conf['changelog_old']) && file_exists($conf['changelog_old'])) {
150150
msg('Old changelog exists', 0);
151151
}
152152

153-
if (@file_exists($conf['changelog'].'_failed')) {
153+
if (file_exists($conf['changelog'].'_failed')) {
154154
msg('Importing old changelog failed', -1);
155-
} else if (@file_exists($conf['changelog'].'_importing')) {
155+
} else if (file_exists($conf['changelog'].'_importing')) {
156156
msg('Importing old changelog now.', 0);
157-
} else if (@file_exists($conf['changelog'].'_import_ok')) {
157+
} else if (file_exists($conf['changelog'].'_import_ok')) {
158158
msg('Old changelog imported', 1);
159159
if (!plugin_isdisabled('importoldchangelog')) {
160160
msg('Importoldchangelog plugin not disabled after import', -1);

0 commit comments

Comments
 (0)