Extension:PageInfo

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
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)
Latest version 1.0
MediaWiki 1.16+, succesfully tested: 1.15.1
PHP 5.2+
License GNU General Public License 3.0 or later
Download
Example none public
Hooks used
BeforePageDisplay
OutputPageBeforeHTML
Translate the PageInfo extension if it is available at translatewiki.net
Check usage and version matrix.

What can this extension do?[edit]

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.

Usage[edit]

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

Download instructions[edit]

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.

Installation[edit]

Add the following line to LocalSettings.php:

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

Mediawiki 1.31[edit]

Even when the changes below are applied, the extension still does not work.

When Using MediaWiki 1.1.18[edit]

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__);

Fix for Mediawiki 1.23.x[edit]

As of 1.23.0 $wgArticle is deprecated and has been replaced, so all uses of it have to be removed. Also you have to do all of the above 1.1.18 changes before.

In the function pi_Show() add this at the beginning:

$context = RequestContext::getMain();
$article_obj = $context->getWikiPage();

In the same function replace

$pi_CreatedBy = $wgArticle->getUserText();

with

$pi_CreatedBy = $context->getUser();

Replace

$pi_LastEditTimestamp = strtotime( $wgArticle->mTouched);

with

$pi_LastEditTimestamp = strtotime( $article_obj->getTimestamp() );

Replace

 $pi_Container .= $this->pi_CreateEntry( wfMsgHTML( 'paramViews' ), $wgArticle->getCount() );

with

 $pi_Container .= $this->pi_CreateEntry( wfMsgHTML( 'paramViews' ), $article_obj->getCount() );

The next function to edit is "pi_DontDisplay()".

Add the start of the function add this:

$context = RequestContext::getMain();

Replace the if-statement:

if( $wgArticle === null || 
    $this->pi_MagicWordMatchedInArticle || 
    !$wgArticle->exists() || 
    !in_array( $ns, $wgPI_Namespaces ) || 
    $action == 'edit' ) 

With

if( !$context->canUseWikiPage() ||
    $this->pi_MagicWordMatchedInArticle ||
    !in_array( $ns, $wgPI_Namespaces ) ||
    $action == 'edit' )

Configuration parameters[edit]

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.

Magic Word, hiding on a single page[edit]

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

Authors[edit]

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

Version[edit]

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

1.0[edit]

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

Internationalization[edit]

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

Screenshots[edit]

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).