X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres/fiche.php?a=blobdiff_plain;ds=sidebyside;f=includes%2FSpecialPage.php;h=7c2cb870319dadd4d5808ca9705a8f8c1bbebb41;hb=f98c133919920e5fa2ce48efc64a6d4930521e3a;hp=4dcb7e9b178c830be731629fc3b24c32c78864dd;hpb=67bcaab800b5ec0d36b88c0f29023a0ab82d3c96;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 4dcb7e9b17..7c2cb87031 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -1,73 +1,166 @@ new UnlistedSpecialPage( "Userlogin" ), - "Userlogout" => new UnlistedSpecialPage( "Userlogout" ), - "Preferences" => new SpecialPage( "Preferences" ), - "Watchlist" => new SpecialPage( "Watchlist" ), - "Recentchanges" => new SpecialPage( "Recentchanges" ), - "Upload" => new SpecialPage( "Upload" ), - "Imagelist" => new SpecialPage( "Imagelist" ), - "Listusers" => new SpecialPage( "Listusers" ), - "Listadmins" => new SpecialPage( "Listadmins" ), - "Statistics" => new SpecialPage( "Statistics" ), - "Randompage" => new SpecialPage( "Randompage" ), - "Lonelypages" => new SpecialPage( "Lonelypages" ), - "Unusedimages" => new SpecialPage( "Unusedimages" ) + 'DoubleRedirects' => new SpecialPage ( 'DoubleRedirects' ), + 'BrokenRedirects' => new SpecialPage ( 'BrokenRedirects' ), + 'Disambiguations' => new SpecialPage ( 'Disambiguations' ), + + 'Userlogin' => new SpecialPage( 'Userlogin' ), + 'Userlogout' => new UnlistedSpecialPage( 'Userlogout' ), + 'Preferences' => new SpecialPage( 'Preferences' ), + 'Watchlist' => new SpecialPage( 'Watchlist' ), + + 'Mytalk' => new UnlistedSpecialPage( 'Mytalk'), + 'Mycontributions' => new UnlistedSpecialPage( 'Mycontributions'), + 'Mypage' => new UnlistedSpecialPage( 'Mypage'), + + 'Recentchanges' => new SpecialPage( 'Recentchanges' ), + 'Upload' => new SpecialPage( 'Upload' ), + 'Imagelist' => new SpecialPage( 'Imagelist' ), + 'Newimages' => new SpecialPage( 'Newimages' ), + 'Listusers' => new SpecialPage( 'Listusers' ), + 'Listadmins' => new UnlistedSpecialPage( 'Listadmins' ), + 'Statistics' => new SpecialPage( 'Statistics' ), + 'Randompage' => new SpecialPage( 'Randompage' ), + 'Lonelypages' => new SpecialPage( 'Lonelypages' ), + 'Uncategorizedpages'=> new SpecialPage( 'Uncategorizedpages' ), + 'Uncategorizedcategories'=> new SpecialPage( 'Uncategorizedcategories' ), + 'Unusedimages' => new SpecialPage( 'Unusedimages' ), + 'Wantedpages' => new SpecialPage( 'Wantedpages' ), + 'Shortpages' => new SpecialPage( 'Shortpages' ), + 'Longpages' => new SpecialPage( 'Longpages' ), + 'Newpages' => new SpecialPage( 'Newpages' ), + 'Ancientpages' => new SpecialPage( 'Ancientpages' ), + 'Deadendpages' => new SpecialPage( 'Deadendpages' ), + 'Allpages' => new SpecialPage( 'Allpages' ), + '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' ), + 'Blockip' => new SpecialPage( 'Blockip', 'block' ), + 'Undelete' => new SpecialPage( 'Undelete', 'delete' ), + "Import" => new SpecialPage( "Import", 'import' ), + 'Lockdb' => new SpecialPage( 'Lockdb', 'siteadmin' ), + 'Unlockdb' => new SpecialPage( 'Unlockdb', 'siteadmin' ), +# 'Sitesettings' => new SpecialPage( 'Sitesettings', 'siteadmin' ), + 'Userrights' => new SpecialPage( 'Userrights', 'userrights' ), + 'Groups' => new SpecialPage( 'Groups' ), ); + +global $wgUseValidation ; +if ( $wgUseValidation ) + $wgSpecialPages['Validate'] = new SpecialPage( 'Validate' ); + global $wgDisableCounters; -if( !$wgDisableCounters ) -{ - $wgSpecialPages["Popularpages"] = new SpecialPage( "Popularpages" ); +if( !$wgDisableCounters ) { + $wgSpecialPages['Popularpages'] = new SpecialPage( 'Popularpages' ); } -$wgSpecialPages = array_merge($wgSpecialPages, array ( - "Wantedpages" => new SpecialPage( "Wantedpages" ), - "Shortpages" => new SpecialPage( "Shortpages" ), - "Longpages" => new SpecialPage( "Longpages" ), - "Newpages" => new SpecialPage( "Newpages" ), - "Ancientpages" => new SpecialPage( "Ancientpages" ), - "Deadendpages" => new SpecialPage( "Deadendpages" ), - "Allpages" => new SpecialPage( "Allpages" ), - "Ipblocklist" => new SpecialPage( "Ipblocklist" ), - "Maintenance" => new SpecialPage( "Maintenance" ), - "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" ), - "Geo" => new SpecialPage( "Geo" ), - "Booksources" => new SpecialPage( "Booksources" ), - "Categories" => new SpecialPage( "Categories" ), - "Export" => new SpecialPage( "Export" ), - "Version" => new SpecialPage( "Version" ), - "Allmessages" => new SpecialPage( "Allmessages" ), - "Search" => new UnlistedSpecialPage( "Search" ), - "Blockip" => new SpecialPage( "Blockip", "sysop" ), - "Asksql" => new SpecialPage( "Asksql", "sysop" ), - "Undelete" => new SpecialPage( "Undelete", "sysop" ), - "Makesysop" => new SpecialPage( "Makesysop", "sysop" ), - "Import" => new SpecialPage( "Import", "sysop" ), - "Lockdb" => new SpecialPage( "Lockdb", "developer" ), - "Unlockdb" => new SpecialPage( "Unlockdb", "developer" ) -)); +global $wgDisableInternalSearch; +if( !$wgDisableInternalSearch ) { + $wgSpecialPages['Search'] = new UnlistedSpecialPage( 'Search' ); +} + +global $wgEmailAuthentication; +if( $wgEmailAuthentication ) { + $wgSpecialPages['Confirmemail'] = new UnlistedSpecialPage( 'Confirmemail' ); +} + +/** + * Parent special page class, also static functions for handling the special + * page list + * @package MediaWiki + */ class SpecialPage { - /* private */ var $mName, $mRestriction, $mListed, $mFunction, $mFile; - - /* static */ function addPage( &$obj ) { + /**#@+ + * @access private + */ + /** + * The name of the class, used in the URL. + * Also used for the default

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; + /**#@-*/ + + /** + * 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 ) { global $wgSpecialPages; $wgSpecialPages[$obj->mName] = $obj; } - /* static */ function removePage( $name ) { + /** + * Remove a special page from the list + * Occasionally used to disable expensive or dangerous special pages + * @static + */ + function removePage( $name ) { global $wgSpecialPages; unset( $wgSpecialPages[$name] ); } - /* static */ function &getPage( $name ) { + /** + * Find the object with a given name and return it (or NULL) + * @static + * @param string $name + */ + function &getPage( $name ) { global $wgSpecialPages; if ( array_key_exists( $name, $wgSpecialPages ) ) { return $wgSpecialPages[$name]; @@ -76,13 +169,17 @@ class SpecialPage } } - # Return categorised listable special pages - /* static */ function getPages() { + /** + * Return categorised listable special pages + * Returns a 2d array where the first index is the restriction name + * @static + */ + function getPages() { global $wgSpecialPages; $pages = array( - "" => array(), - "sysop" => array(), - "developer" => array() + '' => array(), + 'sysop' => array(), + 'developer' => array() ); foreach ( $wgSpecialPages as $name => $page ) { @@ -93,8 +190,14 @@ class SpecialPage return $pages; } - # Execute a special page path, which may contain slashes - /* static */ function executePath( &$title ) { + /** + * 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 + * + * @param $title should be a title object + */ + function executePath( &$title ) { global $wgSpecialPages, $wgOut, $wgTitle; $bits = split( "/", $title->getDBkey(), 2 ); @@ -121,26 +224,48 @@ class SpecialPage } } - function SpecialPage( $name = "", $restriction = "", $listed = true, $function = false, $file = "default" ) { + /** + * 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 + */ + function SpecialPage( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default' ) { $this->mName = $name; $this->mRestriction = $restriction; $this->mListed = $listed; if ( $function == false ) { - $this->mFunction = "wfSpecial{$name}"; + $this->mFunction = 'wfSpecial'.$name; } else { $this->mFunction = $function; } - if ( $file === "default" ) { + if ( $file === 'default' ) { $this->mFile = "Special{$name}.php"; } else { $this->mFile = $file; } } + # Accessor functions, see the descriptions of the associated variables above function getName() { return $this->mName; } function getRestriction() { return $this->mRestriction; } function isListed() { return $this->mListed; } + function getFile() { return $this->mFile; } + /** + * Checks if the given user (identified by an object) can execute this + * special page (as defined by $mRestriction) + */ function userCanExecute( &$user ) { if ( $this->mRestriction == "" ) { return true; @@ -153,6 +278,9 @@ class SpecialPage } } + /** + * Output an error message telling the user what access level they have to have + */ function displayRestrictionError() { global $wgOut; if ( $this->mRestriction == "developer" ) { @@ -161,7 +289,10 @@ class SpecialPage $wgOut->sysopRequired(); } } - + + /** + * Sets headers - this should be called from the execute() method of all derived classes! + */ function setHeaders() { global $wgOut; $wgOut->setArticleRelated( false ); @@ -169,15 +300,19 @@ class SpecialPage $wgOut->setPageTitle( $this->getDescription() ); } + /** + * Default execute method + * Checks user permissions, calls the function given in mFunction + */ function execute( $par ) { global $wgUser, $wgOut, $wgTitle; $this->setHeaders(); - + if ( $this->userCanExecute( $wgUser ) ) { if ( $this->mFile ) { require_once( $this->mFile ); - } + } $func = $this->mFunction; $func( $par ); } else { @@ -185,22 +320,38 @@ class SpecialPage } } + # Returns the name that goes in the

in the special page itself, and also the name that + # will be listed in Special:Specialpages + # + # Derived classes can override this, but usually it is easier to keep the default behaviour. + # Messages can be added at run-time, see MessageCache.php function getDescription() { return wfMsg( strtolower( $this->mName ) ); } + /** + * Get a self-referential title object + */ function getTitle() { return Title::makeTitle( NS_SPECIAL, $this->mName ); } + /** + * Set whether this page is listed in Special:Specialpages, at run-time + */ function setListed( $listed ) { return wfSetVar( $this->mListed, $listed ); } } +/** + * Shortcut to construct a special page which is unlisted by default + * @package MediaWiki + */ class UnlistedSpecialPage extends SpecialPage { - function UnlistedSpecialPage( $name, $restriction = "", $function = false, $file = "default" ) { + function UnlistedSpecialPage( $name, $restriction = '', $function = false, $file = 'default' ) { SpecialPage::SpecialPage( $name, $restriction, false, $function, $file ); } } +?>