Special:WhatLinksHere Don't show edit links for non-direct-editing pages
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 23 Jul 2015 16:15:08 +0000 (18:15 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Wed, 29 Jul 2015 14:12:29 +0000 (14:12 +0000)
It's possible, that pages links to a page, which aren't editable directly
through action=edit. Don't show an edit link for such pages.

Bug: T106680
Change-Id: I01ff6dbd5b4e9fff84795f7c3d8ada23c09c7ae8

includes/specials/SpecialWhatlinkshere.php

index 69a8074..5db81d4 100644 (file)
@@ -267,6 +267,14 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                }
                $prevId = $from;
 
+               // use LinkBatch to make sure, that all required data (associated with Titles)
+               // is loaded in one query
+               $lb = new LinkBatch();
+               foreach ( $rows as $row ) {
+                       $lb->add( $row->page_namespace, $row->page_title );
+               }
+               $lb->execute();
+
                if ( $level == 0 ) {
                        if ( !$this->including() ) {
                                $out->addHTML( $this->whatlinkshereForm() );
@@ -376,23 +384,33 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                        $title = $this->getPageTitle();
                }
 
-               $editLink = '';
-               if ( $this->getUser()->isAllowed( 'edit' ) ) {
-                       $editLink = $this->msg( 'pipe-separator' )->escaped() .
-                               Linker::linkKnown(
-                                       $target,
-                                       $editText,
-                                       array(),
-                                       array( 'action' => 'edit' )
-                               );
+               // always show a "<- Links" link
+               $links = array(
+                       'links' => Linker::linkKnown(
+                               $title,
+                               $text,
+                               array(),
+                               array( 'target' => $target->getPrefixedText() )
+                       ),
+               );
+
+               // 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( $target )->supportsDirectEditing()
+               ) {
+                       $links['edit'] = Linker::linkKnown(
+                               $target,
+                               $editText,
+                               array(),
+                               array( 'action' => 'edit' )
+                       );
                }
 
-               return Linker::linkKnown(
-                       $title,
-                       $text,
-                       array(),
-                       array( 'target' => $target->getPrefixedText() )
-               ) . $editLink;
+               // build the links html
+               return $this->getLanguage()->pipeList( $links );
        }
 
        function makeSelfLink( $text, $query ) {