r43033 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43032‎ | r43033 | r43034 >
Date:21:46, 1 November 2008
Author:siebrand
Status:old
Tags:
Comment:
Update for uniwiki/CreatePage:
* standard special page addition
* split off special page body into a class file
* standard i18n for UI messages
* add i18n for special page aliases
* complete extension credits
* update indentation, remove trailing whitespace, stylize.php
Modified paths:
  • /trunk/extensions/uniwiki/CreatePage/CreatePage.alias.php (added) (history)
  • /trunk/extensions/uniwiki/CreatePage/CreatePage.i18n.php (modified) (history)
  • /trunk/extensions/uniwiki/CreatePage/CreatePage.php (modified) (history)
  • /trunk/extensions/uniwiki/CreatePage/CreatePage_body.php (added) (history)

Diff [purge]

Index: trunk/extensions/uniwiki/CreatePage/CreatePage_body.php
@@ -0,0 +1,77 @@
 2+<?php
 3+class SpecialCreatePage extends SpecialPage {
 4+
 5+ function __construct() {
 6+ SpecialPage::SpecialPage( 'CreatePage' );
 7+ }
 8+
 9+ public function execute( $params ) {
 10+ global $wgOut, $wgRequest, $wgUser;
 11+
 12+ wfLoadExtensionMessages( 'CreatePage' );
 13+
 14+ $skin = $wgUser->getSkin();
 15+
 16+ $thisPage = Title::newFromText ( "CreatePage", NS_SPECIAL );
 17+
 18+ $target = $wgRequest->getVal ( "target", null );
 19+
 20+ // check to see if we are trying to create a page
 21+ if ( $target != null ) {
 22+ $title = Title::newFromText ( $target );
 23+
 24+ if ( $title->getArticleID() > 0 ) {
 25+
 26+ // if the title exists then let the user know and give other options
 27+ $wgOut->addWikiText ( wfMsg ( "createpage_titleexists", $title->getFullText() ) . "<br />" );
 28+ $wgOut->addHTML ( "<a href='" . $title->getEditURL() . "'>" . wfMsg ( "createpage_editexisting" ) . "</a><br />"
 29+ . $skin->makeLinkObj ( $thisPage, wfMsg ( "createpage_tryagain" ) )
 30+ );
 31+ } else {
 32+ /* TODO - may want to search for closely named pages and give
 33+ * other options here... */
 34+
 35+ // otherwise, redirect them to the edit page for their title
 36+ $wgOut->redirect ( $title->getEditURL() );
 37+ }
 38+
 39+ return;
 40+ }
 41+
 42+ // if this is just a normal GET, then output the form
 43+
 44+ // prefill the input with the title, if it was passed along
 45+ $newTitle = $wgRequest->getVal( "newtitle", null );
 46+ if ( $newTitle != null ) $newTitle = str_replace( "_", " ", $newTitle );
 47+
 48+ // add some instructions
 49+ $wgOut->addHTML( wfMsg( 'createpage_instructions' ) );
 50+
 51+ // js for checking the form
 52+ $wgOut->addHTML( "
 53+ <script type='text/javascript' >
 54+ function checkForm(){
 55+ // check the title
 56+ if (document.createpageform.target && document.createpageform.target.value == \"\") {
 57+ alert('" . wfMsg( 'createpage_entertitle' ) . "');
 58+ document.createpageform.target.focus();
 59+ return false;
 60+ }
 61+ // everything is OK, return true
 62+ return true;
 63+ }
 64+ </script>
 65+ " );
 66+
 67+ // output the form
 68+ $wgOut->addHTML( "
 69+ <form method=POST onsubmit='return checkForm()' name='createpageform'>
 70+ <input type=text name=target size=50 value='$newTitle'><br /><br />
 71+ " );
 72+
 73+ $wgOut->addHTML( "
 74+ <input type=submit value='" . wfMsg( 'createpage_submitbutton' ) . "'>
 75+ </form>
 76+ " );
 77+ }
 78+}
Property changes on: trunk/extensions/uniwiki/CreatePage/CreatePage_body.php
___________________________________________________________________
Added: svn:mergeinfo
Added: svn:eol-style
179 + native
Index: trunk/extensions/uniwiki/CreatePage/CreatePage.i18n.php
@@ -1,49 +1,52 @@
22 <?php
3 -/* vim: noet ts=4 sw=4
4 - * http://www.mediawiki.org/wiki/Extension:Uniwiki_Generic_Edit_Page
5 - * http://www.gnu.org/licenses/gpl-3.0.txt */
 3+/**
 4+ * Internationalisation for Uniwiki/CreatePage extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
69
7 -if (!defined("MEDIAWIKI"))
8 - die();
 10+$messages = array();
911
10 -
11 -$wgCreatePageMessages = array();
12 -$wgCreatePageMessages['en'] = array(
13 - 'createpage' => "Create a page",
14 - 'createpage_submitbutton' => "Submit",
15 - 'createpage_instructions' => "Enter the title of the page you wish to create:",
16 - 'createpage_entertitle' => "Please enter a title for your page.",
17 - 'createpage_titleexists' => "A page with this title, [[$1]], already exists. Would you like to edit the existing page?",
18 - 'createpage_tryagain' => "No - I want to create a new page with a distinct title.",
19 - 'createpage_editexisting' => "Yes - I want to contribute to the existing page."
 12+/** English */
 13+$messages['en'] = array(
 14+ 'createpage' => 'Create a page',
 15+ 'createpage-desc' => 'Adds a [[Special:CreatePage|special page]] for creating new pages',
 16+ 'createpage_submitbutton' => 'Submit',
 17+ 'createpage_instructions' => 'Enter the title of the page you wish to create:',
 18+ 'createpage_entertitle' => 'Please enter a title for your page.',
 19+ 'createpage_titleexists' => 'A page with the title [[$1]] already exists.
 20+Would you like to edit the existing page?',
 21+ 'createpage_tryagain' => 'No. I want to create a new page with a distinct title.',
 22+ 'createpage_editexisting' => 'Yes. I want to contribute to the existing page.',
2023 );
2124
22 -$wgCreatePageMessages['es'] = array(
23 - 'createpage' => "Crear una página",
24 - 'createpage_submitbutton' => "Enviar",
25 - 'createpage_instructions' => "Ingresa el título de la página que deseas crear:",
26 - 'createpage_entertitle' => "Ingresa un título para tu página.",
27 - 'createpage_titleexists' => "Ya existe una página con el título [[$1]]. ¿Quieres editar la página que ya existe?",
28 - 'createpage_tryagain' => "No – quiero crear una página nueva con un título diferente.",
29 - 'createpage_editexisting' => "Sí – quiero contribuir a la página que ya existe."
 25+$messages['es'] = array(
 26+ 'createpage' => 'Crear una página',
 27+ 'createpage_submitbutton' => 'Enviar',
 28+ 'createpage_instructions' => 'Ingresa el título de la página que deseas crear:',
 29+ 'createpage_entertitle' => 'Ingresa un título para tu página.',
 30+ 'createpage_titleexists' => 'Ya existe una página con el título [[$1]]. ¿Quieres editar la página que ya existe?',
 31+ 'createpage_tryagain' => 'No – quiero crear una página nueva con un título diferente.',
 32+ 'createpage_editexisting' => 'Sí – quiero contribuir a la página que ya existe.',
3033 );
3134
32 -$wgCreatePageMessages['de'] = array(
33 - 'createpage' => "Neue Seite erstellen",
34 - 'createpage_submitbutton' => "Senden",
35 - 'createpage_instructions' => "Gib den Namen der neu zu erstellenden Seite ein:",
36 - 'createpage_entertitle' => "Titel für deine Seite.",
37 - 'createpage_titleexists' => "Eine Seite mit diesem Namen [[$1]] existiert bereits. Möchtest Du die existierende Seite bearbeiten?",
38 - 'createpage_tryagain' => "Nein - Ich möchte eine neue Seite mit einem anderen Titel anlegen.",
39 - 'createpage_editexisting' => "Ja - Ich möchte die existierende Seite bearbeiten."
 35+$messages['de'] = array(
 36+ 'createpage' => 'Neue Seite erstellen',
 37+ 'createpage_submitbutton' => 'Senden',
 38+ 'createpage_instructions' => 'Gib den Namen der neu zu erstellenden Seite ein:',
 39+ 'createpage_entertitle' => 'Titel für deine Seite.',
 40+ 'createpage_titleexists' => 'Eine Seite mit diesem Namen [[$1]] existiert bereits. Möchtest Du die existierende Seite bearbeiten?',
 41+ 'createpage_tryagain' => 'Nein - Ich möchte eine neue Seite mit einem anderen Titel anlegen.',
 42+ 'createpage_editexisting' => 'Ja - Ich möchte die existierende Seite bearbeiten.',
4043 );
4144
42 -$wgCreatePageMessages['pt-br'] = array(
43 - 'createpage' => "Criar uma página",
44 - 'createpage_submitbutton' => "Criar",
45 - 'createpage_instructions' => "Digite o título da página que você gostaria de criar:",
46 - 'createpage_entertitle' => "Digite um título para sua página.",
47 - 'createpage_titleexists' => "Uma página com o título, [[$1]], já existe. Você gostaria de editar a página existente?",
48 - 'createpage_tryagain' => "Não - Eu quero criar uma nova página com outro título.",
49 - 'createpage_editexisting' => "Sim - Eu quero editar a página existente."
 45+$messages['pt-br'] = array(
 46+ 'createpage' => 'Criar uma página',
 47+ 'createpage_submitbutton' => 'Criar',
 48+ 'createpage_instructions' => 'Digite o título da página que você gostaria de criar:',
 49+ 'createpage_entertitle' => 'Digite um título para sua página.',
 50+ 'createpage_titleexists' => 'Uma página com o título, [[$1]], já existe. Você gostaria de editar a página existente?',
 51+ 'createpage_tryagain' => 'Não - Eu quero criar uma nova página com outro título.',
 52+ 'createpage_editexisting' => 'Sim - Eu quero editar a página existente.',
5053 );
Index: trunk/extensions/uniwiki/CreatePage/CreatePage.php
@@ -3,7 +3,7 @@
44 * http://www.mediawiki.org/wiki/Extension:Uniwiki_Generic_Edit_Page
55 * http://www.gnu.org/licenses/gpl-3.0.txt */
66
7 -if (!defined('MEDIAWIKI'))
 7+if ( !defined( 'MEDIAWIKI' ) )
88 die();
99
1010 /* ---- CREDITS ---- */
@@ -15,102 +15,25 @@
1616 * GNU GPL v2.0 or later */
1717
1818 $wgExtensionCredits['other'][] = array(
19 - 'name' => "CreatePage",
20 - 'author' => "Merrick Schaefer, Mark Johnston, Evan Wheeler and Adam Mckaig (at UNICEF)",
21 - 'description' => "Adds a Special Page for creating new pages"
 19+ 'name' => 'CreatePage',
 20+ 'author' => 'Travis Derouin, Merrick Schaefer, Mark Johnston, Evan Wheeler and Adam Mckaig (at UNICEF), Siebrand Mazeland',
 21+ 'description' => 'Adds a [[Special:CreatePage|special page]] for creating new pages',
 22+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Uniwiki/AutoCreateCategoryPages',
 23+ 'svn-date' => '$LastChangedDate$',
 24+ 'svn-revision' => '$LastChangedRevision$',
 25+ 'descriptionmsg' => 'createpage-desc',
2226 );
2327
 28+$dir = dirname( __FILE__ ) . '/';
 29+$wgExtensionMessagesFiles['CreatePage'] = $dir . '/CreatePage.i18n.php';
 30+$wgExtensionAliasesFiles['CreatePage'] = $dir . 'CreatePage.alias.php';
 31+$wgAutoloadClasses['SpecialCreatePage'] = $dir . '/CreatePage_body.php';
 32+$wgSpecialPages['CreatePage'] = 'SpecialCreatePage';
 33+
 34+
2435 $wgHooks['BeforePageDisplay'][] = 'UW_CreatePage_CSS';
25 -function UW_CreatePage_CSS($out) {
 36+function UW_CreatePage_CSS( $out ) {
2637 global $wgScriptPath;
27 - $out->addScript ("<link rel='stylesheet' href='$wgScriptPath/extensions/uniwiki/CreatePage/style.css' />");
 38+ $out->addScript ( "<link rel='stylesheet' href='$wgScriptPath/extensions/uniwiki/CreatePage/style.css' />" );
2839 return true;
2940 }
30 -
31 -
32 -/* ---- INTERNATIONALIZATION ---- */
33 -
34 -require_once( 'CreatePage.i18n.php' );
35 -$wgExtensionFunctions[] = 'UW_CreatePage_i18n';
36 -
37 -function UW_CreatePage_i18n() {
38 - // add this extension's messages to the message cache
39 - global $wgMessageCache, $wgCreatePageMessages;
40 - foreach ($wgCreatePageMessages as $lang => $messages)
41 - $wgMessageCache->addMessages ($messages, $lang);
42 -}
43 -
44 -
45 -/* ---- SPECIAL PAGE ---- */
46 -
47 -require_once("SpecialPage.php");
48 -
49 -$wgExtensionFunctions[] = "wfCreatePage";
50 -function wfCreatePage() {
51 - SpecialPage::AddPage (new SpecialPage ("CreatePage")); }
52 -
53 -
54 -function wfSpecialCreatePage ($parser) {
55 - global $wgOut, $wgRequest, $wgUser;
56 - $skin = $wgUser->getSkin();
57 - $thisPage = Title::newFromText ("CreatePage", NS_SPECIAL);
58 - $target = $wgRequest->getVal ("target", null);
59 -
60 - // check to see if we are trying to create a page
61 - if ($target != null) {
62 - $title = Title::newFromText ($target);
63 -
64 - if ($title->getArticleID() > 0) {
65 -
66 - // if the title exists then let the user know and give other options
67 - $wgOut->addWikiText (wfMsg ("createpage_titleexists", $title->getFullText())."<br/>");
68 - $wgOut->addHTML ("<a href='".$title->getEditURL()."'>".wfMsg ("createpage_editexisting")."</a><br/>"
69 - .$skin->makeLinkObj ($thisPage, wfMsg ("createpage_tryagain"))
70 - );
71 - } else {
72 - /* TODO - may want to search for closely named pages and give
73 - * other options here... */
74 -
75 - // otherwise, redirect them to the edit page for their title
76 - $wgOut->redirect ($title->getEditURL());
77 - }
78 -
79 - return;
80 - }
81 -
82 - // if this is just a normal GET, then output the form
83 -
84 - // prefill the input with the title, if it was passed along
85 - $newTitle = $wgRequest->getVal("newtitle", null);
86 - if ($newTitle != null) $newTitle = str_replace("_", " ", $newTitle);
87 -
88 - // add some instructions
89 - $wgOut->addHTML(wfMsg('createpage_instructions'));
90 -
91 - // js for checking the form
92 - $wgOut->addHTML("
93 - <script type='text/javascript' >
94 - function checkForm(){
95 - // check the title
96 - if (document.createpageform.target && document.createpageform.target.value == \"\") {
97 - alert('".wfMsg('createpage_entertitle')."');
98 - document.createpageform.target.focus();
99 - return false;
100 - }
101 - // everything is OK, return true
102 - return true;
103 - }
104 - </script>
105 - ");
106 -
107 - // output the form
108 - $wgOut->addHTML("
109 - <form method=POST onsubmit='return checkForm()' name='createpageform'>
110 - <input type=text name=target size=50 value='$newTitle'><br/><br/>
111 - ");
112 -
113 - $wgOut->addHTML("
114 - <input type=submit value='".wfMsg('createpage_submitbutton')."'>
115 - </form>
116 - ");
117 -}
Property changes on: trunk/extensions/uniwiki/CreatePage/CreatePage.php
___________________________________________________________________
Added: svn:keywords
11841 + LastChangedDate LastChangedRevision
Index: trunk/extensions/uniwiki/CreatePage/CreatePage.alias.php
@@ -0,0 +1,11 @@
 2+<?php
 3+/**
 4+ * Aliases for special pages
 5+ *
 6+ */
 7+
 8+$aliases = array();
 9+
 10+$aliases['en'] = array(
 11+ 'CreatePage' => array( 'CreatePage' ),
 12+);
Property changes on: trunk/extensions/uniwiki/CreatePage/CreatePage.alias.php
___________________________________________________________________
Added: svn:eol-style
113 + native
Added: svn:keywords
214 + Id

Status & tagging log