}
}
+ /**
+ * Returns a list of fields that are to be selected for initializing Title objects or LinkCache entries.
+ * Uses $wgContentHandlerUseDB to determine whether to include page_content_model.
+ *
+ * @return array
+ */
+ protected static function getSelectFields() {
+ global $wgContentHandlerUseDB;
+
+ $fields = array(
+ 'page_namespace', 'page_title', 'page_id',
+ 'page_len', 'page_is_redirect', 'page_latest',
+ );
+
+ if ( $wgContentHandlerUseDB ) {
+ $fields[] = 'page_content_model';
+ }
+
+ return $fields;
+ }
+
/**
* Create a new Title from an article ID
*
$db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
$row = $db->selectRow(
'page',
- array(
- 'page_namespace', 'page_title', 'page_id',
- 'page_len', 'page_is_redirect', 'page_latest',
- ),
+ self::getSelectFields(),
array( 'page_id' => $id ),
__METHOD__
);
$res = $dbr->select(
'page',
- array(
- 'page_namespace', 'page_title', 'page_id',
- 'page_len', 'page_is_redirect', 'page_latest',
- ),
+ self::getSelectFields(),
array( 'page_id' => $ids ),
__METHOD__
);
if ( isset( $row->page_is_redirect ) )
$this->mRedirect = (bool)$row->page_is_redirect;
if ( isset( $row->page_latest ) )
- $this->mLatestID = (int)$row->page_latest; # FIXME: whene3ver page_latest is updated, also update page_content_model
+ $this->mLatestID = (int)$row->page_latest;
if ( isset( $row->page_content_model ) )
$this->mContentModel = intval( $row->page_content_model );
else
- $this->mContentModel = null; # initialized lazily in getContentModel()
+ $this->mContentModel = false; # initialized lazily in getContentModel()
} else { // page not found
$this->mArticleID = 0;
$this->mLength = 0;
$this->mRedirect = false;
$this->mLatestID = 0;
- $this->mContentModel = null; # initialized lazily in getContentModel()
+ $this->mContentModel = false; # initialized lazily in getContentModel()
}
}
$t->mArticleID = ( $ns >= 0 ) ? -1 : 0;
$t->mUrlform = wfUrlencode( $t->mDbkeyform );
$t->mTextform = str_replace( '_', ' ', $title );
- $t->mContentModel = null; # initialized lazily in getContentModel()
+ $t->mContentModel = false; # initialized lazily in getContentModel()
return $t;
}
* @return Integer: Content model id
*/
public function getContentModel() {
- if ( empty( $this->mContentModel ) ) {
+ if ( !$this->mContentModel ) {
+ $linkCache = LinkCache::singleton();
+ $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
+ }
+
+ if ( !$this->mContentModel ) {
$this->mContentModel = ContentHandler::getDefaultModelFor( $this );
}
- assert( !empty( $this->mContentModel ) );
+ if( !$this->mContentModel ) {
+ throw new MWException( "failed to determin content model!" );
+ }
+
return $this->mContentModel;
}
* Convenience method for checking a title's content model name
*
* @param int $id
- * @return true if $this->getContentModel() == $id
+ * @return Boolean true if $this->getContentModel() == $id
*/
public function hasContentModel( $id ) {
return $this->getContentModel() == $id;
$this->mRedirect = null;
$this->mLength = -1;
$this->mLatestID = false;
+ $this->mContentModel = false;
$this->mEstimateRevisions = null;
}
$res = $db->select(
array( 'page', $table ),
- array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
+ self::getSelectFields(),
array(
"{$prefix}_from=page_id",
"{$prefix}_namespace" => $this->getNamespace(),
* @return Array of Title objects linking here
*/
public function getLinksFrom( $options = array(), $table = 'pagelinks', $prefix = 'pl' ) {
+ global $wgContentHandlerUseDB;
+
$id = $this->getArticleID();
# If the page doesn't exist; there can't be any link from this page
$namespaceFiled = "{$prefix}_namespace";
$titleField = "{$prefix}_title";
+ $fields = array( $namespaceFiled, $titleField, 'page_id', 'page_len', 'page_is_redirect', 'page_latest' );
+ if ( $wgContentHandlerUseDB ) $fields[] = 'page_content_model';
+
$res = $db->select(
array( $table, 'page' ),
- array( $namespaceFiled, $titleField, 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
+ $fields,
array( "{$prefix}_from" => $id ),
__METHOD__,
$options,
* @return Bool
*/
public function isSingleRevRedirect() {
+ global $wgContentHandlerUseDB;
+
$dbw = wfGetDB( DB_MASTER );
+
# Is it a redirect?
+ $fields = array( 'page_is_redirect', 'page_latest', 'page_id' );
+ if ( $wgContentHandlerUseDB ) $fields[] = 'page_content_model';
+
$row = $dbw->selectRow( 'page',
- array( 'page_is_redirect', 'page_latest', 'page_id' ),
+ $fields,
$this->pageCond(),
__METHOD__,
array( 'FOR UPDATE' )
$this->mArticleID = $row ? intval( $row->page_id ) : 0;
$this->mRedirect = $row ? (bool)$row->page_is_redirect : false;
$this->mLatestID = $row ? intval( $row->page_latest ) : false;
+ $this->mContentModel = $row && isset( $row->page_content_model ) ? intval( $row->page_content_model ) : false;
if ( !$this->mRedirect ) {
return false;
}
* 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 ) );
}
/**
* @since 1.19
* @param $title Title
* @param $row object which has the fields page_id, page_is_redirect,
- * page_latest
+ * page_latest and page_content_model
*/
public function addGoodLinkObjFromRow( $title, $row ) {
$dbkey = $title->getPrefixedDbKey();
'length' => intval( $row->page_len ),
'redirect' => intval( $row->page_is_redirect ),
'revision' => intval( $row->page_latest ),
+ 'model' => !empty( $row->page_content_model ) ? intval( $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...