Addshore has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337183 )
Change subject: Show file details on special page
......................................................................
Show file details on special page
This uses a pretend importable target
to just throw some data on the special page.
This also adds a POST vs GET case for the special
page, the GET will simply show the infomation about
the import and the POST would actually perform the import.
The Importable interface will provide everything needed
to import a file onto the wiki, currently only basic methods
have been added, more will be added as needed.
ExternalMediaWikiFile currently contains mock data.
Some sort of factory will be needed to turn URLs into
Importable objects.
Change-Id: I71b7e7a3b6c09519d51789065d29a770a94e0338
---
M extension.json
M i18n/en.json
M i18n/qqq.json
A src/ExternalMediaWikiFile.php
A src/Importable.php
M src/SpecialImportFile.php
6 files changed, 121 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/FileImporter
refs/changes/83/337183/1
diff --git a/extension.json b/extension.json
index 75dd6bd..70fa5b7 100644
--- a/extension.json
+++ b/extension.json
@@ -19,6 +19,8 @@
"ImportFile": "FileImporter\\SpecialImportFile"
},
"AutoloadClasses": {
+ "FileImporter\\ExternalMediaWikiFile": "src/ExternalMediaWikiFile.php",
+ "FileImporter\\Importable": "src/Importable.php",
"FileImporter\\FileImporterHooks": "src/FileImporterHooks.php",
"FileImporter\\SpecialImportFile": "src/SpecialImportFile.php",
"FileImporter\\UrlBasedSiteLookup": "src/UrlBasedSiteLookup.php"
diff --git a/i18n/en.json b/i18n/en.json
index dc6073c..eb4b211 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -11,5 +11,6 @@
"fileimporter-cantimporturl": "Can't import the given URL",
"fileimporter-exampleprefix": "Example",
"fileimporter-submit": "Submit",
+ "fileimporter-import": "Import",
"fileimporter-importfilefromprefix" : "Importing file from"
}
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index c56b9a4..89afd5e 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -11,5 +11,6 @@
"fileimporter-cantimporturl": "Error message shown on the special page
when the URL entered can not be imported from",
"fileimporter-exampleprefix": "Prefix for the example URL contained
within the URL text box on the special page",
"fileimporter-submit": "Text for the submit button on the special page",
+ "fileimporter-import": "Text for the import button on the special page",
"fileimporter-importfilefromprefix" : "prefix for the URL being
imported from on the special page"
}
diff --git a/src/ExternalMediaWikiFile.php b/src/ExternalMediaWikiFile.php
new file mode 100644
index 0000000..22cb263
--- /dev/null
+++ b/src/ExternalMediaWikiFile.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace FileImporter;
+
+// TODO implement real logic here
+class ExternalMediaWikiFile implements Importable {
+
+ public function getTitle() {
+ return 'Berlin_Montage_4';
+ }
+
+ public function getImageUrl() {
+ return
'https://upload.wikimedia.org/wikipedia/commons/5/52/Berlin_Montage_4.jpg';
+ }
+
+ public function getTargetUrl() {
+ return
'https://en.wikipedia.org/wiki/File:Berlin_Montage_4.jpg';
+ }
+
+}
diff --git a/src/Importable.php b/src/Importable.php
new file mode 100644
index 0000000..ae8b8c2
--- /dev/null
+++ b/src/Importable.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace FileImporter;
+
+interface Importable {
+
+ /**
+ * @return string The text to be used as the title.
+ * e.g. in Mediawiki File:Berlin would simply be "Berlin"
+ */
+ public function getTitle();
+
+ /**
+ * @return string A URL that can be used to display the image
+ * This could be a URL on an external site.
+ */
+ public function getImageUrl();
+
+ /**
+ * @return string The URL that the import was initiated using.
+ */
+ public function getTargetUrl();
+
+}
diff --git a/src/SpecialImportFile.php b/src/SpecialImportFile.php
index ed4461d..2fa5fd7 100644
--- a/src/SpecialImportFile.php
+++ b/src/SpecialImportFile.php
@@ -3,6 +3,7 @@
namespace FileImporter;
use Html;
+use Linker;
use MediaWiki\MediaWikiServices;
use Message;
use OOUI\ButtonInputWidget;
@@ -21,6 +22,7 @@
$out->enableOOUI();
$rawUrl = $out->getRequest()->getVal( 'clientUrl', '' );
+ $wasPosted = $out->getRequest()->wasPosted();
if ( !$rawUrl ) {
$this->showUrlEntryPage();
@@ -35,8 +37,17 @@
$this->showDisallowedUrlMessage();
$this->showUrlEntryPage();
} else {
- $this->showImportPage( $parsedUrl );
+ if ( $wasPosted ) {
+ $this->doImport();
+ } else {
+ $this->showImportPage( $rawUrl );
+ }
}
+ }
+
+ private function doImport() {
+ // TODO implement importing
+ $this->getOutput()->addHTML( 'TODO do the import' );
}
/**
@@ -71,8 +82,37 @@
}
private function showUrlEntryPage() {
+ $this->showInputForm();
+ }
+
+ /**
+ * @param string $rawUrl
+ */
+ private function showImportPage( $rawUrl ) {
+ // TODO actually make the correct file?
+ $file = new ExternalMediaWikiFile();
+ $out = $this->getOutput();
+
$this->getOutput()->addModuleStyles( 'ext.FileImporter.Special'
);
- $this->getOutput()->addHTML(
+ $this->showInputForm( $file->getTargetUrl() );
+
+ $out->addHTML(
+ Html::rawElement(
+ 'p',
+ [],
+ ( new Message(
'fileimporter-importfilefromprefix' ) )->plain() . ': ' .
+ Linker::makeExternalLink(
$file->getTargetUrl(), $file->getTargetUrl() )
+ )
+ );
+
+ $out->addHTML( Html::element( 'p', [], $file->getTitle() ) );
+ $out->addHTML( Linker::makeExternalImage( $file->getImageUrl(),
$file->getTitle() ) );
+ }
+
+ private function showInputForm( $clientUrl = null ) {
+ $out = $this->getOutput();
+
+ $out->addHTML(
Html::openElement( 'div' ) . Html::openElement(
'form',
[
@@ -83,9 +123,10 @@
[
'name' => 'clientUrl',
'classes' => [ 'mw-movtocom-url-text' ],
- 'label' => 'Foo',
'autofocus' => true,
'required' => true,
+ 'type' => 'url',
+ 'value' => $clientUrl ? $clientUrl : '',
'placeholder' => ( new Message(
'fileimporter-exampleprefix' ) )->plain() .
':
https://en.wikipedia.org/wiki/File:Berlin_Skyline'
]
@@ -96,20 +137,39 @@
'type' => 'submit',
'flags' => [ 'primary', 'progressive' ],
]
- ) . Html::closeElement( 'form' ) . Html::closeElement(
'div' )
+ ) . Html::closeElement( 'form' )
);
+
+ if ( $clientUrl ) {
+ $this->showImportForm( $clientUrl );
+ }
+
+ $out->addHTML( Html::closeElement( 'div' ) );
}
- /**
- * @param string[] $parsedUrl return of wfParseUrl
- */
- private function showImportPage( array $parsedUrl ) {
+ private function showImportForm( $clientUrl ) {
$this->getOutput()->addHTML(
- Html::element(
- 'p',
- [],
- ( new Message(
'fileimporter-importfilefromprefix' ) )->plain()
- ) . ': ' . implode( '|', $parsedUrl )
+ Html::openElement(
+ 'form',
+ [
+ 'action' =>
$this->getPageTitle()->getLocalURL(),
+ 'method' => 'POST',
+ ]
+ ) . Html::element(
+ 'input',
+ [
+ 'type' => 'hidden',
+ 'name' => 'clientUrl',
+ 'value' => $clientUrl,
+ ]
+ ). new ButtonInputWidget(
+ [
+ 'classes' => [ 'mw-movtocom-url-import'
],
+ 'label' => ( new Message(
'fileimporter-import' ) )->plain(),
+ 'type' => 'submit',
+ 'flags' => [ 'primary', 'progressive' ],
+ ]
+ ) . Html::closeElement( 'form' )
);
}
--
To view, visit https://gerrit.wikimedia.org/r/337183
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I71b7e7a3b6c09519d51789065d29a770a94e0338
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/FileImporter
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits