00001 <?php
00019 class EditPage {
00020 const AS_SUCCESS_UPDATE = 200;
00021 const AS_SUCCESS_NEW_ARTICLE = 201;
00022 const AS_HOOK_ERROR = 210;
00023 const AS_FILTERING = 211;
00024 const AS_HOOK_ERROR_EXPECTED = 212;
00025 const AS_BLOCKED_PAGE_FOR_USER = 215;
00026 const AS_CONTENT_TOO_BIG = 216;
00027 const AS_USER_CANNOT_EDIT = 217;
00028 const AS_READ_ONLY_PAGE_ANON = 218;
00029 const AS_READ_ONLY_PAGE_LOGGED = 219;
00030 const AS_READ_ONLY_PAGE = 220;
00031 const AS_RATE_LIMITED = 221;
00032 const AS_ARTICLE_WAS_DELETED = 222;
00033 const AS_NO_CREATE_PERMISSION = 223;
00034 const AS_BLANK_ARTICLE = 224;
00035 const AS_CONFLICT_DETECTED = 225;
00036 const AS_SUMMARY_NEEDED = 226;
00037 const AS_TEXTBOX_EMPTY = 228;
00038 const AS_MAX_ARTICLE_SIZE_EXCEEDED = 229;
00039 const AS_OK = 230;
00040 const AS_END = 231;
00041 const AS_SPAM_ERROR = 232;
00042 const AS_IMAGE_REDIRECT_ANON = 233;
00043 const AS_IMAGE_REDIRECT_LOGGED = 234;
00044
00045 var $mArticle;
00046 var $mTitle;
00047 var $action;
00048 var $mMetaData = '';
00049 var $isConflict = false;
00050 var $isCssJsSubpage = false;
00051 var $deletedSinceEdit = false;
00052 var $formtype;
00053 var $firsttime;
00054 var $lastDelete;
00055 var $mTokenOk = false;
00056 var $mTokenOkExceptSuffix = false;
00057 var $mTriedSave = false;
00058 var $tooBig = false;
00059 var $kblength = false;
00060 var $missingComment = false;
00061 var $missingSummary = false;
00062 var $allowBlankSummary = false;
00063 var $autoSumm = '';
00064 var $hookError = '';
00065 #var $mPreviewTemplates;
00066 var $mParserOutput;
00067 var $mBaseRevision = false;
00068
00069 # Form values
00070 var $save = false, $preview = false, $diff = false;
00071 var $minoredit = false, $watchthis = false, $recreate = false;
00072 var $textbox1 = '', $textbox2 = '', $summary = '';
00073 var $edittime = '', $section = '', $starttime = '';
00074 var $oldid = 0, $editintro = '', $scrolltop = null;
00075
00076 # Placeholders for text injection by hooks (must be HTML)
00077 # extensions should take care to _append_ to the present value
00078 public $editFormPageTop;
00079 public $editFormTextTop;
00080 public $editFormTextBeforeContent;
00081 public $editFormTextAfterWarn;
00082 public $editFormTextAfterTools;
00083 public $editFormTextBottom;
00084
00085
00086 public $didSave = false;
00087 public $undidRev = 0;
00088
00089 public $suppressIntro = false;
00090
00095 function EditPage( $article ) {
00096 $this->mArticle =& $article;
00097 $this->mTitle = $article->getTitle();
00098 $this->action = 'submit';
00099
00100 # Placeholders for text injection by hooks (empty per default)
00101 $this->editFormPageTop =
00102 $this->editFormTextTop =
00103 $this->editFormTextBeforeContent =
00104 $this->editFormTextAfterWarn =
00105 $this->editFormTextAfterTools =
00106 $this->editFormTextBottom = "";
00107 }
00108
00109 function getArticle() {
00110 return $this->mArticle;
00111 }
00112
00117 function getContent( $def_text = '' ) {
00118 global $wgOut, $wgRequest, $wgParser, $wgContLang, $wgMessageCache;
00119
00120 wfProfileIn( __METHOD__ );
00121 # Get variables from query string :P
00122 $section = $wgRequest->getVal( 'section' );
00123 $preload = $wgRequest->getVal( 'preload' );
00124 $undoafter = $wgRequest->getVal( 'undoafter' );
00125 $undo = $wgRequest->getVal( 'undo' );
00126
00127 $text = '';
00128
00129
00130 if ( !$this->mTitle->exists() ) {
00131 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
00132 # If this is a system message, get the default text.
00133 list( $message, $lang ) = $wgMessageCache->figureMessage( $wgContLang->lcfirst( $this->mTitle->getText() ) );
00134 $wgMessageCache->loadAllMessages( $lang );
00135 $text = wfMsgGetKey( $message, false, $lang, false );
00136 if( wfEmptyMsg( $message, $text ) )
00137 $text = '';
00138 } else {
00139 # If requested, preload some text.
00140 $text = $this->getPreloadedText( $preload );
00141 }
00142
00143 } else {
00144 $text = $this->mArticle->getContent();
00145 if ( $undo > 0 && $undoafter > 0 && $undo < $undoafter ) {
00146 # If they got undoafter and undo round the wrong way, switch them
00147 list( $undo, $undoafter ) = array( $undoafter, $undo );
00148 }
00149 if ( $undo > 0 && $undo > $undoafter ) {
00150 # Undoing a specific edit overrides section editing; section-editing
00151 # doesn't work with undoing.
00152 if ( $undoafter ) {
00153 $undorev = Revision::newFromId($undo);
00154 $oldrev = Revision::newFromId($undoafter);
00155 } else {
00156 $undorev = Revision::newFromId($undo);
00157 $oldrev = $undorev ? $undorev->getPrevious() : null;
00158 }
00159
00160 # Sanity check, make sure it's the right page,
00161 # the revisions exist and they were not deleted.
00162 # Otherwise, $text will be left as-is.
00163 if ( !is_null( $undorev ) && !is_null( $oldrev ) &&
00164 $undorev->getPage() == $oldrev->getPage() &&
00165 $undorev->getPage() == $this->mArticle->getID() &&
00166 !$undorev->isDeleted( Revision::DELETED_TEXT ) &&
00167 !$oldrev->isDeleted( Revision::DELETED_TEXT ) ) {
00168
00169 $undotext = $this->mArticle->getUndoText( $undorev, $oldrev );
00170 if ( $undotext === false ) {
00171 # Warn the user that something went wrong
00172 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-failure">' . wfMsgNoTrans( 'undo-failure' ) . '</div>' );
00173 } else {
00174 $text = $undotext;
00175 # Inform the user of our success and set an automatic edit summary
00176 $this->editFormPageTop .= $wgOut->parse( '<div class="mw-undo-success">' . wfMsgNoTrans( 'undo-success' ) . '</div>' );
00177 $firstrev = $oldrev->getNext();
00178 # If we just undid one rev, use an autosummary
00179 if ( $firstrev->mId == $undo ) {
00180 $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
00181 $this->undidRev = $undo;
00182 }
00183 $this->formtype = 'diff';
00184 }
00185 } else {
00186
00187
00188
00189 $this->editFormPageTop .= $wgOut->parse( '<div class="error mw-undo-norev">' . wfMsgNoTrans( 'undo-norev' ) . '</div>' );
00190 }
00191 } else if ( $section != '' ) {
00192 if ( $section == 'new' ) {
00193 $text = $this->getPreloadedText( $preload );
00194 } else {
00195 $text = $wgParser->getSection( $text, $section, $def_text );
00196 }
00197 }
00198 }
00199
00200 wfProfileOut( __METHOD__ );
00201 return $text;
00202 }
00203
00210 protected function getPreloadedText( $preload ) {
00211 if ( $preload === '' ) {
00212 return '';
00213 } else {
00214 $preloadTitle = Title::newFromText( $preload );
00215 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
00216 $rev = Revision::newFromTitle($preloadTitle);
00217 if ( is_object( $rev ) ) {
00218 $text = $rev->getText();
00219
00220
00221 $text = preg_replace( '~</?includeonly>~', '', $text );
00222 return $text;
00223 } else
00224 return '';
00225 }
00226 }
00227 }
00228
00234 function extractMetaDataFromArticle () {
00235 global $wgUseMetadataEdit, $wgMetadataWhitelist, $wgContLang;
00236 $this->mMetaData = '';
00237 if ( !$wgUseMetadataEdit ) return;
00238 if ( $wgMetadataWhitelist == '' ) return;
00239 $s = '';
00240 $t = $this->getContent();
00241
00242 # MISSING : <nowiki> filtering
00243
00244 # Categories and language links
00245 $t = explode ( "\n" , $t );
00246 $catlow = strtolower ( $wgContLang->getNsText( NS_CATEGORY ) );
00247 $cat = $ll = array();
00248 foreach ( $t AS $key => $x ) {
00249 $y = trim ( strtolower ( $x ) );
00250 while ( substr ( $y , 0 , 2 ) == '[[' ) {
00251 $y = explode ( ']]' , trim ( $x ) );
00252 $first = array_shift ( $y );
00253 $first = explode ( ':' , $first );
00254 $ns = array_shift ( $first );
00255 $ns = trim ( str_replace ( '[' , '' , $ns ) );
00256 if ( $wgContLang->getLanguageName( $ns ) || strtolower ( $ns ) == $catlow ) {
00257 $add = '[[' . $ns . ':' . implode ( ':' , $first ) . ']]';
00258 if ( strtolower ( $ns ) == $catlow ) $cat[] = $add;
00259 else $ll[] = $add;
00260 $x = implode ( ']]' , $y );
00261 $t[$key] = $x;
00262 $y = trim ( strtolower ( $x ) );
00263 } else {
00264 $x = implode ( ']]' , $y );
00265 $y = trim ( strtolower ( $x ) );
00266 }
00267 }
00268 }
00269 if ( count ( $cat ) ) $s .= implode ( ' ' , $cat ) . "\n";
00270 if ( count ( $ll ) ) $s .= implode ( ' ' , $ll ) . "\n";
00271 $t = implode ( "\n" , $t );
00272
00273 # Load whitelist
00274 $sat = array () ; # stand-alone-templates; must be lowercase
00275 $wl_title = Title::newFromText ( $wgMetadataWhitelist );
00276 $wl_article = new Article ( $wl_title );
00277 $wl = explode ( "\n" , $wl_article->getContent() );
00278 foreach ( $wl AS $x ) {
00279 $isentry = false;
00280 $x = trim ( $x );
00281 while ( substr ( $x , 0 , 1 ) == '*' ) {
00282 $isentry = true;
00283 $x = trim ( substr ( $x , 1 ) );
00284 }
00285 if ( $isentry ) {
00286 $sat[] = strtolower ( $x );
00287 }
00288
00289 }
00290
00291 # Templates, but only some
00292 $t = explode ( '{{' , $t );
00293 $tl = array () ;
00294 foreach ( $t AS $key => $x ) {
00295 $y = explode ( '}}' , $x , 2 );
00296 if ( count ( $y ) == 2 ) {
00297 $z = $y[0];
00298 $z = explode ( '|' , $z );
00299 $tn = array_shift ( $z );
00300 if ( in_array ( strtolower ( $tn ) , $sat ) ) {
00301 $tl[] = '{{' . $y[0] . '}}';
00302 $t[$key] = $y[1];
00303 $y = explode ( '}}' , $y[1] , 2 );
00304 }
00305 else $t[$key] = '{{' . $x;
00306 }
00307 else if ( $key != 0 ) $t[$key] = '{{' . $x;
00308 else $t[$key] = $x;
00309 }
00310 if ( count ( $tl ) ) $s .= implode ( ' ' , $tl );
00311 $t = implode ( '' , $t );
00312
00313 $t = str_replace ( "\n\n\n" , "\n" , $t );
00314 $this->mArticle->mContent = $t;
00315 $this->mMetaData = $s;
00316 }
00317
00318
00319
00320
00321
00322
00323
00324 protected function wasDeletedSinceLastEdit() {
00325 if ( $this->deletedSinceEdit )
00326 return true;
00327 if ( $this->mTitle->isDeletedQuick() ) {
00328 $this->lastDelete = $this->getLastDelete();
00329 if ( $this->lastDelete ) {
00330 $deleteTime = wfTimestamp( TS_MW, $this->lastDelete->log_timestamp );
00331 if ( $deleteTime > $this->starttime ) {
00332 $this->deletedSinceEdit = true;
00333 }
00334 }
00335 }
00336 return $this->deletedSinceEdit;
00337 }
00338
00339 function submit() {
00340 $this->edit();
00341 }
00342
00354 function edit() {
00355 global $wgOut, $wgUser, $wgRequest;
00356
00357 if ( !wfRunHooks( 'AlternateEdit', array( &$this ) ) ) {
00358 return;
00359 }
00360
00361 wfProfileIn( __METHOD__ );
00362 wfDebug( __METHOD__.": enter\n" );
00363
00364
00365 $wgOut->setArticleFlag( false );
00366
00367 $this->importFormData( $wgRequest );
00368 $this->firsttime = false;
00369
00370 if ( $this->live ) {
00371 $this->livePreview();
00372 wfProfileOut( __METHOD__ );
00373 return;
00374 }
00375
00376 if ( wfReadOnly() && $this->save ) {
00377
00378 $this->save = false;
00379 $this->preview = true;
00380 }
00381
00382 $wgOut->addScriptFile( 'edit.js' );
00383 $permErrors = $this->getEditPermissionErrors();
00384 if ( $permErrors ) {
00385 wfDebug( __METHOD__.": User can't edit\n" );
00386 $this->readOnlyPage( $this->getContent(), true, $permErrors, 'edit' );
00387 wfProfileOut( __METHOD__ );
00388 return;
00389 } else {
00390 if ( $this->save ) {
00391 $this->formtype = 'save';
00392 } else if ( $this->preview ) {
00393 $this->formtype = 'preview';
00394 } else if ( $this->diff ) {
00395 $this->formtype = 'diff';
00396 } else { # First time through
00397 $this->firsttime = true;
00398 if ( $this->previewOnOpen() ) {
00399 $this->formtype = 'preview';
00400 } else {
00401 $this->extractMetaDataFromArticle () ;
00402 $this->formtype = 'initial';
00403 }
00404 }
00405 }
00406
00407
00408 if ( $wgRequest->getBool( 'redlink' ) && $this->mTitle->exists() ) {
00409 $wgOut->redirect( $this->mTitle->getFullURL() );
00410 }
00411
00412 wfProfileIn( __METHOD__."-business-end" );
00413
00414 $this->isConflict = false;
00415
00416 $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
00417 $this->isValidCssJsSubpage = $this->mTitle->isValidCssJsSubpage();
00418
00419 # Show applicable editing introductions
00420 if ( $this->formtype == 'initial' || $this->firsttime )
00421 $this->showIntro();
00422
00423 if ( $this->mTitle->isTalkPage() ) {
00424 $wgOut->addWikiMsg( 'talkpagetext' );
00425 }
00426
00427 # Optional notices on a per-namespace and per-page basis
00428 $editnotice_ns = 'editnotice-'.$this->mTitle->getNamespace();
00429 if ( !wfEmptyMsg( $editnotice_ns, wfMsgForContent( $editnotice_ns ) ) ) {
00430 $wgOut->addWikiText( wfMsgForContent( $editnotice_ns ) );
00431 }
00432 if ( MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
00433 $parts = explode( '/', $this->mTitle->getDBkey() );
00434 $editnotice_base = $editnotice_ns;
00435 while ( count( $parts ) > 0 ) {
00436 $editnotice_base .= '-'.array_shift( $parts );
00437 if ( !wfEmptyMsg( $editnotice_base, wfMsgForContent( $editnotice_base ) ) ) {
00438 $wgOut->addWikiText( wfMsgForContent( $editnotice_base ) );
00439 }
00440 }
00441 }
00442
00443 # Attempt submission here. This will check for edit conflicts,
00444 # and redundantly check for locked database, blocked IPs, etc.
00445 # that edit() already checked just in case someone tries to sneak
00446 # in the back door with a hand-edited submission URL.
00447
00448 if ( 'save' == $this->formtype ) {
00449 if ( !$this->attemptSave() ) {
00450 wfProfileOut( __METHOD__."-business-end" );
00451 wfProfileOut( __METHOD__ );
00452 return;
00453 }
00454 }
00455
00456 # First time through: get contents, set time for conflict
00457 # checking, etc.
00458 if ( 'initial' == $this->formtype || $this->firsttime ) {
00459 if ( $this->initialiseForm() === false) {
00460 $this->noSuchSectionPage();
00461 wfProfileOut( __METHOD__."-business-end" );
00462 wfProfileOut( __METHOD__ );
00463 return;
00464 }
00465 if ( !$this->mTitle->getArticleId() )
00466 wfRunHooks( 'EditFormPreloadText', array( &$this->textbox1, &$this->mTitle ) );
00467 }
00468
00469 $this->showEditForm();
00470 wfProfileOut( __METHOD__."-business-end" );
00471 wfProfileOut( __METHOD__ );
00472 }
00473
00474 protected function getEditPermissionErrors() {
00475 global $wgUser;
00476 $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
00477 # Can this title be created?
00478 if ( !$this->mTitle->exists() ) {
00479 $permErrors = array_merge( $permErrors,
00480 wfArrayDiff2( $this->mTitle->getUserPermissionsErrors( 'create', $wgUser ), $permErrors ) );
00481 }
00482 # Ignore some permissions errors when a user is just previewing/viewing diffs
00483 $remove = array();
00484 foreach( $permErrors as $error ) {
00485 if ( ($this->preview || $this->diff) &&
00486 ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext') )
00487 {
00488 $remove[] = $error;
00489 }
00490 }
00491 $permErrors = wfArrayDiff2( $permErrors, $remove );
00492 return $permErrors;
00493 }
00494
00500 function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
00501 global $wgRequest, $wgOut;
00502 if ( $wgRequest->getBool( 'redlink' ) ) {
00503
00504
00505
00506 $wgOut->redirect( $this->mTitle->getFullUrl() );
00507 } else {
00508 $wgOut->readOnlyPage( $source, $protected, $reasons, $action );
00509 }
00510 }
00511
00517 protected function previewOnOpen() {
00518 global $wgRequest, $wgUser;
00519 if ( $wgRequest->getVal( 'preview' ) == 'yes' ) {
00520
00521 return true;
00522 } elseif ( $wgRequest->getVal( 'preview' ) == 'no' ) {
00523
00524 return false;
00525 } elseif ( $this->section == 'new' ) {
00526
00527 return false;
00528 } elseif ( ( $wgRequest->getVal( 'preload' ) !== null || $this->mTitle->exists() ) && $wgUser->getOption( 'previewonfirst' ) ) {
00529
00530 return true;
00531 } elseif ( !$this->mTitle->exists() && $this->mTitle->getNamespace() == NS_CATEGORY ) {
00532
00533 return true;
00534 } else {
00535 return false;
00536 }
00537 }
00538
00543 function importFormData( &$request ) {
00544 global $wgLang, $wgUser;
00545 $fname = 'EditPage::importFormData';
00546 wfProfileIn( $fname );
00547
00548 # Section edit can come from either the form or a link
00549 $this->section = $request->getVal( 'wpSection', $request->getVal( 'section' ) );
00550
00551 if ( $request->wasPosted() ) {
00552 # These fields need to be checked for encoding.
00553 # Also remove trailing whitespace, but don't remove _initial_
00554 # whitespace from the text boxes. This may be significant formatting.
00555 $this->textbox1 = $this->safeUnicodeInput( $request, 'wpTextbox1' );
00556 $this->textbox2 = $this->safeUnicodeInput( $request, 'wpTextbox2' );
00557 $this->mMetaData = rtrim( $request->getText( 'metadata' ) );
00558 # Truncate for whole multibyte characters. +5 bytes for ellipsis
00559 $this->summary = $wgLang->truncate( $request->getText( 'wpSummary' ), 250, '' );
00560
00561 # Remove extra headings from summaries and new sections.
00562 $this->summary = preg_replace('/^\s*=+\s*(.*?)\s*=+\s*$/', '$1', $this->summary);
00563
00564 $this->edittime = $request->getVal( 'wpEdittime' );
00565 $this->starttime = $request->getVal( 'wpStarttime' );
00566
00567 $this->scrolltop = $request->getIntOrNull( 'wpScrolltop' );
00568
00569 if ( is_null( $this->edittime ) ) {
00570 # If the form is incomplete, force to preview.
00571 wfDebug( "$fname: Form data appears to be incomplete\n" );
00572 wfDebug( "POST DATA: " . var_export( $_POST, true ) . "\n" );
00573 $this->preview = true;
00574 } else {
00575
00576 $this->preview = $request->getCheck( 'wpPreview' ) || $request->getCheck( 'wpLivePreview' );
00577 $this->diff = $request->getCheck( 'wpDiff' );
00578
00579
00580
00581 $this->mTriedSave = !$this->preview;
00582
00583 if ( $this->tokenOk( $request ) ) {
00584 # Some browsers will not report any submit button
00585 # if the user hits enter in the comment box.
00586 # The unmarked state will be assumed to be a save,
00587 # if the form seems otherwise complete.
00588 wfDebug( "$fname: Passed token check.\n" );
00589 } else if ( $this->diff ) {
00590 # Failed token check, but only requested "Show Changes".
00591 wfDebug( "$fname: Failed token check; Show Changes requested.\n" );
00592 } else {
00593 # Page might be a hack attempt posted from
00594 # an external site. Preview instead of saving.
00595 wfDebug( "$fname: Failed token check; forcing preview\n" );
00596 $this->preview = true;
00597 }
00598 }
00599 $this->save = !$this->preview && !$this->diff;
00600 if ( !preg_match( '/^\d{14}$/', $this->edittime )) {
00601 $this->edittime = null;
00602 }
00603
00604 if ( !preg_match( '/^\d{14}$/', $this->starttime )) {
00605 $this->starttime = null;
00606 }
00607
00608 $this->recreate = $request->getCheck( 'wpRecreate' );
00609
00610 $this->minoredit = $request->getCheck( 'wpMinoredit' );
00611 $this->watchthis = $request->getCheck( 'wpWatchthis' );
00612
00613 # Don't force edit summaries when a user is editing their own user or talk page
00614 if ( ( $this->mTitle->mNamespace == NS_USER || $this->mTitle->mNamespace == NS_USER_TALK ) &&
00615 $this->mTitle->getText() == $wgUser->getName() )
00616 {
00617 $this->allowBlankSummary = true;
00618 } else {
00619 $this->allowBlankSummary = $request->getBool( 'wpIgnoreBlankSummary' ) || !$wgUser->getOption( 'forceeditsummary');
00620 }
00621
00622 $this->autoSumm = $request->getText( 'wpAutoSummary' );
00623 } else {
00624 # Not a posted form? Start with nothing.
00625 wfDebug( "$fname: Not a posted form.\n" );
00626 $this->textbox1 = '';
00627 $this->textbox2 = '';
00628 $this->mMetaData = '';
00629 $this->summary = '';
00630 $this->edittime = '';
00631 $this->starttime = wfTimestampNow();
00632 $this->edit = false;
00633 $this->preview = false;
00634 $this->save = false;
00635 $this->diff = false;
00636 $this->minoredit = false;
00637 $this->watchthis = false;
00638 $this->recreate = false;
00639
00640 if ( $this->section == 'new' && $request->getVal( 'preloadtitle' ) ) {
00641 $this->summary = $request->getVal( 'preloadtitle' );
00642 }
00643 elseif ( $this->section != 'new' && $request->getVal( 'summary' ) ) {
00644 $this->summary = $request->getText( 'summary' );
00645 }
00646
00647 if ( $request->getVal( 'minor' ) ) {
00648 $this->minoredit = true;
00649 }
00650 }
00651
00652 $this->oldid = $request->getInt( 'oldid' );
00653
00654 $this->live = $request->getCheck( 'live' );
00655 $this->editintro = $request->getText( 'editintro' );
00656
00657 wfProfileOut( $fname );
00658 }
00659
00667 function tokenOk( &$request ) {
00668 global $wgUser;
00669 $token = $request->getVal( 'wpEditToken' );
00670 $this->mTokenOk = $wgUser->matchEditToken( $token );
00671 $this->mTokenOkExceptSuffix = $wgUser->matchEditTokenNoSuffix( $token );
00672 return $this->mTokenOk;
00673 }
00674
00678 protected function showIntro() {
00679 global $wgOut, $wgUser;
00680 if ( $this->suppressIntro ) {
00681 return;
00682 }
00683
00684 $namespace = $this->mTitle->getNamespace();
00685
00686 if ( $namespace == NS_MEDIAWIKI ) {
00687 # Show a warning if editing an interface message
00688 $wgOut->wrapWikiMsg( "<div class='mw-editinginterface'>\n$1</div>", 'editinginterface' );
00689 }
00690
00691 # Show a warning message when someone creates/edits a user (talk) page but the user does not exists
00692 if ( $namespace == NS_USER || $namespace == NS_USER_TALK ) {
00693 $parts = explode( '/', $this->mTitle->getText(), 2 );
00694 $username = $parts[0];
00695 $id = User::idFromName( $username );
00696 $ip = User::isIP( $username );
00697 if ( $id == 0 && !$ip ) {
00698 $wgOut->wrapWikiMsg( '<div class="mw-userpage-userdoesnotexist error">$1</div>',
00699 array( 'userpage-userdoesnotexist', $username ) );
00700 }
00701 }
00702 # Try to add a custom edit intro, or use the standard one if this is not possible.
00703 if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
00704 if ( $wgUser->isLoggedIn() ) {
00705 $wgOut->wrapWikiMsg( '<div class="mw-newarticletext">$1</div>', 'newarticletext' );
00706 } else {
00707 $wgOut->wrapWikiMsg( '<div class="mw-newarticletextanon">$1</div>', 'newarticletextanon' );
00708 }
00709 }
00710 # Give a notice if the user is editing a deleted page...
00711 if ( !$this->mTitle->exists() ) {
00712 $this->showDeletionLog( $wgOut );
00713 }
00714 }
00715
00721 protected function showCustomIntro() {
00722 if ( $this->editintro ) {
00723 $title = Title::newFromText( $this->editintro );
00724 if ( $title instanceof Title && $title->exists() && $title->userCanRead() ) {
00725 global $wgOut;
00726 $revision = Revision::newFromTitle( $title );
00727 $wgOut->addWikiTextTitleTidy( $revision->getText(), $this->mTitle );
00728 return true;
00729 } else {
00730 return false;
00731 }
00732 } else {
00733 return false;
00734 }
00735 }
00736
00741 function internalAttemptSave( &$result, $bot = false ) {
00742 global $wgFilterCallback, $wgUser, $wgOut, $wgParser;
00743 global $wgMaxArticleSize;
00744
00745 $fname = 'EditPage::attemptSave';
00746 wfProfileIn( $fname );
00747 wfProfileIn( "$fname-checks" );
00748
00749 if ( !wfRunHooks( 'EditPage::attemptSave', array( &$this ) ) )
00750 {
00751 wfDebug( "Hook 'EditPage::attemptSave' aborted article saving\n" );
00752 return self::AS_HOOK_ERROR;
00753 }
00754
00755 # Check image redirect
00756 if ( $this->mTitle->getNamespace() == NS_FILE &&
00757 Title::newFromRedirect( $this->textbox1 ) instanceof Title &&
00758 !$wgUser->isAllowed( 'upload' ) ) {
00759 if ( $wgUser->isAnon() ) {
00760 return self::AS_IMAGE_REDIRECT_ANON;
00761 } else {
00762 return self::AS_IMAGE_REDIRECT_LOGGED;
00763 }
00764 }
00765
00766 # Reintegrate metadata
00767 if ( $this->mMetaData != '' ) $this->textbox1 .= "\n" . $this->mMetaData ;
00768 $this->mMetaData = '' ;
00769
00770 # Check for spam
00771 $match = self::matchSummarySpamRegex( $this->summary );
00772 if ( $match === false ) {
00773 $match = self::matchSpamRegex( $this->textbox1 );
00774 }
00775 if ( $match !== false ) {
00776 $result['spam'] = $match;
00777 $ip = wfGetIP();
00778 $pdbk = $this->mTitle->getPrefixedDBkey();
00779 $match = str_replace( "\n", '', $match );
00780 wfDebugLog( 'SpamRegex', "$ip spam regex hit [[$pdbk]]: \"$match\"" );
00781 wfProfileOut( "$fname-checks" );
00782 wfProfileOut( $fname );
00783 return self::AS_SPAM_ERROR;
00784 }
00785 if ( $wgFilterCallback && $wgFilterCallback( $this->mTitle, $this->textbox1, $this->section, $this->hookError, $this->summary ) ) {
00786 # Error messages or other handling should be performed by the filter function
00787 wfProfileOut( "$fname-checks" );
00788 wfProfileOut( $fname );
00789 return self::AS_FILTERING;
00790 }
00791 if ( !wfRunHooks( 'EditFilter', array( $this, $this->textbox1, $this->section, &$this->hookError, $this->summary ) ) ) {
00792 # Error messages etc. could be handled within the hook...
00793 wfProfileOut( "$fname-checks" );
00794 wfProfileOut( $fname );
00795 return self::AS_HOOK_ERROR;
00796 } elseif ( $this->hookError != '' ) {
00797 # ...or the hook could be expecting us to produce an error
00798 wfProfileOut( "$fname-checks" );
00799 wfProfileOut( $fname );
00800 return self::AS_HOOK_ERROR_EXPECTED;
00801 }
00802 if ( $wgUser->isBlockedFrom( $this->mTitle, false ) ) {
00803 # Check block state against master, thus 'false'.
00804 wfProfileOut( "$fname-checks" );
00805 wfProfileOut( $fname );
00806 return self::AS_BLOCKED_PAGE_FOR_USER;
00807 }
00808 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
00809 if ( $this->kblength > $wgMaxArticleSize ) {
00810
00811 $this->tooBig = true;
00812 wfProfileOut( "$fname-checks" );
00813 wfProfileOut( $fname );
00814 return self::AS_CONTENT_TOO_BIG;
00815 }
00816
00817 if ( !$wgUser->isAllowed('edit') ) {
00818 if ( $wgUser->isAnon() ) {
00819 wfProfileOut( "$fname-checks" );
00820 wfProfileOut( $fname );
00821 return self::AS_READ_ONLY_PAGE_ANON;
00822 }
00823 else {
00824 wfProfileOut( "$fname-checks" );
00825 wfProfileOut( $fname );
00826 return self::AS_READ_ONLY_PAGE_LOGGED;
00827 }
00828 }
00829
00830 if ( wfReadOnly() ) {
00831 wfProfileOut( "$fname-checks" );
00832 wfProfileOut( $fname );
00833 return self::AS_READ_ONLY_PAGE;
00834 }
00835 if ( $wgUser->pingLimiter() ) {
00836 wfProfileOut( "$fname-checks" );
00837 wfProfileOut( $fname );
00838 return self::AS_RATE_LIMITED;
00839 }
00840
00841 # If the article has been deleted while editing, don't save it without
00842 # confirmation
00843 if ( $this->wasDeletedSinceLastEdit() && !$this->recreate ) {
00844 wfProfileOut( "$fname-checks" );
00845 wfProfileOut( $fname );
00846 return self::AS_ARTICLE_WAS_DELETED;
00847 }
00848
00849 wfProfileOut( "$fname-checks" );
00850
00851 # If article is new, insert it.
00852 $aid = $this->mTitle->getArticleID( GAID_FOR_UPDATE );
00853 if ( 0 == $aid ) {
00854
00855 if ( !$this->mTitle->userCan( 'create' ) ) {
00856 wfDebug( "$fname: no create permission\n" );
00857 wfProfileOut( $fname );
00858 return self::AS_NO_CREATE_PERMISSION;
00859 }
00860
00861 # Don't save a new article if it's blank.
00862 if ( '' == $this->textbox1 ) {
00863 wfProfileOut( $fname );
00864 return self::AS_BLANK_ARTICLE;
00865 }
00866
00867
00868 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
00869 # Error messages etc. could be handled within the hook...
00870 wfProfileOut( $fname );
00871 return self::AS_HOOK_ERROR;
00872 }
00873
00874 # Handle the user preference to force summaries here. Check if it's not a redirect.
00875 if ( !$this->allowBlankSummary && !Title::newFromRedirect( $this->textbox1 ) ) {
00876 if ( md5( $this->summary ) == $this->autoSumm ) {
00877 $this->missingSummary = true;
00878 wfProfileOut( $fname );
00879 return self::AS_SUMMARY_NEEDED;
00880 }
00881 }
00882
00883 $isComment = ( $this->section == 'new' );
00884
00885 $this->mArticle->insertNewArticle( $this->textbox1, $this->summary,
00886 $this->minoredit, $this->watchthis, false, $isComment, $bot );
00887
00888 wfProfileOut( $fname );
00889 return self::AS_SUCCESS_NEW_ARTICLE;
00890 }
00891
00892 # Article exists. Check for edit conflict.
00893
00894 $this->mArticle->clear(); # Force reload of dates, etc.
00895 $this->mArticle->forUpdate( true ); # Lock the article
00896
00897 wfDebug("timestamp: {$this->mArticle->getTimestamp()}, edittime: {$this->edittime}\n");
00898
00899 if ( $this->mArticle->getTimestamp() != $this->edittime ) {
00900 $this->isConflict = true;
00901 if ( $this->section == 'new' ) {
00902 if ( $this->mArticle->getUserText() == $wgUser->getName() &&
00903 $this->mArticle->getComment() == $this->summary ) {
00904
00905
00906
00907 wfDebug( "EditPage::editForm duplicate new section submission; trigger edit conflict!\n" );
00908 } else {
00909
00910 $this->isConflict = false;
00911 wfDebug( "EditPage::editForm conflict suppressed; new section\n" );
00912 }
00913 }
00914 }
00915 $userid = $wgUser->getId();
00916
00917 # Suppress edit conflict with self, except for section edits where merging is required.
00918 if ( $this->isConflict && $this->section == '' && $this->userWasLastToEdit($userid,$this->edittime) ) {
00919 wfDebug( "EditPage::editForm Suppressing edit conflict, same user.\n" );
00920 $this->isConflict = false;
00921 }
00922
00923 if ( $this->isConflict ) {
00924 wfDebug( "EditPage::editForm conflict! getting section '$this->section' for time '$this->edittime' (article time '" .
00925 $this->mArticle->getTimestamp() . "')\n" );
00926 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary, $this->edittime );
00927 } else {
00928 wfDebug( "EditPage::editForm getting section '$this->section'\n" );
00929 $text = $this->mArticle->replaceSection( $this->section, $this->textbox1, $this->summary );
00930 }
00931 if ( is_null( $text ) ) {
00932 wfDebug( "EditPage::editForm activating conflict; section replace failed.\n" );
00933 $this->isConflict = true;
00934 $text = $this->textbox1;
00935 } else if ( $this->isConflict ) {
00936 # Attempt merge
00937 if ( $this->mergeChangesInto( $text ) ) {
00938
00939 $this->isConflict = false;
00940 wfDebug( "EditPage::editForm Suppressing edit conflict, successful merge.\n" );
00941 } else {
00942 $this->section = '';
00943 $this->textbox1 = $text;
00944 wfDebug( "EditPage::editForm Keeping edit conflict, failed merge.\n" );
00945 }
00946 }
00947
00948 if ( $this->isConflict ) {
00949 wfProfileOut( $fname );
00950 return self::AS_CONFLICT_DETECTED;
00951 }
00952
00953 $oldtext = $this->mArticle->getContent();
00954
00955
00956 if ( !wfRunHooks( 'EditFilterMerged', array( $this, $text, &$this->hookError, $this->summary ) ) ) {
00957 # Error messages etc. could be handled within the hook...
00958 wfProfileOut( $fname );
00959 return self::AS_HOOK_ERROR;
00960 }
00961
00962 # Handle the user preference to force summaries here, but not for null edits
00963 if ( $this->section != 'new' && !$this->allowBlankSummary && 0 != strcmp($oldtext,$text)
00964 && !Title::newFromRedirect( $text ) ) # check if it's not a redirect
00965 {
00966 if ( md5( $this->summary ) == $this->autoSumm ) {
00967 $this->missingSummary = true;
00968 wfProfileOut( $fname );
00969 return self::AS_SUMMARY_NEEDED;
00970 }
00971 }
00972
00973 # And a similar thing for new sections
00974 if ( $this->section == 'new' && !$this->allowBlankSummary ) {
00975 if (trim($this->summary) == '') {
00976 $this->missingSummary = true;
00977 wfProfileOut( $fname );
00978 return self::AS_SUMMARY_NEEDED;
00979 }
00980 }
00981
00982 # All's well
00983 wfProfileIn( "$fname-sectionanchor" );
00984 $sectionanchor = '';
00985 if ( $this->section == 'new' ) {
00986 if ( $this->textbox1 == '' ) {
00987 $this->missingComment = true;
00988 return self::AS_TEXTBOX_EMPTY;
00989 }
00990 if ( $this->summary != '' ) {
00991 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $this->summary );
00992 # This is a new section, so create a link to the new section
00993 # in the revision summary.
00994 $cleanSummary = $wgParser->stripSectionName( $this->summary );
00995 $this->summary = wfMsgForContent( 'newsectionsummary', $cleanSummary );
00996 }
00997 } elseif ( $this->section != '' ) {
00998 # Try to get a section anchor from the section source, redirect to edited section if header found
00999 # XXX: might be better to integrate this into Article::replaceSection
01000 # for duplicate heading checking and maybe parsing
01001 $hasmatch = preg_match( "/^ *([=]{1,6})(.*?)(\\1) *\\n/i", $this->textbox1, $matches );
01002 # we can't deal with anchors, includes, html etc in the header for now,
01003 # headline would need to be parsed to improve this
01004 if ( $hasmatch and strlen($matches[2]) > 0 ) {
01005 $sectionanchor = $wgParser->guessSectionNameFromWikiText( $matches[2] );
01006 }
01007 }
01008 wfProfileOut( "$fname-sectionanchor" );
01009
01010
01011
01012
01013
01014 $this->textbox1 = $text;
01015 $this->section = '';
01016
01017
01018 $this->kblength = (int)(strlen( $text ) / 1024);
01019 if ( $this->kblength > $wgMaxArticleSize ) {
01020 $this->tooBig = true;
01021 wfProfileOut( $fname );
01022 return self::AS_MAX_ARTICLE_SIZE_EXCEEDED;
01023 }
01024
01025 # update the article here
01026 if ( $this->mArticle->updateArticle( $text, $this->summary, $this->minoredit,
01027 $this->watchthis, $bot, $sectionanchor ) )
01028 {
01029 wfProfileOut( $fname );
01030 return self::AS_SUCCESS_UPDATE;
01031 } else {
01032 $this->isConflict = true;
01033 }
01034 wfProfileOut( $fname );
01035 return self::AS_END;
01036 }
01037
01043 protected function userWasLastToEdit( $id, $edittime ) {
01044 if( !$id ) return false;
01045 $dbw = wfGetDB( DB_MASTER );
01046 $res = $dbw->select( 'revision',
01047 'rev_user',
01048 array(
01049 'rev_page' => $this->mArticle->getId(),
01050 'rev_timestamp > '.$dbw->addQuotes( $dbw->timestamp($edittime) )
01051 ),
01052 __METHOD__,
01053 array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
01054 while( $row = $res->fetchObject() ) {
01055 if( $row->rev_user != $id ) {
01056 return false;
01057 }
01058 }
01059 return true;
01060 }
01061
01066 public static function matchSpamRegex( $text ) {
01067 global $wgSpamRegex;
01068
01069 $regexes = (array)$wgSpamRegex;
01070 return self::matchSpamRegexInternal( $text, $regexes );
01071 }
01072
01077 public static function matchSummarySpamRegex( $text ) {
01078 global $wgSummarySpamRegex;
01079 $regexes = (array)$wgSummarySpamRegex;
01080 return self::matchSpamRegexInternal( $text, $regexes );
01081 }
01082
01083 protected static function matchSpamRegexInternal( $text, $regexes ) {
01084 foreach( $regexes as $regex ) {
01085 $matches = array();
01086 if( preg_match( $regex, $text, $matches ) ) {
01087 return $matches[0];
01088 }
01089 }
01090 return false;
01091 }
01092
01097 function initialiseForm() {
01098 $this->edittime = $this->mArticle->getTimestamp();
01099 $this->textbox1 = $this->getContent( false );
01100 if ( $this->textbox1 === false ) return false;
01101 wfProxyCheck();
01102 return true;
01103 }
01104
01105 function setHeaders() {
01106 global $wgOut, $wgTitle;
01107 $wgOut->setRobotPolicy( 'noindex,nofollow' );
01108 if ( $this->formtype == 'preview' ) {
01109 $wgOut->setPageTitleActionText( wfMsg( 'preview' ) );
01110 }
01111 if ( $this->isConflict ) {
01112 $wgOut->setPageTitle( wfMsg( 'editconflict', $wgTitle->getPrefixedText() ) );
01113 } elseif ( $this->section != '' ) {
01114 $msg = $this->section == 'new' ? 'editingcomment' : 'editingsection';
01115 $wgOut->setPageTitle( wfMsg( $msg, $wgTitle->getPrefixedText() ) );
01116 } else {
01117 # Use the title defined by DISPLAYTITLE magic word when present
01118 if ( isset($this->mParserOutput)
01119 && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
01120 $title = $dt;
01121 } else {
01122 $title = $wgTitle->getPrefixedText();
01123 }
01124 $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
01125 }
01126 }
01127
01134 function showEditForm( $formCallback=null ) {
01135 global $wgOut, $wgUser, $wgLang, $wgContLang, $wgMaxArticleSize, $wgTitle, $wgRequest;
01136
01137 # If $wgTitle is null, that means we're in API mode.
01138 # Some hook probably called this function without checking
01139 # for is_null($wgTitle) first. Bail out right here so we don't
01140 # do lots of work just to discard it right after.
01141 if (is_null($wgTitle))
01142 return;
01143
01144 $fname = 'EditPage::showEditForm';
01145 wfProfileIn( $fname );
01146
01147 $sk = $wgUser->getSkin();
01148
01149 wfRunHooks( 'EditPage::showEditForm:initial', array( &$this ) ) ;
01150
01151 #need to parse the preview early so that we know which templates are used,
01152 #otherwise users with "show preview after edit box" will get a blank list
01153 #we parse this near the beginning so that setHeaders can do the title
01154 #setting work instead of leaving it in getPreviewText
01155 $previewOutput = '';
01156 if ( $this->formtype == 'preview' ) {
01157 $previewOutput = $this->getPreviewText();
01158 }
01159
01160 $this->setHeaders();
01161
01162 # Enabled article-related sidebar, toplinks, etc.
01163 $wgOut->setArticleRelated( true );
01164
01165 if ( $this->isConflict ) {
01166 $wgOut->wrapWikiMsg( "<div class='mw-explainconflict'>\n$1</div>", 'explainconflict' );
01167
01168 $this->textbox2 = $this->textbox1;
01169 $this->textbox1 = $this->getContent();
01170 $this->edittime = $this->mArticle->getTimestamp();
01171 } else {
01172 if ( $this->section != '' && $this->section != 'new' ) {
01173 $matches = array();
01174 if ( !$this->summary && !$this->preview && !$this->diff ) {
01175 preg_match( "/^(=+)(.+)\\1/mi", $this->textbox1, $matches );
01176 if ( !empty( $matches[2] ) ) {
01177 global $wgParser;
01178 $this->summary = "/* " .
01179 $wgParser->stripSectionName(trim($matches[2])) .
01180 " */ ";
01181 }
01182 }
01183 }
01184
01185 if ( $this->missingComment ) {
01186 $wgOut->wrapWikiMsg( '<div id="mw-missingcommenttext">$1</div>', 'missingcommenttext' );
01187 }
01188
01189 if ( $this->missingSummary && $this->section != 'new' ) {
01190 $wgOut->wrapWikiMsg( '<div id="mw-missingsummary">$1</div>', 'missingsummary' );
01191 }
01192
01193 if ( $this->missingSummary && $this->section == 'new' ) {
01194 $wgOut->wrapWikiMsg( '<div id="mw-missingcommentheader">$1</div>', 'missingcommentheader' );
01195 }
01196
01197 if ( $this->hookError !== '' ) {
01198 $wgOut->addWikiText( $this->hookError );
01199 }
01200
01201 if ( !$this->checkUnicodeCompliantBrowser() ) {
01202 $wgOut->addWikiMsg( 'nonunicodebrowser' );
01203 }
01204 if ( isset( $this->mArticle ) && isset( $this->mArticle->mRevision ) ) {
01205
01206
01207 if ( !$this->mArticle->mRevision->userCan( Revision::DELETED_TEXT ) ) {
01208 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
01209 } else if ( $this->mArticle->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
01210 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
01211 }
01212
01213 if ( !$this->mArticle->mRevision->isCurrent() ) {
01214 $this->mArticle->setOldSubtitle( $this->mArticle->mRevision->getId() );
01215 $wgOut->addWikiMsg( 'editingold' );
01216 }
01217 }
01218 }
01219
01220 if ( wfReadOnly() ) {
01221 $wgOut->wrapWikiMsg( "<div id=\"mw-read-only-warning\">\n$1\n</div>", array( 'readonlywarning', wfReadOnlyReason() ) );
01222 } elseif ( $wgUser->isAnon() && $this->formtype != 'preview' ) {
01223 $wgOut->wrapWikiMsg( '<div id="mw-anon-edit-warning">$1</div>', 'anoneditwarning' );
01224 } else {
01225 if ( $this->isCssJsSubpage ) {
01226 # Check the skin exists
01227 if ( $this->isValidCssJsSubpage ) {
01228 if ( $this->formtype !== 'preview' ) {
01229 $wgOut->addWikiMsg( 'usercssjsyoucanpreview' );
01230 }
01231 } else {
01232 $wgOut->addWikiMsg( 'userinvalidcssjstitle', $wgTitle->getSkinFromCssJsSubpage() );
01233 }
01234 }
01235 }
01236
01237 $classes = array();
01238 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
01239 } elseif ( $this->mTitle->isProtected( 'edit' ) ) {
01240 # Is the title semi-protected?
01241 if ( $this->mTitle->isSemiProtected() ) {
01242 $noticeMsg = 'semiprotectedpagewarning';
01243 $classes[] = 'mw-textarea-sprotected';
01244 } else {
01245 # Then it must be protected based on static groups (regular)
01246 $noticeMsg = 'protectedpagewarning';
01247 $classes[] = 'mw-textarea-protected';
01248 }
01249 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
01250 $wgOut->addWikiMsg( $noticeMsg );
01251 LogEventsList::showLogExtract( $wgOut, 'protect', $this->mTitle->getPrefixedText(), '', 1 );
01252 $wgOut->addHTML( "</div>\n" );
01253 }
01254 if ( $this->mTitle->isCascadeProtected() ) {
01255 # Is this page under cascading protection from some source pages?
01256 list($cascadeSources, ) = $this->mTitle->getCascadeProtectionSources();
01257 $notice = "<div class='mw-cascadeprotectedwarning'>$1\n";
01258 $cascadeSourcesCount = count( $cascadeSources );
01259 if ( $cascadeSourcesCount > 0 ) {
01260 # Explain, and list the titles responsible
01261 foreach( $cascadeSources as $page ) {
01262 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
01263 }
01264 }
01265 $notice .= '</div>';
01266 $wgOut->wrapWikiMsg( $notice, array( 'cascadeprotectedwarning', $cascadeSourcesCount ) );
01267 }
01268 if ( !$this->mTitle->exists() && $this->mTitle->getRestrictions( 'create' ) ) {
01269 $wgOut->wrapWikiMsg( '<div class="mw-titleprotectedwarning">$1</div>', 'titleprotectedwarning' );
01270 }
01271
01272 if ( $this->kblength === false ) {
01273 $this->kblength = (int)(strlen( $this->textbox1 ) / 1024);
01274 }
01275 if ( $this->tooBig || $this->kblength > $wgMaxArticleSize ) {
01276 $wgOut->addHTML( "<div class='error' id='mw-edit-longpageerror'>\n" );
01277 $wgOut->addWikiMsg( 'longpageerror', $wgLang->formatNum( $this->kblength ), $wgLang->formatNum( $wgMaxArticleSize ) );
01278 $wgOut->addHTML( "</div>\n" );
01279 } elseif ( $this->kblength > 29 ) {
01280 $wgOut->addHTML( "<div id='mw-edit-longpagewarning'>\n" );
01281 $wgOut->addWikiMsg( 'longpagewarning', $wgLang->formatNum( $this->kblength ) );
01282 $wgOut->addHTML( "</div>\n" );
01283 }
01284
01285 $q = 'action='.$this->action;
01286 #if ( "no" == $redirect ) { $q .= "&redirect=no"; }
01287 $action = $wgTitle->escapeLocalURL( $q );
01288
01289 $summary = wfMsg( 'summary' );
01290 $subject = wfMsg( 'subject' );
01291
01292 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedText(),
01293 wfMsgExt('cancel', array('parseinline')) );
01294 $separator = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
01295 $edithelpurl = Skin::makeInternalOrExternalUrl( wfMsgForContent( 'edithelppage' ));
01296 $edithelp = '<a target="helpwindow" href="'.$edithelpurl.'">'.
01297 htmlspecialchars( wfMsg( 'edithelp' ) ).'</a> '.
01298 htmlspecialchars( wfMsg( 'newwindow' ) );
01299
01300 global $wgRightsText;
01301 if ( $wgRightsText ) {
01302 $copywarnMsg = array( 'copyrightwarning',
01303 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]',
01304 $wgRightsText );
01305 } else {
01306 $copywarnMsg = array( 'copyrightwarning2',
01307 '[[' . wfMsgForContent( 'copyrightpage' ) . ']]' );
01308 }
01309
01310 if ( $wgUser->getOption('showtoolbar') and !$this->isCssJsSubpage ) {
01311 # prepare toolbar for edit buttons
01312 $toolbar = EditPage::getEditToolbar();
01313 } else {
01314 $toolbar = '';
01315 }
01316
01317
01318 if ( !$this->preview && !$this->diff ) {
01319 # Sort out the "watch" checkbox
01320 if ( $wgUser->getOption( 'watchdefault' ) ) {
01321 # Watch all edits
01322 $this->watchthis = true;
01323 } elseif ( $wgUser->getOption( 'watchcreations' ) && !$this->mTitle->exists() ) {
01324 # Watch creations
01325 $this->watchthis = true;
01326 } elseif ( $this->mTitle->userIsWatching() ) {
01327 # Already watched
01328 $this->watchthis = true;
01329 }
01330
01331 # May be overriden by request parameters
01332 if( $wgRequest->getBool( 'watchthis' ) ) {
01333 $this->watchthis = true;
01334 }
01335
01336 if ( $wgUser->getOption( 'minordefault' ) ) $this->minoredit = true;
01337 }
01338
01339 $wgOut->addHTML( $this->editFormPageTop );
01340
01341 if ( $wgUser->getOption( 'previewontop' ) ) {
01342 $this->displayPreviewArea( $previewOutput, true );
01343 }
01344
01345
01346 $wgOut->addHTML( $this->editFormTextTop );
01347
01348 # if this is a comment, show a subject line at the top, which is also the edit summary.
01349 # Otherwise, show a summary field at the bottom
01350 $summarytext = $wgContLang->recodeForEdit( $this->summary );
01351
01352 # If a blank edit summary was previously provided, and the appropriate
01353 # user preference is active, pass a hidden tag as wpIgnoreBlankSummary. This will stop the
01354 # user being bounced back more than once in the event that a summary
01355 # is not required.
01356 #####
01357 # For a bit more sophisticated detection of blank summaries, hash the
01358 # automatic one and pass that in the hidden field wpAutoSummary.
01359 $summaryhiddens = '';
01360 if ( $this->missingSummary ) $summaryhiddens .= Xml::hidden( 'wpIgnoreBlankSummary', true );
01361 $autosumm = $this->autoSumm ? $this->autoSumm : md5( $this->summary );
01362 $summaryhiddens .= Xml::hidden( 'wpAutoSummary', $autosumm );
01363 if ( $this->section == 'new' ) {
01364 $commentsubject = '';
01365 if ( !$wgRequest->getBool( 'nosummary' ) ) {
01366 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
01367 $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
01368
01369 $commentsubject =
01370 Xml::tags( 'label', array( 'for' => 'wpSummary' ), $subject );
01371 $commentsubject =
01372 Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
01373 $commentsubject );
01374 $commentsubject .= ' ';
01375 $commentsubject .= Xml::input( 'wpSummary',
01376 60,
01377 $summarytext,
01378 array(
01379 'id' => 'wpSummary',
01380 'maxlength' => '200',
01381 'tabindex' => '1'
01382 ) );
01383 }
01384 $editsummary = "<div class='editOptions'>\n";
01385 global $wgParser;
01386 $formattedSummary = wfMsgForContent( 'newsectionsummary', $wgParser->stripSectionName( $this->summary ) );
01387 $subjectpreview = $summarytext && $this->preview ? "<div class=\"mw-summary-preview\">". wfMsg('subject-preview') . $sk->commentBlock( $formattedSummary, $this->mTitle, true )."</div>\n" : '';
01388 $summarypreview = '';
01389 } else {
01390 $commentsubject = '';
01391
01392 # Add a class if 'missingsummary' is triggered to allow styling of the summary line
01393 $summaryClass = $this->missingSummary ? 'mw-summarymissed' : 'mw-summary';
01394
01395 $editsummary = Xml::tags( 'label', array( 'for' => 'wpSummary' ), $summary );
01396 $editsummary = Xml::tags( 'span', array( 'class' => $summaryClass, 'id' => "wpSummaryLabel" ),
01397 $editsummary ) . ' ';
01398
01399 $editsummary .= Xml::input( 'wpSummary',
01400 60,
01401 $summarytext,
01402 array(
01403 'id' => 'wpSummary',
01404 'maxlength' => '200',
01405 'tabindex' => '1'
01406 ) );
01407
01408
01409 $editsummary = Xml::openElement( 'div', array( 'class' => 'editOptions' ) )
01410 . $editsummary . '<br/>';
01411
01412 $summarypreview = '';
01413 if ( $summarytext && $this->preview ) {
01414 $summarypreview =
01415 Xml::tags( 'div',
01416 array( 'class' => 'mw-summary-preview' ),
01417 wfMsg( 'summary-preview' ) .
01418 $sk->commentBlock( $this->summary, $this->mTitle )
01419 );
01420 }
01421 $subjectpreview = '';
01422 }
01423 $commentsubject .= $summaryhiddens;
01424
01425 # Set focus to the edit box on load, except on preview or diff, where it would interfere with the display
01426 if ( !$this->preview && !$this->diff ) {
01427 $wgOut->setOnloadHandler( 'document.editform.wpTextbox1.focus()' );
01428 }
01429 $templates = $this->getTemplates();
01430 $formattedtemplates = $sk->formatTemplates( $templates, $this->preview, $this->section != '');
01431
01432 $hiddencats = $this->mArticle->getHiddenCategories();
01433 $formattedhiddencats = $sk->formatHiddenCategories( $hiddencats );
01434
01435 global $wgUseMetadataEdit ;
01436 if ( $wgUseMetadataEdit ) {
01437 $metadata = $this->mMetaData ;
01438 $metadata = htmlspecialchars( $wgContLang->recodeForEdit( $metadata ) ) ;
01439 $top = wfMsgWikiHtml( 'metadata_help' );
01440
01441 $ew = $wgUser->getOption( 'editwidth' );
01442 if ( $ew ) $ew = " style=\"width:100%\"";
01443 else $ew = '';
01444 $cols = $wgUser->getIntOption( 'cols' );
01445
01446 $metadata = $top . "<textarea name='metadata' rows='3' cols='{$cols}'{$ew}>{$metadata}</textarea>" ;
01447 }
01448 else $metadata = "" ;
01449
01450 $recreate = '';
01451 if ( $this->wasDeletedSinceLastEdit() ) {
01452 if ( 'save' != $this->formtype ) {
01453 $wgOut->wrapWikiMsg(
01454 "<div class='error mw-deleted-while-editing'>\n$1</div>",
01455 'deletedwhileediting' );
01456 } else {
01457
01458
01459 $toolbar = '';
01460 $recreate = '<div class="mw-confirm-recreate">' .
01461 $wgOut->parse( wfMsg( 'confirmrecreate', $this->lastDelete->user_name , $this->lastDelete->log_comment ) ) .
01462 Xml::checkLabel( wfMsg( 'recreate' ), 'wpRecreate', 'wpRecreate', false,
01463 array( 'title' => $sk->titleAttrib( 'recreate' ), 'tabindex' => 1, 'id' => 'wpRecreate' )
01464 ) . '</div>';
01465 }
01466 }
01467
01468 $tabindex = 2;
01469
01470 $checkboxes = $this->getCheckboxes( $tabindex, $sk,
01471 array( 'minor' => $this->minoredit, 'watch' => $this->watchthis ) );
01472
01473 $checkboxhtml = implode( $checkboxes, "\n" );
01474
01475 $buttons = $this->getEditButtons( $tabindex );
01476 $buttonshtml = implode( $buttons, "\n" );
01477
01478 $safemodehtml = $this->checkUnicodeCompliantBrowser()
01479 ? '' : Xml::hidden( 'safemode', '1' );
01480
01481 $wgOut->addHTML( <<<END
01482 {$toolbar}
01483 <form id="editform" name="editform" method="post" action="$action" enctype="multipart/form-data">
01484 END
01485 );
01486
01487 if ( is_callable( $formCallback ) ) {
01488 call_user_func_array( $formCallback, array( &$wgOut ) );
01489 }
01490
01491 wfRunHooks( 'EditPage::showEditForm:fields', array( &$this, &$wgOut ) );
01492
01493
01494 $this->showFormBeforeText();
01495
01496 $wgOut->addHTML( <<<END
01497 {$recreate}
01498 {$commentsubject}
01499 {$subjectpreview}
01500 {$this->editFormTextBeforeContent}
01501 END
01502 );
01503 $this->showTextbox1( $classes );
01504
01505 $wgOut->wrapWikiMsg( "<div id=\"editpage-copywarn\">\n$1\n</div>", $copywarnMsg );
01506 $wgOut->addHTML( <<<END
01507 {$this->editFormTextAfterWarn}
01508 {$metadata}
01509 {$editsummary}
01510 {$summarypreview}
01511 {$checkboxhtml}
01512 {$safemodehtml}
01513 END
01514 );
01515
01516 $wgOut->addHTML(
01517 "<div class='editButtons'>
01518 {$buttonshtml}
01519 <span class='editHelp'>{$cancel}{$separator}{$edithelp}</span>
01520 </div><!-- editButtons -->
01521 </div><!-- editOptions -->");
01522
01535 $token = htmlspecialchars( $wgUser->editToken() );
01536 $wgOut->addHTML( "\n<input type='hidden' value=\"$token\" name=\"wpEditToken\" />\n" );
01537
01538 $this->showEditTools();
01539
01540 $wgOut->addHTML( <<<END
01541 {$this->editFormTextAfterTools}
01542 <div class='templatesUsed'>
01543 {$formattedtemplates}
01544 </div>
01545 <div class='hiddencats'>
01546 {$formattedhiddencats}
01547 </div>
01548 END
01549 );
01550
01551 if ( $this->isConflict && wfRunHooks( 'EditPageBeforeConflictDiff', array( &$this, &$wgOut ) ) ) {
01552 $wgOut->wrapWikiMsg( '==$1==', "yourdiff" );
01553
01554 $de = new DifferenceEngine( $this->mTitle );
01555 $de->setText( $this->textbox2, $this->textbox1 );
01556 $de->showDiff( wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
01557
01558 $wgOut->wrapWikiMsg( '==$1==', "yourtext" );
01559 $this->showTextbox2();
01560 }
01561 $wgOut->addHTML( $this->editFormTextBottom );
01562 $wgOut->addHTML( "</form>\n" );
01563 if ( !$wgUser->getOption( 'previewontop' ) ) {
01564 $this->displayPreviewArea( $previewOutput, false );
01565 }
01566
01567 wfProfileOut( $fname );
01568 }
01569
01570 protected function showFormBeforeText() {
01571 global $wgOut;
01572 $wgOut->addHTML( "
01573 <input type='hidden' value=\"" . htmlspecialchars( $this->section ) . "\" name=\"wpSection\" />
01574 <input type='hidden' value=\"{$this->starttime}\" name=\"wpStarttime\" />\n
01575 <input type='hidden' value=\"{$this->edittime}\" name=\"wpEdittime\" />\n
01576 <input type='hidden' value=\"{$this->scrolltop}\" name=\"wpScrolltop\" id=\"wpScrolltop\" />\n" );
01577 }
01578
01579 protected function showTextbox1( $classes ) {
01580 $attribs = array( 'tabindex' => 1 );
01581
01582 if ( $this->wasDeletedSinceLastEdit() )
01583 $attribs['type'] = 'hidden';
01584 if ( !empty($classes) )
01585 $attribs['class'] = implode(' ',$classes);
01586
01587 $this->showTextbox( $this->textbox1, 'wpTextbox1', $attribs );
01588 }
01589
01590 protected function showTextbox2() {
01591 $this->showTextbox( $this->textbox2, 'wpTextbox2', array( 'tabindex' => 6 ) );
01592 }
01593
01594 protected function showTextbox( $content, $name, $attribs = array() ) {
01595 global $wgOut, $wgUser;
01596
01597 $wikitext = $this->safeUnicodeOutput( $content );
01598 if ( $wikitext !== '' ) {
01599
01600
01601
01602
01603 $wikitext .= "\n";
01604 }
01605
01606 $attribs['accesskey'] = ',';
01607 $attribs['id'] = $name;
01608
01609 if ( $wgUser->getOption( 'editwidth' ) )
01610 $attribs['style'] = 'width: 100%';
01611
01612 $wgOut->addHTML( Xml::textarea(
01613 $name,
01614 $wikitext,
01615 $wgUser->getIntOption( 'cols' ), $wgUser->getIntOption( 'rows' ),
01616 $attribs ) );
01617 }
01618
01619 protected function displayPreviewArea( $previewOutput, $isOnTop = false ) {
01620 global $wgOut;
01621 $classes = array();
01622 if ( $isOnTop )
01623 $classes[] = 'ontop';
01624
01625 $attribs = array( 'id' => 'wikiPreview', 'class' => implode( ' ', $classes ) );
01626
01627 if ( $this->formtype != 'preview' )
01628 $attribs['style'] = 'display: none;';
01629
01630 $wgOut->addHTML( Xml::openElement( 'div', $attribs ) );
01631
01632 if ( $this->formtype == 'preview' ) {
01633 $this->showPreview( $previewOutput );
01634 }
01635
01636 $wgOut->addHTML( '</div>' );
01637
01638 if ( $this->formtype == 'diff') {
01639 $this->showDiff();
01640 }
01641 }
01642
01649 protected function showPreview( $text ) {
01650 global $wgOut;
01651 if ( $this->mTitle->getNamespace() == NS_CATEGORY) {
01652 $this->mArticle->openShowCategory();
01653 }
01654 # This hook seems slightly odd here, but makes things more
01655 # consistent for extensions.
01656 wfRunHooks( 'OutputPageBeforeHTML',array( &$wgOut, &$text ) );
01657 $wgOut->addHTML( $text );
01658 if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
01659 $this->mArticle->closeShowCategory();
01660 }
01661 }
01662
01673 function doLivePreviewScript() {
01674 global $wgOut, $wgTitle;
01675 $wgOut->addScriptFile( 'preview.js' );
01676 $liveAction = $wgTitle->getLocalUrl( "action={$this->action}&wpPreview=true&live=true" );
01677 return "return !lpDoPreview(" .
01678 "editform.wpTextbox1.value," .
01679 '"' . $liveAction . '"' . ")";
01680 }
01681
01682 protected function showEditTools() {
01683 global $wgOut;
01684 $wgOut->addHTML( '<div class="mw-editTools">' );
01685 $wgOut->addWikiMsgArray( 'edittools', array(), array( 'content' ) );
01686 $wgOut->addHTML( '</div>' );
01687 }
01688
01689 protected function getLastDelete() {
01690 $dbr = wfGetDB( DB_SLAVE );
01691 $data = $dbr->selectRow(
01692 array( 'logging', 'user' ),
01693 array( 'log_type',
01694 'log_action',
01695 'log_timestamp',
01696 'log_user',
01697 'log_namespace',
01698 'log_title',
01699 'log_comment',
01700 'log_params',
01701 'log_deleted',
01702 'user_name' ),
01703 array( 'log_namespace' => $this->mTitle->getNamespace(),
01704 'log_title' => $this->mTitle->getDBkey(),
01705 'log_type' => 'delete',
01706 'log_action' => 'delete',
01707 'user_id=log_user' ),
01708 __METHOD__,
01709 array( 'LIMIT' => 1, 'ORDER BY' => 'log_timestamp DESC' )
01710 );
01711
01712 if( is_object($data) ) {
01713 if( $data->log_deleted & LogPage::DELETED_USER )
01714 $data->user_name = wfMsgHtml('rev-deleted-user');
01715 if( $data->log_deleted & LogPage::DELETED_COMMENT )
01716 $data->log_comment = wfMsgHtml('rev-deleted-comment');
01717 }
01718 return $data;
01719 }
01720
01725 function getPreviewText() {
01726 global $wgOut, $wgUser, $wgTitle, $wgParser, $wgLang, $wgContLang, $wgMessageCache;
01727
01728 wfProfileIn( __METHOD__ );
01729
01730 if ( $this->mTriedSave && !$this->mTokenOk ) {
01731 if ( $this->mTokenOkExceptSuffix ) {
01732 $note = wfMsg( 'token_suffix_mismatch' );
01733 } else {
01734 $note = wfMsg( 'session_fail_preview' );
01735 }
01736 } else {
01737 $note = wfMsg( 'previewnote' );
01738 }
01739
01740 $parserOptions = ParserOptions::newFromUser( $wgUser );
01741 $parserOptions->setEditSection( false );
01742 $parserOptions->setIsPreview( true );
01743 $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
01744
01745 global $wgRawHtml;
01746 if ( $wgRawHtml && !$this->mTokenOk ) {
01747
01748
01749 return $wgOut->parse( "<div class='previewnote'>" .
01750 wfMsg( 'session_fail_preview_html' ) . "</div>" );
01751 }
01752
01753 # don't parse user css/js, show message about preview
01754 # XXX: stupid php bug won't let us use $wgTitle->isCssJsSubpage() here
01755
01756 if ( $this->isCssJsSubpage ) {
01757 if (preg_match("/\\.css$/", $this->mTitle->getText() ) ) {
01758 $previewtext = wfMsg('usercsspreview');
01759 } else if (preg_match("/\\.js$/", $this->mTitle->getText() ) ) {
01760 $previewtext = wfMsg('userjspreview');
01761 }
01762 $parserOptions->setTidy(true);
01763 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
01764 $previewHTML = $parserOutput->mText;
01765 } elseif ( $rt = Title::newFromRedirectArray( $this->textbox1 ) ) {
01766 $previewHTML = $this->mArticle->viewRedirect( $rt, false );
01767 } else {
01768 $toparse = $this->textbox1;
01769
01770 # If we're adding a comment, we need to show the
01771 # summary as the headline
01772 if ( $this->section=="new" && $this->summary!="" ) {
01773 $toparse="== {$this->summary} ==\n\n".$toparse;
01774 }
01775
01776 if ( $this->mMetaData != "" ) $toparse .= "\n" . $this->mMetaData;
01777
01778
01779 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
01780 list( , $lang ) = $wgMessageCache->figureMessage( $this->mTitle->getText() );
01781 $obj = wfGetLangObj( $lang );
01782 $parserOptions->setTargetLanguage( $obj );
01783 }
01784
01785
01786 $parserOptions->setTidy(true);
01787 $parserOptions->enableLimitReport();
01788 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
01789 $this->mTitle, $parserOptions );
01790
01791 $previewHTML = $parserOutput->getText();
01792 $this->mParserOutput = $parserOutput;
01793 $wgOut->addParserOutputNoText( $parserOutput );
01794
01795 if ( count( $parserOutput->getWarnings() ) ) {
01796 $note .= "\n\n" . implode( "\n\n", $parserOutput->getWarnings() );
01797 }
01798 }
01799
01800 $previewhead = '<h2>' . htmlspecialchars( wfMsg( 'preview' ) ) . "</h2>\n" .
01801 "<div class='previewnote'>" . $wgOut->parse( $note ) . "</div>\n";
01802 if ( $this->isConflict ) {
01803 $previewhead .='<h2>' . htmlspecialchars( wfMsg( 'previewconflict' ) ) . "</h2>\n";
01804 }
01805
01806 wfProfileOut( __METHOD__ );
01807 return $previewhead . $previewHTML;
01808 }
01809
01810 function getTemplates() {
01811 if ( $this->preview || $this->section != '' ) {
01812 $templates = array();
01813 if ( !isset($this->mParserOutput) ) return $templates;
01814 foreach( $this->mParserOutput->getTemplates() as $ns => $template) {
01815 foreach( array_keys( $template ) as $dbk ) {
01816 $templates[] = Title::makeTitle($ns, $dbk);
01817 }
01818 }
01819 return $templates;
01820 } else {
01821 return $this->mArticle->getUsedTemplates();
01822 }
01823 }
01824
01828 function blockedPage() {
01829 global $wgOut, $wgUser;
01830 $wgOut->blockedPage( false ); # Standard block notice on the top, don't 'return'
01831
01832 # If the user made changes, preserve them when showing the markup
01833 # (This happens when a user is blocked during edit, for instance)
01834 $first = $this->firsttime || ( !$this->save && $this->textbox1 == '' );
01835 if ( $first ) {
01836 $source = $this->mTitle->exists() ? $this->getContent() : false;
01837 } else {
01838 $source = $this->textbox1;
01839 }
01840
01841 # Spit out the source or the user's modified version
01842 if ( $source !== false ) {
01843 $rows = $wgUser->getIntOption( 'rows' );
01844 $cols = $wgUser->getIntOption( 'cols' );
01845 $attribs = array( 'id' => 'wpTextbox1', 'name' => 'wpTextbox1', 'cols' => $cols, 'rows' => $rows, 'readonly' => 'readonly' );
01846 $wgOut->addHTML( '<hr />' );
01847 $wgOut->addWikiMsg( $first ? 'blockedoriginalsource' : 'blockededitsource', $this->mTitle->getPrefixedText() );
01848 # Why we don't use Xml::element here?
01849 # Is it because if $source is '', it returns <textarea />?
01850 $wgOut->addHTML( Xml::openElement( 'textarea', $attribs ) . htmlspecialchars( $source ) . Xml::closeElement( 'textarea' ) );
01851 }
01852 }
01853
01857 function userNotLoggedInPage() {
01858 global $wgUser, $wgOut, $wgTitle;
01859 $skin = $wgUser->getSkin();
01860
01861 $loginTitle = SpecialPage::getTitleFor( 'Userlogin' );
01862 $loginLink = $skin->makeKnownLinkObj( $loginTitle, wfMsgHtml( 'loginreqlink' ), 'returnto=' . $wgTitle->getPrefixedUrl() );
01863
01864 $wgOut->setPageTitle( wfMsg( 'whitelistedittitle' ) );
01865 $wgOut->setRobotPolicy( 'noindex,nofollow' );
01866 $wgOut->setArticleRelated( false );
01867
01868 $wgOut->addHTML( wfMsgWikiHtml( 'whitelistedittext', $loginLink ) );
01869 $wgOut->returnToMain( false, $wgTitle );
01870 }
01871
01876 function noSuchSectionPage() {
01877 global $wgOut, $wgTitle;
01878
01879 $wgOut->setPageTitle( wfMsg( 'nosuchsectiontitle' ) );
01880 $wgOut->setRobotPolicy( 'noindex,nofollow' );
01881 $wgOut->setArticleRelated( false );
01882
01883 $wgOut->addWikiMsg( 'nosuchsectiontext', $this->section );
01884 $wgOut->returnToMain( false, $wgTitle );
01885 }
01886
01892 function spamPage( $match = false ) {
01893 global $wgOut, $wgTitle;
01894
01895 $wgOut->setPageTitle( wfMsg( 'spamprotectiontitle' ) );
01896 $wgOut->setRobotPolicy( 'noindex,nofollow' );
01897 $wgOut->setArticleRelated( false );
01898
01899 $wgOut->addHTML( '<div id="spamprotected">' );
01900 $wgOut->addWikiMsg( 'spamprotectiontext' );
01901 if ( $match )
01902 $wgOut->addWikiMsg( 'spamprotectionmatch', wfEscapeWikiText( $match ) );
01903 $wgOut->addHTML( '</div>' );
01904
01905 $wgOut->returnToMain( false, $wgTitle );
01906 }
01907
01912 function mergeChangesInto( &$editText ){
01913 $fname = 'EditPage::mergeChangesInto';
01914 wfProfileIn( $fname );
01915
01916 $db = wfGetDB( DB_MASTER );
01917
01918
01919 $baseRevision = $this->getBaseRevision();
01920 if ( is_null( $baseRevision ) ) {
01921 wfProfileOut( $fname );
01922 return false;
01923 }
01924 $baseText = $baseRevision->getText();
01925
01926
01927 $currentRevision = Revision::loadFromTitle( $db, $this->mTitle );
01928 if ( is_null( $currentRevision ) ) {
01929 wfProfileOut( $fname );
01930 return false;
01931 }
01932 $currentText = $currentRevision->getText();
01933
01934 $result = '';
01935 if ( wfMerge( $baseText, $editText, $currentText, $result ) ) {
01936 $editText = $result;
01937 wfProfileOut( $fname );
01938 return true;
01939 } else {
01940 wfProfileOut( $fname );
01941 return false;
01942 }
01943 }
01944
01952 function checkUnicodeCompliantBrowser() {
01953 global $wgBrowserBlackList;
01954 if ( empty( $_SERVER["HTTP_USER_AGENT"] ) ) {
01955
01956 return true;
01957 }
01958 $currentbrowser = $_SERVER["HTTP_USER_AGENT"];
01959 foreach ( $wgBrowserBlackList as $browser ) {
01960 if ( preg_match($browser, $currentbrowser) ) {
01961 return false;
01962 }
01963 }
01964 return true;
01965 }
01966
01970 function pseudoParseSectionAnchor( $text ) {
01971 global $wgParser;
01972 return $wgParser->stripSectionName( $text );
01973 }
01974
01981 function sectionAnchor( $text ) {
01982 global $wgParser;
01983 return $wgParser->guessSectionNameFromWikiText( $text );
01984 }
01985
01993 static function getEditToolbar() {
01994 global $wgStylePath, $wgContLang, $wgLang, $wgJsMimeType;
01995
02007 $toolarray = array(
02008 array(
02009 'image' => $wgLang->getImageFile('button-bold'),
02010 'id' => 'mw-editbutton-bold',
02011 'open' => '\'\'\'',
02012 'close' => '\'\'\'',
02013 'sample' => wfMsg('bold_sample'),
02014 'tip' => wfMsg('bold_tip'),
02015 'key' => 'B'
02016 ),
02017 array(
02018 'image' => $wgLang->getImageFile('button-italic'),
02019 'id' => 'mw-editbutton-italic',
02020 'open' => '\'\'',
02021 'close' => '\'\'',
02022 'sample' => wfMsg('italic_sample'),
02023 'tip' => wfMsg('italic_tip'),
02024 'key' => 'I'
02025 ),
02026 array(
02027 'image' => $wgLang->getImageFile('button-link'),
02028 'id' => 'mw-editbutton-link',
02029 'open' => '[[',
02030 'close' => ']]',
02031 'sample' => wfMsg('link_sample'),
02032 'tip' => wfMsg('link_tip'),
02033 'key' => 'L'
02034 ),
02035 array(
02036 'image' => $wgLang->getImageFile('button-extlink'),
02037 'id' => 'mw-editbutton-extlink',
02038 'open' => '[',
02039 'close' => ']',
02040 'sample' => wfMsg('extlink_sample'),
02041 'tip' => wfMsg('extlink_tip'),
02042 'key' => 'X'
02043 ),
02044 array(
02045 'image' => $wgLang->getImageFile('button-headline'),
02046 'id' => 'mw-editbutton-headline',
02047 'open' => "\n== ",
02048 'close' => " ==\n",
02049 'sample' => wfMsg('headline_sample'),
02050 'tip' => wfMsg('headline_tip'),
02051 'key' => 'H'
02052 ),
02053 array(
02054 'image' => $wgLang->getImageFile('button-image'),
02055 'id' => 'mw-editbutton-image',
02056 'open' => '[['.$wgContLang->getNsText(NS_FILE).':',
02057 'close' => ']]',
02058 'sample' => wfMsg('image_sample'),
02059 'tip' => wfMsg('image_tip'),
02060 'key' => 'D'
02061 ),
02062 array(
02063 'image' => $wgLang->getImageFile('button-media'),
02064 'id' => 'mw-editbutton-media',
02065 'open' => '[['.$wgContLang->getNsText(NS_MEDIA).':',
02066 'close' => ']]',
02067 'sample' => wfMsg('media_sample'),
02068 'tip' => wfMsg('media_tip'),
02069 'key' => 'M'
02070 ),
02071 array(
02072 'image' => $wgLang->getImageFile('button-math'),
02073 'id' => 'mw-editbutton-math',
02074 'open' => "<math>",
02075 'close' => "</math>",
02076 'sample' => wfMsg('math_sample'),
02077 'tip' => wfMsg('math_tip'),
02078 'key' => 'C'
02079 ),
02080 array(
02081 'image' => $wgLang->getImageFile('button-nowiki'),
02082 'id' => 'mw-editbutton-nowiki',
02083 'open' => "<nowiki>",
02084 'close' => "</nowiki>",
02085 'sample' => wfMsg('nowiki_sample'),
02086 'tip' => wfMsg('nowiki_tip'),
02087 'key' => 'N'
02088 ),
02089 array(
02090 'image' => $wgLang->getImageFile('button-sig'),
02091 'id' => 'mw-editbutton-signature',
02092 'open' => '--~~~~',
02093 'close' => '',
02094 'sample' => '',
02095 'tip' => wfMsg('sig_tip'),
02096 'key' => 'Y'
02097 ),
02098 array(
02099 'image' => $wgLang->getImageFile('button-hr'),
02100 'id' => 'mw-editbutton-hr',
02101 'open' => "\n----\n",
02102 'close' => '',
02103 'sample' => '',
02104 'tip' => wfMsg('hr_tip'),
02105 'key' => 'R'
02106 )
02107 );
02108 $toolbar = "<div id='toolbar'>\n";
02109 $toolbar.="<script type='$wgJsMimeType'>\n/*<![CDATA[*/\n";
02110
02111 foreach($toolarray as $tool) {
02112 $params = array(
02113 $image = $wgStylePath.'/common/images/'.$tool['image'],
02114
02115
02116
02117
02118 $tip = $tool['tip'],
02119 $open = $tool['open'],
02120 $close = $tool['close'],
02121 $sample = $tool['sample'],
02122 $cssId = $tool['id'],
02123 );
02124
02125 $paramList = implode( ',',
02126 array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
02127 $toolbar.="addButton($paramList);\n";
02128 }
02129
02130 $toolbar.="/*]]>*/\n</script>";
02131 $toolbar.="\n</div>";
02132 return $toolbar;
02133 }
02134
02146 public function getCheckboxes( &$tabindex, $skin, $checked ) {
02147 global $wgUser;
02148
02149 $checkboxes = array();
02150
02151 $checkboxes['minor'] = '';
02152 $minorLabel = wfMsgExt('minoredit', array('parseinline'));
02153 if ( $wgUser->isAllowed('minoredit') ) {
02154 $attribs = array(
02155 'tabindex' => ++$tabindex,
02156 'accesskey' => wfMsg( 'accesskey-minoredit' ),
02157 'id' => 'wpMinoredit',
02158 );
02159 $checkboxes['minor'] =
02160 Xml::check( 'wpMinoredit', $checked['minor'], $attribs ) .
02161 " <label for='wpMinoredit'".$skin->tooltip('minoredit', 'withaccess').">{$minorLabel}</label>";
02162 }
02163
02164 $watchLabel = wfMsgExt('watchthis', array('parseinline'));
02165 $checkboxes['watch'] = '';
02166 if ( $wgUser->isLoggedIn() ) {
02167 $attribs = array(
02168 'tabindex' => ++$tabindex,
02169 'accesskey' => wfMsg( 'accesskey-watch' ),
02170 'id' => 'wpWatchthis',
02171 );
02172 $checkboxes['watch'] =
02173 Xml::check( 'wpWatchthis', $checked['watch'], $attribs ) .
02174 " <label for='wpWatchthis'".$skin->tooltip('watch', 'withaccess').">{$watchLabel}</label>";
02175 }
02176 wfRunHooks( 'EditPageBeforeEditChecks', array( &$this, &$checkboxes, &$tabindex ) );
02177 return $checkboxes;
02178 }
02179
02188 public function getEditButtons(&$tabindex) {
02189 global $wgLivePreview, $wgUser;
02190
02191 $buttons = array();
02192
02193 $temp = array(
02194 'id' => 'wpSave',
02195 'name' => 'wpSave',
02196 'type' => 'submit',
02197 'tabindex' => ++$tabindex,
02198 'value' => wfMsg('savearticle'),
02199 'accesskey' => wfMsg('accesskey-save'),
02200 'title' => wfMsg( 'tooltip-save' ).' ['.wfMsg( 'accesskey-save' ).']',
02201 );
02202 $buttons['save'] = Xml::element('input', $temp, '');
02203
02204 ++$tabindex;
02205 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
02206 $temp = array(
02207 'id' => 'wpPreview',
02208 'name' => 'wpPreview',
02209 'type' => 'submit',
02210 'tabindex' => $tabindex,
02211 'value' => wfMsg('showpreview'),
02212 'accesskey' => '',
02213 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
02214 'style' => 'display: none;',
02215 );
02216 $buttons['preview'] = Xml::element('input', $temp, '');
02217
02218 $temp = array(
02219 'id' => 'wpLivePreview',
02220 'name' => 'wpLivePreview',
02221 'type' => 'submit',
02222 'tabindex' => $tabindex,
02223 'value' => wfMsg('showlivepreview'),
02224 'accesskey' => wfMsg('accesskey-preview'),
02225 'title' => '',
02226 'onclick' => $this->doLivePreviewScript(),
02227 );
02228 $buttons['live'] = Xml::element('input', $temp, '');
02229 } else {
02230 $temp = array(
02231 'id' => 'wpPreview',
02232 'name' => 'wpPreview',
02233 'type' => 'submit',
02234 'tabindex' => $tabindex,
02235 'value' => wfMsg('showpreview'),
02236 'accesskey' => wfMsg('accesskey-preview'),
02237 'title' => wfMsg( 'tooltip-preview' ).' ['.wfMsg( 'accesskey-preview' ).']',
02238 );
02239 $buttons['preview'] = Xml::element('input', $temp, '');
02240 $buttons['live'] = '';
02241 }
02242
02243 $temp = array(
02244 'id' => 'wpDiff',
02245 'name' => 'wpDiff',
02246 'type' => 'submit',
02247 'tabindex' => ++$tabindex,
02248 'value' => wfMsg('showdiff'),
02249 'accesskey' => wfMsg('accesskey-diff'),
02250 'title' => wfMsg( 'tooltip-diff' ).' ['.wfMsg( 'accesskey-diff' ).']',
02251 );
02252 $buttons['diff'] = Xml::element('input', $temp, '');
02253
02254 wfRunHooks( 'EditPageBeforeEditButtons', array( &$this, &$buttons, &$tabindex ) );
02255 return $buttons;
02256 }
02257
02270 function livePreview() {
02271 global $wgOut;
02272 $wgOut->disable();
02273 header( 'Content-type: text/xml; charset=utf-8' );
02274 header( 'Cache-control: no-cache' );
02275
02276 $previewText = $this->getPreviewText();
02277 #$categories = $skin->getCategoryLinks();
02278
02279 $s =
02280 '<?xml version="1.0" encoding="UTF-8" ?>' . "\n" .
02281 Xml::tags( 'livepreview', null,
02282 Xml::element( 'preview', null, $previewText )
02283 #. Xml::element( 'category', null, $categories )
02284 );
02285 echo $s;
02286 }
02287
02288
02296 function showDiff() {
02297 $oldtext = $this->mArticle->fetchContent();
02298 $newtext = $this->mArticle->replaceSection(
02299 $this->section, $this->textbox1, $this->summary, $this->edittime );
02300 $newtext = $this->mArticle->preSaveTransform( $newtext );
02301 $oldtitle = wfMsgExt( 'currentrev', array('parseinline') );
02302 $newtitle = wfMsgExt( 'yourtext', array('parseinline') );
02303 if ( $oldtext !== false || $newtext != '' ) {
02304 $de = new DifferenceEngine( $this->mTitle );
02305 $de->setText( $oldtext, $newtext );
02306 $difftext = $de->getDiff( $oldtitle, $newtitle );
02307 $de->showDiffStyle();
02308 } else {
02309 $difftext = '';
02310 }
02311
02312 global $wgOut;
02313 $wgOut->addHTML( '<div id="wikiDiff">' . $difftext . '</div>' );
02314 }
02315
02325 function safeUnicodeInput( $request, $field ) {
02326 $text = rtrim( $request->getText( $field ) );
02327 return $request->getBool( 'safemode' )
02328 ? $this->unmakesafe( $text )
02329 : $text;
02330 }
02331
02340 function safeUnicodeOutput( $text ) {
02341 global $wgContLang;
02342 $codedText = $wgContLang->recodeForEdit( $text );
02343 return $this->checkUnicodeCompliantBrowser()
02344 ? $codedText
02345 : $this->makesafe( $codedText );
02346 }
02347
02361 function makesafe( $invalue ) {
02362
02363 $invalue = strtr( $invalue, array( "&#x" => "�" ) );
02364
02365 $bytesleft = 0;
02366 $result = "";
02367 $working = 0;
02368 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
02369 $bytevalue = ord( $invalue{$i} );
02370 if ( $bytevalue <= 0x7F ) {
02371 $result .= chr( $bytevalue );
02372 $bytesleft = 0;
02373 } elseif ( $bytevalue <= 0xBF ) {
02374 $working = $working << 6;
02375 $working += ($bytevalue & 0x3F);
02376 $bytesleft--;
02377 if ( $bytesleft <= 0 ) {
02378 $result .= "&#x" . strtoupper( dechex( $working ) ) . ";";
02379 }
02380 } elseif ( $bytevalue <= 0xDF ) {
02381 $working = $bytevalue & 0x1F;
02382 $bytesleft = 1;
02383 } elseif ( $bytevalue <= 0xEF ) {
02384 $working = $bytevalue & 0x0F;
02385 $bytesleft = 2;
02386 } else {
02387 $working = $bytevalue & 0x07;
02388 $bytesleft = 3;
02389 }
02390 }
02391 return $result;
02392 }
02393
02403 function unmakesafe( $invalue ) {
02404 $result = "";
02405 for( $i = 0; $i < strlen( $invalue ); $i++ ) {
02406 if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue{$i+3} != '0' ) ) {
02407 $i += 3;
02408 $hexstring = "";
02409 do {
02410 $hexstring .= $invalue{$i};
02411 $i++;
02412 } while( ctype_xdigit( $invalue{$i} ) && ( $i < strlen( $invalue ) ) );
02413
02414
02415
02416
02417 if ( (substr($invalue,$i,1)==";") and (strlen($hexstring) <= 6) ) {
02418 $codepoint = hexdec($hexstring);
02419 $result .= codepointToUtf8( $codepoint );
02420 } else {
02421 $result .= "&#x" . $hexstring . substr( $invalue, $i, 1 );
02422 }
02423 } else {
02424 $result .= substr( $invalue, $i, 1 );
02425 }
02426 }
02427
02428 return strtr( $result, array( "�" => "&#x" ) );
02429 }
02430
02431 function noCreatePermission() {
02432 global $wgOut;
02433 $wgOut->setPageTitle( wfMsg( 'nocreatetitle' ) );
02434 $wgOut->addWikiMsg( 'nocreatetext' );
02435 }
02436
02443 protected function showDeletionLog( $out ) {
02444 global $wgUser;
02445 $loglist = new LogEventsList( $wgUser->getSkin(), $out );
02446 $pager = new LogPager( $loglist, 'delete', false, $this->mTitle->getPrefixedText() );
02447 $count = $pager->getNumRows();
02448 if ( $count > 0 ) {
02449 $pager->mLimit = 10;
02450 $out->addHTML( '<div class="mw-warning-with-logexcerpt">' );
02451 $out->addWikiMsg( 'recreate-deleted-warn' );
02452 $out->addHTML(
02453 $loglist->beginLogEventsList() .
02454 $pager->getBody() .
02455 $loglist->endLogEventsList()
02456 );
02457 if($count > 10){
02458 $out->addHTML( $wgUser->getSkin()->link(
02459 SpecialPage::getTitleFor( 'Log' ),
02460 wfMsgHtml( 'deletelog-fulllog' ),
02461 array(),
02462 array(
02463 'type' => 'delete',
02464 'page' => $this->mTitle->getPrefixedText() ) ) );
02465 }
02466 $out->addHTML( '</div>' );
02467 return true;
02468 }
02469
02470 return false;
02471 }
02472
02477 function attemptSave() {
02478 global $wgUser, $wgOut, $wgTitle, $wgRequest;
02479
02480 $resultDetails = false;
02481 # Allow bots to exempt some edits from bot flagging
02482 $bot = $wgUser->isAllowed('bot') && $wgRequest->getBool('bot',true);
02483 $value = $this->internalAttemptSave( $resultDetails, $bot );
02484
02485 if ( $value == self::AS_SUCCESS_UPDATE || $value == self::AS_SUCCESS_NEW_ARTICLE ) {
02486 $this->didSave = true;
02487 }
02488
02489 switch ($value) {
02490 case self::AS_HOOK_ERROR_EXPECTED:
02491 case self::AS_CONTENT_TOO_BIG:
02492 case self::AS_ARTICLE_WAS_DELETED:
02493 case self::AS_CONFLICT_DETECTED:
02494 case self::AS_SUMMARY_NEEDED:
02495 case self::AS_TEXTBOX_EMPTY:
02496 case self::AS_MAX_ARTICLE_SIZE_EXCEEDED:
02497 case self::AS_END:
02498 return true;
02499
02500 case self::AS_HOOK_ERROR:
02501 case self::AS_FILTERING:
02502 case self::AS_SUCCESS_NEW_ARTICLE:
02503 case self::AS_SUCCESS_UPDATE:
02504 return false;
02505
02506 case self::AS_SPAM_ERROR:
02507 $this->spamPage ( $resultDetails['spam'] );
02508 return false;
02509
02510 case self::AS_BLOCKED_PAGE_FOR_USER:
02511 $this->blockedPage();
02512 return false;
02513
02514 case self::AS_IMAGE_REDIRECT_ANON:
02515 $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
02516 return false;
02517
02518 case self::AS_READ_ONLY_PAGE_ANON:
02519 $this->userNotLoggedInPage();
02520 return false;
02521
02522 case self::AS_READ_ONLY_PAGE_LOGGED:
02523 case self::AS_READ_ONLY_PAGE:
02524 $wgOut->readOnlyPage();
02525 return false;
02526
02527 case self::AS_RATE_LIMITED:
02528 $wgOut->rateLimited();
02529 return false;
02530
02531 case self::AS_NO_CREATE_PERMISSION;
02532 $this->noCreatePermission();
02533 return;
02534
02535 case self::AS_BLANK_ARTICLE:
02536 $wgOut->redirect( $wgTitle->getFullURL() );
02537 return false;
02538
02539 case self::AS_IMAGE_REDIRECT_LOGGED:
02540 $wgOut->permissionRequired( 'upload' );
02541 return false;
02542 }
02543 }
02544
02545 function getBaseRevision() {
02546 if ( $this->mBaseRevision == false ) {
02547 $db = wfGetDB( DB_MASTER );
02548 $baseRevision = Revision::loadFromTimestamp(
02549 $db, $this->mTitle, $this->edittime );
02550 return $this->mBaseRevision = $baseRevision;
02551 } else {
02552 return $this->mBaseRevision;
02553 }
02554 }
02555 }