r84542 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84541‎ | r84542 | r84543 >
Date:18:05, 22 March 2011
Author:ialex
Status:deferred
Tags:
Comment:
* Removed usage of extension to define the class and set hooks; just do this while including the file.
* Changed methods to be static.
* Fixed TidyAction::action()'s signature
* Removed usage of $wgTitle
Modified paths:
  • /trunk/extensions/TidyTab/Tidy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TidyTab/Tidy.php
@@ -7,7 +7,6 @@
88 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
99 */
1010
11 -$wgExtensionFunctions[] = 'wfTidy';
1211 $wgExtensionCredits['other'][] = array(
1312 'path' => __FILE__,
1413 'name' => 'TidyTab',
@@ -20,64 +19,53 @@
2120 $dir = dirname(__FILE__) . '/';
2221 $wgExtensionMessagesFiles['tidy'] = $dir . 'Tidy.i18n.php';
2322
24 -function wfTidy() {
25 - wfUsePHP( 5.1 );
26 - wfUseMW( '1.6alpha' );
 23+$wgHooks['SkinTemplateNavigation::Universal'][] = 'TidyAction::tidyHook';
 24+$wgHooks['UnknownAction'][] = 'TidyAction::action';
2725
28 - class TidyAction {
29 - public function __construct() {
30 - global $wgUseTidy, $wgHooks;
31 - wfLoadExtensionMessages( 'tidy' );
 26+class TidyAction {
3227
33 - $wgHooks['SkinTemplateContentActions'][] = array( &$this, 'tidyHook' );
34 - $wgHooks['UnknownAction'][] = array( &$this, 'action' );
35 - }
 28+ public static function tidyHook( $skin, array &$content_actions ) {
 29+ global $wgRequest, $wgUseTidy;
3630
37 - public function tidyHook( array &$content_actions ) {
38 - global $wgRequest, $wgUseTidy, $wgTitle;
 31+ $title = $skin->getTitle();
 32+ $action = $wgRequest->getText( 'action' );
3933
40 - $action = $wgRequest->getText( 'action' );
41 -
42 - if ( $wgTitle->getNamespace() !== NS_SPECIAL )
43 - if ( $action === 'tidy' || $action === 'untidy' )
44 - self::setTidy( $content_actions, $action, $action === 'tidy' );
45 - else if ( $wgUseTidy )
46 - self::setTidy( $content_actions, $action, false );
47 - else
48 - self::setTidy( $content_actions, $action, true );
49 -
50 - return true;
 34+ if ( $title->getNamespace() !== NS_SPECIAL ) {
 35+ if ( $action === 'tidy' || $action === 'untidy' ) {
 36+ self::setTidy( $title, $content_actions, $action, $action === 'tidy' );
 37+ } elseif ( $wgUseTidy ) {
 38+ self::setTidy( $title, $content_actions, $action, false );
 39+ } else {
 40+ self::setTidy( $title, $content_actions, $action, true );
 41+ }
5142 }
5243
53 - private static function setTidy( array &$content_actions, $action, $tidy ) {
54 - global $wgTitle;
 44+ return true;
 45+ }
5546
56 - if ( $tidy )
57 - $content_actions['tidy'] = array(
58 - 'class' => $action === 'tidy' ? 'selected' : false,
59 - 'text' => wfMsg( 'tidy' ),
60 - 'href' => $wgTitle->getLocalUrl( 'action=tidy' )
61 - );
62 - else
63 - $content_actions['untidy'] = array(
64 - 'class' => $action === 'untidy' ? 'selected' : false,
65 - 'text' => wfMsg( 'untidy' ),
66 - 'href' => $wgTitle->getLocalUrl( 'action=untidy' )
67 - );
68 - }
 47+ private static function setTidy( $title, array &$content_actions, $action, $tidy ) {
 48+ if ( $tidy )
 49+ $content_actions['actions']['tidy'] = array(
 50+ 'class' => $action === 'tidy' ? 'selected' : false,
 51+ 'text' => wfMsg( 'tidy' ),
 52+ 'href' => $title->getLocalUrl( 'action=tidy' )
 53+ );
 54+ else
 55+ $content_actions['actions']['untidy'] = array(
 56+ 'class' => $action === 'untidy' ? 'selected' : false,
 57+ 'text' => wfMsg( 'untidy' ),
 58+ 'href' => $title->getLocalUrl( 'action=untidy' )
 59+ );
 60+ }
6961
70 - public static function action( $action, Article &$article ) {
71 - global $wgUseTidy;
 62+ public static function action( $action, Article $article ) {
 63+ global $wgUseTidy;
7264
73 - if ( $action === 'tidy' || $action === 'untidy' )
74 - $wgUseTidy = $action === 'tidy';
 65+ if ( $action === 'tidy' || $action === 'untidy' )
 66+ $wgUseTidy = $action === 'tidy';
7567
76 - $article->purge();
 68+ $article->purge();
7769
78 - return false;
79 - }
 70+ return false;
8071 }
81 -
82 - // Establish a singleton.
83 - new TidyAction;
8472 }

Status & tagging log