r59359 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59358‎ | r59359 | r59360 >
Date:18:32, 23 November 2009
Author:btongminh
Status:ok
Tags:
Comment:
* Only show the TOC link if there are actual results
* Replace all raw <a constructions with Linker
Modified paths:
  • /trunk/extensions/GlobalUsage/SpecialGlobalUsage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php
@@ -127,13 +127,33 @@
128128 str_replace( '_', ' ', $page ) );
129129 }
130130
 131+
 132+ /**
 133+ * Get an executed query for use on image pages
 134+ *
 135+ * @param Title $title File to query for
 136+ * @return GlobalUsageQuery Query object, already executed
 137+ */
 138+ private static function getImagePageQuery( $title ) {
 139+ static $queryCache = array();
 140+
 141+ $name = $title->getDBkey();
 142+ if ( !isset( $queryCache[$name] ) ) {
 143+ $query = new GlobalUsageQuery( $title );
 144+ $query->filterLocal();
 145+ $query->execute();
 146+
 147+ $queryCache[$name] = $query;
 148+ }
 149+
 150+ return $queryCache[$name];
 151+ }
 152+
131153 public static function onImagePageAfterImageLinks( $imagePage, &$html ) {
132154 $title = $imagePage->getFile()->getTitle();
133155 $targetName = $title->getText();
134156
135 - $query = new GlobalUsageQuery( $title );
136 - $query->filterLocal();
137 - $query->execute();
 157+ $query = self::getImagePageQuery( $title );
138158
139159 $guHtml = '';
140160 foreach ( $query->getSingleImageResult() as $wiki => $result ) {
@@ -157,14 +177,21 @@
158178 return true;
159179 }
160180
 181+ /**
 182+ * Show a link to the global image links in the TOC if there are any results available.
 183+ */
161184 public static function onImagePageShowTOC( $imagePage, &$toc ) {
162 - $toc[] = '<li><a href="#globalusage">' . wfMsgHtml( 'globalusage' ) . '</a></li>';
 185+ $query = self::getImagePageQuery( $imagePage->getFile()->getTitle() );
 186+ if ( $query->getResult() )
 187+ $toc[] = '<li><a href="#globalusage">' . wfMsgHtml( 'globalusage' ) . '</a></li>';
163188 return true;
164189 }
165190
166191 protected function getNavBar( $query ) {
167 - global $wgLang;
 192+ global $wgLang, $wgUser;
168193
 194+ $skin = $wgUser->getSkin();
 195+
169196 $target = $this->target->getPrefixedText();
170197 $limit = $query->getLimit();
171198 $fmtLimit = $wgLang->formatNum( $limit );
@@ -184,16 +211,18 @@
185212
186213 # Make 'previous' link
187214 if ( $offset ) {
 215+ $attr = array( 'title' => $pTitle, 'class' => 'mw-prevlink' );
188216 $q = array( 'limit' => $limit, 'offset' => $offset, 'target' => $target );
189 - $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
 217+ $plink = $skin->link( $title, $prev, $attr, $q );
190218 } else {
191219 $plink = $prev;
192220 }
193221
194222 # Make 'next' link
195223 if ( $query->hasMore() ) {
 224+ $attr = array( 'title' => $nTitle, 'class' => 'mw-nextlink' );
196225 $q = array( 'limit' => $limit, 'offset' => $query->getContinueString(), 'target' => $target );
197 - $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
 226+ $nlink = $skin->link( $title, $next, $attr, $q );
198227 } else {
199228 $nlink = $next;
200229 }
@@ -202,9 +231,12 @@
203232 $numLinks = array();
204233 foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
205234 $fmtLimit = $wgLang->formatNum( $num );
 235+
206236 $q = array( 'offset' => $offset, 'limit' => $num, 'target' => $target );
207 - $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num );
208 - $numLinks[] = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$lTitle}\" class=\"mw-numlink\">{$fmtLimit}</a>";
 237+ $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $num );
 238+ $attr = array( 'title' => $lTitle, 'class' => 'mw-numlink' );
 239+
 240+ $numLinks[] = $skin->link( $title, $fmtLimit, $attr, $q );
209241 }
210242 $nums = $wgLang->pipeList( $numLinks );
211243

Status & tagging log