From dd5c1b7fb7ff3983e0fd8f371d5448215efa2201 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Wed, 20 Aug 2014 17:46:11 -0400 Subject: [PATCH] Title::getContentModel(): load from DB if necessary Also don't cast $model to int in LinkCache::addGoodLinkObj(); content model IDs are non-numeric strings, not integers, so that field was always populated with the value 0. Because 0 is a falsy value, this caused subsequent calls to Title::getContentModel() to return the default model rather than the correct one. Also (hopefully) fixed every single query that could cause a LinkCache entry to be added without the content model. Bug: 69789 Change-Id: I94f06baf406afa538cd2b10139598442f9fc6759 --- RELEASE-NOTES-1.24 | 2 ++ includes/OutputPage.php | 12 +++++++++--- includes/Title.php | 6 ++++-- includes/cache/LinkBatch.php | 7 +++++++ includes/cache/LinkCache.php | 6 +++--- includes/parser/LinkHolderArray.php | 24 ++++++++++++++++++------ 6 files changed, 43 insertions(+), 14 deletions(-) diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 01f8b0a6ca..0952400558 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -196,6 +196,8 @@ production. * (bug 67870) wfShellExec() cuts off stdout at multiples of 8192 bytes. * $wgRunJobsAsync now works with private wikis (e.g. read requires login). * (bugs 57238, 65206) Blank pages can now be directly created. +* (bug 69789) Title::getContentModel() now loads from the database when + necessary instead of incorrectly returning the default content model. === Web API changes in 1.24 === * action=parse API now supports prop=modules, which provides the list of diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 6ea495372d..c98f34b172 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1240,7 +1240,7 @@ class OutputPage extends ContextSource { * @param array $categories Mapping category name => sort key */ public function addCategoryLinks( array $categories ) { - global $wgContLang; + global $wgContLang, $wgContentHandlerUseDB; if ( !is_array( $categories ) || count( $categories ) == 0 ) { return; @@ -1253,9 +1253,15 @@ class OutputPage extends ContextSource { # Fetch existence plus the hiddencat property $dbr = wfGetDB( DB_SLAVE ); + $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len', + 'page_is_redirect', 'page_latest', 'pp_value' ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'page_content_model'; + } + $res = $dbr->select( array( 'page', 'page_props' ), - array( 'page_id', 'page_namespace', 'page_title', 'page_len', - 'page_is_redirect', 'page_latest', 'pp_value' ), + $fields, $lb->constructSet( 'page', $dbr ), __METHOD__, array(), diff --git a/includes/Title.php b/includes/Title.php index 15ff216237..2bb56ca43a 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -944,10 +944,12 @@ class Title { * Get the page's content model id, see the CONTENT_MODEL_XXX constants. * * @throws MWException + * @param int $flags A bit field; may be Title::GAID_FOR_UPDATE to select for update * @return string Content model id */ - public function getContentModel() { - if ( !$this->mContentModel ) { + public function getContentModel( $flags = 0 ) { + # Calling getArticleID() loads the field from cache as needed + if ( !$this->mContentModel && $this->getArticleID( $flags ) ) { $linkCache = LinkCache::singleton(); $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' ); } diff --git a/includes/cache/LinkBatch.php b/includes/cache/LinkBatch.php index 76cc583636..48c063f4e5 100644 --- a/includes/cache/LinkBatch.php +++ b/includes/cache/LinkBatch.php @@ -180,6 +180,8 @@ class LinkBatch { * @return bool|ResultWrapper */ public function doQuery() { + global $wgContentHandlerUseDB; + if ( $this->isEmpty() ) { return false; } @@ -190,6 +192,11 @@ class LinkBatch { $table = 'page'; $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len', 'page_is_redirect', 'page_latest' ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'page_content_model'; + } + $conds = $this->constructSet( 'page', $dbr ); // Do query diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index e80dfb3167..6925df9013 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -129,10 +129,10 @@ class LinkCache { * @param int $len Text's length * @param int $redir Whether the page is a redirect * @param int $revision Latest revision's ID - * @param int $model Latest revision's content model ID + * @param string|null $model Latest revision's content model ID */ public function addGoodLinkObj( $id, $title, $len = -1, $redir = null, - $revision = 0, $model = 0 + $revision = 0, $model = null ) { $dbkey = $title->getPrefixedDBkey(); $this->mGoodLinks[$dbkey] = (int)$id; @@ -140,7 +140,7 @@ class LinkCache { 'length' => (int)$len, 'redirect' => (int)$redir, 'revision' => (int)$revision, - 'model' => (int)$model + 'model' => $model ? (string)$model : null, ); } diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index c3925b3e4d..7794fae4e7 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -290,7 +290,7 @@ class LinkHolderArray { } wfProfileIn( __METHOD__ ); - global $wgContLang; + global $wgContLang, $wgContentHandlerUseDB; $colours = array(); $linkCache = LinkCache::singleton(); @@ -348,10 +348,16 @@ class LinkHolderArray { ); } + $fields = array( 'page_id', 'page_namespace', 'page_title', + 'page_is_redirect', 'page_len', 'page_latest' ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'page_content_model'; + } + $res = $dbr->select( 'page', - array( 'page_id', 'page_namespace', 'page_title', - 'page_is_redirect', 'page_len', 'page_latest' ), + $fields, $dbr->makeList( $where, LIST_OR ), __METHOD__ ); @@ -465,7 +471,7 @@ class LinkHolderArray { * @param array $colours */ protected function doVariants( &$colours ) { - global $wgContLang; + global $wgContLang, $wgContentHandlerUseDB; $linkBatch = new LinkBatch(); $variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders) $output = $this->parent->getOutput(); @@ -554,9 +560,15 @@ class LinkHolderArray { if ( !$linkBatch->isEmpty() ) { // construct query $dbr = wfGetDB( DB_SLAVE ); + $fields = array( 'page_id', 'page_namespace', 'page_title', + 'page_is_redirect', 'page_len', 'page_latest' ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'page_content_model'; + } + $varRes = $dbr->select( 'page', - array( 'page_id', 'page_namespace', 'page_title', - 'page_is_redirect', 'page_len', 'page_latest' ), + $fields, $linkBatch->constructSet( 'page', $dbr ), __METHOD__ ); -- 2.20.1