Index: trunk/extensions/Push/Push.i18n.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | 'push-button-all' => 'Push all', |
46 | 46 | 'push-tab-last-edit' => 'Last edit by $1 on $2 at $3.', |
47 | 47 | 'push-tab-not-created' => 'This page does not exist yet.', |
| 48 | + 'push-tab-push-options' => 'Push options:', |
| 49 | + 'push-tab-inc-templates' => 'Include templates', |
| 50 | + 'push-tab-used-templates' => '(Used templates: $1)', |
| 51 | + 'push-tab-no-used-templates' => '(No templates are used on this page.)', |
48 | 52 | |
49 | 53 | // Special page |
50 | 54 | 'special-push' => 'Push pages', |
Index: trunk/extensions/Push/specials/Push_Body.php |
— | — | @@ -135,7 +135,7 @@ |
136 | 136 | |
137 | 137 | // Look up any linked pages if asked... |
138 | 138 | if( $wgRequest->getCheck( 'templates' ) ) { |
139 | | - $pageSet = $this->getTemplates( array_keys( $pageSet ), $pageSet ); |
| 139 | + $pageSet = PushFunctions::getTemplates( array_keys( $pageSet ), $pageSet ); |
140 | 140 | } |
141 | 141 | |
142 | 142 | $pages = array_keys( $pageSet ); |
— | — | @@ -301,64 +301,8 @@ |
302 | 302 | } |
303 | 303 | return $pages; |
304 | 304 | } |
305 | | - |
306 | | - /** |
307 | | - * Expand a list of pages to include templates used in those pages. |
308 | | - * |
309 | | - * @since 0.2 |
310 | | - * |
311 | | - * @param $inputPages array list of titles to look up |
312 | | - * @param $pageSet array associative array indexed by titles for output |
313 | | - * |
314 | | - * @return array associative array index by titles |
315 | | - */ |
316 | | - private function getTemplates( $inputPages, $pageSet ) { |
317 | | - return $this->getLinks( $inputPages, $pageSet, |
318 | | - 'templatelinks', |
319 | | - array( 'tl_namespace AS namespace', 'tl_title AS title' ), |
320 | | - array( 'page_id=tl_from' ) |
321 | | - ); |
322 | | - } |
323 | 305 | |
324 | 306 | /** |
325 | | - * Expand a list of pages to include items used in those pages. |
326 | | - * |
327 | | - * @since 0.2 |
328 | | - */ |
329 | | - protected function getLinks( $inputPages, $pageSet, $table, $fields, $join ) { |
330 | | - $dbr = wfGetDB( DB_SLAVE ); |
331 | | - |
332 | | - foreach( $inputPages as $page ) { |
333 | | - $title = Title::newFromText( $page ); |
334 | | - |
335 | | - if( $title ) { |
336 | | - $pageSet[$title->getPrefixedText()] = true; |
337 | | - /// @todo Fixme: May or may not be more efficient to batch these |
338 | | - /// by namespace when given multiple input pages. |
339 | | - $result = $dbr->select( |
340 | | - array( 'page', $table ), |
341 | | - $fields, |
342 | | - array_merge( |
343 | | - $join, |
344 | | - array( |
345 | | - 'page_namespace' => $title->getNamespace(), |
346 | | - 'page_title' => $title->getDBkey() |
347 | | - ) |
348 | | - ), |
349 | | - __METHOD__ |
350 | | - ); |
351 | | - |
352 | | - foreach( $result as $row ) { |
353 | | - $template = Title::makeTitle( $row->namespace, $row->title ); |
354 | | - $pageSet[$template->getPrefixedText()] = true; |
355 | | - } |
356 | | - } |
357 | | - } |
358 | | - |
359 | | - return $pageSet; |
360 | | - } |
361 | | - |
362 | | - /** |
363 | 307 | * Loads the needed JavaScript. |
364 | 308 | * Takes care of non-RL compatibility. |
365 | 309 | * |
Index: trunk/extensions/Push/Push_Settings.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | $wgGroupPermissions['sysop']['pushadmin'] = true; |
28 | 28 | |
29 | 29 | $egPushShowTab = false; |
| 30 | +$egPushIncTemplates = false; |
30 | 31 | |
31 | 32 | $egPushBulkWorkers = 3; |
32 | 33 | $egPushBatchSize = 3; |
Index: trunk/extensions/Push/RELEASE-NOTES |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | === Version 0.4 === |
9 | 9 | 2010-12-xx |
10 | 10 | |
11 | | -* |
| 11 | +* Added adittional info about target pages to the tab interface. |
12 | 12 | |
13 | 13 | === Version 0.3 === |
14 | 14 | 2010-12-10 |
Index: trunk/extensions/Push/includes/Push_Tab.php |
— | — | @@ -127,46 +127,14 @@ |
128 | 128 | Html::hidden( 'siteName', $wgSitename, array( 'id' => 'siteName' ) ) |
129 | 129 | ); |
130 | 130 | |
131 | | - if ( count( $egPushTargets ) == 1 ) { |
132 | | - self::displayLonelyPushItem(); |
133 | | - } |
134 | | - else { |
135 | | - self::displayPushList(); |
136 | | - } |
| 131 | + self::displayPushList(); |
137 | 132 | |
| 133 | + self::displayPushOptions(); |
| 134 | + |
138 | 135 | return false; |
139 | 136 | } |
140 | 137 | |
141 | 138 | /** |
142 | | - * Displays a target to push to for when there is only a single target. |
143 | | - * |
144 | | - * @since 0.1 |
145 | | - */ |
146 | | - protected static function displayLonelyPushItem() { |
147 | | - global $wgOut, $wgTitle, $egPushTargets; |
148 | | - |
149 | | - $targetNames = array_keys( $egPushTargets ); |
150 | | - |
151 | | - $wgOut->addHTML( |
152 | | - '<table><tr><td><b>' . htmlspecialchars( wfMsgExt( 'push-tab-push-to', 'parsemag', $targetNames[0] ) ) . '</b><br /><i>' . |
153 | | - Html::element( |
154 | | - 'a', |
155 | | - array( 'href' => $egPushTargets[$targetNames[0]] . '/index.php?title=' . $wgTitle->getFullText(), 'rel' => 'nofollow' ), |
156 | | - wfMsgExt( 'push-remote-page-link-full', 'parsemag', $wgTitle->getFullText(), $targetNames[0] ) |
157 | | - ) . '</i></td><td>   ' . |
158 | | - Html::element( |
159 | | - 'button', |
160 | | - array( |
161 | | - 'class' => 'push-button', |
162 | | - 'pushtarget' => $egPushTargets[$targetNames[0]], |
163 | | - 'style' => 'width: 125px; height: 30px', |
164 | | - ), |
165 | | - wfMsg( 'push-button-text' ) |
166 | | - ) . '</td></tr></table>' |
167 | | - ); |
168 | | - } |
169 | | - |
170 | | - /** |
171 | 139 | * Displays a list with all targets to which can be pushed. |
172 | 140 | * |
173 | 141 | * @since 0.1 |
— | — | @@ -200,27 +168,30 @@ |
201 | 169 | $items[] = self::getPushItem( $name, $url ); |
202 | 170 | } |
203 | 171 | |
204 | | - $items[] = Html::rawElement( |
205 | | - 'tr', |
206 | | - array(), |
207 | | - Html::element( |
208 | | - 'th', |
209 | | - array( 'colspan' => 2, 'style' => 'text-align: left' ), |
210 | | - wfMsgExt( 'push-targets-total', 'parsemag', $wgLang->formatNum( count( $egPushTargets ) ) ) |
211 | | - ) . |
212 | | - Html::rawElement( |
213 | | - 'th', |
214 | | - array( 'width' => '125px' ), |
| 172 | + // If there is more then one item, display the 'push all' row. |
| 173 | + if ( count( $egPushTargets ) > 1 ) { |
| 174 | + $items[] = Html::rawElement( |
| 175 | + 'tr', |
| 176 | + array(), |
215 | 177 | Html::element( |
216 | | - 'button', |
217 | | - array( |
218 | | - 'id' => 'push-all-button', |
219 | | - 'style' => 'width: 125px; height: 30px', |
220 | | - ), |
221 | | - wfMsg( 'push-button-all' ) |
222 | | - ) |
223 | | - ) |
224 | | - ); |
| 178 | + 'th', |
| 179 | + array( 'colspan' => 2, 'style' => 'text-align: left' ), |
| 180 | + wfMsgExt( 'push-targets-total', 'parsemag', $wgLang->formatNum( count( $egPushTargets ) ) ) |
| 181 | + ) . |
| 182 | + Html::rawElement( |
| 183 | + 'th', |
| 184 | + array( 'width' => '125px' ), |
| 185 | + Html::element( |
| 186 | + 'button', |
| 187 | + array( |
| 188 | + 'id' => 'push-all-button', |
| 189 | + 'style' => 'width: 125px; height: 30px', |
| 190 | + ), |
| 191 | + wfMsg( 'push-button-all' ) |
| 192 | + ) |
| 193 | + ) |
| 194 | + ); |
| 195 | + } |
225 | 196 | |
226 | 197 | $wgOut->addHtml( |
227 | 198 | Html::rawElement( |
— | — | @@ -257,7 +228,7 @@ |
258 | 229 | ) . |
259 | 230 | Html::rawElement( |
260 | 231 | 'td', |
261 | | - array(), |
| 232 | + array( 'height' => '45px' ), |
262 | 233 | Html::element( |
263 | 234 | 'a', |
264 | 235 | array( |
— | — | @@ -293,4 +264,53 @@ |
294 | 265 | ); |
295 | 266 | } |
296 | 267 | |
| 268 | + /** |
| 269 | + * Outputs the HTML for the push options. |
| 270 | + * |
| 271 | + * @since 0.4 |
| 272 | + */ |
| 273 | + protected static function displayPushOptions() { |
| 274 | + global $wgOut, $wgTitle, $wgLang, $egPushIncTemplates; |
| 275 | + |
| 276 | + $wgOut->addHTML( '<h3>' . htmlspecialchars( wfMsg( 'push-tab-push-options' ) ) . '</h3>' ); |
| 277 | + |
| 278 | + $usedTemplates = array_keys( |
| 279 | + PushFunctions::getTemplates( |
| 280 | + array( $wgTitle->getFullText() ), |
| 281 | + array( $wgTitle->getFullText() => true ) |
| 282 | + ) |
| 283 | + ); |
| 284 | + |
| 285 | + array_shift( $usedTemplates ); |
| 286 | + |
| 287 | + $wgOut->addInlineScript( |
| 288 | + 'var wgPushTemplates = ' . json_encode( $usedTemplates ) . ';' |
| 289 | + ); |
| 290 | + |
| 291 | + foreach ( $usedTemplates as &$template ) { |
| 292 | + $template = "[[$template]]"; |
| 293 | + } |
| 294 | + |
| 295 | + $wgOut->addHTML( |
| 296 | + Html::rawElement( |
| 297 | + 'div', |
| 298 | + array( 'id' => 'divIncTemplates' ), |
| 299 | + Xml::check( 'checkIncTemplates', $egPushIncTemplates, array( 'id' => 'checkIncTemplates' ) ) . |
| 300 | + Html::element( |
| 301 | + 'label', |
| 302 | + array( 'id' => 'lblIncTemplates', 'for' => 'checkIncTemplates' ), |
| 303 | + wfMsg( 'push-tab-inc-templates' ) |
| 304 | + ) . |
| 305 | + ' ' . |
| 306 | + Html::rawElement( |
| 307 | + 'div', |
| 308 | + array( 'style' => 'display:inline; opacity:0', 'id' => 'txtTemplateList' ), |
| 309 | + count( $usedTemplates ) > 0 ? |
| 310 | + wfMsgExt( 'push-tab-used-templates', 'parseinline', $wgLang->listToText( $usedTemplates ) ) : |
| 311 | + htmlspecialchars( wfMsg( 'push-tab-no-used-templates' ) ) |
| 312 | + ) |
| 313 | + ) |
| 314 | + ); |
| 315 | + } |
| 316 | + |
297 | 317 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/includes/Push_Functions.php |
— | — | @@ -12,6 +12,12 @@ |
13 | 13 | */ |
14 | 14 | final class PushFunctions { |
15 | 15 | |
| 16 | + /** |
| 17 | + * Adds the needed JS messages to the page output. |
| 18 | + * This is for backward compatibility with pre-RL MediaWiki. |
| 19 | + * |
| 20 | + * @since 0.2 |
| 21 | + */ |
16 | 22 | public static function addJSLocalisation() { |
17 | 23 | global $egPushJSMessages, $wgOut; |
18 | 24 | |
— | — | @@ -43,6 +49,62 @@ |
44 | 50 | else { |
45 | 51 | return $title->getLatestRevID(); |
46 | 52 | } |
47 | | - } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Expand a list of pages to include templates used in those pages. |
| 57 | + * |
| 58 | + * @since 0.4 |
| 59 | + * |
| 60 | + * @param $inputPages array list of titles to look up |
| 61 | + * @param $pageSet array associative array indexed by titles for output |
| 62 | + * |
| 63 | + * @return array associative array index by titles |
| 64 | + */ |
| 65 | + public static function getTemplates( $inputPages, $pageSet ) { |
| 66 | + return self::getLinks( $inputPages, $pageSet, |
| 67 | + 'templatelinks', |
| 68 | + array( 'tl_namespace AS namespace', 'tl_title AS title' ), |
| 69 | + array( 'page_id=tl_from' ) |
| 70 | + ); |
| 71 | + } |
48 | 72 | |
| 73 | + /** |
| 74 | + * Expand a list of pages to include items used in those pages. |
| 75 | + * |
| 76 | + * @since 0.4 |
| 77 | + */ |
| 78 | + protected static function getLinks( $inputPages, $pageSet, $table, $fields, $join ) { |
| 79 | + $dbr = wfGetDB( DB_SLAVE ); |
| 80 | + |
| 81 | + foreach( $inputPages as $page ) { |
| 82 | + $title = Title::newFromText( $page ); |
| 83 | + |
| 84 | + if( $title ) { |
| 85 | + $pageSet[$title->getPrefixedText()] = true; |
| 86 | + /// @todo Fixme: May or may not be more efficient to batch these |
| 87 | + /// by namespace when given multiple input pages. |
| 88 | + $result = $dbr->select( |
| 89 | + array( 'page', $table ), |
| 90 | + $fields, |
| 91 | + array_merge( |
| 92 | + $join, |
| 93 | + array( |
| 94 | + 'page_namespace' => $title->getNamespace(), |
| 95 | + 'page_title' => $title->getDBkey() |
| 96 | + ) |
| 97 | + ), |
| 98 | + __METHOD__ |
| 99 | + ); |
| 100 | + |
| 101 | + foreach( $result as $row ) { |
| 102 | + $template = Title::makeTitle( $row->namespace, $row->title ); |
| 103 | + $pageSet[$template->getPrefixedText()] = true; |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + return $pageSet; |
| 109 | + } |
| 110 | + |
49 | 111 | } |
\ No newline at end of file |
Index: trunk/extensions/Push/includes/ext.push.tab.js |
— | — | @@ -31,9 +31,17 @@ |
32 | 32 | this.disabled = true; |
33 | 33 | this.innerHTML = mediaWiki.msg( 'push-button-pushing' ); |
34 | 34 | |
| 35 | + if ( $('#checkIncTemplates:checked').val() !== null ) { |
| 36 | + var pages = window.wgPushTemplates; |
| 37 | + pages.unshift( $('#pageName').attr('value') ); |
| 38 | + } |
| 39 | + else { |
| 40 | + var pages = [$('#pageName').attr('value')]; |
| 41 | + } |
| 42 | + |
35 | 43 | initiatePush( |
36 | 44 | this, |
37 | | - $('#pageName').attr('value'), |
| 45 | + pages, |
38 | 46 | $(this).attr( 'pushtarget' ), |
39 | 47 | $(this).attr( 'targetname' ) |
40 | 48 | ); |
— | — | @@ -47,6 +55,18 @@ |
48 | 56 | }); |
49 | 57 | }); |
50 | 58 | |
| 59 | + $('#divIncTemplates').hover( |
| 60 | + function() { |
| 61 | + $('#txtTemplateList').fadeTo( |
| 62 | + ( $('#txtTemplateList').css( 'opacity' ) == 0 ? 'slow' : 'fast' ), |
| 63 | + 1 |
| 64 | + ); |
| 65 | + }, |
| 66 | + function() { |
| 67 | + $('#txtTemplateList').fadeTo( 'fast', 0.5 ) |
| 68 | + } |
| 69 | + ); |
| 70 | + |
51 | 71 | function getRemoteArticleInfo( targetId, targetUrl ) { |
52 | 72 | $.getJSON( |
53 | 73 | targetUrl + '/api.php?callback=?', |
— | — | @@ -87,13 +107,13 @@ |
88 | 108 | ); |
89 | 109 | } |
90 | 110 | |
91 | | - function initiatePush( sender, pageName, targetUrl, targetName ) { |
| 111 | + function initiatePush( sender, pages, targetUrl, targetName ) { |
92 | 112 | $.getJSON( |
93 | 113 | wgScriptPath + '/api.php', |
94 | 114 | { |
95 | 115 | 'action': 'push', |
96 | 116 | 'format': 'json', |
97 | | - 'page': pageName, |
| 117 | + 'page': pages.join( '|' ), |
98 | 118 | 'targets': targetUrl |
99 | 119 | }, |
100 | 120 | function( data ) { |
Index: trunk/extensions/Push/api/ApiPush.php |
— | — | @@ -12,6 +12,8 @@ |
13 | 13 | */ |
14 | 14 | class ApiPush extends ApiBase { |
15 | 15 | |
| 16 | + protected $editResponses = array(); |
| 17 | + |
16 | 18 | public function __construct( $main, $action ) { |
17 | 19 | parent::__construct( $main, $action ); |
18 | 20 | } |
— | — | @@ -27,13 +29,42 @@ |
28 | 30 | $this->dieUsageMsg( array( 'missingparam', 'targets' ) ); |
29 | 31 | } |
30 | 32 | |
31 | | - $title = Title::newFromText( $params['page'] ); |
| 33 | + foreach ( $params['page'] as $page ) { |
| 34 | + $title = Title::newFromText( $page ); |
32 | 35 | |
33 | | - $revision = $this->getPageRevision( $title ); |
| 36 | + $revision = $this->getPageRevision( $title ); |
| 37 | + |
| 38 | + if ( $revision !== false ) { |
| 39 | + $this->doPush( $title, $revision, $params['targets'] ); |
| 40 | + } |
| 41 | + } |
34 | 42 | |
35 | | - if ( $revision !== false ) { |
36 | | - $this->doPush( $title, $revision, $params['targets'] ); |
| 43 | + // TODO: this is hardcoded for JSON, make use of API stuff to support all formats. |
| 44 | + if ( count( $this->editResponses ) == 1 ) { |
| 45 | + die( $this->editResponses[0] ); |
37 | 46 | } |
| 47 | + else { |
| 48 | + foreach ( $this->editResponses as $rawResponse ) { |
| 49 | + $response = FormatJson::decode( $rawResponse ); |
| 50 | + |
| 51 | + if ( property_exists( $response , 'query' ) |
| 52 | + && property_exists( $response->query , 'error' ) ) { |
| 53 | + die( $rawResponse ); |
| 54 | + } |
| 55 | + else if ( property_exists( $response , 'query' ) |
| 56 | + && property_exists( $response->query , 'captcha' ) ) { |
| 57 | + die( $rawResponse ); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + $this->getResult()->addValue( |
| 62 | + null, |
| 63 | + $this->getModuleName(), |
| 64 | + array( |
| 65 | + 'result' => 'Success' |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
38 | 69 | } |
39 | 70 | |
40 | 71 | /** |
— | — | @@ -203,7 +234,7 @@ |
204 | 235 | $response = Http::post( $target, array( 'postData' => $requestData ) ); |
205 | 236 | |
206 | 237 | if ( $response !== false ) { |
207 | | - die( $response ); |
| 238 | + $this->editResponses[] = $response; |
208 | 239 | } |
209 | 240 | else { |
210 | 241 | $this->dieUsage( wfMsg( 'push-special-err-push-failed' ), 'page-push-failed' ); |
— | — | @@ -214,6 +245,7 @@ |
215 | 246 | return array( |
216 | 247 | 'page' => array( |
217 | 248 | ApiBase::PARAM_TYPE => 'string', |
| 249 | + ApiBase::PARAM_ISMULTI => true, |
218 | 250 | //ApiBase::PARAM_REQUIRED => true, |
219 | 251 | ), |
220 | 252 | 'targets' => array( |