actions: Migrate to SelectQueryBuilder API
This patch migrates `selectField()` and `selectRowCount()` to use the query builder interface. Testing this patch: * For info action, go to any page and check the information about the page. For example, the main page; ".../Main_Page?action=info", notice the "?action=info" part added to the main page URL, check to make sure this action works before and after applying this patch and nothing explodes. * For the, do the same thing as the info action above but for deleting a page to also make sure that nothing explodes. In fact, delete a page successfully. Change-Id: Ib5dc67ddab548ad45f3754a6658305a4b698df6c
This commit is contained in:
parent
66c59bbc8c
commit
e7c9d53672
2 changed files with 66 additions and 79 deletions
|
|
@ -255,13 +255,12 @@ class DeleteAction extends FormlessAction {
|
|||
// This, as a side-effect, also makes sure that the following query isn't being run for
|
||||
// pages with a larger history, unless the user has the 'bigdelete' right
|
||||
// (and is about to delete this page).
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$revisions = (int)$dbr->selectField(
|
||||
'revision',
|
||||
'COUNT(rev_page)',
|
||||
[ 'rev_page' => $title->getArticleID() ],
|
||||
__METHOD__
|
||||
);
|
||||
$revisions = (int)wfGetDB( DB_REPLICA )->newSelectQueryBuilder()
|
||||
->select( 'COUNT(rev_page)' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_page' => $title->getArticleID() ] )
|
||||
->caller( __METHOD__ )
|
||||
->fetchField();
|
||||
|
||||
// @todo i18n issue/patchwork message
|
||||
$context->getOutput()->addHTML(
|
||||
|
|
@ -659,16 +658,16 @@ class DeleteAction extends FormlessAction {
|
|||
*/
|
||||
private function pageHasHistory(): bool {
|
||||
$dbr = wfGetDB( DB_REPLICA );
|
||||
$res = $dbr->selectRowCount(
|
||||
'revision',
|
||||
'*',
|
||||
[
|
||||
'rev_page' => $this->getTitle()->getArticleID(),
|
||||
$dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0'
|
||||
],
|
||||
__METHOD__,
|
||||
[ 'LIMIT' => 2 ]
|
||||
);
|
||||
$res = $dbr->newSelectQueryBuilder()
|
||||
->select( '*' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_page' => $this->getTitle()->getArticleID() ] )
|
||||
->andWhere(
|
||||
[ $dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0' ]
|
||||
)->limit( 2 )
|
||||
->caller( __METHOD__ )
|
||||
->fetchRowCount();
|
||||
|
||||
return $res > 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -940,11 +940,8 @@ class InfoAction extends FormlessAction {
|
|||
$dbr = $this->loadBalancer->getConnectionRef( DB_REPLICA );
|
||||
$setOpts += Database::getCacheSetOptions( $dbr );
|
||||
|
||||
$tables = [ 'revision' ];
|
||||
$field = 'rev_actor';
|
||||
$pageField = 'rev_page';
|
||||
$tsField = 'rev_timestamp';
|
||||
$joins = [];
|
||||
|
||||
$watchedItemStore = $this->watchedItemStore;
|
||||
|
||||
|
|
@ -960,55 +957,47 @@ class InfoAction extends FormlessAction {
|
|||
}
|
||||
|
||||
// Total number of edits
|
||||
$edits = (int)$dbr->selectField(
|
||||
'revision',
|
||||
'COUNT(*)',
|
||||
[ 'rev_page' => $id ],
|
||||
$fname
|
||||
);
|
||||
$edits = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(*)' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_page' => $id ] )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
$result['edits'] = $edits;
|
||||
|
||||
// Total number of distinct authors
|
||||
if ( $config->get( MainConfigNames::MiserMode ) ) {
|
||||
$result['authors'] = 0;
|
||||
} else {
|
||||
$result['authors'] = (int)$dbr->selectField(
|
||||
$tables,
|
||||
"COUNT(DISTINCT $field)",
|
||||
[ $pageField => $id ],
|
||||
$fname,
|
||||
[],
|
||||
$joins
|
||||
);
|
||||
$result['authors'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( "COUNT(DISTINCT $field)" )
|
||||
->from( 'revision' )
|
||||
->where( [ $pageField => $id ] )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
// "Recent" threshold defined by RCMaxAge setting
|
||||
$threshold = $dbr->timestamp( time() - $config->get( MainConfigNames::RCMaxAge ) );
|
||||
|
||||
// Recent number of edits
|
||||
$edits = (int)$dbr->selectField(
|
||||
'revision',
|
||||
'COUNT(rev_page)',
|
||||
[
|
||||
'rev_page' => $id,
|
||||
"rev_timestamp >= " . $dbr->addQuotes( $threshold )
|
||||
],
|
||||
$fname
|
||||
);
|
||||
$edits = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(rev_page)' )
|
||||
->from( 'revision' )
|
||||
->where( [ 'rev_page' => $id ] )
|
||||
->andWhere( [ "rev_timestamp >= " . $dbr->addQuotes( $threshold ) ] )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
$result['recent_edits'] = $edits;
|
||||
|
||||
// Recent number of distinct authors
|
||||
$result['recent_authors'] = (int)$dbr->selectField(
|
||||
$tables,
|
||||
"COUNT(DISTINCT $field)",
|
||||
[
|
||||
$pageField => $id,
|
||||
"$tsField >= " . $dbr->addQuotes( $threshold )
|
||||
],
|
||||
$fname,
|
||||
[],
|
||||
$joins
|
||||
);
|
||||
$result['recent_authors'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( "COUNT(DISTINCT $field)" )
|
||||
->from( 'revision' )
|
||||
->where( [ $pageField => $id ] )
|
||||
->andWhere( [ 'rev_timestamp >= ' . $dbr->addQuotes( $threshold ) ] )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
|
||||
// Subpages (if enabled)
|
||||
if ( $this->namespaceInfo->hasSubpages( $title->getNamespace() ) ) {
|
||||
|
|
@ -1018,21 +1007,20 @@ class InfoAction extends FormlessAction {
|
|||
|
||||
// Subpages of this page (redirects)
|
||||
$conds['page_is_redirect'] = 1;
|
||||
$result['subpages']['redirects'] = (int)$dbr->selectField(
|
||||
'page',
|
||||
'COUNT(page_id)',
|
||||
$conds,
|
||||
$fname
|
||||
);
|
||||
|
||||
$result['subpages']['redirects'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(page_id)' )
|
||||
->from( 'page' )
|
||||
->where( $conds )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
// Subpages of this page (non-redirects)
|
||||
$conds['page_is_redirect'] = 0;
|
||||
$result['subpages']['nonredirects'] = (int)$dbr->selectField(
|
||||
'page',
|
||||
'COUNT(page_id)',
|
||||
$conds,
|
||||
$fname
|
||||
);
|
||||
$result['subpages']['nonredirects'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(page_id)' )
|
||||
->from( 'page' )
|
||||
->where( $conds )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
|
||||
// Subpages of this page (total)
|
||||
$result['subpages']['total'] = $result['subpages']['redirects']
|
||||
|
|
@ -1043,20 +1031,20 @@ class InfoAction extends FormlessAction {
|
|||
if ( $config->get( MainConfigNames::MiserMode ) ) {
|
||||
$result['transclusion']['to'] = 0;
|
||||
} else {
|
||||
$result['transclusion']['to'] = (int)$dbr->selectField(
|
||||
'templatelinks',
|
||||
'COUNT(tl_from)',
|
||||
$this->linksMigration->getLinksConditions( 'templatelinks', $title ),
|
||||
$fname
|
||||
);
|
||||
$result['transclusion']['to'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(tl_from)' )
|
||||
->from( 'templatelinks' )
|
||||
->where( $this->linksMigration->getLinksConditions( 'templatelinks', $title ) )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
}
|
||||
|
||||
$result['transclusion']['from'] = (int)$dbr->selectField(
|
||||
'templatelinks',
|
||||
'COUNT(*)',
|
||||
[ 'tl_from' => $title->getArticleID() ],
|
||||
$fname
|
||||
);
|
||||
$result['transclusion']['from'] = (int)$dbr->newSelectQueryBuilder()
|
||||
->select( 'COUNT(*)' )
|
||||
->from( 'templatelinks' )
|
||||
->where( [ 'tl_from' => $title->getArticleID() ] )
|
||||
->caller( $fname )
|
||||
->fetchField();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue