r25992 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25991‎ | r25992 | r25993 >
Date:14:32, 21 September 2007
Author:nikerabbit
Status:old
Tags:
Comment:
* Some cleanups that have been hanging here too long
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Linker.php
@@ -99,16 +99,16 @@
100100 * the end of the link.
101101 */
102102 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
103 - wfProfileIn( 'Linker::makeLink' );
 103+ wfProfileIn( __METHOD__ );
104104 $nt = Title::newFromText( $title );
105 - if ($nt) {
 105+ if ( $nt instanceof Title ) {
106106 $result = $this->makeLinkObj( $nt, $text, $query, $trail );
107107 } else {
108108 wfDebug( 'Invalid title passed to Linker::makeLink(): "'.$title."\"\n" );
109109 $result = $text == "" ? $title : $text;
110110 }
111111
112 - wfProfileOut( 'Linker::makeLink' );
 112+ wfProfileOut( __METHOD__ );
113113 return $result;
114114 }
115115
@@ -125,8 +125,8 @@
126126 */
127127 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
128128 $nt = Title::newFromText( $title );
129 - if ($nt) {
130 - return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
 129+ if ( $nt instanceof Title ) {
 130+ return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix , $aprops );
131131 } else {
132132 wfDebug( 'Invalid title passed to Linker::makeKnownLink(): "'.$title."\"\n" );
133133 return $text == '' ? $title : $text;
@@ -146,8 +146,8 @@
147147 */
148148 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
149149 $nt = Title::newFromText( $title );
150 - if ($nt) {
151 - return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
 150+ if ( $nt instanceof Title ) {
 151+ return $this->makeBrokenLinkObj( $nt, $text, $query, $trail );
152152 } else {
153153 wfDebug( 'Invalid title passed to Linker::makeBrokenLink(): "'.$title."\"\n" );
154154 return $text == '' ? $title : $text;
@@ -167,8 +167,8 @@
168168 */
169169 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
170170 $nt = Title::newFromText( $title );
171 - if ($nt) {
172 - return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
 171+ if ( $nt instanceof Title ) {
 172+ return $this->makeStubLinkObj( $nt, $text, $query, $trail );
173173 } else {
174174 wfDebug( 'Invalid title passed to Linker::makeStubLink(): "'.$title."\"\n" );
175175 return $text == '' ? $title : $text;
@@ -191,13 +191,11 @@
192192 */
193193 function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
194194 global $wgUser;
195 - $fname = 'Linker::makeLinkObj';
196 - wfProfileIn( $fname );
 195+ wfProfileIn( __METHOD__ );
197196
198 - # Fail gracefully
199 - if ( ! is_object($nt) ) {
200 - # throw new MWException();
201 - wfProfileOut( $fname );
 197+ if ( !$nt instanceof Title ) {
 198+ # Fail gracefully
 199+ wfProfileOut( __METHOD__ );
202200 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
203201 }
204202
@@ -217,13 +215,13 @@
218216 }
219217 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
220218
221 - wfProfileOut( $fname );
 219+ wfProfileOut( __METHOD__ );
222220 return $t;
223221 } elseif ( $nt->isAlwaysKnown() ) {
224222 # Image links, special page links and self-links with fragements are always known.
225223 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
226224 } else {
227 - wfProfileIn( $fname.'-immediate' );
 225+ wfProfileIn( __METHOD__.'-immediate' );
228226
229227 # Handles links to special pages wich do not exist in the database:
230228 if( $nt->getNamespace() == NS_SPECIAL ) {
@@ -232,8 +230,8 @@
233231 } else {
234232 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
235233 }
236 - wfProfileOut( $fname.'-immediate' );
237 - wfProfileOut( $fname );
 234+ wfProfileOut( __METHOD__.'-immediate' );
 235+ wfProfileOut( __METHOD__ );
238236 return $retVal;
239237 }
240238
@@ -251,7 +249,7 @@
252250 array( 'page' ),
253251 array( 'page_len',
254252 'page_is_redirect' ),
255 - array( 'page_id' => $aid ), $fname ) ;
 253+ array( 'page_id' => $aid ), __METHOD__ ) ;
256254 $stub = ( $s !== false && !$s->page_is_redirect &&
257255 $s->page_len < $threshold );
258256 }
@@ -262,9 +260,9 @@
263261 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
264262 }
265263 }
266 - wfProfileOut( $fname.'-immediate' );
 264+ wfProfileOut( __METHOD__.'-immediate' );
267265 }
268 - wfProfileOut( $fname );
 266+ wfProfileOut( __METHOD__ );
269267 return $retVal;
270268 }
271269
@@ -283,13 +281,12 @@
284282 * @return the a-element
285283 */
286284 function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
 285+ wfProfileIn( __METHOD__ );
287286
288 - $fname = 'Linker::makeKnownLinkObj';
289 - wfProfileIn( $fname );
290 -
291 - if ( !is_object( $nt ) ) {
292 - wfProfileOut( $fname );
293 - return $text;
 287+ if ( !$nt instanceof Title ) {
 288+ # Fail gracefully
 289+ wfProfileOut( __METHOD__ );
 290+ return "<!-- ERROR -->{$prefix}{$text}{$trail}";
294291 }
295292
296293 $u = $nt->escapeLocalURL( $query );
@@ -313,7 +310,7 @@
314311
315312 list( $inside, $trail ) = Linker::splitTrail( $trail );
316313 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
317 - wfProfileOut( $fname );
 314+ wfProfileOut( __METHOD__ );
318315 return $r;
319316 }
320317
@@ -328,15 +325,14 @@
329326 * the end of the link.
330327 */
331328 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
332 - # Fail gracefully
333 - if ( ! isset($nt) ) {
334 - # throw new MWException();
 329+ wfProfileIn( __METHOD__ );
 330+
 331+ if ( !$nt instanceof Title ) {
 332+ # Fail gracefully
 333+ wfProfileOut( __METHOD__ );
335334 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
336335 }
337336
338 - $fname = 'Linker::makeBrokenLinkObj';
339 - wfProfileIn( $fname );
340 -
341337 if( $nt->getNamespace() == NS_SPECIAL ) {
342338 $q = $query;
343339 } else if ( '' == $query ) {
@@ -354,7 +350,7 @@
355351 list( $inside, $trail ) = Linker::splitTrail( $trail );
356352 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
357353
358 - wfProfileOut( $fname );
 354+ wfProfileOut( __METHOD__ );
359355 return $s;
360356 }
361357
@@ -1103,7 +1099,7 @@
11041100 /** @todo document */
11051101 function tocList($toc) {
11061102 global $wgJsMimeType;
1107 - $title = wfMsgHtml('toc') ;
 1103+ $title = wfMsgHtml('toc') ;
11081104 return
11091105 '<table id="toc" class="toc" summary="' . $title .'"><tr><td>'
11101106 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"

Follow-up revisions

RevisionCommit summaryAuthorDate
r26015Merged revisions 25932-26011 via svnmerge from...david21:05, 21 September 2007

Status & tagging log