fixed redirect-to-image bug
[lhc/web/wiklou.git] / includes / Wiki.php
1 <?php
2 /**
3 * MediaWiki is the to-be base class for this whole project
4 */
5
6
7 class MediaWiki {
8
9 var $params = array();
10
11 /**
12 * Stores parameters (to avoid using globals)
13 */
14 function setVal( $key, &$value ) {
15 $this->param[strtolower( $key )] = $value;
16 }
17
18 /**
19 * Retrieves parameters
20 */
21 function getVal( $key, $default = "" ) {
22 $key = strtolower( $key );
23 if( isset( $this->params[$key] ) ) {
24 return $this->params[$key];
25 }
26 return $default;
27 }
28
29 /**
30 * Creates the article to be known as $wgArticle
31 */
32 function initializeArticle( &$title, &$request, $action ) {
33 // Fix Media namespace
34 if( NS_MEDIA == $title->getNamespace() ) {
35 $title = Title::makeTitle( NS_IMAGE, $title->getDBkey() );
36 }
37
38 $ns = $title->getNamespace();
39
40 // Namespace might change when using redirects
41 $article = new Article( $title );
42 if($action == 'view' && !$request->getVal( 'oldid' ) ) {
43 $rTitle = Title::newFromRedirect( $article->fetchContent() );
44 if($rTitle) {
45 # Reload from the page pointed to later
46 $article->mContentLoaded = false;
47 $ns = $rTitle->getNamespace();
48 $wasRedirected = true;
49 }
50 }
51
52 // Categories and images are handled by a different class
53 if( $ns == NS_IMAGE ) {
54 $b4 = $title->getPrefixedText();
55 unset($article);
56 require_once( 'includes/ImagePage.php' );
57 $article = new ImagePage( $title );
58 if( isset( $wasRedirected ) ) {
59 $article->mTitle = $rTitle;
60 $article->mRedirectedFrom = $b4;
61 }
62 } elseif( $ns == NS_CATEGORY ) {
63 unset($article);
64 require_once( 'includes/CategoryPage.php' );
65 $article = new CategoryPage( $title );
66 }
67 return $article;
68 }
69
70 /**
71 * Performs any of a wide range of passed actions
72 */
73 function performAction( $action, &$output, &$article, &$title, &$user, &$request ) {
74 switch( $action ) {
75 case 'view':
76 $output->setSquidMaxage( $this->getVal('SquidMaxage') );
77 $article->view();
78 break;
79 case 'watch':
80 case 'unwatch':
81 case 'delete':
82 case 'revert':
83 case 'rollback':
84 case 'protect':
85 case 'unprotect':
86 case 'info':
87 case 'markpatrolled':
88 case 'validate':
89 case 'render':
90 case 'deletetrackback':
91 case 'purge':
92 $article->$action();
93 break;
94 case 'print':
95 $article->view();
96 break;
97 case 'dublincore':
98 if( !$this->getVal('EnableDublinCoreRdf') ) {
99 wfHttpError( 403, 'Forbidden', wfMsg( 'nodublincore' ) );
100 } else {
101 require_once( 'includes/Metadata.php' );
102 wfDublinCoreRdf( $article );
103 }
104 break;
105 case 'creativecommons':
106 if( !$this->getVal('EnableCreativeCommonsRdf') ) {
107 wfHttpError( 403, 'Forbidden', wfMsg('nocreativecommons') );
108 } else {
109 require_once( 'includes/Metadata.php' );
110 wfCreativeCommonsRdf( $article );
111 }
112 break;
113 case 'credits':
114 require_once( 'includes/Credits.php' );
115 showCreditsPage( $article );
116 break;
117 case 'submit':
118 if( !$this->getVal('CommandLineMode') && !$request->checkSessionCookie() ) {
119 # Send a cookie so anons get talk message notifications
120 User::SetupSession();
121 }
122 # Continue...
123 case 'edit':
124 $internal = $request->getVal( 'internaledit' );
125 $external = $request->getVal( 'externaledit' );
126 $section = $request->getVal( 'section' );
127 $oldid = $request->getVal( 'oldid' );
128 if(!$this->getVal('UseExternalEditor') || $action=='submit' || $internal ||
129 $section || $oldid ||(!$user->getOption('externaleditor') && !$external)) {
130 require_once( 'includes/EditPage.php' );
131 $editor = new EditPage( $article );
132 $editor->submit();
133 } elseif($this->getVal('UseExternalEditor') &&($external || $user->getOption('externaleditor'))) {
134 require_once( 'includes/ExternalEdit.php' );
135 $mode = $request->getVal( 'mode' );
136 $extedit = new ExternalEdit( $article, $mode );
137 $extedit->edit();
138 }
139 break;
140 case 'history':
141 if($_SERVER['REQUEST_URI'] == $title->getInternalURL('action=history')) {
142 $output->setSquidMaxage( $this->getVal('SquidMaxage') );
143 }
144 require_once( 'includes/PageHistory.php' );
145 $history = new PageHistory( $article );
146 $history->history();
147 break;
148 case 'raw':
149 require_once( 'includes/RawPage.php' );
150 $raw = new RawPage( $article );
151 $raw->view();
152 break;
153 default:
154 if(wfRunHooks('UnknownAction', array($action, $article))) {
155 $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
156 }
157 }
158 }
159
160 }; # End of class MediaWiki
161
162 ?>
163