jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/401092 )

Change subject: Create Special:GloballyUnusedFiles page
......................................................................


Create Special:GloballyUnusedFiles page

This special page shows files which are unused at all wikis.
So in fact this special page is global equivalent to
Special:UnusedFiles

Bug: T183673
Change-Id: I47a591622ae5955757810ef1995e916a810bc506
---
M GlobalUsage.alias.php
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/GlobalUsageHooks.php
A includes/SpecialGloballyUnusedFiles.php
6 files changed, 143 insertions(+), 3 deletions(-)

Approvals:
  Brian Wolff: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/GlobalUsage.alias.php b/GlobalUsage.alias.php
index a0ddb61..3b6e2c4 100644
--- a/GlobalUsage.alias.php
+++ b/GlobalUsage.alias.php
@@ -13,6 +13,7 @@
        'GlobalUsage' => [ 'GlobalUsage' ],
        'MostGloballyLinkedFiles' => [ 'MostGloballyLinkedFiles' ],
        'GloballyWantedFiles' => [ 'GloballyWantedFiles' ],
+       'GloballyUnusedFiles' => [ 'GloballyUnusedFiles' ]
 ];
 
 /** Arabic (العربية) */
diff --git a/extension.json b/extension.json
index f2aba51..84acdd7 100644
--- a/extension.json
+++ b/extension.json
@@ -12,6 +12,7 @@
        "SpecialPages": {
                "MostGloballyLinkedFiles": "SpecialMostGloballyLinkedFiles",
                "GloballyWantedFiles": "SpecialGloballyWantedFiles",
+               "GloballyUnusedFiles": "SpecialGloballyUnusedFiles",
                "GlobalUsage": "SpecialGlobalUsage"
        },
        "JobClasses": {
@@ -37,7 +38,8 @@
                "ApiQueryGlobalUsage": "includes/ApiQueryGlobalUsage.php",
                "GlobalUsageCachePurgeJob": 
"includes/GlobalUsageCachePurgeJob.php",
                "SpecialMostGloballyLinkedFiles": 
"includes/SpecialMostGloballyLinkedFiles.php",
-               "SpecialGloballyWantedFiles": 
"includes/SpecialGloballyWantedFiles.php"
+               "SpecialGloballyWantedFiles": 
"includes/SpecialGloballyWantedFiles.php",
+               "SpecialGloballyUnusedFiles": 
"includes/SpecialGloballyUnusedFiles.php"
        },
        "@doc": [
                "Things that can cause link updates:",
diff --git a/i18n/en.json b/i18n/en.json
index 31733a6..191c021 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -27,5 +27,8 @@
        "apihelp-query+globalusage-param-filterlocal": "Filter local usage of 
the file.",
        "apihelp-query+globalusage-example-1": "Get usage of 
[[:File:Example.jpg]]",
        "globalusage-header": "This page shows where a file is used on other 
wikis. You can also find that information at the bottom of the file description 
page.",
-       "globalusage-header-image": ""
+       "globalusage-header-image": "",
+       "globallyunusedfiles": "Globally unused files",
+       "globallyunusedfilestext": "The following files exist but are not 
embedded in any page on any wiki.",
+       "globallyunusedfiles-error-nonsharedrepo": "This wiki is not on the 
shared repo"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 1d3db4a..28b49dd 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -39,5 +39,8 @@
        "apihelp-query+globalusage-param-filterlocal": 
"{{doc-apihelp-param|query+globalusage|filterlocal}}",
        "apihelp-query+globalusage-example-1": 
"{{doc-apihelp-example|query+globalusage}}",
        "globalusage-header": "Text message used in [[Special:GlobalUsage]] 
right above the form describing the purpose of special page.",
-       "globalusage-header-image": "{{notranslate}}. Extra header for on-wiki 
customization. $1 - File being looked for."
+       "globalusage-header-image": "{{notranslate}}. Extra header for on-wiki 
customization. $1 - File being looked for.",
+       "globallyunusedfilestext": "Header message of 
[[Special:GloballyUnusedFiles]]",
+       "globallyunusedfiles": "{{doc-special|GloballyUnusedFiles}}",
+       "globallyunusedfiles-error-nonsharedrepo": "This error is displayed if 
user tries to access wiki which is not on shared repo"
 }
diff --git a/includes/GlobalUsageHooks.php b/includes/GlobalUsageHooks.php
index 006abf8..e515a96 100644
--- a/includes/GlobalUsageHooks.php
+++ b/includes/GlobalUsageHooks.php
@@ -223,6 +223,9 @@
        public static function onwgQueryPages( &$queryPages ) {
                $queryPages[] = [ 'SpecialMostGloballyLinkedFiles', 
'MostGloballyLinkedFiles' ];
                $queryPages[] = [ 'SpecialGloballyWantedFiles', 
'GloballyWantedFiles' ];
+               if ( GlobalUsage::onSharedRepo() ) {
+                       $queryPages[] = [ 'SpecialGloballyUnusedFiles', 
'GloballyUnusedFiles' ];
+               }
                return true;
        }
 }
diff --git a/includes/SpecialGloballyUnusedFiles.php 
b/includes/SpecialGloballyUnusedFiles.php
new file mode 100644
index 0000000..0c05671
--- /dev/null
+++ b/includes/SpecialGloballyUnusedFiles.php
@@ -0,0 +1,128 @@
+<?php
+/**
+ * Implements Special:GloballyUnusedFiles, the global equivalent to
+ * Special:UnusedFiles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup SpecialPage
+ */
+
+/**
+ * A special page that lists globally unused files
+ *
+ * @ingroup SpecialPage
+ */
+class SpecialGloballyUnusedFiles extends ImageQueryPage {
+       function __construct( $name = 'GloballyUnusedFiles' ) {
+               parent::__construct( $name );
+       }
+
+       /**
+        * Check if we are on wiki with globalimagelinks table in database.
+        * @return bool
+        */
+       function isOnGlobalUsageDatabase() {
+               global $wgGlobalUsageDatabase;
+               return !$wgGlobalUsageDatabase || $wgGlobalUsageDatabase === 
wfWikiID();
+       }
+
+       /**
+        * Main execution function. Use the parent if we're on the right wiki.
+        * @throws ErrorPageError if we are not on a wiki with GlobalUsage 
database
+        * @param string $par
+        */
+       function execute( $par ) {
+               if ( self::isOnGlobalUsageDatabase() ) {
+                       parent::execute( $par );
+               } else {
+                       throw new ErrorPageError( 'globallyunusedfiles', 
'globallyunusedfiles-error-nonsharedrepo' );
+               }
+       }
+
+       /**
+        * Allow to cache only if globalimagelinks table exists in database.
+        * @return bool
+        */
+       function isCacheable() {
+               return self::isOnGlobalUsageDatabase();
+       }
+
+       /**
+        * Only list this special page on the wiki that has globalimagelinks 
table.
+        * @return bool Should this be listed in Special:SpecialPages
+        */
+       function isListed() {
+               return self::isOnGlobalUsageDatabase();
+       }
+
+       function isExpensive() {
+               return true;
+       }
+
+       function sortDescending() {
+               return false;
+       }
+
+       function isSyndicated() {
+               return false;
+       }
+
+       function getQueryInfo() {
+               if ( !self::isOnGlobalUsageDatabase() ) {
+                       throw new Exception( "This wiki is not on shared repo" 
);
+               }
+
+               $retval = [
+                       'tables' => [ 'image', 'globalimagelinks' ],
+                       'fields' => [
+                               'namespace' => NS_FILE,
+                               'title' => 'img_name',
+                               'value' => 'img_timestamp',
+                       ],
+                       'conds' => [ 'gil_to IS NULL' ],
+                       'join_conds' => [ 'globalimagelinks' => [ 'LEFT JOIN', 
'gil_to = img_name' ] ]
+               ];
+
+               if ( $this->getConfig()->get( 'CountCategorizedImagesAsUsed' ) 
) {
+                       // Order is significant
+                       $retval['tables'] = [ 'image', 'page', 'categorylinks',
+                               'globalimagelinks' ];
+                       $retval['conds']['page_namespace'] = NS_FILE;
+                       $retval['conds'][] = 'cl_from IS NULL';
+                       $retval['conds'][] = 'img_name = page_title';
+                       $retval['join_conds']['categorylinks'] = [
+                               'LEFT JOIN', 'cl_from = page_id' ];
+                       $retval['join_conds']['globalimagelinks'] = [
+                               'LEFT JOIN', 'gil_to = page_title' ];
+               }
+
+               return $retval;
+       }
+
+       function usesTimestamps() {
+               return true;
+       }
+
+       function getPageHeader() {
+               return $this->msg( 'globallyunusedfilestext' )->parseAsBlock();
+       }
+
+       protected function getGroupName() {
+               return 'maintenance';
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/401092
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I47a591622ae5955757810ef1995e916a810bc506
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/GlobalUsage
Gerrit-Branch: master
Gerrit-Owner: Phantom42 <nikita...@gmail.com>
Gerrit-Reviewer: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Framawiki <framaw...@tools.wmflabs.org>
Gerrit-Reviewer: Phantom42 <nikita...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to