Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -48,9 +48,10 @@ |
49 | 49 | $wgExtensionMessagesFiles['TranslateGroupDescriptions'] = $dir . 'TranslateGroupDescriptions.i18n.php'; |
50 | 50 | $wgExtensionAliasesFiles['Translate'] = $dir . 'Translate.alias.php'; |
51 | 51 | |
52 | | -// Register initialization hook |
53 | | -$wgExtensionFunctions[] = 'efTranslateInit'; |
54 | | -$wgHooks['CanonicalNamespaces'][] = 'efTranslateNamespaces'; |
| 52 | +// Register initialization code |
| 53 | +$wgExtensionFunctions[] = 'TranslateHooks::setupTranslate'; |
| 54 | +$wgHooks['CanonicalNamespaces'][] = 'TranslateHooks::setupNamespaces'; |
| 55 | +$wgHooks['UnitTestsList'][] = 'TranslateHooks::setupUnitTests'; |
55 | 56 | |
56 | 57 | // Register special pages into MediaWiki |
57 | 58 | $wgSpecialPages['Translate'] = 'SpecialTranslate'; |
— | — | @@ -118,8 +119,6 @@ |
119 | 120 | |
120 | 121 | $wgHooks['LinkBegin'][] = 'SpecialMyLanguage::linkfix'; |
121 | 122 | |
122 | | -$wgHooks['UnitTestsList'][] = 'efTranslateAppendTestsToVariable'; |
123 | | - |
124 | 123 | // New rights |
125 | 124 | $wgAvailableRights[] = 'translate'; |
126 | 125 | $wgAvailableRights[] = 'translate-import'; |
— | — | @@ -507,160 +506,6 @@ |
508 | 507 | $wgTranslateYamlLibrary = 'spyc'; |
509 | 508 | |
510 | 509 | |
511 | | -# Startup code |
512 | | -function efTranslateNamespaces( &$list ) { |
513 | | - global $wgPageTranslationNamespace; |
514 | | - if ( !defined( 'NS_TRANSLATIONS' ) ) { |
515 | | - define( 'NS_TRANSLATIONS', $wgPageTranslationNamespace ); |
516 | | - define( 'NS_TRANSLATIONS_TALK', $wgPageTranslationNamespace + 1 ); |
517 | | - } |
518 | | - $list[NS_TRANSLATIONS] = 'Translations'; |
519 | | - $list[NS_TRANSLATIONS_TALK] = 'Translations_talk'; |
520 | | - return true; |
521 | | -} |
522 | | - |
523 | | -/** |
524 | | - * Initialises the extension. |
525 | | - * Does late-initialization that is not possible at file level, |
526 | | - * because it depends on user configuration. |
527 | | - * @private |
528 | | - */ |
529 | | -function efTranslateInit() { |
530 | | - global $wgTranslatePHPlot, $wgAutoloadClasses, $wgHooks; |
531 | | - |
532 | | - if ( $wgTranslatePHPlot ) { |
533 | | - $wgAutoloadClasses['PHPlot'] = $wgTranslatePHPlot; |
534 | | - } |
535 | | - |
536 | | - global $wgReservedUsernames, $wgTranslateFuzzyBotName; |
537 | | - $wgReservedUsernames[] = $wgTranslateFuzzyBotName; |
538 | | - |
539 | | - // Hook for database schema. |
540 | | - $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
541 | | - |
542 | | - // Fuzzy tags for speed. |
543 | | - $wgHooks['ArticleSaveComplete'][] = 'TranslateEditAddons::onSave'; |
544 | | - |
545 | | - // Page translation setup check and init if enabled. |
546 | | - if ( $wgEnablePageTranslation ) { |
547 | | - // Special page and the right to use it |
548 | | - global $wgSpecialPages, $wgAvailableRights, $wgSpecialPageGroups; |
549 | | - $wgSpecialPages['PageTranslation'] = 'SpecialPageTranslation'; |
550 | | - $wgSpecialPageGroups['PageTranslation'] = 'pagetools'; |
551 | | - $wgSpecialPages['PageTranslationDeletePage'] = 'SpecialPageTranslationDeletePage'; |
552 | | - $wgSpecialPageGroups['PageTranslationDeletePage'] = 'pagetools'; |
553 | | - $wgAvailableRights[] = 'pagetranslation'; |
554 | | - |
555 | | - global $wgLogNames, $wgLogActionsHandlers, $wgLogTypes, $wgLogHeaders; |
556 | | - $wgLogTypes[] = 'pagetranslation'; |
557 | | - $wgLogHeaders['pagetranslation'] = 'pt-log-header'; |
558 | | - $wgLogNames['pagetranslation'] = 'pt-log-name'; |
559 | | - $wgLogActionsHandlers['pagetranslation/mark'] = 'PageTranslationHooks::formatLogEntry'; |
560 | | - $wgLogActionsHandlers['pagetranslation/unmark'] = 'PageTranslationHooks::formatLogEntry'; |
561 | | - $wgLogActionsHandlers['pagetranslation/moveok'] = 'PageTranslationHooks::formatLogEntry'; |
562 | | - $wgLogActionsHandlers['pagetranslation/movenok'] = 'PageTranslationHooks::formatLogEntry'; |
563 | | - $wgLogActionsHandlers['pagetranslation/deletelok'] = 'PageTranslationHooks::formatLogEntry'; |
564 | | - $wgLogActionsHandlers['pagetranslation/deletefok'] = 'PageTranslationHooks::formatLogEntry'; |
565 | | - $wgLogActionsHandlers['pagetranslation/deletelnok'] = 'PageTranslationHooks::formatLogEntry'; |
566 | | - $wgLogActionsHandlers['pagetranslation/deletefnok'] = 'PageTranslationHooks::formatLogEntry'; |
567 | | - |
568 | | - |
569 | | - global $wgJobClasses; |
570 | | - $wgJobClasses['RenderJob'] = 'RenderJob'; |
571 | | - $wgJobClasses['MoveJob'] = 'MoveJob'; |
572 | | - $wgJobClasses['DeleteJob'] = 'DeleteJob'; |
573 | | - |
574 | | - // Namespaces |
575 | | - global $wgPageTranslationNamespace, $wgExtraNamespaces; |
576 | | - global $wgNamespacesWithSubpages, $wgNamespaceProtection; |
577 | | - global $wgTranslateMessageNamespaces, $wgVersion; |
578 | | - |
579 | | - // Define constants for more readable core |
580 | | - if ( !defined( 'NS_TRANSLATIONS' ) ) { |
581 | | - define( 'NS_TRANSLATIONS', $wgPageTranslationNamespace ); |
582 | | - define( 'NS_TRANSLATIONS_TALK', $wgPageTranslationNamespace + 1 ); |
583 | | - } |
584 | | - |
585 | | - if ( version_compare( $wgVersion, '1.17alpha', '<' ) ) { |
586 | | - efTranslateNamespaces( $wgExtraNamespaces ); |
587 | | - } |
588 | | - |
589 | | - $wgNamespacesWithSubpages[NS_TRANSLATIONS] = true; |
590 | | - $wgNamespacesWithSubpages[NS_TRANSLATIONS_TALK] = true; |
591 | | - |
592 | | - // Standard protection and register it for filtering |
593 | | - $wgNamespaceProtection[NS_TRANSLATIONS] = array( 'translate' ); |
594 | | - $wgTranslateMessageNamespaces[] = NS_TRANSLATIONS; |
595 | | - |
596 | | - /// Page translation hooks |
597 | | - |
598 | | - /// @todo Register our css, is there a better place for this? |
599 | | - $wgHooks['OutputPageBeforeHTML'][] = 'PageTranslationHooks::injectCss'; |
600 | | - |
601 | | - // Add transver tags and update translation target pages |
602 | | - $wgHooks['ArticleSaveComplete'][] = 'PageTranslationHooks::onSectionSave'; |
603 | | - |
604 | | - // Register \<languages/> |
605 | | - $wgHooks['ParserFirstCallInit'][] = 'efTranslateInitTags'; |
606 | | - |
607 | | - // Strip \<translate> tags etc. from source pages when rendering |
608 | | - $wgHooks['ParserBeforeStrip'][] = 'PageTranslationHooks::renderTagPage'; |
609 | | - |
610 | | - // Check syntax for \<translate> |
611 | | - $wgHooks['ArticleSave'][] = 'PageTranslationHooks::tpSyntaxCheck'; |
612 | | - $wgHooks['EditFilterMerged'][] = 'PageTranslationHooks::tpSyntaxCheckForEditPage'; |
613 | | - |
614 | | - // Set the page content language |
615 | | - $wgHooks['PageContentLanguage'][] = 'PageTranslationHooks::onPageContentLanguage'; |
616 | | - |
617 | | - // Add transtag to page props for discovery |
618 | | - $wgHooks['ArticleSaveComplete'][] = 'PageTranslationHooks::addTranstag'; |
619 | | - |
620 | | - // Prevent editing of unknown pages in Translations namespace |
621 | | - $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventUnknownTranslations'; |
622 | | - // Prevent editing of translation pages directly |
623 | | - $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventDirectEditing'; |
624 | | - |
625 | | - // Locking during page moves |
626 | | - $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::lockedPagesCheck'; |
627 | | - |
628 | | - // Our custom header for translation pages |
629 | | - $wgHooks['ArticleViewHeader'][] = 'PageTranslationHooks::test'; |
630 | | - |
631 | | - // Our tables are needed for parser tests |
632 | | - $wgHooks['ParserTestTables'][] = 'PageTranslationHooks::parserTestTables'; |
633 | | - |
634 | | - // Prevent section pages appearing in categories |
635 | | - $wgHooks['LinksUpdate'][] = 'PageTranslationHooks::preventCategorization'; |
636 | | - |
637 | | - // Custom move page that can move all the associated pages too |
638 | | - $wgHooks['SpecialPage_initList'][] = 'PageTranslationHooks::replaceMovePage'; |
639 | | - |
640 | | - // Replace subpage logic behaviour |
641 | | - $wgHooks['SkinSubPageSubtitle'][] = 'PageTranslationHooks::replaceSubtitle'; |
642 | | - |
643 | | - // Disable action=delete |
644 | | - $wgHooks['ArticleConfirmDelete'][] = 'PageTranslationHooks::disableDelete'; |
645 | | - } |
646 | | -} |
647 | | - |
648 | | -/** |
649 | | - * Registers \<languages> tag with the parser. |
650 | | - * @param $parser Parser |
651 | | - * @return \bool true |
652 | | - */ |
653 | | -function efTranslateInitTags( $parser ) { |
654 | | - // For nice language list in-page |
655 | | - $parser->setHook( 'languages', array( 'PageTranslationHooks', 'languages' ) ); |
656 | | - return true; |
657 | | -} |
658 | | - |
659 | | -function efTranslateAppendTestsToVariable( &$files ) { |
660 | | - $testDir = dirname( __FILE__ ) . '/tests/'; |
661 | | - $files[] = $testDir . 'MessageGroupBaseTest.php'; |
662 | | - return true; |
663 | | -} |
664 | | - |
665 | 510 | /** @cond cli_support */ |
666 | 511 | if ( !defined( 'TRANSLATE_CLI' ) ) { |
667 | 512 | function STDOUT() { } |
Index: trunk/extensions/Translate/TranslateHooks.php |
— | — | @@ -0,0 +1,169 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contains class with basic non-feature specific hooks. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Niklas Laxström |
| 8 | + * @copyright Copyright © 2011, Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Some hooks for Translate extension. |
| 14 | + */ |
| 15 | +class TranslateHooks { |
| 16 | + /// Hook: CanonicalNamespaces |
| 17 | + public static function setupNamespaces( &$list ) { |
| 18 | + global $wgPageTranslationNamespace; |
| 19 | + if ( !defined( 'NS_TRANSLATIONS' ) ) { |
| 20 | + define( 'NS_TRANSLATIONS', $wgPageTranslationNamespace ); |
| 21 | + define( 'NS_TRANSLATIONS_TALK', $wgPageTranslationNamespace + 1 ); |
| 22 | + } |
| 23 | + $list[NS_TRANSLATIONS] = 'Translations'; |
| 24 | + $list[NS_TRANSLATIONS_TALK] = 'Translations_talk'; |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Initialises the extension. |
| 30 | + * Does late-initialization that is not possible at file level, |
| 31 | + * because it depends on user configuration. |
| 32 | + */ |
| 33 | + public static function setupTranslate() { |
| 34 | + global $wgTranslatePHPlot, $wgAutoloadClasses, $wgHooks; |
| 35 | + |
| 36 | + if ( $wgTranslatePHPlot ) { |
| 37 | + $wgAutoloadClasses['PHPlot'] = $wgTranslatePHPlot; |
| 38 | + } |
| 39 | + |
| 40 | + global $wgReservedUsernames, $wgTranslateFuzzyBotName; |
| 41 | + $wgReservedUsernames[] = $wgTranslateFuzzyBotName; |
| 42 | + |
| 43 | + // Hook for database schema. |
| 44 | + $wgHooks['LoadExtensionSchemaUpdates'][] = 'PageTranslationHooks::schemaUpdates'; |
| 45 | + |
| 46 | + // Fuzzy tags for speed. |
| 47 | + $wgHooks['ArticleSaveComplete'][] = 'TranslateEditAddons::onSave'; |
| 48 | + |
| 49 | + // Page translation setup check and init if enabled. |
| 50 | + global $wgEnablePageTranslation; |
| 51 | + if ( $wgEnablePageTranslation ) { |
| 52 | + // Special page and the right to use it |
| 53 | + global $wgSpecialPages, $wgAvailableRights, $wgSpecialPageGroups; |
| 54 | + $wgSpecialPages['PageTranslation'] = 'SpecialPageTranslation'; |
| 55 | + $wgSpecialPageGroups['PageTranslation'] = 'pagetools'; |
| 56 | + $wgSpecialPages['PageTranslationDeletePage'] = 'SpecialPageTranslationDeletePage'; |
| 57 | + $wgSpecialPageGroups['PageTranslationDeletePage'] = 'pagetools'; |
| 58 | + $wgAvailableRights[] = 'pagetranslation'; |
| 59 | + |
| 60 | + global $wgLogNames, $wgLogActionsHandlers, $wgLogTypes, $wgLogHeaders; |
| 61 | + $wgLogTypes[] = 'pagetranslation'; |
| 62 | + $wgLogHeaders['pagetranslation'] = 'pt-log-header'; |
| 63 | + $wgLogNames['pagetranslation'] = 'pt-log-name'; |
| 64 | + $wgLogActionsHandlers['pagetranslation/mark'] = 'PageTranslationHooks::formatLogEntry'; |
| 65 | + $wgLogActionsHandlers['pagetranslation/unmark'] = 'PageTranslationHooks::formatLogEntry'; |
| 66 | + $wgLogActionsHandlers['pagetranslation/moveok'] = 'PageTranslationHooks::formatLogEntry'; |
| 67 | + $wgLogActionsHandlers['pagetranslation/movenok'] = 'PageTranslationHooks::formatLogEntry'; |
| 68 | + $wgLogActionsHandlers['pagetranslation/deletelok'] = 'PageTranslationHooks::formatLogEntry'; |
| 69 | + $wgLogActionsHandlers['pagetranslation/deletefok'] = 'PageTranslationHooks::formatLogEntry'; |
| 70 | + $wgLogActionsHandlers['pagetranslation/deletelnok'] = 'PageTranslationHooks::formatLogEntry'; |
| 71 | + $wgLogActionsHandlers['pagetranslation/deletefnok'] = 'PageTranslationHooks::formatLogEntry'; |
| 72 | + |
| 73 | + |
| 74 | + global $wgJobClasses; |
| 75 | + $wgJobClasses['RenderJob'] = 'RenderJob'; |
| 76 | + $wgJobClasses['MoveJob'] = 'MoveJob'; |
| 77 | + $wgJobClasses['DeleteJob'] = 'DeleteJob'; |
| 78 | + |
| 79 | + // Namespaces |
| 80 | + global $wgPageTranslationNamespace, $wgExtraNamespaces; |
| 81 | + global $wgNamespacesWithSubpages, $wgNamespaceProtection; |
| 82 | + global $wgTranslateMessageNamespaces, $wgVersion; |
| 83 | + |
| 84 | + // Define constants for more readable core |
| 85 | + if ( !defined( 'NS_TRANSLATIONS' ) ) { |
| 86 | + define( 'NS_TRANSLATIONS', $wgPageTranslationNamespace ); |
| 87 | + define( 'NS_TRANSLATIONS_TALK', $wgPageTranslationNamespace + 1 ); |
| 88 | + } |
| 89 | + |
| 90 | + if ( version_compare( $wgVersion, '1.17alpha', '<' ) ) { |
| 91 | + efTranslateNamespaces( $wgExtraNamespaces ); |
| 92 | + } |
| 93 | + |
| 94 | + $wgNamespacesWithSubpages[NS_TRANSLATIONS] = true; |
| 95 | + $wgNamespacesWithSubpages[NS_TRANSLATIONS_TALK] = true; |
| 96 | + |
| 97 | + // Standard protection and register it for filtering |
| 98 | + $wgNamespaceProtection[NS_TRANSLATIONS] = array( 'translate' ); |
| 99 | + $wgTranslateMessageNamespaces[] = NS_TRANSLATIONS; |
| 100 | + |
| 101 | + /// Page translation hooks |
| 102 | + |
| 103 | + /// @todo Register our css, is there a better place for this? |
| 104 | + $wgHooks['OutputPageBeforeHTML'][] = 'PageTranslationHooks::injectCss'; |
| 105 | + |
| 106 | + // Add transver tags and update translation target pages |
| 107 | + $wgHooks['ArticleSaveComplete'][] = 'PageTranslationHooks::onSectionSave'; |
| 108 | + |
| 109 | + // Register \<languages/> |
| 110 | + $wgHooks['ParserFirstCallInit'][] = 'TranslateHooks::setupParserHooks'; |
| 111 | + |
| 112 | + // Strip \<translate> tags etc. from source pages when rendering |
| 113 | + $wgHooks['ParserBeforeStrip'][] = 'PageTranslationHooks::renderTagPage'; |
| 114 | + |
| 115 | + // Check syntax for \<translate> |
| 116 | + $wgHooks['ArticleSave'][] = 'PageTranslationHooks::tpSyntaxCheck'; |
| 117 | + $wgHooks['EditFilterMerged'][] = 'PageTranslationHooks::tpSyntaxCheckForEditPage'; |
| 118 | + |
| 119 | + // Set the page content language |
| 120 | + $wgHooks['PageContentLanguage'][] = 'PageTranslationHooks::onPageContentLanguage'; |
| 121 | + |
| 122 | + // Add transtag to page props for discovery |
| 123 | + $wgHooks['ArticleSaveComplete'][] = 'PageTranslationHooks::addTranstag'; |
| 124 | + |
| 125 | + // Prevent editing of unknown pages in Translations namespace |
| 126 | + $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventUnknownTranslations'; |
| 127 | + // Prevent editing of translation pages directly |
| 128 | + $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::preventDirectEditing'; |
| 129 | + |
| 130 | + // Locking during page moves |
| 131 | + $wgHooks['getUserPermissionsErrorsExpensive'][] = 'PageTranslationHooks::lockedPagesCheck'; |
| 132 | + |
| 133 | + // Our custom header for translation pages |
| 134 | + $wgHooks['ArticleViewHeader'][] = 'PageTranslationHooks::test'; |
| 135 | + |
| 136 | + // Our tables are needed for parser tests |
| 137 | + $wgHooks['ParserTestTables'][] = 'PageTranslationHooks::parserTestTables'; |
| 138 | + |
| 139 | + // Prevent section pages appearing in categories |
| 140 | + $wgHooks['LinksUpdate'][] = 'PageTranslationHooks::preventCategorization'; |
| 141 | + |
| 142 | + // Custom move page that can move all the associated pages too |
| 143 | + $wgHooks['SpecialPage_initList'][] = 'PageTranslationHooks::replaceMovePage'; |
| 144 | + |
| 145 | + // Replace subpage logic behaviour |
| 146 | + $wgHooks['SkinSubPageSubtitle'][] = 'PageTranslationHooks::replaceSubtitle'; |
| 147 | + |
| 148 | + // Disable action=delete |
| 149 | + $wgHooks['ArticleConfirmDelete'][] = 'PageTranslationHooks::disableDelete'; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Hook: ParserFirstCallInit |
| 155 | + * Registers \<languages> tag with the parser. |
| 156 | + */ |
| 157 | + public static function setupParserHooks( $parser ) { |
| 158 | + // For nice language list in-page |
| 159 | + $parser->setHook( 'languages', array( 'PageTranslationHooks', 'languages' ) ); |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + /// Hook: UnitTestsList |
| 164 | + public static function setupUnitTests( &$files ) { |
| 165 | + $testDir = dirname( __FILE__ ) . '/tests/'; |
| 166 | + $files[] = $testDir . 'MessageGroupBaseTest.php'; |
| 167 | + return true; |
| 168 | + } |
| 169 | + |
| 170 | +} |
Property changes on: trunk/extensions/Translate/TranslateHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 171 | + native |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -22,6 +22,8 @@ |
23 | 23 | $wgAutoloadClasses['TranslateUtils'] = $dir . 'TranslateUtils.php'; |
24 | 24 | $wgAutoloadClasses['HTMLSelector'] = $dir . 'TranslateUtils.php'; |
25 | 25 | |
| 26 | +$wgAutoloadClasses['TranslateHooks'] = $dir . 'TranslateHooks.php'; |
| 27 | + |
26 | 28 | $wgAutoloadClasses['MessageChecker'] = $dir . 'MessageChecks.php'; |
27 | 29 | |
28 | 30 | $wgAutoloadClasses['MessageGroup'] = $dir . 'Groups.php'; |