http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84542

Revision: 84542
Author:   ialex
Date:     2011-03-22 18:05:05 +0000 (Tue, 22 Mar 2011)
Log Message:
-----------
* 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: trunk/extensions/TidyTab/Tidy.php
===================================================================
--- trunk/extensions/TidyTab/Tidy.php   2011-03-22 17:49:16 UTC (rev 84541)
+++ trunk/extensions/TidyTab/Tidy.php   2011-03-22 18:05:05 UTC (rev 84542)
@@ -7,7 +7,6 @@
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
  */
 
-$wgExtensionFunctions[] = 'wfTidy';
 $wgExtensionCredits['other'][] = array(
        'path'           => __FILE__,
        'name'           => 'TidyTab',
@@ -20,64 +19,53 @@
 $dir = dirname(__FILE__) . '/';
 $wgExtensionMessagesFiles['tidy'] = $dir . 'Tidy.i18n.php';
 
-function wfTidy() {
-       wfUsePHP( 5.1 );
-       wfUseMW( '1.6alpha' );
+$wgHooks['SkinTemplateNavigation::Universal'][] = 'TidyAction::tidyHook';
+$wgHooks['UnknownAction'][] = 'TidyAction::action';
 
-       class TidyAction {
-               public function __construct() {
-                       global $wgUseTidy, $wgHooks;
-                       wfLoadExtensionMessages( 'tidy' );
+class TidyAction {
 
-                       $wgHooks['SkinTemplateContentActions'][] = array( 
&$this, 'tidyHook' );
-                       $wgHooks['UnknownAction'][] = array( &$this, 'action' );
-               }
+       public static function tidyHook( $skin, array &$content_actions ) {
+               global $wgRequest, $wgUseTidy;
 
-               public function tidyHook( array &$content_actions ) {
-                       global $wgRequest, $wgUseTidy, $wgTitle;
+               $title = $skin->getTitle();
+               $action = $wgRequest->getText( 'action' );
 
-                       $action = $wgRequest->getText( 'action' );
-
-                       if ( $wgTitle->getNamespace() !== NS_SPECIAL )
-                               if ( $action === 'tidy' || $action === 'untidy' 
)
-                                       self::setTidy( $content_actions, 
$action, $action === 'tidy' );
-                               else if ( $wgUseTidy )
-                                       self::setTidy( $content_actions, 
$action, false );
-                               else
-                                       self::setTidy( $content_actions, 
$action, true );
-
-                       return true;
+               if ( $title->getNamespace() !== NS_SPECIAL ) {
+                       if ( $action === 'tidy' || $action === 'untidy' ) {
+                               self::setTidy( $title, $content_actions, 
$action, $action === 'tidy' );
+                       } elseif ( $wgUseTidy ) {
+                               self::setTidy( $title, $content_actions, 
$action, false );
+                       } else {
+                               self::setTidy( $title, $content_actions, 
$action, true );
+                       }
                }
 
-               private static function setTidy( array &$content_actions, 
$action, $tidy ) {
-                       global $wgTitle;
+               return true;
+       }
 
-                       if ( $tidy )
-                               $content_actions['tidy'] = array(
-                                       'class' => $action === 'tidy' ? 
'selected' : false,
-                                       'text' => wfMsg( 'tidy' ),
-                                       'href' => $wgTitle->getLocalUrl( 
'action=tidy' )
-                               );
-                       else
-                               $content_actions['untidy'] = array(
-                                       'class' => $action === 'untidy' ? 
'selected' : false,
-                                       'text' => wfMsg( 'untidy' ),
-                                       'href' => $wgTitle->getLocalUrl( 
'action=untidy' )
-                               );
-               }
+       private static function setTidy( $title, array &$content_actions, 
$action, $tidy ) {
+               if ( $tidy )
+                       $content_actions['actions']['tidy'] = array(
+                               'class' => $action === 'tidy' ? 'selected' : 
false,
+                               'text' => wfMsg( 'tidy' ),
+                               'href' => $title->getLocalUrl( 'action=tidy' )
+                       );
+               else
+                       $content_actions['actions']['untidy'] = array(
+                               'class' => $action === 'untidy' ? 'selected' : 
false,
+                               'text' => wfMsg( 'untidy' ),
+                               'href' => $title->getLocalUrl( 'action=untidy' )
+                       );
+       }
 
-               public static function action( $action, Article &$article ) {
-                       global $wgUseTidy;
+       public static function action( $action, Article $article ) {
+               global $wgUseTidy;
 
-                       if ( $action === 'tidy' || $action === 'untidy' )
-                               $wgUseTidy = $action === 'tidy';
+               if ( $action === 'tidy' || $action === 'untidy' )
+                       $wgUseTidy = $action === 'tidy';
 
-                       $article->purge();
+               $article->purge();
 
-                       return false;
-               }
+               return false;
        }
-
-       // Establish a singleton.
-       new TidyAction;
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to