Special:WhatLinksHere Don't show edit links for non-direct-editing pages
[lhc/web/wiklou.git] / includes / specials / SpecialWhatlinkshere.php
index 0b3175a..5db81d4 100644 (file)
@@ -46,6 +46,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
 
                $this->setHeaders();
                $this->outputHeader();
+               $this->addHelpLink( 'Help:What links here' );
 
                $opts = new FormOptions();
 
@@ -266,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() );
@@ -313,7 +322,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                static $msgcache = null;
                if ( $msgcache === null ) {
                        static $msgs = array( 'isredirect', 'istemplate', 'semicolon-separator',
-                               'whatlinkshere-links', 'isimage' );
+                               'whatlinkshere-links', 'isimage', 'edit' );
                        $msgcache = array();
                        foreach ( $msgs as $msg ) {
                                $msgcache[$msg] = $this->msg( $msg )->escaped();
@@ -354,7 +363,7 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                }
 
                # Space for utilities links, with a what-links-here link provided
-               $wlhLink = $this->wlhLink( $nt, $msgcache['whatlinkshere-links'] );
+               $wlhLink = $this->wlhLink( $nt, $msgcache['whatlinkshere-links'], $msgcache['edit'] );
                $wlh = Xml::wrapClass(
                        $this->msg( 'parentheses' )->rawParams( $wlhLink )->escaped(),
                        'mw-whatlinkshere-tools'
@@ -369,18 +378,39 @@ class SpecialWhatLinksHere extends IncludableSpecialPage {
                return Xml::closeElement( 'ul' );
        }
 
-       protected function wlhLink( Title $target, $text ) {
+       protected function wlhLink( Title $target, $text, $editText ) {
                static $title = null;
                if ( $title === null ) {
                        $title = $this->getPageTitle();
                }
 
-               return Linker::linkKnown(
-                       $title,
-                       $text,
-                       array(),
-                       array( 'target' => $target->getPrefixedText() )
+               // 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' )
+                       );
+               }
+
+               // build the links html
+               return $this->getLanguage()->pipeList( $links );
        }
 
        function makeSelfLink( $text, $query ) {