jenkins-bot has submitted this change and it was merged.
Change subject: Add Special:GloballyWantedFiles
......................................................................
Add Special:GloballyWantedFiles
Like Special:WantedFiles, but for all wikis.
Some functionality was added as static methods to GlobalUsage
in order so that other special pages could share the code.
To fully work, this needs Ic72be60d13, but it degrades gracefully
without that change.
Change-Id: I91ce050d46096326c2b6508a34a30b71695cb21e
---
M GlobalUsage.alias.php
M GlobalUsage.php
M GlobalUsageHooks.php
M GlobalUsage_body.php
A SpecialGloballyWantedFiles.php
M i18n/en.json
M i18n/qqq.json
7 files changed, 168 insertions(+), 2 deletions(-)
Approvals:
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 d87412b..4c3b9d0 100644
--- a/GlobalUsage.alias.php
+++ b/GlobalUsage.alias.php
@@ -13,6 +13,7 @@
$specialPageAliases['en'] = array(
'GlobalUsage' => array( 'GlobalUsage' ),
'MostGloballyLinkedFiles' => array( 'MostGloballyLinkedFiles' ),
+ 'GloballyWantedFiles' => array( 'GloballyWantedFiles' ),
);
/** Arabic (العربية) */
diff --git a/GlobalUsage.php b/GlobalUsage.php
index e278289..c91b0b2 100644
--- a/GlobalUsage.php
+++ b/GlobalUsage.php
@@ -57,8 +57,10 @@
$wgAutoloadClasses['ApiQueryGlobalUsage'] = $dir . 'ApiQueryGlobalUsage.php';
$wgAutoloadClasses['GlobalUsageCachePurgeJob'] = $dir .
'GlobalUsageCachePurgeJob.php';
$wgAutoloadClasses['MostGloballyLinkedFilesPage'] = $dir .
'SpecialMostGloballyLinkedFiles.php';
+$wgAutoloadClasses['SpecialGloballyWantedFiles'] = $dir .
'SpecialGloballyWantedFiles.php';
$wgSpecialPages['MostGloballyLinkedFiles'] = 'MostGloballyLinkedFilesPage';
+$wgSpecialPages['GloballyWantedFiles'] = 'SpecialGloballyWantedFiles';
$wgSpecialPages['GlobalUsage'] = 'SpecialGlobalUsage';
$wgSpecialPageGroups['GlobalUsage'] = 'media';
diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php
index 635b919..d965442 100644
--- a/GlobalUsageHooks.php
+++ b/GlobalUsageHooks.php
@@ -237,6 +237,7 @@
public static function onwgQueryPages( $queryPages ) {
$queryPages[] = array( 'MostGloballyLinkedFilesPage',
'MostGloballyLinkedFiles' );
+ $queryPages[] = array( 'SpecialGloballyWantedFiles',
'GloballyWantedFiles' );
return true;
}
}
diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php
index 85d14f0..7713230 100644
--- a/GlobalUsage_body.php
+++ b/GlobalUsage_body.php
@@ -201,4 +201,58 @@
return $wgGlobalUsageSharedRepoWiki === wfWikiID();
}
}
+
+ /**
+ * Query info for getting wanted files using global image links
+ *
+ * Adding a utility method here, as this same query is used in
+ * two different special page classes.
+ *
+ * @return Array Query info array, as a QueryPage would expect.
+ */
+ public static function getWantedFilesQueryInfo( $wiki = false ) {
+ $qi = array(
+ 'tables' => array(
+ 'globalimagelinks',
+ 'page',
+ 'redirect',
+ 'img1' => 'image',
+ 'img2' => 'image',
+ ),
+ 'fields' => array(
+ 'namespace' => NS_FILE,
+ 'title' => 'gil_to',
+ 'value' => 'COUNT(*)'
+ ),
+ 'conds' => array(
+ 'img1.img_name' => null,
+ // We also need to exclude file redirects
+ 'img2.img_name' => null,
+ ),
+ 'options' => array( 'GROUP BY' => 'gil_to' ),
+ 'join_conds' => array(
+ 'img1' => array( 'LEFT JOIN',
+ 'gil_to = img_name'
+ ),
+ 'page' => array( 'LEFT JOIN', array(
+ 'gil_to = page_title',
+ 'page_namespace' => NS_FILE,
+ ) ),
+ 'redirect' => array( 'LEFT JOIN', array(
+ 'page_id = rd_from',
+ 'rd_namespace' => NS_FILE,
+ 'rd_interwiki' => ''
+ ) ),
+ 'img2' => array( 'LEFT JOIN',
+ 'rd_title = img2.img_name'
+ )
+ )
+ );
+ if ( $wiki !== false ) {
+ // Limit to just one wiki.
+ $qi['conds']['gil_wiki'] = $wiki;
+ }
+
+ return $qi;
+ }
}
diff --git a/SpecialGloballyWantedFiles.php b/SpecialGloballyWantedFiles.php
new file mode 100644
index 0000000..573e961
--- /dev/null
+++ b/SpecialGloballyWantedFiles.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Implements Special:GloballyWantedFiles, the global equivalent to
+ * Special:WantedFiles
+ *
+ * @file
+ * @author Brian Wolff <[email protected]>
+ * @ingroup SpecialPage
+ */
+class SpecialGloballyWantedFiles extends WantedFilesPage {
+
+ function __construct( $name = 'GloballyWantedFiles' ) {
+ return 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() );
+ }
+ }
+
+ /**
+ * Output an extra header
+ *
+ * @return String html to output
+ */
+ function getPageHeader() {
+ if ( RepoGroup::singleton()->hasForeignRepos() ) {
+ return $this->msg( 'globallywantedfiles-foreign-repo'
)->parseAsBlock();
+ } else {
+ // Use grandparent behaviour. Parent adds a message
+ // about the tracking category which doesn't make sense
here.
+ return WantedQueryPage::getPageHeader();
+ }
+ }
+
+ /**
+ * Don't want to do cached handling on non-shared repo, since we only
redirect.
+ *
+ * Also make sure that GlobalUsage db same as shared repo.
+ * (To catch the unlikely case where GlobalUsage db is different db
from the
+ * shared repo db).
+ * @return boolean
+ */
+ function isCacheable() {
+ global $wgGlobalUsageDatabase;
+ return GlobalUsage::onSharedRepo()
+ && ( !$wgGlobalUsageDatabase || $wgGlobalUsageDatabase
=== wfWikiID() );
+ }
+
+ /**
+ * 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();
+ }
+
+ function getQueryInfo() {
+ return GlobalUsage::getWantedFilesQueryInfo();
+ }
+
+ /**
+ * Format a row of the results
+ *
+ * We need to override this in order to link to Special:GlobalUsage
+ * instead of Special:WhatLinksHere.
+ *
+ * @param $skin Skin
+ * @param $result stdClass A row from the database
+ * @return String HTML to output
+ */
+ public function formatResult( $skin, $result ) {
+ $title = Title::makeTitleSafe( $result->namespace,
$result->title );
+ if ( $title instanceof Title ) {
+ $pageLink = Linker::link( $title );
+ if ( $title->isKnown() && wfFindFile( $title ) ) {
+ // If the title exists and is a file, than
strike.
+ // The wfFindFile() call should already be
cached from Linker::link call
+ // so it shouldn't be too expensive. However a
future @todo would be
+ // to do preload existence checks for files all
at once via RepoGroup::findFiles.
+ $pageLink = Html::rawElement( 'del', array(),
$pageLink );
+ }
+
+ $gu = SpecialPage::getTitleFor( 'GlobalUsage',
$title->getDBKey() );
+ $label = $this->msg( 'nlinks' )->numParams(
$result->value )->escaped();
+ $usages = Linker::link( $gu, $label );
+
+ return $this->getLanguage()->specialList( $pageLink,
$usages );
+ } else {
+ return $this->msg( 'wantedpages-badtitle',
$result->title )->escaped();
+ }
+ }
+}
diff --git a/i18n/en.json b/i18n/en.json
index 108804b..5241c6b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -15,5 +15,8 @@
"globalusage-more": "View [[{{#Special:GlobalUsage}}/$1|more global
usage]] of this 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}}]]."
+ "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}}]].",
+ "globallywantedfiles": "Globally wanted files",
+ "globallywantedfiles-summary": "List of files that have been embedded the
highest number of times across all wikis despite not existing. For the
equivalent list that takes into account only usages on {{SITENAME}}, see
[[{{#special:WantedFiles}}]].",
+ "globallywantedfiles-foreign-repo": "<strong>Warning:</strong> This wiki
uses a foreign file repository. Files from the foreign repository that are in
use will show up on this list as struck out blue links despite the fact that
they exist."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 2795e78..154d043 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -25,5 +25,8 @@
"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]]",
"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."
+ "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.",
+ "globallywantedfiles": "{{doc-special|GloballyWantedFiles}}\nName of
the the special that lists non-existent files with most usages across all
wikis. Global refers to the usage (all wikis, not just current wiki). This is
similar to {{msg-mw|wantedfiles}}, but for the global special page.",
+ "globallywantedfiles-summary":
"{{doc-specialpagesummary|GloballyWantedFiles}}\nGlobal refers to the fact that
this takes all wikis into account, not just the current wiki. This is similar
to {{msg-mw|wantedfiles-summary}} or {{msg-mw|wantedfilestext-cat}}, but for
the global special page.",
+ "globallywantedfiles-foreign-repo": "Warning shown on top of
Special:GloballyWantedFiles (Between the {{msg-mw|perfcachedts}} and
{{msg-mw|showingresultsinrange}} messages) if the wiki has a foreign repository
enabled."
}
--
To view, visit https://gerrit.wikimedia.org/r/143828
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I91ce050d46096326c2b6508a34a30b71695cb21e
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/GlobalUsage
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[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