<?php
+/**
+ * Page existence cache.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Cache
+ */
+
/**
* Cache for article titles (prefixed DB keys) and ids linked from one source
*
// becomes incompatible with the new version.
private $mClassVer = 4;
- private $mGoodLinks, $mBadLinks;
- private $mForUpdate;
+ private $mGoodLinks = array();
+ private $mGoodLinkFields = array();
+ private $mBadLinks = array();
+ private $mForUpdate = false;
/**
* Get an instance of this class
return $instance;
}
- function __construct() {
- $this->mForUpdate = false;
- $this->mGoodLinks = array();
- $this->mGoodLinkFields = array();
- $this->mBadLinks = array();
- }
-
/**
* General accessor to get/set whether SELECT FOR UPDATE should be used
*
* Get a field of a title object from cache.
* If this link is not good, it will return NULL.
* @param $title Title
- * @param $field String: ('length','redirect','revision')
+ * @param $field String: ('length','redirect','revision','model')
* @return mixed
*/
public function getGoodLinkFieldObj( $title, $field ) {
* @param $len Integer: text's length
* @param $redir Integer: whether the page is a redirect
* @param $revision Integer: latest revision's ID
+ * @param $model Integer: latest revision's content model ID
*/
- public function addGoodLinkObj( $id, $title, $len = -1, $redir = null, $revision = false ) {
+ public function addGoodLinkObj( $id, $title, $len = -1, $redir = null, $revision = false, $model = false ) {
$dbkey = $title->getPrefixedDbKey();
$this->mGoodLinks[$dbkey] = intval( $id );
$this->mGoodLinkFields[$dbkey] = array(
'length' => intval( $len ),
'redirect' => intval( $redir ),
- 'revision' => intval( $revision ) );
+ 'revision' => intval( $revision ),
+ 'model' => intval( $model ) );
+ }
+
+ /**
+ * Same as above with better interface.
+ * @since 1.19
+ * @param $title Title
+ * @param $row object which has the fields page_id, page_is_redirect,
+ * page_latest and page_content_model
+ */
+ public function addGoodLinkObjFromRow( $title, $row ) {
+ $dbkey = $title->getPrefixedDbKey();
+ $this->mGoodLinks[$dbkey] = intval( $row->page_id );
+ $this->mGoodLinkFields[$dbkey] = array(
+ 'length' => intval( $row->page_len ),
+ 'redirect' => intval( $row->page_is_redirect ),
+ 'revision' => intval( $row->page_latest ),
+ 'model' => !empty( $row->page_content_model ) ? strval( $row->page_content_model ) : null,
+ );
}
/**
* @return Integer
*/
public function addLinkObj( $nt ) {
- global $wgAntiLockFlags;
+ global $wgAntiLockFlags, $wgContentHandlerUseDB;
+
wfProfileIn( __METHOD__ );
$key = $nt->getPrefixedDBkey();
$options = array();
}
- $s = $db->selectRow( 'page',
- array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
+ $f = array( 'page_id', 'page_len', 'page_is_redirect', 'page_latest' );
+ if ( $wgContentHandlerUseDB ) $f[] = 'page_content_model';
+
+ $s = $db->selectRow( 'page', $f,
array( 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ),
__METHOD__, $options );
# Set fields...
if ( $s !== false ) {
+ $this->addGoodLinkObjFromRow( $nt, $s );
$id = intval( $s->page_id );
- $len = intval( $s->page_len );
- $redirect = intval( $s->page_is_redirect );
- $revision = intval( $s->page_latest );
} else {
+ $this->addBadLinkObj( $nt );
$id = 0;
- $len = -1;
- $redirect = 0;
- $revision = 0;
}
- if ( $id == 0 ) {
- $this->addBadLinkObj( $nt );
- } else {
- $this->addGoodLinkObj( $id, $nt, $len, $redirect, $revision );
- }
wfProfileOut( __METHOD__ );
return $id;
}