X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialDoubleRedirects.php;h=9140bf1426b750150082a5750c740a11fd9616af;hb=f3ecd4855cebb001ca96efe9d55fdf03fc9a7277;hp=c364f70fa934025d2eeb1a9a4e2f72cc36314edf;hpb=b65669ff7adbbde55872a8ddd93214a9e1df75c6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialDoubleRedirects.php b/includes/specials/SpecialDoubleRedirects.php index c364f70fa9..9140bf1426 100644 --- a/includes/specials/SpecialDoubleRedirects.php +++ b/includes/specials/SpecialDoubleRedirects.php @@ -32,7 +32,7 @@ class DoubleRedirectsPage extends QueryPage { parent::__construct( $name ); } - function isExpensive() { + public function isExpensive() { return true; } @@ -50,15 +50,15 @@ class DoubleRedirectsPage extends QueryPage { function reallyGetQueryInfo( $namespace = null, $title = null ) { $limitToTitle = !( $namespace === null && $title === null ); - $dbr = wfGetDB( DB_SLAVE ); - $retval = array( - 'tables' => array( + $dbr = wfGetDB( DB_REPLICA ); + $retval = [ + 'tables' => [ 'ra' => 'redirect', 'rb' => 'redirect', 'pa' => 'page', 'pb' => 'page' - ), - 'fields' => array( + ], + 'fields' => [ 'namespace' => 'pa.page_namespace', 'title' => 'pa.page_title', 'value' => 'pa.page_title', @@ -71,8 +71,8 @@ class DoubleRedirectsPage extends QueryPage { 'nsc' => 'rb.rd_namespace', 'tc' => 'rb.rd_title', 'iwc' => 'rb.rd_interwiki', - ), - 'conds' => array( + ], + 'conds' => [ 'ra.rd_from = pa.page_id', // Filter out redirects where the target goes interwiki (bug 40353). @@ -88,8 +88,8 @@ class DoubleRedirectsPage extends QueryPage { 'pb.page_title = ra.rd_title', 'rb.rd_from = pb.page_id', - ) - ); + ] + ]; if ( $limitToTitle ) { $retval['conds']['pa.page_namespace'] = $namespace; @@ -99,12 +99,12 @@ class DoubleRedirectsPage extends QueryPage { return $retval; } - function getQueryInfo() { + public function getQueryInfo() { return $this->reallyGetQueryInfo(); } function getOrderFields() { - return array( 'ra.rd_namespace', 'ra.rd_title' ); + return [ 'ra.rd_namespace', 'ra.rd_title' ]; } /** @@ -121,7 +121,7 @@ class DoubleRedirectsPage extends QueryPage { // get a little more detail about each individual entry quickly // using the filter of reallyGetQueryInfo. if ( $result && !isset( $result->nsb ) ) { - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $qi = $this->reallyGetQueryInfo( $result->namespace, $result->title @@ -137,38 +137,46 @@ class DoubleRedirectsPage extends QueryPage { $result = $dbr->fetchObject( $res ); } } + $linkRenderer = $this->getLinkRenderer(); if ( !$result ) { - return '' . Linker::link( $titleA, null, array(), array( 'redirect' => 'no' ) ) . ''; + return '' . $linkRenderer->makeLink( $titleA, null, [], [ 'redirect' => 'no' ] ) . ''; } $titleB = Title::makeTitle( $result->nsb, $result->tb ); $titleC = Title::makeTitle( $result->nsc, $result->tc, '', $result->iwc ); - $linkA = Linker::linkKnown( + $linkA = $linkRenderer->makeKnownLink( $titleA, null, - array(), - array( 'redirect' => 'no' ) + [], + [ 'redirect' => 'no' ] ); - $edit = Linker::linkKnown( - $titleA, - $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(), - array(), - array( - 'redirect' => 'no', - 'action' => 'edit' - ) - ); + // if the page is editable, add an edit link + if ( + // check user permissions + $this->getUser()->isAllowed( 'edit' ) && + // check, if the content model is editable through action=edit + ContentHandler::getForTitle( $titleA )->supportsDirectEditing() + ) { + $edit = $linkRenderer->makeKnownLink( + $titleA, + $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->text(), + [], + [ 'action' => 'edit' ] + ); + } else { + $edit = ''; + } - $linkB = Linker::linkKnown( + $linkB = $linkRenderer->makeKnownLink( $titleB, null, - array(), - array( 'redirect' => 'no' ) + [], + [ 'redirect' => 'no' ] ); - $linkC = Linker::linkKnown( $titleC ); + $linkC = $linkRenderer->makeKnownLink( $titleC ); $lang = $this->getLanguage(); $arr = $lang->getArrow() . $lang->getDirMark(); @@ -176,6 +184,35 @@ class DoubleRedirectsPage extends QueryPage { return ( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" ); } + /** + * Cache page content model and gender distinction for performance + * + * @param IDatabase $db + * @param ResultWrapper $res + */ + function preprocessResults( $db, $res ) { + if ( !$res->numRows() ) { + return; + } + + $batch = new LinkBatch; + foreach ( $res as $row ) { + $batch->add( $row->namespace, $row->title ); + if ( isset( $row->nsb ) ) { + // lazy loaded when using cached results + $batch->add( $row->nsb, $row->tb ); + } + if ( isset( $row->iwc ) && !$row->iwc ) { + // lazy loaded when using cached result, not added when interwiki link + $batch->add( $row->nsc, $row->tc ); + } + } + $batch->execute(); + + // Back to start for display + $res->seek( 0 ); + } + protected function getGroupName() { return 'maintenance'; }