7f3853d279522276692a478a7a83d7bd25949ac1
[lhc/web/wiklou.git] / includes / EditPage.php
1 <?php
2 /**
3 * Contains the EditPage class
4 * @file
5 */
6
7 /**
8 * The edit page/HTML interface (split from Article)
9 * The actual database and text munging is still in Article,
10 * but it should get easier to call those from alternate
11 * interfaces.
12 *
13 * EditPage cares about two distinct titles:
14 * $wgTitle is the page that forms submit to, links point to,
15 * redirects go to, etc. $this->mTitle (as well as $mArticle) is the
16 * page in the database that is actually being edited. These are
17 * usually the same, but they are now allowed to be different.
18 */
19 class EditPage {
20 const AS_SUCCESS_UPDATE = 200;
21 const AS_SUCCESS_NEW_ARTICLE = 201;
22 const AS_HOOK_ERROR = 210;
23 const AS_FILTERING = 211;
24 const AS_HOOK_ERROR_EXPECTED = 212;
25 const AS_BLOCKED_PAGE_FOR_USER = 215;
26 const AS_CONTENT_TOO_BIG = 216;
27 const AS_USER_CANNOT_EDIT = 217;
28 const AS_READ_ONLY_PAGE_ANON = 218;
29 const AS_READ_ONLY_PAGE_LOGGED = 219;
30 const AS_READ_ONLY_PAGE = 220;
31 const AS_RATE_LIMITED = 221;
32 const AS_ARTICLE_WAS_DELETED = 222;
33 const AS_NO_CREATE_PERMISSION = 223;
34 const AS_BLANK_ARTICLE = 224;
35 const AS_CONFLICT_DETECTED = 225;
36 const AS_SUMMARY_NEEDED = 226;
37 const AS_TEXTBOX_EMPTY = 228;
38 const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
39 const AS_OK = 230;
40 const AS_END = 231;
41 const AS_SPAM_ERROR = 232;
42 const AS_IMAGE_REDIRECT_ANON = 233;
43 const AS_IMAGE_REDIRECT_LOGGED = 234;
44
45 var $mArticle;
46 var $mTitle;
47 var $action;
48 var $mMetaData = '';
49 var $isConflict = false;
50 var $isCssJsSubpage = false;
51 var $deletedSinceEdit = false;
52 var $formtype;
53 var $firsttime;
54 var $lastDelete;
55 var $mTokenOk = false;
56 var $mTokenOkExceptSuffix = false;
57 var $mTriedSave = false;
58 var $tooBig = false;
59 var $kblength = false;
60 var $missingComment = false;
61 var $missingSummary = false;
62 var $allowBlankSummary = false;
63 var $autoSumm = '';
64 var $hookError = '';
65 #var $mPreviewTemplates;
66 var $mParserOutput;
67 var $mBaseRevision = false;
68
69 # Form values
70 var $save = false, $preview = false, $diff = false;
71 var $minoredit = false, $watchthis = false, $recreate = false;
72 var $textbox1 = '', $textbox2 = '', $summary = '';
73 var $edittime = '', $section = '', $starttime = '';
74 var $oldid = 0, $editintro = '', $scrolltop = null;
75
76 # Placeholders for text injection by hooks (must be HTML)
77 # extensions should take care to _append_ to the present value
78 public $editFormPageTop; // Before even the preview
79 public $editFormTextTop;
80 public $editFormTextBeforeContent;
81 public $editFormTextAfterWarn;
82 public $editFormTextAfterTools;
83 public $editFormTextBottom;
84
85 /* $didSave should be set to true whenever an article was succesfully altered. */
86 public $didSave = false;
87
88 public $suppressIntro = false;
89
90 /**
91 * @todo document
92 * @param $article
93 */
94 function EditPage( $article ) {
95 $this->mArticle =& $article;
96 $this->mTitle = $article->getTitle();
97 $this->action = 'submit';
98
99 # Placeholders for text injection by hooks (empty per default)
100 $this->editFormPageTop =
101 $this->editFormTextTop =
102 $this->editFormTextBeforeContent =
103 $this->editFormTextAfterWarn =
104 $this->editFormTextAfterTools =
105 $this->editFormTextBottom = "";
106 }
107
108 /**
109 * Fetch initial editing page content.
110 * @private
111 */
112 function getContent( $def_text = '' ) {
113 global $wgOut, $wgRequest, $wgParser, $wgMessageCache;
114
115 # Get variables from query string :P
116 $section = $wgRequest->getVal( 'section' );
117 $preload = $wgRequest->getVal( 'preload' );
118 $undoafter = $wgRequest->getVal( 'undoafter' );
119 $undo = $wgRequest->getVal( 'undo' );
120
121 wfProfileIn( __METHOD__ );
122
123 $text = '';
124 if( !$this->mTitle->exists() ) {
125 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
126 $wgMessageCache->loadAllMessages();
127 # If this is a system message, get the default text.
128 $text = wfMsgWeirdKey( $this->mTitle->getText() ) ;
129 } else {
130 # If requested, preload some text.
131 $text = $this->getPreloadedText( $preload );
132 }
133 # We used to put MediaWiki:Newarticletext here if
134 # $text was empty at this point.
135 # This is now shown above the edit box instead.
136 } else {
137 // FIXME: may be better to use Revision class directly
138 // But don't mess with it just yet. Article knows how to
139 // fetch the page record from the high-priority server,
140 // which is needed to guarantee we don't pick up lagged
141 // information.
142
143 $text = $this->mArticle->getContent();
144
145 if ($undo > 0 && $undoafter > 0 && $undo < $undoafter) {
146 # If they got undoafter and undo round the wrong way, switch them
147 list( $undo, $undoafter ) = array( $undoafter, $undo );
148 }
149
150 if ( $undo > 0 && $undo > $undoafter ) {
151 # Undoing a specific edit overrides section editing; section-editing
152 # doesn't work with undoing.
153 if ( $undoafter ) {
154 $undorev = Revision::newFromId($undo);
155 $oldrev = Revision::newFromId($undoafter);
156 } else {
157 $undorev = Revision::newFromId($undo);
158 $oldrev = $undorev ? $undorev->getPrevious() : null;
159 }
160
161 # Sanity check, make sure it's the right page,
162 # the revisions exist and they were not deleted.
163 # Otherwise, $text will be left as-is.
164 if( !is_null( $undorev ) && !is_null( $oldrev ) &&
165 $undorev->getPage() == $oldrev->getPage() &&
166 $undorev->getPage() == $this->mArticle->getID() &&
167 !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
168 !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
169 $undorev_text = $undorev->getText();
170 $oldrev_text = $oldrev->getText();
171 $currev_text = $text;
172
173 if ( $currev_text != $undorev_text ) {
174 $result = wfMerge( $undorev_text, $oldrev_text, $currev_text, $text );
175 } else {
176 # No use doing a merge if it's just a straight revert.
177 $text = $oldrev_text;
178 $result = true;
179 }
180 if( $result ) {
181 # Inform the user of our success and set an automatic edit summary
182 $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
183 $firstrev = $oldrev->getNext();
184 # If we just undid one rev, use an autosummary
185 if( $firstrev->mId == $undo ) {
186 $this->summary = wfMsgForContent('undo-summary', $undo, $undorev->getUserText());
187 }
188 $this->formtype = 'diff';
189 } else {
190 # Warn the user that something went wrong
191 $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
192 }
193 } else {
194 // Failed basic sanity checks.
195 // Older revisions may have been removed since the link
196 // was created, or we may simply have got bogus input.
197 $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-norev' ) );
198 }
199 } else if( $section != '' ) {
200 if( $section == 'new' ) {
201 $text = $this->getPreloadedText( $preload );
202 } else {
203 $text = $wgParser->getSection( $text, $section, $def_text );
204 }
205 }
206 }
207
208 wfProfileOut( __METHOD__ );
209 return $text;
210 }
211
212 /**
213 * Get the contents of a page from its title and remove includeonly tags
214 *
215 * @param $preload String: the title of the page.
216 * @return string The contents of the page.
217 */
218 protected function getPreloadedText($preload) {
219 if ( $preload === '' )
220 return '';
221 else {
222 $preloadTitle = Title::newFromText( $preload );
223 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
224 $rev=Revision::newFromTitle($preloadTitle);
225 if ( is_object( $rev ) ) {
226 $text = $rev->getText();
227 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
228 // its own mini-parser! -ævar
229 $text = preg_replace( '~</?includeonly>~', '', $text );
230 return $text;
231 } else
232 return '';
233 }
234 }
235 }
236
237 /**
238 * This is the function that extracts metadata from the article body on the first view.
239 * To turn the feature on, set $wgUseMetadataEdit = true ; in LocalSettings
240 * and set $wgMetadataWhitelist to the *full* title of the template whitelist
241 */
242 function extractMetaDataFromArticle () {
243 global $wgUseMetadataEdit , $wgMetadataWhitelist , $wgLang ;
244 $this->mMetaData = '' ;
245 if ( !$wgUseMetadataEdit ) return ;
246 if ( $wgMetadataWhitelist == '' ) return ;
247 $s = '' ;
248 $t = $this->getContent();
249
250 # MISSING : <nowiki> filtering
251
252 # Categories and language links
253 $t = explode ( "\n" , $t ) ;
254 $catlow = strtolower ( $wgLang->getNsText ( NS_CATEGORY ) ) ;
255 $cat = $ll = array() ;
256 foreach ( $t AS $key => $x )
257 {
258 $y = trim ( strtolower ( $x ) ) ;
259 while ( substr ( $y , 0 , 2 ) == '[[' )
260 {
261 $y = explode ( ']]' , trim ( $x ) ) ;
262 $first = array_shift ( $y ) ;
263 $first = explode ( ':' , $first ) ;
264 $ns = array_shift ( $first ) ;
265 $ns = trim ( str_replace ( '[' , '' , $ns ) ) ;
266 if ( strlen ( $ns ) == 2 OR strtolower ( $ns ) == $catlow )
267 {
268 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]' ;
269 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add ;
270 else $ll[] = $add ;
271 $x = implode ( ']]' , $y ) ;
272 $t[$key] = $x ;
273 $y = trim ( strtolower ( $x ) ) ;
274 }
275 }
276 }
277 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n" ;
278 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n" ;
279 $t = implode ( "\n" , $t ) ;
280
281 # Load whitelist
282 $sat = array () ; # stand-alone-templates; must be lowercase
283 $wl_title = Title::newFromText ( $wgMetadataWhitelist ) ;
284 $wl_article = new Article ( $wl_title ) ;
285 $wl = explode ( "\n" , $wl_article->getContent() ) ;
286 foreach ( $wl AS $x )
287 {
288 $isentry = false ;
289 $x = trim ( $x ) ;
290 while ( substr ( $x , 0 , 1 ) == '*' )
291 {
292 $isentry = true ;
293 $x = trim ( substr ( $x , 1 ) ) ;
294 }
295 if ( $isentry )
296 {
297 $sat[] = strtolower ( $x ) ;
298 }
299
300 }
301
302 # Templates, but only some
303 $t = explode ( '{{' , $t ) ;
304 $tl = array () ;
305 foreach ( $t AS $key => $x )
306 {
307 $y = explode ( '}}' , $x , 2 ) ;
308 if ( count ( $y ) == 2 )
309 {
310 $z = $y[0] ;
311 $z = explode ( '|' , $z ) ;
312 $tn = array_shift ( $z ) ;
313 if ( in_array ( strtolower ( $tn ) , $sat ) )
314 {
315 $tl[] = '{{' . $y[0] . '}}' ;
316 $t[$key] = $y[1] ;
317 $y = explode ( '}}' , $y[1] , 2 ) ;
318 }
319 else $t[$key] = '{{' . $x ;
320 }
321 else if ( $key != 0 ) $t[$key] = '{{' . $x ;
322 else $t[$key] = $x ;
323 }
324 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl ) ;
325 $t = implode ( '' , $t ) ;
326
327 $t = str_replace ( "\n\n\n" , "\n" , $t ) ;
328 $this->mArticle->mContent = $t ;
329 $this->mMetaData = $s ;
330 }
331
332 protected function wasDeletedSinceLastEdit() {
333 /* Note that we rely on the logging table, which hasn't been always there,
334 * but that doesn't matter, because this only applies to brand new
335 * deletes.
336 */
337 if ( $this->deletedSinceEdit )
338 return true;
339 if ( $this->mTitle->isDeleted() ) {
340 $this->lastDelete = $this->getLastDelete();
341 if ( !is_null($this->lastDelete) ) {
342 $deletetime = $this->lastDelete->log_timestamp;
343 if ( ($deletetime - $this->starttime) > 0 ) {
344 $this->deletedSinceEdit = true;
345 }
346 }
347 }
348 return $this->deletedSinceEdit;
349 }
350
351 function submit() {
352 $this->edit();
353 }
354
355 /**
356 * This is the function that gets called for "action=edit". It
357 * sets up various member variables, then passes execution to
358 * another function, usually showEditForm()
359 *
360 * The edit form is self-submitting, so that when things like
361 * preview and edit conflicts occur, we get the same form back
362 * with the extra stuff added. Only when the final submission
363 * is made and all is well do we actually save and redirect to
364 * the newly-edited page.
365 */
366 function edit() {
367 global $wgOut, $wgUser, $wgRequest;
368
369 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) )
370 return;
371
372 wfProfileIn( __METHOD__ );
373 wfDebug( __METHOD__.": enter\n" );
374
375 // this is not an article
376 $wgOut->setArticleFlag( false );
377
378 $this->importFormData( $wgRequest );
379 $this->firsttime = false;
380
381 if( $this->live ) {
382 $this->livePreview();
383 wfProfileOut( __METHOD__ );
384 return;
385 }
386
387 if( wfReadOnly() ) {
388 if( $this->save ){
389 // Force preview
390 $this->save = false;
391 $this->preview = true;
392 } elseif( $this->preview || $this->diff ){
393 // A warning will be displayed instead
394 } else {
395 $this->readOnlyPage( $this->getContent() );
396 wfProfileOut( __METHOD__ );
397 return;
398 }
399 }
400
401 $wgOut->addScriptFile( 'edit.js' );
402
403 $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
404
405 if( !$this->mTitle->exists() ) {
406 $permErrors = array_merge( $permErrors,
407 wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
408 }
409
410 # Ignore some permissions errors.
411 $remove = array();
412 foreach( $permErrors as $error ) {
413 if ( ( $this->preview || $this->diff ) &&
414 ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext'))
415 {
416 // Don't worry about blocks when previewing/diffing
417 $remove[] = $error;
418 }
419 }
420 $permErrors = wfArrayDiff2( $permErrors, $remove );
421
422 if ( $permErrors ) {
423 wfDebug( __METHOD__.": User can't edit\n" );
424 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
425 wfProfileOut( __METHOD__ );
426 return;
427 } else {
428 if ( $this->save ) {
429 $this->formtype = 'save';
430 } else if( $this->preview ) {
431 $this->formtype = 'preview';
432 } else if ( $this->diff ) {
433 $this->formtype = 'diff';
434 } else { # First time through
435 $this->firsttime = true;
436 if( $this->previewOnOpen() ) {
437 $this->formtype = 'preview';
438 } else {
439 $this->extractMetaDataFromArticle () ;
440 $this->formtype = 'initial';
441 }
442 }
443 }
444
445 wfProfileIn( __METHOD__."-business-end" );
446
447 $this->isConflict = false;
448 // css / js subpages of user pages get a special treatment
449 $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
450 $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
451
452 # Show applicable editing introductions
453 if( $this->formtype == 'initial' || $this->firsttime )
454 $this->showIntro();
455
456 if( $this->mTitle->isTalkPage() ) {
457 $wgOut->addWikiMsg( 'talkpagetext' );
458 }
459
460 # Optional notices on a per-namespace and per-page basis
461 $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace();
462 $editnotice_page = $editnotice_ns.'-'.$this->mTitle->getDBkey();
463 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
464 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
465 }
466 if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
467 $parts = explode( '/', $this->mTitle->getDBkey() );
468 $editnotice_base = $editnotice_ns;
469 while ( count( $parts ) > 0 ) {
470 $editnotice_base .= '-'.array_shift( $parts );
471 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
472 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
473 }
474 }
475 } else if ( !wfEmptyMsg( $editnotice_page, wfMsgForContent( $editnotice_page ) ) ) {
476 $wgOut->addWikiText( wfMsgForContent( $editnotice_page ) );
477 }
478
479 # Attempt submission here. This will check for edit conflicts,
480 # and redundantly check for locked database, blocked IPs, etc.
481 # that edit() already checked just in case someone tries to sneak
482 # in the back door with a hand-edited submission URL.
483
484 if ( 'save' == $this->formtype ) {
485 if ( !$this->attemptSave() ) {
486 wfProfileOut( __METHOD__."-business-end" );
487 wfProfileOut( __METHOD__ );
488 return;
489 }
490 }
491
492 # First time through: get contents, set time for conflict
493 # checking, etc.
494 if ( 'initial' == $this->formtype || $this->firsttime ) {
495 if ($this->initialiseForm() === false) {
496 $this->noSuchSectionPage();
497 wfProfileOut( __METHOD__."-business-end" );
498 wfProfileOut( __METHOD__ );
499 return;
500 }
501 if( !$this->mTitle->getArticleId() )
502 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
503 }
504
505 $this->showEditForm();
506 wfProfileOut( __METHOD__."-business-end" );
507 wfProfileOut( __METHOD__ );
508 }
509
510 /**
511 * Show a read-only error
512 * Parameters are the same as OutputPage:readOnlyPage()
513 * Redirect to the article page if redlink=1
514 */
515 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
516 global $wgRequest, $wgOut;
517 if ( $wgRequest->getBool( 'redlink' ) ) {
518 // The edit page was reached via a red link.
519 // Redirect to the article page and let them click the edit tab if
520 // they really want a permission error.
521 $wgOut->redirect( $this->mTitle->getFullUrl() );
522 } else {
523 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
524 }
525 }
526
527 /**
528 * Should we show a preview when the edit form is first shown?
529 *
530 * @return bool
531 */
532 protected function previewOnOpen() {
533 global $wgRequest, $wgUser;
534 if( $wgRequest->getVal( 'preview' ) == 'yes' ) {
535 // Explicit override from request
536 return true;
537 } elseif( $wgRequest->getVal( 'preview' ) == 'no' ) {
538 // Explicit override from request
539 return false;
540 } elseif( $this->section == 'new' ) {
541 // Nothing *to* preview for new sections
542 return false;
543 } elseif( ( $wgRequest->getVal( 'preload' ) !== '' || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
544 // Standard preference behaviour
545 return true;
546 } elseif( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
547 // Categories are special
548 return true;
549 } else {
550 return false;
551 }
552 }
553
554 /**
555 * @todo document
556 * @param $request
557 */
558 function importFormData( &$request ) {
559 global $wgLang, $wgUser;
560 $fname = 'EditPage::importFormData';
561 wfProfileIn( $fname );
562
563 # Section edit can come from either the form or a link
564 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
565
566 if( $request->wasPosted() ) {
567 # These fields need to be checked for encoding.
568 # Also remove trailing whitespace, but don't remove _initial_
569 # whitespace from the text boxes. This may be significant formatting.
570 $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
571 $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
572 $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
573 # Truncate for whole multibyte characters. +5 bytes for ellipsis
574 $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250 );
575
576 # Remove extra headings from summaries and new sections.
577 $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
578
579 $this->edittime = $request->getVal( 'wpEdittime' );
580 $this->starttime = $request->getVal( 'wpStarttime' );
581
582 $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
583
584 if( is_null( $this->edittime ) ) {
585 # If the form is incomplete, force to preview.
586 wfDebug( "$fname: Form data appears to be incomplete\n" );
587 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
588 $this->preview = true;
589 } else {
590 /* Fallback for live preview */
591 $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' );
592 $this->diff = $request->getCheck( 'wpDiff' );
593
594 // Remember whether a save was requested, so we can indicate
595 // if we forced preview due to session failure.
596 $this->mTriedSave = !$this->preview;
597
598 if ( $this->tokenOk( $request ) ) {
599 # Some browsers will not report any submit button
600 # if the user hits enter in the comment box.
601 # The unmarked state will be assumed to be a save,
602 # if the form seems otherwise complete.
603 wfDebug( "$fname: Passed token check.\n" );
604 } else if ( $this->diff ) {
605 # Failed token check, but only requested "Show Changes".
606 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
607 } else {
608 # Page might be a hack attempt posted from
609 # an external site. Preview instead of saving.
610 wfDebug( "$fname: Failed token check; forcing preview\n" );
611 $this->preview = true;
612 }
613 }
614 $this->save = !$this->preview && !$this->diff;
615 if( !preg_match( '/^\d{14}$/', $this->edittime )) {
616 $this->edittime = null;
617 }
618
619 if( !preg_match( '/^\d{14}$/', $this->starttime )) {
620 $this->starttime = null;
621 }
622
623 $this->recreate = $request->getCheck( 'wpRecreate' );
624
625 $this->minoredit = $request->getCheck( 'wpMinoredit' );
626 $this->watchthis = $request->getCheck( 'wpWatchthis' );
627
628 # Don't force edit summaries when a user is editing their own user or talk page
629 if( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) && $this->mTitle->getText() == $wgUser->getName() ) {
630 $this->allowBlankSummary = true;
631 } else {
632 $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' );
633 }
634
635 $this->autoSumm = $request->getText( 'wpAutoSummary' );
636 } else {
637 # Not a posted form? Start with nothing.
638 wfDebug( "$fname: Not a posted form.\n" );
639 $this->textbox1 = '';
640 $this->textbox2 = '';
641 $this->mMetaData = '';
642 $this->summary = '';
643 $this->edittime = '';
644 $this->starttime = wfTimestampNow();
645 $this->edit = false;
646 $this->preview = false;
647 $this->save = false;
648 $this->diff = false;
649 $this->minoredit = false;
650 $this->watchthis = false;
651 $this->recreate = false;
652
653 if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
654 $this->summary = $request->getVal( 'preloadtitle' );
655 }
656 }
657
658 $this->oldid = $request->getInt( 'oldid' );
659
660 $this->live = $request->getCheck( 'live' );
661 $this->editintro = $request->getText( 'editintro' );
662
663 wfProfileOut( $fname );
664 }
665
666 /**
667 * Make sure the form isn't faking a user's credentials.
668 *
669 * @param $request WebRequest
670 * @return bool
671 * @private
672 */
673 function tokenOk( &$request ) {
674 global $wgUser;
675 $token = $request->getVal( 'wpEditToken' );
676 $this->mTokenOk = $wgUser->matchEditToken( $token );
677 $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
678 return $this->mTokenOk;
679 }
680
681 /**
682 * Show all applicable editing introductions
683 */
684 protected function showIntro() {
685 global $wgOut, $wgUser;
686 if( $this->suppressIntro )
687 return;
688
689 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
690 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
691 $parts = explode( '/', $this->mTitle->getText(), 2 );
692 $username = $parts[0];
693 $id = User::idFromName( $username );
694 $ip = User::isIP( $username );
695
696 if ( $id == 0 && !$ip ) {
697 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
698 array( 'userpage-userdoesnotexist', $username ) );
699 }
700 }
701
702 if( !$this->mTitle->exists() && !$this->showCustomIntro() ) {
703 if( $wgUser->isLoggedIn() ) {
704 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
705 } else {
706 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
707 }
708 $this->showDeletionLog( $wgOut );
709 }
710 }
711
712 /**
713 * Attempt to show a custom editing introduction, if supplied
714 *
715 * @return bool
716 */
717 protected function showCustomIntro() {
718 if( $this->editintro ) {
719 $title = Title::newFromText( $this->editintro );
720 if( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
721 global $wgOut;
722 $revision = Revision::newFromTitle( $title );
723 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
724 return true;
725 } else {
726 return false;
727 }
728 } else {
729 return false;
730 }
731 }
732
733 /**
734 * Attempt submission (no UI)
735 * @return one of the constants describing the result
736 */
737 function internalAttemptSave( &$result, $bot = false ) {
738 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
739 global $wgMaxArticleSize;
740
741 $fname = 'EditPage::attemptSave';
742 wfProfileIn( $fname );
743 wfProfileIn( "$fname-checks" );
744
745 if( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
746 {
747 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving" );
748 return self::AS_HOOK_ERROR;
749 }
750
751 # Check image redirect
752 if ( $this->mTitle->getNamespace() == NS_IMAGE &&
753 Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
754 !$wgUser->isAllowed( 'upload' ) ) {
755 if( $wgUser->isAnon() ) {
756 return self::AS_IMAGE_REDIRECT_ANON;
757 } else {
758 return self::AS_IMAGE_REDIRECT_LOGGED;
759 }
760 }
761
762 # Reintegrate metadata
763 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
764 $this->mMetaData = '' ;
765
766 # Check for spam
767 $match = self::matchSpamRegex( $this->summary );
768 if( $match === false ) {
769 $match = self::matchSpamRegex( $this->textbox1 );
770 }
771 if( $match !== false ) {
772 $result['spam'] = $match;
773 $ip = wfGetIP();
774 $pdbk = $this->mTitle->getPrefixedDBkey();
775 $match = str_replace( "\n", '', $match );
776 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
777 wfProfileOut( "$fname-checks" );
778 wfProfileOut( $fname );
779 return self::AS_SPAM_ERROR;
780 }
781 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
782 # Error messages or other handling should be performed by the filter function
783 wfProfileOut( "$fname-checks" );
784 wfProfileOut( $fname );
785 return self::AS_FILTERING;
786 }
787 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
788 # Error messages etc. could be handled within the hook...
789 wfProfileOut( "$fname-checks" );
790 wfProfileOut( $fname );
791 return self::AS_HOOK_ERROR;
792 } elseif( $this->hookError != '' ) {
793 # ...or the hook could be expecting us to produce an error
794 wfProfileOut( "$fname-checks" );
795 wfProfileOut( $fname );
796 return self::AS_HOOK_ERROR_EXPECTED;
797 }
798 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
799 # Check block state against master, thus 'false'.
800 wfProfileOut( "$fname-checks" );
801 wfProfileOut( $fname );
802 return self::AS_BLOCKED_PAGE_FOR_USER;
803 }
804 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
805 if ( $this->kblength > $wgMaxArticleSize ) {
806 // Error will be displayed by showEditForm()
807 $this->tooBig = true;
808 wfProfileOut( "$fname-checks" );
809 wfProfileOut( $fname );
810 return self::AS_CONTENT_TOO_BIG;
811 }
812
813 if ( !$wgUser->isAllowed('edit') ) {
814 if ( $wgUser->isAnon() ) {
815 wfProfileOut( "$fname-checks" );
816 wfProfileOut( $fname );
817 return self::AS_READ_ONLY_PAGE_ANON;
818 }
819 else {
820 wfProfileOut( "$fname-checks" );
821 wfProfileOut( $fname );
822 return self::AS_READ_ONLY_PAGE_LOGGED;
823 }
824 }
825
826 if ( wfReadOnly() ) {
827 wfProfileOut( "$fname-checks" );
828 wfProfileOut( $fname );
829 return self::AS_READ_ONLY_PAGE;
830 }
831 if ( $wgUser->pingLimiter() ) {
832 wfProfileOut( "$fname-checks" );
833 wfProfileOut( $fname );
834 return self::AS_RATE_LIMITED;
835 }
836
837 # If the article has been deleted while editing, don't save it without
838 # confirmation
839 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
840 wfProfileOut( "$fname-checks" );
841 wfProfileOut( $fname );
842 return self::AS_ARTICLE_WAS_DELETED;
843 }
844
845 wfProfileOut( "$fname-checks" );
846
847 # If article is new, insert it.
848 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
849 if ( 0 == $aid ) {
850
851 // Late check for create permission, just in case *PARANOIA*
852 if ( !$this->mTitle->userCan( 'create' ) ) {
853 wfDebug( "$fname: no create permission\n" );
854 wfProfileOut( $fname );
855 return self::AS_NO_CREATE_PERMISSION;
856 }
857
858 # Don't save a new article if it's blank.
859 if ( '' == $this->textbox1 ) {
860 wfProfileOut( $fname );
861 return self::AS_BLANK_ARTICLE;
862 }
863
864 // Run post-section-merge edit filter
865 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
866 # Error messages etc. could be handled within the hook...
867 wfProfileOut( $fname );
868 return self::AS_HOOK_ERROR;
869 }
870
871 $isComment = ( $this->section == 'new' );
872
873 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
874 $this->minoredit, $this->watchthis, false, $isComment, $bot);
875
876 wfProfileOut( $fname );
877 return self::AS_SUCCESS_NEW_ARTICLE;
878 }
879
880 # Article exists. Check for edit conflict.
881
882 $this->mArticle->clear(); # Force reload of dates, etc.
883 $this->mArticle->forUpdate( true ); # Lock the article
884
885 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
886
887 if( $this->mArticle->getTimestamp() != $this->edittime ) {
888 $this->isConflict = true;
889 if( $this->section == 'new' ) {
890 if( $this->mArticle->getUserText() == $wgUser->getName() &&
891 $this->mArticle->getComment() == $this->summary ) {
892 // Probably a duplicate submission of a new comment.
893 // This can happen when squid resends a request after
894 // a timeout but the first one actually went through.
895 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
896 } else {
897 // New comment; suppress conflict.
898 $this->isConflict = false;
899 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
900 }
901 }
902 }
903 $userid = $wgUser->getId();
904
905 if ( $this->isConflict) {
906 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
907 $this->mArticle->getTimestamp() . "')\n" );
908 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime);
909 }
910 else {
911 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
912 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary);
913 }
914 if( is_null( $text ) ) {
915 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
916 $this->isConflict = true;
917 $text = $this->textbox1;
918 }
919
920 # Suppress edit conflict with self, except for section edits where merging is required.
921 if ( ( $this->section == '' ) && ( 0 != $userid ) && ( $this->mArticle->getUser() == $userid ) ) {
922 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
923 $this->isConflict = false;
924 } else {
925 # switch from section editing to normal editing in edit conflict
926 if($this->isConflict) {
927 # Attempt merge
928 if( $this->mergeChangesInto( $text ) ){
929 // Successful merge! Maybe we should tell the user the good news?
930 $this->isConflict = false;
931 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
932 } else {
933 $this->section = '';
934 $this->textbox1 = $text;
935 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
936 }
937 }
938 }
939
940 if ( $this->isConflict ) {
941 wfProfileOut( $fname );
942 return self::AS_CONFLICT_DETECTED;
943 }
944
945 $oldtext = $this->mArticle->getContent();
946
947 // Run post-section-merge edit filter
948 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
949 # Error messages etc. could be handled within the hook...
950 wfProfileOut( $fname );
951 return self::AS_HOOK_ERROR;
952 }
953
954 # Handle the user preference to force summaries here, but not for null edits
955 if( $this->section != 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary') &&
956 0 != strcmp($oldtext, $text) &&
957 !is_object( Title::newFromRedirect( $text ) ) # check if it's not a redirect
958 ) {
959
960 if( md5( $this->summary ) == $this->autoSumm ) {
961 $this->missingSummary = true;
962 wfProfileOut( $fname );
963 return self::AS_SUMMARY_NEEDED;
964 }
965 }
966
967 # And a similar thing for new sections
968 if( $this->section == 'new' && !$this->allowBlankSummary && $wgUser->getOption( 'forceeditsummary' ) ) {
969 if (trim($this->summary) == '') {
970 $this->missingSummary = true;
971 wfProfileOut( $fname );
972 return self::AS_SUMMARY_NEEDED;
973 }
974 }
975
976 # All's well
977 wfProfileIn( "$fname-sectionanchor" );
978 $sectionanchor = '';
979 if( $this->section == 'new' ) {
980 if ( $this->textbox1 == '' ) {
981 $this->missingComment = true;
982 return self::AS_TEXTBOX_EMPTY;
983 }
984 if( $this->summary != '' ) {
985 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
986 # This is a new section, so create a link to the new section
987 # in the revision summary.
988 $cleanSummary = $wgParser->stripSectionName( $this->summary );
989 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
990 }
991 } elseif( $this->section != '' ) {
992 # Try to get a section anchor from the section source, redirect to edited section if header found
993 # XXX: might be better to integrate this into Article::replaceSection
994 # for duplicate heading checking and maybe parsing
995 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
996 # we can't deal with anchors, includes, html etc in the header for now,
997 # headline would need to be parsed to improve this
998 if($hasmatch and strlen($matches[2]) > 0) {
999 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
1000 }
1001 }
1002 wfProfileOut( "$fname-sectionanchor" );
1003
1004 // Save errors may fall down to the edit form, but we've now
1005 // merged the section into full text. Clear the section field
1006 // so that later submission of conflict forms won't try to
1007 // replace that into a duplicated mess.
1008 $this->textbox1 = $text;
1009 $this->section = '';
1010
1011 // Check for length errors again now that the section is merged in
1012 $this->kblength = (int)(strlen( $text ) / 1024);
1013 if ( $this->kblength > $wgMaxArticleSize ) {
1014 $this->tooBig = true;
1015 wfProfileOut( $fname );
1016 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
1017 }
1018
1019 # update the article here
1020 if( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
1021 $this->watchthis, $bot, $sectionanchor ) ) {
1022 wfProfileOut( $fname );
1023 return self::AS_SUCCESS_UPDATE;
1024 } else {
1025 $this->isConflict = true;
1026 }
1027 wfProfileOut( $fname );
1028 return self::AS_END;
1029 }
1030
1031 /**
1032 * Check given input text against $wgSpamRegex, and return the text of the first match.
1033 * @return mixed -- matching string or false
1034 */
1035 public static function matchSpamRegex( $text ) {
1036 global $wgSpamRegex;
1037 if( $wgSpamRegex ) {
1038 // For back compatibility, $wgSpamRegex may be a single string or an array of regexes.
1039 $regexes = (array)$wgSpamRegex;
1040 foreach( $regexes as $regex ) {
1041 $matches = array();
1042 if ( preg_match( $regex, $text, $matches ) ) {
1043 return $matches[0];
1044 }
1045 }
1046 }
1047 return false;
1048 }
1049
1050 /**
1051 * Initialise form fields in the object
1052 * Called on the first invocation, e.g. when a user clicks an edit link
1053 */
1054 function initialiseForm() {
1055 $this->edittime = $this->mArticle->getTimestamp();
1056 $this->textbox1 = $this->getContent(false);
1057 if ($this->textbox1 === false) return false;
1058
1059 if ( !$this->mArticle->exists() && $this->mTitle->getNamespace() == NS_MEDIAWIKI )
1060 $this->textbox1 = wfMsgWeirdKey( $this->mTitle->getText() );
1061 wfProxyCheck();
1062 return true;
1063 }
1064
1065 function setHeaders() {
1066 global $wgOut, $wgTitle;
1067 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1068 if ( $this->formtype == 'preview' ) {
1069 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
1070 }
1071 if ( $this->isConflict ) {
1072 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
1073 } elseif( $this->section != '' ) {
1074 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
1075 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
1076 } else {
1077 # Use the title defined by DISPLAYTITLE magic word when present
1078 if( isset($this->mParserOutput)
1079 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
1080 $title = $dt;
1081 } else {
1082 $title = $wgTitle->getPrefixedText();
1083 }
1084 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
1085 }
1086 }
1087
1088 /**
1089 * Send the edit form and related headers to $wgOut
1090 * @param $formCallback Optional callable that takes an OutputPage
1091 * parameter; will be called during form output
1092 * near the top, for captchas and the like.
1093 */
1094 function showEditForm( $formCallback=null ) {
1095 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle;
1096
1097 # If $wgTitle is null, that means we're in API mode.
1098 # Some hook probably called this function without checking
1099 # for is_null($wgTitle) first. Bail out right here so we don't
1100 # do lots of work just to discard it right after.
1101 if(is_null($wgTitle))
1102 return;
1103
1104 $fname = 'EditPage::showEditForm';
1105 wfProfileIn( $fname );
1106
1107 $sk = $wgUser->getSkin();
1108
1109 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
1110
1111 #need to parse the preview early so that we know which templates are used,
1112 #otherwise users with "show preview after edit box" will get a blank list
1113 #we parse this near the beginning so that setHeaders can do the title
1114 #setting work instead of leaving it in getPreviewText
1115 $previewOutput = '';
1116 if ( $this->formtype == 'preview' ) {
1117 $previewOutput = $this->getPreviewText();
1118 }
1119
1120 $this->setHeaders();
1121
1122 # Enabled article-related sidebar, toplinks, etc.
1123 $wgOut->setArticleRelated( true );
1124
1125 if ( $this->isConflict ) {
1126 $wgOut->addWikiMsg( 'explainconflict' );
1127
1128 $this->textbox2 = $this->textbox1;
1129 $this->textbox1 = $this->getContent();
1130 $this->edittime = $this->mArticle->getTimestamp();
1131 } else {
1132 if( $this->section != '' && $this->section != 'new' ) {
1133 $matches = array();
1134 if( !$this->summary && !$this->preview && !$this->diff ) {
1135 preg_match( "/^(=+)(.+)\\1/mi",
1136 $this->textbox1,
1137 $matches );
1138 if( !empty( $matches[2] ) ) {
1139 global $wgParser;
1140 $this->summary = "/* " .
1141 $wgParser->stripSectionName(trim($matches[2])) .
1142 " */ ";
1143 }
1144 }
1145 }
1146
1147 if ( $this->missingComment ) {
1148 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
1149 }
1150
1151 if( $this->missingSummary && $this->section != 'new' ) {
1152 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
1153 }
1154
1155 if( $this->missingSummary && $this->section == 'new' ) {
1156 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
1157 }
1158
1159 if( $this->hookError !== '' ) {
1160 $wgOut->addWikiText( $this->hookError );
1161 }
1162
1163 if ( !$this->checkUnicodeCompliantBrowser() ) {
1164 $wgOut->addWikiMsg( 'nonunicodebrowser' );
1165 }
1166
1167 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
1168 // Let sysop know that this will make private content public if saved
1169 if( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
1170 $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
1171 } else if( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
1172 $wgOut->addWikiMsg( 'rev-deleted-text-view' );
1173 }
1174 // Let user know they are editing an old version
1175 if( !$this->mArticle->mRevision->isCurrent() ) {
1176 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
1177 $wgOut->addWikiMsg( 'editingold' );
1178 }
1179 }
1180 }
1181
1182 if( wfReadOnly() ) {
1183 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
1184 } elseif( $wgUser->isAnon() && $this->formtype != 'preview' ) {
1185 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
1186 } else {
1187 if( $this->isCssJsSubpage && $this->formtype != 'preview' ) {
1188 # Check the skin exists
1189 if( $this->isValidCssJsSubpage ) {
1190 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
1191 } else {
1192 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
1193 }
1194 }
1195 }
1196
1197 if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1198 # Show a warning if editing an interface message
1199 $wgOut->addWikiMsg( 'editinginterface' );
1200 } elseif( $this->mTitle->isProtected( 'edit' ) ) {
1201 # Is the title semi-protected?
1202 if( $this->mTitle->isSemiProtected() ) {
1203 $noticeMsg = 'semiprotectedpagewarning';
1204 } else {
1205 # Then it must be protected based on static groups (regular)
1206 $noticeMsg = 'protectedpagewarning';
1207 }
1208 $wgOut->addHTML( "<div id='mw-edit-$noticeMsg'>\n" );
1209 $wgOut->addWikiMsg( $noticeMsg );
1210 $wgOut->addHTML( "</div>\n" );
1211 }
1212 if ( $this->mTitle->isCascadeProtected() ) {
1213 # Is this page under cascading protection from some source pages?
1214 list($cascadeSources, /* $restrictions */) = $this->mTitle->getCascadeProtectionSources();
1215 $notice = "$1\n";
1216 if ( count($cascadeSources) > 0 ) {
1217 # Explain, and list the titles responsible
1218 foreach( $cascadeSources as $page ) {
1219 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
1220 }
1221 }
1222 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', count($cascadeSources) ) );
1223 }
1224 if( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) != array() ){
1225 $wgOut->addWikiMsg( 'titleprotectedwarning' );
1226 }
1227
1228 if ( $this->kblength === false ) {
1229 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
1230 }
1231 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
1232 $wgOut->addHTML( "<div id='mw-edit-longpageerror'>\n" );
1233 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
1234 $wgOut->addHTML( "</div>\n" );
1235 } elseif( $this->kblength > 29 ) {
1236 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
1237 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
1238 $wgOut->addHTML( "</div>\n" );
1239 }
1240
1241 $q = 'action='.$this->action;
1242 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
1243 $action = $wgTitle->escapeLocalURL( $q );
1244
1245 $colonSep = wfMsg( 'colon-separator' );
1246 $summary = wfMsg( 'summary' ) . $colonSep;
1247 $subject = wfMsg( 'subject' ) . $colonSep;
1248
1249 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
1250 wfMsgExt('cancel', array('parseinline')) );
1251 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
1252 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
1253 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
1254 htmlspecialchars( wfMsg( 'newwindow' ) );
1255
1256 global $wgRightsText;
1257 if ( $wgRightsText ) {
1258 $copywarnMsg = array( 'copyrightwarning',
1259 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
1260 $wgRightsText );
1261 } else {
1262 $copywarnMsg = array( 'copyrightwarning2',
1263 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
1264 }
1265
1266 if( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
1267 # prepare toolbar for edit buttons
1268 $toolbar = EditPage::getEditToolbar();
1269 } else {
1270 $toolbar = '';
1271 }
1272
1273 // activate checkboxes if user wants them to be always active
1274 if( !$this->preview && !$this->diff ) {
1275 # Sort out the "watch" checkbox
1276 if( $wgUser->getOption( 'watchdefault' ) ) {
1277 # Watch all edits
1278 $this->watchthis = true;
1279 } elseif( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
1280 # Watch creations
1281 $this->watchthis = true;
1282 } elseif( $this->mTitle->userIsWatching() ) {
1283 # Already watched
1284 $this->watchthis = true;
1285 }
1286
1287 if( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
1288 }
1289
1290 $wgOut->addHTML( $this->editFormPageTop );
1291
1292 if ( $wgUser->getOption( 'previewontop' ) ) {
1293 $this->displayPreviewArea( $previewOutput, true );
1294 }
1295
1296
1297 $wgOut->addHTML( $this->editFormTextTop );
1298
1299 # if this is a comment, show a subject line at the top, which is also the edit summary.
1300 # Otherwise, show a summary field at the bottom
1301 $summarytext = htmlspecialchars( $wgContLang->recodeForEdit( $this->summary ) ); # FIXME
1302
1303 # If a blank edit summary was previously provided, and the appropriate
1304 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
1305 # user being bounced back more than once in the event that a summary
1306 # is not required.
1307 #####
1308 # For a bit more sophisticated detection of blank summaries, hash the
1309 # automatic one and pass that in the hidden field wpAutoSummary.
1310 $summaryhiddens = '';
1311 if( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
1312 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
1313 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
1314 if( $this->section == 'new' ) {
1315 $commentsubject="<span id='wpSummaryLabel'><label for='wpSummary'>{$subject}</label></span>\n<input tabindex='1' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' />{$summaryhiddens}<br />";
1316 $editsummary = "<div class='editOptions'>\n";
1317 global $wgParser;
1318 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
1319 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('subject-preview').$colonSep.$sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
1320 $summarypreview = '';
1321 } else {
1322 $commentsubject = '';
1323 $editsummary="<div class='editOptions'>\n<span id='wpSummaryLabel'><label for='wpSummary'>{$summary}</label></span>\n<input tabindex='2' type='text' value=\"$summarytext\" name='wpSummary' id='wpSummary' maxlength='200' size='60' />{$summaryhiddens}<br />";
1324 $summarypreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">".wfMsg('summary-preview').$colonSep.$sk->commentBlock( $this->summary, $this->mTitle )."</div>\n" : '';
1325 $subjectpreview = '';
1326 }
1327
1328 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
1329 if( !$this->preview && !$this->diff ) {
1330 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
1331 }
1332 $templates = $this->getTemplates();
1333 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
1334
1335 $hiddencats = $this->mArticle->getHiddenCategories();
1336 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
1337
1338 global $wgUseMetadataEdit ;
1339 if ( $wgUseMetadataEdit ) {
1340 $metadata = $this->mMetaData ;
1341 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
1342 $top = wfMsgWikiHtml( 'metadata_help' );
1343 /* ToDo: Replace with clean code */
1344 $ew = $wgUser->getOption( 'editwidth' );
1345 if ( $ew ) $ew = " style=\"width:100%\"";
1346 else $ew = '';
1347 /* /ToDo */
1348 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
1349 }
1350 else $metadata = "" ;
1351
1352 $recreate = '';
1353 if ($this->wasDeletedSinceLastEdit()) {
1354 if ( 'save' != $this->formtype ) {
1355 $wgOut->addWikiMsg('deletedwhileediting');
1356 } else {
1357 // Hide the toolbar and edit area, use can click preview to get it back
1358 // Add an confirmation checkbox and explanation.
1359 $toolbar = '';
1360 $recreate = $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ));
1361 $recreate .=
1362 "<br /><input tabindex='1' type='checkbox' value='1' name='wpRecreate' id='wpRecreate' />".
1363 "<label for='wpRecreate' title='".wfMsg('tooltip-recreate')."'>". wfMsg('recreate')."</label>";
1364 }
1365 }
1366
1367 $tabindex = 2;
1368
1369 $checkboxes = self::getCheckboxes( $tabindex, $sk,
1370 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
1371
1372 $checkboxhtml = implode( $checkboxes, "\n" );
1373
1374 $buttons = $this->getEditButtons( $tabindex );
1375 $buttonshtml = implode( $buttons, "\n" );
1376
1377 $safemodehtml = $this->checkUnicodeCompliantBrowser()
1378 ? '' : Xml::hidden( 'safemode', '1' );
1379
1380 $wgOut->addHTML( <<<END
1381 {$toolbar}
1382 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
1383 END
1384 );
1385
1386 if( is_callable( $formCallback ) ) {
1387 call_user_func_array( $formCallback, array( &$wgOut ) );
1388 }
1389
1390 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
1391
1392 // Put these up at the top to ensure they aren't lost on early form submission
1393 $this->showFormBeforeText();
1394
1395 $wgOut->addHTML( <<<END
1396 {$recreate}
1397 {$commentsubject}
1398 {$subjectpreview}
1399 {$this->editFormTextBeforeContent}
1400 END
1401 );
1402 $this->showTextbox1();
1403
1404 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
1405 $wgOut->addHTML( <<<END
1406 {$this->editFormTextAfterWarn}
1407 {$metadata}
1408 {$editsummary}
1409 {$summarypreview}
1410 {$checkboxhtml}
1411 {$safemodehtml}
1412 END
1413 );
1414
1415 $wgOut->addHTML(
1416 "<div class='editButtons'>
1417 {$buttonshtml}
1418 <span class='editHelp'>{$cancel} | {$edithelp}</span>
1419 </div><!-- editButtons -->
1420 </div><!-- editOptions -->");
1421
1422 /**
1423 * To make it harder for someone to slip a user a page
1424 * which submits an edit form to the wiki without their
1425 * knowledge, a random token is associated with the login
1426 * session. If it's not passed back with the submission,
1427 * we won't save the page, or render user JavaScript and
1428 * CSS previews.
1429 *
1430 * For anon editors, who may not have a session, we just
1431 * include the constant suffix to prevent editing from
1432 * broken text-mangling proxies.
1433 */
1434 $token = htmlspecialchars( $wgUser->editToken() );
1435 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
1436
1437 $this->showEditTools();
1438
1439 $wgOut->addHTML( <<<END
1440 {$this->editFormTextAfterTools}
1441 <div class='templatesUsed'>
1442 {$formattedtemplates}
1443 </div>
1444 <div class='hiddencats'>
1445 {$formattedhiddencats}
1446 </div>
1447 END
1448 );
1449
1450 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
1451 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
1452
1453 $de = new DifferenceEngine( $this->mTitle );
1454 $de->setText( $this->textbox2, $this->textbox1 );
1455 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
1456
1457 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
1458 $this->showTextbox2();
1459 }
1460 $wgOut->addHTML( $this->editFormTextBottom );
1461 $wgOut->addHTML( "</form>\n" );
1462 if ( !$wgUser->getOption( 'previewontop' ) ) {
1463 $this->displayPreviewArea( $previewOutput, false );
1464 }
1465
1466 wfProfileOut( $fname );
1467 }
1468
1469 protected function showFormBeforeText() {
1470 global $wgOut;
1471 $wgOut->addHTML( "
1472 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
1473 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
1474 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
1475 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
1476 }
1477
1478 protected function showTextbox1() {
1479 $attribs = array( 'tabindex' => 1 );
1480
1481 if( $this->wasDeletedSinceLastEdit() )
1482 $attribs['type'] = 'hidden';
1483
1484 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
1485 }
1486
1487 protected function showTextbox2() {
1488 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
1489 }
1490
1491 protected function showTextbox( $content, $name, $attribs = array() ) {
1492 global $wgOut, $wgUser;
1493
1494 $wikitext = $this->safeUnicodeOutput( $content );
1495 if( $wikitext !== '' ) {
1496 // Ensure there's a newline at the end, otherwise adding lines
1497 // is awkward.
1498 // But don't add a newline if the ext is empty, or Firefox in XHTML
1499 // mode will show an extra newline. A bit annoying.
1500 $wikitext .= "\n";
1501 }
1502
1503 $attribs['accesskey'] = ',';
1504 $attribs['id'] = $name;
1505
1506 if( $wgUser->getOption( 'editwidth' ) )
1507 $attribs['style'] = 'width: 100%';
1508
1509 $wgOut->addHTML( Xml::textarea(
1510 $name,
1511 $wikitext,
1512 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
1513 $attribs ) );
1514 }
1515
1516 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
1517 global $wgOut;
1518 $classes = array();
1519 if( $isOnTop )
1520 $classes[] = 'ontop';
1521
1522 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
1523
1524 if( $this->formtype != 'preview' )
1525 $attribs['style'] = 'display: none;';
1526
1527 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
1528
1529 if ( $this->formtype == 'preview' ) {
1530 $this->showPreview( $previewOutput );
1531 }
1532
1533 $wgOut->addHTML( '</div>' );
1534
1535 if ( $this->formtype == 'diff') {
1536 $this->showDiff();
1537 }
1538 }
1539
1540 /**
1541 * Append preview output to $wgOut.
1542 * Includes category rendering if this is a category page.
1543 *
1544 * @param string $text The HTML to be output for the preview.
1545 */
1546 protected function showPreview( $text ) {
1547 global $wgOut;
1548
1549 if($this->mTitle->getNamespace() == NS_CATEGORY) {
1550 $this->mArticle->openShowCategory();
1551 }
1552 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
1553 $wgOut->addHTML( $text );
1554 if($this->mTitle->getNamespace() == NS_CATEGORY) {
1555 $this->mArticle->closeShowCategory();
1556 }
1557 }
1558
1559 /**
1560 * Live Preview lets us fetch rendered preview page content and
1561 * add it to the page without refreshing the whole page.
1562 * If not supported by the browser it will fall through to the normal form
1563 * submission method.
1564 *
1565 * This function outputs a script tag to support live preview, and
1566 * returns an onclick handler which should be added to the attributes
1567 * of the preview button
1568 */
1569 function doLivePreviewScript() {
1570 global $wgOut, $wgTitle;
1571 $wgOut->addScriptFile( 'preview.js' );
1572 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
1573 return "return !lpDoPreview(" .
1574 "editform.wpTextbox1.value," .
1575 '"' . $liveAction . '"' . ")";
1576 }
1577
1578 protected function showEditTools() {
1579 global $wgOut;
1580 $wgOut->addHtml( '<div class="mw-editTools">' );
1581 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
1582 $wgOut->addHtml( '</div>' );
1583 }
1584
1585 function getLastDelete() {
1586 $dbr = wfGetDB( DB_SLAVE );
1587 $fname = 'EditPage::getLastDelete';
1588 $res = $dbr->select(
1589 array( 'logging', 'user' ),
1590 array( 'log_type',
1591 'log_action',
1592 'log_timestamp',
1593 'log_user',
1594 'log_namespace',
1595 'log_title',
1596 'log_comment',
1597 'log_params',
1598 'user_name', ),
1599 array( 'log_namespace' => $this->mTitle->getNamespace(),
1600 'log_title' => $this->mTitle->getDBkey(),
1601 'log_type' => 'delete',
1602 'log_action' => 'delete',
1603 'user_id=log_user' ),
1604 $fname,
1605 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' ) );
1606
1607 if($dbr->numRows($res) == 1) {
1608 while ( $x = $dbr->fetchObject ( $res ) )
1609 $data = $x;
1610 $dbr->freeResult ( $res ) ;
1611 } else {
1612 $data = null;
1613 }
1614 return $data;
1615 }
1616
1617 /**
1618 * Get the rendered text for previewing.
1619 * @return string
1620 */
1621 function getPreviewText() {
1622 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang;
1623
1624 wfProfileIn( __METHOD__ );
1625
1626 if ( $this->mTriedSave && !$this->mTokenOk ) {
1627 if ( $this->mTokenOkExceptSuffix ) {
1628 $note = wfMsg( 'token_suffix_mismatch' );
1629 } else {
1630 $note = wfMsg( 'session_fail_preview' );
1631 }
1632 } else {
1633 $note = wfMsg( 'previewnote' );
1634 }
1635
1636 $parserOptions = ParserOptions::newFromUser( $wgUser );
1637 $parserOptions->setEditSection( false );
1638
1639 global $wgRawHtml;
1640 if( $wgRawHtml && !$this->mTokenOk ) {
1641 // Could be an offsite preview attempt. This is very unsafe if
1642 // HTML is enabled, as it could be an attack.
1643 return $wgOut->parse( "<div class='previewnote'>" .
1644 wfMsg( 'session_fail_preview_html' ) . "</div>" );
1645 }
1646
1647 # don't parse user css/js, show message about preview
1648 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
1649
1650 if ( $this->isCssJsSubpage ) {
1651 if(preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
1652 $previewtext = wfMsg('usercsspreview');
1653 } else if(preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
1654 $previewtext = wfMsg('userjspreview');
1655 }
1656 $parserOptions->setTidy(true);
1657 $parserOutput = $wgParser->parse( $previewtext , $this->mTitle, $parserOptions );
1658 //$wgOut->addHTML( $parserOutput->mText );
1659 $previewHTML = '';
1660 } elseif( $rt = Title::newFromRedirect( $this->textbox1 ) ) {
1661 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
1662 } else {
1663 $toparse = $this->textbox1;
1664
1665 # If we're adding a comment, we need to show the
1666 # summary as the headline
1667 if($this->section=="new" && $this->summary!="") {
1668 $toparse="== {$this->summary} ==\n\n".$toparse;
1669 }
1670
1671 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
1672
1673 // Parse mediawiki messages with correct target language
1674 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
1675 $pos = strrpos( $this->mTitle->getText(), '/' );
1676 if ( $pos !== false ) {
1677 $code = substr( $this->mTitle->getText(), $pos+1 );
1678 switch ($code) {
1679 case $wgLang->getCode():
1680 $obj = $wgLang; break;
1681 case $wgContLang->getCode():
1682 $obj = $wgContLang; break;
1683 default:
1684 $obj = Language::factory( $code );
1685 }
1686 $parserOptions->setTargetLanguage( $obj );
1687 }
1688 }
1689
1690
1691 $parserOptions->setTidy(true);
1692 $parserOptions->enableLimitReport();
1693 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
1694 $this->mTitle, $parserOptions );
1695
1696 $previewHTML = $parserOutput->getText();
1697 $this->mParserOutput = $parserOutput;
1698 $wgOut->addParserOutputNoText( $parserOutput );
1699
1700 if ( count( $parserOutput->getWarnings() ) ) {
1701 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
1702 }
1703 }
1704
1705 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
1706 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
1707 if ( $this->isConflict ) {
1708 $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
1709 }
1710
1711 wfProfileOut( __METHOD__ );
1712 return $previewhead . $previewHTML;
1713 }
1714
1715 function getTemplates() {
1716 if( $this->preview || $this->section != '' ) {
1717 $templates = array();
1718 if( !isset($this->mParserOutput) ) return $templates;
1719 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
1720 foreach( array_keys( $template ) as $dbk ) {
1721 $templates[] = Title::makeTitle($ns, $dbk);
1722 }
1723 }
1724 return $templates;
1725 } else {
1726 return $this->mArticle->getUsedTemplates();
1727 }
1728 }
1729
1730 /**
1731 * Call the stock "user is blocked" page
1732 */
1733 function blockedPage() {
1734 global $wgOut, $wgUser;
1735 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
1736
1737 # If the user made changes, preserve them when showing the markup
1738 # (This happens when a user is blocked during edit, for instance)
1739 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
1740 if( $first ) {
1741 $source = $this->mTitle->exists() ? $this->getContent() : false;
1742 } else {
1743 $source = $this->textbox1;
1744 }
1745
1746 # Spit out the source or the user's modified version
1747 if( $source !== false ) {
1748 $rows = $wgUser->getIntOption( 'rows' );
1749 $cols = $wgUser->getIntOption( 'cols' );
1750 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
1751 $wgOut->addHtml( '<hr />' );
1752 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
1753 # Why we don't use Xml::element here?
1754 # Is it because if $source is '', it returns <textarea />?
1755 $wgOut->addHtml( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
1756 }
1757 }
1758
1759 /**
1760 * Produce the stock "please login to edit pages" page
1761 */
1762 function userNotLoggedInPage() {
1763 global $wgUser, $wgOut, $wgTitle;
1764 $skin = $wgUser->getSkin();
1765
1766 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
1767 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
1768
1769 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
1770 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1771 $wgOut->setArticleRelated( false );
1772
1773 $wgOut->addHtml( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
1774 $wgOut->returnToMain( false, $wgTitle );
1775 }
1776
1777 /**
1778 * Creates a basic error page which informs the user that
1779 * they have attempted to edit a nonexistant section.
1780 */
1781 function noSuchSectionPage() {
1782 global $wgOut, $wgTitle;
1783
1784 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
1785 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1786 $wgOut->setArticleRelated( false );
1787
1788 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
1789 $wgOut->returnToMain( false, $wgTitle );
1790 }
1791
1792 /**
1793 * Produce the stock "your edit contains spam" page
1794 *
1795 * @param $match Text which triggered one or more filters
1796 */
1797 function spamPage( $match = false ) {
1798 global $wgOut, $wgTitle;
1799
1800 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
1801 $wgOut->setRobotPolicy( 'noindex,nofollow' );
1802 $wgOut->setArticleRelated( false );
1803
1804 $wgOut->addHtml( '<div id="spamprotected">' );
1805 $wgOut->addWikiMsg( 'spamprotectiontext' );
1806 if ( $match )
1807 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
1808 $wgOut->addHtml( '</div>' );
1809
1810 $wgOut->returnToMain( false, $wgTitle );
1811 }
1812
1813 /**
1814 * @private
1815 * @todo document
1816 */
1817 function mergeChangesInto( &$editText ){
1818 $fname = 'EditPage::mergeChangesInto';
1819 wfProfileIn( $fname );
1820
1821 $db = wfGetDB( DB_MASTER );
1822
1823 // This is the revision the editor started from
1824 $baseRevision = $this->getBaseRevision();
1825 if( is_null( $baseRevision ) ) {
1826 wfProfileOut( $fname );
1827 return false;
1828 }
1829 $baseText = $baseRevision->getText();
1830
1831 // The current state, we want to merge updates into it
1832 $currentRevision = Revision::loadFromTitle(
1833 $db, $this->mTitle );
1834 if( is_null( $currentRevision ) ) {
1835 wfProfileOut( $fname );
1836 return false;
1837 }
1838 $currentText = $currentRevision->getText();
1839
1840 $result = '';
1841 if( wfMerge( $baseText, $editText, $currentText, $result ) ){
1842 $editText = $result;
1843 wfProfileOut( $fname );
1844 return true;
1845 } else {
1846 wfProfileOut( $fname );
1847 return false;
1848 }
1849 }
1850
1851 /**
1852 * Check if the browser is on a blacklist of user-agents known to
1853 * mangle UTF-8 data on form submission. Returns true if Unicode
1854 * should make it through, false if it's known to be a problem.
1855 * @return bool
1856 * @private
1857 */
1858 function checkUnicodeCompliantBrowser() {
1859 global $wgBrowserBlackList;
1860 if( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
1861 // No User-Agent header sent? Trust it by default...
1862 return true;
1863 }
1864 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
1865 foreach ( $wgBrowserBlackList as $browser ) {
1866 if ( preg_match($browser, $currentbrowser) ) {
1867 return false;
1868 }
1869 }
1870 return true;
1871 }
1872
1873 /**
1874 * @deprecated use $wgParser->stripSectionName()
1875 */
1876 function pseudoParseSectionAnchor( $text ) {
1877 global $wgParser;
1878 return $wgParser->stripSectionName( $text );
1879 }
1880
1881 /**
1882 * Format an anchor fragment as it would appear for a given section name
1883 * @param string $text
1884 * @return string
1885 * @private
1886 */
1887 function sectionAnchor( $text ) {
1888 global $wgParser;
1889 return $wgParser->guessSectionNameFromWikiText( $text );
1890 }
1891
1892 /**
1893 * Shows a bulletin board style toolbar for common editing functions.
1894 * It can be disabled in the user preferences.
1895 * The necessary JavaScript code can be found in skins/common/edit.js.
1896 *
1897 * @return string
1898 */
1899 static function getEditToolbar() {
1900 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
1901
1902 /**
1903 * toolarray an array of arrays which each include the filename of
1904 * the button image (without path), the opening tag, the closing tag,
1905 * and optionally a sample text that is inserted between the two when no
1906 * selection is highlighted.
1907 * The tip text is shown when the user moves the mouse over the button.
1908 *
1909 * Already here are accesskeys (key), which are not used yet until someone
1910 * can figure out a way to make them work in IE. However, we should make
1911 * sure these keys are not defined on the edit page.
1912 */
1913 $toolarray = array(
1914 array(
1915 'image' => $wgLang->getImageFile('button-bold'),
1916 'id' => 'mw-editbutton-bold',
1917 'open' => '\'\'\'',
1918 'close' => '\'\'\'',
1919 'sample' => wfMsg('bold_sample'),
1920 'tip' => wfMsg('bold_tip'),
1921 'key' => 'B'
1922 ),
1923 array(
1924 'image' => $wgLang->getImageFile('button-italic'),
1925 'id' => 'mw-editbutton-italic',
1926 'open' => '\'\'',
1927 'close' => '\'\'',
1928 'sample' => wfMsg('italic_sample'),
1929 'tip' => wfMsg('italic_tip'),
1930 'key' => 'I'
1931 ),
1932 array(
1933 'image' => $wgLang->getImageFile('button-link'),
1934 'id' => 'mw-editbutton-link',
1935 'open' => '[[',
1936 'close' => ']]',
1937 'sample' => wfMsg('link_sample'),
1938 'tip' => wfMsg('link_tip'),
1939 'key' => 'L'
1940 ),
1941 array(
1942 'image' => $wgLang->getImageFile('button-extlink'),
1943 'id' => 'mw-editbutton-extlink',
1944 'open' => '[',
1945 'close' => ']',
1946 'sample' => wfMsg('extlink_sample'),
1947 'tip' => wfMsg('extlink_tip'),
1948 'key' => 'X'
1949 ),
1950 array(
1951 'image' => $wgLang->getImageFile('button-headline'),
1952 'id' => 'mw-editbutton-headline',
1953 'open' => "\n== ",
1954 'close' => " ==\n",
1955 'sample' => wfMsg('headline_sample'),
1956 'tip' => wfMsg('headline_tip'),
1957 'key' => 'H'
1958 ),
1959 array(
1960 'image' => $wgLang->getImageFile('button-image'),
1961 'id' => 'mw-editbutton-image',
1962 'open' => '[['.$wgContLang->getNsText(NS_IMAGE).':',
1963 'close' => ']]',
1964 'sample' => wfMsg('image_sample'),
1965 'tip' => wfMsg('image_tip'),
1966 'key' => 'D'
1967 ),
1968 array(
1969 'image' => $wgLang->getImageFile('button-media'),
1970 'id' => 'mw-editbutton-media',
1971 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
1972 'close' => ']]',
1973 'sample' => wfMsg('media_sample'),
1974 'tip' => wfMsg('media_tip'),
1975 'key' => 'M'
1976 ),
1977 array(
1978 'image' => $wgLang->getImageFile('button-math'),
1979 'id' => 'mw-editbutton-math',
1980 'open' => "<math>",
1981 'close' => "</math>",
1982 'sample' => wfMsg('math_sample'),
1983 'tip' => wfMsg('math_tip'),
1984 'key' => 'C'
1985 ),
1986 array(
1987 'image' => $wgLang->getImageFile('button-nowiki'),
1988 'id' => 'mw-editbutton-nowiki',
1989 'open' => "<nowiki>",
1990 'close' => "</nowiki>",
1991 'sample' => wfMsg('nowiki_sample'),
1992 'tip' => wfMsg('nowiki_tip'),
1993 'key' => 'N'
1994 ),
1995 array(
1996 'image' => $wgLang->getImageFile('button-sig'),
1997 'id' => 'mw-editbutton-signature',
1998 'open' => '--~~~~',
1999 'close' => '',
2000 'sample' => '',
2001 'tip' => wfMsg('sig_tip'),
2002 'key' => 'Y'
2003 ),
2004 array(
2005 'image' => $wgLang->getImageFile('button-hr'),
2006 'id' => 'mw-editbutton-hr',
2007 'open' => "\n----\n",
2008 'close' => '',
2009 'sample' => '',
2010 'tip' => wfMsg('hr_tip'),
2011 'key' => 'R'
2012 )
2013 );
2014 $toolbar = "<div id='toolbar'>\n";
2015 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
2016
2017 foreach($toolarray as $tool) {
2018 $params = array(
2019 $image = $wgStylePath.'/common/images/'.$tool['image'],
2020 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2021 // Older browsers show a "speedtip" type message only for ALT.
2022 // Ideally these should be different, realistically they
2023 // probably don't need to be.
2024 $tip = $tool['tip'],
2025 $open = $tool['open'],
2026 $close = $tool['close'],
2027 $sample = $tool['sample'],
2028 $cssId = $tool['id'],
2029 );
2030
2031 $paramList = implode( ',',
2032 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2033 $toolbar.="addButton($paramList);\n";
2034 }
2035
2036 $toolbar.="/*]]>*/\n</script>";
2037 $toolbar.="\n</div>";
2038 return $toolbar;
2039 }
2040
2041 /**
2042 * Returns an array of html code of the following checkboxes:
2043 * minor and watch
2044 *
2045 * @param $tabindex Current tabindex
2046 * @param $skin Skin object
2047 * @param $checked Array of checkbox => bool, where bool indicates the checked
2048 * status of the checkbox
2049 *
2050 * @return array
2051 */
2052 public static function getCheckboxes( &$tabindex, $skin, $checked ) {
2053 global $wgUser;
2054
2055 $checkboxes = array();
2056
2057 $checkboxes['minor'] = '';
2058 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
2059 if ( $wgUser->isAllowed('minoredit') ) {
2060 $attribs = array(
2061 'tabindex' => ++$tabindex,
2062 'accesskey' => wfMsg( 'accesskey-minoredit' ),
2063 'id' => 'wpMinoredit',
2064 );
2065 $checkboxes['minor'] =
2066 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
2067 "&nbsp;<label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
2068 }
2069
2070 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
2071 $checkboxes['watch'] = '';
2072 if ( $wgUser->isLoggedIn() ) {
2073 $attribs = array(
2074 'tabindex' => ++$tabindex,
2075 'accesskey' => wfMsg( 'accesskey-watch' ),
2076 'id' => 'wpWatchthis',
2077 );
2078 $checkboxes['watch'] =
2079 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
2080 "&nbsp;<label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
2081 }
2082 return $checkboxes;
2083 }
2084
2085 /**
2086 * Returns an array of html code of the following buttons:
2087 * save, diff, preview and live
2088 *
2089 * @param $tabindex Current tabindex
2090 *
2091 * @return array
2092 */
2093 public function getEditButtons(&$tabindex) {
2094 global $wgLivePreview, $wgUser;
2095
2096 $buttons = array();
2097
2098 $temp = array(
2099 'id' => 'wpSave',
2100 'name' => 'wpSave',
2101 'type' => 'submit',
2102 'tabindex' => ++$tabindex,
2103 'value' => wfMsg('savearticle'),
2104 'accesskey' => wfMsg('accesskey-save'),
2105 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
2106 );
2107 $buttons['save'] = Xml::element('input', $temp, '');
2108
2109 ++$tabindex; // use the same for preview and live preview
2110 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
2111 $temp = array(
2112 'id' => 'wpPreview',
2113 'name' => 'wpPreview',
2114 'type' => 'submit',
2115 'tabindex' => $tabindex,
2116 'value' => wfMsg('showpreview'),
2117 'accesskey' => '',
2118 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2119 'style' => 'display: none;',
2120 );
2121 $buttons['preview'] = Xml::element('input', $temp, '');
2122
2123 $temp = array(
2124 'id' => 'wpLivePreview',
2125 'name' => 'wpLivePreview',
2126 'type' => 'submit',
2127 'tabindex' => $tabindex,
2128 'value' => wfMsg('showlivepreview'),
2129 'accesskey' => wfMsg('accesskey-preview'),
2130 'title' => '',
2131 'onclick' => $this->doLivePreviewScript(),
2132 );
2133 $buttons['live'] = Xml::element('input', $temp, '');
2134 } else {
2135 $temp = array(
2136 'id' => 'wpPreview',
2137 'name' => 'wpPreview',
2138 'type' => 'submit',
2139 'tabindex' => $tabindex,
2140 'value' => wfMsg('showpreview'),
2141 'accesskey' => wfMsg('accesskey-preview'),
2142 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
2143 );
2144 $buttons['preview'] = Xml::element('input', $temp, '');
2145 $buttons['live'] = '';
2146 }
2147
2148 $temp = array(
2149 'id' => 'wpDiff',
2150 'name' => 'wpDiff',
2151 'type' => 'submit',
2152 'tabindex' => ++$tabindex,
2153 'value' => wfMsg('showdiff'),
2154 'accesskey' => wfMsg('accesskey-diff'),
2155 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
2156 );
2157 $buttons['diff'] = Xml::element('input', $temp, '');
2158
2159 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons ) );
2160 return $buttons;
2161 }
2162
2163 /**
2164 * Output preview text only. This can be sucked into the edit page
2165 * via JavaScript, and saves the server time rendering the skin as
2166 * well as theoretically being more robust on the client (doesn't
2167 * disturb the edit box's undo history, won't eat your text on
2168 * failure, etc).
2169 *
2170 * @todo This doesn't include category or interlanguage links.
2171 * Would need to enhance it a bit, <s>maybe wrap them in XML
2172 * or something...</s> that might also require more skin
2173 * initialization, so check whether that's a problem.
2174 */
2175 function livePreview() {
2176 global $wgOut;
2177 $wgOut->disable();
2178 header( 'Content-type: text/xml; charset=utf-8' );
2179 header( 'Cache-control: no-cache' );
2180
2181 $previewText = $this->getPreviewText();
2182 #$categories = $skin->getCategoryLinks();
2183
2184 $s =
2185 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
2186 Xml::tags( 'livepreview', null,
2187 Xml::element( 'preview', null, $previewText )
2188 #. Xml::element( 'category', null, $categories )
2189 );
2190 echo $s;
2191 }
2192
2193
2194 /**
2195 * Get a diff between the current contents of the edit box and the
2196 * version of the page we're editing from.
2197 *
2198 * If this is a section edit, we'll replace the section as for final
2199 * save and then make a comparison.
2200 */
2201 function showDiff() {
2202 $oldtext = $this->mArticle->fetchContent();
2203 $newtext = $this->mArticle->replaceSection(
2204 $this->section, $this->textbox1, $this->summary, $this->edittime );
2205 $newtext = $this->mArticle->preSaveTransform( $newtext );
2206 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
2207 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
2208 if ( $oldtext !== false || $newtext != '' ) {
2209 $de = new DifferenceEngine( $this->mTitle );
2210 $de->setText( $oldtext, $newtext );
2211 $difftext = $de->getDiff( $oldtitle, $newtitle );
2212 $de->showDiffStyle();
2213 } else {
2214 $difftext = '';
2215 }
2216
2217 global $wgOut;
2218 $wgOut->addHtml( '<div id="wikiDiff">' . $difftext . '</div>' );
2219 }
2220
2221 /**
2222 * Filter an input field through a Unicode de-armoring process if it
2223 * came from an old browser with known broken Unicode editing issues.
2224 *
2225 * @param WebRequest $request
2226 * @param string $field
2227 * @return string
2228 * @private
2229 */
2230 function safeUnicodeInput( $request, $field ) {
2231 $text = rtrim( $request->getText( $field ) );
2232 return $request->getBool( 'safemode' )
2233 ? $this->unmakesafe( $text )
2234 : $text;
2235 }
2236
2237 /**
2238 * Filter an output field through a Unicode armoring process if it is
2239 * going to an old browser with known broken Unicode editing issues.
2240 *
2241 * @param string $text
2242 * @return string
2243 * @private
2244 */
2245 function safeUnicodeOutput( $text ) {
2246 global $wgContLang;
2247 $codedText = $wgContLang->recodeForEdit( $text );
2248 return $this->checkUnicodeCompliantBrowser()
2249 ? $codedText
2250 : $this->makesafe( $codedText );
2251 }
2252
2253 /**
2254 * A number of web browsers are known to corrupt non-ASCII characters
2255 * in a UTF-8 text editing environment. To protect against this,
2256 * detected browsers will be served an armored version of the text,
2257 * with non-ASCII chars converted to numeric HTML character references.
2258 *
2259 * Preexisting such character references will have a 0 added to them
2260 * to ensure that round-trips do not alter the original data.
2261 *
2262 * @param string $invalue
2263 * @return string
2264 * @private
2265 */
2266 function makesafe( $invalue ) {
2267 // Armor existing references for reversability.
2268 $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
2269
2270 $bytesleft = 0;
2271 $result = "";
2272 $working = 0;
2273 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2274 $bytevalue = ord( $invalue{$i} );
2275 if( $bytevalue <= 0x7F ) { //0xxx xxxx
2276 $result .= chr( $bytevalue );
2277 $bytesleft = 0;
2278 } elseif( $bytevalue <= 0xBF ) { //10xx xxxx
2279 $working = $working << 6;
2280 $working += ($bytevalue & 0x3F);
2281 $bytesleft--;
2282 if( $bytesleft <= 0 ) {
2283 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
2284 }
2285 } elseif( $bytevalue <= 0xDF ) { //110x xxxx
2286 $working = $bytevalue & 0x1F;
2287 $bytesleft = 1;
2288 } elseif( $bytevalue <= 0xEF ) { //1110 xxxx
2289 $working = $bytevalue & 0x0F;
2290 $bytesleft = 2;
2291 } else { //1111 0xxx
2292 $working = $bytevalue & 0x07;
2293 $bytesleft = 3;
2294 }
2295 }
2296 return $result;
2297 }
2298
2299 /**
2300 * Reverse the previously applied transliteration of non-ASCII characters
2301 * back to UTF-8. Used to protect data from corruption by broken web browsers
2302 * as listed in $wgBrowserBlackList.
2303 *
2304 * @param string $invalue
2305 * @return string
2306 * @private
2307 */
2308 function unmakesafe( $invalue ) {
2309 $result = "";
2310 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
2311 if( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
2312 $i += 3;
2313 $hexstring = "";
2314 do {
2315 $hexstring .= $invalue{$i};
2316 $i++;
2317 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
2318
2319 // Do some sanity checks. These aren't needed for reversability,
2320 // but should help keep the breakage down if the editor
2321 // breaks one of the entities whilst editing.
2322 if ((substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6)) {
2323 $codepoint = hexdec($hexstring);
2324 $result .= codepointToUtf8( $codepoint );
2325 } else {
2326 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
2327 }
2328 } else {
2329 $result .= substr( $invalue, $i, 1 );
2330 }
2331 }
2332 // reverse the transform that we made for reversability reasons.
2333 return strtr( $result, array( "&#x0" => "&#x" ) );
2334 }
2335
2336 function noCreatePermission() {
2337 global $wgOut;
2338 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
2339 $wgOut->addWikiMsg( 'nocreatetext' );
2340 }
2341
2342 /**
2343 * If there are rows in the deletion log for this page, show them,
2344 * along with a nice little note for the user
2345 *
2346 * @param OutputPage $out
2347 */
2348 protected function showDeletionLog( $out ) {
2349 global $wgUser;
2350 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
2351 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
2352 if( $pager->getNumRows() > 0 ) {
2353 $out->addHtml( '<div id="mw-recreate-deleted-warn">' );
2354 $out->addWikiMsg( 'recreate-deleted-warn' );
2355 $out->addHTML(
2356 $loglist->beginLogEventsList() .
2357 $pager->getBody() .
2358 $loglist->endLogEventsList()
2359 );
2360 $out->addHtml( '</div>' );
2361 }
2362 }
2363
2364 /**
2365 * Attempt submission
2366 * @return bool false if output is done, true if the rest of the form should be displayed
2367 */
2368 function attemptSave() {
2369 global $wgUser, $wgOut, $wgTitle, $wgRequest;
2370
2371 $resultDetails = false;
2372 $value = $this->internalAttemptSave( $resultDetails, $wgUser->isAllowed('bot') && $wgRequest->getBool('bot', true) );
2373
2374 if( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
2375 $this->didSave = true;
2376 }
2377
2378 switch ($value) {
2379 case self::AS_HOOK_ERROR_EXPECTED:
2380 case self::AS_CONTENT_TOO_BIG:
2381 case self::AS_ARTICLE_WAS_DELETED:
2382 case self::AS_CONFLICT_DETECTED:
2383 case self::AS_SUMMARY_NEEDED:
2384 case self::AS_TEXTBOX_EMPTY:
2385 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
2386 case self::AS_END:
2387 return true;
2388
2389 case self::AS_HOOK_ERROR:
2390 case self::AS_FILTERING:
2391 case self::AS_SUCCESS_NEW_ARTICLE:
2392 case self::AS_SUCCESS_UPDATE:
2393 return false;
2394
2395 case self::AS_SPAM_ERROR:
2396 $this->spamPage ( $resultDetails['spam'] );
2397 return false;
2398
2399 case self::AS_BLOCKED_PAGE_FOR_USER:
2400 $this->blockedPage();
2401 return false;
2402
2403 case self::AS_IMAGE_REDIRECT_ANON:
2404 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
2405 return false;
2406
2407 case self::AS_READ_ONLY_PAGE_ANON:
2408 $this->userNotLoggedInPage();
2409 return false;
2410
2411 case self::AS_READ_ONLY_PAGE_LOGGED:
2412 case self::AS_READ_ONLY_PAGE:
2413 $wgOut->readOnlyPage();
2414 return false;
2415
2416 case self::AS_RATE_LIMITED:
2417 $wgOut->rateLimited();
2418 return false;
2419
2420 case self::AS_NO_CREATE_PERMISSION;
2421 $this->noCreatePermission();
2422 return;
2423
2424 case self::AS_BLANK_ARTICLE:
2425 $wgOut->redirect( $wgTitle->getFullURL() );
2426 return false;
2427
2428 case self::AS_IMAGE_REDIRECT_LOGGED:
2429 $wgOut->permissionRequired( 'upload' );
2430 return false;
2431 }
2432 }
2433
2434 function getBaseRevision() {
2435 if ($this->mBaseRevision == false) {
2436 $db = wfGetDB( DB_MASTER );
2437 $baseRevision = Revision::loadFromTimestamp(
2438 $db, $this->mTitle, $this->edittime );
2439 return $this->mBaseRevision = $baseRevision;
2440 } else {
2441 return $this->mBaseRevision;
2442 }
2443 }
2444 }