r73943 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73942‎ | r73943 | r73944 >
Date:12:30, 29 September 2010
Author:jojo
Status:ok
Tags:
Comment:
return redirect URL as JSON or a 302 response
Modified paths:
  • /trunk/extensions/Collection/Collection.body.php (modified) (history)
  • /trunk/extensions/Collection/Collection.php (modified) (history)
  • /trunk/extensions/Collection/Collection.session.php (modified) (history)
  • /trunk/extensions/Collection/js/check_load_from_localstorage.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/Collection.php
@@ -174,15 +174,24 @@
175175
176176 $wgAjaxExportList[] = 'wfAjaxGetCollection';
177177
178 -function wfAjaxPostCollection( $collection = '' ) {
 178+function wfAjaxPostCollection( $collection = '', $redirect = '' ) {
179179 $json = new Services_JSON( SERVICES_JSON_LOOSE_TYPE );
180180 if ( session_id() == '' ) {
181181 wfSetupSession();
182182 }
183183 $collection = $json->decode( $collection );
 184+ $collection['enabled'] = true;
184185 $_SESSION['wsCollection'] = $collection;
185 - $r = new AjaxResponse( $json->encode( array( 'collection' => $collection ) ) );
186 - $r->setContentType( 'application/json' );
 186+ $title = SpecialPage::getTitleFor( 'Book' );
 187+ $redirecturl = $title->getFullURL( $urlaction );
 188+ $r = new AjaxResponse();
 189+ if ( $redirect ) {
 190+ $r->setResponseCode( 302 );
 191+ header( 'Location: ' . $redirecturl );
 192+ } else {
 193+ $r->setContentType( 'application/json' );
 194+ $r->addText( $json->encode( array( 'redirect_url' => $redirecturl ) ) );
 195+ }
187196 return $r;
188197 }
189198
Index: trunk/extensions/Collection/Collection.session.php
@@ -42,7 +42,7 @@
4343
4444 static function clearCollection() {
4545 $_SESSION['wsCollection'] = array(
46 - 'enabled' => 'true',
 46+ 'enabled' => true,
4747 'title' => '',
4848 'subtitle' => '',
4949 'items' => array(),
Index: trunk/extensions/Collection/js/check_load_from_localstorage.js
@@ -25,8 +25,8 @@
2626 'action': 'ajax',
2727 'rs': 'wfAjaxPostCollection',
2828 'rsargs[]': [JSON.stringify(c)]
29 - }, function() {
30 - window.location.href = collection_redirect_url;
 29+ }, function(result) {
 30+ window.location.href = result.redirect_url;
3131 }, 'json');
3232 }
3333 }
Index: trunk/extensions/Collection/Collection.body.php
@@ -339,12 +339,10 @@
340340
341341 $coll = CollectionSession::getCollection();
342342 $dialogtxt = wfMsg( 'coll-load_local_book' );
343 - $redirecturl = SkinTemplate::makeSpecialUrl( 'Book' );
344343
345344 $wgOut->addScript(
346345 "<script type=\"$wgJsMimeType\">\n" .
347346 "var collection_dialogtxt = " . Xml::encodeJsVar( $dialogtxt ) . ";\n" .
348 - "var collection_redirect_url = " . Xml::encodeJsVar( $redirecturl ) . ";\n" .
349347 "</script>" );
350348
351349 $wgOut->mScripts .= <<<EOS

Status & tagging log