From: Niklas Laxström Date: Fri, 21 Sep 2007 14:32:26 +0000 (+0000) Subject: * Some cleanups that have been hanging here too long X-Git-Tag: 1.31.0-rc.0~51341 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=d8a096b97b59a8161e5cfe96a851d50b7d1ef556;p=lhc%2Fweb%2Fwiklou.git * Some cleanups that have been hanging here too long --- diff --git a/includes/Linker.php b/includes/Linker.php index 9397b80055..1d187b8ca9 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -99,16 +99,16 @@ class Linker { * the end of the link. */ function makeLink( $title, $text = '', $query = '', $trail = '' ) { - wfProfileIn( 'Linker::makeLink' ); + wfProfileIn( __METHOD__ ); $nt = Title::newFromText( $title ); - if ($nt) { + if ( $nt instanceof Title ) { $result = $this->makeLinkObj( $nt, $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" ); $result = $text == "" ? $title : $text; } - wfProfileOut( 'Linker::makeLink' ); + wfProfileOut( __METHOD__ ); return $result; } @@ -125,8 +125,8 @@ class Linker { */ function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') { $nt = Title::newFromText( $title ); - if ($nt) { - return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops ); + if ( $nt instanceof Title ) { + return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops ); } else { wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; @@ -146,8 +146,8 @@ class Linker { */ function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) { $nt = Title::newFromText( $title ); - if ($nt) { - return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail ); + if ( $nt instanceof Title ) { + return $this->makeBrokenLinkObj( $nt, $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; @@ -167,8 +167,8 @@ class Linker { */ function makeStubLink( $title, $text = '', $query = '', $trail = '' ) { $nt = Title::newFromText( $title ); - if ($nt) { - return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail ); + if ( $nt instanceof Title ) { + return $this->makeStubLinkObj( $nt, $text, $query, $trail ); } else { wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" ); return $text == '' ? $title : $text; @@ -191,13 +191,11 @@ class Linker { */ function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) { global $wgUser; - $fname = 'Linker::makeLinkObj'; - wfProfileIn( $fname ); + wfProfileIn( __METHOD__ ); - # Fail gracefully - if ( ! is_object($nt) ) { - # throw new MWException(); - wfProfileOut( $fname ); + if ( !$nt instanceof Title ) { + # Fail gracefully + wfProfileOut( __METHOD__ ); return "{$prefix}{$text}{$trail}"; } @@ -217,13 +215,13 @@ class Linker { } $t = "{$text}{$inside}"; - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $t; } elseif ( $nt->isAlwaysKnown() ) { # Image links, special page links and self-links with fragements are always known. $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } else { - wfProfileIn( $fname.'-immediate' ); + wfProfileIn( __METHOD__.'-immediate' ); # Handles links to special pages wich do not exist in the database: if( $nt->getNamespace() == NS_SPECIAL ) { @@ -232,8 +230,8 @@ class Linker { } else { $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix ); } - wfProfileOut( $fname.'-immediate' ); - wfProfileOut( $fname ); + wfProfileOut( __METHOD__.'-immediate' ); + wfProfileOut( __METHOD__ ); return $retVal; } @@ -251,7 +249,7 @@ class Linker { array( 'page' ), array( 'page_len', 'page_is_redirect' ), - array( 'page_id' => $aid ), $fname ) ; + array( 'page_id' => $aid ), __METHOD__ ) ; $stub = ( $s !== false && !$s->page_is_redirect && $s->page_len < $threshold ); } @@ -262,9 +260,9 @@ class Linker { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); } } - wfProfileOut( $fname.'-immediate' ); + wfProfileOut( __METHOD__.'-immediate' ); } - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $retVal; } @@ -283,13 +281,12 @@ class Linker { * @return the a-element */ function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) { + wfProfileIn( __METHOD__ ); - $fname = 'Linker::makeKnownLinkObj'; - wfProfileIn( $fname ); - - if ( !is_object( $nt ) ) { - wfProfileOut( $fname ); - return $text; + if ( !$nt instanceof Title ) { + # Fail gracefully + wfProfileOut( __METHOD__ ); + return "{$prefix}{$text}{$trail}"; } $u = $nt->escapeLocalURL( $query ); @@ -313,7 +310,7 @@ class Linker { list( $inside, $trail ) = Linker::splitTrail( $trail ); $r = "{$prefix}{$text}{$inside}{$trail}"; - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $r; } @@ -328,15 +325,14 @@ class Linker { * the end of the link. */ function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { - # Fail gracefully - if ( ! isset($nt) ) { - # throw new MWException(); + wfProfileIn( __METHOD__ ); + + if ( !$nt instanceof Title ) { + # Fail gracefully + wfProfileOut( __METHOD__ ); return "{$prefix}{$text}{$trail}"; } - $fname = 'Linker::makeBrokenLinkObj'; - wfProfileIn( $fname ); - if( $nt->getNamespace() == NS_SPECIAL ) { $q = $query; } else if ( '' == $query ) { @@ -354,7 +350,7 @@ class Linker { list( $inside, $trail ) = Linker::splitTrail( $trail ); $s = "{$prefix}{$text}{$inside}{$trail}"; - wfProfileOut( $fname ); + wfProfileOut( __METHOD__ ); return $s; } @@ -1103,7 +1099,7 @@ class Linker { /** @todo document */ function tocList($toc) { global $wgJsMimeType; - $title = wfMsgHtml('toc') ; + $title = wfMsgHtml('toc') ; return '
' . '

' . $title . "

\n"