From f311221ec27763caaadfe5e8ea1dbc7e8bc9c4f0 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Fri, 6 Nov 2015 10:36:59 +0100 Subject: [PATCH] Make edit link conditional on Special:BrokenRedirects/DoubleRedirects When an user has no permission, do not show an edit link. Also do not show an edit link when content model does not allow direct editing, like WikiData items. For performance reason the special pages now run a LinkBatch to collect the content model information. Bug: T117900 Change-Id: Ieb56a6f314059356b95bc045f3d255930d54f213 --- includes/specials/SpecialBrokenRedirects.php | 48 ++++++++++++++--- includes/specials/SpecialDoubleRedirects.php | 55 +++++++++++++++++--- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/includes/specials/SpecialBrokenRedirects.php b/includes/specials/SpecialBrokenRedirects.php index 701f75f047..9ea18daa87 100644 --- a/includes/specials/SpecialBrokenRedirects.php +++ b/includes/specials/SpecialBrokenRedirects.php @@ -121,12 +121,20 @@ class BrokenRedirectsPage extends QueryPage { array( 'redirect' => 'no' ) ); $links = array(); - $links[] = Linker::linkKnown( - $fromObj, - $this->msg( 'brokenredirects-edit' )->escaped(), - array(), - array( '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( $fromObj )->supportsDirectEditing() + ) { + $links[] = Linker::linkKnown( + $fromObj, + $this->msg( 'brokenredirects-edit' )->escaped(), + array(), + array( 'action' => 'edit' ) + ); + } $to = Linker::link( $toObj, null, @@ -147,13 +155,37 @@ class BrokenRedirectsPage extends QueryPage { ); } - $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage() - ->pipeList( $links ) )->escaped(); + if ( $links ) { + $out .= $this->msg( 'parentheses' )->rawParams( $this->getLanguage() + ->pipeList( $links ) )->escaped(); + } $out .= " {$arr} {$to}"; return $out; } + + /** + * Cache page content model 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 ); + } + $batch->execute(); + + // Back to start for display + $res->seek( 0 ); + } + protected function getGroupName() { return 'maintenance'; } diff --git a/includes/specials/SpecialDoubleRedirects.php b/includes/specials/SpecialDoubleRedirects.php index 6d40985bbd..c04582e5c4 100644 --- a/includes/specials/SpecialDoubleRedirects.php +++ b/includes/specials/SpecialDoubleRedirects.php @@ -151,14 +151,24 @@ class DoubleRedirectsPage extends QueryPage { array( 'redirect' => 'no' ) ); - $edit = Linker::linkKnown( - $titleA, - $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(), - array(), - array( - '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 = Linker::linkKnown( + $titleA, + $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(), + array(), + array( + 'action' => 'edit' + ) + ); + } else { + $edit = ''; + } $linkB = Linker::linkKnown( $titleB, @@ -175,6 +185,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'; } -- 2.20.1