Manual talk:Special pages

From MediaWiki.org

Jump to: navigation, search
The following discussion has been transferred from meta.wikimedia.org.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).


Contents

[edit] Outdated?

I think this page has to be updated? It seems that you only need a file in the extension directory to create special page now.

An example is the Board Vote file

I have accordingly updated the word of warning section. I think the old material is for 1.4, so it's still relevant, so I'm going to try to rewrite the whole thing for 1.5. Ambush Commander 00:09, 22 December 2005 (UTC)
As of 1.6.x, my PageCreateOrder extension broke and I spent some time trying to figure out why until I looked at the BoardVote extension you mentioned. I now see that the class I was defining needs to be done inside the loader function and the includes file no longer needs to be there. I've updated the documentation to reflect this. -- Suso 13:44, 5 May 2006 (UTC)
Hey, Suso, are you User:216.9.137.122? (because that's the only edit I see) Ambush Commander 21:30, 5 May 2006 (UTC)
Yes I am. Sorry, I must have logged out or something when I made the edit. It happens. -- Suso 22:29, 30 May 2006 (UTC)

[edit] create a new special page

Hello, I would like to insert forms in pages related to my wiki, which is necessary to modify in the quick template to have a special page?

a: I didn't have to change anything in the template. Try using BoardVote.php as a model for your page, put it in the extensions directory. You can put your forms in the 'execute' function as this is what gets called automatically when the special page is loaded. To get mediawiki to recognize the existence of your new page, just include it at the end of LocalSettings.php.

You probably want to read into Extending wiki markup, which lets you add arbitrary HTML to a page and is great for creating really quick extensions for creating forms. Ambush Commander 00:09, 22 December 2005 (UTC)

[edit] clear title < >

I can't remove the < > witch appears on both sides of the page title. First, I added a line in the $wgValidSpecialPagesFr array and then in all arrays of my language file. I read the explanation with the addMessage() function but y didn't very understand because of my bad english. Barbux 22:10, 1 October 2005 (UTC)

Put $wgMessageCache->addMessages(array('page' => 'My Page Name')); into the start of your wfExampleExtension() after the globals declaration.
Failing that, create this page: MediaWiki:Yourpagename and put the name of your page there. Ambush Commander 00:09, 22 December 2005 (UTC)

[edit] sysops only?

ImaTard 20:06, 31 October 2005 (UTC)

How would i go about making a sysops only special page? im using v1.5

a:I thought it might help to show what I have in my code at the beginning of my execute function:

               if (! $wgUser->isBureaucrat() && ! $wgUser->isDeveloper() ){
                       $wgOut->errorpage( "bureaucrattitle", "bureaucrattext" );
                       return;
               }

This code only allows admins to use the page. Note that i have only tested this on v1.4.6 though.

This is a good idea for a section on the page, but it's fairly obvious if you just look at some of the code. Those functions are deprecated, you can use: $this->isAllowed( 'protect' );. Ambush Commander 00:12, 22 December 2005 (UTC)
Extra note: the code given earlier does not make the page sysops only. Ambush Commander 00:13, 22 December 2005 (UTC)

I'm using 1.8, and i'm having problems as well...Here's what i have in my function:

SpecialPage::addPage(new SpecialPage('ArchiveNews', 'sysop', true, 'ArchiveNews', false));

I thought that passing "sysop" as the second parameter would only allow sysops to see the page. But, when i do that and go to the page, I get:

Permission error
You are not allowed to execute the action you have requested.

I am a sysop, so i can't figure out why it wouldn't work...is this by chance deprecated? I've tried everything...sysop, admin, administrator, etc, and nothing works. The only thing that made any difference, was when i set it to "bot" just for fun, and I got a different message, stating that I was not in the group "bots". Any help would be appreciated. --Duke33 22:31, 20 December 2006 (UTC)

The second parameter of SpecialPage's constructor is the right needed to view the page, not the group. Since (by default at least) a bureaucrat's only right is userrights, pass "userrights" as the second parameter to limit the page to bureaucrats. To limit the page to sysops, consider why -- because sysops can delete pages? Or upload files? A full list of default user group/rights settings is in DefaultSettings.php. 23:18, 22 May 2007 (UTC)

[edit] Modification needed for 1.6

I just made a special page using the example found on this page. But, apparently on 1.6 you need to add this to the execute(); function.

 $wgOut->setPagetitle( wfMsg( 'messagename' ) );

--Phroziac (talk) 20:34, 8 November 2005 (UTC)

This is not necessary. Read about how MediaWiki can be used to dynamically load extensions and their functions. Ambush Commander 00:09, 22 December 2005 (UTC)

[edit] Revert to previous version

In this edit User:Slanted reverted the new set of instructions to a pre-1.5 state. The edit was marked minor and had no edit summary, so I chose to revert him before posting an inquiry on his talk page. So... discussion? Ambush Commander 02:52, 5 January 2006 (UTC)

[edit] Add setHeaders() to example?

The code in SpecialPage.php says you should call setHeaders() in your execute function. This turns out to be necessary to set the window title and other stuff (Thanks to Michael on Wikitech-l for pointing this out). Shouldn't we add something like the following to the example on this page?

$this->setHeaders(); // call this method of the super class to set the window title

--Jmcneil86043 19:09, 7 January 2006 (UTC)

SpecialPage automatically calls the function from its base method. Notice how in the code examples, I do not inherit a new class from SpecialPage. Calling this is only necessary if you overload execute() and you don't call the original. Generally, inherited classes are overkill: UnlistedSpecialPage and IncludableSpecialPage should have all the alternate functionality you need, and there probably should not be any domain logic inside the SpecialPage class (perhaps somewhat counterintuitively).
However, if you followed the instructions correctly, it should have worked. Where did you get your special page template anyway? Ambush Commander 00:01, 8 January 2006 (UTC)

I based my code on BoardVote.php, which was recommended in the old code as an example (I started this code a few months ago when that doc was current). It was over-complicated for my purposes, but I am implementing a form, so it was helpful. These new docs are more simple, but It's not completely obvious how to do a form, although I guess I could figure it out with a little work. Do you recommend calling the base-class' execute method, or re-writing so I don't sub-class? I'm going to be doing several more of these, so I'd like to do this prototype correctly. Thanks, --Jmcneil86043 03:58, 8 January 2006 (UTC)

The developers likely aren't in agreement about everything. After all, I am just an outside. My observations are based off the upload special page, which Vibber does say is a, and I paraphrase, piece of crap. I'll do some more research on the other standard special pages. I think that this simply way is a lot better though.
Regarding your question about rewriting versus calling the base class's execute method, you can't call the base class's execute method because it will go off and call the function anyway (even if it doesn't exist). You will have to rewrite it, or give it a dud function. Not that you'd want to: just put all the logic inside the function that it calls. Do you understand that idea?
Regarding the creation of forms, I do need to add some documentation about WebRequest. I'm concerned, however, that the page is getting a bit long. Ambush Commander 00:36, 9 January 2006 (UTC)

[edit] Passing Parameters to a Special Page?

Is there any way to pass parameters to a special page? The preceding unsigned comment was added by Behrang Amini (talk • contribs) .

Yes, see "Special Parameters" on article page
84.137.220.251 14:12, 2 March 2006 (UTC)


How about calling SpecialPage::executePath in the php code. How can I pass parameters to the page? Nazly.elshazly 09:35, 17 January 2007 (UTC)

[edit] Special:Example

Special:Example is dead. The preceding unsigned comment was added by 80.185.25.241 (talk • contribs) .

Of course. There's no special page by the name of Example on this wiki. Ambush Commander 21:46, 18 January 2006 (UTC)

[edit] Special Characters in $wgMessageCache->addMessages

Hi, how is it possible to put german umlauts in $wgMessageCache->addMessages? (&ouml; or &#246; don't work)
84.137.220.251 14:10, 2 March 2006 (UTC)

I suppose MediaWiki expects pure text. I recommend using $string = 'needsumlat' . chr(246) . 'textafterumlat';. Remember, you can always edit the corresponding system message if you don't want to put special characters in the source code. Ambush Commander 22:38, 3 March 2006 (UTC)
> Remember, you can always edit the corresponding system message if you don't want to put special characters in the source code.
That's a splendid Idea. I'm going to do it like that, thanks!
By the way, I tried "chr(246)" and it didn'd work either (allways get a question mark instead of the special character).
Otterstedt 21:22, 4 March 2006 (UTC)
Hmm... that's interesting. Probably 246 is the incorrect number (it's in decimal, not hex, and remember, it has to be UTF-8 encoded). I'll have to look into that (or a developer, in their infinite wisdom, will give us the answer). Glad you resolved your problem though. Ambush Commander 23:20, 4 March 2006 (UTC)
I'm getting a little bit annoyed with not finding information on how to actually achieve this. I'm writing an extension with finnish texts. Nothing so far has been displayed correctly. Including the above tip. And the tip about being able to edit the messages Special:Allmessages page doesn't work either for some reason. In my extensions/SpecialDigitemp.php I have this
$wgMessageCache->addMessages(array('digitemp' => 'Lämpötila'));
The message name and the message itself are present in the Special:Allmessages page, but when trying to edit the message I get a page saying that the page doesn't exist. The link on the Special:Allmessages page for the word digitemp is
http://xxx/wiki/index.php?title=MediaWiki:Digitemp&action=edit when for other texts it's
http://xxx/wiki/index.php/MediaWiki:Diff
So what's the deal? And how to get ä's and ö's to work? The preceding unsigned comment was added by 193.167.88.25 (talk • contribs) .
You need to use the &#nn; (HTML Unicode format) encoding when hard coding messages. Nn is equivalent to the decimal number representing the character. For example:
wgOut->HTML('LŠmpštila');
When using messageCache you could use php's utf8_encode() function to convert your strings to UTF-8 like in the following:
$wgMessageCache->addMessages(array('digitemp' => utf8_encode('Lämpötila')));
Hope this helps. The preceding unsigned comment was added by 213.186.252.201 (talk • contribs) .

The system messages aren't supposed to exist. Here's the thing: as an aide to you, the MediaWiki installer automatically populates the core set of system messages. Most extensions don't do so. Just create the page and it will work as normal. I strongly discourage non-ASCII characters in source code, just because of encoding issues (if you're using the wrong encoding, they'll show up weird in the source (unlikely, since Latin-1 is the most widely used character set (but still possible, esp. for non-European languages))). Ambush Commander 23:09, 31 March 2006 (UTC)

[edit] Modifying permissions for existing special pages

An anon posted this. I don't agree with it's methodology, but the main reason it's not appropriate for this article is that it has nothing to do with new special pages. Just old ones. Anyone know of a more appropriate place to put it? Ambush Commander 04:18, 30 March 2006 (UTC)

This was my post. I postet it because I was looking for that kind of solution for preventing access for some hours in the documentation in here before I used my own brain ;-) But you are totally right, it is not about writing a new page. So I fitted it now in there, where I would have expected it at first and where it is fully logical: at Preventing_Access.

Great job. (removed text) :-D Ambush Commander 21:31, 30 March 2006 (UTC)

[edit] Defining functions/classes from a function

I don't think that defining classes/functions from inside a function is conceptually the cleanest way to go about doing things. In fact, the developers tend to disagree about where the extension code should go.

From this page: [1], here's an overview of what developers are doing:

  • Cite by avar - inlined inside function, extends special page class
  • Makebot by robchurch - non-conditional definition, extends special page class
  • NewestPages by robchurch - non-conditional definition, extends special page class
  • SpecialMakesysop by timstarling et al - non-conditional definition, uses generic special page class but tells special page not to load file
  • SpecialRenameuser by avar - inlined inside function, extends special page class
  • SpecialCrossNamespaceLinks by avar - inlined inside function, extends special page class
  • BoardVote by vibber - inlined inside function, extends special page class
  • SpecialFileList by Magnus Manske - inlined inside function, extends special page class
  • PurgeCache by robchurch - unconditional definition, extends special page class
  • SpecialFilePath by avar - inlined inside function, extends special page class
  • LuceneSearch by vibber - inlined inside function, extends special page class
  • OAI repository by vibber - inlined inside function, extends special page class
  • SiteMatrix by vibber - inlined inside function, extends special page class

Ambush Commander 22:23, 5 May 2006 (UTC)

Egads! It seems I was barking up the wrong tree to begin with! Ambush Commander 04:27, 7 May 2006 (UTC)

[edit] BoardVote example -- where is it?

The article says:

If this is unclear, you might check out the BoardVote.php file in the extentions/BoardVote directory, as it does things the right way.

Great, but BoardVote.php is not in my extentions/BoardVote directory. If this is supposed to be the canonical example, how about publishing it where folks can see it -- like the extensions category here? JohanTheGhost 15:05, 20 May 2006 (UTC)

I used to not endorse that statement, but it prompted me to check out a bunch of the other extensions by leading developers, and it turns out that inlining the class definition in the function is the commonly accepted way. Please see the above topic, Defining functions/classes from a function.
You can view the HEAD version of the BoardVote extension in the SVN repository. Personally, I wouldn't use it as a template since it's a bit too complicatd. — Ambush Commander(Talk) 17:27, 20 May 2006 (UTC)


[edit] Question...

Ok can some one explain to me why when I follow the instructions on this page I end up with a blank Special Pages page?

I'm using Fedora Core 5
MediaWiki: 1.9.3
PHP: 5.1.6 (apache2handler)
MySQL: 5.0.27

April 17 2007

add the following line in MyExtension_body.php
        # Do stuff
        $output = 'Hello World!';

Vic 21:51, 23 April 2007 (UTC)

Vic add this to MyExtension_body.php right after your <?PHP line:
error_reporting(1);
This should give you the error instead of a blank page 00:52, 25 April 2007 (UTC)


[edit] Special Page with MW Version 1.6.9

Hi, I've written a special page with the proposed template and it works really fine with 1.9.3. But under V 1.6.9 I can't call that page (It is listed under Special:Version, but not at Special pages and if I call it directl it doesn't exist) :-( I googled a little bit and found that this problem exists. Do you know how to solve it?

Thanx Chris

End of content from meta.wikimedia.org.
Note that the above conversation may have been edited or added to since the transfer. If in doubt, check the edit history.


[edit] Other Important Files?

I really didn't get where I'm supposed to stick this stuff. Lets say I want to make it so that my special page does not appear in Special:Specialpages, what function exactly am I supposed to modify in the above code? Can anyone clarify please? --Nate 89.0.127.224 23:58, 1 October 2007 (UTC)


[edit] Making a Special Page Printable


How do I go about this? I have a special page that I created that needs to be printable. If I pass in a variable to tell the Page it should be printable is there a function that should be called in the code for that page to let the parser know to make it printable instead of using the standard display?

Thanks Will

I believe that just by printing the page, the browser will automatically figure out (using the @media print { ... } calls in the CSS) the correct way to display it for printing. 68.80.149.10 16:36, 31 October 2007 (UTC)

[edit] Cache Question

Regarding caching, I was wondering how to go about doing an object cache. I assume MediaWiki abstracts the underlying cache systems (memcahed, APC, DB cache, etc), and was just wondering what class I would need to call to do some basic object caching. I can figure it out from there with the help of the code documentation, just need to be pointed at the right class ;)

Thanks, 68.80.149.10 16:34, 31 October 2007 (UTC)

[edit] Special:Statistics

My Special:Statistics page has a huge number (18,446,744,073,709,551,614) listed in "Excluding those, there are $2 pages that are probably legitimate content pages.". Any idea why this is? --Egingell 03:05, 8 January 2008 (UTC)

[edit] Problem with SpecialPage hooks

As per https://bugzilla.wikimedia.org/show_bug.cgi?id=10719, extensions that subclass SpecialPage and implement their own execute() function have a couple of drawbacks. The main one being they don't fire off all the SpecialPage hooks that SpecialPage::execute() fires. Also, the subclass execute() function has to call setHeaders() and do it's own user permission checking. I added some information on all this and suggested a work around here: Manual:Special pages#The Body File. --Cneubauer 22:36, 11 February 2008 (UTC)

[edit] php4

This manual includes a note saying: It should be pointed out that the method used below will not work on PHP 4:. Where can I find the description on how to write a Special page-extension with Mediawiki 1.6 and PHP 4? -- JanCK 11:43, 11 April 2008 (UTC)

Try an old revision of the page. [2] should probably work. --Cneubauer 12:12, 11 April 2008 (UTC)
Personal tools