X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FWikiFilePage.php;h=817f0fa7eb5abc4d154096b39e738d970967598e;hb=aea3a5dce215b9f3929d65365fe9bd101ecdf07d;hp=fe1ff88a95ca9abdf6b6acb4f1b12e269fec4c3e;hpb=ebbea3c974312c56e93799fc93ee3f35130703f9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/WikiFilePage.php b/includes/WikiFilePage.php index fe1ff88a95..817f0fa7eb 100644 --- a/includes/WikiFilePage.php +++ b/includes/WikiFilePage.php @@ -85,7 +85,8 @@ class WikiFilePage extends WikiPage { if ( $from == $to ) { return null; } - return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to ); + $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to ); + return $this->mRedirectTarget; } /** @@ -142,7 +143,8 @@ class WikiFilePage extends WikiPage { } $hash = $this->mFile->getSha1(); if ( !( $hash ) ) { - return $this->mDupes = array(); + $this->mDupes = array(); + return $this->mDupes; } $dupes = RepoGroup::singleton()->findBySha1( $hash ); // Remove duplicates with self and non matching file sizes @@ -189,4 +191,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 ); + } }