From 015184c6f8970951f5032fb250927ac8fdd0c4fc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Sat, 19 Apr 2008 14:36:04 +0000 Subject: [PATCH] * Split output formatting away from the mile long function --- includes/SpecialWhatlinkshere.php | 104 ++++++++++++++++++------------ 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index 53b9b7aa2b..e3bb530b84 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -82,7 +82,6 @@ class WhatLinksHerePage { */ function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) { global $wgOut, $wgMaxRedirectLinksRetrieved; - $fname = 'WhatLinksHerePage::showIndirectLinks'; $dbr = wfGetDB( DB_SLAVE ); $options = array(); @@ -131,13 +130,13 @@ class WhatLinksHerePage { if( $this->fetchlinks ) { $options['ORDER BY'] = 'pl_from'; $plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields, - $plConds, $fname, $options ); + $plConds, __METHOD__, $options ); } if( !$this->hidetrans ) { $options['ORDER BY'] = 'tl_from'; $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields, - $tlConds, $fname, $options ); + $tlConds, __METHOD__, $options ); } if( ( !$this->fetchlinks || !$dbr->numRows( $plRes ) ) && ( $this->hidetrans || !$dbr->numRows( $tlRes ) ) ) { @@ -219,59 +218,80 @@ class WhatLinksHerePage { $wgOut->addHTML( $prevnext ); } - $wgOut->addHTML( '\n" ); + + $wgOut->addHTML( $this->listEnd() ); if( $level == 0 ) { $wgOut->addHTML( $prevnext ); } } + protected function listStart() { + return Xml::openElement( 'ul' ); + } + + protected function listItem( $row, $nt ) { + # local message cache + static $msgcache = null; + if ( $msgcache === null ) { + static $msgs = array( 'isredirect', 'istemplate', 'semicolon-separator', + 'whatlinkshere-links' ); + $msgcache = array(); + foreach ( $msgs as $msg ) { + $msgcache[$msg] = wfMsgHtml( $msg ); + } + } + + $suppressRedirect = $row->page_is_redirect ? 'redirect=no' : ''; + $link = $this->skin->makeKnownLinkObj( $nt, '', $suppressRedirect ); + + // Display properties (redirect or template) + $propsText = ''; + $props = array(); + if ( $row->page_is_redirect ) + $props[] = $msgcache['isredirect']; + if ( $row->is_template ) + $props[] = $msgcache['istemplate']; + + if ( count( $props ) ) { + $propsText = '(' . implode( $msgcache['semicolon-separator'], $props ) . ')'; + } + + # Space for utilities links, with a what-links-here link provided + $wlhLink = $this->wlhLink( $nt, $msgcache['whatlinkshere-links'] ); + $wlh = Xml::wrapClass( "($wlhLink)", 'mw-whatlinkshere-tools' ); + + return Xml::tags( 'li', null, "$link $propsText $wlh" ) . "\n"; + } + + protected function listEnd() { + return Xml::closeElement( 'ul' ); + } + + protected function wlhLink( Title $target, $text ) { + static $title = null; + if ( $title === null ) + $title = SpecialPage::getTitleFor( 'Whatlinkshere' ); + + $targetText = $target->getPrefixedUrl(); + return $this->skin->makeKnownLinkObj( $title, $text, 'target=' . $targetText ); + } + function makeSelfLink( $text, $query ) { return $this->skin->makeKnownLinkObj( $this->selfTitle, $text, $query ); } @@ -279,8 +299,8 @@ class WhatLinksHerePage { /** Get a query string to append to hide appropriate entries */ function getHideParams() { return ($this->hidetrans ? '&hidetrans=1' : '') - . ($this->hidelinks ? '&hidelinks=1' : '') - . ($this->hideredirs ? '&hideredirs=1' : ''); + . ($this->hidelinks ? '&hidelinks=1' : '') + . ($this->hideredirs ? '&hideredirs=1' : ''); } function getPrevNext( $limit, $prevId, $nextId ) { -- 2.20.1