Index: trunk/extensions/TidyTab/Tidy.php |
— | — | @@ -7,7 +7,6 @@ |
8 | 8 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
9 | 9 | */ |
10 | 10 | |
11 | | -$wgExtensionFunctions[] = 'wfTidy'; |
12 | 11 | $wgExtensionCredits['other'][] = array( |
13 | 12 | 'path' => __FILE__, |
14 | 13 | 'name' => 'TidyTab', |
— | — | @@ -20,64 +19,53 @@ |
21 | 20 | $dir = dirname(__FILE__) . '/'; |
22 | 21 | $wgExtensionMessagesFiles['tidy'] = $dir . 'Tidy.i18n.php'; |
23 | 22 | |
24 | | -function wfTidy() { |
25 | | - wfUsePHP( 5.1 ); |
26 | | - wfUseMW( '1.6alpha' ); |
| 23 | +$wgHooks['SkinTemplateNavigation::Universal'][] = 'TidyAction::tidyHook'; |
| 24 | +$wgHooks['UnknownAction'][] = 'TidyAction::action'; |
27 | 25 | |
28 | | - class TidyAction { |
29 | | - public function __construct() { |
30 | | - global $wgUseTidy, $wgHooks; |
31 | | - wfLoadExtensionMessages( 'tidy' ); |
| 26 | +class TidyAction { |
32 | 27 | |
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; |
36 | 30 | |
37 | | - public function tidyHook( array &$content_actions ) { |
38 | | - global $wgRequest, $wgUseTidy, $wgTitle; |
| 31 | + $title = $skin->getTitle(); |
| 32 | + $action = $wgRequest->getText( 'action' ); |
39 | 33 | |
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 | + } |
51 | 42 | } |
52 | 43 | |
53 | | - private static function setTidy( array &$content_actions, $action, $tidy ) { |
54 | | - global $wgTitle; |
| 44 | + return true; |
| 45 | + } |
55 | 46 | |
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 | + } |
69 | 61 | |
70 | | - public static function action( $action, Article &$article ) { |
71 | | - global $wgUseTidy; |
| 62 | + public static function action( $action, Article $article ) { |
| 63 | + global $wgUseTidy; |
72 | 64 | |
73 | | - if ( $action === 'tidy' || $action === 'untidy' ) |
74 | | - $wgUseTidy = $action === 'tidy'; |
| 65 | + if ( $action === 'tidy' || $action === 'untidy' ) |
| 66 | + $wgUseTidy = $action === 'tidy'; |
75 | 67 | |
76 | | - $article->purge(); |
| 68 | + $article->purge(); |
77 | 69 | |
78 | | - return false; |
79 | | - } |
| 70 | + return false; |
80 | 71 | } |
81 | | - |
82 | | - // Establish a singleton. |
83 | | - new TidyAction; |
84 | 72 | } |