r102093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102092‎ | r102093 | r102094 >
Date:13:36, 5 November 2011
Author:ashley
Status:deferred
Tags:
Comment:
CreateAPage: follow-up to r98699 as per Roan's review: rename the extension setup file to match directory name (no code changes)
Modified paths:
  • /trunk/extensions/CreateAPage/CreateAPage.php (added) (history)
  • /trunk/extensions/CreateAPage/CreatePage.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/CreateAPage/CreatePage.php
@@ -1,198 +0,0 @@
2 -<?php
3 -/**
4 - * A special page to create a new article using the easy-to-use interface at
5 - * Special:CreatePage.
6 - *
7 - * @file
8 - * @ingroup Extensions
9 - * @version 3.91 (r15554)
10 - * @author Bartek Łapiński <bartek@wikia-inc.com>
11 - * @author Jack Phoenix <jack@countervandalism.net>
12 - * @copyright Copyright © 2007-2008 Wikia Inc.
13 - * @copyright Copyright © 2009-2011 Jack Phoenix
14 - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
15 - * @link http://www.mediawiki.org/wiki/Extension:CreateAPage Documentation
16 - */
17 -
18 -if( !defined( 'MEDIAWIKI' ) ) {
19 - die();
20 -}
21 -
22 -// Extension credits that will show up on Special:Version
23 -$wgExtensionCredits['specialpage'][] = array(
24 - 'name' => 'CreateAPage',
25 - 'author' => array(
26 - 'Bartek Łapiński', 'Łukasz Garczewski', 'Przemek Piotrowski',
27 - 'Jack Phoenix'
28 - ),
29 - 'version' => '3.91',
30 - 'description' => '[[Special:CreatePage|Easy to use interface]] for creating new articles',
31 - 'url' => 'http://www.mediawiki.org/wiki/Extension:CreateAPage',
32 -);
33 -
34 -// Autoload classes and set up the new special page(s)
35 -$dir = dirname( __FILE__ ) . '/';
36 -$wgExtensionMessagesFiles['CreateAPage'] = $dir . 'CreateAPage.i18n.php';
37 -$wgAutoloadClasses['EasyTemplate'] = $dir . 'EasyTemplate.php'; // @todo FIXME: kill templates and remove this class
38 -$wgAutoloadClasses['CreateMultiPage'] = $dir . 'CreateMultiPage.php';
39 -$wgAutoloadClasses['CreatePage'] = $dir . 'SpecialCreatePage.body.php';
40 -$wgAutoloadClasses['CreatePageEditor'] = $dir . 'CreatePageEditor.php';
41 -$wgAutoloadClasses['CreatePageMultiEditor'] = $dir . 'CreatePageEditor.php';
42 -$wgAutoloadClasses['CreatePageCreateplateForm'] = $dir . 'CreatePageCreateplateForm.php';
43 -$wgAutoloadClasses['CreatePageImageUploadForm'] = $dir . 'CreatePageImageUploadForm.php';
44 -$wgAutoloadClasses['PocketSilentArticle'] = $dir . 'CreatePageEditor.php';
45 -$wgSpecialPages['CreatePage'] = 'CreatePage';
46 -$wgSpecialPageGroups['CreatePage'] = 'pagetools';
47 -
48 -// Load AJAX functions, too
49 -require_once $dir . 'SpecialCreatePage_ajax.php';
50 -
51 -// ResourceLoader support for MediaWiki 1.17+
52 -$wgResourceModules['ext.createAPage'] = array(
53 - 'styles' => 'CreatePage.css',
54 - 'scripts' => 'js/CreateAPage.js',
55 - 'messages' => array(
56 - 'createpage-insert-image', 'createpage-upload-aborted',
57 - 'createpage-img-uploaded', 'createpage-login-required',
58 - 'createpage-login-href', 'createpage-login-required2',
59 - 'createpage-give-title', 'createpage-img-uploaded',
60 - 'createpage-article-exists', 'createpage-article-exists2',
61 - 'createpage-title-invalid', 'createpage-please-wait',
62 - 'createpage-show', 'createpage-hide',
63 - 'createpage-must-specify-title', 'createpage-unsaved-changes',
64 - 'createpage-unsaved-changes-details'
65 - ),
66 - 'dependencies' => array( 'jquery.ui', 'jquery.ui.dialog' ),
67 - 'localBasePath' => dirname( __FILE__ ),
68 - 'remoteExtPath' => 'CreateAPage',
69 - 'position' => 'top' // available since r85616
70 -);
71 -
72 -// Our only configuration setting -- use CreateAPage on redlinks (i.e. clicking
73 -// on a redlink takes you to index.php?title=Special:CreatePage&Createtitle=Title_of_our_page
74 -// instead of taking you to index.php?title=Title_of_our_page&action=edit&redlink=1)
75 -$wgCreatePageCoverRedLinks = false;
76 -
77 -// Hooked functions
78 -$wgHooks['EditPage::showEditForm:initial'][] = 'wfCreatePagePreloadContent';
79 -// I'm not sure if this and the related, custom Article class are even needed
80 -// nowadays, so I'm disabling it for the time being.
81 -//$wgHooks['Image::RecordUpload:article'][] = 'wfCreatePageShowNoImagePage';
82 -$wgHooks['CustomEditor'][] = 'wfCreatePageRedLinks';
83 -$wgHooks['ConfirmEdit::onConfirmEdit'][] = 'wfCreatePageConfirmEdit'; // ConfirmEdit CAPTCHA
84 -
85 -$wgHooks['GetPreferences'][] = 'wfCreatePageToggle';
86 -
87 -// handle ConfirmEdit CAPTCHA, only for CreatePage, which will be treated a bit differently (edits in special page)
88 -function wfCreatePageConfirmEdit( &$captcha, &$editPage, $newtext, $section, $merged, &$result ) {
89 - global $wgTitle, $wgCreatePageCoverRedLinks;
90 -
91 - // Enable only if the configuration global is set to true,
92 - // only for Special:CreatePage and only when ConfirmEdit is installed
93 - $canonspname = SpecialPage::resolveAlias( $wgTitle->getDBkey() );
94 - if ( !$wgCreatePageCoverRedLinks ) {
95 - return true;
96 - }
97 - if ( $canonspname != 'CreatePage' ) {
98 - return true;
99 - }
100 - if ( !class_exists( 'SimpleCaptcha' ) ) {
101 - return true;
102 - }
103 -
104 - if( $captcha->shouldCheck( $editPage, $newtext, $section, $merged ) ) {
105 - if( $captcha->passCaptcha() ) {
106 - $result = true;
107 - return false;
108 - } else {
109 - // display CAP page
110 - $mainform = new CreatePageCreatePlateForm();
111 - $mainform->showForm( '', false, array( &$captcha, 'editCallback' ) );
112 - $editor = new CreatePageMultiEditor( $_SESSION['article_createplate'] );
113 - $editor->generateForm( $newtext );
114 -
115 - $result = false;
116 - return false;
117 - }
118 - } else {
119 - return true;
120 - }
121 -}
122 -
123 -// when AdvancedEdit button is used, the existing content is preloaded
124 -function wfCreatePagePreloadContent( $editpage ) {
125 - global $wgRequest;
126 - if( $wgRequest->getCheck( 'createpage' ) ) {
127 - $editpage->textbox1 = $_SESSION['article_content'];
128 - }
129 - return true;
130 -}
131 -
132 -// because MediaWiki jumps happily to the article page
133 -// when we create it - in this case, for image upload
134 -function wfCreatePageShowNoImagePage( $article, $title ) {
135 - $article = new PocketSilentArticle( $title );
136 - return true;
137 -}
138 -
139 -function wfCreatePageRedLinks( $article, $user ) {
140 - global $wgRequest, $wgContentNamespaces, $wgCreatePageCoverRedLinks;
141 -
142 - if ( !$wgCreatePageCoverRedLinks ) {
143 - return true;
144 - }
145 -
146 - $namespace = $article->getTitle()->getNamespace();
147 - if (
148 - ( $user->getOption( 'createpage-redlinks', 1 ) == 0 ) ||
149 - !in_array( $namespace, $wgContentNamespaces )
150 - )
151 - {
152 - return true;
153 - }
154 -
155 - // nomulti should always bypass that (this is for AdvancedEdit mode)
156 - if (
157 - $article->getTitle()->exists() ||
158 - ( $wgRequest->getVal( 'editmode' ) == 'nomulti' )
159 - )
160 - {
161 - return true;
162 - } else {
163 - if ( $wgRequest->getCheck( 'wpPreview' ) ) {
164 - return true;
165 - }
166 - $mainform = new CreatePageCreateplateForm();
167 - $mainform->mTitle = $wgRequest->getVal( 'title' );
168 - $mainform->mRedLinked = true;
169 - $mainform->showForm( '' );
170 - $mainform->showCreateplate( true );
171 - return false;
172 - }
173 -}
174 -
175 -/**
176 - * Adds a new toggle into Special:Preferences when $wgCreatePageCoverRedLinks
177 - * is set to true.
178 - *
179 - * @param $user Object: current User object
180 - * @param $preferences Object: Preferences object
181 - * @return Boolean: true
182 - */
183 -function wfCreatePageToggle( $user, &$preferences ) {
184 - global $wgCreatePageCoverRedLinks;
185 - if ( $wgCreatePageCoverRedLinks ) {
186 - $preferences['create-page-redlinks'] = array(
187 - 'type' => 'toggle',
188 - 'section' => 'editing/advancedediting',
189 - 'label-message' => 'tog-createpage-redlinks',
190 - );
191 - }
192 - return true;
193 -}
194 -
195 -// Restore what we temporarily encoded
196 -// moved from CreateMultiPage.php
197 -function wfCreatePageUnescapeKnownMarkupTags( &$text ) {
198 - $text = str_replace( '<!---pipe--->', '|', $text );
199 -}
\ No newline at end of file
Index: trunk/extensions/CreateAPage/CreateAPage.php
@@ -0,0 +1,198 @@
 2+<?php
 3+/**
 4+ * A special page to create a new article using the easy-to-use interface at
 5+ * Special:CreatePage.
 6+ *
 7+ * @file
 8+ * @ingroup Extensions
 9+ * @version 3.91 (r15554)
 10+ * @author Bartek Łapiński <bartek@wikia-inc.com>
 11+ * @author Jack Phoenix <jack@countervandalism.net>
 12+ * @copyright Copyright © 2007-2008 Wikia Inc.
 13+ * @copyright Copyright © 2009-2011 Jack Phoenix
 14+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 15+ * @link http://www.mediawiki.org/wiki/Extension:CreateAPage Documentation
 16+ */
 17+
 18+if( !defined( 'MEDIAWIKI' ) ) {
 19+ die();
 20+}
 21+
 22+// Extension credits that will show up on Special:Version
 23+$wgExtensionCredits['specialpage'][] = array(
 24+ 'name' => 'CreateAPage',
 25+ 'author' => array(
 26+ 'Bartek Łapiński', 'Łukasz Garczewski', 'Przemek Piotrowski',
 27+ 'Jack Phoenix'
 28+ ),
 29+ 'version' => '3.91',
 30+ 'description' => '[[Special:CreatePage|Easy to use interface]] for creating new articles',
 31+ 'url' => 'http://www.mediawiki.org/wiki/Extension:CreateAPage',
 32+);
 33+
 34+// Autoload classes and set up the new special page(s)
 35+$dir = dirname( __FILE__ ) . '/';
 36+$wgExtensionMessagesFiles['CreateAPage'] = $dir . 'CreateAPage.i18n.php';
 37+$wgAutoloadClasses['EasyTemplate'] = $dir . 'EasyTemplate.php'; // @todo FIXME: kill templates and remove this class
 38+$wgAutoloadClasses['CreateMultiPage'] = $dir . 'CreateMultiPage.php';
 39+$wgAutoloadClasses['CreatePage'] = $dir . 'SpecialCreatePage.body.php';
 40+$wgAutoloadClasses['CreatePageEditor'] = $dir . 'CreatePageEditor.php';
 41+$wgAutoloadClasses['CreatePageMultiEditor'] = $dir . 'CreatePageEditor.php';
 42+$wgAutoloadClasses['CreatePageCreateplateForm'] = $dir . 'CreatePageCreateplateForm.php';
 43+$wgAutoloadClasses['CreatePageImageUploadForm'] = $dir . 'CreatePageImageUploadForm.php';
 44+$wgAutoloadClasses['PocketSilentArticle'] = $dir . 'CreatePageEditor.php';
 45+$wgSpecialPages['CreatePage'] = 'CreatePage';
 46+$wgSpecialPageGroups['CreatePage'] = 'pagetools';
 47+
 48+// Load AJAX functions, too
 49+require_once $dir . 'SpecialCreatePage_ajax.php';
 50+
 51+// ResourceLoader support for MediaWiki 1.17+
 52+$wgResourceModules['ext.createAPage'] = array(
 53+ 'styles' => 'CreatePage.css',
 54+ 'scripts' => 'js/CreateAPage.js',
 55+ 'messages' => array(
 56+ 'createpage-insert-image', 'createpage-upload-aborted',
 57+ 'createpage-img-uploaded', 'createpage-login-required',
 58+ 'createpage-login-href', 'createpage-login-required2',
 59+ 'createpage-give-title', 'createpage-img-uploaded',
 60+ 'createpage-article-exists', 'createpage-article-exists2',
 61+ 'createpage-title-invalid', 'createpage-please-wait',
 62+ 'createpage-show', 'createpage-hide',
 63+ 'createpage-must-specify-title', 'createpage-unsaved-changes',
 64+ 'createpage-unsaved-changes-details'
 65+ ),
 66+ 'dependencies' => array( 'jquery.ui', 'jquery.ui.dialog' ),
 67+ 'localBasePath' => dirname( __FILE__ ),
 68+ 'remoteExtPath' => 'CreateAPage',
 69+ 'position' => 'top' // available since r85616
 70+);
 71+
 72+// Our only configuration setting -- use CreateAPage on redlinks (i.e. clicking
 73+// on a redlink takes you to index.php?title=Special:CreatePage&Createtitle=Title_of_our_page
 74+// instead of taking you to index.php?title=Title_of_our_page&action=edit&redlink=1)
 75+$wgCreatePageCoverRedLinks = false;
 76+
 77+// Hooked functions
 78+$wgHooks['EditPage::showEditForm:initial'][] = 'wfCreatePagePreloadContent';
 79+// I'm not sure if this and the related, custom Article class are even needed
 80+// nowadays, so I'm disabling it for the time being.
 81+//$wgHooks['Image::RecordUpload:article'][] = 'wfCreatePageShowNoImagePage';
 82+$wgHooks['CustomEditor'][] = 'wfCreatePageRedLinks';
 83+$wgHooks['ConfirmEdit::onConfirmEdit'][] = 'wfCreatePageConfirmEdit'; // ConfirmEdit CAPTCHA
 84+
 85+$wgHooks['GetPreferences'][] = 'wfCreatePageToggle';
 86+
 87+// handle ConfirmEdit CAPTCHA, only for CreatePage, which will be treated a bit differently (edits in special page)
 88+function wfCreatePageConfirmEdit( &$captcha, &$editPage, $newtext, $section, $merged, &$result ) {
 89+ global $wgTitle, $wgCreatePageCoverRedLinks;
 90+
 91+ // Enable only if the configuration global is set to true,
 92+ // only for Special:CreatePage and only when ConfirmEdit is installed
 93+ $canonspname = SpecialPage::resolveAlias( $wgTitle->getDBkey() );
 94+ if ( !$wgCreatePageCoverRedLinks ) {
 95+ return true;
 96+ }
 97+ if ( $canonspname != 'CreatePage' ) {
 98+ return true;
 99+ }
 100+ if ( !class_exists( 'SimpleCaptcha' ) ) {
 101+ return true;
 102+ }
 103+
 104+ if( $captcha->shouldCheck( $editPage, $newtext, $section, $merged ) ) {
 105+ if( $captcha->passCaptcha() ) {
 106+ $result = true;
 107+ return false;
 108+ } else {
 109+ // display CAP page
 110+ $mainform = new CreatePageCreatePlateForm();
 111+ $mainform->showForm( '', false, array( &$captcha, 'editCallback' ) );
 112+ $editor = new CreatePageMultiEditor( $_SESSION['article_createplate'] );
 113+ $editor->generateForm( $newtext );
 114+
 115+ $result = false;
 116+ return false;
 117+ }
 118+ } else {
 119+ return true;
 120+ }
 121+}
 122+
 123+// when AdvancedEdit button is used, the existing content is preloaded
 124+function wfCreatePagePreloadContent( $editpage ) {
 125+ global $wgRequest;
 126+ if( $wgRequest->getCheck( 'createpage' ) ) {
 127+ $editpage->textbox1 = $_SESSION['article_content'];
 128+ }
 129+ return true;
 130+}
 131+
 132+// because MediaWiki jumps happily to the article page
 133+// when we create it - in this case, for image upload
 134+function wfCreatePageShowNoImagePage( $article, $title ) {
 135+ $article = new PocketSilentArticle( $title );
 136+ return true;
 137+}
 138+
 139+function wfCreatePageRedLinks( $article, $user ) {
 140+ global $wgRequest, $wgContentNamespaces, $wgCreatePageCoverRedLinks;
 141+
 142+ if ( !$wgCreatePageCoverRedLinks ) {
 143+ return true;
 144+ }
 145+
 146+ $namespace = $article->getTitle()->getNamespace();
 147+ if (
 148+ ( $user->getOption( 'createpage-redlinks', 1 ) == 0 ) ||
 149+ !in_array( $namespace, $wgContentNamespaces )
 150+ )
 151+ {
 152+ return true;
 153+ }
 154+
 155+ // nomulti should always bypass that (this is for AdvancedEdit mode)
 156+ if (
 157+ $article->getTitle()->exists() ||
 158+ ( $wgRequest->getVal( 'editmode' ) == 'nomulti' )
 159+ )
 160+ {
 161+ return true;
 162+ } else {
 163+ if ( $wgRequest->getCheck( 'wpPreview' ) ) {
 164+ return true;
 165+ }
 166+ $mainform = new CreatePageCreateplateForm();
 167+ $mainform->mTitle = $wgRequest->getVal( 'title' );
 168+ $mainform->mRedLinked = true;
 169+ $mainform->showForm( '' );
 170+ $mainform->showCreateplate( true );
 171+ return false;
 172+ }
 173+}
 174+
 175+/**
 176+ * Adds a new toggle into Special:Preferences when $wgCreatePageCoverRedLinks
 177+ * is set to true.
 178+ *
 179+ * @param $user Object: current User object
 180+ * @param $preferences Object: Preferences object
 181+ * @return Boolean: true
 182+ */
 183+function wfCreatePageToggle( $user, &$preferences ) {
 184+ global $wgCreatePageCoverRedLinks;
 185+ if ( $wgCreatePageCoverRedLinks ) {
 186+ $preferences['create-page-redlinks'] = array(
 187+ 'type' => 'toggle',
 188+ 'section' => 'editing/advancedediting',
 189+ 'label-message' => 'tog-createpage-redlinks',
 190+ );
 191+ }
 192+ return true;
 193+}
 194+
 195+// Restore what we temporarily encoded
 196+// moved from CreateMultiPage.php
 197+function wfCreatePageUnescapeKnownMarkupTags( &$text ) {
 198+ $text = str_replace( '<!---pipe--->', '|', $text );
 199+}
\ No newline at end of file
Property changes on: trunk/extensions/CreateAPage/CreateAPage.php
___________________________________________________________________
Added: svn:eol-style
1200 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98699add CreateAPage to SVN. Mostly compatible with 1.16, except that the upload f...ashley18:27, 2 October 2011

Status & tagging log