MediaWiki r108096 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r108095‎ | r108096 (on ViewVC)‎ | r108097 >
Date:23:11, 4 January 2012
Author:ashley
Status:ok
Tags:
Comment:
BlogPage: ResourceLoader fixes, dropped backwards compatibility and of course, the obligatory version number bump.
I had to take out the edit buttons from Special:CreateBlogPost because the current edit page JS (resources/mediawiki.action/mediawiki.action.edit.js) doesn't seem to be flexible enough and I didn't feel like duplicating lots and lots of both PHP and JS code.
Modified paths:

Diff [purge]

Index: trunk/extensions/BlogPage/SpecialCreateBlogPost.php
@@ -5,7 +5,7 @@
66 *
77 * @file
88 * @ingroup Extensions
9 - * @date 16 July 2011
 9+ * @date 4 January 2012
1010 */
1111 class SpecialCreateBlogPost extends SpecialPage {
1212
@@ -24,7 +24,7 @@
2525 * @param $par Mixed: parameter passed to the special page or null
2626 */
2727 public function execute( $par ) {
28 - global $wgOut, $wgUser, $wgRequest, $wgContLang, $wgScriptPath, $wgHooks;
 28+ global $wgOut, $wgUser, $wgRequest, $wgContLang;
2929
3030 // If the user can't create blog posts, display an error
3131 if( !$wgUser->isAllowed( 'createblogpost' ) ) {
@@ -47,19 +47,8 @@
4848 // Set page title, robot policies, etc.
4949 $this->setHeaders();
5050
51 - // i18n for JS
52 - $wgHooks['MakeGlobalVariablesScript'][] = 'SpecialCreateBlogPost::addJSGlobals';
53 -
5451 // Add CSS & JS
55 - if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
56 - $wgOut->addModules( array(
57 - 'mediawiki.legacy.edit', 'ext.blogPage.create'
58 - ) );
59 - } else {
60 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/BlogPage/CreateBlogPost.css' );
61 - $wgOut->addScriptFile( $wgScriptPath . '/extensions/BlogPage/CreateBlogPost.js' );
62 - $wgOut->addScriptFile( 'edit.js' ); // for the edit toolbar
63 - }
 52+ $wgOut->addModules( 'ext.blogPage.create' );
6453
6554 // If the request was POSTed, we haven't submitted a request yet AND
6655 // we have a title, create the page...otherwise just display the
@@ -225,7 +214,11 @@
226215 '</span><br />';
227216 // The EditPage toolbar wasn't originally present here but I figured
228217 // that adding it might be more helpful than anything else.
229 - $output .= EditPage::getEditToolbar();
 218+ // Guess what...turns out that resources/mediawiki.action/mediawiki.action.edit.js
 219+ // assumes way too many things and no longer is suitable for different
 220+ // editing interfaces, such as this special page.
 221+ // I miss the old edit.js...
 222+ //$output .= EditPage::getEditToolbar();
230223 $output .= '<textarea class="createbox" tabindex="' .
231224 $this->tabCounter . '" accesskey="," name="pageBody" id="pageBody" rows="10" cols="80"></textarea><br /><br />';
232225 $this->tabCounter++;
@@ -253,7 +246,7 @@
254247 $slashedTag = str_replace( "'", "\'", $tag );
255248 }
256249 $tagcloud .= " <span id=\"tag-{$tagnumber}\" style=\"font-size:{$cloud->tags[$tag]['size']}{$cloud->tags_size_type}\">
257 - <a class=\"tag-cloud-entry\" onclick=\"javascript:CreateBlogPost.insertTag('" . $slashedTag . "',{$tagnumber});\">{$tag}</a>
 250+ <a class=\"tag-cloud-entry\" data-blog-slashed-tag=\"" . $slashedTag . "\" data-blog-tag-number=\"{$tagnumber}\">{$tag}</a>
258251 </span>";
259252 $tagnumber++;
260253 }
@@ -313,8 +306,8 @@
314307
315308 $output .= "\n" . $this->displayFormPageCategories() . "\n";
316309 $output .= "\n" . $this->displayCopyrightWarning() . "\n";
317 - $output .= '<input type="button" onclick="CreateBlogPost.performChecks()" value="' .
318 - wfMsg( 'blog-create-button' ) . '" name="wpSave" class="createsubmit site-button" accesskey="s" title="' .
 310+ $output .= '<input type="button" value="' . wfMsg( 'blog-create-button' ) .
 311+ '" name="wpSave" class="createsubmit site-button" accesskey="s" title="' .
319312 wfMsg( 'tooltip-save' ) . ' [alt-s]" />
320313 <input type="hidden" value="" name="wpSection" />
321314 <input type="hidden" value="" name="wpEdittime" />
@@ -352,17 +345,4 @@
353346 return 'OK';
354347 }
355348 }
356 -
357 - /**
358 - * Add i18n messages for the JS file.
359 - *
360 - * @param $vars Array: array of pre-existing JavaScript globals
361 - * @return Boolean: true
362 - */
363 - public static function addJSGlobals( $vars ) {
364 - $vars['_BLOG_NEEDS_CONTENT'] = wfMsg( 'blog-js-create-error-need-content' );
365 - $vars['_BLOG_NEEDS_TITLE'] = wfMsg( 'blog-js-create-error-need-title' );
366 - $vars['_BLOG_PAGE_EXISTS'] = wfMsg( 'blog-js-create-error-page-exists' );
367 - return true;
368 - }
369349 }
\ No newline at end of file
Index: trunk/extensions/BlogPage/SpecialArticlesHome.php
@@ -30,11 +30,7 @@
3131 $wgSupressPageTitle = true;
3232
3333 // Add CSS
34 - if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
35 - $wgOut->addModules( 'ext.blogPage.articlesHome' );
36 - } else {
37 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/BlogPage/ArticlesHome.css' );
38 - }
 34+ $wgOut->addModules( 'ext.blogPage.articlesHome' );
3935
4036 if( !$type ) {
4137 $type = 'popular';
Index: trunk/extensions/BlogPage/CreateBlogPost.js
@@ -27,12 +27,12 @@
2828 // name
2929 var title = document.getElementById( 'title' ).value;
3030 if ( !title || title == '' ) {
31 - alert( _BLOG_NEEDS_TITLE );
 31+ alert( mw.msg( 'blog-js-create-error-need-title' ) );
3232 return '';
3333 }
3434 var pageBody = document.getElementById( 'pageBody' ).value;
3535 if ( !pageBody || pageBody == '' ) {
36 - alert( _BLOG_NEEDS_CONTENT );
 36+ alert( mw.msg( 'blog-js-create-error-need-content' ) );
3737 return '';
3838 }
3939
@@ -41,8 +41,26 @@
4242 if( r.responseText.indexOf( 'OK' ) >= 0 ) {
4343 document.editform.submit();
4444 } else {
45 - alert( _BLOG_PAGE_EXISTS );
 45+ alert( mw.msg( 'blog-js-create-error-page-exists' ) );
4646 }
4747 });
4848 }
49 -};
\ No newline at end of file
 49+};
 50+
 51+jQuery( document ).ready( function() {
 52+ // Tag cloud
 53+ jQuery( 'a.tag-cloud-entry' ).each( function( index ) {
 54+ var that = jQuery( this );
 55+ that.click( function() {
 56+ CreateBlogPost.insertTag(
 57+ that.data( 'blog-slashed-tag' ),
 58+ that.data( 'blog-tag-number' )
 59+ );
 60+ } );
 61+ } );
 62+
 63+ // Save button
 64+ jQuery( 'input[name="wpSave"]' ).click( function() {
 65+ CreateBlogPost.performChecks();
 66+ } );
 67+} );
\ No newline at end of file
Index: trunk/extensions/BlogPage/Blog.php
@@ -5,7 +5,7 @@
66 *
77 * @file
88 * @ingroup Extensions
9 - * @version 2.0
 9+ * @version 2.1
1010 * @author David Pean <david.pean@gmail.com>
1111 * @author Jack Phoenix <jack@countervandalism.net>
1212 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
@@ -18,7 +18,7 @@
1919 // Extension credits that will show up on Special:Version
2020 $wgExtensionCredits['other'][] = array(
2121 'name' => 'BlogPage',
22 - 'version' => '2.0',
 22+ 'version' => '2.1',
2323 'author' => array( 'David Pean', 'Jack Phoenix' ),
2424 'description' => 'Blogging system with commenting and voting features, ' .
2525 '[[Special:CreateBlogPost|a special page to create blog posts]] and ' .
@@ -50,11 +50,11 @@
5151 $wgResourceModules['ext.blogPage.create'] = $blogResourceTemplate + array(
5252 'styles' => 'CreateBlogPost.css',
5353 'scripts' => 'CreateBlogPost.js',
 54+ //'dependencies' => 'mediawiki.action.edit',
5455 'messages' => array(
5556 'blog-js-create-error-need-content', 'blog-js-create-error-need-title',
5657 'blog-js-create-error-page-exists'
57 - ),
58 - 'position' => 'top' // available since r85616
 58+ )
5959 );
6060
6161 // Default setup for displaying sections
Index: trunk/extensions/BlogPage/SpecialArticleLists.php
@@ -34,11 +34,7 @@
3535 // @todo FIXME: this should be loaded when including the special page,
3636 // too, but if ( $this->including() ) does nothing, prolly because of
3737 // the parser cache
38 - if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
39 - $wgOut->addModules( 'ext.blogPage.articlesHome' );
40 - } else {
41 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/BlogPage/ArticlesHome.css' );
42 - }
 38+ $wgOut->addModules( 'ext.blogPage.articlesHome' );
4339
4440 $imgPath = $wgScriptPath . '/extensions/BlogPage/images/';
4541
Index: trunk/extensions/BlogPage/BlogHooks.php
@@ -36,11 +36,7 @@
3737 $wgOut->enableClientCache( false );
3838
3939 // Add CSS
40 - if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
41 - $wgOut->addModules( 'ext.blogPage' );
42 - } else {
43 - $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/BlogPage/BlogPage.css' );
44 - }
 40+ $wgOut->addModules( 'ext.blogPage' );
4541
4642 // This originally used $wgTitle but I saw no point in that, so I
4743 // changed that as per Chad et al.
@@ -59,6 +55,7 @@
6056 */
6157 public static function allowShowEditBlogPage( $editPage ) {
6258 global $wgOut, $wgUser;
 59+
6360 if( $editPage->mTitle->getNamespace() == NS_BLOG ) {
6461 if( $wgUser->isAnon() ) { // anons can't edit blog pages
6562 if( !$editPage->mTitle->exists() ) {
@@ -74,6 +71,7 @@
7572 return false;
7673 }
7774 }
 75+
7876 return true;
7977 }
8078

Status & tagging log

  • 01:42, 1 March 2012 Krinkle (Talk | contribs) changed the tags for r108096 [removed: frontend]
  • 17:43, 16 January 2012 ^demon (Talk | contribs) changed the status of r108096 [removed: new added: ok]
  • 14:24, 15 January 2012 Jack Phoenix (Talk | contribs) changed the status of r108096 [removed: deferred added: new]
  • 16:38, 6 January 2012 Reedy (Talk | contribs) changed the status of r108096 [removed: new added: deferred]
  • 00:49, 5 January 2012 Johnduhart (Talk | contribs) changed the tags for r108096 [added: frontend]
Personal tools
Namespaces

Variants
Views
Actions
Navigation
Support
Download
Development
Communication
Toolbox