http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72181
Revision: 72181
Author: reedy
Date: 2010-09-01 23:58:26 +0000 (Wed, 01 Sep 2010)
Log Message:
-----------
Add a "isInCategory" function to check if a specific title is in a certain
category
Modified Paths:
--------------
trunk/phase3/includes/Title.php
Modified: trunk/phase3/includes/Title.php
===================================================================
--- trunk/phase3/includes/Title.php 2010-09-01 23:52:26 UTC (rev 72180)
+++ trunk/phase3/includes/Title.php 2010-09-01 23:58:26 UTC (rev 72181)
@@ -3530,6 +3530,31 @@
return !$this->isExternal() && MWNamespace::isWatchable(
$this->getNamespace() );
}
+ /*
+ * Returns whether an article is in the specific category
+ *
+ * @param $category String: The category name (without Category: Prefix)
+ *
+ * @return bool
+ */
+ public function isInCategory( $category ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select(
+ 'categorylinks',
+ '*',
+ array(
+ 'cl_from' => $this->getArticleId(),
+ 'cl_to' => $category,
+ ),
+ __METHOD__,
+ array(
+ 'LIMIT' => 1
+ )
+ );
+
+ return ( $dbr->numRows( $res ) > 0 );
+ }
+
/**
* Get categories to which this Title belongs and return an array of
* categories' names.
@@ -3553,9 +3578,10 @@
$res = $dbr->query( $sql );
if ( $dbr->numRows( $res ) > 0 ) {
- foreach ( $res as $row )
+ foreach ( $res as $row ) {
// $data[] =
Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
$data[$wgContLang->getNSText( NS_CATEGORY ) .
':' . $row->cl_to] = $this->getFullText();
+ }
} else {
$data = array();
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs