Skip to content

Commit

Permalink
Remove error supression for file_exists()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
splitbrain committed Jan 7, 2015
1 parent cb339ea commit 79e7937
Show file tree
Hide file tree
Showing 35 changed files with 140 additions and 140 deletions.
4 changes: 2 additions & 2 deletions _test/core/DokuWikiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function setUp() {
foreach (array('default','local','protected') as $config_group) {
if (empty($config_cascade['main'][$config_group])) continue;
foreach ($config_cascade['main'][$config_group] as $config_file) {
if (@file_exists($config_file)) {
if (file_exists($config_file)) {
include($config_file);
}
}
Expand All @@ -68,7 +68,7 @@ public function setUp() {
foreach (array('default','local') as $config_group) {
if (empty($config_cascade['license'][$config_group])) continue;
foreach ($config_cascade['license'][$config_group] as $config_file) {
if(@file_exists($config_file)){
if(file_exists($config_file)){
include($config_file);
}
}
Expand Down
2 changes: 1 addition & 1 deletion feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function rss_buildItems(&$rss, &$data, $opt) {
$date = $ditem['date'];
} elseif ($ditem['media']) {
$date = @filemtime(mediaFN($id));
} elseif (@file_exists(wikiFN($id))) {
} elseif (file_exists(wikiFN($id))) {
$date = @filemtime(wikiFN($id));
} elseif($meta['date']['modified']) {
$date = $meta['date']['modified'];
Expand Down
2 changes: 1 addition & 1 deletion inc/JpegMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ function save($fileName = "") {
if ($fileName == "") {
$tmpName = tempnam(dirname($this->_fileName),'_metatemp_');
$this->_writeJPEG($tmpName);
if (@file_exists($tmpName)) {
if (file_exists($tmpName)) {
return io_rename($tmpName, $this->_fileName);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion inc/Sitemapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function generate(){

$sitemap = Sitemapper::getFilePath();

if(@file_exists($sitemap)){
if(file_exists($sitemap)){
if(!is_writable($sitemap)) return false;
}else{
if(!is_writable(dirname($sitemap))) return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ function act_resendpwd() {
// we're in token phase - get user info from token

$tfile = $conf['cachedir'].'/'.$token{0}.'/'.$token.'.pwauth';
if(!@file_exists($tfile)) {
if(!file_exists($tfile)) {
msg($lang['resendpwdbadauth'], -1);
$INPUT->remove('pwauth');
return false;
Expand Down
2 changes: 1 addition & 1 deletion inc/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function cache_parser($id, $file, $mode) {
*/
public function _useCache() {

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

Expand Down
8 changes: 4 additions & 4 deletions inc/changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function _handleRecent($line,$ns,$flags,&$seen){
// check existance
if($flags & RECENTS_SKIP_DELETED){
$fn = (($flags & RECENTS_MEDIA_CHANGES) ? mediaFN($recent['id']) : wikiFN($recent['id']));
if(!@file_exists($fn)) return false;
if(!file_exists($fn)) return false;
}

return $recent;
Expand Down Expand Up @@ -498,14 +498,14 @@ public function getRevisions($first, $num) {

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

$file = $this->getChangelogFilename();

if(!@file_exists($file)) {
if(!file_exists($file)) {
return $revs;
}
if(filesize($file) < $this->chunk_size || $this->chunk_size == 0) {
Expand Down Expand Up @@ -735,7 +735,7 @@ public function getRevisionsAround($rev1, $rev2, $max = 50) {
protected function readloglines($rev) {
$file = $this->getChangelogFilename();

if(!@file_exists($file)) {
if(!file_exists($file)) {
return false;
}

Expand Down
24 changes: 12 additions & 12 deletions inc/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function pageinfo() {

$info['locked'] = checklock($ID);
$info['filepath'] = fullpath(wikiFN($ID));
$info['exists'] = @file_exists($info['filepath']);
$info['exists'] = file_exists($info['filepath']);
$info['currentrev'] = @filemtime($info['filepath']);
if($REV) {
//check if current revision was meant
Expand All @@ -202,7 +202,7 @@ function pageinfo() {
} else {
//really use old revision
$info['filepath'] = fullpath(wikiFN($ID, $REV));
$info['exists'] = @file_exists($info['filepath']);
$info['exists'] = file_exists($info['filepath']);
}
}
$info['rev'] = $REV;
Expand Down Expand Up @@ -256,7 +256,7 @@ function pageinfo() {

// draft
$draft = getCacheName($info['client'].$ID, '.draft');
if(@file_exists($draft)) {
if(file_exists($draft)) {
if(@filemtime($draft) < @filemtime(wikiFN($ID))) {
// remove stale draft
@unlink($draft);
Expand Down Expand Up @@ -352,7 +352,7 @@ function breadcrumbs() {
$crumbs = isset($_SESSION[DOKU_COOKIE]['bc']) ? $_SESSION[DOKU_COOKIE]['bc'] : array();
//we only save on show and existing wiki documents
$file = wikiFN($ID);
if($ACT != 'show' || !@file_exists($file)) {
if($ACT != 'show' || !file_exists($file)) {
$_SESSION[DOKU_COOKIE]['bc'] = $crumbs;
return $crumbs;
}
Expand Down Expand Up @@ -853,7 +853,7 @@ function checklock($id) {
$lock = wikiLockFN($id);

//no lockfile
if(!@file_exists($lock)) return false;
if(!file_exists($lock)) return false;

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

$lock = wikiLockFN($id);
if(@file_exists($lock)) {
if(file_exists($lock)) {
@list($ip, $session) = explode("\n", io_readFile($lock));
if($ip == $INPUT->server->str('REMOTE_USER') || $ip == clientIP() || $session == session_id()) {
@unlink($lock);
Expand Down Expand Up @@ -1010,13 +1010,13 @@ function pageTemplate($id) {
// if the before event did not set a template file, try to find one
if(empty($data['tplfile'])) {
$path = dirname(wikiFN($id));
if(@file_exists($path.'/_template.txt')) {
if(file_exists($path.'/_template.txt')) {
$data['tplfile'] = $path.'/_template.txt';
} else {
// search upper namespaces for templates
$len = strlen(rtrim($conf['datadir'], '/'));
while(strlen($path) >= $len) {
if(@file_exists($path.'/__template.txt')) {
if(file_exists($path.'/__template.txt')) {
$data['tplfile'] = $path.'/__template.txt';
break;
}
Expand Down Expand Up @@ -1197,13 +1197,13 @@ function saveWikiText($id, $text, $summary, $minor = false) {
$file = wikiFN($id);
$old = @filemtime($file); // from page
$wasRemoved = (trim($text) == ''); // check for empty or whitespace only
$wasCreated = !@file_exists($file);
$wasCreated = !file_exists($file);
$wasReverted = ($REV == true);
$pagelog = new PageChangeLog($id, 1024);
$newRev = false;
$oldRev = $pagelog->getRevisions(-1, 1); // from changelog
$oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]);
if(!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) {
if(!file_exists(wikiFN($id, $old)) && file_exists($file) && $old >= $oldRev) {
// add old revision to the attic if missing
saveOldRevision($id);
// add a changelog entry if this edit came from outside dokuwiki
Expand Down Expand Up @@ -1285,7 +1285,7 @@ function saveWikiText($id, $text, $summary, $minor = false) {
*/
function saveOldRevision($id) {
$oldf = wikiFN($id);
if(!@file_exists($oldf)) return '';
if(!file_exists($oldf)) return '';
$date = filemtime($oldf);
$newf = wikiFN($id, $date);
io_writeWikiPage($newf, rawWiki($id), $id, $date);
Expand Down Expand Up @@ -1743,7 +1743,7 @@ function license_img($type) {
$try[] = 'lib/images/license/'.$type.'/cc.png';
}
foreach($try as $src) {
if(@file_exists(DOKU_INC.$src)) return $src;
if(file_exists(DOKU_INC.$src)) return $src;
}
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion inc/confutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function retrieveConfig($type,$fn,$params=null) {
foreach (array('default','local','protected') as $config_group) {
if (empty($config_cascade[$type][$config_group])) continue;
foreach ($config_cascade[$type][$config_group] as $file) {
if (@file_exists($file)) {
if (file_exists($file)) {
$config = call_user_func_array($fn,array_merge(array($file),$params));
$combined = array_merge($combined, $config);
}
Expand Down
2 changes: 1 addition & 1 deletion inc/fetch.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) {
}

//check file existance
if(!@file_exists($file)) {
if(!file_exists($file)) {
return array(404, 'Not Found');
}

Expand Down
6 changes: 3 additions & 3 deletions inc/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ function html_revisions($first=0, $media_id = false){
$form->addElement(form_makeOpenTag('ul'));

if (!$media_id) $exists = $INFO['exists'];
else $exists = @file_exists(mediaFN($id));
else $exists = file_exists(mediaFN($id));

$display_name = (!$media_id && useHeading('navigation')) ? hsc(p_get_first_heading($id)) : $id;
if (!$display_name) $display_name = $id;
Expand Down Expand Up @@ -568,7 +568,7 @@ function html_revisions($first=0, $media_id = false){
$date = dformat($rev);
$info = $changelog->getRevisionInfo($rev);
if($media_id) {
$exists = @file_exists(mediaFN($id, $rev));
$exists = file_exists(mediaFN($id, $rev));
} else {
$exists = page_exists($id, $rev);
}
Expand Down Expand Up @@ -765,7 +765,7 @@ function html_recent($first=0, $show_changes='both'){
$href = '';

if (!empty($recent['media'])) {
$diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && @file_exists(mediaFN($recent['id'])));
$diff = (count(getRevisions($recent['id'], 0, 1, 8192, true)) && file_exists(mediaFN($recent['id'])));
if ($diff) {
$href = media_managerURL(array('tab_details' => 'history',
'mediado' => 'diff', 'image' => $recent['id'], 'ns' => getNS($recent['id'])), '&');
Expand Down
20 changes: 10 additions & 10 deletions inc/indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ protected function unlock() {
protected function getIndex($idx, $suffix) {
global $conf;
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
if (!@file_exists($fn)) return array();
if (!file_exists($fn)) return array();
return file($fn, FILE_IGNORE_NEW_LINES);
}

Expand Down Expand Up @@ -1118,7 +1118,7 @@ protected function saveIndex($idx, $suffix, &$lines) {
protected function getIndexKey($idx, $suffix, $id) {
global $conf;
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
if (!@file_exists($fn)) return '';
if (!file_exists($fn)) return '';
$fh = @fopen($fn, 'r');
if (!$fh) return '';
$ln = -1;
Expand Down Expand Up @@ -1228,7 +1228,7 @@ protected function indexLengths($filter) {
// testing if index files exist only
$path = $conf['indexdir']."/i";
foreach ($filter as $key => $value) {
if (@file_exists($path.$key.'.idx'))
if (file_exists($path.$key.'.idx'))
$idx[] = $key;
}
} else {
Expand Down Expand Up @@ -1339,7 +1339,7 @@ function & idx_get_stopwords() {
if (is_null($stopwords)) {
global $conf;
$swfile = DOKU_INC.'inc/lang/'.$conf['lang'].'/stopwords.txt';
if(@file_exists($swfile)){
if(file_exists($swfile)){
$stopwords = file($swfile, FILE_IGNORE_NEW_LINES);
}else{
$stopwords = array();
Expand All @@ -1364,7 +1364,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
$idxtag = metaFN($page,'.indexed');
// check if page was deleted but is still in the index
if (!page_exists($page)) {
if (!@file_exists($idxtag)) {
if (!file_exists($idxtag)) {
if ($verbose) print("Indexer: $page does not exist, ignoring".DOKU_LF);
return false;
}
Expand All @@ -1379,7 +1379,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
}

// check if indexing needed
if(!$force && @file_exists($idxtag)){
if(!$force && file_exists($idxtag)){
if(trim(io_readFile($idxtag)) == idx_get_version()){
$last = @filemtime($idxtag);
if($last > @filemtime(wikiFN($page))){
Expand All @@ -1392,7 +1392,7 @@ function idx_addPage($page, $verbose=false, $force=false) {
$indexenabled = p_get_metadata($page, 'internal index', METADATA_RENDER_UNLIMITED);
if ($indexenabled === false) {
$result = false;
if (@file_exists($idxtag)) {
if (file_exists($idxtag)) {
$Indexer = idx_get_indexer();
$result = $Indexer->deletePage($page);
if ($result === "locked") {
Expand Down Expand Up @@ -1494,7 +1494,7 @@ function idx_tokenizer($string, $wc=false) {
function idx_getIndex($idx, $suffix) {
global $conf;
$fn = $conf['indexdir'].'/'.$idx.$suffix.'.idx';
if (!@file_exists($fn)) return array();
if (!file_exists($fn)) return array();
return file($fn);
}

Expand All @@ -1515,7 +1515,7 @@ function idx_listIndexLengths() {
$docache = false;
} else {
clearstatcache();
if (@file_exists($conf['indexdir'].'/lengths.idx')
if (file_exists($conf['indexdir'].'/lengths.idx')
&& (time() < @filemtime($conf['indexdir'].'/lengths.idx') + $conf['readdircache'])) {
if (($lengths = @file($conf['indexdir'].'/lengths.idx', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) !== false) {
$idx = array();
Expand Down Expand Up @@ -1572,7 +1572,7 @@ function idx_indexLengths($filter) {
// testing if index files exist only
$path = $conf['indexdir']."/i";
foreach ($filter as $key => $value) {
if (@file_exists($path.$key.'.idx'))
if (file_exists($path.$key.'.idx'))
$idx[] = $key;
}
} else {
Expand Down
12 changes: 6 additions & 6 deletions inc/infoutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function checkUpdateMessages(){
function getVersionData(){
$version = array();
//import version string
if(@file_exists(DOKU_INC.'VERSION')){
if(file_exists(DOKU_INC.'VERSION')){
//official release
$version['date'] = trim(io_readfile(DOKU_INC.'VERSION'));
$version['type'] = 'Release';
Expand Down Expand Up @@ -141,20 +141,20 @@ function check(){
if(is_writable($conf['changelog'])){
msg('Changelog is writable',1);
}else{
if (@file_exists($conf['changelog'])) {
if (file_exists($conf['changelog'])) {
msg('Changelog is not writable',-1);
}
}

if (isset($conf['changelog_old']) && @file_exists($conf['changelog_old'])) {
if (isset($conf['changelog_old']) && file_exists($conf['changelog_old'])) {
msg('Old changelog exists', 0);
}

if (@file_exists($conf['changelog'].'_failed')) {
if (file_exists($conf['changelog'].'_failed')) {
msg('Importing old changelog failed', -1);
} else if (@file_exists($conf['changelog'].'_importing')) {
} else if (file_exists($conf['changelog'].'_importing')) {
msg('Importing old changelog now.', 0);
} else if (@file_exists($conf['changelog'].'_import_ok')) {
} else if (file_exists($conf['changelog'].'_import_ok')) {
msg('Old changelog imported', 1);
if (!plugin_isdisabled('importoldchangelog')) {
msg('Importoldchangelog plugin not disabled after import', -1);
Expand Down

0 comments on commit 79e7937

Please sign in to comment.