r95267 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95266‎ | r95267 | r95268 >
Date:22:30, 22 August 2011
Author:neilk
Status:reverted
Tags:
Comment:
uploadwizard with various fixes to make Special:UploadCampaign(s) work
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/HTMLForm.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/Message.php (modified) (history)
  • /branches/wmf/1.17wmf1/includes/SpecialPage.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizardHooks.php
@@ -26,7 +26,6 @@
2727 'mediawiki.language',
2828 'mediawiki.Uri',
2929 'mediawiki.util',
30 - 'mediawiki.libs.jpegmeta',
3130 'ext.uploadwizard.mediawiki.language.parser',
3231 ),
3332 'scripts' => array(
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php
@@ -129,7 +129,8 @@
130130 }
131131
132132 public function onSuccess() {
133 - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() );
 133+ global $wgOut;
 134+ $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() );
134135 }
135136
136137 }
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php
@@ -40,7 +40,7 @@
4141 * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo.
4242 */
4343 public function execute( $subPage ) {
44 - global $wgRequest, $wgUser;
 44+ global $wgRequest, $wgUser, $wgOut;
4545
4646 $this->setHeaders();
4747 $this->outputHeader();
@@ -51,12 +51,12 @@
5252 if ( $wgRequest->wasPosted()
5353 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) )
5454 && $wgRequest->getCheck( 'newcampaign' ) ) {
55 - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() );
 55+ $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() );
5656 }
5757 elseif ( count( $subPage ) == 2 && $subPage[0] == 'del' ) {
5858 $campaign = UploadWizardCampaign::newFromName( $subPage[1], false );
5959 $campaign->deleteFromDB();
60 - $this->getOutput()->redirect( $this->getTitle()->getLocalURL() );
 60+ $wgOut->redirect( $this->getTitle()->getLocalURL() );
6161 }
6262 else {
6363 $this->displayUploadCamaigns();
@@ -96,7 +96,8 @@
9797 * @since 1.2
9898 */
9999 protected function displayAddNewControl() {
100 - $out = $this->getOutput();
 100+ global $wgOut;
 101+ $out = $wgOut; // $out = $wgOut;
101102
102103 $out->addHTML( Html::openElement(
103104 'form',
@@ -136,7 +137,8 @@
137138 * @param ResultWrapper $campaigns
138139 */
139140 protected function displayCampaignTable( ResultWrapper $campaigns ) {
140 - $out = $this->getOutput();
 141+ global $wgOut;
 142+ $out = $wgOut;
141143
142144 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) );
143145
Index: branches/wmf/1.17wmf1/includes/HTMLForm.php
@@ -369,10 +369,16 @@
370370 * @return String wrapped HTML.
371371 */
372372 function wrapForm( $html ) {
 373+ global $wgUserLanguage;
373374
374375 # Include a <fieldset> wrapper for style, if requested.
375376 if ( $this->mWrapperLegend !== false ) {
376 - $html = Xml::fieldset( $this->mWrapperLegend, $html );
 377+ if ( is_a( $this->mWrapperLegend, 'Message' ) ) {
 378+ $legend = $this->mWrapperLegend->toString();
 379+ } else {
 380+ $legend = $this->mWrapperLegend;
 381+ }
 382+ $html = Xml::fieldset( $legend, $html );
377383 }
378384 # Use multipart/form-data
379385 $encType = $this->mUseMultipart
Index: branches/wmf/1.17wmf1/includes/Message.php
@@ -357,4 +357,4 @@
358358 return $this->message;
359359 }
360360
361 -}
\ No newline at end of file
 361+}
Index: branches/wmf/1.17wmf1/includes/SpecialPage.php
@@ -937,7 +937,148 @@
938938 }
939939 }
940940
 941+
941942 /**
 943+ * Special page which uses an HTMLForm to handle processing. This is mostly a
 944+ * clone of FormAction. More special pages should be built this way; maybe this could be
 945+ * a new structure for SpecialPages
 946+ */
 947+abstract class FormSpecialPage extends SpecialPage {
 948+
 949+ /**
 950+ * Get an HTMLForm descriptor array
 951+ * @return Array
 952+ */
 953+ protected abstract function getFormFields();
 954+
 955+ /**
 956+ * Add pre- or post-text to the form
 957+ * @return String HTML which will be sent to $form->addPreText()
 958+ */
 959+ protected function preText() { return ''; }
 960+ protected function postText() { return ''; }
 961+
 962+ /**
 963+ * Play with the HTMLForm if you need to more substantially
 964+ * @param $form HTMLForm
 965+ */
 966+ protected function alterForm( HTMLForm $form ) {}
 967+
 968+ /**
 969+ * Get the HTMLForm to control behaviour
 970+ * @return HTMLForm|null
 971+ */
 972+ protected function getForm() {
 973+ global $wgRequest;
 974+ $this->fields = $this->getFormFields();
 975+
 976+ $form = new HTMLForm( $this->fields );
 977+ $form->setTitle( $this->getTitle() );
 978+
 979+ $form->setSubmitCallback( array( $this, 'onSubmit' ) );
 980+ $form->setWrapperLegend( wfMessage( strtolower( $this->getName() ) . '-legend' ) );
 981+ $form->addHeaderText(
 982+ wfMessage( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
 983+
 984+ // Retain query parameters (uselang etc)
 985+ $params = array_diff_key( $_GET, array( 'title' => null ) );
 986+ $form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
 987+
 988+ $form->addPreText( $this->preText() );
 989+ $form->addPostText( $this->postText() );
 990+ $this->alterForm( $form );
 991+
 992+ // Give hooks a chance to alter the form, adding extra fields or text etc
 993+ wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) );
 994+
 995+ return $form;
 996+ }
 997+
 998+ /**
 999+ * Process the form on POST submission.
 1000+ * @param $data Array
 1001+ * @return Bool|Array true for success, false for didn't-try, array of errors on failure
 1002+ */
 1003+ public abstract function onSubmit( array $data );
 1004+
 1005+ /**
 1006+ * Do something exciting on successful processing of the form, most likely to show a
 1007+ * confirmation message
 1008+ */
 1009+ public abstract function onSuccess();
 1010+
 1011+ /**
 1012+ * Basic SpecialPage workflow: get a form, send it to the user; get some data back,
 1013+ *
 1014+ * @param $par String Subpage string if one was specified
 1015+ */
 1016+ public function execute( $par ) {
 1017+ global $wgUser;
 1018+ $this->setParameter( $par );
 1019+ $this->setHeaders();
 1020+
 1021+ // This will throw exceptions if there's a problem
 1022+ $this->userCanExecute( $wgUser );
 1023+
 1024+ $form = $this->getForm();
 1025+ if ( $form->show() ) {
 1026+ $this->onSuccess();
 1027+ }
 1028+ }
 1029+
 1030+ /**
 1031+ * Maybe do something interesting with the subpage parameter
 1032+ * @param $par String
 1033+ */
 1034+ protected function setParameter( $par ){}
 1035+
 1036+ /**
 1037+ * Checks if the given user (identified by an object) can perform this action. Can be
 1038+ * overridden by sub-classes with more complicated permissions schemes. Failures here
 1039+ * must throw subclasses of ErrorPageError
 1040+ *
 1041+ * @param $user User: the user to check, or null to use the context user
 1042+ * @return Bool true
 1043+ * @throws ErrorPageError
 1044+ */
 1045+ public function userCanExecute( $user ) {
 1046+ if ( $this->requiresWrite() && wfReadOnly() ) {
 1047+ throw new ReadOnlyError();
 1048+ }
 1049+
 1050+ if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
 1051+ throw new PermissionsError( $this->getRestriction() );
 1052+ }
 1053+
 1054+ if ( $this->requiresUnblock() && $user->isBlocked() ) {
 1055+ $block = $user->mBlock;
 1056+ throw new UserBlockedError( $block );
 1057+ }
 1058+
 1059+ return true;
 1060+ }
 1061+
 1062+ /**
 1063+ * Whether this action requires the wiki not to be locked
 1064+ * @return Bool
 1065+ */
 1066+ public function requiresWrite() {
 1067+ return true;
 1068+ }
 1069+
 1070+ /**
 1071+ * Whether this action cannot be executed by a blocked user
 1072+ * @return Bool
 1073+ */
 1074+ public function requiresUnblock() {
 1075+ return true;
 1076+ }
 1077+}
 1078+
 1079+
 1080+
 1081+
 1082+/**
9421083 * Shortcut to construct a special page which is unlisted by default
9431084 * @ingroup SpecialPage
9441085 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r95285reverting hacks to get UploadWizard deploy to work (r95273, r95267, r95266)neilk23:54, 22 August 2011

Status & tagging log