jenkins-bot has submitted this change and it was merged.

Change subject: Add WikiFilePage::getForeignCategories() method
......................................................................


Add WikiFilePage::getForeignCategories() method

Unlike getCategories(), this will return the categories
on the wiki where the file is hosted (so it should work with Commons).

Bug: 56598
Change-Id: Ice972f023c676b5857707ccf58ee108585a7f021
---
M includes/WikiFilePage.php
1 file changed, 41 insertions(+), 0 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php
index fe1ff88a..2b192b0 100644
--- a/includes/WikiFilePage.php
+++ b/includes/WikiFilePage.php
@@ -189,4 +189,45 @@
                }
                return parent::doPurge();
        }
+
+       /**
+        * Get the categories this file is a member of on the wiki where it was 
uploaded.
+        * For local files, this is the same as getCategories().
+        * For foreign API files (InstantCommons), this is not supported 
currently.
+        * Results will include hidden categories.
+        *
+        * @return TitleArray|Title[]
+        * @since 1.23
+        */
+       public function getForeignCategories() {
+               $this->loadFile();
+               $title = $this->mTitle;
+               $file = $this->mFile;
+
+               if ( ! $file instanceof LocalFile ) {
+                       wfDebug( __CLASS__ . '::' . __METHOD__ . ' is not 
supported for this file' );
+                       return TitleArray::newFromResult( new 
FakeResultWrapper( array() ) );
+               }
+
+               /** @var LocalRepo $repo */
+               $repo = $file->getRepo();
+               $dbr = $repo->getSlaveDB();
+
+               $res = $dbr->select(
+                       array( 'page', 'categorylinks' ),
+                       array(
+                               'page_title' => 'cl_to',
+                               'page_namespace' => NS_CATEGORY,
+                       ),
+                       array(
+                               'page_namespace' => $title->getNamespace(),
+                               'page_title' => $title->getDBkey(),
+                       ),
+                       __METHOD__,
+                       array(),
+                       array( 'categorylinks' => array( 'INNER JOIN', 'page_id 
= cl_from' ) )
+               );
+
+               return TitleArray::newFromResult( $res );
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ice972f023c676b5857707ccf58ee108585a7f021
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: GergÅ‘ Tisza <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Parent5446 <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to