Gergő Tisza has uploaded a new change for review. https://gerrit.wikimedia.org/r/95148
Change subject: Add LocalFile::getParentCategories() method ...................................................................... Add LocalFile::getParentCategories() method Unlike Title::getParentCategories(), this will return the categories on the hosting wiki (so it should work with Commons). Bug: 56598 Change-Id: Ice972f023c676b5857707ccf58ee108585a7f021 --- M includes/filerepo/file/LocalFile.php 1 file changed, 35 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/48/95148/1 diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index fe769be..58859b2 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -680,6 +680,41 @@ } /** + * Get the categories this file belongs to. + * Unlike $file->getOriginalTitle()->getParentCategories(), + * this will return the categories on the wiki where the image is hosted, + * and the category names will not contain the namespace name. + * + * @return Array of parents in the form: + * $parent => $currentarticle + */ + public function getParentCategories() { + global $wgContLang, $wgCanonicalNamespaceNames; + + $categories = array(); + + $title = $this->getOriginalTitle(); + $dbr = $this->repo->getSlaveDB(); + + $res = $dbr->select( + array( 'page', 'categorylinks' ), + array( 'cl_to' ), + array( + 'page_namespace' => $title->getNamespace(), + 'page_title' => $title->getDBkey(), + 'page_id = cl_from', + ), + __METHOD__ + ); + + $categoryNamespace = MWNamespace::getCanonicalName( NS_CATEGORY ); + foreach ( $res as $row ) { + $categories[ $categoryNamespace . ':' . $row->cl_to ] = $title->getFullText(); + } + return $categories; + } + + /** * @return int */ function getBitDepth() { -- To view, visit https://gerrit.wikimedia.org/r/95148 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ice972f023c676b5857707ccf58ee108585a7f021 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits