r72915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72914‎ | r72915 | r72916 >
Date:16:56, 13 September 2010
Author:btongminh
Status:deferred (Comments)
Tags:
Comment:
Revert r71067. Most users think that the links are actually useful, see http://commons.wikimedia.org/wiki/Commons:Village_pump/Archive/2010Aug#Global_usage_links_useful.3F

It would perhaps be useful though to allow collapsing of the list via some JavaScript magic.
Modified paths:
  • /trunk/extensions/GlobalUsage/GlobalUsage.i18n.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageImagePageHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageImagePageHooks.php
@@ -1,23 +1,110 @@
22 <?php
33
44 class GlobalUsageImagePageHooks {
 5+ private static $queryCache = array();
56
67 /**
7 - * Show a global usage link on the image page
 8+ * Get an executed query for use on image pages
 9+ *
 10+ * @param Title $title File to query for
 11+ * @return GlobalUsageQuery Query object, already executed
 12+ */
 13+ private static function getImagePageQuery( $title ) {
 14+ $name = $title->getDBkey();
 15+ if ( !isset( self::$queryCache[$name] ) ) {
 16+ $query = new GlobalUsageQuery( $title );
 17+ $query->filterLocal();
 18+ $query->execute();
 19+
 20+ self::$queryCache[$name] = $query;
 21+
 22+ // Limit cache size to 100
 23+ if ( count( self::$queryCache ) > 100 )
 24+ array_shift( self::$queryCache );
 25+ }
 26+
 27+ return self::$queryCache[$name];
 28+ }
 29+
 30+ /**
 31+ * Show a global usage section on the image page
832 *
933 * @param object $imagePage The ImagePage
10 - * @param string $html HTML to add to the image page as the link in image links section
 34+ * @param string $html HTML to add to the image page as global usage section
1135 * @return bool
1236 */
1337 public static function onImagePageAfterImageLinks( $imagePage, &$html ) {
 38+ if ( !self::hasResults( $imagePage ) )
 39+ return true;
 40+
 41+ $title = $imagePage->getFile()->getTitle();
 42+ $targetName = $title->getText();
 43+
 44+ $query = self::getImagePageQuery( $title );
 45+
 46+ $guHtml = '';
 47+ foreach ( $query->getSingleImageResult() as $wiki => $result ) {
 48+ $wikiName = WikiMap::getWikiName( $wiki );
 49+ $escWikiName = Sanitizer::escapeClass( $wikiName );
 50+ $guHtml .= "<li class='mw-gu-onwiki-$escWikiName'>" . wfMsgExt(
 51+ 'globalusage-on-wiki', 'parseinline',
 52+ $targetName, $wikiName ) . "\n<ul>";
 53+ foreach ( $result as $item )
 54+ $guHtml .= "\t<li>" . SpecialGlobalUsage::formatItem( $item ) . "</li>\n";
 55+ $guHtml .= "</ul></li>\n";
 56+ }
 57+
 58+ if ( $guHtml ) {
 59+ $html .= '<h2 id="globalusage">' . wfMsgHtml( 'globalusage' ) . "</h2>\n"
 60+ . '<div id="mw-imagepage-section-globalusage">'
 61+ . wfMsgExt( 'globalusage-of-file', 'parse' )
 62+ . "<ul>\n" . $guHtml . "</ul>\n";
 63+ if ( $query->hasMore() )
 64+ $html .= wfMsgExt( 'globalusage-more', 'parse', $targetName );
 65+ $html .= '</div>';
 66+ }
 67+
 68+ return true;
 69+ }
 70+
 71+ /**
 72+ * Show a link to the global image links in the TOC if there are any results available.
 73+ */
 74+ public static function onImagePageShowTOC( $imagePage, &$toc ) {
 75+ if ( self::hasResults( $imagePage ) ) {
 76+ # Insert a link after the 3rd entry in the TOC
 77+ array_splice( $toc, 3, 0, '<li><a href="#globalusage">'
 78+ . wfMsgHtml( 'globalusage' ) . '</a></li>');
 79+ }
 80+ return true;
 81+ }
 82+
 83+ /**
 84+ * Check whether there are results for an image page. Checks whether the
 85+ * file exists and is not local.
 86+ *
 87+ * @param $imagePage ImagePage
 88+ * @return bool
 89+ */
 90+ protected static function hasResults( $imagePage ) {
 91+ # Don't display links if the target file does not exist
 92+ $file = $imagePage->getFile();
 93+ if ( !$file->exists() ) {
 94+ return false;
 95+ }
1496
15 - $targetName = $imagePage->getFile()->getTitle()->getText();
 97+ # Don't show global usage if the file is local.
 98+ # Do show it however if the current repo is the shared repo. The way
 99+ # we detect this is a bit hacky and less than ideal. See bug 23136 for
 100+ # a discussion.
 101+ global $wgGlobalUsageDatabase;
 102+ $dbr = wfGetDB( DB_SLAVE );
 103+ if ( $file->getRepoName() == 'local'
 104+ && $dbr->getDBname() != $wgGlobalUsageDatabase ) {
 105+ return false;
 106+ }
16107
17 - $html .= '<p id="mw-imagepage-section-globalusage">';
18 - $html .= wfMsgExt( 'globalusage-more', 'parse', $targetName );
19 - $html .= '</p>';
20 -
21 - return true;
 108+ $query = self::getImagePageQuery( $imagePage->getFile()->getTitle() );
 109+ return (bool)$query->getResult();
22110 }
23 -
24 -}
 111+}
\ No newline at end of file
Index: trunk/extensions/GlobalUsage/GlobalUsage.i18n.php
@@ -20,7 +20,7 @@
2121 'globalusage-no-results' => '[[:$1]] is not used on other wikis.',
2222 'globalusage-on-wiki' => 'Usage on $2',
2323 'globalusage-of-file' => 'The following other wikis use this file:',
24 - 'globalusage-more' => 'View [[{{#Special:GlobalUsage}}/$1|global usage]] of this file.',
 24+ 'globalusage-more' => 'View [[{{#Special:GlobalUsage}}/$1|more global usage]] of this file.',
2525 'globalusage-filterlocal' => 'Do not show local usage',
2626 );
2727

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r71067* Do not clutter and unnecessarily prolong the file description page with sho...danny_b13:02, 14 August 2010

Comments

#Comment by Danny B. (talk | contribs)   09:41, 14 September 2010

If it's useful on Commons, it should work only on Commons, not annoy on other projects.

Javascript magic is worth nothing, because presence of the list still unnecessary prolongs the page and its loading, additional script would create another load.

There should be preference for user, if he wants to display the list or the link. Forcing of the list to those, who don't care about it at all, is annoying, not speaking about it lowers down the usability and accessibility of the page.

#Comment by The Evil IP address (talk | contribs)   18:57, 15 September 2010

"not speaking about it lowers down the usability and accessibility of the page."

It's at the bottom of the page, where most people don't notice this anyway.

#Comment by Danny B. (talk | contribs)   22:49, 16 September 2010

Just few examples:

  • Everybody notices it because the page loads slower because of it. Not everybody uses cheap broadband.
  • Everybody, who is interested in metadata, notices it, because must roll it away to get to the metadata.
  • It gives hard times to visual impaired people using assistive technology.
  • And others.

By default, there should be the link to the special page (why do we have it then, when we show the list on the file page anyway?) which serves well to everybody (provides access to the list) and whoever needs that list directly (just wondering why...), should enable it via preferences (Show list instead of link) or gadget (eg. AJAX loading of the list). The current way is wothless and annoying cluttering of the file page with secondary data, which are not primarily relevant to the file, such as File info or metadata are.

#Comment by Aaron Schulz (talk | contribs)   22:51, 16 September 2010

No more preferences :)

#Comment by Danny B. (talk | contribs)   22:55, 16 September 2010

Dogma.

No more new features then. :-P

#Comment by 😂 (talk | contribs)   22:57, 16 September 2010

I could support that!

#Comment by The Evil IP address (talk | contribs)   13:24, 18 September 2010

> Everybody notices it because the page loads slower because of it. Not everybody uses cheap broadband.

There's other stuff on Commons that takes most of the load. This is only a very small part.

> Everybody, who is interested in metadata, notices it, because must roll it away to get to the metadata.

The section usually isn't that big.

> It gives hard times to visual impaired people using assistive technology.

Media repositories like Commons are hardly usable for visually impaired people anyway since they're all about images.

Status & tagging log