Extension:ListRedLinks

From MediaWiki.org
Jump to: navigation, search


MediaWiki extensions manual - list
Crystal Clear action run.png
ListRedLinks

Release status: stable

Implementation Special page
Description Lists all the red links on the wiki in alphabetical order
Author(s) Steve Elliott (PhantomsteveTalk)
Last version 1.0 (22 June 2010)
MediaWiki 1.15.4
PHP 5.2.13
License Creative Commons Attribution/Share-Alike License 3.0
Download No link

Check usage (experimental)

Contents

[edit] What can this extension do?

This extension will create a Special page (Special:ListRedLinks) which will list all the redlinks on a wiki. Please note that this is really only suitable for a small wiki, as it can take some time!

It looks at all the titles on the pagelinks table, and lists all of the ones which are not on the page table.

Note: If a deleted page had redlinks, these will show up on this listing

[edit] Usage

Go to Special:ListRedLinks and the list will be generated.

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/ListRedLinks/ListRedLinks.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

To install this extension, add the following to LocalSettings.php:

#add configuration parameters here
#setup user rights here
require_once("$IP/extensions/ListRedLinks/ListRedLinks.php");

[edit] Code

[edit] ListRedLinks.php

<?php
# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
if (!defined('MEDIAWIKI')) {
        echo <<<EOT
To install my extension, put the following line in LocalSettings.php:
require_once( "\$IP/extensions/ListRedLinks/ListRedLinks.php" );
EOT;
        exit( 1 );
}
 
$wgExtensionCredits['specialpage'][] = array(
        'name' => 'ListRedLinks',
        'author' => '[[User:Phantomsteve|Phantomsteve]] (based on the original RedLinks by Luc Brunet - luc.brunet at cnri.fr)',
        'url' => 'http://www.mediawiki.org/wiki/Extension:ListRedLinks',
        'description' => 'List all the red links in the wiki in alphabetical order',
        'version' => '1.0',
);
 
$dir = dirname(__FILE__) . '/';
 
$wgAutoloadClasses['ListRedLinks'] = $dir . 'ListRedLinks_body.php'; # Tell MediaWiki to load the extension body.
$wgExtensionMessagesFiles['ListRedLinks'] = $dir . 'ListRedLinks.i18n.php';
$wgExtensionAliasesFiles['ListRedLinks'] = $dir . 'ListRedLinks.alias.php';
$wgSpecialPages['ListRedLinks'] = 'ListRedLinks'; # Let MediaWiki know about your new special page.

$wgSpecialPageGroups['ListRedLinks'] = 'pages'; # Put the special page in the section of "Pages"

[edit] ListRedLinks_body.php

Please note the underscore _ between "RedLinks" and "body"

Note: you will need to put your database details in the "Database details" section below

<?php
class ListRedLinks extends SpecialPage {
        function __construct() {
                parent::__construct( 'ListRedLinks' );
                wfLoadExtensionMessages('ListRedLinks');
        }
 
        function execute( $par) {
        /*
     * List Red Links
     * By Phantom Phantomsteve
     * based on the original RedLinks by Luc Brunet - luc.brunet at cnri.fr
     * http://www.mediawiki.org/wiki/Extension:ListRedLinks
     *
     * List all the red links in the wiki in alphabetical order
     * Version 1.0
    */
 
                global $output, $wgOut;
 
                $this->setHeaders();
 
                // Database details             
                $wgDBserver         = "server";
                $wgDBname           = "name";
                $wgDBuser           = "user";
                $wgDBpassword       = "password";
                $wgDBprefix         = "dbprefix_";
 
                // Handle the query
                $chandle = mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword) ;
                mysql_select_db($wgDBname, $chandle);
                $query1="SELECT DISTINCT pl_title , COUNT(*) as pl_title_count FROM {$wgDBprefix}pagelinks WHERE" .
                               "pl_title NOT IN ( SELECT page_title FROM {$wgDBprefix}page ) GROUP BY pl_title ORDER BY pl_title";
                $result = mysql_query($query1);
 
                // Create the list
        $output="{|\n";
                $itemcount=0;
                while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
                        list($itm,$cnt)=$row;
                        $output.="|[[$itm]] ([[Special:WhatLinksHere/$itm|$cnt page" . ($cnt>1?"s":"") . "]])\n";
                        $itemcount += 1;
                        if ($itemcount==3) {
                                $output.="|-\n";
                                $itemcount=0;
                        }
                }
                $output.="|}";
                $wgOut->addWikiText($output);
 
                // Leave the database
                mysql_free_result($result);
        }
}

[edit] ListRedLinks.i18n.php

<?php
$messages = array();
 
/* *** English *** */
$messages['en'] = array(
        'listredlinks' => 'Red Links (Pages that are non-existent but linked to)',
        'listredlinks-desc' => 'List [[Special:ListRedLinks|all of the current red links on the wiki in alphabetical order]]',
        'listredlinks-header' => "'''This page lists the red links on the wiki - pages which need to be created.'''",
);

[edit] ListRedLinks.alias.php

<?php
$aliases = array();
 
/** English */
$aliases['en'] = array(
        'ListRedLinks' => array( 'ListRedLinks' ),
);

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox