2004-05-15 03:36:39 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* SpecialPage: handling special pages and lists thereof
|
|
|
|
|
* $wgSpecialPages is a list of all SpecialPage objects. These objects are
|
|
|
|
|
* either instances of SpecialPage or a sub-class thereof. They have an
|
|
|
|
|
* execute() method, which sends the HTML for the special page to $wgOut.
|
|
|
|
|
* The parent class has an execute() method which distributes the call to
|
|
|
|
|
* the historical global functions. Additionally, execute() also checks if the
|
|
|
|
|
* user has the necessary access privileges and bails out if not.
|
|
|
|
|
*
|
|
|
|
|
* To add a special page at run-time, use SpecialPage::addPage().
|
|
|
|
|
* DO NOT manipulate this array at run-time.
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
2005-01-27 19:51:47 +00:00
|
|
|
* @subpackage SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-08-12 14:55:35 +00:00
|
|
|
|
2005-04-24 04:16:50 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
$wgSpecialPages = array(
|
2005-04-24 04:16:50 +00:00
|
|
|
'DoubleRedirects' => new SpecialPage ( 'DoubleRedirects' ),
|
|
|
|
|
'BrokenRedirects' => new SpecialPage ( 'BrokenRedirects' ),
|
|
|
|
|
'Disambiguations' => new SpecialPage ( 'Disambiguations' ),
|
2004-11-12 21:56:58 +00:00
|
|
|
|
|
|
|
|
'Userlogin' => new SpecialPage( 'Userlogin' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Userlogout' => new UnlistedSpecialPage( 'Userlogout' ),
|
|
|
|
|
'Preferences' => new SpecialPage( 'Preferences' ),
|
|
|
|
|
'Watchlist' => new SpecialPage( 'Watchlist' ),
|
2005-07-23 05:47:25 +00:00
|
|
|
|
2005-05-28 11:09:22 +00:00
|
|
|
'Recentchanges' => new IncludableSpecialPage( 'Recentchanges' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Upload' => new SpecialPage( 'Upload' ),
|
|
|
|
|
'Imagelist' => new SpecialPage( 'Imagelist' ),
|
2005-09-08 14:15:28 +00:00
|
|
|
'Newimages' => new IncludableSpecialPage( 'Newimages' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Listusers' => new SpecialPage( 'Listusers' ),
|
|
|
|
|
'Statistics' => new SpecialPage( 'Statistics' ),
|
2005-05-13 11:57:31 +00:00
|
|
|
'Random' => new SpecialPage( 'Randompage' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Lonelypages' => new SpecialPage( 'Lonelypages' ),
|
|
|
|
|
'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ),
|
2004-12-01 12:23:14 +00:00
|
|
|
'Uncategorizedcategories'=> new SpecialPage( 'Uncategorizedcategories' ),
|
2005-07-09 19:19:10 +00:00
|
|
|
'Unusedcategories' => new SpecialPage( 'Unusedcategories' ),
|
2005-05-01 12:59:39 +00:00
|
|
|
'Unusedimages' => new SpecialPage( 'Unusedimages' ),
|
2005-10-16 02:23:55 +00:00
|
|
|
'Wantedpages' => new IncludableSpecialPage( 'Wantedpages' ),
|
2005-10-21 02:07:29 +00:00
|
|
|
'Wantedcategories' => new SpecialPage( 'Wantedcategories' ),
|
2005-08-15 02:59:12 +00:00
|
|
|
'Mostlinked' => new SpecialPage( 'Mostlinked' ),
|
2005-10-23 18:26:37 +00:00
|
|
|
'Mostlinkedcategories' => new SpecialPage( 'Mostlinkedcategories' ),
|
2005-10-08 22:39:17 +00:00
|
|
|
'Mostcategories' => new SpecialPage( 'Mostcategories' ),
|
|
|
|
|
'Mostimages' => new SpecialPage( 'Mostimages' ),
|
|
|
|
|
'Mostrevisions' => new SpecialPage( 'Mostrevisions' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Shortpages' => new SpecialPage( 'Shortpages' ),
|
|
|
|
|
'Longpages' => new SpecialPage( 'Longpages' ),
|
2005-05-28 17:17:27 +00:00
|
|
|
'Newpages' => new IncludableSpecialPage( 'Newpages' ),
|
2004-09-19 19:37:26 +00:00
|
|
|
'Ancientpages' => new SpecialPage( 'Ancientpages' ),
|
|
|
|
|
'Deadendpages' => new SpecialPage( 'Deadendpages' ),
|
2005-05-28 11:09:22 +00:00
|
|
|
'Allpages' => new IncludableSpecialPage( 'Allpages' ),
|
2005-08-10 21:14:38 +00:00
|
|
|
'Prefixindex' => new IncludableSpecialPage( 'Prefixindex' ) ,
|
2004-09-19 19:37:26 +00:00
|
|
|
'Ipblocklist' => new SpecialPage( 'Ipblocklist' ),
|
|
|
|
|
'Specialpages' => new UnlistedSpecialPage( 'Specialpages' ),
|
|
|
|
|
'Contributions' => new UnlistedSpecialPage( 'Contributions' ),
|
|
|
|
|
'Emailuser' => new UnlistedSpecialPage( 'Emailuser' ),
|
|
|
|
|
'Whatlinkshere' => new UnlistedSpecialPage( 'Whatlinkshere' ),
|
|
|
|
|
'Recentchangeslinked' => new UnlistedSpecialPage( 'Recentchangeslinked' ),
|
|
|
|
|
'Movepage' => new UnlistedSpecialPage( 'Movepage' ),
|
|
|
|
|
'Blockme' => new UnlistedSpecialPage( 'Blockme' ),
|
|
|
|
|
'Booksources' => new SpecialPage( 'Booksources' ),
|
|
|
|
|
'Categories' => new SpecialPage( 'Categories' ),
|
|
|
|
|
'Export' => new SpecialPage( 'Export' ),
|
|
|
|
|
'Version' => new SpecialPage( 'Version' ),
|
|
|
|
|
'Allmessages' => new SpecialPage( 'Allmessages' ),
|
|
|
|
|
'Log' => new SpecialPage( 'Log' ),
|
2005-12-11 10:39:51 +00:00
|
|
|
'Blockip' => new SpecialPage( 'Blockip', 'block' ),
|
2005-12-25 19:55:34 +00:00
|
|
|
'Undelete' => new SpecialPage( 'Undelete', 'deletedhistory' ),
|
2005-03-20 06:09:26 +00:00
|
|
|
"Import" => new SpecialPage( "Import", 'import' ),
|
2004-10-24 19:14:48 +00:00
|
|
|
'Lockdb' => new SpecialPage( 'Lockdb', 'siteadmin' ),
|
|
|
|
|
'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ),
|
2005-05-01 12:59:39 +00:00
|
|
|
'Userrights' => new SpecialPage( 'Userrights', 'userrights' ),
|
2005-09-13 16:35:35 +00:00
|
|
|
'MIMEsearch' => new SpecialPage( 'MIMEsearch' ),
|
2006-01-02 13:03:14 +00:00
|
|
|
'Unwatchedpages' => new SpecialPage( 'Unwatchedpages', 'unwatchedpages' ),
|
2006-03-16 19:04:25 +00:00
|
|
|
'Listredirects' => new SpecialPage( 'Listredirects' ),
|
|
|
|
|
'Revisiondelete' => new SpecialPage( 'Revisiondelete', 'deleterevision' ),
|
2005-05-01 12:59:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if( !$wgDisableCounters ) {
|
|
|
|
|
$wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !$wgDisableInternalSearch ) {
|
2005-09-13 16:35:35 +00:00
|
|
|
$wgSpecialPages['Search'] = new SpecialPage( 'Search' );
|
2005-05-01 12:59:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( $wgEmailAuthentication ) {
|
|
|
|
|
$wgSpecialPages['Confirmemail'] = new UnlistedSpecialPage( 'Confirmemail' );
|
|
|
|
|
}
|
2004-05-15 03:36:39 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Parent special page class, also static functions for handling the special
|
|
|
|
|
* page list
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
class SpecialPage
|
|
|
|
|
{
|
2004-09-19 19:37:26 +00:00
|
|
|
/**#@+
|
|
|
|
|
* @access private
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* The name of the class, used in the URL.
|
|
|
|
|
* Also used for the default <h1> heading, @see getDescription()
|
|
|
|
|
*/
|
|
|
|
|
var $mName;
|
|
|
|
|
/**
|
|
|
|
|
* Minimum user level required to access this page, or "" for anyone.
|
|
|
|
|
* Also used to categorise the pages in Special:Specialpages
|
|
|
|
|
*/
|
|
|
|
|
var $mRestriction;
|
|
|
|
|
/**
|
|
|
|
|
* Listed in Special:Specialpages?
|
|
|
|
|
*/
|
|
|
|
|
var $mListed;
|
|
|
|
|
/**
|
|
|
|
|
* Function name called by the default execute()
|
|
|
|
|
*/
|
|
|
|
|
var $mFunction;
|
|
|
|
|
/**
|
|
|
|
|
* File which needs to be included before the function above can be called
|
|
|
|
|
*/
|
|
|
|
|
var $mFile;
|
2005-05-28 11:09:22 +00:00
|
|
|
/**
|
|
|
|
|
* Whether or not this special page is being included from an article
|
|
|
|
|
*/
|
|
|
|
|
var $mIncluding;
|
|
|
|
|
/**
|
|
|
|
|
* Whether the special page can be included in an article
|
|
|
|
|
*/
|
|
|
|
|
var $mIncludable;
|
2005-07-23 05:47:25 +00:00
|
|
|
|
2005-05-28 11:09:22 +00:00
|
|
|
|
2005-01-27 19:51:47 +00:00
|
|
|
/**#@-*/
|
2004-08-13 02:48:42 +00:00
|
|
|
|
2005-07-23 05:47:25 +00:00
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Add a page to the list of valid special pages
|
|
|
|
|
* $obj->execute() must send HTML to $wgOut then return
|
|
|
|
|
* Use this for a special page extension
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function addPage( &$obj ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
global $wgSpecialPages;
|
|
|
|
|
$wgSpecialPages[$obj->mName] = $obj;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Remove a special page from the list
|
|
|
|
|
* Occasionally used to disable expensive or dangerous special pages
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function removePage( $name ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
global $wgSpecialPages;
|
|
|
|
|
unset( $wgSpecialPages[$name] );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Find the object with a given name and return it (or NULL)
|
|
|
|
|
* @static
|
|
|
|
|
* @param string $name
|
|
|
|
|
*/
|
2005-08-15 02:59:12 +00:00
|
|
|
function getPage( $name ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
global $wgSpecialPages;
|
|
|
|
|
if ( array_key_exists( $name, $wgSpecialPages ) ) {
|
|
|
|
|
return $wgSpecialPages[$name];
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-23 05:47:25 +00:00
|
|
|
|
2005-05-11 03:21:25 +00:00
|
|
|
/**
|
|
|
|
|
* @static
|
2005-05-11 04:06:36 +00:00
|
|
|
* @param string $name
|
|
|
|
|
* @return mixed Title object if the redirect exists, otherwise NULL
|
2005-05-11 03:21:25 +00:00
|
|
|
*/
|
2005-08-15 02:59:12 +00:00
|
|
|
function getRedirect( $name ) {
|
2005-05-28 11:51:27 +00:00
|
|
|
global $wgUser;
|
2005-10-12 06:11:37 +00:00
|
|
|
|
2005-10-12 06:14:47 +00:00
|
|
|
$redirects = array(
|
2005-10-12 06:11:37 +00:00
|
|
|
'Mypage' => Title::makeTitle( NS_USER, $wgUser->getName() ),
|
|
|
|
|
'Mytalk' => Title::makeTitle( NS_USER_TALK, $wgUser->getName() ),
|
|
|
|
|
'Mycontributions' => Title::makeTitle( NS_SPECIAL, 'Contributions/' . $wgUser->getName() ),
|
|
|
|
|
'Listadmins' => Title::makeTitle( NS_SPECIAL, 'Listusers/sysop' ), # @bug 2832
|
2005-12-11 10:39:51 +00:00
|
|
|
'Randompage' => Title::makeTitle( NS_SPECIAL, 'Random' )
|
2005-10-12 06:11:37 +00:00
|
|
|
);
|
|
|
|
|
wfRunHooks( 'SpecialPageGetRedirect', array( &$redirects ) );
|
|
|
|
|
|
|
|
|
|
return isset( $redirects[$name] ) ? $redirects[$name] : null;
|
2005-05-11 03:21:25 +00:00
|
|
|
}
|
2004-05-15 03:36:39 +00:00
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Return categorised listable special pages
|
|
|
|
|
* Returns a 2d array where the first index is the restriction name
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function getPages() {
|
2004-05-20 14:13:03 +00:00
|
|
|
global $wgSpecialPages;
|
|
|
|
|
$pages = array(
|
2005-12-11 10:39:51 +00:00
|
|
|
'' => array(),
|
|
|
|
|
'sysop' => array(),
|
|
|
|
|
'developer' => array()
|
2004-05-20 14:13:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ( $wgSpecialPages as $name => $page ) {
|
|
|
|
|
if ( $page->isListed() ) {
|
|
|
|
|
$pages[$page->getRestriction()][$page->getName()] =& $wgSpecialPages[$name];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $pages;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Execute a special page path.
|
|
|
|
|
* The path may contain parameters, e.g. Special:Name/Params
|
|
|
|
|
* Extracts the special page name and call the execute method, passing the parameters
|
|
|
|
|
*
|
2005-07-23 05:47:25 +00:00
|
|
|
* Returns a title object if the page is redirected, false if there was no such special
|
2005-05-28 11:09:22 +00:00
|
|
|
* page, and true if it was successful.
|
|
|
|
|
*
|
|
|
|
|
* @param $title a title object
|
|
|
|
|
* @param $including output is being captured for use in {{special:whatever}}
|
2004-09-19 19:37:26 +00:00
|
|
|
*/
|
2005-05-28 11:09:22 +00:00
|
|
|
function executePath( &$title, $including = false ) {
|
2006-03-07 01:10:39 +00:00
|
|
|
global $wgOut, $wgTitle;
|
2005-08-23 16:48:39 +00:00
|
|
|
$fname = 'SpecialPage::executePath';
|
|
|
|
|
wfProfileIn( $fname );
|
2004-05-15 03:36:39 +00:00
|
|
|
|
|
|
|
|
$bits = split( "/", $title->getDBkey(), 2 );
|
|
|
|
|
$name = $bits[0];
|
2005-05-06 05:48:57 +00:00
|
|
|
if( !isset( $bits[1] ) ) { // bug 2087
|
2004-05-15 03:36:39 +00:00
|
|
|
$par = NULL;
|
|
|
|
|
} else {
|
|
|
|
|
$par = $bits[1];
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 02:59:12 +00:00
|
|
|
$page = SpecialPage::getPage( $name );
|
2004-05-15 03:36:39 +00:00
|
|
|
if ( is_null( $page ) ) {
|
2005-05-28 11:49:40 +00:00
|
|
|
if ( $including ) {
|
2005-08-23 16:48:39 +00:00
|
|
|
wfProfileOut( $fname );
|
2005-05-28 11:49:40 +00:00
|
|
|
return false;
|
2005-05-11 03:21:25 +00:00
|
|
|
} else {
|
2005-08-15 02:59:12 +00:00
|
|
|
$redir = SpecialPage::getRedirect( $name );
|
2005-05-28 11:49:40 +00:00
|
|
|
if ( isset( $redir ) ) {
|
2005-07-23 05:47:25 +00:00
|
|
|
if ( isset( $par ) )
|
2005-05-28 11:49:40 +00:00
|
|
|
$wgOut->redirect( $redir->getFullURL() . '/' . $par );
|
|
|
|
|
else
|
|
|
|
|
$wgOut->redirect( $redir->getFullURL() );
|
|
|
|
|
$retVal = $redir;
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->setArticleRelated( false );
|
2005-10-12 03:12:40 +00:00
|
|
|
$wgOut->setRobotpolicy( 'noindex,follow' );
|
|
|
|
|
$wgOut->setStatusCode( 404 );
|
|
|
|
|
$wgOut->errorpage( 'nosuchspecialpage', 'nospecialpagetext' );
|
2005-05-28 11:49:40 +00:00
|
|
|
$retVal = false;
|
|
|
|
|
}
|
2005-05-11 03:21:25 +00:00
|
|
|
}
|
2004-05-15 03:36:39 +00:00
|
|
|
} else {
|
2005-05-28 11:09:22 +00:00
|
|
|
if ( $including && !$page->includable() ) {
|
2005-08-23 16:48:39 +00:00
|
|
|
wfProfileOut( $fname );
|
2005-05-28 11:09:22 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-05-15 03:36:39 +00:00
|
|
|
if($par !== NULL) {
|
|
|
|
|
$wgTitle = Title::makeTitle( NS_SPECIAL, $name );
|
|
|
|
|
} else {
|
|
|
|
|
$wgTitle = $title;
|
|
|
|
|
}
|
2005-05-28 11:09:22 +00:00
|
|
|
$page->including( $including );
|
2004-05-15 03:36:39 +00:00
|
|
|
|
2005-08-23 16:48:39 +00:00
|
|
|
$profName = 'Special:' . $page->getName();
|
|
|
|
|
wfProfileIn( $profName );
|
2004-05-15 03:36:39 +00:00
|
|
|
$page->execute( $par );
|
2005-08-23 16:48:39 +00:00
|
|
|
wfProfileOut( $profName );
|
2005-05-28 11:09:22 +00:00
|
|
|
$retVal = true;
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2005-08-23 16:48:39 +00:00
|
|
|
wfProfileOut( $fname );
|
2005-05-28 11:09:22 +00:00
|
|
|
return $retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Just like executePath() except it returns the HTML instead of outputting it
|
|
|
|
|
* Returns false if there was no such special page, or a title object if it was
|
|
|
|
|
* a redirect.
|
|
|
|
|
* @static
|
|
|
|
|
*/
|
|
|
|
|
function capturePath( &$title ) {
|
|
|
|
|
global $wgOut, $wgTitle;
|
|
|
|
|
|
|
|
|
|
$oldTitle = $wgTitle;
|
|
|
|
|
$oldOut = $wgOut;
|
|
|
|
|
$wgOut = new OutputPage;
|
2005-07-23 05:47:25 +00:00
|
|
|
|
2005-05-28 11:09:22 +00:00
|
|
|
$ret = SpecialPage::executePath( $title, true );
|
|
|
|
|
if ( $ret === true ) {
|
|
|
|
|
$ret = $wgOut->getHTML();
|
|
|
|
|
}
|
|
|
|
|
$wgTitle = $oldTitle;
|
|
|
|
|
$wgOut = $oldOut;
|
|
|
|
|
return $ret;
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Default constructor for special pages
|
|
|
|
|
* Derivative classes should call this from their constructor
|
|
|
|
|
* Note that if the user does not have the required level, an error message will
|
|
|
|
|
* be displayed by the default execute() method, without the global function ever
|
|
|
|
|
* being called.
|
|
|
|
|
*
|
|
|
|
|
* If you override execute(), you can recover the default behaviour with userCanExecute()
|
|
|
|
|
* and displayRestrictionError()
|
|
|
|
|
*
|
|
|
|
|
* @param string $name Name of the special page, as seen in links and URLs
|
|
|
|
|
* @param string $restriction Minimum user level required, e.g. "sysop" or "developer".
|
|
|
|
|
* @param boolean $listed Whether the page is listed in Special:Specialpages
|
|
|
|
|
* @param string $function Function called by execute(). By default it is constructed from $name
|
|
|
|
|
* @param string $file File which is included by execute(). It is also constructed from $name by default
|
|
|
|
|
*/
|
2005-05-28 11:09:22 +00:00
|
|
|
function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
$this->mName = $name;
|
|
|
|
|
$this->mRestriction = $restriction;
|
|
|
|
|
$this->mListed = $listed;
|
2005-05-28 11:09:22 +00:00
|
|
|
$this->mIncludable = $includable;
|
2004-05-15 03:36:39 +00:00
|
|
|
if ( $function == false ) {
|
2004-09-19 19:37:26 +00:00
|
|
|
$this->mFunction = 'wfSpecial'.$name;
|
2004-05-15 03:36:39 +00:00
|
|
|
} else {
|
|
|
|
|
$this->mFunction = $function;
|
|
|
|
|
}
|
2004-09-19 19:37:26 +00:00
|
|
|
if ( $file === 'default' ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
$this->mFile = "Special{$name}.php";
|
|
|
|
|
} else {
|
|
|
|
|
$this->mFile = $file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-12 03:36:07 +00:00
|
|
|
/**#@+
|
|
|
|
|
* Accessor
|
|
|
|
|
*
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function getName() { return $this->mName; }
|
|
|
|
|
function getRestriction() { return $this->mRestriction; }
|
2005-04-24 04:16:50 +00:00
|
|
|
function getFile() { return $this->mFile; }
|
2005-10-12 03:36:07 +00:00
|
|
|
function isListed() { return $this->mListed; }
|
|
|
|
|
/**#@-*/
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2005-10-12 03:36:07 +00:00
|
|
|
/**#@+
|
|
|
|
|
* Accessor and mutator
|
|
|
|
|
*/
|
|
|
|
|
function name( $x = NULL ) { return wfSetVar( $this->mName, $x ); }
|
|
|
|
|
function restrictions( $x = NULL) { return wfSetVar( $this->mRestrictions, $x ); }
|
|
|
|
|
function listed( $x = NULL) { return wfSetVar( $this->mListed, $x ); }
|
|
|
|
|
function func( $x = NULL) { return wfSetVar( $this->mFunction, $x ); }
|
|
|
|
|
function file( $x = NULL) { return wfSetVar( $this->mFile, $x ); }
|
2005-07-23 05:47:25 +00:00
|
|
|
function includable( $x = NULL ) { return wfSetVar( $this->mIncludable, $x ); }
|
2005-10-12 03:36:07 +00:00
|
|
|
function including( $x = NULL ) { return wfSetVar( $this->mIncluding, $x ); }
|
|
|
|
|
/**#@-*/
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Checks if the given user (identified by an object) can execute this
|
|
|
|
|
* special page (as defined by $mRestriction)
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function userCanExecute( &$user ) {
|
|
|
|
|
if ( $this->mRestriction == "" ) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
if ( in_array( $this->mRestriction, $user->getRights() ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-13 02:48:42 +00:00
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Output an error message telling the user what access level they have to have
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function displayRestrictionError() {
|
2004-05-21 00:57:17 +00:00
|
|
|
global $wgOut;
|
2005-06-19 06:25:53 +00:00
|
|
|
$wgOut->permissionRequired( $this->mRestriction );
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
2004-08-13 02:48:42 +00:00
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Sets headers - this should be called from the execute() method of all derived classes!
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function setHeaders() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
$wgOut->setArticleRelated( false );
|
|
|
|
|
$wgOut->setRobotPolicy( "noindex,follow" );
|
|
|
|
|
$wgOut->setPageTitle( $this->getDescription() );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Default execute method
|
|
|
|
|
* Checks user permissions, calls the function given in mFunction
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function execute( $par ) {
|
2006-03-07 01:10:39 +00:00
|
|
|
global $wgUser;
|
2004-05-15 03:36:39 +00:00
|
|
|
|
|
|
|
|
$this->setHeaders();
|
2004-08-13 02:48:42 +00:00
|
|
|
|
2004-05-15 03:36:39 +00:00
|
|
|
if ( $this->userCanExecute( $wgUser ) ) {
|
2005-08-31 20:19:01 +00:00
|
|
|
$func = $this->mFunction;
|
|
|
|
|
// only load file if the function does not exist
|
|
|
|
|
if(!function_exists($func) and $this->mFile) {
|
2004-05-15 03:36:39 +00:00
|
|
|
require_once( $this->mFile );
|
2004-08-13 02:48:42 +00:00
|
|
|
}
|
2005-12-11 03:03:34 +00:00
|
|
|
if ( wfRunHooks( 'SpecialPageExecuteBeforeHeader', array( &$this, &$par, &$func ) ) )
|
|
|
|
|
$this->outputHeader();
|
|
|
|
|
if ( ! wfRunHooks( 'SpecialPageExecuteBeforePage', array( &$this, &$par, &$func ) ) )
|
|
|
|
|
return;
|
2005-05-28 11:09:22 +00:00
|
|
|
$func( $par, $this );
|
2005-12-11 03:03:34 +00:00
|
|
|
if ( ! wfRunHooks( 'SpecialPageExecuteAfterPage', array( &$this, &$par, &$func ) ) )
|
|
|
|
|
return;
|
2004-05-15 03:36:39 +00:00
|
|
|
} else {
|
|
|
|
|
$this->displayRestrictionError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-10 05:40:25 +00:00
|
|
|
function outputHeader() {
|
|
|
|
|
global $wgOut, $wgContLang;
|
|
|
|
|
|
|
|
|
|
$msg = $wgContLang->lc( $this->name() ) . '-summary';
|
|
|
|
|
$out = wfMsg( $msg );
|
|
|
|
|
if ( ! wfEmptyMsg( $msg, $out ) and $out !== '' and ! $this->including() )
|
|
|
|
|
$wgOut->addWikiText( $out );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-13 02:48:42 +00:00
|
|
|
# Returns the name that goes in the <h1> in the special page itself, and also the name that
|
2004-08-12 14:55:35 +00:00
|
|
|
# will be listed in Special:Specialpages
|
|
|
|
|
#
|
2004-08-13 02:48:42 +00:00
|
|
|
# Derived classes can override this, but usually it is easier to keep the default behaviour.
|
2004-08-12 14:55:35 +00:00
|
|
|
# Messages can be added at run-time, see MessageCache.php
|
2004-05-15 03:36:39 +00:00
|
|
|
function getDescription() {
|
|
|
|
|
return wfMsg( strtolower( $this->mName ) );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get a self-referential title object
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function getTitle() {
|
|
|
|
|
return Title::makeTitle( NS_SPECIAL, $this->mName );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 19:37:26 +00:00
|
|
|
/**
|
|
|
|
|
* Set whether this page is listed in Special:Specialpages, at run-time
|
|
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
function setListed( $listed ) {
|
|
|
|
|
return wfSetVar( $this->mListed, $listed );
|
|
|
|
|
}
|
2005-05-28 11:09:22 +00:00
|
|
|
|
2004-05-15 03:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Shortcut to construct a special page which is unlisted by default
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-05-15 03:36:39 +00:00
|
|
|
class UnlistedSpecialPage extends SpecialPage
|
|
|
|
|
{
|
2004-09-19 19:37:26 +00:00
|
|
|
function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) {
|
2004-05-15 03:36:39 +00:00
|
|
|
SpecialPage::SpecialPage( $name, $restriction, false, $function, $file );
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-05-28 11:09:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Shortcut to construct an includable special page
|
2005-07-05 21:22:25 +00:00
|
|
|
* @package MediaWiki
|
2005-05-28 11:09:22 +00:00
|
|
|
*/
|
|
|
|
|
class IncludableSpecialPage extends SpecialPage
|
|
|
|
|
{
|
|
|
|
|
function IncludableSpecialPage( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
|
|
|
|
|
SpecialPage::SpecialPage( $name, $restriction, $listed, $function, $file, true );
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-04-24 04:16:50 +00:00
|
|
|
?>
|