X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FWikiFilePage.php;h=2b192b0f068e13f20af59a6fc7664ef97fc14269;hb=368a95dc658bada230ba8f163e8e9f85e99c8263;hp=fe1ff88a95ca9abdf6b6acb4f1b12e269fec4c3e;hpb=edba2e008c079f4d51abc70f2c98c1dc8009a900;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php index fe1ff88a95..2b192b0f06 100644 --- a/includes/WikiFilePage.php +++ b/includes/WikiFilePage.php @@ -189,4 +189,45 @@ class WikiFilePage extends WikiPage { } 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 ); + } }