jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/332903 )

Change subject: Revert "Move all functions into CollectionAjaxFunctions file in 
preparation for extension.json"
......................................................................


Revert "Move all functions into CollectionAjaxFunctions file in preparation for 
extension.json"

Completely broke all the AJAX calls because JS wasn't updated with
new function names.

E.g. try adding pages to books, etc.

This reverts commit 52f2af1b6f7ad3ff463246e668b7c7886ad31a6c.

Change-Id: Iaf51dc459782693f0cbdc0f49ea61802dfe2a1aa
(cherry picked from commit 89e627f5b880b448253919ae10d0d86ac1b54d97)
---
M Collection.php
D CollectionAjaxFunctions.php
2 files changed, 253 insertions(+), 258 deletions(-)

Approvals:
  MaxSem: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Collection.php b/Collection.php
index 80852a9..8587dfd 100644
--- a/Collection.php
+++ b/Collection.php
@@ -176,7 +176,6 @@
 $wgAutoloadClasses['SpecialCollection'] = __DIR__ . '/Collection.body.php';
 $wgAutoloadClasses['CollectionSession'] = __DIR__ . '/Collection.session.php';
 $wgAutoloadClasses['CollectionHooks'] = __DIR__ . '/Collection.hooks.php';
-$wgAutoloadClasses['CollectionAjaxFunctions'] = __DIR__ . 
'/CollectionAjaxFunctions.php';
 $wgAutoloadClasses['CollectionSuggest'] = __DIR__ . '/Collection.suggest.php';
 $wgAutoloadClasses['CollectionProposals'] = __DIR__ . 
'/Collection.suggest.php';
 
@@ -251,42 +250,275 @@
 
 # register global Ajax functions:
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxGetCollection';
+function wfAjaxGetCollection() {
+       if ( isset( $_SESSION['wsCollection'] ) ) {
+               $collection = $_SESSION['wsCollection'];
+       } else {
+               $collection = array();
+       }
+       $r = new AjaxResponse( FormatJson::encode( array( 'collection' => 
$collection ) ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxPostCollection';
+$wgAjaxExportList[] = 'wfAjaxGetCollection';
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxGetMWServeStatus';
+function wfAjaxPostCollection( $collection = '', $redirect = '' ) {
+       if ( session_id() == '' ) {
+               wfSetupSession();
+       }
+       $collection = FormatJson::decode( $collection, true );
+       $collection['enabled'] = true;
+       $_SESSION['wsCollection'] = $collection;
+       $r = new AjaxResponse();
+       if ( $redirect ) {
+               $title = Title::newFromText( $redirect );
+               $redirecturl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT 
);
+               $r->setResponseCode( 302 );
+               header( 'Location: ' . $redirecturl );
+       } else {
+               $title = SpecialPage::getTitleFor( 'Book' );
+               $redirecturl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT 
);
+               $r->setContentType( 'application/json' );
+               $r->addText( FormatJson::encode( array( 'redirect_url' => 
$redirecturl ) ) );
+       }
+       return $r;
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionAddArticle';
+$wgAjaxExportList[] = 'wfAjaxPostCollection';
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionRemoveArticle';
+function wfAjaxGetMWServeStatus( $collection_id = '', $writer = 'rl' ) {
+       $response = CollectionRenderingAPI::instance( $writer )
+               ->getRenderStatus( $collection_id );
+       $result = $response->response;
+       if ( isset( $result['status']['progress'] ) ) {
+               $result['status']['progress'] = number_format( 
$result['status']['progress'], 2, '.', '' );
+       }
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionAddCategory';
+$wgAjaxExportList[] = 'wfAjaxGetMWServeStatus';
 
-$wgAjaxExportList[] = 
'CollectionAjaxFunctions::onAjaxCollectionGetBookCreatorBoxContent';
+function wfAjaxCollectionAddArticle( $namespace = 0, $title = '', $oldid = '' 
) {
+       SpecialCollection::addArticleFromName( $namespace, $title, $oldid );
+       return wfAjaxCollectionGetItemList();
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionGetItemList';
+$wgAjaxExportList[] = 'wfAjaxCollectionAddArticle';
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionRemoveItem';
+function wfAjaxCollectionRemoveArticle( $namespace = 0, $title = '', $oldid = 
'' ) {
+       SpecialCollection::removeArticleFromName( $namespace, $title, $oldid );
+       return wfAjaxCollectionGetItemList();
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionAddChapter';
+$wgAjaxExportList[] = 'wfAjaxCollectionRemoveArticle';
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionRenameChapter';
+function wfAjaxCollectionAddCategory( $title = '' ) {
+       SpecialCollection::addCategoryFromName( $title );
+       return wfAjaxCollectionGetItemList();
+}
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionSetTitles';
+$wgAjaxExportList[] = 'wfAjaxCollectionAddCategory';
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionSetSorting';
+function wfAjaxCollectionGetBookCreatorBoxContent(
+       $ajaxHint = '',
+       $oldid = null,
+       $pageName = null
+) {
+       if ( !is_null( $oldid ) ) {
+               $oldid = intval( $oldid );
+       }
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionClear';
+       $title = null;
+       if ( !is_null( $pageName ) ) {
+               $title = Title::newFromText( $pageName );
+       }
+       if ( is_null( $title ) ) {
+               $title = Title::newMainPage();
+       }
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionGetPopupData';
+       $html = CollectionHooks::getBookCreatorBoxContent( $title, $ajaxHint, 
$oldid );
 
-$wgAjaxExportList[] = 
'CollectionAjaxFunctions::onAjaxCollectionSuggestBanArticle';
+       $result = array();
+       $result['html'] = $html;
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
 
-$wgAjaxExportList[] = 
'CollectionAjaxFunctions::onAjaxCollectionSuggestAddArticle';
+$wgAjaxExportList[] = 'wfAjaxCollectionGetBookCreatorBoxContent';
 
-$wgAjaxExportList[] = 
'CollectionAjaxFunctions::onAjaxCollectionSuggestRemoveArticle';
+function wfAjaxCollectionGetItemList() {
+       $collection = $_SESSION['wsCollection'];
 
-$wgAjaxExportList[] = 
'CollectionAjaxFunctions::onAjaxCollectionSuggestUndoArticle';
+       $template = new CollectionListTemplate();
+       $template->set( 'collection', $collection );
+       $template->set( 'is_ajax', true );
+       ob_start();
+       $template->execute();
+       $html = ob_get_contents();
+       ob_end_clean();
 
-$wgAjaxExportList[] = 'CollectionAjaxFunctions::onAjaxCollectionSortItems';
+       $result = array();
+       $result['html'] = $html;
+       $result['collection'] = $collection;
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionGetItemList';
+
+function wfAjaxCollectionRemoveItem( $index ) {
+       SpecialCollection::removeItem( (int)$index );
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionRemoveItem';
+
+function wfAjaxCollectionAddChapter( $name ) {
+       SpecialCollection::addChapter( $name );
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionAddChapter';
+
+function wfAjaxCollectionRenameChapter( $index, $name ) {
+       SpecialCollection::renameChapter( (int)$index, $name );
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionRenameChapter';
+
+function wfAjaxCollectionSetTitles( $title, $subtitle, $settings = '' ) {
+       SpecialCollection::setTitles( $title, $subtitle );
+       $settings = FormatJson::decode( $settings, true );
+       if ( is_array( $settings ) ) {
+               SpecialCollection::setSettings( $settings );
+       }
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSetTitles';
+
+function wfAjaxCollectionSetSorting( $items_string ) {
+       $parsed = array();
+       parse_str( $items_string, $parsed );
+       $items = array();
+       foreach ( $parsed['item'] as $s ) {
+               if ( is_numeric( $s ) ) {
+                       $items[] = intval( $s );
+               }
+       }
+       SpecialCollection::setSorting( $items );
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSetSorting';
+
+function wfAjaxCollectionClear() {
+       CollectionSession::clearCollection();
+       CollectionSuggest::clear();
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionClear';
+
+function wfAjaxCollectionGetPopupData( $title ) {
+       global $wgExtensionAssetsPath;
+
+       $result = array();
+       $imagePath = "$wgExtensionAssetsPath/Collection/images";
+       $t = Title::newFromText( $title );
+       if ( $t && $t->isRedirect() ) {
+               $wikiPage = WikiPage::factory( $t );
+               $t = $wikiPage->followRedirect();
+               if ( $t instanceof Title ) {
+                       $title = $t->getPrefixedText();
+               }
+       }
+       if ( CollectionSession::findArticle( $title ) == - 1 ) {
+               $result['action'] = 'add';
+               $result['text'] = wfMessage( 'coll-add_linked_article' 
)->text();
+               $result['img'] = "$imagePath/silk-add.png";
+       } else {
+               $result['action'] = 'remove';
+               $result['text'] = wfMessage( 'coll-remove_linked_article' 
)->text();
+               $result['img'] = "$imagePath/silk-remove.png";
+       }
+       $result['title'] = $title;
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+
+       return $r;
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionGetPopupData';
+
+/**
+ * Backend of several following SAJAX function handlers...
+ * @param String $action provided by the specific handlers internally
+ * @param String $article title passed in from client
+ * @return AjaxResponse with JSON-encoded array including HTML fragment.
+ */
+function wfCollectionSuggestAction( $action, $article ) {
+       $result = CollectionSuggest::refresh( $action, $article );
+       $undoLink = Xml::element( 'a',
+               array(
+                       'href' => SkinTemplate::makeSpecialUrl(
+                               'Book',
+                               array( 'bookcmd' => 'suggest', 'undo' => 
$action, 'arttitle' => $article )
+                       ),
+                       'onclick' => "collectionSuggestCall('UndoArticle'," .
+                               Xml::encodeJsVar( array( $action, $article ) ) 
. "); return false;",
+                       'title' => wfMessage( 'coll-suggest_undo_tooltip' 
)->text(),
+               ),
+               wfMessage( 'coll-suggest_undo' )->text()
+       );
+       // Message keys used:
+       // coll-suggest_article_ban
+       // coll-suggest_article_add
+       // coll-suggest_article_remove
+       $result['last_action'] = wfMessage( "coll-suggest_article_$action", 
$article )
+               ->rawParams( $undoLink )->parse();
+       $result['collection'] = CollectionSession::getCollection();
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
+
+function wfAjaxCollectionSuggestBanArticle( $article ) {
+       return wfCollectionSuggestAction( 'ban', $article );
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSuggestBanArticle';
+
+function wfAjaxCollectionSuggestAddArticle( $article ) {
+       return wfCollectionSuggestAction( 'add', $article );
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSuggestAddArticle';
+
+function wfAjaxCollectionSuggestRemoveArticle( $article ) {
+       return wfCollectionSuggestAction( 'remove', $article );
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSuggestRemoveArticle';
+
+function wfAjaxCollectionSuggestUndoArticle( $lastAction, $article ) {
+       $result = CollectionSuggest::undo( $lastAction, $article );
+       $r = new AjaxResponse( FormatJson::encode( $result ) );
+       $r->setContentType( 'application/json' );
+       return $r;
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSuggestUndoArticle';
+
+function wfAjaxCollectionSortItems() {
+       SpecialCollection::sortItems();
+       return wfAjaxCollectionGetItemList();
+}
+
+$wgAjaxExportList[] = 'wfAjaxCollectionSortItems';
diff --git a/CollectionAjaxFunctions.php b/CollectionAjaxFunctions.php
deleted file mode 100644
index 9c9951b..0000000
--- a/CollectionAjaxFunctions.php
+++ /dev/null
@@ -1,237 +0,0 @@
-<?php
-
-class CollectionAjaxFunctions {
-
-       public static function onAjaxGetCollection() {
-               if ( isset( $_SESSION['wsCollection'] ) ) {
-                       $collection = $_SESSION['wsCollection'];
-               } else {
-                       $collection = array();
-               }
-               $r = new AjaxResponse( FormatJson::encode( array( 'collection' 
=> $collection ) ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxPostCollection( $collection = '', 
$redirect = '' ) {
-               if ( session_id() == '' ) {
-                       wfSetupSession();
-               }
-               $collection = FormatJson::decode( $collection, true );
-               $collection['enabled'] = true;
-               $_SESSION['wsCollection'] = $collection;
-               $r = new AjaxResponse();
-               if ( $redirect ) {
-                       $title = Title::newFromText( $redirect );
-                       $redirecturl = wfExpandUrl( $title->getFullURL(), 
PROTO_CURRENT );
-                       $r->setResponseCode( 302 );
-                       header( 'Location: ' . $redirecturl );
-               } else {
-                       $title = SpecialPage::getTitleFor( 'Book' );
-                       $redirecturl = wfExpandUrl( $title->getFullURL(), 
PROTO_CURRENT );
-                       $r->setContentType( 'application/json' );
-                       $r->addText( FormatJson::encode( array( 'redirect_url' 
=> $redirecturl ) ) );
-               }
-               return $r;
-       }
-
-       public static function onAjaxGetMWServeStatus( $collection_id = '', 
$writer = 'rl' ) {
-               $response = CollectionRenderingAPI::instance( $writer )
-                       ->getRenderStatus( $collection_id );
-               $result = $response->response;
-               if ( isset( $result['status']['progress'] ) ) {
-                       $result['status']['progress'] = number_format( 
$result['status']['progress'], 2, '.', '' );
-               }
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxCollectionAddArticle( $namespace = 0, 
$title = '', $oldid = '' ) {
-               SpecialCollection::addArticleFromName( $namespace, $title, 
$oldid );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionRemoveArticle( $namespace = 0, 
$title = '', $oldid = '' ) {
-               SpecialCollection::removeArticleFromName( $namespace, $title, 
$oldid );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionAddCategory( $title = '' ) {
-               SpecialCollection::addCategoryFromName( $title );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionGetBookCreatorBoxContent(
-               $ajaxHint = '',
-               $oldid = null,
-               $pageName = null
-       ) {
-               if ( !is_null( $oldid ) ) {
-                       $oldid = intval( $oldid );
-               }
-
-               $title = null;
-               if ( !is_null( $pageName ) ) {
-                       $title = Title::newFromText( $pageName );
-               }
-               if ( is_null( $title ) ) {
-                       $title = Title::newMainPage();
-               }
-
-               $html = CollectionHooks::getBookCreatorBoxContent( $title, 
$ajaxHint, $oldid );
-
-               $result = array();
-               $result['html'] = $html;
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxCollectionGetItemList() {
-               $collection = $_SESSION['wsCollection'];
-
-               $template = new CollectionListTemplate();
-               $template->set( 'collection', $collection );
-               $template->set( 'is_ajax', true );
-               ob_start();
-               $template->execute();
-               $html = ob_get_contents();
-               ob_end_clean();
-
-               $result = array();
-               $result['html'] = $html;
-               $result['collection'] = $collection;
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxCollectionRemoveItem( $index ) {
-               SpecialCollection::removeItem( (int)$index );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionAddChapter( $name ) {
-               SpecialCollection::addChapter( $name );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionRenameChapter( $index, $name ) {
-               SpecialCollection::renameChapter( (int)$index, $name );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionSetTitles( $title, $subtitle, 
$settings = '' ) {
-               SpecialCollection::setTitles( $title, $subtitle );
-               $settings = FormatJson::decode( $settings, true );
-               if ( is_array( $settings ) ) {
-                       SpecialCollection::setSettings( $settings );
-               }
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionSetSorting( $items_string ) {
-               $parsed = array();
-               parse_str( $items_string, $parsed );
-               $items = array();
-               foreach ( $parsed['item'] as $s ) {
-                       if ( is_numeric( $s ) ) {
-                               $items[] = intval( $s );
-                       }
-               }
-               SpecialCollection::setSorting( $items );
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionClear() {
-               CollectionSession::clearCollection();
-               CollectionSuggest::clear();
-               return self::onAjaxCollectionGetItemList();
-       }
-
-       public static function onAjaxCollectionGetPopupData( $title ) {
-               global $wgExtensionAssetsPath;
-
-               $result = array();
-               $imagePath = "$wgExtensionAssetsPath/Collection/images";
-               $t = Title::newFromText( $title );
-               if ( $t && $t->isRedirect() ) {
-                       $wikiPage = WikiPage::factory( $t );
-                       $t = $wikiPage->followRedirect();
-                       if ( $t instanceof Title ) {
-                               $title = $t->getPrefixedText();
-                       }
-               }
-               if ( CollectionSession::findArticle( $title ) == - 1 ) {
-                       $result['action'] = 'add';
-                       $result['text'] = wfMessage( 'coll-add_linked_article' 
)->text();
-                       $result['img'] = "$imagePath/silk-add.png";
-               } else {
-                       $result['action'] = 'remove';
-                       $result['text'] = wfMessage( 
'coll-remove_linked_article' )->text();
-                       $result['img'] = "$imagePath/silk-remove.png";
-               }
-               $result['title'] = $title;
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-
-               return $r;
-       }
-
-       /**
-        * Backend of several following SAJAX function handlers...
-        * @param String $action provided by the specific handlers internally
-        * @param String $article title passed in from client
-        * @return AjaxResponse with JSON-encoded array including HTML fragment.
-        */
-       public static function onCollectionSuggestAction( $action, $article ) {
-               $result = CollectionSuggest::refresh( $action, $article );
-               $undoLink = Xml::element( 'a',
-                       array(
-                               'href' => SkinTemplate::makeSpecialUrl(
-                                       'Book',
-                                       array( 'bookcmd' => 'suggest', 'undo' 
=> $action, 'arttitle' => $article )
-                               ),
-                               'onclick' => 
"collectionSuggestCall('UndoArticle'," .
-                                       Xml::encodeJsVar( array( $action, 
$article ) ) . "); return false;",
-                               'title' => wfMessage( 
'coll-suggest_undo_tooltip' )->text(),
-                       ),
-                       wfMessage( 'coll-suggest_undo' )->text()
-               );
-               // Message keys used:
-               // coll-suggest_article_ban
-               // coll-suggest_article_add
-               // coll-suggest_article_remove
-               $result['last_action'] = wfMessage( 
"coll-suggest_article_$action", $article )
-                       ->rawParams( $undoLink )->parse();
-               $result['collection'] = CollectionSession::getCollection();
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxCollectionSuggestBanArticle( $article ) {
-               return self::onCollectionSuggestAction( 'ban', $article );
-       }
-
-       public static function onAjaxCollectionSuggestAddArticle( $article ) {
-               return self::onCollectionSuggestAction( 'add', $article );
-       }
-
-       public static function onAjaxCollectionSuggestRemoveArticle( $article ) 
{
-               return self::onCollectionSuggestAction( 'remove', $article );
-       }
-
-       public static function onAjaxCollectionSuggestUndoArticle( $lastAction, 
$article ) {
-               $result = CollectionSuggest::undo( $lastAction, $article );
-               $r = new AjaxResponse( FormatJson::encode( $result ) );
-               $r->setContentType( 'application/json' );
-               return $r;
-       }
-
-       public static function onAjaxCollectionSortItems() {
-               SpecialCollection::sortItems();
-               return self::onAjaxCollectionGetItemList();
-       }
-}

-- 
To view, visit https://gerrit.wikimedia.org/r/332903
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaf51dc459782693f0cbdc0f49ea61802dfe2a1aa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Collection
Gerrit-Branch: wmf/1.29.0-wmf.8
Gerrit-Owner: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to