* @return Array of Title objects linking here
*/
public function getLinksTo( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
- $linkCache = LinkCache::singleton();
-
if ( count( $options ) > 0 ) {
$db = wfGetDB( DB_MASTER );
} else {
);
$retVal = array();
- if ( $db->numRows( $res ) ) {
+ if ( $res->numRows() ) {
+ $linkCache = LinkCache::singleton();
foreach ( $res as $row ) {
$titleObj = Title::makeTitle( $row->page_namespace, $row->page_title );
if ( $titleObj ) {
return $this->getLinksTo( $options, 'templatelinks', 'tl' );
}
+ /**
+ * Get an array of Title objects linked from this Title
+ * Also stores the IDs in the link cache.
+ *
+ * WARNING: do not use this function on arbitrary user-supplied titles!
+ * On heavily-used templates it will max out the memory.
+ *
+ * @param $options Array: may be FOR UPDATE
+ * @param $table String: table name
+ * @param $prefix String: fields prefix
+ * @return Array of Title objects linking here
+ */
+ public function getLinksFrom( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
+ $id = $this->getArticleId();
+
+ # If the page doesn't exist; there can't be any link from this page
+ if ( !$id ) {
+ return array();
+ }
+
+ if ( count( $options ) > 0 ) {
+ $db = wfGetDB( DB_MASTER );
+ } else {
+ $db = wfGetDB( DB_SLAVE );
+ }
+
+ $namespaceFiled = "{$prefix}_namespace";
+ $titleField = "{$prefix}_title";
+
+ $res = $db->select(
+ array( $table, 'page' ),
+ array( $namespaceFiled, $titleField, 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
+ array( "{$prefix}_from" => $id ),
+ __METHOD__,
+ $options,
+ array( 'page' => array( 'LEFT JOIN', array( "page_namespace=$namespaceFiled", "page_title=$titleField" ) ) )
+ );
+
+ $retVal = array();
+ if ( $res->numRows() ) {
+ $linkCache = LinkCache::singleton();
+ foreach ( $res as $row ) {
+ $titleObj = Title::makeTitle( $row->$namespaceFiled, $row->$titleField );
+ if ( $titleObj ) {
+ if ( $row->page_id ) {
+ $linkCache->addGoodLinkObjFromRow( $titleObj, $row );
+ } else {
+ $linkCache->addBadLinkObj( $titleObj );
+ }
+ $retVal[] = $titleObj;
+ }
+ }
+ }
+ return $retVal;
+ }
+
+ /**
+ * Get an array of Title objects used on this Title as a template
+ * Also stores the IDs in the link cache.
+ *
+ * WARNING: do not use this function on arbitrary user-supplied titles!
+ * On heavily-used templates it will max out the memory.
+ *
+ * @param $options Array: may be FOR UPDATE
+ * @return Array of Title the Title objects used here
+ */
+ public function getTemplateLinksFrom( $options = array() ) {
+ return $this->getLinksFrom( $options, 'templatelinks', 'tl' );
+ }
+
/**
* Get an array of Title objects referring to non-existent articles linked from this page
*
/**#@-*/
- /**
- * Return a list of templates used by this article.
- * Uses the templatelinks table
- *
- * @return Array of Title objects
- */
- public function getUsedTemplates() {
- $result = array();
- $id = $this->mTitle->getArticleID();
-
- if ( $id == 0 ) {
- return array();
- }
-
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'templatelinks' ),
- array( 'tl_namespace', 'tl_title' ),
- array( 'tl_from' => $id ),
- __METHOD__ );
-
- if ( $res !== false ) {
- foreach ( $res as $row ) {
- $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
- }
- }
-
- return $result;
- }
-
/**
* Returns a list of hidden categories this page is a member of.
* Uses the page_props and categorylinks tables.
}
}
+ /**
+ * Return a list of templates used by this article.
+ * Uses the templatelinks table
+ *
+ * @deprecated in 1.19; use Title::getTemplateLinksFrom()
+ * @return Array of Title objects
+ */
+ public function getUsedTemplates() {
+ return $this->mTitle->getTemplateLinksFrom();
+ }
+
/**
* Perform article updates on a special page creation.
*