r102627 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102626‎ | r102627 | r102628 >
Date:08:24, 10 November 2011
Author:aaron
Status:ok
Tags:
Comment:
* Moved MW_HTML_FOR_DUMP check to FlaggedRevsUISetup::defineHookHandlers(). We only want to disable the FR page view UI changes, not any backend and parser hook handlers. FR parser variables or includable special pages should still work, and DB related hooks should still trigger.
* Moved parser hooks to FlaggedRevsSetup::setConditionalHooks. These are not UI hooks.
* Reorganized hook definition order in defineHookHandlers() to group them a bit better.
* Added some array type hinting.
* A few whitespace and doc tweaks.
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.setup.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.setup.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.setup.php
@@ -10,17 +10,31 @@
1111 * @param $hooks Array $wgHooks (assoc array of hooks and handlers)
1212 * @return void
1313 */
14 - public static function defineHookHandlers( &$hooks ) {
 14+ public static function defineHookHandlers( array &$hooks ) {
1515 global $wgFlaggedRevsProtection;
1616
17 - # Override current revision, set cache...
18 - $hooks['ArticleViewHeader'][] = 'FlaggedRevsUIHooks::onArticleViewHeader';
19 - $hooks['ImagePageFindFile'][] = 'FlaggedRevsUIHooks::onImagePageFindFile';
20 - # Override redirect behavior...
21 - $hooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevsUIHooks::overrideRedirect';
22 - # Set page view tabs
23 - $hooks['SkinTemplateTabs'][] = 'FlaggedRevsUIHooks::onSkinTemplateTabs'; // All skins
24 - $hooks['SkinTemplateNavigation'][] = 'FlaggedRevsUIHooks::onSkinTemplateNavigation'; // Vector
 17+ # XXX: Don't mess with dumpHTML article view output...
 18+ if ( !defined( 'MW_HTML_FOR_DUMP' ) ) {
 19+ # Override current revision, set cache...
 20+ $hooks['ArticleViewHeader'][] = 'FlaggedRevsUIHooks::onArticleViewHeader';
 21+ $hooks['ImagePageFindFile'][] = 'FlaggedRevsUIHooks::onImagePageFindFile';
 22+ # Override redirect behavior...
 23+ $hooks['InitializeArticleMaybeRedirect'][] = 'FlaggedRevsUIHooks::overrideRedirect';
 24+ # Set page view tabs (non-Vector)
 25+ $hooks['SkinTemplateTabs'][] = 'FlaggedRevsUIHooks::onSkinTemplateTabs';
 26+ # Set page view tabs (Vector)
 27+ $hooks['SkinTemplateNavigation'][] = 'FlaggedRevsUIHooks::onSkinTemplateNavigation';
 28+ # Add review form
 29+ $hooks['SkinAfterContent'][] = 'FlaggedRevsUIHooks::onSkinAfterContent';
 30+ # Show unreviewed pages links
 31+ $hooks['CategoryPageView'][] = 'FlaggedRevsUIHooks::onCategoryPageView';
 32+ # Mark items in file history (shown on page view)
 33+ $hooks['LocalFile::getHistory'][] = 'FlaggedRevsUIHooks::addToFileHistQuery';
 34+ $hooks['ImagePageFileHistoryLine'][] = 'FlaggedRevsUIHooks::addToFileHistLine';
 35+ # Add review notice, backlog notices, protect form link, and CSS/JS and set robots
 36+ $hooks['BeforePageDisplay'][] = 'FlaggedRevsUIHooks::onBeforePageDisplay';
 37+ }
 38+
2539 # Add notice tags to edit view
2640 $hooks['EditPage::showEditForm:initial'][] = 'FlaggedRevsUIHooks::addToEditView';
2741 # Tweak submit button name/title
@@ -30,57 +44,47 @@
3145 $hooks['EditPage::showEditForm:fields'][] = 'FlaggedRevsUIHooks::addRevisionIDField';
3246 # Add draft link to section edit error
3347 $hooks['EditPageNoSuchSection'][] = 'FlaggedRevsUIHooks::onNoSuchSection';
34 - # Add notice tags to history
35 - $hooks['PageHistoryBeforeList'][] = 'FlaggedRevsUIHooks::addToHistView';
36 - # Add review form and visiblity settings link
37 - $hooks['SkinAfterContent'][] = 'FlaggedRevsUIHooks::onSkinAfterContent';
 48+ # Page review on edit
 49+ $hooks['ArticleUpdateBeforeRedirect'][] = 'FlaggedRevsUIHooks::injectPostEditURLParams';
 50+
3851 # Mark items in page history
3952 $hooks['PageHistoryPager::getQueryInfo'][] = 'FlaggedRevsUIHooks::addToHistQuery';
4053 $hooks['PageHistoryLineEnding'][] = 'FlaggedRevsUIHooks::addToHistLine';
41 - $hooks['LocalFile::getHistory'][] = 'FlaggedRevsUIHooks::addToFileHistQuery';
42 - $hooks['ImagePageFileHistoryLine'][] = 'FlaggedRevsUIHooks::addToFileHistLine';
4354 # Select extra info & filter items in RC
4455 $hooks['SpecialRecentChangesQuery'][] = 'FlaggedRevsUIHooks::modifyRecentChangesQuery';
4556 $hooks['SpecialNewpagesConditions'][] = 'FlaggedRevsUIHooks::modifyNewPagesQuery';
4657 $hooks['SpecialWatchlistQuery'][] = 'FlaggedRevsUIHooks::modifyChangesListQuery';
4758 # Mark items in RC
4859 $hooks['ChangesListInsertArticleLink'][] = 'FlaggedRevsUIHooks::addToChangeListLine';
 60+ if ( !$wgFlaggedRevsProtection ) {
 61+ # Mark items in user contribs
 62+ $hooks['ContribsPager::getQueryInfo'][] = 'FlaggedRevsUIHooks::addToContribsQuery';
 63+ $hooks['ContributionsLineEnding'][] = 'FlaggedRevsUIHooks::addToContribsLine';
 64+ }
 65+
4966 # RC filter UIs
5067 $hooks['SpecialNewPagesFilters'][] = 'FlaggedRevsUIHooks::addHideReviewedFilter';
5168 $hooks['SpecialRecentChangesFilters'][] = 'FlaggedRevsUIHooks::addHideReviewedFilter';
5269 $hooks['SpecialWatchlistFilters'][] = 'FlaggedRevsUIHooks::addHideReviewedFilter';
53 - # Page review on edit
54 - $hooks['ArticleUpdateBeforeRedirect'][] = 'FlaggedRevsUIHooks::injectPostEditURLParams';
 70+ # Add notice tags to history
 71+ $hooks['PageHistoryBeforeList'][] = 'FlaggedRevsUIHooks::addToHistView';
5572 # Diff-to-stable
5673 $hooks['DiffViewHeader'][] = 'FlaggedRevsUIHooks::onDiffViewHeader';
5774 # Add diff=review url param alias
5875 $hooks['NewDifferenceEngine'][] = 'FlaggedRevsUIHooks::checkDiffUrl';
5976 # Local user account preference
6077 $hooks['GetPreferences'][] = 'FlaggedRevsUIHooks::onGetPreferences';
61 - # Show unreviewed pages links
62 - $hooks['CategoryPageView'][] = 'FlaggedRevsUIHooks::onCategoryPageView';
6378 # Review/stability log links
6479 $hooks['LogLine'][] = 'FlaggedRevsUIHooks::logLineLinks';
65 - # Add review notice, backlog notices and CSS/JS and set robots
66 - $hooks['BeforePageDisplay'][] = 'FlaggedRevsUIHooks::onBeforePageDisplay';
6780 # Add global JS vars
6881 $hooks['MakeGlobalVariablesScript'][] = 'FlaggedRevsUIHooks::injectGlobalJSVars';
6982
70 - if ( !$wgFlaggedRevsProtection ) {
71 - # Mark items in user contribs
72 - $hooks['ContribsPager::getQueryInfo'][] = 'FlaggedRevsUIHooks::addToContribsQuery';
73 - $hooks['ContributionsLineEnding'][] = 'FlaggedRevsUIHooks::addToContribsLine';
74 - } else {
 83+ if ( $wgFlaggedRevsProtection ) {
7584 # Add protection form field
7685 $hooks['ProtectionForm::buildForm'][] = 'FlaggedRevsUIHooks::onProtectionForm';
7786 $hooks['ProtectionForm::showLogExtract'][] = 'FlaggedRevsUIHooks::insertStabilityLog';
7887 # Save stability settings
7988 $hooks['ProtectionForm::save'][] = 'FlaggedRevsUIHooks::onProtectionSave';
80 - # Parser stuff
81 - $hooks['ParserFirstCallInit'][] = 'FlaggedRevsHooks::onParserFirstCallInit';
82 - $hooks['LanguageGetMagic'][] = 'FlaggedRevsHooks::onLanguageGetMagic';
83 - $hooks['ParserGetVariableValueSwitch'][] = 'FlaggedRevsHooks::onParserGetVariableValueSwitch';
84 - $hooks['MagicWordwgVariableIDs'][] = 'FlaggedRevsHooks::onMagicWordwgVariableIDs';
8589 }
8690 }
8791
@@ -134,7 +138,7 @@
135139 * @param $modules Array $wgResourceModules (list of modules)
136140 * @return void
137141 */
138 - public static function defineResourceModules( &$modules ) {
 142+ public static function defineResourceModules( array &$modules ) {
139143 $localModulePath = dirname( __FILE__ ) . '/modules/';
140144 $remoteModulePath = 'FlaggedRevs/presentation/modules';
141145 $modules['ext.flaggedRevs.basic'] = array(
@@ -178,7 +182,7 @@
179183 * @param $ajaxExportList Array $wgAjaxExportList
180184 * @return void
181185 */
182 - public static function defineAjaxFunctions( &$ajaxExportList ) {
 186+ public static function defineAjaxFunctions( array &$ajaxExportList ) {
183187 $ajaxExportList[] = 'RevisionReview::AjaxReview';
184188 $ajaxExportList[] = 'FlaggablePageView::AjaxBuildDiffHeaderItems';
185189 }
@@ -190,7 +194,9 @@
191195 * @param $filterLogTypes Array $wgFilterLogTypes
192196 * @return void
193197 */
194 - public static function defineLogBasicDescription( &$logNames, &$logHeaders, &$filterLogTypes ) {
 198+ public static function defineLogBasicDescription(
 199+ array &$logNames, array &$logHeaders, array &$filterLogTypes
 200+ ) {
195201 $logNames['review'] = 'review-logpage';
196202 $logHeaders['review'] = 'review-logpagetext';
197203
@@ -206,7 +212,9 @@
207213 * @param $logActionsHandlers Array $wgLogActionsHandlers (assoc array of log handlers)
208214 * @return void
209215 */
210 - public static function defineLogActionHandlers( &$logActions, &$logActionsHandlers ) {
 216+ public static function defineLogActionHandlers(
 217+ array &$logActions, array &$logActionsHandlers
 218+ ) {
211219 # Various actions are used for log filtering ...
212220 $logActions['review/approve'] = 'review-logentry-app'; // checked (again)
213221 $logActions['review/approve2'] = 'review-logentry-app'; // quality (again)
Index: trunk/extensions/FlaggedRevs/presentation/FlaggedRevsUI.hooks.php
@@ -63,7 +63,7 @@
6464 }
6565
6666 /*
67 - * Add tag notice, CSS/JS, and set robots policy
 67+ * Add tag notice, CSS/JS, protect form link, and set robots policy
6868 */
6969 public static function onBeforePageDisplay( &$out, &$skin ) {
7070 if ( $out->getTitle()->getNamespace() != NS_SPECIAL ) {
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.setup.php
@@ -9,6 +9,8 @@
1010
1111 /**
1212 * Signal that LocalSettings.php is loaded.
 13+
 14+ * @return void
1315 */
1416 public static function setReady() {
1517 self::$canLoad = true;
@@ -16,6 +18,7 @@
1719
1820 /*
1921 * The FlaggedRevs class uses this as a sanity check.
 22+
2023 * @return bool
2124 */
2225 public static function isReady() {
@@ -31,7 +34,9 @@
3235 * @param $aliasesFiles Array $wgExtensionAliasesFiles
3336 * @return void
3437 */
35 - public static function defineSourcePaths( &$classes, &$messagesFiles, &$aliasesFiles ) {
 38+ public static function defineSourcePaths(
 39+ array &$classes, array &$messagesFiles, array &$aliasesFiles
 40+ ) {
3641 $dir = dirname( __FILE__ );
3742
3843 # Basic directory layout
@@ -233,15 +238,23 @@
234239 * @return void
235240 */
236241 public static function setConditionalHooks() {
237 - global $wgHooks;
 242+ global $wgHooks, $wgFlaggedRevsProtection;
238243
 244+ # Give bots the 'autoreview' right (here so it triggers after CentralAuth)
 245+ # @TODO: better way to ensure hook order
 246+ $wgHooks['UserGetRights'][] = 'FlaggedRevsHooks::onUserGetRights';
 247+
 248+ if ( $wgFlaggedRevsProtection ) {
 249+ # Add pending changes related magic words
 250+ $wgHooks['ParserFirstCallInit'][] = 'FlaggedRevsHooks::onParserFirstCallInit';
 251+ $wgHooks['LanguageGetMagic'][] = 'FlaggedRevsHooks::onLanguageGetMagic';
 252+ $wgHooks['ParserGetVariableValueSwitch'][] = 'FlaggedRevsHooks::onParserGetVariableValueSwitch';
 253+ $wgHooks['MagicWordwgVariableIDs'][] = 'FlaggedRevsHooks::onMagicWordwgVariableIDs';
 254+ }
 255+
239256 # ######## User interface #########
240257 FlaggedRevsUISetup::defineHookHandlers( $wgHooks );
241258 # ########
242 -
243 - # Give bots the 'autoreview' right (here so it triggers after CentralAuth)
244 - # @TODO: better way to ensure hook order
245 - $wgHooks['UserGetRights'][] = 'FlaggedRevsHooks::onUserGetRights';
246259 }
247260
248261 /**
@@ -252,6 +265,7 @@
253266 public static function setAutopromoteConfig() {
254267 global $wgFlaggedRevsAutoconfirm, $wgFlaggedRevsAutopromote;
255268 global $wgAutopromoteOnce, $wgGroupPermissions;
 269+
256270 # $wgFlaggedRevsAutoconfirm is now a wrapper around $wgAutopromoteOnce
257271 $req = $wgFlaggedRevsAutoconfirm; // convenience
258272 if ( is_array( $req ) ) {
@@ -312,6 +326,7 @@
313327 */
314328 public static function setSpecialPages() {
315329 global $wgSpecialPages, $wgSpecialPageGroups, $wgSpecialPageCacheUpdates;
 330+
316331 FlaggedRevsUISetup::defineSpecialPages(
317332 $wgSpecialPages, $wgSpecialPageGroups, $wgSpecialPageCacheUpdates );
318333 }
@@ -324,6 +339,7 @@
325340 public static function setAPIModules() {
326341 global $wgAPIModules, $wgAPIListModules, $wgAPIPropModules;
327342 global $wgFlaggedRevsProtection;
 343+
328344 if ( $wgFlaggedRevsProtection ) {
329345 $wgAPIModules['stabilize'] = 'ApiStabilizeProtect';
330346 } else {
@@ -351,6 +367,7 @@
352368 */
353369 public static function setConditionalRights() {
354370 global $wgGroupPermissions, $wgFlaggedRevsProtection;
 371+
355372 if ( $wgFlaggedRevsProtection ) {
356373 // XXX: Removes sp:ListGroupRights cruft
357374 if ( isset( $wgGroupPermissions['editor'] ) ) {
@@ -369,6 +386,7 @@
370387 */
371388 public static function setConditionalPreferences() {
372389 global $wgDefaultUserOptions, $wgSimpleFlaggedRevsUI;
 390+
373391 $wgDefaultUserOptions['flaggedrevssimpleui'] = (int)$wgSimpleFlaggedRevsUI;
374392 }
375393 }
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -40,11 +40,6 @@
4141 # Load default configuration variables
4242 require( "FlaggedRevs.config.php" );
4343
44 -# XXX: Don't mess with dump HTML...
45 -if ( defined( 'MW_HTML_FOR_DUMP' ) ) {
46 - return; // done after default config set to avoid LocalSettings errors
47 -}
48 -
4944 # Define were classes and i18n files are located
5045 require( "FlaggedRevs.setup.php" );
5146 FlaggedRevsSetup::defineSourcePaths(
@@ -96,7 +91,7 @@
9792 # Load the extension after setup is finished
9893 $wgExtensionFunctions[] = 'efLoadFlaggedRevs';
9994
100 -/*
 95+/**
10196 * This function is for setup that has to happen in Setup.php
10297 * when the functions in $wgExtensionFunctions get executed.
10398 * Note: avoid calls to FlaggedRevs class here for performance.

Status & tagging log