r95285 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95284‎ | r95285 | r95286 >
Date:23:54, 22 August 2011
Author:neilk
Status:ok
Tags:
Comment:
reverting hacks to get UploadWizard deploy to work (r95273, r95267, r95266)
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/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js (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)
  • /branches/wmf/1.17wmf1/resources/Resources.php (modified) (history)
  • /branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.uri.js (deleted) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/UploadWizard/UploadWizardHooks.php
@@ -26,6 +26,7 @@
2727 'mediawiki.language',
2828 'mediawiki.Uri',
2929 'mediawiki.util',
 30+ 'mediawiki.libs.jpegmeta',
3031 'ext.uploadwizard.mediawiki.language.parser',
3132 ),
3233 'scripts' => array(
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/includes/specials/SpecialUploadCampaign.php
@@ -129,8 +129,7 @@
130130 }
131131
132132 public function onSuccess() {
133 - global $wgOut;
134 - $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() );
 133+ $this->getOutput()->redirect( SpecialPage::getTitleFor( 'UploadCampaigns' )->getLocalURL() );
135134 }
136135
137136 }
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, $wgOut;
 44+ global $wgRequest, $wgUser;
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 - $wgOut->redirect( SpecialPage::getTitleFor( 'UploadCampaign', $wgRequest->getVal( 'newcampaign' ) )->getLocalURL() );
 55+ $this->getOutput()->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 - $wgOut->redirect( $this->getTitle()->getLocalURL() );
 60+ $this->getOutput()->redirect( $this->getTitle()->getLocalURL() );
6161 }
6262 else {
6363 $this->displayUploadCamaigns();
@@ -96,8 +96,7 @@
9797 * @since 1.2
9898 */
9999 protected function displayAddNewControl() {
100 - global $wgOut;
101 - $out = $wgOut; // $out = $wgOut;
 100+ $out = $this->getOutput();
102101
103102 $out->addHTML( Html::openElement(
104103 'form',
@@ -137,8 +136,7 @@
138137 * @param ResultWrapper $campaigns
139138 */
140139 protected function displayCampaignTable( ResultWrapper $campaigns ) {
141 - global $wgOut;
142 - $out = $wgOut;
 140+ $out = $this->getOutput();
143141
144142 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'mwe-upwiz-campaigns-existing' ) ) );
145143
Index: branches/wmf/1.17wmf1/extensions/UploadWizard/resources/jquery/jquery.mwCoolCats.js
@@ -24,14 +24,21 @@
2525 };
2626
2727 var confirmIt = function() {
28 - var buttons = {};
29 - buttons[ gM( 'mw-coolcats-confirm-new-cancel' ) ] = function() {
30 - $( this ).dialog( "close" );
31 - };
32 - buttons[ gM( 'mw-coolcats-confirm-new-ok' ) ] = function() {
33 - insertIt();
34 - $( this ).dialog( "close" );
35 - };
 28+ var buttons = [
 29+ {
 30+ text: gM( 'mw-coolcats-confirm-new-cancel' ),
 31+ click: function() {
 32+ $( this ).dialog( "close" );
 33+ }
 34+ },
 35+ {
 36+ text: gM( 'mw-coolcats-confirm-new-ok' ),
 37+ click: function() {
 38+ insertIt();
 39+ $( this ).dialog( "close" );
 40+ }
 41+ }
 42+ ];
3643 $j( '<div></div>' )
3744 .msg( 'mw-coolcats-confirm-new', title.getMainText() )
3845 .dialog( {
Index: branches/wmf/1.17wmf1/includes/HTMLForm.php
@@ -369,16 +369,10 @@
370370 * @return String wrapped HTML.
371371 */
372372 function wrapForm( $html ) {
373 - global $wgUserLanguage;
374373
375374 # Include a <fieldset> wrapper for style, if requested.
376375 if ( $this->mWrapperLegend !== false ) {
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 );
 376+ $html = Xml::fieldset( $this->mWrapperLegend, $html );
383377 }
384378 # Use multipart/form-data
385379 $encType = $this->mUseMultipart
Index: branches/wmf/1.17wmf1/includes/Message.php
@@ -357,4 +357,4 @@
358358 return $this->message;
359359 }
360360
361 -}
 361+}
\ No newline at end of file
Index: branches/wmf/1.17wmf1/includes/SpecialPage.php
@@ -937,148 +937,7 @@
938938 }
939939 }
940940
941 -
942941 /**
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 -/**
1083942 * Shortcut to construct a special page which is unlisted by default
1084943 * @ingroup SpecialPage
1085944 */
Index: branches/wmf/1.17wmf1/resources/Resources.php
@@ -342,9 +342,6 @@
343343 'dependencies' => array( 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.placeholder' ),
344344 'debugScripts' => 'resources/mediawiki.util/mediawiki.util.test.js',
345345 ),
346 - 'mediawiki.Uri' => array(
347 - 'scripts' => 'resources/mediawiki/mediawiki.uri.js',
348 - ),
349346 'mediawiki.action.history' => array(
350347 'scripts' => 'resources/mediawiki.action/mediawiki.action.history.js',
351348 'dependencies' => 'mediawiki.legacy.history',
Index: branches/wmf/1.17wmf1/resources/mediawiki/mediawiki.uri.js
@@ -1,260 +0,0 @@
2 -/**
3 - * Library for simple URI parsing and manipulation. Requires jQuery.
4 - *
5 - * Do not expect full RFC 3986 compliance. Intended to be minimal, but featureful.
6 - * The use cases we have in mind are constructing 'next page' or 'previous page' URLs,
7 - * detecting whether we need to use cross-domain proxies for an API, constructing
8 - * simple URL-based API calls, etc.
9 - *
10 - * Intended to compress very well if you use a JS-parsing minifier.
11 - *
12 - * Dependencies: mw, jQuery
13 - *
14 - * Example:
15 - *
16 - * var uri = new mw.Uri( 'http://foo.com/mysite/mypage.php?quux=2' );
17 - *
18 - * if ( uri.host == 'foo.com' ) {
19 - * uri.host = 'www.foo.com';
20 - * uri.extend( { bar: 1 } );
21 - *
22 - * $( 'a#id1' ).attr( 'href', uri );
23 - * // anchor with id 'id1' now links to http://foo.com/mysite/mypage.php?bar=1&quux=2
24 - *
25 - * $( 'a#id2' ).attr( 'href', uri.clone().extend( { bar: 3, pif: 'paf' } ) );
26 - * // anchor with id 'id2' now links to http://foo.com/mysite/mypage.php?bar=3&quux=2&pif=paf
27 - * }
28 - *
29 - * Parsing here is regex based, so may not work on all URIs, but is good enough for most.
30 - *
31 - * Given a URI like
32 - * 'http://usr:pwd@www.test.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=&test3=value+%28escaped%29&r=1&r=2#top':
33 - * The returned object will have the following properties:
34 - *
35 - * protocol 'http'
36 - * user 'usr'
37 - * password 'pwd'
38 - * host 'www.test.com'
39 - * port '81'
40 - * path '/dir/dir.2/index.htm'
41 - * query {
42 - * q1: 0,
43 - * test1: null,
44 - * test2: '',
45 - * test3: 'value (escaped)'
46 - * r: [1, 2]
47 - * }
48 - * fragment 'top'
49 - *
50 - * n.b. 'password' is not technically allowed for HTTP URIs, but it is possible with other
51 - * sorts of URIs.
52 - * You can modify the properties directly. Then use the toString() method to extract the
53 - * full URI string again.
54 - *
55 - * Parsing based on parseUri 1.2.2 (c) Steven Levithan <stevenlevithan.com> MIT License
56 - * http://stevenlevithan.com/demo/parseuri/js/
57 - *
58 - */
59 -
60 -( function( $ ) {
61 -
62 - /**
63 - * Function that's useful when constructing the URI string -- we frequently encounter the pattern of
64 - * having to add something to the URI as we go, but only if it's present, and to include a character before or after if so.
65 - * @param {String} to prepend, if value not empty
66 - * @param {String} value to include, if not empty
67 - * @param {String} to append, if value not empty
68 - * @param {Boolean} raw -- if true, do not URI encode
69 - * @return {String}
70 - */
71 - function cat( pre, val, post, raw ) {
72 - if ( val === undefined || val === null || val === '' ) {
73 - return '';
74 - } else {
75 - return pre + ( raw ? val : mw.Uri.encode( val ) ) + post;
76 - }
77 - }
78 -
79 - // Regular expressions to parse many common URIs.
80 - var parser = {
81 - strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
82 - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/
83 - },
84 -
85 - // The order here matches the order of captured matches in the above parser regexes.
86 - properties = [
87 - 'protocol', // http
88 - 'user', // usr
89 - 'password', // pwd
90 - 'host', // www.test.com
91 - 'port', // 81
92 - 'path', // /dir/dir.2/index.htm
93 - 'query', // q1=0&&test1&test2=value (will become { q1: 0, test1: '', test2: 'value' } )
94 - 'fragment' // top
95 - ];
96 -
97 - /**
98 - * Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse.
99 - * @constructor
100 - * @param {!Object|String} URI string, or an Object with appropriate properties (especially another URI object to clone). Object must have non-blank 'protocol', 'host', and 'path' properties.
101 - * @param {Boolean} strict mode (when parsing a string)
102 - */
103 - mw.Uri = function( uri, strictMode ) {
104 - strictMode = !!strictMode;
105 - if ( uri !== undefined && uri !== null || uri !== '' ) {
106 - if ( typeof uri === 'string' ) {
107 - this._parse( uri, strictMode );
108 - } else if ( typeof uri === 'object' ) {
109 - var _this = this;
110 - $.each( properties, function( i, property ) {
111 - _this[property] = uri[property];
112 - } );
113 - if ( this.query === undefined ) {
114 - this.query = {};
115 - }
116 - }
117 - }
118 - if ( !( this.protocol && this.host && this.path ) ) {
119 - throw new Error( 'Bad constructor arguments' );
120 - }
121 - };
122 -
123 - /**
124 - * Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more compliant with RFC 3986
125 - * Similar to rawurlencode from PHP and our JS library mw.util.rawurlencode, but we also replace space with a +
126 - * @param {String} string
127 - * @return {String} encoded for URI
128 - */
129 - mw.Uri.encode = function( s ) {
130 - return encodeURIComponent( s )
131 - .replace( /!/g, '%21').replace( /'/g, '%27').replace( /\(/g, '%28')
132 - .replace( /\)/g, '%29').replace( /\*/g, '%2A')
133 - .replace( /%20/g, '+' );
134 - };
135 -
136 - /**
137 - * Standard decodeURIComponent, with '+' to space
138 - * @param {String} string encoded for URI
139 - * @return {String} decoded string
140 - */
141 - mw.Uri.decode = function( s ) {
142 - return decodeURIComponent( s ).replace( /\+/g, ' ' );
143 - };
144 -
145 - mw.Uri.prototype = {
146 -
147 - /**
148 - * Parse a string and set our properties accordingly.
149 - * @param {String} URI
150 - * @param {Boolean} strictness
151 - * @return {Boolean} success
152 - */
153 - _parse: function( str, strictMode ) {
154 - var matches = parser[ strictMode ? 'strict' : 'loose' ].exec( str );
155 - var uri = this;
156 - $.each( properties, function( i, property ) {
157 - uri[ property ] = matches[ i+1 ];
158 - } );
159 -
160 - // uri.query starts out as the query string; we will parse it into key-val pairs then make
161 - // that object the "query" property.
162 - // we overwrite query in uri way to make cloning easier, it can use the same list of properties.
163 - var q = {};
164 - // using replace to iterate over a string
165 - if ( uri.query ) {
166 - uri.query.replace( /(?:^|&)([^&=]*)(?:(=)([^&]*))?/g, function ($0, $1, $2, $3) {
167 - if ( $1 ) {
168 - var k = mw.Uri.decode( $1 );
169 - var v = ( $2 === '' || $2 === undefined ) ? null : mw.Uri.decode( $3 );
170 - if ( typeof q[ k ] === 'string' ) {
171 - q[ k ] = [ q[ k ] ];
172 - }
173 - if ( typeof q[ k ] === 'object' ) {
174 - q[ k ].push( v );
175 - } else {
176 - q[ k ] = v;
177 - }
178 - }
179 - } );
180 - }
181 - this.query = q;
182 - },
183 -
184 - /**
185 - * Returns user and password portion of a URI.
186 - * @return {String}
187 - */
188 - getUserInfo: function() {
189 - return cat( '', this.user, cat( ':', this.password, '' ) );
190 - },
191 -
192 - /**
193 - * Gets host and port portion of a URI.
194 - * @return {String}
195 - */
196 - getHostPort: function() {
197 - return this.host + cat( ':', this.port, '' );
198 - },
199 -
200 - /**
201 - * Returns the userInfo and host and port portion of the URI.
202 - * In most real-world URLs, this is simply the hostname, but it is more general.
203 - * @return {String}
204 - */
205 - getAuthority: function() {
206 - return cat( '', this.getUserInfo(), '@' ) + this.getHostPort();
207 - },
208 -
209 - /**
210 - * Returns the query arguments of the URL, encoded into a string
211 - * Does not preserve the order of arguments passed into the URI. Does handle escaping.
212 - * @return {String}
213 - */
214 - getQueryString: function() {
215 - var args = [];
216 - $.each( this.query, function( key, val ) {
217 - var k = mw.Uri.encode( key );
218 - var vals = val === null ? [ null ] : $.makeArray( val );
219 - $.each( vals, function( i, v ) {
220 - args.push( k + ( v === null ? '' : '=' + mw.Uri.encode( v ) ) );
221 - } );
222 - } );
223 - return args.join( '&' );
224 - },
225 -
226 - /**
227 - * Returns everything after the authority section of the URI
228 - * @return {String}
229 - */
230 - getRelativePath: function() {
231 - return this.path + cat( '?', this.getQueryString(), '', true ) + cat( '#', this.fragment, '' );
232 - },
233 -
234 - /**
235 - * Gets the entire URI string. May not be precisely the same as input due to order of query arguments.
236 - * @return {String} the URI string
237 - */
238 - toString: function() {
239 - return this.protocol + '://' + this.getAuthority() + this.getRelativePath();
240 - },
241 -
242 - /**
243 - * Clone this URI
244 - * @return {Object} new URI object with same properties
245 - */
246 - clone: function() {
247 - return new mw.Uri( this );
248 - },
249 -
250 - /**
251 - * Extend the query -- supply query parameters to override or add to ours
252 - * @param {Object} query parameters in key-val form to override or add
253 - * @return {Object} this URI object
254 - */
255 - extend: function( parameters ) {
256 - $.extend( this.query, parameters );
257 - return this;
258 - }
259 - };
260 -
261 -} )( jQuery );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95266mediawiki.uri.js (needed for uploadwizard)neilk22:29, 22 August 2011
r95267uploadwizard with various fixes to make Special:UploadCampaign(s) workneilk22:30, 22 August 2011
r95273fixing buttons to work with old jquery uineilk23:11, 22 August 2011

Status & tagging log