Extension:Protected pages
|
|
This extension is obsolete! It has been replaced by core functionality in the MediaWiki software (which was added in version 1.10.0). |
Protected pages is a Special page that shows - yes, you guessed it right ;) - list of protected pages. Page was requested by Filip Maljković aka Dungodung, so he gets the credit for comming up with the idea.
[edit] The files
This extension is a Query Page / Special page extension, so it has to have two files (if anyone knows a better way to do this, I'm open for suggestions):
[edit] Protectedpages.php
This file registers the special page with Mediawiki; it goes into the extensions folder, and is what gets included in LocalSettings.php (that is, you have to put include ("extensions/protectedpages.php"); in LocalSettings.php)
<?php
require_once( "SpecialPage.php" );
$wgExtensionFunctions[] = "wfProtectedpagesSetup";
$wgExtensionCredits['other'][] = array(
'name' => 'ProtectedPages',
'description' => 'displays protected pages',
'author' => 'Branislav Jovanovic, acting on the request by Filip Maljkovic'
);
function wfProtectedpagesSetup() {
SpecialPage::addPage( new SpecialPage("Protectedpages") );
global $wgMessageCache;
$wgMessageCache->addMessages(
array('protectedpages' => 'Protected pages')
);
}
?>
[edit] SpecialProtectedpages.php
This is the actual code of special page. I wanted to put it all in one file, but apparently when you add a page via SpecialPage::addpage method, you have to have a SpecialPAGENAME.php file :( thus two files. This one goes into te includes (or any other directory in include_path).
<?php
if (!defined('MEDIAWIKI')) die();
/**
* Display list of protected pages
*
* @package MediaWiki
* @subpackage Extensions
*
*
* @author Branislav Jovanović <branej@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
*
*/
require_once( "QueryPage.php" );
class SpecialProtectedPages extends PageQueryPage {
var $Namespace = null;
var $Invert = false;
function isExpensive() { return true; }
function isSyndicated() { return false; }
function linkParameters() {
return array('namespace' => $this->Namespace,
'invert' => $this->Invert);
}
function getPageHeader ( ) {
global $wgContLang, $wgScript;
$t = Title::makeTitle( NS_SPECIAL, 'Protectedpages' );
$namespaceselect = HTMLnamespaceselector($this->Namespace, '');
$submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
$invertbox = "<input type='checkbox' name='invert' value='1' id='nsinvert'" .
( $this->Invert ? ' checked="checked"' : '' ) . ' />';
$out = "<div class='namespacesettings'><form method='get' action='{$wgScript}'>\n";
$out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
$out .= "
<div id='nsselect' class='recentchanges'>
<label for='namespace'>" . wfMsgHtml('namespace') . "</label>
$namespaceselect $submitbutton $invertbox <label for='nsinvert'>" .
wfMsgHtml('invert') . "</label>
</div>";
$out .= '</form></div>';
return $out;
}
function getName() { return "Protectedpages"; }
function getSQL() {
global $wgRequest;
$this->Namespace = $wgRequest->getIntOrNull('namespace');
if ($this->Namespace === null) {
$namespace = 'page_namespace';
} else {
$namespace = $this->Namespace;
}
$this->Invert = $wgRequest->getBool('invert');
$dbr =& wfGetDB( DB_SLAVE );
$page = $dbr->tableName( "page" );
$sql = "SELECT 'ProtectedPages' as type, $namespace as namespace, page_title as title," .
"page_title as value FROM $page WHERE " .
"page_restrictions NOT LIKE '' AND page_restrictions NOT LIKE 'move=:edit=' ";
if ($this->Namespace !== null) {
if ($this->Invert) {
$sql .= "AND page_namespace != " . $this->Namespace . " ";
} else {
$sql .= "AND page_namespace = " . $this->Namespace . " ";
}
}
return $sql;
}
}
function wfSpecialProtectedpages() {
list( $limit, $offset ) = wfCheckLimits();
$app = new SpecialProtectedPages();
$app->doQuery( $offset, $limit );
}
?>
Comments are welcome.
