Index: trunk/extensions/GlobalUsage/SpecialGlobalUsage.php |
— | — | @@ -127,13 +127,33 @@ |
128 | 128 | str_replace( '_', ' ', $page ) ); |
129 | 129 | } |
130 | 130 | |
| 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 | + |
131 | 153 | public static function onImagePageAfterImageLinks( $imagePage, &$html ) { |
132 | 154 | $title = $imagePage->getFile()->getTitle(); |
133 | 155 | $targetName = $title->getText(); |
134 | 156 | |
135 | | - $query = new GlobalUsageQuery( $title ); |
136 | | - $query->filterLocal(); |
137 | | - $query->execute(); |
| 157 | + $query = self::getImagePageQuery( $title ); |
138 | 158 | |
139 | 159 | $guHtml = ''; |
140 | 160 | foreach ( $query->getSingleImageResult() as $wiki => $result ) { |
— | — | @@ -157,14 +177,21 @@ |
158 | 178 | return true; |
159 | 179 | } |
160 | 180 | |
| 181 | + /** |
| 182 | + * Show a link to the global image links in the TOC if there are any results available. |
| 183 | + */ |
161 | 184 | 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>'; |
163 | 188 | return true; |
164 | 189 | } |
165 | 190 | |
166 | 191 | protected function getNavBar( $query ) { |
167 | | - global $wgLang; |
| 192 | + global $wgLang, $wgUser; |
168 | 193 | |
| 194 | + $skin = $wgUser->getSkin(); |
| 195 | + |
169 | 196 | $target = $this->target->getPrefixedText(); |
170 | 197 | $limit = $query->getLimit(); |
171 | 198 | $fmtLimit = $wgLang->formatNum( $limit ); |
— | — | @@ -184,16 +211,18 @@ |
185 | 212 | |
186 | 213 | # Make 'previous' link |
187 | 214 | if ( $offset ) { |
| 215 | + $attr = array( 'title' => $pTitle, 'class' => 'mw-prevlink' ); |
188 | 216 | $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 ); |
190 | 218 | } else { |
191 | 219 | $plink = $prev; |
192 | 220 | } |
193 | 221 | |
194 | 222 | # Make 'next' link |
195 | 223 | if ( $query->hasMore() ) { |
| 224 | + $attr = array( 'title' => $nTitle, 'class' => 'mw-nextlink' ); |
196 | 225 | $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 ); |
198 | 227 | } else { |
199 | 228 | $nlink = $next; |
200 | 229 | } |
— | — | @@ -202,9 +231,12 @@ |
203 | 232 | $numLinks = array(); |
204 | 233 | foreach ( array( 20, 50, 100, 250, 500 ) as $num ) { |
205 | 234 | $fmtLimit = $wgLang->formatNum( $num ); |
| 235 | + |
206 | 236 | $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 ); |
209 | 241 | } |
210 | 242 | $nums = $wgLang->pipeList( $numLinks ); |
211 | 243 | |