Extension:Validation
- Extension:Validation – Ensuring Data Integrity in Your Wiki
- Introduction
The `Validation` extension for MediaWiki is a powerful tool for enforcing data integrity on wiki pages. It allows administrators to define rules for the content of specific form parameters, ensuring that users submit data in a consistent and correct format. This is particularly useful for templates that collect structured information, such as infoboxes, forms for requests, or any page where data consistency is critical. Without validation, wikis can be plagued by poorly formatted data, making searching, reporting, and overall data management significantly more difficult. This article will provide a comprehensive guide to the `Validation` extension, covering its installation, configuration, available features, and practical examples. We'll explore how it interacts with Forms, Parser functions, and other essential wiki components. Understanding this extension is crucial for building robust and reliable wiki applications.
- Why Use Validation?
Consider a wiki dedicated to cataloging Technical Analysis strategies. Without validation, users might input strategies with missing key information, inconsistent date formats, or ambiguous descriptions. This leads to a fragmented and unreliable database. The `Validation` extension solves this problem by allowing you to:
- **Enforce Data Types:** Ensure that fields intended for numbers actually contain numbers, dates are in a valid format, and email addresses are properly structured.
- **Require Fields:** Mandate that certain fields are not left blank, preventing incomplete submissions.
- **Define Length Restrictions:** Limit the number of characters allowed in a field, preventing overly verbose or truncated entries.
- **Regular Expression Matching:** Validate data against complex patterns, ensuring adherence to specific formats (e.g., stock ticker symbols, Candlestick patterns).
- **Custom Error Messages:** Provide clear and helpful feedback to users when their input fails validation, improving the user experience.
- **Prevent Broken Templates:** Ensure that templates receiving validated data will function correctly, avoiding display errors and maintaining a consistent look and feel.
- **Improve Data Quality:** Ultimately, validation leads to a cleaner, more reliable, and more useful wiki database. This is critical for any wiki that relies on structured data for reporting or analysis – think Fibonacci retracement levels, Moving averages, or Bollinger Bands calculations.
- Installation
The `Validation` extension is available from the MediaWiki Extensions Repository. Installation typically involves the following steps:
1. **Download:** Download the latest stable release of the `Validation` extension from [1](https://www.mediawiki.org/wiki/Extension:Validation). 2. **Upload:** Upload the contents of the downloaded archive to the `/extensions/Validation` directory on your MediaWiki server. 3. **Configure:** Add the following line to your `LocalSettings.php` file:
```php require_once "$IP/extensions/Validation/Validation.php"; ```
4. **Enable:** If you are using a recent version of MediaWiki, you might need to explicitly enable the extension in `LocalSettings.php` using:
```php wfLoadExtension( 'Validation' ); ```
5. **Clear Cache:** Clear your MediaWiki cache (usually via Special:Purge or by deleting the cache directory on the server) to ensure the changes are applied.
- Configuration
The `Validation` extension is configured through a special page, `MediaWiki:Validation.json`. This file uses JSON format to define validation rules. Here's a breakdown of the configuration options:
- **`rules`:** This is the core of the configuration. It's a JSON object where keys are the names of form parameters (as defined in your Forms or template code) and values are the validation rules for that parameter.
- **`type`:** Specifies the data type expected for the parameter. Supported types include:
* `string`: A sequence of characters. * `number`: A numerical value. * `integer`: A whole number. * `boolean`: A true/false value. * `email`: A valid email address. * `url`: A valid URL. * `date`: A date in a specific format. * `regex`: A string matching a regular expression.
- **`required`:** A boolean value indicating whether the parameter is mandatory. `true` means the field must be filled; `false` means it's optional.
- **`minLength`:** The minimum length of a string.
- **`maxLength`:** The maximum length of a string.
- **`minValue`:** The minimum value for a number or integer.
- **`maxValue`:** The maximum value for a number or integer.
- **`format`:** Used with the `date` type to specify the expected date format (e.g., "YYYY-MM-DD", "MM/DD/YYYY").
- **`pattern`:** Used with the `regex` type to specify the regular expression to match.
- **`message`:** A custom error message to display if validation fails. If not provided, a default message will be used.
- Example Configuration
Let's say you have a template for adding Trading signals to your wiki. The template has the following parameters:
- `signal_name`: The name of the signal.
- `asset`: The asset the signal applies to (e.g., EURUSD, AAPL).
- `entry_price`: The entry price of the trade.
- `stop_loss`: The stop-loss price.
- `take_profit`: The take-profit price.
- `signal_date`: The date the signal was issued.
Here's a `MediaWiki:Validation.json` configuration for this template:
```json {
"rules": { "signal_name": { "type": "string", "required": true, "minLength": 3, "maxLength": 100, "message": "Signal name must be between 3 and 100 characters." }, "asset": { "type": "string", "required": true, "pattern": "^[A-Z]{3,5}$", "message": "Asset must be a valid ticker symbol (3-5 uppercase letters)." }, "entry_price": { "type": "number", "required": true, "minValue": 0.001, "message": "Entry price must be a positive number." }, "stop_loss": { "type": "number", "required": true, "minValue": 0.001, "message": "Stop loss must be a positive number." }, "take_profit": { "type": "number", "required": true, "minValue": 0.001, "message": "Take profit must be a positive number." }, "signal_date": { "type": "date", "required": true, "format": "YYYY-MM-DD", "message": "Signal date must be in YYYY-MM-DD format." } }
} ```
In this example, we've enforced several validation rules:
- The `signal_name` must be a string between 3 and 100 characters.
- The `asset` must be a string matching the regular expression `^[A-Z]{3,5}$`, which ensures it consists of 3 to 5 uppercase letters (suitable for ticker symbols). This is particularly useful for filtering based on Market capitalization.
- The `entry_price`, `stop_loss`, and `take_profit` must be positive numbers.
- The `signal_date` must be a date in the `YYYY-MM-DD` format.
- Integrating with Forms and Templates
The `Validation` extension works seamlessly with Forms and templates. When a user submits a form or template with parameters defined in the `Validation.json` file, the extension automatically checks the input against the configured rules. If any validation rules are violated, error messages are displayed to the user, preventing the submission from being saved.
To integrate with templates, you typically use the `{{#validation}}` parser function. This function takes the parameter name as input and returns an error message if the validation fails, or an empty string if it passes. You can then display the error message in your template using conditional logic.
For example, within your template:
```wiki {{#validation:signal_name}}
Template:.message
{{#forminput:signal_name|label=Signal Name}}
This code snippet checks if the `signal_name` parameter is valid. If it's not, it displays the error message associated with that parameter. Otherwise, it displays a standard form input field for the `signal_name`.
- Advanced Usage
- **Conditional Validation:** You can create validation rules that depend on the value of other parameters. This requires more advanced configuration and potentially custom code.
- **Custom Validation Functions:** For complex validation scenarios, you can write custom PHP functions to perform validation checks that are not covered by the built-in types and rules.
- **AJAX Validation:** With some JavaScript coding, you can implement AJAX validation, which allows you to validate parameters in real-time as the user types, providing immediate feedback. This can significantly improve the user experience.
- **Integration with other Extensions:** The `Validation` extension can be combined with other extensions, such as AbuseFilter, to provide a more comprehensive security and data integrity solution. This is especially important when dealing with potentially sensitive data, like Trend analysis results or predictions.
- **Dynamic Validation Rules:** While `Validation.json` is static, you can dynamically generate the JSON content using PHP scripts if your validation requirements change frequently or depend on user roles.
- Troubleshooting
- **Validation Rules Not Applied:** Ensure that the `Validation` extension is properly installed and enabled in `LocalSettings.php`. Clear your MediaWiki cache. Double-check the syntax of your `Validation.json` file. Verify that the parameter names in your `Validation.json` file match the parameter names used in your forms or templates exactly.
- **Incorrect Error Messages:** Review your `Validation.json` file and ensure that the `message` values are correct.
- **Regular Expression Errors:** Test your regular expressions thoroughly using a regular expression tester to ensure they match the expected patterns. Incorrectly formed regular expressions can cause unexpected validation errors. Consider using resources like [2](https://regex101.com/) for testing.
- **Performance Issues:** Complex validation rules, especially those involving regular expressions, can impact performance. Optimize your rules and consider caching validation results if necessary. Avoid overly complex Elliott Wave patterns in regex.
- Security Considerations
While the `Validation` extension enhances data integrity, it's important to remember that it's not a substitute for proper security measures. Always sanitize user input to prevent cross-site scripting (XSS) and other security vulnerabilities. Combine validation with other security best practices, such as input filtering and output encoding. Don't rely solely on client-side validation, as it can be easily bypassed. Server-side validation, provided by the `Validation` extension, is essential for ensuring data security. Consider the implications of data validation on Risk management and potential manipulation of data.
- Resources
- **MediaWiki Extension:Validation:** [3](https://www.mediawiki.org/wiki/Extension:Validation)
- **JSON Format:** [4](https://www.json.org/)
- **Regular Expression Tester:** [5](https://regex101.com/)
- **MediaWiki Parser Functions:** Help:Magic words#Parser functions
- **MediaWiki Forms:** Extension:Forms
- **Understanding Technical Analysis:** [6](https://www.investopedia.com/terms/t/technicalanalysis.asp)
- **Candlestick Pattern Guide:** [7](https://www.schoolofpips.com/candlestick-patterns/)
- **Fibonacci Retracement Explained:** [8](https://www.investopedia.com/terms/f/fibonacciretracement.asp)
- **Moving Average Convergence Divergence (MACD):** [9](https://www.investopedia.com/terms/m/macd.asp)
- **Bollinger Bands:** [10](https://www.investopedia.com/terms/b/bollingerbands.asp)
- **Elliott Wave Theory:** [11](https://www.investopedia.com/terms/e/elliottwavetheory.asp)
- **Risk Management in Trading:** [12](https://www.investopedia.com/terms/r/riskmanagement.asp)
- **Support and Resistance Levels:** [13](https://www.babypips.com/learn-forex/forex-trading-basics/support-and-resistance)
- **Trend Lines:** [14](https://www.investopedia.com/terms/t/trendline.asp)
- **Head and Shoulders Pattern:** [15](https://www.investopedia.com/terms/h/head-and-shoulders.asp)
- **Double Top and Double Bottom:** [16](https://www.investopedia.com/terms/d/doubletop.asp)
- **Triangles:** [17](https://www.investopedia.com/terms/t/triangle.asp)
- **Gaps in Trading:** [18](https://www.investopedia.com/terms/g/gap.asp)
- **Ichimoku Cloud:** [19](https://www.investopedia.com/terms/i/ichimoku-cloud.asp)
- **Parabolic SAR:** [20](https://www.investopedia.com/terms/p/parabolicsar.asp)
- **Average True Range (ATR):** [21](https://www.investopedia.com/terms/a/atr.asp)
- **Relative Strength Index (RSI):** [22](https://www.investopedia.com/terms/r/rsi.asp)
- **Stochastic Oscillator:** [23](https://www.investopedia.com/terms/s/stochasticoscillator.asp)
- **Money Flow Index (MFI):** [24](https://www.investopedia.com/terms/m/mfi.asp)
- **On Balance Volume (OBV):** [25](https://www.investopedia.com/terms/o/obv.asp)
- **Chaikin Money Flow (CMF):** [26](https://www.investopedia.com/terms/c/chaikin-money-flow.asp)
Start Trading Now
Sign up at IQ Option (Minimum deposit $10) Open an account at Pocket Option (Minimum deposit $5)
Join Our Community
Subscribe to our Telegram channel @strategybin to receive: ✓ Daily trading signals ✓ Exclusive strategy analysis ✓ Market trend alerts ✓ Educational materials for beginners