From: Kunal Mehta Date: Fri, 9 Aug 2013 04:59:27 +0000 (+0800) Subject: Add a function that returns a list of categories the page is a member of X-Git-Tag: 1.31.0-rc.0~18968^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=5eb1d775bd6bd01e164306c402dad1bdf9e22831;p=lhc%2Fweb%2Fwiklou.git Add a function that returns a list of categories the page is a member of Main reason is so internal code does not have to recreate the database query each time. This will also be useful for extensions. Change-Id: Ia80c051ff0691087564710f2864ed617d5b9ee96 --- diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 9d61abc754..ce26fb9c9b 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -2978,6 +2978,29 @@ class WikiPage implements Page, IDBAccessObject { /**#@-*/ + /** + * Returns a list of categories this page is a member of. + * Results will include hidden categories + * + * @return TitleArray + */ + public function getCategories() { + $id = $this->getId(); + if ( $id == 0 ) { + return TitleArray::newFromResult( new FakeResultWrapper( array() ) ); + } + + $dbr = wfGetDB( DB_SLAVE ); + $res = $dbr->select( 'categorylinks', + array( 'cl_to AS page_title, ' . NS_CATEGORY . ' AS page_namespace' ), + // Have to do that since DatabaseBase::fieldNamesWithAlias treats numeric indexes + // as not being aliases, and NS_CATEGORY is numeric + array( 'cl_from' => $id ), + __METHOD__ ); + + return TitleArray::newFromResult( $res ); + } + /** * Returns a list of hidden categories this page is a member of. * Uses the page_props and categorylinks tables.