MediaWiki extensions manual
PageAttachment
Release status: unmaintained
Implementation User interface, User activity , Skin , Ajax, Special page , Database
Description This extension extends MediaWiki to allow adding files to a page as attachments.
Author(s) Aldrin Baroi (Aldrintalk)
Latest version See Compatibility Section
MediaWiki See Compatibility Section
PHP 5.4, 5.3, 5.2
Database changes Yes
License GNU General Public License 3.0
Download

GitHub:

Note:
No localisation updates are
provided by translatewiki.net .


README
Hooks used
  • LoadExtensionSchemaUpdates
  • BeforeInitialize
  • EditPage::importFormData
  • ArticleSaveComplete
  • BeforePageDisplay
  • SkinAfterContent
  • SkinAfterBottomScripts
  • UploadForm:initial
  • UploadForm:BeforeProcessing
  • UploadComplete
  • SpecialUploadComplete
  • UserLoginComplete
  • UserLogoutComplete
  • ArticleDelete
  • FileDeleteComplete
  • FileUndeleteComplete
  • LinksUpdate
  • LinksUpdateComplete
  • MagicWordwgVariableIDs
  • LanguageGetMagic
  • ParserBeforeInternalParse

The PageAttachment extension allows adding files to a page as attachments.

By default, attachments are only allowed to be added to pages in the "Main" namespace. Through configuration changes, attachments can be allowed to be attached to any other pages under other namespaces, for example, "User Talk" pages.

Security

Every precaution has been taken to make this extension secure by following guidelines outlined in MediaWiki's security manual for developers.

See Security for developers

If you identify any security (or any other) issues, please, open a bug report at the following link:

PageAttachment Issues

What is new?

New Versions Released: (January 21, 2013)

  • 3.1.0
  • 3.1.0 PHP 5.2.3
  • 2.3.0
  • 2.3.0 PHP 5.2
  • 1.5.0
  • 1.5.0 PHP 5.2

See compatibility section to choose the right version for you platform

The foregoing releases contain the following fixes/enhancements:

Version 3.1.0 Only

  • Issue# 67 - Browse/Search & Attach Files function returns error message...
    • Part 1) Fixed - IContextSource issue
      • Impacted PHP 5.2.3 only (MediaWiki 1.19 & 1.20)
    • Part 2) Fixed - Attachment option disappears on browsing beyond first page or, executing search function
      • Impacted PHP 5.3 & 5.4 (MediaWiki 1.20 Only)
    • Part 3) Fixed - Search not working

Version 3.1.0, 2.3.0, 1.5.0

  • Issue# 65 - PageAttachment not setting filelinks (backlinks)
    • Maintenance script to update file links for existing attachments is included
      • You can run the script using the following command from MediaWiki install directory:

        php extensions/PageAttachment/maintenance/AddMissingFileLinks.php




New Versions Released: (January 13, 2013)

  • 3.0.1 PHP 5.2.3

This release contains the following fixes/enhancements:

  • Issue 67: Browse/Search & Attach Files function returns error message...
    • Was partially fixed

New Versions Released: (December 28, 2012)

  • 3.0.0
  • 3.0.0 PHP 5.2.3
  • 2.2.0
  • 2.2.0 PHP 5.2

See compatibility section to choose the right version for you platform.

This release contains the following fixes/enhancements:

Version 3.0.0 Only

  • Issue 39: Fatal error: Call to private method LinksUpdate::getExistingCategories() from context 'PageAttachment\Category\CategoryManager'
  • Issue 40: Page Attachments List Section Does Not Load
  • Issue 41: Catchable fatal error: Argument 1 passed to ImageListPager::__construct() must implement interface IContextSource...
  • Issue 47: Get "No such action" error page

Versions 2.2.0 and 3.0.0

  • Issue 50: Ability to remove the attachment box on pages? __NoAttachment__ for example?
  • Issue 52: Specify default pages to have attachments using category names
  • Issue 53: Specify exclusion pages through configuration settings
  • Issue 54: Allow attachments to a page through the use of "__ATTACHMENT__" token
  • Issue 55: Exclude attachments to a page through the use of "__NOATTACHMENT__" token
  • Issue 57: Removing attached files (utf8 pages)

Compatibility


PHP Versions (minimum) 5.4   5.3   5.2   5.2.3
PageAttachment Versions Stable 3.1.0 1.5.0 2.3.0 3.1.0 1.5.0-php-5.2 2.3.0-php-5.2 3.1.0-php-5.2.3
Latest 3.1.0 1.5.0 2.3.0 3.1.0 1.5.0-php-5.2 2.3.0-php-5.2 3.1.0-php-5.2.3
MediaWiki Versions 1.19.0 1.20.0 1.16.2 1.17.0 1.18.0 1.19.0 1.20.0 1.16.2 1.17.0 1.18.0 1.19.0 1.20.0

TBR: To be released.

* Code checked in.

  • Notes on PHP 5.4 release
    • Tested on Ubuntu 12.10 only
  • Notes on PHP 5.2.x release
    • PHP 5.2.x compatible release is created by transforming the PHP 5.3 compatible code through the use of "Ant" script.
    • Custom Date Formatting is not supported
    • MediaWiki 1.19 & 1.20 requires PHP 5.2.3 (minimum)


Supported databases

  • MySQL
    • Supported in all versions of PageAttachment
  • PostgreSQL
    • Supported from PageAttachment version 3.2.0
    • Not yet released
    • Code checked in the default & v3.2.0 branches

Known issues

  1. File link (backlinks)
    If you run the "maintenance/refreshLinks.php" script, be sure re-run the "AddMissingFileLinks.php" script; since, "refreshLinks.php" removes the backlinks and need to be recreated.


Usage

Supported use-cases:

  • View attachments
  • Upload & attach a file
  • Browse/search for existing (uploaded) files and attach
  • Download an attachment
  • Remove an attachment (does not delete the file from MediaWiki repository)
    • Remove an attachment permanentely
      • NOTE: MediaWiki archives the deleted files. You would have to run the maintenance script
            php deleteArchivedFiles.php --delete
        to remove the files from the archive. See: Manual:DeleteArchivedFiles
  • View an attachment file's history
  • View audit log
    • For a specific attachment
    • For all attachmnets for a page
  • Auto remove an attachment when the attachment file is deleted from MediaWiki repository
  • Auto restore an attachment when a file deleted from MediaWiki repository is restored and if it was attached to any page
  • Set attachment category during upload
  • Watch Attachments
  • NEW in 3.0.0 and 2.2.0 versions
    • Specify default pages to have attachments using category names
    • Specify exclusion pages through configuration settings
    • Allow attachments to a page through the use of "__ATTACHMENTS__" token
    • Exclude attachments to a page through the use of "__NOATTACHMENTS__" token
  • NEW in 3.1.0, 2.3.0, and 1.5.0 versions
    • Auto set file links (back links)
      • Maintenance script to update file links for existing attachments is included
        • You can run the script using the following command from MediaWiki install directory:

          php extensoins/PageAttachment/maintenance/AddMissingFileLinks.php

Note: By default following are turned off/not activated

  • Audit logging
  • Set attachment category during upload
  • Permanent file deletion
  • Watch Attachments
  • Default pages to have attachments using category names
  • Exclusion pages through configuration settings
  • Allow attachments to a page through the use of "__ATTACHMENTS__" token
  • Exclude attachments to a page through the use of "__NOATTACHMENTS__" token


Download instructions

This project is hosted on GitHub at the following link:

https://github.com/aldrinbaroi/mediawiki-page-attachment

You can also download the code directly via Git from the MediaWiki source code repository

git clone https://github.com/aldrinbaroi/mediawiki-page-attachment.git

Prerequisites


MediaWiki file upload functionality must be enabled for this extension to work. If file upload is not enabled, only "view" activity is allowed.

Please consult: Configuring File Uploads

Installation

  • To build the extension, first Apache Ant must be installed
  • To build the source code the do the following:
    $ git clone https://github.com/aldrinbaroi/mediawiki-page-attachment
    $ cd mediawiki-page-attachment
    $ ant distribute
    
  • Ant has now generated a ZIP archive in the folder dist/. Unpack this archive in your extensions/ folder. Now you should have a PageAttachment/ folder in the extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once("$IP/extensions/PageAttachment/SetupExtension.php");
    
  • Update the database
  • Yes Done Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

Configuration


For complete & detail configuration options, see the following link:

Complete & Detail Configuration Options

  • NOTE: The configuration options detailed in the following would be removed in the future.
    • Since the configuration options are huge and hard to maintain on a single page.


It is recommended to use the site specific configuration file to override the defaults and specify site specific settings.

Default configuration file is:

config/DefaultConfigurations.php

Site specific configuration file is:

config/SiteSpecificConfigurations.php

Allowed Namespaces

Attachments are allowed only on pages under configured namespaces.

By default, only "Main" namespace is enabled:

$wgPageAttachment_allowedNameSpaces[] = NS_MAIN;

To add other namespaces, for example, "Talk", "User", and "User Talk" add the following in the site specific configuration file:

$wgPageAttachment_allowedNameSpaces[] = NS_TALK; 
$wgPageAttachment_allowedNameSpaces[] = NS_USER; 
$wgPageAttachment_allowedNameSpaces[] = NS_USER_TALK;


MediaWiki User Rights

For upload & attachment activity, check is made to ensure the following:

  • User is not blocked
  • Wiki is not in readonly mode

PageAttachment User Rights

This extension maintains page attachment specific rights separately.

Page attachment specific rights are:

  • View attachments
  • Upload & attach a file
  • Browse/Search for existing (uploaded) files and attach
  • Remove attachments
  • Download attachments
  • View history
  • View audit log (if audit logging is enabled)


NOTE: View rights must be enabled for all other rights to work


The rights can be applied:

  • When login is not required
    • Only at the activity level (e.g. upload & attach a file)
  • When login is required, rights can be applied to each activity
    • At a group level
    • At a user specific level


NOTE: The groups/users must be valid MediaWiki groups/users.

Audit Log

Audit logging by default is turned off. To enable audit logging, set the following:

$wgPageAttachment_enableAuditLog = true;


Cache

Server side cache
PageAttachment extension uses cache to store page attachment list, attachment data, and article names.
MediaWiki's Cache
By default, MediaWiki cache is used and recommended.
Recommended for production use.
To use MediaWiki's cache, no configuration change is required.
Please consult: Set up object caching
PageAttachment's Internal Cache
Alternatively, you can use one of the two internal cache implementations.
* SQLite3 Cache
* Database Cache
Use internal cache implementations for development & testing purposes only.
To use SQLite3 internal cache, set the following in the site-specific configuration file:
    $wgPageAttachment_useInternalCache = true;
    $wgPageAttachment_internalCacheType = 'SQLite3';
    $wgPageAttachment_sqlite3CacheDirectory = 'Absolute path to a directory where web server has read-write access';
To use Database cache, set the following in the site-specific configuration file:
    $wgPageAttachment_useInternalCache = true;
    $wgPageAttachment_internalCacheType = 'Database';
Browser cache
Ajax is used to load the page attachment list.
By default Ajax data caching in user's web browser is disabled. The reason for this that Ajax caching will sometime cause inconsistent data display based on when an attachment was added/update/removed and after user's login/logout.
If you want to enable Ajax caching, set the following in the site-specific configuration file:
    $wgPageAttachment_ajaxCacheDuration = N;
N = Number of seconds to cache Ajax data in the user's browser.

User Interface


User Name Format
By default, real-user name is displayed, if available. To disable this and to display only user id, set the following:

$wgPageAttachment_showUserRealName = false;


Status Message Display Format
The default format applies to all skins. You can override the default and/or provide skin specific formats.
The default status message format is:

$wgPageAttachment_statusMessageFormat['default'] = ' » STATUS_MESSAGE « ';

The foregoing is rendered as the following:

 » STATUS_MESSAGE « 


The STATUS_MESSAGE is replaced with the actual message.
To change the default format, replace the YOUR_HTML_CODE with your actual HTML code. Please, leave the STATUS_MESSAGE token in:

$wgPageAttachment_statusMessageFormat['default'] = 'YOUR_HTML_CODE STATUS_MESSAGE YOUR_HTML_CODE';

To specify skin specific format, add additional settings and replace 'default' with the actual skin name. Example:

$wgPageAttachment_statusMessageFormat['skin name'] = 'YOUR_HTML_CODE STATUS_MESSAGE YOUR_HTML_CODE';


Date Format
Date formatting is based on MediaWiki settings. You can override this and specify language specific settings. By default, for English language, MediaWiki date format is overridden with the following format:

$wgPageAttachment_dateFormat['en'] = 'M d, Y h:i a';

The rendered date looks like, e.g.: Jul 24, 2011 11:17 pm
To disable this, unset the foregoing setting as follows:

$wgPageAttachment_dateFormat['en'] = null;


Cascading Style Sheet (CSS) Files

  • Common
  • For left-to-right (LTR) language
  • For right-to-left (RTL) language


Icon Image Files
The default icons apply to all skins. You can override the default and/or provide skin specific icons.
The default icon image files are:

$wgPageAttachment_imgSpacer['default']             = 'transparent-16x16.png';
$wgPageAttachment_imgBrowseSearchAttach['default'] = 'tango-folder-saved-search-16x16.png';
$wgPageAttachment_imgUploadAndAttach['default']    = 'tango-mail-attachment-16x16.png';
$wgPageAttachment_imgAttachFile['default']         = 'tango-mail-attachment-16x16.png';
$wgPageAttachment_imgRemoveAttachment['default']   = 'tango-edit-cut-16x16.png';
$wgPageAttachment_imgViewAuditLog['default']       = 'tango-edit-find-16x16.png';
$wgPageAttachment_imgViewHistory['default']        = 'tango-system-file-manager-16x16.png';

To provide skin specific icons, add additional settings and replace the 'default' with the skin name.
Note: The included image files are obtained from Tango Desktop Project and resized.

Display Column Widths


Watch Attachments

On watched pages, to send notification on attachment activity:

$wgPageAttachment_enableNotification = true;


To send the emails using MediaWiki Job Queue

  • Setup MediaWiki's Job Queue processing
  • In the site specific configuration file, set the following:
$wgPageAttachment_useJobQueueForNotification = true;


Notification emails are formatted using a template. Two templates are included:

  • Plain Text
  • HTML

Note: You must specify which template to use.

To use plain-text template, set the following:

$wgPageAttachment_messageFormat = 'plaintext';


To use HTML template, set the following:

$wgPageAttachment_messageFormat = 'html';

View/Submit Issues, Enhancement Requests

Please, submit new issue/enhancement-request at the following link:

PageAttachment Issues

Google Discussion Group

Google Discussion Group for PageAttachment Extension

This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.