Index: branches/RL2/extensions/Gadgets/sql/patch-gadgetpagelist.sql |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +CREATE TABLE /*_*/gadgetpagelist ( |
| 3 | + gpl_extension varchar(32) NOT NULL, |
| 4 | + gpl_namespace int NOT NULL, |
| 5 | + gpl_title varchar(255) NOT NULL |
| 6 | +) /*$wgDBTableOptions*/; |
| 7 | +CREATE UNIQUE INDEX /*i*/gpl_namespace_title ON /*_*/gadgetpagelist (gpl_namespace, gpl_title); |
| 8 | +CREATE INDEX /*i*/gpl_extension_namespace_title ON /*_*/gadgetpagelist (gpl_extension, gpl_namespace, gpl_title); |
Property changes on: branches/RL2/extensions/Gadgets/sql/patch-gadgetpagelist.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 9 | + native |
Index: branches/RL2/extensions/Gadgets/sql/gadgets.sql |
— | — | @@ -13,3 +13,16 @@ |
14 | 14 | |
15 | 15 | CREATE INDEX /*i*/gd_shared_name ON /*_*/gadgets (gd_shared, gd_name); |
16 | 16 | CREATE INDEX /*i*/gd_name_timestamp ON /*_*/gadgets (gd_name, gd_timestamp); |
| 17 | + |
| 18 | +-- Table tracking .js and .css pages to make efficient prefix searches by extension possible |
| 19 | +-- (used for AJAX autocompletion) |
| 20 | +CREATE TABLE /*_*/gadgetpagelist ( |
| 21 | + -- Extension of the page. Right now this can only be 'js' or 'css' but this may change in the future |
| 22 | + gpl_extension varchar(32) NOT NULL, |
| 23 | + -- Namespace |
| 24 | + gpl_namespace int NOT NULL, |
| 25 | + -- Page title |
| 26 | + gpl_title varchar(255) NOT NULL |
| 27 | +) /*$wgDBTableOptions*/; |
| 28 | +CREATE UNIQUE INDEX /*i*/gpl_namespace_title ON /*_*/gadgetpagelist (gpl_namespace, gpl_title); |
| 29 | +CREATE INDEX /*i*/gpl_extension_namespace_title ON /*_*/gadgetpagelist (gpl_extension, gpl_namespace, gpl_title); |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -92,9 +92,12 @@ |
93 | 93 | 'gadgets-definition-delete' |
94 | 94 | ) ); |
95 | 95 | |
96 | | -$wgHooks['ArticleDeleteComplete'][] = 'GadgetHooks::articleDeleteComplete'; |
97 | | -$wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::articleSaveComplete'; |
98 | | -$wgHooks['ArticleUndelete'][] = 'GadgetHooks::articleUndelete'; |
| 96 | +$wgHooks['ArticleDeleteComplete'][] = 'GadgetHooks::gadgetDefinitionDelete'; |
| 97 | +$wgHooks['ArticleDeleteComplete'][] = 'GadgetHooks::cssJsPageDelete'; |
| 98 | +$wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::gadgetDefinitionSave'; |
| 99 | +$wgHooks['ArticleSaveComplete'][] = 'GadgetHooks::cssOrJsPageSave'; |
| 100 | +$wgHooks['ArticleUndelete'][] = 'GadgetHooks::gadgetDefinitionUndelete'; |
| 101 | +$wgHooks['ArticleUndelete'][] = 'GadgetHooks::cssOrJsPageUndelete'; |
99 | 102 | $wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay'; |
100 | 103 | $wgHooks['CanonicalNamespaces'][] = 'GadgetHooks::canonicalNamespaces'; |
101 | 104 | $wgHooks['GetPreferences'][] = 'GadgetHooks::getPreferences'; |
— | — | @@ -102,6 +105,7 @@ |
103 | 106 | $wgHooks['ResourceLoaderRegisterModules'][] = 'GadgetHooks::registerModules'; |
104 | 107 | $wgHooks['TitleIsCssOrJsPage'][] = 'GadgetHooks::titleIsCssOrJsPage'; |
105 | 108 | $wgHooks['TitleIsMovable'][] = 'GadgetHooks::titleIsMovable'; |
| 109 | +$wgHooks['TitleMoveComplete'][] = 'GadgetHooks::cssOrJsPageMove'; |
106 | 110 | $wgHooks['getUserPermissionsErrors'][] = 'GadgetHooks::getUserPermissionsErrors'; |
107 | 111 | #$wgHooks['UnitTestsList'][] = 'GadgetHooks::unitTestsList'; // FIXME: broken |
108 | 112 | |
— | — | @@ -116,6 +120,7 @@ |
117 | 121 | $wgAutoloadClasses['ForeignDBGadgetRepo'] = $dir . 'backend/ForeignDBGadgetRepo.php'; |
118 | 122 | $wgAutoloadClasses['Gadget'] = $dir . 'backend/Gadget.php'; |
119 | 123 | $wgAutoloadClasses['GadgetHooks'] = $dir . 'GadgetHooks.php'; |
| 124 | +$wgAutoloadClasses['GadgetPageList'] = $dir . 'backend/GadgetPageList.php'; |
120 | 125 | $wgAutoloadClasses['GadgetRepo'] = $dir . 'backend/GadgetRepo.php'; |
121 | 126 | $wgAutoloadClasses['GadgetResourceLoaderModule'] = $dir . 'backend/GadgetResourceLoaderModule.php'; |
122 | 127 | $wgAutoloadClasses['LocalGadgetRepo'] = $dir . 'backend/LocalGadgetRepo.php'; |
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * @param $reason String: Deletion summary |
24 | 24 | * @param $id Int: Page ID |
25 | 25 | */ |
26 | | - public static function articleDeleteComplete( $article, $user, $reason, $id ) { |
| 26 | + public static function gadgetDefinitionDelete( $article, $user, $reason, $id ) { |
27 | 27 | // FIXME: AARGH, duplication, refactor this |
28 | 28 | $title = $article->getTitle(); |
29 | 29 | $name = $title->getText(); |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | * @param $flags: Int: Bitmap of flags passed to WikiPage::doEdit() |
54 | 54 | * @param $revision: Revision object for the new revision |
55 | 55 | */ |
56 | | - public static function articleSaveComplete( $article, $user, $text, $summary, $isMinor, |
| 56 | + public static function gadgetDefinitionSave( $article, $user, $text, $summary, $isMinor, |
57 | 57 | $isWatch, $section, $flags, $revision ) |
58 | 58 | { |
59 | 59 | $title = $article->getTitle(); |
— | — | @@ -80,8 +80,14 @@ |
81 | 81 | |
82 | 82 | return true; |
83 | 83 | } |
84 | | - |
85 | | - public static function articleUndelete( $title, $created, $comment ) { |
| 84 | + |
| 85 | + /** |
| 86 | + * ArticleUndelete hook handler |
| 87 | + * @param $title Title object |
| 88 | + * @param $created Bool: Whether this undeletion recreated the page |
| 89 | + * @param $comment String: Undeletion summary |
| 90 | + */ |
| 91 | + public static function gadgetDefinitionUndelete( $title, $created, $comment ) { |
86 | 92 | // FIXME: AARGH, duplication, refactor this |
87 | 93 | $name = $title->getText(); |
88 | 94 | // Check that the deletion is in the Gadget definition: namespace and that the name ends in .js |
— | — | @@ -114,6 +120,74 @@ |
115 | 121 | } |
116 | 122 | |
117 | 123 | /** |
| 124 | + * ArticleDeleteComplete hook handler. |
| 125 | + * |
| 126 | + * @param $article Article |
| 127 | + * @param $user User |
| 128 | + * @param $reason String: Deletion summary |
| 129 | + * @param $id Int: Page ID |
| 130 | + */ |
| 131 | + public static function cssJsPageDelete( $article, $user, $reason, $id ) { |
| 132 | + GadgetPageList::delete( $article->getTitle() ); |
| 133 | + return true; |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * ArticleSaveComplete hook handler. |
| 138 | + * |
| 139 | + * @param $article Article |
| 140 | + * @param $user User |
| 141 | + * @param $text String: New page text |
| 142 | + * @param $summary String: Edit summary |
| 143 | + * @param $isMinor Bool: Whether this was a minor edit |
| 144 | + * @param $isWatch unused |
| 145 | + * @param $section unused |
| 146 | + * @param $flags: Int: Bitmap of flags passed to WikiPage::doEdit() |
| 147 | + * @param $revision: Revision object for the new revision |
| 148 | + */ |
| 149 | + public static function cssOrJsPageSave( $article, $user, $text, $summary, $isMinor, |
| 150 | + $isWatch, $section, $flags, $revision ) |
| 151 | + { |
| 152 | + $title = $article->getTitle(); |
| 153 | + if ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) { |
| 154 | + if ( $title->isRedirect() ) { |
| 155 | + GadgetPageList::delete( $title ); |
| 156 | + } else { |
| 157 | + GadgetPageList::add( $title ); |
| 158 | + } |
| 159 | + } |
| 160 | + return true; |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * ArticleUndelete hook handler |
| 165 | + * @param $title Title object |
| 166 | + * @param $created Bool: Whether this undeletion recreated the page |
| 167 | + * @param $comment String: Undeletion summary |
| 168 | + */ |
| 169 | + public static function cssOrJsPageUndelete( $title, $created, $comment ) { |
| 170 | + if ( ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) && !$title->isRedirect() ) { |
| 171 | + GadgetPageList::add( $title ); |
| 172 | + } |
| 173 | + return true; |
| 174 | + } |
| 175 | + |
| 176 | + public static function cssOrJsPageMove( $oldTitle, $newTitle, $user, $pageid, $redirid ) { |
| 177 | + // Delete the old title from the list. Even if it still exists after the move, |
| 178 | + // it'll be a redirect and we don't want those in there |
| 179 | + GadgetPageList::delete( $oldTitle ); |
| 180 | + |
| 181 | + if ( $newTitle->isCssOrJsPage() || $newTitle->isCssJsSubpage() ) { |
| 182 | + if ( $title->isRedirect() ) { |
| 183 | + GadgetPageList::delete( $newTitle ); |
| 184 | + } else { |
| 185 | + GadgetPageList::add( $newTitle ); |
| 186 | + } |
| 187 | + } |
| 188 | + return true; |
| 189 | + } |
| 190 | + |
| 191 | + /** |
118 | 192 | * GetPreferences hook handler. |
119 | 193 | * @param $user User |
120 | 194 | * @param $preferences Array: Preference descriptions |
— | — | @@ -233,6 +307,7 @@ |
234 | 308 | public static function loadExtensionSchemaUpdates( $updater ) { |
235 | 309 | $dir = dirname( __FILE__ ); |
236 | 310 | $updater->addExtensionUpdate( array( 'addtable', 'gadgets', "$dir/sql/gadgets.sql", true ) ); |
| 311 | + $updater->addExtensionUpdate( array( 'addtable', 'gadgetpagelist', "$dir/sql/patch-gadgetpagelist.sql", true ) ); |
237 | 312 | return true; |
238 | 313 | } |
239 | 314 | |
Index: branches/RL2/extensions/Gadgets/backend/GadgetPageList.php |
— | — | @@ -0,0 +1,56 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Gadgets extension - lets users select custom javascript gadgets |
| 5 | + * |
| 6 | + * |
| 7 | + * For more info see http://mediawiki.org/wiki/Extension:Gadgets |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
| 11 | + * @author Roan Kattouw |
| 12 | + * @copyright © 2011 Roan Kattouw |
| 13 | + * @license GNU General Public Licence 2.0 or later |
| 14 | + */ |
| 15 | + |
| 16 | +/** |
| 17 | + * Class with static methods for accessing the gadgetpagelist table |
| 18 | + */ |
| 19 | +class GadgetPageList { |
| 20 | + /** |
| 21 | + * Determine the extension of a title ('css' or 'js') |
| 22 | + * @param $title Title object |
| 23 | + * @return string The extension of the title, or empty string |
| 24 | + */ |
| 25 | + public static function determineExtension( $title ) { |
| 26 | + $m = null; |
| 27 | + preg_match( '!\.(css|js)$!u', $title->getText(), $m ); |
| 28 | + return isset( $m[1] ) ? $m[1] : ''; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Add a title to the gadgetpagelist table |
| 33 | + * @param $title Title object |
| 34 | + */ |
| 35 | + public static function add( $title ) { |
| 36 | + $dbw = wfGetDB( DB_MASTER ); |
| 37 | + $dbw->insert( 'gadgetpagelist', array( |
| 38 | + 'gpl_extension' => self::determineExtension( $title ), |
| 39 | + 'gpl_namespace' => $title->getNamespace(), |
| 40 | + 'gpl_title' => $title->getPrefixedDBKey() |
| 41 | + ), __METHOD__, array( 'IGNORE' ) |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Delete a title from the gadgetpagelist table |
| 47 | + * @param $title Title object |
| 48 | + */ |
| 49 | + public static function delete( $title ) { |
| 50 | + $dbw = wfGetDB( DB_MASTER ); |
| 51 | + $dbw->delete( 'gadgetpagelist', array( |
| 52 | + 'gpl_namespace' => $title->getNamespace(), |
| 53 | + 'gpl_title' => $title->getPrefixedDBKey() |
| 54 | + ), __METHOD__ |
| 55 | + ); |
| 56 | + } |
| 57 | +} |
Property changes on: branches/RL2/extensions/Gadgets/backend/GadgetPageList.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 58 | + native |