Index: branches/RL2/extensions/Gadgets/GadgetHooks.php |
— | — | @@ -149,13 +149,7 @@ |
150 | 150 | $isWatch, $section, $flags, $revision ) |
151 | 151 | { |
152 | 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 | | - } |
| 153 | + GadgetPageList::updatePageStatus( $title ); |
160 | 154 | return true; |
161 | 155 | } |
162 | 156 | |
— | — | @@ -166,9 +160,7 @@ |
167 | 161 | * @param $comment String: Undeletion summary |
168 | 162 | */ |
169 | 163 | public static function cssOrJsPageUndelete( $title, $created, $comment ) { |
170 | | - if ( ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) && !$title->isRedirect() ) { |
171 | | - GadgetPageList::add( $title ); |
172 | | - } |
| 164 | + GadgetPageList::updatePageStatus( $title ); |
173 | 165 | return true; |
174 | 166 | } |
175 | 167 | |
— | — | @@ -177,13 +169,7 @@ |
178 | 170 | // it'll be a redirect and we don't want those in there |
179 | 171 | GadgetPageList::delete( $oldTitle ); |
180 | 172 | |
181 | | - if ( $newTitle->isCssOrJsPage() || $newTitle->isCssJsSubpage() ) { |
182 | | - if ( $title->isRedirect() ) { |
183 | | - GadgetPageList::delete( $newTitle ); |
184 | | - } else { |
185 | | - GadgetPageList::add( $newTitle ); |
186 | | - } |
187 | | - } |
| 173 | + GadgetPageList::updatePageStatus( $newTitle ); |
188 | 174 | return true; |
189 | 175 | } |
190 | 176 | |
Index: branches/RL2/extensions/Gadgets/backend/GadgetPageList.php |
— | — | @@ -28,16 +28,54 @@ |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
| 32 | + * Check whether a given title is a gadget page |
| 33 | + * @param $title Title object |
| 34 | + * @return bool True if $title is a CSS/JS page and isn't a redirect, false otherwise |
| 35 | + */ |
| 36 | + public static function isGadgetPage( $title ) { |
| 37 | + return ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) && !$title->isRedirect(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Get a row for the gadgetpagelist table |
| 42 | + * @param $title Title object |
| 43 | + * @return array Database row |
| 44 | + */ |
| 45 | + public static function getRowForTitle( $title ) { |
| 46 | + return array( |
| 47 | + 'gpl_extension' => self::determineExtension( $title ), |
| 48 | + 'gpl_namespace' => $title->getNamespace(), |
| 49 | + 'gpl_title' => $title->getDBKey() |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Update the status of a title, typically called when a title has been |
| 55 | + * edited or created. |
| 56 | + * |
| 57 | + * If $title is a CSS/JS page and not a redirect, it is added to the table. |
| 58 | + * If it is a CSS/JS page but is a redirect, it is removed from the table. |
| 59 | + * If it's not a CSS/JS page, it's assumed never to have been added to begin with, so nothing happens/ |
| 60 | + * @param $title Title object |
| 61 | + */ |
| 62 | + public static function updatePageStatus( $title ) { |
| 63 | + if ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) { |
| 64 | + if ( $title->isRedirect() ) { |
| 65 | + self::delete( $title ); |
| 66 | + } else { |
| 67 | + self::add( $title ); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + /** |
32 | 73 | * Add a title to the gadgetpagelist table |
33 | 74 | * @param $title Title object |
34 | 75 | */ |
35 | 76 | public static function add( $title ) { |
36 | 77 | $dbw = wfGetDB( DB_MASTER ); |
37 | | - $dbw->insert( 'gadgetpagelist', array( |
38 | | - 'gpl_extension' => self::determineExtension( $title ), |
39 | | - 'gpl_namespace' => $title->getNamespace(), |
40 | | - 'gpl_title' => $title->getDBKey() |
41 | | - ), __METHOD__, array( 'IGNORE' ) |
| 78 | + $dbw->insert( 'gadgetpagelist', self::getRowForTitle( $title ), |
| 79 | + __METHOD__, array( 'IGNORE' ) |
42 | 80 | ); |
43 | 81 | } |
44 | 82 | |