jenkins-bot has submitted this change and it was merged.
Change subject: Add Special:MostGloballyLinkedFiles (global version
Special:Mostimages)
......................................................................
Add Special:MostGloballyLinkedFiles (global version Special:Mostimages)
I was surprised to find out this didn't already exist
Change-Id: I3850da0bb12e2de45dc7b0db332f9169a00f1b8e
---
M GlobalUsage.alias.php
M GlobalUsage.php
M GlobalUsageHooks.php
M GlobalUsage_body.php
A SpecialMostGloballyLinkedFiles.php
M i18n/en.json
M i18n/qqq.json
7 files changed, 175 insertions(+), 4 deletions(-)
Approvals:
Gilles: Looks good to me, but someone else must approve
Reedy: Looks good to me, approved
Siebrand: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/GlobalUsage.alias.php b/GlobalUsage.alias.php
index d0644b7..d87412b 100644
--- a/GlobalUsage.alias.php
+++ b/GlobalUsage.alias.php
@@ -12,6 +12,7 @@
/** English (English) */
$specialPageAliases['en'] = array(
'GlobalUsage' => array( 'GlobalUsage' ),
+ 'MostGloballyLinkedFiles' => array( 'MostGloballyLinkedFiles' ),
);
/** Arabic (العربية) */
@@ -332,4 +333,4 @@
/** Traditional Chinese (中文(繁體)) */
$specialPageAliases['zh-hant'] = array(
'GlobalUsage' => array( '全域使用狀況' ),
-);
\ No newline at end of file
+);
diff --git a/GlobalUsage.php b/GlobalUsage.php
index 46fb400..e278289 100644
--- a/GlobalUsage.php
+++ b/GlobalUsage.php
@@ -56,7 +56,9 @@
$wgAutoloadClasses['GlobalUsageQuery'] = $dir . 'GlobalUsageQuery.php';
$wgAutoloadClasses['ApiQueryGlobalUsage'] = $dir . 'ApiQueryGlobalUsage.php';
$wgAutoloadClasses['GlobalUsageCachePurgeJob'] = $dir .
'GlobalUsageCachePurgeJob.php';
+$wgAutoloadClasses['MostGloballyLinkedFilesPage'] = $dir .
'SpecialMostGloballyLinkedFiles.php';
+$wgSpecialPages['MostGloballyLinkedFiles'] = 'MostGloballyLinkedFilesPage';
$wgSpecialPages['GlobalUsage'] = 'SpecialGlobalUsage';
$wgSpecialPageGroups['GlobalUsage'] = 'media';
@@ -82,6 +84,7 @@
/* Other hooks */
$wgHooks['ParserTestTables'][] = 'GlobalUsageHooks::onParserTestTables';
$wgHooks['LoadExtensionSchemaUpdates'][] =
'GlobalUsageHooks::onLoadExtensionSchemaUpdates';
+$wgHooks['wgQueryPages'][] = 'GlobalUsageHooks::onwgQueryPages';
// If set to false, the local database contains the globalimagelinks table
// Else set to something understandable to LBFactory
diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php
index 45ed572..635b919 100644
--- a/GlobalUsageHooks.php
+++ b/GlobalUsageHooks.php
@@ -234,4 +234,9 @@
}
return true;
}
+
+ public static function onwgQueryPages( $queryPages ) {
+ $queryPages[] = array( 'MostGloballyLinkedFilesPage',
'MostGloballyLinkedFiles' );
+ return true;
+ }
}
diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php
index dc1a162..85d14f0 100644
--- a/GlobalUsage_body.php
+++ b/GlobalUsage_body.php
@@ -146,4 +146,59 @@
__METHOD__
);
}
+
+ /**
+ * Utility function to redirect special pages that are only on the
shared repo
+ *
+ * Putting here as this can be useful in multiple special page classes.
+ * This redirects the current page to the same page on the shared repo
+ * wiki, making sure to use the english name of the special page, in
case the
+ * current wiki uses something other than english for its content
language.
+ *
+ * @param IContextSource $context $this->getContext() from the special
page.
+ */
+ public static function redirectSpecialPageToSharedRepo( IContextSource
$context ) {
+ global $wgGlobalUsageSharedRepoWiki;
+ // Make sure to get the "canonical" page name, and not a
translation.
+ $titleText = $context->getTitle()->getDBkey();
+ list( $canonicalName, $subpage ) =
SpecialPageFactory::resolveAlias( $titleText );
+ $canonicalName = MWNamespace::getCanonicalName( NS_SPECIAL ) .
':' . $canonicalName;
+ if ( $subpage !== null ) {
+ $canonicalName .= '/' . $subpage;
+ }
+
+ $url = WikiMap::getForeignURL( $wgGlobalUsageSharedRepoWiki,
$canonicalName );
+ if ( $url !== false ) {
+ // We have a url
+ $args = $context->getRequest()->getQueryValues();
+ unset( $args['title'] );
+ $url = wfAppendQuery( $url, $args );
+
+ $context->getOutput()->redirect( $url );
+ } else {
+ // WikiMap can't find the url for the shared repo.
+ // Just pretend we don't exist in this case.
+ $context->getOutput()->setStatusCode( 404 );
+ $context->getOutput()->showErrorPage(
'nosuchspecialpage', 'nospecialpagetext' );
+ }
+ }
+
+ /**
+ * Are we currently on the shared repo? (Utility function)
+ *
+ * @note This assumes the user has a single shared repo. If the user has
+ * multiple/nested foreign repos, then its unclear what it means to
+ * be on the "shared repo". See discussion on bug 23136.
+ * @return boolean
+ */
+ public static function onSharedRepo() {
+ global $wgGlobalUsageSharedRepoWiki, $wgGlobalUsageDatabase;
+ if ( !$wgGlobalUsageSharedRepoWiki ) {
+ // backwards compatability with settings from before
$wgGlobalUsageSharedRepoWiki
+ // was introduced.
+ return $wgGlobalUsageDatabase === wfWikiID() ||
!$wgGlobalUsageDatabase;
+ } else {
+ return $wgGlobalUsageSharedRepoWiki === wfWikiID();
+ }
+ }
}
diff --git a/SpecialMostGloballyLinkedFiles.php
b/SpecialMostGloballyLinkedFiles.php
new file mode 100644
index 0000000..e61bddb
--- /dev/null
+++ b/SpecialMostGloballyLinkedFiles.php
@@ -0,0 +1,103 @@
+<?php
+/**
+ * Special page to list files with most global usages
+ *
+ * @file
+ * @ingroup SpecialPage
+ * @author Brian Wolff <[email protected]>
+ */
+
+class MostGloballyLinkedFilesPage extends MostimagesPage {
+
+ function __construct( $name = 'MostGloballyLinkedFiles' ) {
+ parent::__construct( $name );
+ }
+
+ /**
+ * Main execution function. Use the parent if we're on the right wiki.
+ * If we're not on a shared repo, try to redirect there.
+ */
+ function execute( $par ) {
+ global $wgGlobalUsageSharedRepoWiki;
+ if ( GlobalUsage::onSharedRepo() ) {
+ parent::execute( $par );
+ } else {
+ GlobalUsage::redirectSpecialPageToSharedRepo(
$this->getContext() );
+ }
+ }
+
+ /**
+ * Don't want to do cached handling on non-shared repo, since we only
redirect.
+ * @return boolean
+ */
+ function isCacheable() {
+ return GlobalUsage::onSharedRepo();
+ }
+
+ /**
+ * What query to do.
+ * @return array
+ */
+ function getQueryInfo() {
+ $this->assertOnSharedRepo();
+ return array(
+ 'tables' => array( 'globalimagelinks' ),
+ 'fields' => array(
+ 'namespace' => NS_FILE,
+ 'title' => 'gil_to',
+ 'value' => 'COUNT(*)'
+ ),
+ 'options' => array(
+ 'GROUP BY' => 'gil_to',
+ 'HAVING' => 'COUNT(*) > 1'
+ )
+ );
+ }
+
+ /**
+ * Make sure we are on the shared repo.
+ *
+ * This function should only be used as a paranoia check, and should
never actually be hit.
+ * There should be actual error handling for any code path a user could
hit.
+ */
+ protected function assertOnSharedRepo() {
+ if ( !GlobalUsage::onSharedRepo() ) {
+ throw new MWException( "Special:MostGloballyLinkedFiles
should only be processed on the shared repo" );
+ }
+ }
+
+ /**
+ * Only list this special page on the wiki that is the shared repo.
+ *
+ * @return boolean Should this be listed in Special:SpecialPages
+ */
+ function isListed() {
+ return GlobalUsage::onSharedRepo();
+ }
+
+ /**
+ * In most common configs (including WMF's), this wouldn't be needed.
However
+ * for completeness support having the shared repo db be separate from
the
+ * globalimagelinks db.
+ */
+ function getRecacheDB() {
+ global $wgGlobalUsageDatabase;
+
+ // There's no reason why we couldn't make this special page
work on all wikis,
+ // it just doesn't really make sense to. We should be prevented
from getting
+ // to this point by $this->isCachable(), but just to be safe:
+ $this->assertOnSharedRepo();
+
+ if ( $wgGlobalUsageDatabase === false || $wgGlobalUsageDatabase
=== wfWikiID() ) {
+ // We are using the local wiki
+ return parent::getRecacheDB();
+ } else {
+ // The global usage db could be on a different db
+ return wfGetDB(
+ DB_SLAVE,
+ array( $this->getName(), 'QueryPage::recache',
'vslow' ),
+ $wgGlobalUsageDatabase
+ );
+ }
+ }
+}
diff --git a/i18n/en.json b/i18n/en.json
index fe8e8e1..108804b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -13,5 +13,7 @@
"globalusage-on-wiki": "Usage on $2",
"globalusage-of-file": "The following other wikis use this file:",
"globalusage-more": "View [[{{#Special:GlobalUsage}}/$1|more global
usage]] of this file.",
- "globalusage-filterlocal": "Do not show local usage"
-}
\ No newline at end of file
+ "globalusage-filterlocal": "Do not show local usage",
+ "mostgloballylinkedfiles": "Most globally linked files",
+ "mostgloballylinkedfiles-summary": "List of files that have been embedded
the highest number of times across all wikis. For the equivalent list that
takes into account only usages on {{SITENAME}}, see
[[{{#special:MostLinkedFiles}}]]."
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index ee8b455..2795e78 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -23,5 +23,7 @@
"globalusage-on-wiki": "Shown in the list of global usages.\n\nExample:
[[Commons:Special:GlobalUsage/Example.jpg]] and
[[Commons:File:Example.jpg]]\n\nParameters:\n* $1 - (Unused) the filename\n* $2
- the project name given as a domain, e.g. en.wikipedia.org",
"globalusage-of-file": "Used on an image page.\n\nThe number of
following wikis is unknown. By an empty result, no message is shown.",
"globalusage-more": "Used on an image page, when more global usage
results are available. Example: [[Commons:File:Example.jpg]]\n* $1 - name of
the file (without namespace)",
- "globalusage-filterlocal": "Filteroption for [[Special:GlobalUsage]]"
+ "globalusage-filterlocal": "Filteroption for [[Special:GlobalUsage]]",
+ "mostgloballylinkedfiles":
"{{doc-special|MostGloballyLinkedFiles}}\nName of the the special that lists
files with most usages across all wikis. Global refers to the usage (all wikis,
not just current wiki). This is similar to {{msg-mw|mostimages}}, but for the
global special page.",
+ "mostgloballylinkedfiles-summary":
"{{doc-specialpagesummary|MostGloballyLinkedFiles}}\nGlobal refers to the fact
that this takes all wikis into account, not just the current wiki. This is
similar to {{msg-mw|mostimages-summary}}, but for the global special page."
}
--
To view, visit https://gerrit.wikimedia.org/r/143755
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3850da0bb12e2de45dc7b0db332f9169a00f1b8e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/GlobalUsage
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits