Extension:PageInfo

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
PageInfo

Release status: beta

px
Implementation Skin, User rights
Description A info-box near the table of contents or at the top of a wiki page. Informations about creation, edits and views.
Author(s) Philipp Glatza, le-tex publishing services GmbH (PhilGTalk)
Last version 1.0
MediaWiki 1.16+, succesfully tested: 1.15.1
PHP 5.2+
License GPL v3 or newer
Download https://github.com/pglatza/mw-ext-pageinfo
Example none public
Hooks used
BeforePageDisplay

OutputPageBeforeHTML

Check usage (experimental)

Contents

[edit] What can this extension do?

This extension displays an information box near to the table of contents about creation and editing.

Overall features:

  • Displaying creator, creation date, other authors, last edit date, edit rights needed to edit this page (currently only the info "all" or "admin" supported), page views and edit state: you define the number of min/mid/max days since last edit and this extension remind you to update the article.
  • Displays also other authors and the number of watchers and edits. (so, the extension replaces/includes the siteinfo query).
  • When the table of content is present, it will be placed right of it (JS needed); otherwise before article content.
  • You can save the state (hide or show) with cookies enabled on.

[edit] Usage

This extension just displays some information on every wiki content page. No interactive elements.

[edit] Download instructions

Download the files PageInfo.php and PageInfo.i18n.php from https://github.com/pglatza/mw-ext-pageinfo and save both files at $IP/extensions/PageInfo.

Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

Add the following line to LocalSettings.php:

require_once( "$IP/extensions/PageInfo/PageInfo.php" );

[edit] When Using MediaWiki 1.1.18

I could not update the source for this extension. There is a bug when using with MediaWiki 1.1.18. The following sections need to be changed:

// Collect informations
$pi_sql = "
SELECT rev_user_text
FROM " . $db->tableName( 'revision' ) . " 
WHERE rev_page = " . $wgTitle->getArticleID() . "
ORDER BY rev_id ASC
LIMIT 1";
$pi_CreatedBy_SQL = $dbr->fetchRow( $dbr->query( $pi_sql ) );
$pi_CreatedBy = $pi_CreatedBy_SQL[ 'rev_user_text' ];

Becomes:

$pi_CreatedBy_SQL = $dbr->select('revision', 
                                 'rev_user_text', 
                                 'rev_page = ' . $wgTitle->getArticleID(),
                                 __METHOD__,
                                 array('ORDER BY' => 'rev_id ASC')
                                 );
$row = $pi_CreatedBy_SQL->fetchRow();
$pi_CreatedBy = $row['rev_user_text'];


// Get other authors
$pi_sql = "
SELECT DISTINCT rev_user_text
FROM " . $db->tableName( 'revision' ) . "
WHERE rev_user_text NOT REGEXP '^$pi_CreatedBy$' 
AND rev_page = " . $wgTitle->getArticleID();
$pi_Contributors_SQL = $dbr->fetchRow( $dbr->query( $pi_sql ) );
if( is_array( $pi_Contributors_SQL ) ) {
        $pi_Contributors_SQL = array_unique( $pi_Contributors_SQL );
        if( count( $pi_Contributors_SQL ) > 0 ) {
                foreach( $pi_Contributors_SQL as $contributor ) {
                        $pi_Contributors .= $contributor . ", ";
                }
                $pi_Container .= $this->pi_CreateEntry( 
                        wfMsgHTML( 'paramOtherAuthors' ), 
                        substr( $pi_Contributors, 0, -2 ) );
        }
}

Becomes:

// Get other authors
$pi_Contributors_SQL = $dbr->select('revision',
                                    'rev_user_text',
                                     array("rev_user_text NOT REGEXP '^" . $pi_CreatedBy . "$'", 'rev_page = '  . $wgTitle->getArticleID()),
                                     __METHOD__);
$pi_Contributors = "";
$count = 1;
while( $count <= $pi_Contributors_SQL->numRows() ) {
    $row = $pi_CreatedBy_SQL->fetchRow();
    if(stripos($pi_Contributors,$row['rev_user_text']) === false && trim($row['rev_user_text']) <> "") {
        $pi_Contributors .= $row['rev_user_text'] . ", ";
    }
    $count += 1;
}
if ($pi_Contributors != ""){
    $pi_Container .= $this->pi_CreateEntry( 
    wfMsgHTML( 'paramOtherAuthors' ), 
    substr( $pi_Contributors, 0, -2 ) );
}


$pi_sql = "
SELECT COUNT( * )
FROM " .  $db->tableName( 'revision' ) . "
WHERE rev_page = " . $wgTitle->getArticleID();
$pi_CountEdits = $dbr->fetchRow( $dbr->query( $pi_sql ) );

Becomes:

$pi_CountEdits = $dbr->selectField('revision',
                                   'COUNT( * )',
                                   'rev_page = ' . $wgTitle->getArticleID(),
                                   __METHOD__);


$pi_sql = "
SELECT COUNT( * )
FROM " . $db->tableName( 'watchlist' ) . "
WHERE wl_title = '" . $wgTitle->getDBkey() . "'
AND wl_namespace = " . $wgTitle->getNamespace();
$pi_Watcher_SQL = $dbr->fetchRow( $dbr->query( $pi_sql ) );

Becomes:

$pi_Watcher_SQL = $dbr->selectField('watchlist',
                                    'COUNT( * )',
                                    array("wl_title = '" . $wgTitle->getDBkey() . "'", 'wl_namespace = ' . $wgTitle->getNamespace()),
                                    __METHOD__);

[edit] Configuration parameters

Adjust these variables before the page-info line (see Installation above) in LocalSettings.php.

Name Default value Meaning
$wgPI_EDITSTATUS_MIN 30 Sets minimum difference of days between today and last edit (message: "up to date").
$wgPI_EDITSTATUS_MID 60 Middle value for difference of days between today and last edit (message: "out of date?").
$wgPI_EDITSTATUS_MAX 90 Sets maximum difference of days between today and last edit (message: "please update").
$wgPI_COLORPARAM "#000" Font color of param.
$wgPI_COLORVALUE "#5318FE" Font color of the value.

[edit] Magic Word, hiding on a single page

On every page you can use the magic word "__NO_PI__" to disable the extension.

[edit] Authors

PageInfo has been written by Philipp Glatza and was requested by Alexander Goerlt (Vandenhoeck & Ruprecht).

[edit] Version

Maybe in a future version all rows are adjustable - adding functionality to reorder and removing rows from output.

[edit] 1.0

Initial release. Name of the extension during development, until public release: CurrentSiteInfo.

[edit] Internationalization

Currently (v1.0), english and german are supported.

[edit] Screenshots

Rendering of the info box at main page (version 1.0, german).
Rendering of the info box on a page with table of contents enabled (version 1.0, english).
Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox