r67951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67950‎ | r67951 | r67952 >
Date:14:36, 13 June 2010
Author:ialex
Status:deferred
Tags:
Comment:
* Use OutputPage::addStyle() and OutputPage::addScriptFile()
* Changed "global $action" to $wgRequest->getVal( 'action' )
* Use Html::(open|close)?element() instead of their Xml:: variant
* Added missing 'ajaxtest' message
Modified paths:
  • /trunk/extensions/AjaxShowEditors/Hooks.php (modified) (history)
  • /trunk/extensions/AjaxShowEditors/Response.php (modified) (history)
  • /trunk/extensions/AjaxTest/AjaxTest.i18n.php (modified) (history)
  • /trunk/extensions/AjaxTest/AjaxTest.php (modified) (history)
  • /trunk/extensions/AjaxTest/AjaxTestPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/AjaxShowEditors/Response.php
@@ -15,10 +15,9 @@
1616 */
1717 function wfAjaxShowEditors( $articleId, $username ) {
1818 global $wgOut;
 19+
1920 $articleId = intval( $articleId );
2021
21 - wfLoadExtensionMessages( 'AjaxShowEditors' );
22 -
2322 // Validate request
2423 $title = Title::newFromID( $articleId );
2524 if ( !( $title ) ) { return wfMsg( 'ajax-se-pagedoesnotexist' ); }
Index: trunk/extensions/AjaxShowEditors/Hooks.php
@@ -21,6 +21,7 @@
2222 */
2323 function wfAjaxShowEditorsCleanup( $article, $user ) {
2424 global $wgCommandLineMode;
 25+
2526 if ( $wgCommandLineMode ) {
2627 return true;
2728 }
@@ -40,24 +41,18 @@
4142
4243 // Only when editing a page
4344 function wfAjaxShowEditorsAddCSS( $out ) {
44 - global $action;
45 - if ( $action != 'edit' ) {
46 - return true;
 45+ global $wgRequest, $wgExtensionAssetsPath;
 46+
 47+ if ( $wgRequest->getVal( 'action' ) == 'edit' ) {
 48+ $out->addStyle( "$wgExtensionAssetsPath/AjaxShowEditors/AjaxShowEditors.css" );
4749 }
48 - global $wgScriptPath;
49 - $out->addLink(
50 - array(
51 - 'rel' => 'stylesheet',
52 - 'type' => 'text/css',
53 - 'href' => $wgScriptPath . '/extensions/AjaxShowEditors/AjaxShowEditors.css',
54 - )
55 - );
5650 return true;
5751 }
5852
5953 function wfAjaxShowEditorsAddJS( $out ) {
60 - global $wgJsMimeType, $wgScriptPath ;
61 - $out->addScript( "<script type=\"{$wgJsMimeType}\" src=\"$wgScriptPath/extensions/AjaxShowEditors/AjaxShowEditors.js\"></script>\n" );
 54+ global $wgExtensionAssetsPath;
 55+
 56+ $out->addScriptFile( "$wgExtensionAssetsPath/AjaxShowEditors/AjaxShowEditors.js" );
6257 return true;
6358 }
6459
@@ -65,8 +60,6 @@
6661 function wfAjaxShowEditorsShowBox( ) {
6762 global $wgOut;
6863
69 - wfLoadExtensionMessages( 'AjaxShowEditors' );
70 -
7164 $wgOut->addWikiText(
7265 '<div id="ajax-se"><p id="ajax-se-title">' . wfMsg( 'ajax-se-title' ) . '</p>'
7366 . '<p id="ajax-se-editors">' . wfMsg( 'ajax-se-pending' ) . '</p>'
Index: trunk/extensions/AjaxTest/AjaxTestPage.php
@@ -27,17 +27,12 @@
2828 * @param $par Parameters passed to the page
2929 */
3030 function execute( $par ) {
31 - global $wgRequest, $wgOut;
32 - global $wgJsMimeType, $wgScriptPath;
 31+ global $wgOut, $wgExtensionAssetsPath;
3332
3433 $this->setHeaders();
3534
36 - $wgOut->addScript(
37 - "<script type=\"{$wgJsMimeType}\" src=\"{$wgScriptPath}/extensions/AjaxTest/AjaxTest.js\">" .
38 - "</script>\n"
39 - );
 35+ $wgOut->addScriptFile( "$wgExtensionAssetsPath/AjaxTest/AjaxTest.js" );
4036
41 -
4237 $wgOut->addHTML( $this->makeInputForm() );
4338 }
4439
@@ -45,38 +40,37 @@
4641 * Input form for entering a category
4742 */
4843 function makeInputForm() {
49 - $thisTitle = SpecialPage::getTitleFor( $this->getName() );
5044 $form = '';
51 - $form .= Xml::openElement( 'form', array( 'name' => 'ajaxtest', 'method' => 'get', 'action' => $thisTitle->getLocalUrl() ) );
52 - $form .= Xml::element( 'input', array( 'type' => 'text', 'name' => 'ajaxtest_text', 'id' => 'ajaxtest_text', 'value' => '', 'size' => '64' ) ) . ' ';
53 - $form .= Xml::element( 'br' );
54 - $form .= Xml::element( 'label', array( 'for' => 'usestring' ), 'use string value' );
55 - $form .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => 'usestring', 'id' => 'usestring' ) );
56 - $form .= Xml::element( 'br' );
57 - $form .= Xml::element( 'label', array( 'for' => 'httpcache' ), 'use http cache' );
58 - $form .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => 'httpcache', 'id' => 'httpcache' ) );
59 - $form .= Xml::element( 'br' );
60 - $form .= Xml::element( 'label', array( 'for' => 'lastmod' ), 'use last modified' );
61 - $form .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => 'lastmod', 'id' => 'lastmod' ) );
62 - $form .= Xml::element( 'br' );
63 - $form .= Xml::element( 'label', array( 'for' => 'error' ), 'trigger error' );
64 - $form .= Xml::element( 'input', array( 'type' => 'checkbox', 'name' => 'error', 'id' => 'error' ) );
65 - $form .= Xml::element( 'br' );
66 - $form .= Xml::openElement( 'select', array( 'name' => 'ajaxtest_target', 'id' => 'ajaxtest_target' ) );
67 - $form .= Xml::element( 'option', array( 'value' => 'function' ), "function" );
68 - $form .= Xml::element( 'option', array( 'value' => 'element' ), "element" );
69 - $form .= Xml::element( 'option', array( 'value' => 'input' ), "input" );
70 - $form .= Xml::closeElement( 'select' );
71 - $form .= Xml::element( 'input', array( 'type' => 'button', 'onclick' => 'doAjaxTest();', 'value' => 'TEST' ) );
72 - $form .= Xml::element( 'input', array( 'type' => 'button', 'onclick' => 'clearAjaxTest();', 'value' => 'CLEAR' ) );
73 - # $form .= Xml::element( 'input', array( 'type' => 'button', 'onclick' => 'getElementById("ajaxtest_out").value= getElementById("ajaxtest_text").value;', 'value' => 'DUMMY' ) );
74 - $form .= Xml::closeElement( 'form' );
 45+ $form .= Html::openElement( 'form', array( 'name' => 'ajaxtest', 'method' => 'GET', 'action' => $this->getTitle()->getLocalUrl() ) );
 46+ $form .= Html::element( 'input', array( 'type' => 'text', 'name' => 'ajaxtest_text', 'id' => 'ajaxtest_text', 'value' => '', 'size' => '64' ) ) . ' ';
 47+ $form .= Html::element( 'br' );
 48+ $form .= Html::element( 'label', array( 'for' => 'usestring' ), 'use string value' );
 49+ $form .= Html::element( 'input', array( 'type' => 'checkbox', 'name' => 'usestring', 'id' => 'usestring' ) );
 50+ $form .= Html::element( 'br' );
 51+ $form .= Html::element( 'label', array( 'for' => 'httpcache' ), 'use http cache' );
 52+ $form .= Html::element( 'input', array( 'type' => 'checkbox', 'name' => 'httpcache', 'id' => 'httpcache' ) );
 53+ $form .= Html::element( 'br' );
 54+ $form .= Html::element( 'label', array( 'for' => 'lastmod' ), 'use last modified' );
 55+ $form .= Html::element( 'input', array( 'type' => 'checkbox', 'name' => 'lastmod', 'id' => 'lastmod' ) );
 56+ $form .= Html::element( 'br' );
 57+ $form .= Html::element( 'label', array( 'for' => 'error' ), 'trigger error' );
 58+ $form .= Html::element( 'input', array( 'type' => 'checkbox', 'name' => 'error', 'id' => 'error' ) );
 59+ $form .= Html::element( 'br' );
 60+ $form .= Html::openElement( 'select', array( 'name' => 'ajaxtest_target', 'id' => 'ajaxtest_target' ) );
 61+ $form .= Html::element( 'option', array( 'value' => 'function' ), "function" );
 62+ $form .= Html::element( 'option', array( 'value' => 'element' ), "element" );
 63+ $form .= Html::element( 'option', array( 'value' => 'input' ), "input" );
 64+ $form .= Html::closeElement( 'select' );
 65+ $form .= Html::element( 'input', array( 'type' => 'button', 'onclick' => 'doAjaxTest();', 'value' => 'TEST' ) );
 66+ $form .= Html::element( 'input', array( 'type' => 'button', 'onclick' => 'clearAjaxTest();', 'value' => 'CLEAR' ) );
 67+ # $form .= Html::element( 'input', array( 'type' => 'button', 'onclick' => 'getElementById("ajaxtest_out").value= getElementById("ajaxtest_text").value;', 'value' => 'DUMMY' ) );
 68+ $form .= Html::closeElement( 'form' );
7569
76 - $form .= Xml::element( 'hr' );
77 - $form .= Xml::element( 'input', array( 'type' => 'text', 'name' => 'ajaxtest_out', 'id' => 'ajaxtest_out', 'value' => '', 'size' => '64' ) ) . ' ';
78 - $form .= Xml::element( 'p', array( 'id' => 'ajaxtest_area' ) );
79 - $form .= Xml::element( 'hr' );
80 - $form .= Xml::element( 'p', array( 'id' => 'sajax_debug' ) );
 70+ $form .= Html::element( 'hr' );
 71+ $form .= Html::element( 'input', array( 'type' => 'text', 'name' => 'ajaxtest_out', 'id' => 'ajaxtest_out', 'value' => '', 'size' => '64' ) ) . ' ';
 72+ $form .= Html::element( 'p', array( 'id' => 'ajaxtest_area' ) );
 73+ $form .= Html::element( 'hr' );
 74+ $form .= Html::element( 'p', array( 'id' => 'sajax_debug' ) );
8175 return $form;
8276 }
8377 }
Index: trunk/extensions/AjaxTest/AjaxTest.i18n.php
@@ -9,5 +9,6 @@
1010 $messages = array();
1111
1212 $messages['en'] = array(
13 - 'ajaxtest-desc' => '[[Special:AjaxTest|AjaxTest]] extension',
 13+ 'ajaxtest' => 'Ajax Test',
 14+ 'ajaxtest-desc' => '[[Special:AjaxTest|AjaxTest]] extension',
1415 );
Index: trunk/extensions/AjaxTest/AjaxTest.php
@@ -38,6 +38,7 @@
3939 $dir = dirname( __FILE__ ) . '/';
4040 $wgExtensionMessagesFiles['AjaxTest'] = $dir . 'AjaxTest.i18n.php';
4141 $wgExtensionAliasesFiles['AjaxTest'] = $dir . 'AjaxTest.alias.php';
 42+$wgAutoloadClasses['AjaxTestPage'] = $dir . 'AjaxTestPage.php';
4243
4344 /**
4445 * register Ajax function

Status & tagging log