2 # Class representing a Wikipedia article and history.
3 # See design.doc for an overview.
5 # Note: edit user interface and cache support functions have been
6 # moved to separate EditPage and CacheManager classes.
11 * s/\$wgTitle/\$this->mTitle/ performed, many replacements
12 * mTitle variable added to class
15 include_once( "CacheManager.php" );
18 /* private */ var $mContent, $mContentLoaded;
19 /* private */ var $mUser, $mTimestamp, $mUserText;
20 /* private */ var $mCounter, $mComment, $mCountAdjustment;
21 /* private */ var $mMinorEdit, $mRedirectedFrom;
22 /* private */ var $mTouched, $mFileCache, $mTitle;
24 function Article( &$title ) {
25 $this->mTitle
=& $title;
29 /* private */ function clear()
31 $this->mContentLoaded
= false;
32 $this->mUser
= $this->mCounter
= -1; # Not loaded
33 $this->mRedirectedFrom
= $this->mUserText
=
34 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= "";
35 $this->mCountAdjustment
= 0;
36 $this->mTouched
= "19700101000000";
39 # Note that getContent/loadContent may follow redirects if
40 # not told otherwise, and so may cause a change to mTitle.
42 function getContent( $noredir = false )
44 global $action,$section,$count; # From query string
45 $fname = "Article::getContent";
46 wfProfileIn( $fname );
48 if ( 0 == $this->getID() ) {
49 if ( "edit" == $action ) {
50 wfProfileOut( $fname );
51 return ""; # was "newarticletext", now moved above the box)
53 wfProfileOut( $fname );
54 return wfMsg( "noarticletext" );
56 $this->loadContent( $noredir );
59 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
60 ( $this->mTitle
->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
61 preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$this->mTitle
->getText()) &&
65 wfProfileOut( $fname );
66 return $this->mContent
. "\n" .wfMsg("anontalkpagetext"); }
71 wfProfileOut( $fname );
75 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
77 PREG_SPLIT_DELIM_CAPTURE
);
79 wfProfileOut( $fname );
80 return trim($secs[0]);
82 wfProfileOut( $fname );
83 return trim($secs[$section*2-1] . $secs[$section*2]);
87 wfProfileOut( $fname );
88 return $this->mContent
;
93 function loadContent( $noredir = false )
95 global $wgOut, $wgMwRedir;
96 global $oldid, $redirect; # From query
98 if ( $this->mContentLoaded
) return;
99 $fname = "Article::loadContent";
101 # Pre-fill content with error message so that if something
102 # fails we'll have something telling us what we intended.
104 $t = $this->mTitle
->getPrefixedText();
105 if ( isset( $oldid ) ) {
106 $oldid = IntVal( $oldid );
107 $t .= ",oldid={$oldid}";
109 if ( isset( $redirect ) ) {
110 $redirect = ($redirect == "no") ?
"no" : "yes";
111 $t .= ",redirect={$redirect}";
113 $this->mContent
= wfMsg( "missingarticle", $t );
115 if ( ! $oldid ) { # Retrieve current version
116 $id = $this->getID();
117 if ( 0 == $id ) return;
120 "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
121 "FROM cur WHERE cur_id={$id}";
123 $res = wfQuery( $sql, DB_READ
, $fname );
124 if ( 0 == wfNumRows( $res ) ) {
128 $s = wfFetchObject( $res );
129 # If we got a redirect, follow it (unless we've been told
130 # not to by either the function parameter or the query
131 if ( ( "no" != $redirect ) && ( false == $noredir ) &&
132 ( $wgMwRedir->matchStart( $s->cur_text
) ) ) {
133 if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/",
134 $s->cur_text
, $m ) ) {
135 $rt = Title
::newFromText( $m[1] );
137 # Gotta hand redirects to special pages differently:
138 # Fill the HTTP response "Location" header and ignore
139 # the rest of the page we're on.
141 if ( $rt->getInterwiki() != "" ) {
142 $wgOut->redirect( $rt->getFullURL() ) ;
145 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
146 $wgOut->redirect( wfLocalUrl(
147 $rt->getPrefixedURL() ) );
150 $rid = $rt->getArticleID();
152 $sql = "SELECT cur_text,cur_timestamp,cur_user," .
153 "cur_counter,cur_restrictions,cur_touched FROM cur WHERE cur_id={$rid}";
154 $res = wfQuery( $sql, DB_READ
, $fname );
156 if ( 0 != wfNumRows( $res ) ) {
157 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
159 $s = wfFetchObject( $res );
165 $this->mContent
= $s->cur_text
;
166 $this->mUser
= $s->cur_user
;
167 $this->mCounter
= $s->cur_counter
;
168 $this->mTimestamp
= $s->cur_timestamp
;
169 $this->mTouched
= $s->cur_touched
;
170 $this->mTitle
->mRestrictions
= explode( ",", trim( $s->cur_restrictions
) );
171 $this->mTitle
->mRestrictionsLoaded
= true;
172 wfFreeResult( $res );
173 } else { # oldid set, retrieve historical version
174 $sql = "SELECT old_text,old_timestamp,old_user FROM old " .
175 "WHERE old_id={$oldid}";
176 $res = wfQuery( $sql, DB_READ
, $fname );
177 if ( 0 == wfNumRows( $res ) ) { return; }
179 $s = wfFetchObject( $res );
180 $this->mContent
= $s->old_text
;
181 $this->mUser
= $s->old_user
;
183 $this->mTimestamp
= $s->old_timestamp
;
184 wfFreeResult( $res );
186 $this->mContentLoaded
= true;
189 function getID() { return $this->mTitle
->getArticleID(); }
193 if ( -1 == $this->mCounter
) {
194 $id = $this->getID();
195 $this->mCounter
= wfGetSQL( "cur", "cur_counter", "cur_id={$id}" );
197 return $this->mCounter
;
200 # Would the given text make this article a "good" article (i.e.,
201 # suitable for including in the article count)?
203 function isCountable( $text )
205 global $wgUseCommaCount, $wgMwRedir;
207 if ( 0 != $this->mTitle
->getNamespace() ) { return 0; }
208 if ( $wgMwRedir->matchStart( $text ) ) { return 0; }
209 $token = ($wgUseCommaCount ?
"," : "[[" );
210 if ( false === strstr( $text, $token ) ) { return 0; }
214 # Load the field related to the last edit time of the article.
215 # This isn't necessary for all uses, so it's only done if needed.
217 /* private */ function loadLastEdit()
220 if ( -1 != $this->mUser
) return;
222 $sql = "SELECT cur_user,cur_user_text,cur_timestamp," .
223 "cur_comment,cur_minor_edit FROM cur WHERE " .
224 "cur_id=" . $this->getID();
225 $res = wfQuery( $sql, DB_READ
, "Article::loadLastEdit" );
227 if ( wfNumRows( $res ) > 0 ) {
228 $s = wfFetchObject( $res );
229 $this->mUser
= $s->cur_user
;
230 $this->mUserText
= $s->cur_user_text
;
231 $this->mTimestamp
= $s->cur_timestamp
;
232 $this->mComment
= $s->cur_comment
;
233 $this->mMinorEdit
= $s->cur_minor_edit
;
237 function getTimestamp()
239 $this->loadLastEdit();
240 return $this->mTimestamp
;
245 $this->loadLastEdit();
249 function getUserText()
251 $this->loadLastEdit();
252 return $this->mUserText
;
255 function getComment()
257 $this->loadLastEdit();
258 return $this->mComment
;
261 function getMinorEdit()
263 $this->loadLastEdit();
264 return $this->mMinorEdit
;
267 # This is the default action of the script: just view the page of
272 global $wgUser, $wgOut, $wgLang;
273 global $oldid, $diff; # From query
274 global $wgLinkCache, $IP;
275 $fname = "Article::view";
276 wfProfileIn( $fname );
278 $wgOut->setArticleFlag( true );
279 $wgOut->setRobotpolicy( "index,follow" );
281 # If we got diff and oldid in the query, we want to see a
282 # diff page instead of the article.
284 if ( isset( $diff ) ) {
285 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
286 $de = new DifferenceEngine( $oldid, $diff );
288 wfProfileOut( $fname );
292 if ( !isset( $oldid ) ) {
293 if( $this->checkTouched() ) {
294 $wgOut->checkLastModified( $this->mTouched
);
295 $this->tryFileCache();
299 $text = $this->getContent(); # May change mTitle
300 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
301 $wgOut->setHTMLTitle( $this->mTitle
->getPrefixedText() .
302 " - " . wfMsg( "wikititlesuffix" ) );
304 # We're looking at an old revision
307 $this->setOldSubtitle();
308 $wgOut->setRobotpolicy( "noindex,follow" );
310 if ( "" != $this->mRedirectedFrom
) {
311 $sk = $wgUser->getSkin();
312 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, "",
314 $s = wfMsg( "redirectedfrom", $redir );
315 $wgOut->setSubtitle( $s );
317 $wgOut->checkLastModified( $this->mTouched
);
318 $this->tryFileCache();
319 $wgLinkCache->preFill( $this->mTitle
);
320 $wgOut->addWikiText( $text );
322 $this->viewUpdates();
323 wfProfileOut( $fname );
326 # This is the function that gets called for "action=edit".
330 global $wgOut, $wgUser;
331 global $wpTextbox1, $wpSummary, $wpSave, $wpPreview;
332 global $wpMinoredit, $wpEdittime, $wpTextbox2;
334 $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" );
335 wfCleanFormFields( $fields );
337 if ( ! $this->mTitle
->userCanEdit() ) {
338 $wgOut->readOnlyPage( $this->getContent(), true );
341 if ( $wgUser->isBlocked() ) {
342 $this->blockedIPpage();
345 if ( wfReadOnly() ) {
346 if( isset( $wpSave ) or isset( $wpPreview ) ) {
347 $this->editForm( "preview" );
349 $wgOut->readOnlyPage( $this->getContent() );
353 if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave );
354 if ( isset( $wpSave ) ) {
355 $this->editForm( "save" );
356 } else if ( isset( $wpPreview ) ) {
357 $this->editForm( "preview" );
358 } else { # First time through
359 $this->editForm( "initial" );
363 # Since there is only one text field on the edit form,
364 # pressing <enter> will cause the form to be submitted, but
365 # the submit button value won't appear in the query, so we
366 # Fake it here before going back to edit(). This is kind of
367 # ugly, but it helps some old URLs to still work.
371 global $wpSave, $wpPreview;
372 if ( ! isset( $wpPreview ) ) { $wpSave = 1; }
377 # The edit form is self-submitting, so that when things like
378 # preview and edit conflicts occur, we get the same form back
379 # with the extra stuff added. Only when the final submission
380 # is made and all is well do we actually save and redirect to
381 # the newly-edited page.
383 function editForm( $formtype )
385 global $wgOut, $wgUser;
386 global $wpTextbox1, $wpSummary, $wpWatchthis;
387 global $wpSave, $wpPreview;
388 global $wpMinoredit, $wpEdittime, $wpTextbox2, $wpSection;
389 global $oldid, $redirect, $section;
392 if(isset($wpSection)) { $section=$wpSection; } else { $wpSection=$section; }
394 $sk = $wgUser->getSkin();
396 $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview
398 if(!$this->mTitle
->getArticleID()) { # new article
400 $wgOut->addWikiText(wfmsg("newarticletext"));
404 # Attempt submission here. This will check for edit conflicts,
405 # and redundantly check for locked database, blocked IPs, etc.
406 # that edit() already checked just in case someone tries to sneak
407 # in the back door with a hand-edited submission URL.
409 if ( "save" == $formtype ) {
410 if ( $wgUser->isBlocked() ) {
411 $this->blockedIPpage();
414 if ( wfReadOnly() ) {
415 $wgOut->readOnlyPage();
418 # If article is new, insert it.
420 $aid = $this->mTitle
->getArticleID();
422 # we need to strip Windoze linebreaks because some browsers
423 # append them and the string comparison fails
424 if ( ( "" == $wpTextbox1 ) ||
425 ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
426 $wgOut->redirect( wfLocalUrl(
427 $this->mTitle
->getPrefixedURL() ) );
430 $this->mCountAdjustment
= $this->isCountable( $wpTextbox1 );
431 $this->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
434 # Article exists. Check for edit conflict.
435 # Don't check for conflict when appending a comment - this should always work
437 $this->clear(); # Force reload of dates, etc.
438 if ( $section!="new" && ( $this->getTimestamp() != $wpEdittime ) ) {
441 $u = $wgUser->getID();
443 # Supress edit conflict with self
445 if ( ( 0 != $u ) && ( $this->getUser() == $u ) ) {
448 # switch from section editing to normal editing in edit conflict
450 $section="";$wpSection="";
454 if ( ! $isConflict ) {
455 # All's well: update the article here
456 if($this->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis, $wpSection ))
462 # First time through: get contents, set time for conflict
465 if ( "initial" == $formtype ) {
466 $wpEdittime = $this->getTimestamp();
467 $wpTextbox1 = $this->getContent(true);
470 $wgOut->setRobotpolicy( "noindex,nofollow" );
471 $wgOut->setArticleFlag( false );
474 $s = wfMsg( "editconflict", $this->mTitle
->getPrefixedText() );
475 $wgOut->setPageTitle( $s );
476 $wgOut->addHTML( wfMsg( "explainconflict" ) );
478 $wpTextbox2 = $wpTextbox1;
479 $wpTextbox1 = $this->getContent(true);
480 $wpEdittime = $this->getTimestamp();
482 $s = wfMsg( "editing", $this->mTitle
->getPrefixedText() );
485 if($section=="new") {
486 $s.=wfMsg("commentedit");
488 $s.=wfMsg("sectionedit");
491 $wgOut->setPageTitle( $s );
493 $this->setOldSubtitle();
494 $wgOut->addHTML( wfMsg( "editingold" ) );
499 $wgOut->addHTML( "<strong>" .
500 wfMsg( "readonlywarning" ) .
503 if( $this->mTitle
->isProtected() ) {
504 $wgOut->addHTML( "<strong>" . wfMsg( "protectedpagewarning" ) .
505 "</strong><br />\n" );
508 $kblength = (int)(strlen( $wpTextbox1 ) / 1024);
509 if( $kblength > 29 ) {
510 $wgOut->addHTML( "<strong>" .
511 wfMsg( "longpagewarning", $kblength )
515 $rows = $wgUser->getOption( "rows" );
516 $cols = $wgUser->getOption( "cols" );
518 $ew = $wgUser->getOption( "editwidth" );
519 if ( $ew ) $ew = " style=\"width:100%\"";
522 $q = "action=submit";
523 if ( "no" == $redirect ) { $q .= "&redirect=no"; }
524 $action = wfEscapeHTML( wfLocalUrl( $this->mTitle
->getPrefixedURL(), $q ) );
526 $summary = wfMsg( "summary" );
527 $subject = wfMsg("subject");
528 $minor = wfMsg( "minoredit" );
529 $watchthis = wfMsg ("watchthis");
530 $save = wfMsg( "savearticle" );
531 $prev = wfMsg( "showpreview" );
533 $cancel = $sk->makeKnownLink( $this->mTitle
->getPrefixedURL(),
535 $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ),
536 wfMsg( "edithelp" ) );
537 $copywarn = wfMsg( "copyrightwarning", $sk->makeKnownLink(
538 wfMsg( "copyrightpage" ) ) );
540 $wpTextbox1 = wfEscapeHTML( $wpTextbox1 );
541 $wpTextbox2 = wfEscapeHTML( $wpTextbox2 );
542 $wpSummary = wfEscapeHTML( $wpSummary );
544 // activate checkboxes if user wants them to be always active
545 if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1;
546 if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1;
548 // activate checkbox also if user is already watching the page,
549 // require wpWatchthis to be unset so that second condition is not
550 // checked unnecessarily
551 if (!$wpWatchthis && !$wpPreview && $this->mTitle
->userIsWatching()) $wpWatchthis=1;
553 if ( 0 != $wgUser->getID() ) {
555 "<input tabindex=3 type=checkbox value=1 name='wpMinoredit'".($wpMinoredit?
" checked":"").">{$minor}".
556 "<input tabindex=4 type=checkbox name='wpWatchthis'".($wpWatchthis?
" checked":"").">{$watchthis}<br>";
563 if ( "preview" == $formtype) {
565 $previewhead="<h2>" . wfMsg( "preview" ) . "</h2>\n<p><large><center><font color=\"#cc0000\">" .
566 wfMsg( "note" ) . wfMsg( "previewnote" ) . "</font></center></large><P>\n";
568 $previewhead.="<h2>" . wfMsg( "previewconflict" ) .
571 $previewtext = wfUnescapeHTML( $wpTextbox1 );
573 if($wgUser->getOption("previewontop")) {
574 $wgOut->addHTML($previewhead);
575 $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) ."\n\n");
577 $wgOut->addHTML( "<br clear=\"all\" />\n" );
580 # if this is a comment, show a subject line at the top, which is also the edit summary.
581 # Otherwise, show a summary field at the bottom
582 if($section=="new") {
584 $commentsubject="{$subject}: <input tabindex=1 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
587 $editsummary="{$summary}: <input tabindex=3 type=text value=\"{$wpSummary}\" name=\"wpSummary\" maxlength=200 size=60><br>";
591 <form id=\"editform\" name=\"editform\" method=\"post\" action=\"$action\"
592 enctype=\"application/x-www-form-urlencoded\">
594 <textarea tabindex=2 name=\"wpTextbox1\" rows={$rows}
595 cols={$cols}{$ew} wrap=\"virtual\">" .
596 $wgLang->recodeForEdit( $wpTextbox1 ) .
601 <input tabindex=5 type=submit value=\"{$save}\" name=\"wpSave\">
602 <input tabindex=6 type=submit value=\"{$prev}\" name=\"wpPreview\">
603 <em>{$cancel}</em> | <em>{$edithelp}</em>
605 <input type=hidden value=\"{$section}\" name=\"wpSection\">
606 <input type=hidden value=\"{$wpEdittime}\" name=\"wpEdittime\">\n" );
609 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
610 DifferenceEngine
::showDiff( $wpTextbox2, $wpTextbox1,
611 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
613 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
614 <textarea tabindex=6 name=\"wpTextbox2\" rows={$rows} cols={$cols} wrap=virtual>"
615 . $wgLang->recodeForEdit( $wpTextbox2 ) .
619 $wgOut->addHTML( "</form>\n" );
620 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
621 $wgOut->addHTML($previewhead);
622 $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) );
626 # Theoretically we could defer these whole insert and update
627 # functions for after display, but that's taking a big leap
628 # of faith, and we want to be able to report database
629 # errors at some point.
631 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
633 global $wgOut, $wgUser, $wgLinkCache, $wgMwRedir;
634 global $wgEnablePersistentLC;
636 $fname = "Article::insertNewArticle";
638 $ns = $this->mTitle
->getNamespace();
639 $ttl = $this->mTitle
->getDBkey();
640 $text = $this->preSaveTransform( $text );
641 if ( $wgMwRedir->matchStart( $text ) ) { $redir = 1; }
644 $now = wfTimestampNow();
645 $won = wfInvertTimestamp( $now );
647 $rand = number_format( mt_rand() / mt_getrandmax(), 12, ".", "" );
648 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
649 "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," .
650 "cur_restrictions,cur_user_text,cur_is_redirect," .
651 "cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES ({$ns},'" . wfStrencode( $ttl ) . "', '" .
652 wfStrencode( $text ) . "', '" .
653 wfStrencode( $summary ) . "', '" .
654 $wgUser->getID() . "', '{$now}', " .
655 ( $isminor ?
1 : 0 ) . ", 0, '', '" .
656 wfStrencode( $wgUser->getName() ) . "', $redir, 1, $rand, '{$now}', '{$won}')";
657 $res = wfQuery( $sql, DB_WRITE
, $fname );
659 $newid = wfInsertId();
660 $this->mTitle
->resetArticleID( $newid );
662 if ( $wgEnablePersistentLC ) {
663 // Purge related entries in links cache on new page, to heal broken links
664 $ptitle = wfStrencode( $ttl );
665 wfQuery("DELETE linkscc FROM linkscc,brokenlinks ".
666 "WHERE lcc_pageid=bl_from AND bl_to='{$ptitle}'", DB_WRITE
);
669 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
670 "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
671 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
672 "'{$now}','{$now}',{$ns},'" . wfStrencode( $ttl ) . "',1," .
673 ( $isminor ?
1 : 0 ) . ",{$newid}," . $wgUser->getID() . ",'" .
674 wfStrencode( $wgUser->getName() ) . "','" .
675 wfStrencode( $summary ) . "',0,0," .
676 ( $wgUser->isBot() ?
1 : 0 ) . ")";
677 wfQuery( $sql, DB_WRITE
, $fname );
679 if(!$this->mTitle
->userIsWatching()) $this->watch();
681 if ( $this->mTitle
->userIsWatching() ) {
686 # The talk page isn't in the regular link tables, so we need to update manually:
687 $talkns = $ns ^
1; # talk -> normal; normal -> talk
688 $sql = "UPDATE cur set cur_touched='$now' WHERE cur_namespace=$talkns AND cur_title='" . wfStrencode( $ttl ) . "'";
689 wfQuery( $sql, DB_WRITE
);
691 $this->showArticle( $text, wfMsg( "newarticle" ) );
694 function updateArticle( $text, $summary, $minor, $watchthis, $section = "")
696 global $wgOut, $wgUser, $wgLinkCache;
697 global $wgDBtransactions, $wgMwRedir;
698 $fname = "Article::updateArticle";
700 $this->loadLastEdit();
702 // insert updated section into old text if we have only edited part
704 if ($section != "") {
705 $oldtext=$this->getContent();
706 if($section=="new") {
707 if($summary) $subject="== {$summary} ==\n\n";
708 $text=$oldtext."\n\n".$subject.$text;
710 $secs=preg_split("/(^=+.*?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)/mi",
711 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
712 $secs[$section*2]=$text."\n\n"; // replace with edited
713 if($section) { $secs[$section*2-1]=""; } // erase old headline
714 $text=join("",$secs);
717 if ( $this->mMinorEdit
) { $me1 = 1; } else { $me1 = 0; }
718 if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
719 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ")[^\\n]+)/i", $text, $m ) ) {
721 $text = $m[1] . "\n"; # Remove all content but redirect
725 $text = $this->preSaveTransform( $text );
727 # Update article, but only if changed.
729 if( $wgDBtransactions ) {
731 wfQuery( $sql, DB_WRITE
);
733 $oldtext = $this->getContent( true );
735 if ( 0 != strcmp( $text, $oldtext ) ) {
736 $this->mCountAdjustment
= $this->isCountable( $text )
737 - $this->isCountable( $oldtext );
739 $now = wfTimestampNow();
740 $won = wfInvertTimestamp( $now );
741 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
742 "',cur_comment='" . wfStrencode( $summary ) .
743 "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
744 ",cur_timestamp='{$now}',cur_user_text='" .
745 wfStrencode( $wgUser->getName() ) .
746 "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
747 "WHERE cur_id=" . $this->getID() .
748 " AND cur_timestamp='" . $this->getTimestamp() . "'";
749 $res = wfQuery( $sql, DB_WRITE
, $fname );
751 if( wfAffectedRows() == 0 ) {
752 /* Belated edit conflict! Run away!! */
756 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
757 "old_comment,old_user,old_user_text,old_timestamp," .
758 "old_minor_edit,inverse_timestamp) VALUES (" .
759 $this->mTitle
->getNamespace() . ", '" .
760 wfStrencode( $this->mTitle
->getDBkey() ) . "', '" .
761 wfStrencode( $oldtext ) . "', '" .
762 wfStrencode( $this->getComment() ) . "', " .
763 $this->getUser() . ", '" .
764 wfStrencode( $this->getUserText() ) . "', '" .
765 $this->getTimestamp() . "', " . $me1 . ", '" .
766 wfInvertTimestamp( $this->getTimestamp() ) . "')";
767 $res = wfQuery( $sql, DB_WRITE
, $fname );
768 $oldid = wfInsertID( $res );
770 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
771 "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
772 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
773 "'{$now}','{$now}'," . $this->mTitle
->getNamespace() . ",'" .
774 wfStrencode( $this->mTitle
->getDBkey() ) . "',0,{$me2}," .
775 ( $wgUser->isBot() ?
1 : 0 ) . "," .
776 $this->getID() . "," . $wgUser->getID() . ",'" .
777 wfStrencode( $wgUser->getName() ) . "','" .
778 wfStrencode( $summary ) . "',0,{$oldid})";
779 wfQuery( $sql, DB_WRITE
, $fname );
781 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
782 "WHERE rc_namespace=" . $this->mTitle
->getNamespace() . " AND " .
783 "rc_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' AND " .
784 "rc_timestamp='" . $this->getTimestamp() . "'";
785 wfQuery( $sql, DB_WRITE
, $fname );
787 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
788 "WHERE rc_cur_id=" . $this->getID();
789 wfQuery( $sql, DB_WRITE
, $fname );
791 if ( $wgEnablePersistentLC ) {
793 // Purge link cache for this page
794 $pageid=$this->getID();
795 wfQuery("DELETE FROM linkscc WHERE lcc_pageid='{$pageid}'", DB_WRITE
);
797 // This next query just makes sure stub colored links to this page
798 // are updated correctly (I think). If performance is more important
799 // than real-time updating of stub links, we really should skip
801 wfQuery("DELETE linkscc FROM linkscc,links ".
802 "WHERE lcc_title=links.l_from AND l_to={$pageid}", DB_WRITE
);
806 if( $wgDBtransactions ) {
808 wfQuery( $sql, DB_WRITE
);
812 if (!$this->mTitle
->userIsWatching()) $this->watch();
814 if ( $this->mTitle
->userIsWatching() ) {
819 $this->showArticle( $text, wfMsg( "updated" ) );
823 # After we've either updated or inserted the article, update
824 # the link tables and redirect to the new page.
826 function showArticle( $text, $subtitle )
828 global $wgOut, $wgUser, $wgLinkCache, $wgUseBetterLinksUpdate;
831 $wgLinkCache = new LinkCache();
833 # Get old version of link table to allow incremental link updates
834 if ( $wgUseBetterLinksUpdate ) {
835 $wgLinkCache->preFill( $this->mTitle
);
836 $wgLinkCache->clear();
839 # Now update the link cache by parsing the text
840 $wgOut = new OutputPage();
841 $wgOut->addWikiText( $text );
843 $this->editUpdates( $text );
844 if( $wgMwRedir->matchStart( $text ) )
848 $wgOut->redirect( wfLocalUrl( $this->mTitle
->getPrefixedURL(), $r ) );
851 # Add this page to my watchlist
853 function watch( $add = true )
855 global $wgUser, $wgOut, $wgLang;
856 global $wgDeferredUpdateList;
858 if ( 0 == $wgUser->getID() ) {
859 $wgOut->errorpage( "watchnologin", "watchnologintext" );
862 if ( wfReadOnly() ) {
863 $wgOut->readOnlyPage();
867 $wgUser->addWatch( $this->mTitle
);
869 $wgUser->removeWatch( $this->mTitle
);
871 $wgOut->setPagetitle( wfMsg( $add ?
"addedwatch" : "removedwatch" ) );
872 $wgOut->setRobotpolicy( "noindex,follow" );
874 $sk = $wgUser->getSkin() ;
875 $link = $sk->makeKnownLink ( $this->mTitle
->getPrefixedText() ) ;
878 $text = wfMsg( "addedwatchtext", $link );
880 $text = wfMsg( "removedwatchtext", $link );
881 $wgOut->addHTML( $text );
883 $up = new UserUpdate();
884 array_push( $wgDeferredUpdateList, $up );
886 $wgOut->returnToMain( false );
891 $this->watch( false );
894 # This shares a lot of issues (and code) with Recent Changes
898 global $wgUser, $wgOut, $wgLang, $offset, $limit;
900 # If page hasn't changed, client can cache this
902 $wgOut->checkLastModified( $this->getTimestamp() );
903 $fname = "Article::history";
904 wfProfileIn( $fname );
906 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
907 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
908 $wgOut->setArticleFlag( false );
909 $wgOut->setRobotpolicy( "noindex,nofollow" );
911 if( $this->mTitle
->getArticleID() == 0 ) {
912 $wgOut->addHTML( wfMsg( "nohistory" ) );
913 wfProfileOut( $fname );
917 $offset = (int)$offset;
918 $limit = (int)$limit;
919 if( $limit == 0 ) $limit = 50;
920 $namespace = $this->mTitle
->getNamespace();
921 $title = $this->mTitle
->getText();
922 $sql = "SELECT old_id,old_user," .
923 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
924 "FROM old USE INDEX (name_title_timestamp) " .
925 "WHERE old_namespace={$namespace} AND " .
926 "old_title='" . wfStrencode( $this->mTitle
->getDBkey() ) . "' " .
927 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
928 $res = wfQuery( $sql, DB_READ
, "Article::history" );
930 $revs = wfNumRows( $res );
931 if( $this->mTitle
->getArticleID() == 0 ) {
932 $wgOut->addHTML( wfMsg( "nohistory" ) );
933 wfProfileOut( $fname );
937 $sk = $wgUser->getSkin();
938 $numbar = wfViewPrevNext(
940 $this->mTitle
->getPrefixedText(),
943 $s .= $sk->beginHistoryList();
946 $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
947 $this->getUserText(), $namespace,
948 $title, 0, $this->getComment(),
949 ( $this->getMinorEdit() > 0 ) );
951 $revs = wfNumRows( $res );
952 while ( $line = wfFetchObject( $res ) ) {
953 $s .= $sk->historyLine( $line->old_timestamp
, $line->old_user
,
954 $line->old_user_text
, $namespace,
955 $title, $line->old_id
,
956 $line->old_comment
, ( $line->old_minor_edit
> 0 ) );
958 $s .= $sk->endHistoryList();
960 $wgOut->addHTML( $s );
961 wfProfileOut( $fname );
964 function protect( $limit = "sysop" )
966 global $wgUser, $wgOut;
968 if ( ! $wgUser->isSysop() ) {
969 $wgOut->sysopRequired();
972 if ( wfReadOnly() ) {
973 $wgOut->readOnlyPage();
976 $id = $this->mTitle
->getArticleID();
978 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
981 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
982 "cur_restrictions='{$limit}' WHERE cur_id={$id}";
983 wfQuery( $sql, DB_WRITE
, "Article::protect" );
985 $log = new LogPage( wfMsg( "protectlogpage" ), wfMsg( "protectlogtext" ) );
986 if ( $limit === "" ) {
987 $log->addEntry( wfMsg( "unprotectedarticle", $this->mTitle
->getPrefixedText() ), "" );
989 $log->addEntry( wfMsg( "protectedarticle", $this->mTitle
->getPrefixedText() ), "" );
991 $wgOut->redirect( wfLocalUrl( $this->mTitle
->getPrefixedURL() ) );
996 return $this->protect( "" );
1001 global $wgUser, $wgOut;
1002 global $wpConfirm, $wpReason, $image, $oldimage;
1004 # This code desperately needs to be totally rewritten
1006 if ( ( ! $wgUser->isSysop() ) ) {
1007 $wgOut->sysopRequired();
1010 if ( wfReadOnly() ) {
1011 $wgOut->readOnlyPage();
1015 # Better double-check that it hasn't been deleted yet!
1016 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
1017 if ( ( "" == trim( $this->mTitle
->getText() ) )
1018 or ( $this->mTitle
->getArticleId() == 0 ) ) {
1019 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
1028 # determine whether this page has earlier revisions
1029 # and insert a warning if it does
1030 # we select the text because it might be useful below
1031 $sql="SELECT old_text FROM old WHERE old_namespace=0 and old_title='" . wfStrencode($this->mTitle
->getPrefixedDBkey())."' ORDER BY inverse_timestamp LIMIT 1";
1032 $res=wfQuery($sql, DB_READ
, $fname);
1033 if( ($old=wfFetchObject($res)) && !$wpConfirm ) {
1034 $skin=$wgUser->getSkin();
1035 $wgOut->addHTML("<B>".wfMsg("historywarning"));
1036 $wgOut->addHTML( $skin->historyLink() ."</B><P>");
1039 $sql="SELECT cur_text FROM cur WHERE cur_namespace=0 and cur_title='" . wfStrencode($this->mTitle
->getPrefixedDBkey())."'";
1040 $res=wfQuery($sql, DB_READ
, $fname);
1041 if( ($s=wfFetchObject($res))) {
1043 # if this is a mini-text, we can paste part of it into the deletion reason
1045 #if this is empty, an earlier revision may contain "useful" text
1046 if($s->cur_text
!="") {
1050 $text=$old->old_text
;
1056 $length=strlen($text);
1058 # this should not happen, since it is not possible to store an empty, new
1059 # page. Let's insert a standard text in case it does, though
1060 if($length==0 && !$wpReason) { $wpReason=wfmsg("exblank");}
1063 if($length < 500 && !$wpReason) {
1065 # comment field=255, let's grep the first 150 to have some user
1067 $text=substr($text,0,150);
1068 # let's strip out newlines and HTML tags
1069 $text=preg_replace("/\"/","'",$text);
1070 $text=preg_replace("/\</","<",$text);
1071 $text=preg_replace("/\>/",">",$text);
1072 $text=preg_replace("/[\n\r]/","",$text);
1074 $wpReason=wfMsg("excontent"). " '".$text;
1076 $wpReason=wfMsg("exbeforeblank") . " '".$text;
1078 if($length>150) { $wpReason .= "..."; } # we've only pasted part of the text
1083 return $this->confirmDelete();
1086 function confirmDelete( $par = "" )
1090 wfDebug( "Article::confirmDelete\n" );
1092 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1093 $wgOut->setSubtitle( wfMsg( "deletesub", $sub ) );
1094 $wgOut->setRobotpolicy( "noindex,nofollow" );
1095 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
1097 $t = $this->mTitle
->getPrefixedURL();
1099 $formaction = wfEscapeHTML( wfLocalUrl( $t, "action=delete" . $par ) );
1100 $confirm = wfMsg( "confirm" );
1101 $check = wfMsg( "confirmcheck" );
1102 $delcom = wfMsg( "deletecomment" );
1105 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
1106 <table border=0><tr><td align=right>
1107 {$delcom}:</td><td align=left>
1108 <input type=text size=60 name=\"wpReason\" value=\"{$wpReason}\">
1109 </td></tr><tr><td> </td></tr>
1110 <tr><td align=right>
1111 <input type=checkbox name=\"wpConfirm\" value='1' id=\"wpConfirm\">
1112 </td><td><label for=\"wpConfirm\">{$check}</label></td>
1113 </tr><tr><td> </td><td>
1114 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
1115 </td></tr></table></form>\n" );
1117 $wgOut->returnToMain( false );
1122 global $wgOut, $wgUser, $wgLang;
1124 $fname = "Article::doDelete";
1125 wfDebug( "$fname\n" );
1127 $this->doDeleteArticle( $this->mTitle
);
1128 $deleted = $this->mTitle
->getPrefixedText();
1130 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1131 $wgOut->setRobotpolicy( "noindex,nofollow" );
1133 $sk = $wgUser->getSkin();
1134 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
1135 Namespace::getWikipedia() ) .
1136 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
1138 $text = wfMsg( "deletedtext", $deleted, $loglink );
1140 $wgOut->addHTML( "<p>" . $text );
1141 $wgOut->returnToMain( false );
1144 function doDeleteArticle( $title )
1146 global $wgUser, $wgOut, $wgLang, $wpReason, $wgDeferredUpdateList;
1148 $fname = "Article::doDeleteArticle";
1149 wfDebug( "$fname\n" );
1151 $ns = $title->getNamespace();
1152 $t = wfStrencode( $title->getDBkey() );
1153 $id = $title->getArticleID();
1156 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
1160 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1161 array_push( $wgDeferredUpdateList, $u );
1163 # Move article and history to the "archive" table
1164 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
1165 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
1166 "ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment," .
1167 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
1168 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
1169 wfQuery( $sql, DB_WRITE
, $fname );
1171 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
1172 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
1173 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
1174 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
1175 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
1176 wfQuery( $sql, DB_WRITE
, $fname );
1178 # Now that it's safely backed up, delete it
1180 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
1182 wfQuery( $sql, DB_WRITE
, $fname );
1184 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
1186 wfQuery( $sql, DB_WRITE
, $fname );
1188 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
1190 wfQuery( $sql, DB_WRITE
, $fname );
1192 # Finally, clean up the link tables
1196 $t = wfStrencode( $title->getPrefixedDBkey() );
1198 if ( $wgEnablePersistentLC ) {
1199 // Purge related entries in links cache on delete,
1200 wfQuery("DELETE linkscc FROM linkscc,links ".
1201 "WHERE lcc_title=links.l_from AND l_to={$id}", DB_WRITE
);
1202 wfQuery("DELETE FROM linkscc WHERE lcc_title='{$t}'", DB_WRITE
);
1205 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
1206 $res = wfQuery( $sql, DB_READ
, $fname );
1208 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
1209 $now = wfTimestampNow();
1210 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
1213 while ( $s = wfFetchObject( $res ) ) {
1214 $nt = Title
::newFromDBkey( $s->l_from
);
1215 $lid = $nt->getArticleID();
1217 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
1219 $sql .= "({$lid},'{$t}')";
1224 wfQuery( $sql, DB_WRITE
, $fname );
1225 wfQuery( $sql2, DB_WRITE
, $fname );
1227 wfFreeResult( $res );
1229 $sql = "DELETE FROM links WHERE l_to={$id}";
1230 wfQuery( $sql, DB_WRITE
, $fname );
1232 $sql = "DELETE FROM links WHERE l_from='{$t}'";
1233 wfQuery( $sql, DB_WRITE
, $fname );
1235 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
1236 wfQuery( $sql, DB_WRITE
, $fname );
1238 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
1239 wfQuery( $sql, DB_WRITE
, $fname );
1242 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
1243 $art = $title->getPrefixedText();
1244 $wpReason = wfCleanQueryVar( $wpReason );
1245 $log->addEntry( wfMsg( "deletedarticle", $art ), $wpReason );
1247 # Clear the cached article id so the interface doesn't act like we exist
1248 $this->mTitle
->resetArticleID( 0 );
1249 $this->mTitle
->mArticleID
= 0;
1254 global $wgUser, $wgLang, $wgOut, $from;
1256 if ( ! $wgUser->isSysop() ) {
1257 $wgOut->sysopRequired();
1261 # Replace all this user's current edits with the next one down
1262 $tt = wfStrencode( $this->mTitle
->getDBKey() );
1263 $n = $this->mTitle
->getNamespace();
1265 # Get the last editor
1266 $sql = "SELECT cur_id,cur_user,cur_user_text,cur_comment FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
1267 $res = wfQuery( $sql, DB_READ
);
1268 if( ($x = wfNumRows( $res )) != 1 ) {
1270 $wgOut->addHTML( wfMsg( "notanarticle" ) );
1273 $s = wfFetchObject( $res );
1274 $ut = wfStrencode( $s->cur_user_text
);
1275 $uid = $s->cur_user
;
1278 $from = str_replace( '_', ' ', wfCleanQueryVar( $from ) );
1279 if( $from != $s->cur_user_text
) {
1280 $wgOut->setPageTitle(wfmsg("rollbackfailed"));
1281 $wgOut->addWikiText( wfMsg( "alreadyrolled",
1282 htmlspecialchars( $this->mTitle
->getPrefixedText()),
1283 htmlspecialchars( $from ),
1284 htmlspecialchars( $s->cur_user_text
) ) );
1285 if($s->cur_comment
!= "") {
1287 wfMsg("editcomment",
1288 htmlspecialchars( $s->cur_comment
) ) );
1293 # Get the last edit not by this guy
1294 $sql = "SELECT old_text,old_user,old_user_text
1295 FROM old USE INDEX (name_title_timestamp)
1296 WHERE old_namespace={$n} AND old_title='{$tt}'
1297 AND (old_user <> {$uid} OR old_user_text <> '{$ut}')
1298 ORDER BY inverse_timestamp LIMIT 1";
1299 $res = wfQuery( $sql, DB_READ
);
1300 if( wfNumRows( $res ) != 1 ) {
1302 $wgOut->setPageTitle(wfMsg("rollbackfailed"));
1303 $wgOut->addHTML( wfMsg( "cantrollback" ) );
1306 $s = wfFetchObject( $res );
1309 $newcomment = wfMsg( "revertpage", $s->old_user_text
);
1310 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1311 $wgOut->setRobotpolicy( "noindex,nofollow" );
1312 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
1313 $this->updateArticle( $s->old_text
, $newcomment, 1, $this->mTitle
->userIsWatching() );
1315 $wgOut->returnToMain( false );
1319 # Do standard deferred updates after page view
1321 /* private */ function viewUpdates()
1323 global $wgDeferredUpdateList;
1325 if ( 0 != $this->getID() ) {
1326 global $wgDisableCounters;
1327 if( !$wgDisableCounters ) {
1328 $u = new ViewCountUpdate( $this->getID() );
1329 array_push( $wgDeferredUpdateList, $u );
1330 $u = new SiteStatsUpdate( 1, 0, 0 );
1331 array_push( $wgDeferredUpdateList, $u );
1333 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(),
1334 $this->mTitle
->getDBkey() );
1335 array_push( $wgDeferredUpdateList, $u );
1339 # Do standard deferred updates after page edit.
1340 # Every 1000th edit, prune the recent changes table.
1342 /* private */ function editUpdates( $text )
1344 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1347 if ( 0 == mt_rand( 0, 999 ) ) {
1348 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1349 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1350 wfQuery( $sql, DB_WRITE
);
1352 $id = $this->getID();
1353 $title = $this->mTitle
->getPrefixedDBkey();
1354 $adj = $this->mCountAdjustment
;
1357 $u = new LinksUpdate( $id, $title );
1358 array_push( $wgDeferredUpdateList, $u );
1359 $u = new SiteStatsUpdate( 0, 1, $adj );
1360 array_push( $wgDeferredUpdateList, $u );
1361 $u = new SearchUpdate( $id, $title, $text );
1362 array_push( $wgDeferredUpdateList, $u );
1364 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(),
1365 $this->mTitle
->getDBkey() );
1366 array_push( $wgDeferredUpdateList, $u );
1368 if ( $this->getNamespace
== NS_MEDIAWIKI
) {
1369 $messageCache = $wgMemc->get( "$wgDBname:messages" );
1370 if (!$messageCache) {
1371 $messageCache = wfLoadAllMessages();
1373 $messageCache[$title] = $text;
1374 $wgMemc->set( "$wgDBname:messages" );
1379 /* private */ function setOldSubtitle()
1381 global $wgLang, $wgOut;
1383 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
1384 $r = wfMsg( "revisionasof", $td );
1385 $wgOut->setSubtitle( "({$r})" );
1388 function blockedIPpage()
1390 global $wgOut, $wgUser, $wgLang;
1392 $wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
1393 $wgOut->setRobotpolicy( "noindex,nofollow" );
1394 $wgOut->setArticleFlag( false );
1396 $id = $wgUser->blockedBy();
1397 $reason = $wgUser->blockedFor();
1399 $name = User
::whoIs( $id );
1400 $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
1401 ":{$name}|{$name}]]";
1403 $text = wfMsg( "blockedtext", $link, $reason, getenv( "REMOTE_ADDR" ) );
1404 $wgOut->addWikiText( $text );
1405 $wgOut->returnToMain( false );
1408 # This function is called right before saving the wikitext,
1409 # so we can do things like signatures and links-in-context.
1411 function preSaveTransform( $text )
1414 while ( "" != $text ) {
1415 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1416 $s .= $this->pstPass2( $p[0] );
1418 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) { $text = ""; }
1420 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1421 $s .= "<nowiki>{$q[0]}</nowiki>";
1428 /* private */ function pstPass2( $text )
1430 global $wgUser, $wgLang, $wgLocaltimezone;
1434 $n = $wgUser->getName();
1435 $k = $wgUser->getOption( "nickname" );
1436 if ( "" == $k ) { $k = $n; }
1437 if(isset($wgLocaltimezone)) {
1438 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1440 /* Note: this is an ugly timezone hack for the European wikis */
1441 $d = $wgLang->timeanddate( date( "YmdHis" ), false ) .
1442 " (" . date( "T" ) . ")";
1443 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1445 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1446 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1447 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1448 Namespace::getUser() ) . ":$n|$k]]", $text );
1450 # Context links: [[|name]] and [[name (context)|]]
1452 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1453 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1454 $namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
1455 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1457 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1458 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1459 $p3 = "/\[\[($namespacechar+):({$np}+)\\|]]/"; # [[namespace:page|]]
1460 $p4 = "/\[\[($namespacechar+):({$np}+) \\(({$np}+)\\)\\|]]/";
1461 # [[ns:page (cont)|]]
1463 $t = $this->mTitle
->getText();
1464 if ( preg_match( $conpat, $t, $m ) ) {
1467 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1468 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1469 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1471 if ( "" == $context ) {
1472 $text = preg_replace( $p2, "[[\\1]]", $text );
1474 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1477 # {{SUBST:xxx}} variables
1479 $mw =& MagicWord
::get( MAG_SUBST
);
1480 $text = $mw->substituteCallback( $text, "wfReplaceSubstVar" );
1485 /* Caching functions */
1487 function tryFileCache() {
1488 if($this->isFileCacheable()) {
1489 $touched = $this->mTouched
;
1490 if( strpos( $this->mContent
, "{{" ) !== false ) {
1491 # Expire pages with variable replacements in an hour
1492 $expire = wfUnix2Timestamp( time() - 3600 );
1493 $touched = max( $expire, $touched );
1495 $cache = new CacheManager( $this->mTitle
);
1496 if($cache->isFileCacheGood( $touched )) {
1498 wfDebug( " tryFileCache() - about to load\n" );
1499 $cache->loadFromFileCache();
1500 $wgOut->reportTime(); # For profiling
1503 wfDebug( " tryFileCache() - starting buffer\n" );
1504 if($cache->useGzip() && wfClientAcceptsGzip()) {
1505 /* For some reason, adding this header line over in
1506 CacheManager::saveToFileCache() fails on my test
1507 setup at home, though it works on the live install.
1508 Make double-sure... --brion */
1509 header( "Content-Encoding: gzip" );
1511 ob_start( array(&$cache, 'saveToFileCache' ) );
1514 wfDebug( " tryFileCache() - not cacheable\n" );
1518 function isFileCacheable() {
1519 global $wgUser, $wgUseFileCache, $wgShowIPinHeader;
1520 global $action, $oldid, $diff, $redirect, $printable;
1521 return $wgUseFileCache
1522 and (!$wgShowIPinHeader)
1523 and ($this->getID() != 0)
1524 and ($wgUser->getId() == 0)
1525 and (!$wgUser->getNewtalk())
1526 and ($this->mTitle
->getNamespace
!= Namespace::getSpecial())
1527 and ($action == "view")
1528 and (!isset($oldid))
1530 and (!isset($redirect))
1531 and (!isset($printable))
1532 and (!$this->mRedirectedFrom
);
1535 function checkTouched() {
1536 $id = $this->getID();
1537 $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id";
1538 $res = wfQuery( $sql, DB_READ
, "Article::checkTouched" );
1539 if( $s = wfFetchObject( $res ) ) {
1540 $this->mTouched
= $s->cur_touched
;
1541 return !$s->cur_is_redirect
;
1548 function wfReplaceSubstVar( $matches ) {
1549 return wfMsg( $matches[1] );