Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / page / ImagePage.php
index 16b83d1..653e443 100644 (file)
@@ -27,6 +27,9 @@ use Wikimedia\Rdbms\ResultWrapper;
  * Class for viewing MediaWiki file description pages
  *
  * @ingroup Media
+ *
+ * @property WikiFilePage $mPage Set by overwritten newPage() in this class
+ * @method WikiFilePage getPage()
  */
 class ImagePage extends Article {
        /** @var File|false */
@@ -41,11 +44,6 @@ class ImagePage extends Article {
        /** @var bool */
        protected $mExtraDescription = false;
 
-       /**
-        * @var WikiFilePage
-        */
-       protected $mPage;
-
        /**
         * @param Title $title
         * @return WikiFilePage
@@ -736,13 +734,10 @@ EOT
        }
 
        /**
-        * Print out the various links at the bottom of the image page, e.g. reupload,
-        * external editing (and instructions link) etc.
+        * Add the re-upload link (or message about not being able to re-upload) to the output.
         */
        protected function uploadLinksBox() {
-               global $wgEnableUploads;
-
-               if ( !$wgEnableUploads ) {
+               if ( !$this->getContext()->getConfig()->get( 'EnableUploads' ) ) {
                        return;
                }
 
@@ -751,27 +746,28 @@ EOT
                        return;
                }
 
-               $out = $this->getContext()->getOutput();
-               $out->addHTML( "<ul>\n" );
-
-               # "Upload a new version of this file" link
-               $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
+               $canUpload = MediaWikiServices::getInstance()->getPermissionManager()
+                       ->quickUserCan( 'upload', $this->getContext()->getUser(), $this->getTitle() );
                if ( $canUpload && UploadBase::userCanReUpload(
                                $this->getContext()->getUser(),
                                $this->mPage->getFile() )
                ) {
+                       // "Upload a new version of this file" link
                        $ulink = Linker::makeExternalLink(
                                $this->getUploadUrl(),
                                $this->getContext()->msg( 'uploadnewversion-linktext' )->text()
                        );
-                       $out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
-                               . "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
+                       $attrs = [ 'class' => 'plainlinks', 'id' => 'mw-imagepage-reupload-link' ];
+                       $linkPara = Html::rawElement( 'p', $attrs, $ulink );
                } else {
-                       $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
-                               . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
+                       // "You cannot overwrite this file." message
+                       $attrs = [ 'id' => 'mw-imagepage-upload-disallowed' ];
+                       $msg = $this->getContext()->msg( 'upload-disallowed-here' )->text();
+                       $linkPara = Html::element( 'p', $attrs, $msg );
                }
 
-               $out->addHTML( "</ul>\n" );
+               $uploadLinks = Html::rawElement( 'div', [ 'class' => 'mw-imagepage-upload-links' ], $linkPara );
+               $this->getContext()->getOutput()->addHTML( $uploadLinks );
        }
 
        /**
@@ -991,6 +987,7 @@ EOT
                        parent::delete();
                        return;
                }
+               '@phan-var LocalFile $file';
 
                $deleter = new FileDeleteForm( $file );
                $deleter->execute();