r12282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12281‎ | r12282 | r12283 >
Date:10:21, 29 December 2005
Author:magnus_manske
Status:old
Tags:
Comment:
moving stuff from index.php to includes/Wiki.php
Modified paths:
  • /trunk/phase3/includes/Wiki.php (added) (history)
  • /trunk/phase3/index.php (modified) (history)

Diff [purge]

Index: trunk/phase3/index.php
@@ -67,6 +67,12 @@
6868 wfProfileIn( 'main-misc-setup' );
6969 OutputPage::setEncodings(); # Not really used yet
7070
 71+
 72+# The wiki action class
 73+require_once ( "includes/Wiki.php" ) ;
 74+$wgTheWiki = new MediaWikiType ;
 75+
 76+
7177 # Query string fields
7278 $action = $wgRequest->getVal( 'action', 'view' );
7379 $title = $wgRequest->getVal( 'title' );
@@ -110,158 +116,12 @@
111117 exit;
112118 }
113119
114 -wfProfileIn( 'main-action' );
115120
116 -if( !$wgDisableInternalSearch && !is_null( $search ) && $search !== '' ) {
117 - require_once( 'includes/SpecialSearch.php' );
118 - $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
119 - wfSpecialSearch();
120 -} else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
121 - $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
122 - $wgOut->errorpage( 'badtitle', 'badtitletext' );
123 -} else if ( $wgTitle->getInterwiki() != '' ) {
124 - if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
125 - $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
126 - } else {
127 - $url = $wgTitle->getFullURL();
128 - }
129 - # Check for a redirect loop
130 - if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
131 - $wgOut->redirect( $url );
132 - } else {
133 - $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
134 - $wgOut->errorpage( 'badtitle', 'badtitletext' );
135 - }
136 -} else if ( ( $action == 'view' ) &&
137 - (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
138 - !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
139 -{
140 - /* redirect to canonical url, make it a 301 to allow caching */
141 - $wgOut->setSquidMaxage( 1200 );
142 - $wgOut->redirect( $wgTitle->getFullURL(), '301');
143 -} else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
144 - # actions that need to be made when we have a special pages
145 - SpecialPage::executePath( $wgTitle );
146 -} else {
147 - if ( NS_MEDIA == $wgTitle->getNamespace() ) {
148 - $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
149 - }
 121+$wgTheWiki->mSearch = $search ;
 122+$wgTheWiki->main_action () ;
 123+# $search = $wgTheWiki->mSearch ; # Not needed
150124
151 - $ns = $wgTitle->getNamespace();
152125
153 - // Namespace might change when using redirects
154 - if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
155 - $wgArticle = new Article( $wgTitle );
156 - $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
157 - if($rTitle) {
158 - # Reload from the page pointed to later
159 - $wgArticle->mContentLoaded = false;
160 - $ns = $rTitle->getNamespace();
161 - }
162 - }
163 -
164 - // Categories and images are handled by a different class
165 - if ( $ns == NS_IMAGE ) {
166 - unset($wgArticle);
167 - require_once( 'includes/ImagePage.php' );
168 - $wgArticle = new ImagePage( $wgTitle );
169 - } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
170 - unset($wgArticle);
171 - require_once( 'includes/CategoryPage.php' );
172 - $wgArticle = new CategoryPage( $wgTitle );
173 - }
174 -
175 - if ( in_array( $action, $wgDisabledActions ) ) {
176 - $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
177 - } else {
178 - switch( $action ) {
179 - case 'view':
180 - $wgOut->setSquidMaxage( $wgSquidMaxage );
181 - $wgArticle->view();
182 - break;
183 - case 'watch':
184 - case 'unwatch':
185 - case 'delete':
186 - case 'revert':
187 - case 'rollback':
188 - case 'protect':
189 - case 'unprotect':
190 - case 'info':
191 - case 'markpatrolled':
192 - case 'validate':
193 - case 'render':
194 - case 'deletetrackback':
195 - case 'purge':
196 - $wgArticle->$action();
197 - break;
198 - case 'print':
199 - $wgArticle->view();
200 - break;
201 - case 'dublincore':
202 - if( !$wgEnableDublinCoreRdf ) {
203 - wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
204 - } else {
205 - require_once( 'includes/Metadata.php' );
206 - wfDublinCoreRdf( $wgArticle );
207 - }
208 - break;
209 - case 'creativecommons':
210 - if( !$wgEnableCreativeCommonsRdf ) {
211 - wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
212 - } else {
213 - require_once( 'includes/Metadata.php' );
214 - wfCreativeCommonsRdf( $wgArticle );
215 - }
216 - break;
217 - case 'credits':
218 - require_once( 'includes/Credits.php' );
219 - showCreditsPage( $wgArticle );
220 - break;
221 - case 'submit':
222 - if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
223 - # Send a cookie so anons get talk message notifications
224 - User::SetupSession();
225 - }
226 - # Continue...
227 - case 'edit':
228 - $internal = $wgRequest->getVal( 'internaledit' );
229 - $external = $wgRequest->getVal( 'externaledit' );
230 - $section = $wgRequest->getVal( 'section' );
231 - $oldid = $wgRequest->getVal( 'oldid' );
232 - if(!$wgUseExternalEditor || $action=='submit' || $internal ||
233 - $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
234 - require_once( 'includes/EditPage.php' );
235 - $editor = new EditPage( $wgArticle );
236 - $editor->submit();
237 - } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
238 - require_once( 'includes/ExternalEdit.php' );
239 - $mode = $wgRequest->getVal( 'mode' );
240 - $extedit = new ExternalEdit( $wgArticle, $mode );
241 - $extedit->edit();
242 - }
243 - break;
244 - case 'history':
245 - if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
246 - $wgOut->setSquidMaxage( $wgSquidMaxage );
247 - }
248 - require_once( 'includes/PageHistory.php' );
249 - $history = new PageHistory( $wgArticle );
250 - $history->history();
251 - break;
252 - case 'raw':
253 - require_once( 'includes/RawPage.php' );
254 - $raw = new RawPage( $wgArticle );
255 - $raw->view();
256 - break;
257 - default:
258 - if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
259 - $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
260 - }
261 - }
262 - }
263 -}
264 -wfProfileOut( 'main-action' );
265 -
266126 # Deferred updates aren't really deferred anymore. It's important to report errors to the
267127 # user, and that means doing this before OutputPage::output(). Note that for page saves,
268128 # the client will wait until the script exits anyway before following the redirect.
Index: trunk/phase3/includes/Wiki.php
@@ -0,0 +1,204 @@
 2+<?
 3+
 4+#__________________________
 5+#wiki class
 6+
 7+class MediaWikiType {
 8+
 9+ function main_action () {
 10+ global $wgTitle , $wgArticle , $wgRequest , $wgOut , $wgServer ;
 11+ global $wgDisableInternalSearch , $wgUseCategoryMagic , $wgDisabledActions , $action ;
 12+ wfProfileIn( 'main-action' );
 13+
 14+ if( !$wgDisableInternalSearch && !is_null( $this->mSearch ) && $this->mSearch !== '' ) {
 15+ require_once( 'includes/SpecialSearch.php' );
 16+ $wgTitle = Title::makeTitle( NS_SPECIAL, 'Search' );
 17+ wfSpecialSearch();
 18+ } else if( !$wgTitle or $wgTitle->getDBkey() == '' ) {
 19+ $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
 20+ $wgOut->errorpage( 'badtitle', 'badtitletext' );
 21+ } else if ( $wgTitle->getInterwiki() != '' ) {
 22+ if( $rdfrom = $wgRequest->getVal( 'rdfrom' ) ) {
 23+ $url = $wgTitle->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
 24+ } else {
 25+ $url = $wgTitle->getFullURL();
 26+ }
 27+ # Check for a redirect loop
 28+ if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url ) && $wgTitle->isLocal() ) {
 29+ $wgOut->redirect( $url );
 30+ } else {
 31+ $wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) );
 32+ $wgOut->errorpage( 'badtitle', 'badtitletext' );
 33+ }
 34+ } else if ( ( $action == 'view' ) &&
 35+ (!isset( $_GET['title'] ) || $wgTitle->getPrefixedDBKey() != $_GET['title'] ) &&
 36+ !count( array_diff( array_keys( $_GET ), array( 'action', 'title' ) ) ) )
 37+ {
 38+ /* redirect to canonical url, make it a 301 to allow caching */
 39+ $wgOut->setSquidMaxage( 1200 );
 40+ $wgOut->redirect( $wgTitle->getFullURL(), '301');
 41+ } else if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
 42+ # actions that need to be made when we have a special pages
 43+ SpecialPage::executePath( $wgTitle );
 44+ } else {
 45+ if ( NS_MEDIA == $wgTitle->getNamespace() ) {
 46+ $wgTitle = Title::makeTitle( NS_IMAGE, $wgTitle->getDBkey() );
 47+ }
 48+
 49+ $ns = $wgTitle->getNamespace();
 50+
 51+ // Namespace might change when using redirects
 52+ if($action == 'view' && !$wgRequest->getVal( 'oldid' ) ) {
 53+ $wgArticle = new Article( $wgTitle );
 54+ $rTitle = Title::newFromRedirect( $wgArticle->fetchContent() );
 55+ if($rTitle) {
 56+ # Reload from the page pointed to later
 57+ $wgArticle->mContentLoaded = false;
 58+ $ns = $rTitle->getNamespace();
 59+ }
 60+ }
 61+
 62+ // Categories and images are handled by a different class
 63+ if ( $ns == NS_IMAGE ) {
 64+ unset($wgArticle);
 65+ require_once( 'includes/ImagePage.php' );
 66+ $wgArticle = new ImagePage( $wgTitle );
 67+ } elseif ( $wgUseCategoryMagic && $ns == NS_CATEGORY ) {
 68+ unset($wgArticle);
 69+ require_once( 'includes/CategoryPage.php' );
 70+ $wgArticle = new CategoryPage( $wgTitle );
 71+ }
 72+
 73+ if ( in_array( $action, $wgDisabledActions ) ) {
 74+ $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
 75+ } else {
 76+ $act = 'act_' . $action ;
 77+ if ( method_exists ( $this , $act ) ) {
 78+ $this->$act ( $action ) ;
 79+ } else {
 80+ $this->action_unknown ( $action ) ;
 81+ }
 82+ }
 83+ }
 84+
 85+ wfProfileOut( 'main-action' );
 86+ }
 87+
 88+#____________________________________________________________________________________
 89+#Action methods
 90+
 91+ function act_view ( $action ) {
 92+ global $wgOut , $wgSquidMaxage , $wgArticle ;
 93+ $wgOut->setSquidMaxage( $wgSquidMaxage );
 94+ $wgArticle->view();
 95+ }
 96+
 97+ function act_print ( $action ) {
 98+ global $wgArticle ;
 99+ $wgArticle->view () ;
 100+ }
 101+
 102+ function act_dublincore ( $action ) {
 103+ global $wgArticle , $wgEnableDublinCoreRdf ;
 104+ if( !$wgEnableDublinCoreRdf ) {
 105+ wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
 106+ } else {
 107+ require_once( 'includes/Metadata.php' );
 108+ wfDublinCoreRdf( $wgArticle );
 109+ }
 110+ }
 111+
 112+ function act_creativecommons ( $action ) {
 113+ global $wgArticle , $wgEnableCreativeCommonsRdf ;
 114+ if( !$wgEnableCreativeCommonsRdf ) {
 115+ wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
 116+ } else {
 117+ require_once( 'includes/Metadata.php' );
 118+ wfCreativeCommonsRdf( $wgArticle );
 119+ }
 120+ }
 121+
 122+ function act_credits ( $action ) {
 123+ global $wgArticle ;
 124+ require_once( 'includes/Credits.php' );
 125+ showCreditsPage( $wgArticle );
 126+ }
 127+
 128+ function act_submit ( $action ) {
 129+ global $wgCommandLineMode , $wgRequest ;
 130+ if( !$wgCommandLineMode && !$wgRequest->checkSessionCookie() ) {
 131+ # Send a cookie so anons get talk message notifications
 132+ User::SetupSession();
 133+ }
 134+ $this->act_edit ( $action ) ;
 135+ }
 136+
 137+ function act_edit ( $action ) {
 138+ global $wgRequest , $wgUseExternalEditor , $wgUser , $wgArticle ;
 139+ $internal = $wgRequest->getVal( 'internaledit' );
 140+ $external = $wgRequest->getVal( 'externaledit' );
 141+ $section = $wgRequest->getVal( 'section' );
 142+ $oldid = $wgRequest->getVal( 'oldid' );
 143+ if(!$wgUseExternalEditor || $action=='submit' || $internal ||
 144+ $section || $oldid || (!$wgUser->getOption('externaleditor') && !$external)) {
 145+ require_once( 'includes/EditPage.php' );
 146+ $editor = new EditPage( $wgArticle );
 147+ $editor->submit();
 148+ } elseif($wgUseExternalEditor && ($external || $wgUser->getOption('externaleditor'))) {
 149+ require_once( 'includes/ExternalEdit.php' );
 150+ $mode = $wgRequest->getVal( 'mode' );
 151+ $extedit = new ExternalEdit( $wgArticle, $mode );
 152+ $extedit->edit();
 153+ }
 154+ }
 155+
 156+ function act_history ( $action ) {
 157+ global $wgTitle , $wgArticle , $wgSquidMaxage ;
 158+ if ($_SERVER['REQUEST_URI'] == $wgTitle->getInternalURL('action=history')) {
 159+ $wgOut->setSquidMaxage( $wgSquidMaxage );
 160+ }
 161+ require_once( 'includes/PageHistory.php' );
 162+ $history = new PageHistory( $wgArticle );
 163+ $history->history();
 164+ }
 165+
 166+ function act_raw ( $action ) {
 167+ global $wgArticle ;
 168+ require_once( 'includes/RawPage.php' );
 169+ $raw = new RawPage( $wgArticle );
 170+ $raw->view();
 171+ }
 172+
 173+
 174+ function action_unknown ( $action ) {
 175+ global $wgArticle , $wgOut ;
 176+ if (wfRunHooks('UnknownAction', array($action, $wgArticle))) {
 177+ $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
 178+ }
 179+ }
 180+
 181+
 182+ function act_watch ( $action ) { $this->article_action ( $action ) ; }
 183+ function act_unwatch ( $action ) { $this->article_action ( $action ) ; }
 184+ function act_delete ( $action ) { $this->article_action ( $action ) ; }
 185+ function act_revert ( $action ) { $this->article_action ( $action ) ; }
 186+ function act_rollback ( $action ) { $this->article_action ( $action ) ; }
 187+ function act_protect ( $action ) { $this->article_action ( $action ) ; }
 188+ function act_unprotect ( $action ) { $this->article_action ( $action ) ; }
 189+ function act_info ( $action ) { $this->article_action ( $action ) ; }
 190+ function act_markpatrolled ( $action ) { $this->article_action ( $action ) ; }
 191+ function act_validate ( $action ) { $this->article_action ( $action ) ; }
 192+ function act_render ( $action ) { $this->article_action ( $action ) ; }
 193+ function act_deletetrackback ( $action ) { $this->article_action ( $action ) ; }
 194+ function act_purge ( $action ) { $this->article_action ( $action ) ; }
 195+
 196+ function article_action ( $action ) {
 197+ global $wgArticle ;
 198+ $wgArticle->$action() ;
 199+ }
 200+
 201+
 202+} ; # end of class MediaWikiType
 203+
 204+?>
 205+
Property changes on: trunk/phase3/includes/Wiki.php
___________________________________________________________________
Added: svn:eol-style
1206 + native
Added: svn:keywords
2207 + Author Date Id Revision

Status & tagging log