r78234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78233‎ | r78234 | r78235 >
Date:05:42, 12 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added include templates option to the push interface and changed the push api module to provide the needed functionality
Modified paths:
  • /trunk/extensions/Push/Push.i18n.php (modified) (history)
  • /trunk/extensions/Push/Push_Settings.php (modified) (history)
  • /trunk/extensions/Push/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Push/api/ApiPush.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Functions.php (modified) (history)
  • /trunk/extensions/Push/includes/Push_Tab.php (modified) (history)
  • /trunk/extensions/Push/includes/ext.push.tab.js (modified) (history)
  • /trunk/extensions/Push/specials/Push_Body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Push/Push.i18n.php
@@ -44,6 +44,10 @@
4545 'push-button-all' => 'Push all',
4646 'push-tab-last-edit' => 'Last edit by $1 on $2 at $3.',
4747 '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.)',
4852
4953 // Special page
5054 'special-push' => 'Push pages',
Index: trunk/extensions/Push/specials/Push_Body.php
@@ -135,7 +135,7 @@
136136
137137 // Look up any linked pages if asked...
138138 if( $wgRequest->getCheck( 'templates' ) ) {
139 - $pageSet = $this->getTemplates( array_keys( $pageSet ), $pageSet );
 139+ $pageSet = PushFunctions::getTemplates( array_keys( $pageSet ), $pageSet );
140140 }
141141
142142 $pages = array_keys( $pageSet );
@@ -301,64 +301,8 @@
302302 }
303303 return $pages;
304304 }
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 - }
323305
324306 /**
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 - /**
363307 * Loads the needed JavaScript.
364308 * Takes care of non-RL compatibility.
365309 *
Index: trunk/extensions/Push/Push_Settings.php
@@ -26,6 +26,7 @@
2727 $wgGroupPermissions['sysop']['pushadmin'] = true;
2828
2929 $egPushShowTab = false;
 30+$egPushIncTemplates = false;
3031
3132 $egPushBulkWorkers = 3;
3233 $egPushBatchSize = 3;
Index: trunk/extensions/Push/RELEASE-NOTES
@@ -7,7 +7,7 @@
88 === Version 0.4 ===
99 2010-12-xx
1010
11 -*
 11+* Added adittional info about target pages to the tab interface.
1212
1313 === Version 0.3 ===
1414 2010-12-10
Index: trunk/extensions/Push/includes/Push_Tab.php
@@ -127,46 +127,14 @@
128128 Html::hidden( 'siteName', $wgSitename, array( 'id' => 'siteName' ) )
129129 );
130130
131 - if ( count( $egPushTargets ) == 1 ) {
132 - self::displayLonelyPushItem();
133 - }
134 - else {
135 - self::displayPushList();
136 - }
 131+ self::displayPushList();
137132
 133+ self::displayPushOptions();
 134+
138135 return false;
139136 }
140137
141138 /**
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>&#160;&#160;&#160;' .
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 - /**
171139 * Displays a list with all targets to which can be pushed.
172140 *
173141 * @since 0.1
@@ -200,27 +168,30 @@
201169 $items[] = self::getPushItem( $name, $url );
202170 }
203171
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(),
215177 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+ }
225196
226197 $wgOut->addHtml(
227198 Html::rawElement(
@@ -257,7 +228,7 @@
258229 ) .
259230 Html::rawElement(
260231 'td',
261 - array(),
 232+ array( 'height' => '45px' ),
262233 Html::element(
263234 'a',
264235 array(
@@ -293,4 +264,53 @@
294265 );
295266 }
296267
 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+ '&#160;' .
 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+
297317 }
\ No newline at end of file
Index: trunk/extensions/Push/includes/Push_Functions.php
@@ -12,6 +12,12 @@
1313 */
1414 final class PushFunctions {
1515
 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+ */
1622 public static function addJSLocalisation() {
1723 global $egPushJSMessages, $wgOut;
1824
@@ -43,6 +49,62 @@
4450 else {
4551 return $title->getLatestRevID();
4652 }
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+ }
4872
 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+
49111 }
\ No newline at end of file
Index: trunk/extensions/Push/includes/ext.push.tab.js
@@ -31,9 +31,17 @@
3232 this.disabled = true;
3333 this.innerHTML = mediaWiki.msg( 'push-button-pushing' );
3434
 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+
3543 initiatePush(
3644 this,
37 - $('#pageName').attr('value'),
 45+ pages,
3846 $(this).attr( 'pushtarget' ),
3947 $(this).attr( 'targetname' )
4048 );
@@ -47,6 +55,18 @@
4856 });
4957 });
5058
 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+
5171 function getRemoteArticleInfo( targetId, targetUrl ) {
5272 $.getJSON(
5373 targetUrl + '/api.php?callback=?',
@@ -87,13 +107,13 @@
88108 );
89109 }
90110
91 - function initiatePush( sender, pageName, targetUrl, targetName ) {
 111+ function initiatePush( sender, pages, targetUrl, targetName ) {
92112 $.getJSON(
93113 wgScriptPath + '/api.php',
94114 {
95115 'action': 'push',
96116 'format': 'json',
97 - 'page': pageName,
 117+ 'page': pages.join( '|' ),
98118 'targets': targetUrl
99119 },
100120 function( data ) {
Index: trunk/extensions/Push/api/ApiPush.php
@@ -12,6 +12,8 @@
1313 */
1414 class ApiPush extends ApiBase {
1515
 16+ protected $editResponses = array();
 17+
1618 public function __construct( $main, $action ) {
1719 parent::__construct( $main, $action );
1820 }
@@ -27,13 +29,42 @@
2830 $this->dieUsageMsg( array( 'missingparam', 'targets' ) );
2931 }
3032
31 - $title = Title::newFromText( $params['page'] );
 33+ foreach ( $params['page'] as $page ) {
 34+ $title = Title::newFromText( $page );
3235
33 - $revision = $this->getPageRevision( $title );
 36+ $revision = $this->getPageRevision( $title );
 37+
 38+ if ( $revision !== false ) {
 39+ $this->doPush( $title, $revision, $params['targets'] );
 40+ }
 41+ }
3442
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] );
3746 }
 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+ }
3869 }
3970
4071 /**
@@ -203,7 +234,7 @@
204235 $response = Http::post( $target, array( 'postData' => $requestData ) );
205236
206237 if ( $response !== false ) {
207 - die( $response );
 238+ $this->editResponses[] = $response;
208239 }
209240 else {
210241 $this->dieUsage( wfMsg( 'push-special-err-push-failed' ), 'page-push-failed' );
@@ -214,6 +245,7 @@
215246 return array(
216247 'page' => array(
217248 ApiBase::PARAM_TYPE => 'string',
 249+ ApiBase::PARAM_ISMULTI => true,
218250 //ApiBase::PARAM_REQUIRED => true,
219251 ),
220252 'targets' => array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r78235Follow up to r78234jeroendedauw05:51, 12 December 2010
r78237Follow-up r78234: PLURALize messageraymond08:39, 12 December 2010

Status & tagging log