r24237 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24236‎ | r24237 | r24238 >
Date:11:10, 18 July 2007
Author:raymond
Status:old
Tags:
Comment:
* (bug 6808) Allow import to different page name
* (bug 6436) Localization of Special:Import XML parser Error message(s).
Reworking error message handling as the former behaviour showed success though import failed
Proper XML functions for input forms
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/WikiError.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesDe.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1441,6 +1441,11 @@
14421442 'importnosources',
14431443 'importnofile',
14441444 'importuploaderror',
 1445+ 'import-parse-failure',
 1446+ 'import-articlename',
 1447+ 'import-noarticle',
 1448+ 'import-nonewrevisions',
 1449+ 'xml-error-string',
14451450 ),
14461451 'importlog' => array(
14471452 'importlogpage',
Index: trunk/phase3/includes/SpecialImport.php
@@ -30,12 +30,14 @@
3131 global $wgImportTargetNamespace;
3232
3333 $interwiki = false;
 34+ $articleName = '';
3435 $namespace = $wgImportTargetNamespace;
3536 $frompage = '';
3637 $history = true;
3738
3839 if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') {
3940 $isUpload = false;
 41+ $articleName = htmlspecialchars( $wgRequest->getText( 'articlename' ) );
4042 $namespace = $wgRequest->getIntOrNull( 'namespace' );
4143
4244 switch( $wgRequest->getVal( "source" ) ) {
@@ -61,7 +63,7 @@
6264 }
6365
6466 if( WikiError::isError( $source ) ) {
65 - $wgOut->addWikiText( wfEscapeWikiText( $source->getMessage() ) );
 67+ $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $source->getMessage() ) ) . '</p>' );
6668 } else {
6769 $wgOut->addWikiText( wfMsg( "importstart" ) );
6870
@@ -69,19 +71,26 @@
7072 if( !is_null( $namespace ) ) {
7173 $importer->setTargetNamespace( $namespace );
7274 }
 75+ if( !is_null( $articleName ) ) {
 76+ $importer->setTargetArticleName( $articleName );
 77+ }
7378 $reporter = new ImportReporter( $importer, $isUpload, $interwiki );
7479
7580 $reporter->open();
7681 $result = $importer->doImport();
77 - $reporter->close();
 82+ $resultCount = $reporter->close();
7883
7984 if( WikiError::isError( $result ) ) {
80 - $wgOut->addWikiText( wfMsg( "importfailed",
81 - wfEscapeWikiText( $result->getMessage() ) ) );
 85+ # No source or XML parse error
 86+ $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $result->getMessage() ) ) . '</p>' );
 87+ } elseif( WikiError::isError( $resultCount ) ) {
 88+ # Zero revisions
 89+ $wgOut->addWikiText( '<p class="error">' . wfMsg( "importfailed", wfEscapeWikiText( $resultCount->getMessage() ) ) . '</p>' );
8290 } else {
8391 # Success!
8492 $wgOut->addWikiText( wfMsg( "importsuccess" ) );
8593 }
 94+ $wgOut->addWikiText( '<hr />' );
8695 }
8796 }
8897
@@ -89,18 +98,17 @@
9099
91100 if( $wgUser->isAllowed( 'importupload' ) ) {
92101 $wgOut->addWikiText( wfMsg( "importtext" ) );
93 - $wgOut->addHTML( "
94 -<fieldset>
95 - <legend>" . wfMsgHtml('upload') . "</legend>
96 - <form enctype='multipart/form-data' method='post' action=\"$action\">
97 - <input type='hidden' name='action' value='submit' />
98 - <input type='hidden' name='source' value='upload' />
99 - <input type='hidden' name='MAX_FILE_SIZE' value='2000000' />
100 - <input type='file' name='xmlimport' value='' size='30' />
101 - <input type='submit' value=\"" . wfMsgHtml( "uploadbtn" ) . "\" />
102 - </form>
103 -</fieldset>
104 -" );
 102+ $wgOut->addHTML(
 103+ Xml::openElement( 'fieldset' ).
 104+ Xml::element( 'legend', null, wfMsg( 'upload' ) ) .
 105+ Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
 106+ Xml::hidden( 'action', 'submit' ) .
 107+ Xml::hidden( 'source', 'upload' ) .
 108+ Xml::hidden( 'MAX_FILE_SIZE', '2000000' ) .
 109+ "<input type='file' name='xmlimport' value='' size='30' />" . // No Xml function for type=file? Todo?
 110+ Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
 111+ Xml::closeElement( 'form' ) .
 112+ Xml::closeElement( 'fieldset' ) );
105113 } else {
106114 if( empty( $wgImportSources ) ) {
107115 $wgOut->addWikiText( wfMsg( 'importnosources' ) );
@@ -108,53 +116,57 @@
109117 }
110118
111119 if( !empty( $wgImportSources ) ) {
112 - $wgOut->addHTML( "
113 -<fieldset>
114 - <legend>" . wfMsgHtml('importinterwiki') . "</legend>
115 - <form method='post' action=\"$action\">" .
116 - $wgOut->parse( wfMsg( 'import-interwiki-text' ) ) . "
117 - <input type='hidden' name='action' value='submit' />
118 - <input type='hidden' name='source' value='interwiki' />
119 - <table>
120 - <tr>
121 - <td>
122 - <select name='interwiki'>" );
 120+ $wgOut->addHTML(
 121+ Xml::openElement( 'fieldset' ) .
 122+ Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
 123+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
 124+ wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
 125+ Xml::hidden( 'action', 'submit' ) .
 126+ Xml::hidden( 'source', 'interwiki' ) .
 127+ Xml::openElement( 'table' ) .
 128+ "<tr>
 129+ <td>" .
 130+ Xml::openElement( 'select', array( 'name' => 'interwiki' ) ) );
123131 foreach( $wgImportSources as $prefix ) {
124132 $iw = htmlspecialchars( $prefix );
125133 $selected = ($interwiki === $prefix) ? ' selected="selected"' : '';
126 - $wgOut->addHTML( "<option value=\"$iw\"$selected>$iw</option>\n" );
 134+ $wgOut->addHTML( Xml::option( $iw, $iw, $selected ) );
127135 }
128 - $wgOut->addHTML( "
129 - </select>
130 - </td>
 136+ $wgOut->addHTML(
 137+ Xml::closeElement( 'select' ) .
 138+ "</td>
131139 <td>" .
132 - wfInput( 'frompage', 50, $frompage ) .
 140+ Xml::input( 'frompage', 50, $frompage ) .
133141 "</td>
134142 </tr>
135143 <tr>
136144 <td></td>
137145 <td>" .
138 - wfCheckLabel( wfMsg( 'import-interwiki-history' ),
139 - 'interwikiHistory', 'interwikiHistory', $history ) .
 146+ Xml::checkLabel( wfMsg( 'import-interwiki-history' ), 'interwikiHistory', 'interwikiHistory', $history ) .
140147 "</td>
141148 </tr>
142149 <tr>
143150 <td></td>
144 - <td>
145 - " . wfMsgHtml( 'import-interwiki-namespace' ) . " " .
146 - HTMLnamespaceselector( $namespace, '' ) . "
147 - </td>
 151+ <td>" .
 152+ Xml::inputLabel( wfMsg( 'import-articlename' ), 'articlename', 'articlename', 50, $articleName ) .
 153+ "</td>
148154 </tr>
149155 <tr>
150156 <td></td>
151157 <td>" .
152 - wfSubmitButton( wfMsg( 'import-interwiki-submit' ) ) .
 158+ Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
 159+ Xml::namespaceSelector( $namespace, '' ) .
153160 "</td>
154161 </tr>
155 - </table>
156 - </form>
157 -</fieldset>
158 -" );
 162+ <tr>
 163+ <td></td>
 164+ <td>" .
 165+ Xml::submitButton( wfMsg( 'import-interwiki-submit' ) ) .
 166+ "</td>
 167+ </tr>" .
 168+ Xml::closeElement( 'table' ).
 169+ Xml::closeElement( 'form' ) .
 170+ Xml::closeElement( 'fieldset' ) );
159171 }
160172 }
161173
@@ -185,12 +197,12 @@
186198 $localCount = $wgLang->formatNum( $successCount );
187199 $contentCount = $wgContLang->formatNum( $successCount );
188200
189 - $wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
190 - " " .
191 - wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
192 - "</li>\n" );
 201+ if( $successCount > 0 ) {
 202+ $wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
 203+ " " .
 204+ wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
 205+ "</li>\n" );
193206
194 - if( $successCount > 0 ) {
195207 $log = new LogPage( 'import' );
196208 if( $this->mIsUpload ) {
197209 $detail = wfMsgForContent( 'import-logentry-upload-detail',
@@ -209,15 +221,21 @@
210222 $nullRevision = Revision::newNullRevision(
211223 $dbw, $title->getArticleId(), $comment, true );
212224 $nullRevision->insertOn( $dbw );
 225+ } else {
 226+ $wgOut->addHtml( '<li>' . wfMsgExt( 'import-nonewrevisions', array( 'parse', ) ) . '</li>' );
213227 }
 228+
214229 }
215230
216231 function close() {
217232 global $wgOut;
218233 if( $this->mPageCount == 0 ) {
219 - $wgOut->addHtml( "<li>" . wfMsgHtml( 'importnopages' ) . "</li>\n" );
 234+ $wgOut->addHtml( "</ul>\n" );
 235+ return new WikiErrorMsg( "importnopages" );
220236 }
221237 $wgOut->addHtml( "</ul>\n" );
 238+
 239+ return $this->mPageCount;
222240 }
223241 }
224242
@@ -393,6 +411,7 @@
394412 var $mPageOutCallback = null;
395413 var $mRevisionCallback = null;
396414 var $mTargetNamespace = null;
 415+ var $mTargetArticleName = null;
397416 var $lastfield;
398417
399418 function WikiImporter( $source ) {
@@ -425,7 +444,7 @@
426445 $chunk = $this->mSource->readChunk();
427446 if( !xml_parse( $parser, $chunk, $this->mSource->atEnd() ) ) {
428447 wfDebug( "WikiImporter::doImport encountered XML parsing error\n" );
429 - return new WikiXmlError( $parser, 'XML import parse failure', $chunk, $offset );
 448+ return new WikiXmlError( $parser, wfMsgHtml( 'import-parse-failure' ), $chunk, $offset );
430449 }
431450 $offset += strlen( $chunk );
432451 } while( $chunk !== false && !$this->mSource->atEnd() );
@@ -501,6 +520,13 @@
502521 }
503522
504523 /**
 524+ * Set a target articlename to override the defaults
 525+ */
 526+ function setTargetArticleName( $articleName ) {
 527+ $this->mTargetArticleName = is_null( $articleName ) ? null : $articleName;
 528+ }
 529+
 530+ /**
505531 * Default per-revision callback, performs the import.
506532 * @param WikiRevision $revision
507533 * @private
@@ -677,6 +703,11 @@
678704 switch( $this->appendfield ) {
679705 case "title":
680706 $this->workTitle = $this->appenddata;
 707+
 708+ if( $this->mTargetArticleName != '' ) {
 709+ // Import article with a different target article name
 710+ $this->workTitle = $this->mTargetArticleName;
 711+ }
681712 $this->origTitle = Title::newFromText( $this->workTitle );
682713 if( !is_null( $this->mTargetNamespace ) && !is_null( $this->origTitle ) ) {
683714 $this->pageTitle = Title::makeTitle( $this->mTargetNamespace,
@@ -876,6 +907,9 @@
877908 }
878909
879910 public static function newFromInterwiki( $interwiki, $page, $history=false ) {
 911+ if( $page == '' ) {
 912+ return new WikiErrorMsg( 'import-noarticle' );
 913+ }
880914 $link = Title::newFromText( "$interwiki:Special:Export/$page" );
881915 if( is_null( $link ) || $link->getInterwiki() == '' ) {
882916 return new WikiErrorMsg( 'importbadinterwiki' );
Index: trunk/phase3/includes/WikiError.php
@@ -101,7 +101,7 @@
102102
103103 /** @return string */
104104 function getMessage() {
105 - return sprintf( '%s at line %d, col %d (byte %d%s): %s',
 105+ return sprintf( wfMsgHtml( 'xml-error-string', '%s', '%d', '%d', '%d%s', '%s' ),
106106 $this->mMessage,
107107 $this->mLine,
108108 $this->mColumn,
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2158,11 +2158,16 @@
21592159 'importcantopen' => "Couldn't open import file",
21602160 'importbadinterwiki' => 'Bad interwiki link',
21612161 'importnotext' => 'Empty or no text',
2162 -'importsuccess' => 'Import succeeded!',
 2162+'importsuccess' => 'Import finished!',
21632163 'importhistoryconflict' => 'Conflicting history revision exists (may have imported this page before)',
21642164 'importnosources' => 'No transwiki import sources have been defined and direct history uploads are disabled.',
21652165 'importnofile' => 'No import file was uploaded.',
21662166 'importuploaderror' => 'Upload of import file failed; perhaps the file is bigger than the allowed upload size.',
 2167+'import-parse-failure' => 'XML import parse failure',
 2168+'import-articlename' => 'New article name:',
 2169+'import-noarticle' => 'No article to import!',
 2170+'import-nonewrevisions' => 'All revisions were previously imported.',
 2171+'xml-error-string' => '$1 at line $2, col $3 (byte $4): $5',
21672172
21682173 # Import log
21692174 'importlogpage' => 'Import log',
Index: trunk/phase3/languages/messages/MessagesDe.php
@@ -1726,19 +1726,24 @@
17271727 'import-interwiki-submit' => 'Import',
17281728 'import-interwiki-namespace' => 'Importiere die Seite in den Namensraum:',
17291729 'importtext' => 'Auf dieser Spezialseite können über [[{{ns:special}}:Export]] exportierte Seiten in dieses Wiki importiert werden.',
1730 -'importstart' => 'Importiere Seiten …',
 1730+'importstart' => 'Importiere Seite …',
17311731 'import-revision-count' => '– {{PLURAL:$1|1 Version|$1 Versionen}}',
1732 -'importnopages' => 'Keine Seiten zum Importieren vorhanden.',
 1732+'importnopages' => 'Keine Seite zum Importieren vorhanden.',
17331733 'importfailed' => 'Import fehlgeschlagen: $1',
17341734 'importunknownsource' => 'Unbekannte Importquelle',
17351735 'importcantopen' => 'Importdatei konnte nicht geöffnet werden',
17361736 'importbadinterwiki' => 'Falscher Interwiki-Link',
17371737 'importnotext' => 'Leer oder kein Text',
1738 -'importsuccess' => 'Import erfolgreich!',
 1738+'importsuccess' => 'Import abgeschlossen!',
17391739 'importhistoryconflict' => 'Es existieren bereits ältere Versionen, welche mit diesen kollidieren. Möglicherweise wurde die Seite bereits vorher importiert.',
17401740 'importnosources' => 'Für den Transwiki-Import sind keine Quellen definiert. Das direkte Hochladen von Versionen ist gesperrt.',
17411741 'importnofile' => 'Es ist keine Importdatei ausgewählt worden!',
17421742 'importuploaderror' => 'Das Hochladen der Importdatei ist fehlgeschlagen. Vielleicht ist die Datei größer als erlaubt.',
 1743+'import-parse-failure' => 'Fehler beim XML-Import:',
 1744+'import-articlename' => 'Neuer Artikelname:',
 1745+'import-noarticle' => 'Es wurde kein zu importierender Artikel angegeben!',
 1746+'import-nonewrevisions' => 'Es sind keine neuen Versionen zum Import vorhanden, alle Versionen wurden bereits früher importiert.',
 1747+'xml-error-string' => '$1 Zeile $2, Spalte $3, (Byte $4): $5' ,
17431748
17441749 # Import log
17451750 'importlogpage' => 'Import-Logbuch',
Index: trunk/phase3/RELEASE-NOTES
@@ -152,6 +152,8 @@
153153 inline, as in most browsers
154154 * Pass the user as an argument to 'isValidPassword' hook callbacks; see
155155 docs/hooks.txt for more information
 156+* (bug 6808) Allow import to different page name
 157+* (bug 6436) Localization of Special:Import XML parser Error message(s).
156158
157159 == Bugfixes since 1.10 ==
158160

Follow-up revisions

RevisionCommit summaryAuthorDate
r24250Revert r24237, r24239, r24245 for the moment. We expect transwiki system to c...brion20:05, 18 July 2007
r24276Merged revisions 24213-24275 via svnmerge from...david20:20, 19 July 2007
r30053* (bug 6436) Localization of Special:Import XML parser Error message(s)...raymond14:19, 22 January 2008

Status & tagging log