From: Aryeh Gregor Date: Tue, 29 Jul 2008 00:08:25 +0000 (+0000) Subject: Linker.php cleanup: X-Git-Tag: 1.31.0-rc.0~46313 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=422f937e754e8f8fc5932c19e9fe8ed054b9af54;p=lhc%2Fweb%2Fwiklou.git Linker.php cleanup: * Allow makeLinkObj to accept an associative array of arguments for $aprops, so Brion's eyes can be saved from melting. * Fail fast when various methods are passed non-Titles, don't just return some garbage and hope no one notices. * Whitespace, wfDeprecated(). --- diff --git a/includes/Linker.php b/includes/Linker.php index 0661e3701e..eaa56f3f95 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -234,16 +234,10 @@ class Linker { * the end of the link. * @param $prefix String: optional prefix. As trail, only before instead of after. */ - function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) { + function makeLinkObj( Title $nt, $text= '', $query = '', $trail = '', $prefix = '' ) { global $wgUser; wfProfileIn( __METHOD__ ); - if ( !$nt instanceof Title ) { - # Fail gracefully - wfProfileOut( __METHOD__ ); - return "{$prefix}{$text}{$trail}"; - } - if ( $nt->isExternal() ) { $u = $nt->getFullURL(); $link = $nt->getPrefixedURL(); @@ -308,19 +302,16 @@ class Linker { * @param $query String: link target * @param $trail String: text after link * @param $prefix String: text before link text - * @param $aprops String: extra attributes to the a-element + * @param $aprops Mixed: extra attributes to the a-element. If a string, + * inserted literally into the HTML, with a space prepended. It can also + * be an associative array. In this case the keys are attributes, and + * values are *unescaped* attribute values. * @param $style String: style to apply - if empty, use getInternalLinkAttributesObj instead * @return the a-element */ - function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) { + function makeKnownLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) { wfProfileIn( __METHOD__ ); - if ( !$title instanceof Title ) { - # Fail gracefully - wfProfileOut( __METHOD__ ); - return "{$prefix}{$text}{$trail}"; - } - $nt = $this->normaliseSpecialPage( $title ); $u = $nt->escapeLocalURL( $query ); @@ -340,7 +331,16 @@ class Linker { $style = $this->getInternalLinkAttributesObj( $nt, $text ); } - if ( $aprops !== '' ) $aprops = ' ' . $aprops; + if( is_string( $aprops ) && $aprops != '' ) { + $aprops = " $aprops"; + } elseif( is_array( $aprops ) ) { + $attributes = $aprops; + $aprops = ''; + foreach( $attributes as $key => $value ) { + $value = htmlspecialchars( $value ); + $aprops .= " $key=\"$value\""; + } + } list( $inside, $trail ) = Linker::splitTrail( $trail ); $r = "{$prefix}{$text}{$inside}{$trail}"; @@ -358,15 +358,9 @@ class Linker { * be included in the link text. Other characters will be appended after * the end of the link. */ - function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) { + function makeBrokenLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' ) { wfProfileIn( __METHOD__ ); - if ( !$title instanceof Title ) { - # Fail gracefully - wfProfileOut( __METHOD__ ); - return "{$prefix}{$text}{$trail}"; - } - $nt = $this->normaliseSpecialPage( $title ); if( $nt->getNamespace() == NS_SPECIAL ) { @@ -406,6 +400,7 @@ class Linker { * the end of the link. */ function makeStubLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { + wfDeprecated( __METHOD__ ); return $this->makeColouredLinkObj( $nt, 'stub', $text, $query, $trail, $prefix ); } @@ -421,7 +416,6 @@ class Linker { * the end of the link. */ function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) { - if($colour != ''){ $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour ); } else $style = ''; @@ -1304,21 +1298,22 @@ class Linker { * @return string HTML to use for edit link */ public function doEditSectionLink( Title $nt, $section, $tooltip='' ) { - $attribs = ''; - if( $tooltip ) { - $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) ); - $attribs = " title=\"$attribs\""; - } - $url = $this->makeKnownLinkObj( $nt, htmlspecialchars(wfMsg('editsection')), "action=edit§ion=$section", - '', '', '', $attribs + '', '', '', + array( 'title' => wfMsg( 'editsectionhint', $tooltip ) ) ); - # Run the old hook + # Run the old hook. This takes up most of the function . . . hopefully + # we can rid of it someday. $result = null; + $attribs = ''; + if( $tooltip ) { + $attribs = wfMsgHtml( 'editsectionhint', htmlspecialchars( $tooltip ) ); + $attribs = " title=\"$attribs\""; + } wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $url, &$result ) ); if( !is_null( $result ) ) { # For reverse compatibility, add the brackets *after* the hook is