Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/272728
Change subject: Version 2.4.1: AJAX stuff replaced by an API module ...................................................................... Version 2.4.1: AJAX stuff replaced by an API module Because it's so much "better" to have a 50+ line wrapper around a simple function than just calling the function directly... A more practical reason for this is that extension.json doesn't (intentionally) support $wgAjaxExportList, so before this change, if anyone used wfLoadExtension( 'BlogPage' ); Special:CreateBlogPost wouldn't have worked correctly and submitting new blog posts would've been impossible. Change-Id: I82f57eb04f53f0d778ff0953ef8cc705b11ac757 --- A ApiBlogPage.php M BlogPage.php M extension.json M i18n/en.json M resources/js/CreateBlogPost.js 5 files changed, 69 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlogPage refs/changes/28/272728/1 diff --git a/ApiBlogPage.php b/ApiBlogPage.php new file mode 100644 index 0000000..62a3c87 --- /dev/null +++ b/ApiBlogPage.php @@ -0,0 +1,53 @@ +<?php +/** + * BlogPage API module + * + * As of 23 February 2016, this does precisely one thing: + * checks if there is already a blog post with the given title. + * + * @file + * @ingroup API + * @date 23 February 2016 + * @see https://www.mediawiki.org/wiki/API:Extensions#ApiSampleApiExtension.php + */ +class ApiBlogPage extends ApiBase { + + /** + * Main entry point. + */ + public function execute() { + // Get the request parameters + $params = $this->extractRequestParams(); + + $pageName = $params['pageName']; + $output = SpecialCreateBlogPost::checkTitleExistence( $pageName ); + + // Top level + $this->getResult()->addValue( null, $this->getModuleName(), + array( 'result' => $output ) + ); + + return true; + } + + /** + * @return array + */ + public function getAllowedParams() { + return array( + 'pageName' => array( + ApiBase::PARAM_TYPE => 'string', + ApiBase::PARAM_REQUIRED => true + ) + ); + } + + /** + * @see ApiBase::getExamplesMessages() + */ + protected function getExamplesMessages() { + return array( + 'action=blogpage&pageName=My%20Cool%20New%20Blog%20Post' => 'apihelp-blogpage-example-1' + ); + } +} diff --git a/BlogPage.php b/BlogPage.php index 017d981..6a34e4e 100644 --- a/BlogPage.php +++ b/BlogPage.php @@ -5,7 +5,6 @@ * * @file * @ingroup Extensions - * @version 2.3.2 * @author David Pean <[email protected]> * @author Jack Phoenix <[email protected]> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later @@ -15,7 +14,7 @@ // Extension credits that will show up on Special:Version $wgExtensionCredits['other'][] = array( 'name' => 'BlogPage', - 'version' => '2.4.0', + 'version' => '2.4.1', 'author' => array( 'David Pean', 'Jack Phoenix' ), 'descriptionmsg' => 'blogpage-desc', 'url' => 'https://www.mediawiki.org/wiki/Extension:BlogPage', @@ -124,7 +123,9 @@ $wgAutoloadClasses['SpecialCreateBlogPost'] = __DIR__ . '/SpecialCreateBlogPost.php'; $wgSpecialPages['CreateBlogPost'] = 'SpecialCreateBlogPost'; -$wgAjaxExportList[] = 'SpecialCreateBlogPost::checkTitleExistence'; +// Load the API module +$wgAutoloadClasses['ApiBlogPage'] = __DIR__ . '/ApiBlogPage.php'; +$wgAPIModules['blogpage'] = 'ApiBlogPage'; // New user right, required to create new blog posts via the new special page $wgAvailableRights[] = 'createblogpost'; diff --git a/extension.json b/extension.json index 697ff5b..f6f5861 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "BlogPage", - "version": "2.4.0", + "version": "2.4.1", "author": [ "David Pean", "Jack Phoenix" @@ -9,9 +9,6 @@ "descriptionmsg": "blogpage-desc", "type": "other", "config": { - "AjaxExportList": [ - "SpecialCreateBlogPost::checkTitleExistence" - ], "BlogPageDisplay": { "leftcolumn": true, "rightcolumn": true, @@ -31,7 +28,11 @@ "articles": true } }, + "APIModules": { + "blogpage": "ApiBlogPage" + }, "AutoloadClasses": { + "ApiBlogPage": "ApiBlogPage.php", "BlogPage": "BlogPageClass.php", "ArticlesHome": "SpecialArticlesHome.php", "ArticleLists": "SpecialArticleLists.php", diff --git a/i18n/en.json b/i18n/en.json index fc6ce60..983ed3c 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,6 +5,7 @@ ] }, "blogpage-desc": "Blogging system with commenting and voting features, [[Special:CreateBlogPost|a special page to create blog posts]] and [[Special:ArticlesHome|a special page to list blog posts]]", + "apihelp-blogpage-example-1": "Check if there is already a blog page with the title \"My Cool New Blog Post\"", "blog-and": "and", "blog-anonymous-name": "Anonymous Fanatic", "blog-author-comments": "$1 {{PLURAL:$1|comment|comments}}", diff --git a/resources/js/CreateBlogPost.js b/resources/js/CreateBlogPost.js index 82fdb1c..bc86b8b 100644 --- a/resources/js/CreateBlogPost.js +++ b/resources/js/CreateBlogPost.js @@ -39,13 +39,13 @@ } $.post( - mw.util.wikiScript(), { - action: 'ajax', - rs: 'SpecialCreateBlogPost::checkTitleExistence', - rsargs: [ title ] + mw.util.wikiScript( 'api' ), { + action: 'blogpage', + format: 'json', + pageName: title }, - function ( r ) { - if ( r === 'OK' ) { + function ( data ) { + if ( data.blogpage.result === 'OK' ) { document.editform.submit(); } else { alert( mw.msg( 'blog-js-create-error-page-exists' ) ); -- To view, visit https://gerrit.wikimedia.org/r/272728 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I82f57eb04f53f0d778ff0953ef8cc705b11ac757 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/BlogPage Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
