http://www.mediawiki.org/wiki/Special:Code/MediaWiki/96010
Revision: 96010
Author: catrope
Date: 2011-09-01 16:53:29 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
RL2: Refactor GadgetPageList resulting in less code duplication in GadgetHooks
* Factor getRowForTitle() out of add(), will be useful for the maintenance
script I'm about to commit
* Factor the duplicated if-redirect-else logic out into updatePageStatus()
** also use it in the undelete hook, it appears that previously suffered of a
bug where undeleting a newer revision on top of an older one making the page a
redirect didn't cause it to be unlisted in gadgetpagelist
* Add a function isGadgetPage() that checks if a page qualifies for being in
the table. Not used anywhere right now but will be used by the maintenance
script
Modified Paths:
--------------
branches/RL2/extensions/Gadgets/GadgetHooks.php
branches/RL2/extensions/Gadgets/backend/GadgetPageList.php
Modified: branches/RL2/extensions/Gadgets/GadgetHooks.php
===================================================================
--- branches/RL2/extensions/Gadgets/GadgetHooks.php 2011-09-01 16:19:14 UTC
(rev 96009)
+++ branches/RL2/extensions/Gadgets/GadgetHooks.php 2011-09-01 16:53:29 UTC
(rev 96010)
@@ -149,13 +149,7 @@
$isWatch, $section, $flags, $revision )
{
$title = $article->getTitle();
- if ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) {
- if ( $title->isRedirect() ) {
- GadgetPageList::delete( $title );
- } else {
- GadgetPageList::add( $title );
- }
- }
+ GadgetPageList::updatePageStatus( $title );
return true;
}
@@ -166,9 +160,7 @@
* @param $comment String: Undeletion summary
*/
public static function cssOrJsPageUndelete( $title, $created, $comment
) {
- if ( ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) &&
!$title->isRedirect() ) {
- GadgetPageList::add( $title );
- }
+ GadgetPageList::updatePageStatus( $title );
return true;
}
@@ -177,13 +169,7 @@
// it'll be a redirect and we don't want those in there
GadgetPageList::delete( $oldTitle );
- if ( $newTitle->isCssOrJsPage() || $newTitle->isCssJsSubpage()
) {
- if ( $title->isRedirect() ) {
- GadgetPageList::delete( $newTitle );
- } else {
- GadgetPageList::add( $newTitle );
- }
- }
+ GadgetPageList::updatePageStatus( $newTitle );
return true;
}
Modified: branches/RL2/extensions/Gadgets/backend/GadgetPageList.php
===================================================================
--- branches/RL2/extensions/Gadgets/backend/GadgetPageList.php 2011-09-01
16:19:14 UTC (rev 96009)
+++ branches/RL2/extensions/Gadgets/backend/GadgetPageList.php 2011-09-01
16:53:29 UTC (rev 96010)
@@ -28,16 +28,54 @@
}
/**
+ * Check whether a given title is a gadget page
+ * @param $title Title object
+ * @return bool True if $title is a CSS/JS page and isn't a redirect,
false otherwise
+ */
+ public static function isGadgetPage( $title ) {
+ return ( $title->isCssOrJsPage() || $title->isCssJsSubpage() )
&& !$title->isRedirect();
+ }
+
+ /**
+ * Get a row for the gadgetpagelist table
+ * @param $title Title object
+ * @return array Database row
+ */
+ public static function getRowForTitle( $title ) {
+ return array(
+ 'gpl_extension' => self::determineExtension( $title ),
+ 'gpl_namespace' => $title->getNamespace(),
+ 'gpl_title' => $title->getDBKey()
+ );
+ }
+
+ /**
+ * Update the status of a title, typically called when a title has been
+ * edited or created.
+ *
+ * If $title is a CSS/JS page and not a redirect, it is added to the
table.
+ * If it is a CSS/JS page but is a redirect, it is removed from the
table.
+ * If it's not a CSS/JS page, it's assumed never to have been added to
begin with, so nothing happens/
+ * @param $title Title object
+ */
+ public static function updatePageStatus( $title ) {
+ if ( $title->isCssOrJsPage() || $title->isCssJsSubpage() ) {
+ if ( $title->isRedirect() ) {
+ self::delete( $title );
+ } else {
+ self::add( $title );
+ }
+ }
+ }
+
+ /**
* Add a title to the gadgetpagelist table
* @param $title Title object
*/
public static function add( $title ) {
$dbw = wfGetDB( DB_MASTER );
- $dbw->insert( 'gadgetpagelist', array(
- 'gpl_extension' => self::determineExtension(
$title ),
- 'gpl_namespace' => $title->getNamespace(),
- 'gpl_title' => $title->getDBKey()
- ), __METHOD__, array( 'IGNORE' )
+ $dbw->insert( 'gadgetpagelist', self::getRowForTitle( $title ),
+ __METHOD__, array( 'IGNORE' )
);
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs