r72583 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72582‎ | r72583 | r72584 >
Date:12:17, 8 September 2010
Author:raymond
Status:ok
Tags:
Comment:
Restrict function to one or more namespaces. Per default it works for all namespaces as before.
Modified paths:
  • /trunk/extensions/MetadataEdit/MetadataEdit.hooks.php (modified) (history)
  • /trunk/extensions/MetadataEdit/MetadataEdit.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MetadataEdit/MetadataEdit.php
@@ -24,6 +24,11 @@
2525 */
2626 $wgMetadataWhitelist = '';
2727
 28+/**
 29+ * Restrict function to one or more namespaces, i.e. NS_MAIN
 30+ */
 31+$wgMetadataNamespaces = array();
 32+
2833 $dir = dirname( __FILE__ ) . '/';
2934 $wgExtensionMessagesFiles['MetadataEdit'] = $dir . 'MetadataEdit.i18n.php';
3035
Index: trunk/extensions/MetadataEdit/MetadataEdit.hooks.php
@@ -4,8 +4,7 @@
55
66 public static function wfMetadataEditExtractFromArticle( $editPage ) {
77 global $wgMetadataWhitelist, $wgContLang;
8 -
9 - if ( $wgMetadataWhitelist == '' ) {
 8+ if ( $wgMetadataWhitelist == '' || !self::isValidMetadataNamespace( $editPage->mTitle->getNamespace() ) ) {
109 return true;
1110 }
1211
@@ -95,7 +94,7 @@
9695 }
9796
9897 public static function wfMetadataEditOnImportData( $editPage, $request ) {
99 - if ( $request->wasPosted() ) {
 98+ if ( self::isValidMetadataNamespace( $editPage->mTitle->getNamespace() ) && $request->wasPosted() ) {
10099 $editPage->mMetaData = rtrim( $request->getText( 'metadata' ) );
101100 } else {
102101 $editPage->mMetaData = '';
@@ -115,6 +114,10 @@
116115 }
117116
118117 public static function wfMetadataEditOnShowFields( $editPage ) {
 118+ if ( !self::isValidMetadataNamespace( $editPage->mTitle->getNamespace() ) ) {
 119+ return true;
 120+ }
 121+
119122 global $wgContLang, $wgUser;
120123 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $editPage->mMetaData ) );
121124
@@ -147,4 +150,9 @@
148151 }
149152 return true;
150153 }
 154+
 155+ public static function isValidMetadataNamespace( $namespace ) {
 156+ global $wgMetadataNamespaces;
 157+ return in_array( $namespace, $wgMetadataNamespaces );
 158+ }
151159 }

Status & tagging log