Index: branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -26,7 +26,6 @@ |
27 | 27 | 'mediawiki.language', |
28 | 28 | 'mediawiki.Uri', |
29 | 29 | 'mediawiki.util', |
30 | | - 'mediawiki.libs.jpegmeta', |
31 | 30 | 'ext.uploadwizard.mediawiki.language.parser', |
32 | 31 | ), |
33 | 32 | 'scripts' => array( |
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php |
— | — | @@ -129,7 +129,8 @@ |
130 | 130 | } |
131 | 131 | |
132 | 132 | public function onSuccess() { |
133 | | - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() ); |
| 133 | + global $wgOut; |
| 134 | + $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() ); |
134 | 135 | } |
135 | 136 | |
136 | 137 | } |
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaigns.php |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | * @param string $subPage, e.g. the "foo" in Special:UploadCampaigns/foo. |
42 | 42 | */ |
43 | 43 | public function execute( $subPage ) { |
44 | | - global $wgRequest, $wgUser; |
| 44 | + global $wgRequest, $wgUser, $wgOut; |
45 | 45 | |
46 | 46 | $this->setHeaders(); |
47 | 47 | $this->outputHeader(); |
— | — | @@ -51,12 +51,12 @@ |
52 | 52 | if ( $wgRequest->wasPosted() |
53 | 53 | && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) |
54 | 54 | && $wgRequest->getCheck( 'newcampaign' ) ) { |
55 | | - $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() ); |
| 55 | + $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() ); |
56 | 56 | } |
57 | 57 | elseif ( count( $subPage ) == 2 && $subPage[0] == 'del' ) { |
58 | 58 | $campaign = UploadWizardCampaign::newFromName( $subPage[1], false ); |
59 | 59 | $campaign->deleteFromDB(); |
60 | | - $this->getOutput()->redirect( $this->getTitle()->getLocalURL() ); |
| 60 | + $wgOut->redirect( $this->getTitle()->getLocalURL() ); |
61 | 61 | } |
62 | 62 | else { |
63 | 63 | $this->displayUploadCamaigns(); |
— | — | @@ -96,7 +96,8 @@ |
97 | 97 | * @since 1.2 |
98 | 98 | */ |
99 | 99 | protected function displayAddNewControl() { |
100 | | - $out = $this->getOutput(); |
| 100 | + global $wgOut; |
| 101 | + $out = $wgOut; // $out = $wgOut; |
101 | 102 | |
102 | 103 | $out->addHTML( Html::openElement( |
103 | 104 | 'form', |
— | — | @@ -136,7 +137,8 @@ |
137 | 138 | * @param ResultWrapper $campaigns |
138 | 139 | */ |
139 | 140 | protected function displayCampaignTable( ResultWrapper $campaigns ) { |
140 | | - $out = $this->getOutput(); |
| 141 | + global $wgOut; |
| 142 | + $out = $wgOut; |
141 | 143 | |
142 | 144 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) ); |
143 | 145 | |
Index: branches/wmf/1.17wmf1/includes/HTMLForm.php |
— | — | @@ -369,10 +369,16 @@ |
370 | 370 | * @return String wrapped HTML. |
371 | 371 | */ |
372 | 372 | function wrapForm( $html ) { |
| 373 | + global $wgUserLanguage; |
373 | 374 | |
374 | 375 | # Include a <fieldset> wrapper for style, if requested. |
375 | 376 | 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 ); |
377 | 383 | } |
378 | 384 | # Use multipart/form-data |
379 | 385 | $encType = $this->mUseMultipart |
Index: branches/wmf/1.17wmf1/includes/Message.php |
— | — | @@ -357,4 +357,4 @@ |
358 | 358 | return $this->message; |
359 | 359 | } |
360 | 360 | |
361 | | -} |
\ No newline at end of file |
| 361 | +} |
Index: branches/wmf/1.17wmf1/includes/SpecialPage.php |
— | — | @@ -937,7 +937,148 @@ |
938 | 938 | } |
939 | 939 | } |
940 | 940 | |
| 941 | + |
941 | 942 | /** |
| 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 | +/** |
942 | 1083 | * Shortcut to construct a special page which is unlisted by default |
943 | 1084 | * @ingroup SpecialPage |
944 | 1085 | */ |