r95953 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95952‎ | r95953 | r95954 >
Date:09:38, 1 September 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Add gadgetpagelist table and track .js and .css pages in it

* Rename existing hook functions for tracking stuff in the Gadget definition: namespace
* Add hook functions for tracking CSS/JS pages
* Add GadgetPageList class to interface with the gadgetpagelist table
Modified paths:
  • /branches/RL2/extensions/Gadgets/GadgetHooks.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/Gadgets.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/GadgetPageList.php (added) (history)
  • /branches/RL2/extensions/Gadgets/sql/gadgets.sql (modified) (history)
  • /branches/RL2/extensions/Gadgets/sql/patch-gadgetpagelist.sql (added) (history)

Diff [purge]

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
19 + native
Index: branches/RL2/extensions/Gadgets/sql/gadgets.sql
@@ -13,3 +13,16 @@
1414
1515 CREATE INDEX /*i*/gd_shared_name ON /*_*/gadgets (gd_shared, gd_name);
1616 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 @@
9393 'gadgets-definition-delete'
9494 ) );
9595
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';
99102 $wgHooks['BeforePageDisplay'][] = 'GadgetHooks::beforePageDisplay';
100103 $wgHooks['CanonicalNamespaces'][] = 'GadgetHooks::canonicalNamespaces';
101104 $wgHooks['GetPreferences'][] = 'GadgetHooks::getPreferences';
@@ -102,6 +105,7 @@
103106 $wgHooks['ResourceLoaderRegisterModules'][] = 'GadgetHooks::registerModules';
104107 $wgHooks['TitleIsCssOrJsPage'][] = 'GadgetHooks::titleIsCssOrJsPage';
105108 $wgHooks['TitleIsMovable'][] = 'GadgetHooks::titleIsMovable';
 109+$wgHooks['TitleMoveComplete'][] = 'GadgetHooks::cssOrJsPageMove';
106110 $wgHooks['getUserPermissionsErrors'][] = 'GadgetHooks::getUserPermissionsErrors';
107111 #$wgHooks['UnitTestsList'][] = 'GadgetHooks::unitTestsList'; // FIXME: broken
108112
@@ -116,6 +120,7 @@
117121 $wgAutoloadClasses['ForeignDBGadgetRepo'] = $dir . 'backend/ForeignDBGadgetRepo.php';
118122 $wgAutoloadClasses['Gadget'] = $dir . 'backend/Gadget.php';
119123 $wgAutoloadClasses['GadgetHooks'] = $dir . 'GadgetHooks.php';
 124+$wgAutoloadClasses['GadgetPageList'] = $dir . 'backend/GadgetPageList.php';
120125 $wgAutoloadClasses['GadgetRepo'] = $dir . 'backend/GadgetRepo.php';
121126 $wgAutoloadClasses['GadgetResourceLoaderModule'] = $dir . 'backend/GadgetResourceLoaderModule.php';
122127 $wgAutoloadClasses['LocalGadgetRepo'] = $dir . 'backend/LocalGadgetRepo.php';
Index: branches/RL2/extensions/Gadgets/GadgetHooks.php
@@ -22,7 +22,7 @@
2323 * @param $reason String: Deletion summary
2424 * @param $id Int: Page ID
2525 */
26 - public static function articleDeleteComplete( $article, $user, $reason, $id ) {
 26+ public static function gadgetDefinitionDelete( $article, $user, $reason, $id ) {
2727 // FIXME: AARGH, duplication, refactor this
2828 $title = $article->getTitle();
2929 $name = $title->getText();
@@ -52,7 +52,7 @@
5353 * @param $flags: Int: Bitmap of flags passed to WikiPage::doEdit()
5454 * @param $revision: Revision object for the new revision
5555 */
56 - public static function articleSaveComplete( $article, $user, $text, $summary, $isMinor,
 56+ public static function gadgetDefinitionSave( $article, $user, $text, $summary, $isMinor,
5757 $isWatch, $section, $flags, $revision )
5858 {
5959 $title = $article->getTitle();
@@ -80,8 +80,14 @@
8181
8282 return true;
8383 }
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 ) {
8692 // FIXME: AARGH, duplication, refactor this
8793 $name = $title->getText();
8894 // Check that the deletion is in the Gadget definition: namespace and that the name ends in .js
@@ -114,6 +120,74 @@
115121 }
116122
117123 /**
 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+ /**
118192 * GetPreferences hook handler.
119193 * @param $user User
120194 * @param $preferences Array: Preference descriptions
@@ -233,6 +307,7 @@
234308 public static function loadExtensionSchemaUpdates( $updater ) {
235309 $dir = dirname( __FILE__ );
236310 $updater->addExtensionUpdate( array( 'addtable', 'gadgets', "$dir/sql/gadgets.sql", true ) );
 311+ $updater->addExtensionUpdate( array( 'addtable', 'gadgetpagelist', "$dir/sql/patch-gadgetpagelist.sql", true ) );
237312 return true;
238313 }
239314
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
158 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r95962RL2: Fix r95953: put DBkey in title field, not prefixedDBkeycatrope10:54, 1 September 2011

Status & tagging log