2 # Class representing a Wikipedia article and history.
3 # See design.doc for an overview.
6 /* private */ var $mContent, $mContentLoaded;
7 /* private */ var $mUser, $mTimestamp, $mUserText;
8 /* private */ var $mCounter, $mComment, $mCountAdjustment;
9 /* private */ var $mMinorEdit, $mRedirectedFrom;
10 /* private */ var $mTouched;
12 function Article() { $this->clear(); }
14 /* private */ function clear()
16 $this->mContentLoaded
= false;
17 $this->mUser
= $this->mCounter
= -1; # Not loaded
18 $this->mRedirectedFrom
= $this->mUserText
=
19 $this->mTimestamp
= $this->mComment
= "";
20 $this->mCountAdjustment
= 0;
21 $this->mTouched
= "19700101000000";
24 /* static */ function newFromID( $newid )
26 global $wgOut, $wgTitle, $wgArticle;
28 $n = Article
::nameOf( $newid );
30 $wgTitle = Title
::newFromDBkey( $n );
31 $wgTitle->resetArticleID( $newid );
36 /* static */ function nameOf( $id )
38 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE " .
40 $res = wfQuery( $sql, "Article::nameOf" );
41 if ( 0 == wfNumRows( $res ) ) { return NULL; }
43 $s = wfFetchObject( $res );
44 $n = Title
::makeName( $s->cur_namespace
, $s->cur_title
);
48 # Note that getContent/loadContent may follow redirects if
49 # not told otherwise, and so may cause a change to wgTitle.
51 function getContent( $noredir = false )
53 global $action,$wgTitle; # From query string
54 wfProfileIn( "Article::getContent" );
56 if ( 0 == $this->getID() ) {
57 if ( "edit" == $action ) {
60 return ""; # was "newarticletext", now moved above the box)
65 return wfMsg( "noarticletext" );
67 $this->loadContent( $noredir );
71 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
72 ( $wgTitle->getNamespace() == Namespace::getTalk( Namespace::getUser()) ) &&
73 preg_match("/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/",$wgTitle->getText()) &&
77 return $this->mContent
. "\n" .wfMsg("anontalkpagetext"); }
79 return $this->mContent
;
84 function loadContent( $noredir = false )
86 global $wgOut, $wgTitle;
87 global $oldid, $redirect; # From query
89 if ( $this->mContentLoaded
) return;
90 $fname = "Article::loadContent";
92 # Pre-fill content with error message so that if something
93 # fails we'll have something telling us what we intended.
95 $t = $wgTitle->getPrefixedText();
96 if ( $oldid ) { $t .= ",oldid={$oldid}"; }
97 if ( $redirect ) { $t .= ",redirect={$redirect}"; }
98 $this->mContent
= str_replace( "$1", $t, wfMsg( "missingarticle" ) );
100 if ( ! $oldid ) { # Retrieve current version
101 $id = $this->getID();
102 if ( 0 == $id ) return;
105 "cur_text,cur_timestamp,cur_user,cur_counter,cur_restrictions,cur_touched " .
106 "FROM cur WHERE cur_id={$id}";
107 $res = wfQuery( $sql, $fname );
108 if ( 0 == wfNumRows( $res ) ) { return; }
110 $s = wfFetchObject( $res );
112 # If we got a redirect, follow it (unless we've been told
113 # not to by either the function parameter or the query
115 if ( ( "no" != $redirect ) && ( false == $noredir ) &&
116 ( preg_match( "/^#redirect/i", $s->cur_text
) ) ) {
117 if ( preg_match( "/\\[\\[([^\\]\\|]+)[\\]\\|]/",
118 $s->cur_text
, $m ) ) {
119 $rt = Title
::newFromText( $m[1] );
121 # Gotta hand redirects to special pages differently:
122 # Fill the HTTP response "Location" header and ignore
123 # the rest of the page we're on.
125 if ( $rt->getInterwiki() != "" ) {
126 $wgOut->redirect( $rt->getFullURL() ) ;
129 if ( $rt->getNamespace() == Namespace::getSpecial() ) {
130 $wgOut->redirect( wfLocalUrl(
131 $rt->getPrefixedURL() ) );
134 $rid = $rt->getArticleID();
136 $sql = "SELECT cur_text,cur_timestamp,cur_user," .
137 "cur_counter,cur_touched FROM cur WHERE cur_id={$rid}";
138 $res = wfQuery( $sql, $fname );
140 if ( 0 != wfNumRows( $res ) ) {
141 $this->mRedirectedFrom
= $wgTitle->getPrefixedText();
143 $s = wfFetchObject( $res );
148 $this->mContent
= $s->cur_text
;
149 $this->mUser
= $s->cur_user
;
150 $this->mCounter
= $s->cur_counter
;
151 $this->mTimestamp
= $s->cur_timestamp
;
152 $this->mTouched
= $s->cur_touched
;
153 $wgTitle->mRestrictions
= explode( ",", trim( $s->cur_restrictions
) );
154 $wgTitle->mRestrictionsLoaded
= true;
155 wfFreeResult( $res );
156 } else { # oldid set, retrieve historical version
157 $sql = "SELECT old_text,old_timestamp,old_user FROM old " .
158 "WHERE old_id={$oldid}";
159 $res = wfQuery( $sql, $fname );
160 if ( 0 == wfNumRows( $res ) ) { return; }
162 $s = wfFetchObject( $res );
163 $this->mContent
= $s->old_text
;
164 $this->mUser
= $s->old_user
;
166 $this->mTimestamp
= $s->old_timestamp
;
167 wfFreeResult( $res );
169 $this->mContentLoaded
= true;
172 function getID() { global $wgTitle; return $wgTitle->getArticleID(); }
176 if ( -1 == $this->mCounter
) {
177 $id = $this->getID();
178 $this->mCounter
= wfGetSQL( "cur", "cur_counter", "cur_id={$id}" );
180 return $this->mCounter
;
183 # Would the given text make this article a "good" article (i.e.,
184 # suitable for including in the article count)?
186 function isCountable( $text )
188 global $wgTitle, $wgUseCommaCount;
190 if ( 0 != $wgTitle->getNamespace() ) { return 0; }
191 if ( preg_match( "/^#redirect/i", $text ) ) { return 0; }
192 $token = ($wgUseCommaCount ?
"," : "[[" );
193 if ( false === strstr( $text, $token ) ) { return 0; }
197 # Load the field related to the last edit time of the article.
198 # This isn't necessary for all uses, so it's only done if needed.
200 /* private */ function loadLastEdit()
203 if ( -1 != $this->mUser
) return;
205 $sql = "SELECT cur_user,cur_user_text,cur_timestamp," .
206 "cur_comment,cur_minor_edit FROM cur WHERE " .
207 "cur_id=" . $this->getID();
208 $res = wfQuery( $sql, "Article::loadLastEdit" );
210 if ( wfNumRows( $res ) > 0 ) {
211 $s = wfFetchObject( $res );
212 $this->mUser
= $s->cur_user
;
213 $this->mUserText
= $s->cur_user_text
;
214 $this->mTimestamp
= $s->cur_timestamp
;
215 $this->mComment
= $s->cur_comment
;
216 $this->mMinorEdit
= $s->cur_minor_edit
;
220 function getTimestamp()
222 $this->loadLastEdit();
223 return $this->mTimestamp
;
228 $this->loadLastEdit();
232 function getUserText()
234 $this->loadLastEdit();
235 return $this->mUserText
;
238 function getComment()
240 $this->loadLastEdit();
241 return $this->mComment
;
244 function getMinorEdit()
246 $this->loadLastEdit();
247 return $this->mMinorEdit
;
250 # This is the default action of the script: just view the page of
255 global $wgUser, $wgOut, $wgTitle, $wgLang;
256 global $oldid, $diff; # From query
258 wfProfileIn( "Article::view" );
260 $wgOut->setArticleFlag( true );
261 $wgOut->setRobotpolicy( "index,follow" );
263 # If we got diff and oldid in the query, we want to see a
264 # diff page instead of the article.
266 if ( isset( $diff ) ) {
267 $wgOut->setPageTitle( $wgTitle->getPrefixedText() );
268 $de = new DifferenceEngine( $oldid, $diff );
273 $text = $this->getContent(); # May change wgTitle!
274 $wgOut->setPageTitle( $wgTitle->getPrefixedText() );
275 $wgOut->setHTMLTitle( $wgTitle->getPrefixedText() .
276 " - " . wfMsg( "wikititlesuffix" ) );
278 # We're looking at an old revision
281 $this->setOldSubtitle();
282 $wgOut->setRobotpolicy( "noindex,follow" );
284 if ( "" != $this->mRedirectedFrom
) {
285 $sk = $wgUser->getSkin();
286 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, "",
288 $s = str_replace( "$1", $redir, wfMsg( "redirectedfrom" ) );
289 $wgOut->setSubtitle( $s );
291 $wgOut->checkLastModified( $this->mTouched
);
292 $wgLinkCache->preFill( $wgTitle );
293 $wgOut->addWikiText( $text );
295 # If the article we've just shown is in the "Image" namespace,
296 # follow it with the history list and link list for the image
299 if ( Namespace::getImage() == $wgTitle->getNamespace() ) {
300 $this->imageHistory();
303 $this->viewUpdates();
307 # This is the function that gets called for "action=edit".
311 global $wgOut, $wgUser, $wgTitle;
312 global $wpTextbox1, $wpSummary, $wpSave, $wpPreview;
313 global $wpMinoredit, $wpEdittime, $wpTextbox2;
315 $fields = array( "wpTextbox1", "wpSummary", "wpTextbox2" );
316 wfCleanFormFields( $fields );
318 if ( ! $wgTitle->userCanEdit() ) {
322 if ( $wgUser->isBlocked() ) {
323 $this->blockedIPpage();
326 if ( wfReadOnly() ) {
327 if( isset( $wpSave ) or isset( $wpPreview ) ) {
328 $this->editForm( "preview" );
330 $wgOut->readOnlyPage();
334 if ( $_SERVER['REQUEST_METHOD'] != "POST" ) unset( $wpSave );
335 if ( isset( $wpSave ) ) {
336 $this->editForm( "save" );
337 } else if ( isset( $wpPreview ) ) {
338 $this->editForm( "preview" );
339 } else { # First time through
340 $this->editForm( "initial" );
344 # Since there is only one text field on the edit form,
345 # pressing <enter> will cause the form to be submitted, but
346 # the submit button value won't appear in the query, so we
347 # Fake it here before going back to edit(). This is kind of
348 # ugly, but it helps some old URLs to still work.
352 global $wpSave, $wpPreview;
353 if ( ! isset( $wpPreview ) ) { $wpSave = 1; }
358 # The edit form is self-submitting, so that when things like
359 # preview and edit conflicts occur, we get the same form back
360 # with the extra stuff added. Only when the final submission
361 # is made and all is well do we actually save and redirect to
362 # the newly-edited page.
364 function editForm( $formtype )
366 global $wgOut, $wgUser, $wgTitle;
367 global $wpTextbox1, $wpSummary, $wpWatchthis;
368 global $wpSave, $wpPreview;
369 global $wpMinoredit, $wpEdittime, $wpTextbox2;
370 global $oldid, $redirect;
373 $sk = $wgUser->getSkin();
375 $wpTextbox1 = rtrim ( $wpTextbox1 ) ; # To avoid text getting longer on each preview
377 if(!$wgTitle->getArticleID()) { # new article
379 $wgOut->addWikiText(wfmsg("newarticletext"));
383 # Attempt submission here. This will check for edit conflicts,
384 # and redundantly check for locked database, blocked IPs, etc.
385 # that edit() already checked just in case someone tries to sneak
386 # in the back door with a hand-edited submission URL.
388 if ( "save" == $formtype ) {
389 if ( $wgUser->isBlocked() ) {
390 $this->blockedIPpage();
393 if ( wfReadOnly() ) {
394 $wgOut->readOnlyPage();
397 # If article is new, insert it.
399 $aid = $wgTitle->getArticleID();
401 # we need to strip Windoze linebreaks because some browsers
402 # append them and the string comparison fails
403 if ( ( "" == $wpTextbox1 ) ||
404 ( wfMsg( "newarticletext" ) == rtrim( preg_replace("/\r/","",$wpTextbox1) ) ) ) {
405 $wgOut->redirect( wfLocalUrl(
406 $wgTitle->getPrefixedURL() ) );
409 $this->mCountAdjustment
= $this->isCountable( $wpTextbox1 );
410 $this->insertNewArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
413 # Article exists. Check for edit conflict.
415 $this->clear(); # Force reload of dates, etc.
416 if ( $this->getTimestamp() != $wpEdittime ) { $isConflict = true; }
417 $u = $wgUser->getID();
419 # Supress edit conflict with self
421 if ( ( 0 != $u ) && ( $this->getUser() == $u ) ) {
424 if ( ! $isConflict ) {
425 # All's well: update the article here
426 $this->updateArticle( $wpTextbox1, $wpSummary, $wpMinoredit, $wpWatchthis );
430 # First time through: get contents, set time for conflict
433 if ( "initial" == $formtype ) {
434 $wpEdittime = $this->getTimestamp();
435 $wpTextbox1 = $this->getContent();
438 $wgOut->setRobotpolicy( "noindex,nofollow" );
439 $wgOut->setArticleFlag( false );
442 $s = str_replace( "$1", $wgTitle->getPrefixedText(),
443 wfMsg( "editconflict" ) );
444 $wgOut->setPageTitle( $s );
445 $wgOut->addHTML( wfMsg( "explainconflict" ) );
447 $wpTextbox2 = $wpTextbox1;
448 $wpTextbox1 = $this->getContent();
449 $wpEdittime = $this->getTimestamp();
451 $s = str_replace( "$1", $wgTitle->getPrefixedText(),
452 wfMsg( "editing" ) );
453 $wgOut->setPageTitle( $s );
455 $this->setOldSubtitle();
456 $wgOut->addHTML( wfMsg( "editingold" ) );
461 $wgOut->addHTML( "<strong>" .
462 wfMsg( "readonlywarning" ) .
465 if( $wgTitle->isProtected() ) {
466 $wgOut->addHTML( "<strong>" . wfMsg( "protectedpagewarning" ) .
467 "</strong><br />\n" );
470 $kblength = (int)(strlen( $wpTextbox1 ) / 1024);
471 if( $kblength > 29 ) {
472 $wgOut->addHTML( "<strong>" .
473 str_replace( '$1', $kblength , wfMsg( "longpagewarning" ) )
477 $rows = $wgUser->getOption( "rows" );
478 $cols = $wgUser->getOption( "cols" );
480 $ew = $wgUser->getOption( "editwidth" );
481 if ( $ew ) $ew = " style=\"width:100%\"";
484 $q = "action=submit";
485 if ( "no" == $redirect ) { $q .= "&redirect=no"; }
486 $action = wfEscapeHTML( wfLocalUrl( $wgTitle->getPrefixedURL(), $q ) );
488 $summary = wfMsg( "summary" );
489 $minor = wfMsg( "minoredit" );
490 $watchthis = wfMsg ("watchthis");
491 $save = wfMsg( "savearticle" );
492 $prev = wfMsg( "showpreview" );
494 $cancel = $sk->makeKnownLink( $wgTitle->getPrefixedURL(),
496 $edithelp = $sk->makeKnownLink( wfMsg( "edithelppage" ),
497 wfMsg( "edithelp" ) );
498 $copywarn = str_replace( "$1", $sk->makeKnownLink(
499 wfMsg( "copyrightpage" ) ), wfMsg( "copyrightwarning" ) );
501 $wpTextbox1 = wfEscapeHTML( $wpTextbox1 );
502 $wpTextbox2 = wfEscapeHTML( $wpTextbox2 );
503 $wpSummary = wfEscapeHTML( $wpSummary );
505 // activate checkboxes if user wants them to be always active
506 if (!$wpPreview && $wgUser->getOption("watchdefault")) $wpWatchthis=1;
507 if (!$wpPreview && $wgUser->getOption("minordefault")) $wpMinoredit=1;
509 // activate checkbox also if user is already watching the page,
510 // require wpWatchthis to be unset so that second condition is not
511 // checked unnecessarily
512 if (!$wpWatchthis && !$wpPreview && $wgTitle->userIsWatching()) $wpWatchthis=1;
514 if ( 0 != $wgUser->getID() ) {
516 "<input tabindex=3 type=checkbox value=1 name='wpMinoredit'".($wpMinoredit?
" checked":"").">{$minor}".
517 "<input tabindex=4 type=checkbox name='wpWatchthis'".($wpWatchthis?
" checked":"").">{$watchthis}<br>";
524 if ( "preview" == $formtype) {
526 $previewhead="<h2>" . wfMsg( "preview" ) . "</h2>\n<p><large><center><font color=\"#cc0000\">" .
527 wfMsg( "note" ) . wfMsg( "previewnote" ) . "</font></center></large><P>\n";
529 $previewhead.="<h2>" . wfMsg( "previewconflict" ) .
532 $previewtext = wfUnescapeHTML( $wpTextbox1 );
534 if($wgUser->getOption("previewontop")) {
535 $wgOut->addHTML($previewhead);
536 $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) ."\n\n");
540 <form id=\"editform\" method=\"post\" action=\"$action\"
541 enctype=\"application/x-www-form-urlencoded\">
542 <textarea tabindex=1 name=\"wpTextbox1\" rows={$rows}
543 cols={$cols}{$ew} wrap=\"virtual\">" .
544 $wgLang->recodeForEdit( $wpTextbox1 ) .
547 {$summary}: <input tabindex=2 type=text value=\"{$wpSummary}\"
548 name=\"wpSummary\" maxlength=200 size=60><br>
550 <input tabindex=5 type=submit value=\"{$save}\" name=\"wpSave\">
551 <input tabindex=6 type=submit value=\"{$prev}\" name=\"wpPreview\">
552 <em>{$cancel}</em> | <em>{$edithelp}</em>
554 <input type=hidden value=\"{$wpEdittime}\" name=\"wpEdittime\">\n" );
557 $wgOut->addHTML( "<h2>" . wfMsg( "yourdiff" ) . "</h2>\n" );
558 DifferenceEngine
::showDiff( $wpTextbox2, $wpTextbox1,
559 wfMsg( "yourtext" ), wfMsg( "storedversion" ) );
561 $wgOut->addHTML( "<h2>" . wfMsg( "yourtext" ) . "</h2>
562 <textarea tabindex=6 name=\"wpTextbox2\" rows={$rows} cols={$cols} wrap=virtual>"
563 . $wgLang->recodeForEdit( $wpTextbox2 ) .
567 $wgOut->addHTML( "</form>\n" );
568 if($formtype =="preview" && !$wgUser->getOption("previewontop")) {
569 $wgOut->addHTML($previewhead);
570 $wgOut->addWikiText( $this->preSaveTransform( $previewtext ) );
575 # Theoretically we could defer these whole insert and update
576 # functions for after display, but that's taking a big leap
577 # of faith, and we want to be able to report database
578 # errors at some point.
580 /* private */ function insertNewArticle( $text, $summary, $isminor, $watchthis )
582 global $wgOut, $wgUser, $wgTitle, $wgLinkCache;
583 $fname = "Article::insertNewArticle";
585 $ns = $wgTitle->getNamespace();
586 $ttl = $wgTitle->getDBkey();
587 $text = $this->preSaveTransform( $text );
588 if ( preg_match( "/^#redirect/i", $text ) ) { $redir = 1; }
591 $now = wfTimestampNow();
592 $won = wfInvertTimestamp( $now );
593 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
594 "cur_comment,cur_user,cur_timestamp,cur_minor_edit,cur_counter," .
595 "cur_restrictions,cur_user_text,cur_is_redirect," .
596 "cur_is_new,cur_random,cur_touched,inverse_timestamp) VALUES ({$ns},'" . wfStrencode( $ttl ) . "', '" .
597 wfStrencode( $text ) . "', '" .
598 wfStrencode( $summary ) . "', '" .
599 $wgUser->getID() . "', '{$now}', " .
600 ( $isminor ?
1 : 0 ) . ", 0, '', '" .
601 wfStrencode( $wgUser->getName() ) . "', $redir, 1, RAND(), '{$now}', '{$won}')";
602 $res = wfQuery( $sql, $fname );
604 $newid = wfInsertId();
605 $wgTitle->resetArticleID( $newid );
607 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
608 "rc_namespace,rc_title,rc_new,rc_minor,rc_cur_id,rc_user," .
609 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid,rc_bot) VALUES (" .
610 "'{$now}','{$now}',{$ns},'" . wfStrencode( $ttl ) . "',1," .
611 ( $isminor ?
1 : 0 ) . ",{$newid}," . $wgUser->getID() . ",'" .
612 wfStrencode( $wgUser->getName() ) . "','" .
613 wfStrencode( $summary ) . "',0,0," .
614 ( $wgUser->isBot() ?
1 : 0 ) . ")";
615 wfQuery( $sql, $fname );
617 if(!$wgTitle->userIsWatching()) $this->watch();
619 if ( $wgTitle->userIsWatching() ) {
624 $this->showArticle( $text, wfMsg( "newarticle" ) );
627 function updateArticle( $text, $summary, $minor, $watchthis )
629 global $wgOut, $wgUser, $wgTitle, $wgLinkCache;
630 global $wgDBtransactions;
631 $fname = "Article::updateArticle";
633 if ( $this->mMinorEdit
) { $me1 = 1; } else { $me1 = 0; }
634 if ( $minor ) { $me2 = 1; } else { $me2 = 0; }
635 if ( preg_match( "/^(#redirect[^\\n]+)/i", $text, $m ) ) {
637 $text = $m[1] . "\n"; # Remove all content but redirect
640 $this->loadLastEdit();
642 $text = $this->preSaveTransform( $text );
644 # Update article, but only if changed.
646 if( $wgDBtransactions ) {
650 $oldtext = $this->getContent( true );
652 if ( 0 != strcmp( $text, $oldtext ) ) {
653 $this->mCountAdjustment
= $this->isCountable( $text )
654 - $this->isCountable( $oldtext );
656 $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
657 "old_comment,old_user,old_user_text,old_timestamp," .
658 "old_minor_edit,inverse_timestamp) VALUES (" .
659 $wgTitle->getNamespace() . ", '" .
660 wfStrencode( $wgTitle->getDBkey() ) . "', '" .
661 wfStrencode( $oldtext ) . "', '" .
662 wfStrencode( $this->getComment() ) . "', " .
663 $this->getUser() . ", '" .
664 wfStrencode( $this->getUserText() ) . "', '" .
665 $this->getTimestamp() . "', " . $me1 . ", '" .
666 wfInvertTimestamp( $this->getTimestamp() ) . "')";
667 $res = wfQuery( $sql, $fname );
668 $oldid = wfInsertID( $res );
670 $now = wfTimestampNow();
671 $won = wfInvertTimestamp( $now );
672 $sql = "UPDATE cur SET cur_text='" . wfStrencode( $text ) .
673 "',cur_comment='" . wfStrencode( $summary ) .
674 "',cur_minor_edit={$me2}, cur_user=" . $wgUser->getID() .
675 ",cur_timestamp='{$now}',cur_user_text='" .
676 wfStrencode( $wgUser->getName() ) .
677 "',cur_is_redirect={$redir}, cur_is_new=0, cur_touched='{$now}', inverse_timestamp='{$won}' " .
678 "WHERE cur_id=" . $this->getID();
679 wfQuery( $sql, $fname );
681 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time," .
682 "rc_namespace,rc_title,rc_new,rc_minor,rc_bot,rc_cur_id,rc_user," .
683 "rc_user_text,rc_comment,rc_this_oldid,rc_last_oldid) VALUES (" .
684 "'{$now}','{$now}'," . $wgTitle->getNamespace() . ",'" .
685 wfStrencode( $wgTitle->getDBkey() ) . "',0,{$me2}," .
686 ( $wgUser->isBot() ?
1 : 0 ) . "," .
687 $this->getID() . "," . $wgUser->getID() . ",'" .
688 wfStrencode( $wgUser->getName() ) . "','" .
689 wfStrencode( $summary ) . "',0,{$oldid})";
690 wfQuery( $sql, $fname );
692 $sql = "UPDATE recentchanges SET rc_this_oldid={$oldid} " .
693 "WHERE rc_namespace=" . $wgTitle->getNamespace() . " AND " .
694 "rc_title='" . wfStrencode( $wgTitle->getDBkey() ) . "' AND " .
695 "rc_timestamp='" . $this->getTimestamp() . "'";
696 wfQuery( $sql, $fname );
698 $sql = "UPDATE recentchanges SET rc_cur_time='{$now}' " .
699 "WHERE rc_cur_id=" . $this->getID();
700 wfQuery( $sql, $fname );
702 if( $wgDBtransactions ) {
708 if (!$wgTitle->userIsWatching()) $this->watch();
710 if ( $wgTitle->userIsWatching() ) {
715 $this->showArticle( $text, wfMsg( "updated" ) );
718 # After we've either updated or inserted the article, update
719 # the link tables and redirect to the new page.
721 function showArticle( $text, $subtitle )
723 global $wgOut, $wgTitle, $wgUser, $wgLinkCache;
725 $wgLinkCache = new LinkCache();
726 $wgOut->addWikiText( $text ); # Just to update links
728 $this->editUpdates( $text );
729 if( preg_match( "/^#redirect/i", $text ) )
733 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL(), $r ) );
736 # If the page we've just displayed is in the "Image" namespace,
737 # we follow it with an upload history of the image and its usage.
739 function imageHistory()
741 global $wgUser, $wgOut, $wgLang, $wgTitle;
742 $fname = "Article::imageHistory";
744 $sql = "SELECT img_size,img_description,img_user," .
745 "img_user_text,img_timestamp FROM image WHERE " .
746 "img_name='" . wfStrencode( $wgTitle->getDBkey() ) . "'";
747 $res = wfQuery( $sql, $fname );
749 if ( 0 == wfNumRows( $res ) ) { return; }
751 $sk = $wgUser->getSkin();
752 $s = $sk->beginImageHistoryList();
754 $line = wfFetchObject( $res );
755 $s .= $sk->imageHistoryLine( true, $line->img_timestamp
,
756 $wgTitle->getText(), $line->img_user
,
757 $line->img_user_text
, $line->img_size
, $line->img_description
);
759 $sql = "SELECT oi_size,oi_description,oi_user," .
760 "oi_user_text,oi_timestamp,oi_archive_name FROM oldimage WHERE " .
761 "oi_name='" . wfStrencode( $wgTitle->getDBkey() ) . "' " .
762 "ORDER BY oi_timestamp DESC";
763 $res = wfQuery( $sql, $fname );
765 while ( $line = wfFetchObject( $res ) ) {
766 $s .= $sk->imageHistoryLine( false, $line->oi_timestamp
,
767 $line->oi_archive_name
, $line->oi_user
,
768 $line->oi_user_text
, $line->oi_size
, $line->oi_description
);
770 $s .= $sk->endImageHistoryList();
771 $wgOut->addHTML( $s );
774 function imageLinks()
776 global $wgUser, $wgOut, $wgTitle;
778 $wgOut->addHTML( "<h2>" . wfMsg( "imagelinks" ) . "</h2>\n" );
780 $sql = "SELECT il_from FROM imagelinks WHERE il_to='" .
781 wfStrencode( $wgTitle->getDBkey() ) . "'";
782 $res = wfQuery( $sql, "Article::imageLinks" );
784 if ( 0 == wfNumRows( $res ) ) {
785 $wgOut->addHtml( "<p>" . wfMsg( "nolinkstoimage" ) . "\n" );
788 $wgOut->addHTML( "<p>" . wfMsg( "linkstoimage" ) . "\n<ul>" );
790 $sk = $wgUser->getSkin();
791 while ( $s = wfFetchObject( $res ) ) {
793 $link = $sk->makeKnownLink( $name, "" );
794 $wgOut->addHTML( "<li>{$link}</li>\n" );
796 $wgOut->addHTML( "</ul>\n" );
799 # Add this page to my watchlist
803 global $wgUser, $wgTitle, $wgOut, $wgLang;
804 global $wgDeferredUpdateList;
806 if ( 0 == $wgUser->getID() ) {
807 $wgOut->errorpage( "watchnologin", "watchnologintext" );
810 if ( wfReadOnly() ) {
811 $wgOut->readOnlyPage();
814 $wgUser->addWatch( $wgTitle );
816 $wgOut->setPagetitle( wfMsg( "addedwatch" ) );
817 $wgOut->setRobotpolicy( "noindex,follow" );
819 $sk = $wgUser->getSkin() ;
820 $link = $sk->makeKnownLink ( $wgTitle->getPrefixedText() ) ;
822 $text = str_replace( "$1", $link ,
823 wfMsg( "addedwatchtext" ) );
824 $wgOut->addHTML( $text );
826 $up = new UserUpdate();
827 array_push( $wgDeferredUpdateList, $up );
829 $wgOut->returnToMain( false );
834 global $wgUser, $wgTitle, $wgOut, $wgLang;
835 global $wgDeferredUpdateList;
837 if ( 0 == $wgUser->getID() ) {
838 $wgOut->errorpage( "watchnologin", "watchnologintext" );
841 if ( wfReadOnly() ) {
842 $wgOut->readOnlyPage();
845 $wgUser->removeWatch( $wgTitle );
847 $wgOut->setPagetitle( wfMsg( "removedwatch" ) );
848 $wgOut->setRobotpolicy( "noindex,follow" );
850 $sk = $wgUser->getSkin() ;
851 $link = $sk->makeKnownLink ( $wgTitle->getPrefixedText() ) ;
853 $text = str_replace( "$1", $link ,
854 wfMsg( "removedwatchtext" ) );
855 $wgOut->addHTML( $text );
857 $up = new UserUpdate();
858 array_push( $wgDeferredUpdateList, $up );
860 $wgOut->returnToMain( false );
863 # This shares a lot of issues (and code) with Recent Changes
867 global $wgUser, $wgOut, $wgLang, $wgTitle, $offset, $limit;
869 # If page hasn't changed, client can cache this
871 $wgOut->checkLastModified( $this->getTimestamp() );
872 wfProfileIn( "Article::history" );
874 $wgOut->setPageTitle( $wgTitle->getPRefixedText() );
875 $wgOut->setSubtitle( wfMsg( "revhistory" ) );
876 $wgOut->setArticleFlag( false );
877 $wgOut->setRobotpolicy( "noindex,nofollow" );
879 if( $wgTitle->getArticleID() == 0 ) {
880 $wgOut->addHTML( wfMsg( "nohistory" ) );
885 $offset = (int)$offset;
886 $limit = (int)$limit;
887 if( $limit == 0 ) $limit = 50;
888 $namespace = $wgTitle->getNamespace();
889 $title = $wgTitle->getText();
890 $sql = "SELECT old_id,old_user," .
891 "old_comment,old_user_text,old_timestamp,old_minor_edit ".
892 "FROM old USE INDEX (name_title_timestamp) " .
893 "WHERE old_namespace={$namespace} AND " .
894 "old_title='" . wfStrencode( $wgTitle->getDBkey() ) . "' " .
895 "ORDER BY inverse_timestamp LIMIT $offset, $limit";
896 $res = wfQuery( $sql, "Article::history" );
898 $revs = wfNumRows( $res );
899 if( $wgTitle->getArticleID() == 0 ) {
900 $wgOut->addHTML( wfMsg( "nohistory" ) );
905 $sk = $wgUser->getSkin();
906 $numbar = wfViewPrevNext(
908 $wgTitle->getPrefixedText(),
911 $s .= $sk->beginHistoryList();
914 $s .= $sk->historyLine( $this->getTimestamp(), $this->getUser(),
915 $this->getUserText(), $namespace,
916 $title, 0, $this->getComment(),
917 ( $this->getMinorEdit() > 0 ) );
919 $revs = wfNumRows( $res );
920 while ( $line = wfFetchObject( $res ) ) {
921 $s .= $sk->historyLine( $line->old_timestamp
, $line->old_user
,
922 $line->old_user_text
, $namespace,
923 $title, $line->old_id
,
924 $line->old_comment
, ( $line->old_minor_edit
> 0 ) );
926 $s .= $sk->endHistoryList();
928 $wgOut->addHTML( $s );
934 global $wgUser, $wgOut, $wgTitle;
936 if ( ! $wgUser->isSysop() ) {
937 $wgOut->sysopRequired();
940 if ( wfReadOnly() ) {
941 $wgOut->readOnlyPage();
944 $id = $wgTitle->getArticleID();
946 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
949 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
950 "cur_restrictions='sysop' WHERE cur_id={$id}";
951 wfQuery( $sql, "Article::protect" );
953 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
958 global $wgUser, $wgOut, $wgTitle;
960 if ( ! $wgUser->isSysop() ) {
961 $wgOut->sysopRequired();
964 if ( wfReadOnly() ) {
965 $wgOut->readOnlyPage();
968 $id = $wgTitle->getArticleID();
970 $wgOut->fatalEror( wfMsg( "badarticleerror" ) );
973 $sql = "UPDATE cur SET cur_touched='" . wfTimestampNow() . "'," .
974 "cur_restrictions='' WHERE cur_id={$id}";
975 wfQuery( $sql, "Article::unprotect" );
977 $wgOut->redirect( wfLocalUrl( $wgTitle->getPrefixedURL() ) );
982 global $wgUser, $wgOut, $wgTitle;
983 global $wpConfirm, $wpReason, $image, $oldimage;
985 # Anybody can delete old revisions of images; only sysops
986 # can delete articles and current images
988 if ( ( ! $oldimage ) && ( ! $wgUser->isSysop() ) ) {
989 $wgOut->sysopRequired();
992 if ( wfReadOnly() ) {
993 $wgOut->readOnlyPage();
997 # Better double-check that it hasn't been deleted yet!
998 $wgOut->setPagetitle( wfMsg( "confirmdelete" ) );
1000 if ( "" == trim( $image ) ) {
1001 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
1004 $sub = str_replace( "$1", $image, wfMsg( "deletesub" ) );
1006 if ( ( "" == trim( $wgTitle->getText() ) )
1007 or ( $wgTitle->getArticleId() == 0 ) ) {
1008 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
1011 $sub = str_replace( "$1", $wgTitle->getPrefixedText(),
1012 wfMsg( "deletesub" ) );
1015 # Likewise, deleting old images doesn't require confirmation
1016 if ( $oldimage ||
1 == $wpConfirm ) {
1021 $wgOut->setSubtitle( $sub );
1022 $wgOut->setRobotpolicy( "noindex,nofollow" );
1023 $wgOut->addWikiText( wfMsg( "confirmdeletetext" ) );
1025 $t = $wgTitle->getPrefixedURL();
1026 $q = "action=delete";
1029 $q .= "&image={$image}";
1030 } else if ( $oldimage ) {
1031 $q .= "&oldimage={$oldimage}";
1033 $q .= "&title={$t}";
1035 $formaction = wfEscapeHTML( wfLocalUrl( "", $q ) );
1036 $confirm = wfMsg( "confirm" );
1037 $check = wfMsg( "confirmcheck" );
1038 $delcom = wfMsg( "deletecomment" );
1041 <form id=\"deleteconfirm\" method=\"post\" action=\"{$formaction}\">
1042 <table border=0><tr><td align=right>
1043 {$delcom}:</td><td align=left>
1044 <input type=text size=20 name=\"wpReason\" value=\"{$wpReason}\">
1045 </td></tr><tr><td> </td></tr>
1046 <tr><td align=right>
1047 <input type=checkbox name=\"wpConfirm\" value='1'>
1048 </td><td>{$check}</td>
1049 </tr><tr><td> </td><td>
1050 <input type=submit name=\"wpConfirmB\" value=\"{$confirm}\">
1051 </td></tr></table></form>\n" );
1053 $wgOut->returnToMain( false );
1058 global $wgOut, $wgTitle, $wgUser, $wgLang;
1059 global $image, $oldimage, $wpReason;
1060 $fname = "Article::doDelete";
1063 $dest = wfImageDir( $image );
1064 $archive = wfImageDir( $image );
1065 if ( ! unlink( "{$dest}/{$image}" ) ) {
1066 $wgOut->fileDeleteError( "{$dest}/{$image}" );
1069 $sql = "DELETE FROM image WHERE img_name='" .
1070 wfStrencode( $image ) . "'";
1071 wfQuery( $sql, $fname );
1073 $sql = "SELECT oi_archive_name FROM oldimage WHERE oi_name='" .
1074 wfStrencode( $image ) . "'";
1075 $res = wfQuery( $sql, $fname );
1077 while ( $s = wfFetchObject( $res ) ) {
1078 $this->doDeleteOldImage( $s->oi_archive_name
);
1080 $sql = "DELETE FROM oldimage WHERE oi_name='" .
1081 wfStrencode( $image ) . "'";
1082 wfQuery( $sql, $fname );
1084 # Image itself is now gone, and database is cleaned.
1085 # Now we remove the image description page.
1087 $nt = Title
::newFromText( $wgLang->getNsText( Namespace::getImage() ) . ":" . $image );
1088 $this->doDeleteArticle( $nt );
1091 } else if ( $oldimage ) {
1092 $this->doDeleteOldImage( $oldimage );
1093 $sql = "DELETE FROM oldimage WHERE oi_archive_name='" .
1094 wfStrencode( $oldimage ) . "'";
1095 wfQuery( $sql, $fname );
1097 $deleted = $oldimage;
1099 $this->doDeleteArticle( $wgTitle );
1100 $deleted = $wgTitle->getPrefixedText();
1102 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1103 $wgOut->setRobotpolicy( "noindex,nofollow" );
1105 $sk = $wgUser->getSkin();
1106 $loglink = $sk->makeKnownLink( $wgLang->getNsText(
1107 Namespace::getWikipedia() ) .
1108 ":" . wfMsg( "dellogpage" ), wfMsg( "deletionlog" ) );
1110 $text = str_replace( "$1" , $deleted, wfMsg( "deletedtext" ) );
1111 $text = str_replace( "$2", $loglink, $text );
1113 $wgOut->addHTML( "<p>" . $text );
1114 $wgOut->returnToMain( false );
1117 function doDeleteOldImage( $oldimage )
1121 $name = substr( $oldimage, 15 );
1122 $archive = wfImageArchiveDir( $name );
1123 if ( ! unlink( "{$archive}/{$oldimage}" ) ) {
1124 $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
1128 function doDeleteArticle( $title )
1130 global $wgUser, $wgOut, $wgLang, $wpReason, $wgTitle, $wgDeferredUpdateList;
1132 $fname = "Article::doDeleteArticle";
1133 $ns = $title->getNamespace();
1134 $t = wfStrencode( $title->getDBkey() );
1135 $id = $title->getArticleID();
1138 $wgOut->fatalError( wfMsg( "cannotdelete" ) );
1142 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1143 array_push( $wgDeferredUpdateList, $u );
1145 # Move article and history to the "archive" table
1146 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
1147 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
1148 "ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment," .
1149 "cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur " .
1150 "WHERE cur_namespace={$ns} AND cur_title='{$t}'";
1151 wfQuery( $sql, $fname );
1153 $sql = "INSERT INTO archive (ar_namespace,ar_title,ar_text," .
1154 "ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit," .
1155 "ar_flags) SELECT old_namespace,old_title,old_text,old_comment," .
1156 "old_user,old_user_text,old_timestamp,old_minor_edit,old_flags " .
1157 "FROM old WHERE old_namespace={$ns} AND old_title='{$t}'";
1158 wfQuery( $sql, $fname );
1160 # Now that it's safely backed up, delete it
1162 $sql = "DELETE FROM cur WHERE cur_namespace={$ns} AND " .
1164 wfQuery( $sql, $fname );
1166 $sql = "DELETE FROM old WHERE old_namespace={$ns} AND " .
1168 wfQuery( $sql, $fname );
1170 $sql = "DELETE FROM recentchanges WHERE rc_namespace={$ns} AND " .
1172 wfQuery( $sql, $fname );
1174 # Finally, clean up the link tables
1177 $t = wfStrencode( $title->getPrefixedDBkey() );
1178 $sql = "SELECT l_from FROM links WHERE l_to={$id}";
1179 $res = wfQuery( $sql, $fname );
1181 $sql = "INSERT INTO brokenlinks (bl_from,bl_to) VALUES ";
1182 $now = wfTimestampNow();
1183 $sql2 = "UPDATE cur SET cur_touched='{$now}' WHERE cur_id IN (";
1186 while ( $s = wfFetchObject( $res ) ) {
1187 $nt = Title
::newFromDBkey( $s->l_from
);
1188 $lid = $nt->getArticleID();
1190 if ( ! $first ) { $sql .= ","; $sql2 .= ","; }
1192 $sql .= "({$lid},'{$t}')";
1197 wfQuery( $sql, $fname );
1198 wfQuery( $sql2, $fname );
1200 wfFreeResult( $res );
1202 $sql = "DELETE FROM links WHERE l_to={$id}";
1203 wfQuery( $sql, $fname );
1205 $sql = "DELETE FROM links WHERE l_from='{$t}'";
1206 wfQuery( $sql, $fname );
1208 $sql = "DELETE FROM imagelinks WHERE il_from='{$t}'";
1209 wfQuery( $sql, $fname );
1211 $sql = "DELETE FROM brokenlinks WHERE bl_from={$id}";
1212 wfQuery( $sql, $fname );
1215 $log = new LogPage( wfMsg( "dellogpage" ), wfMsg( "dellogpagetext" ) );
1216 $art = $title->getPrefixedText();
1217 $wpReason = wfCleanQueryVar( $wpReason );
1218 $log->addEntry( str_replace( "$1", $art, wfMsg( "deletedarticle" ) ), $wpReason );
1220 # Clear the cached article id so the interface doesn't act like we exist
1221 $wgTitle->resetArticleID( 0 );
1222 $wgTitle->mArticleID
= 0;
1230 if ( strlen( $oldimage ) < 16 ) {
1231 $wgOut->unexpectedValueError( "oldimage", $oldimage );
1234 if ( wfReadOnly() ) {
1235 $wgOut->readOnlyPage();
1238 $name = substr( $oldimage, 15 );
1240 $dest = wfImageDir( $name );
1241 $archive = wfImageArchiveDir( $name );
1242 $curfile = "{$dest}/{$name}";
1244 if ( ! is_file( $curfile ) ) {
1245 $wgOut->fileNotFoundError( $curfile );
1248 $oldver = wfTimestampNow() . "!{$name}";
1249 $size = wfGetSQL( "oldimage", "oi_size", "oi_archive_name='" .
1250 wfStrencode( $oldimage ) . "'" );
1252 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
1253 $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
1256 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
1257 $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
1259 wfRecordUpload( $name, $oldver, $size, wfMsg( "reverted" ) );
1261 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1262 $wgOut->setRobotpolicy( "noindex,nofollow" );
1263 $wgOut->addHTML( wfMsg( "imagereverted" ) );
1264 $wgOut->returnToMain( false );
1269 global $wgUser, $wgTitle, $wgLang, $wgOut;
1271 if ( ! $wgUser->isSysop() ) {
1272 $wgOut->sysopRequired();
1276 # Replace all this user's current edits with the next one down
1277 $tt = wfStrencode( $wgTitle->getDBKey() );
1278 $n = $wgTitle->getNamespace();
1280 # Get the last editor
1281 $sql = "SELECT cur_id,cur_user,cur_user_text FROM cur WHERE cur_title='{$tt}' AND cur_namespace={$n}";
1282 $res = wfQuery( $sql );
1283 if( ($x = wfNumRows( $res )) != 1 ) {
1285 $wgOut->addHTML( wfMsg( "notanarticle" ) );
1288 $s = wfFetchObject( $res );
1289 $ut = wfStrencode( $s->cur_user_text
);
1290 $uid = $s->cur_user
;
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 );
1300 if( wfNumRows( $res ) != 1 ) {
1302 $wgOut->addHTML( wfMsg( "cantrollback" ) );
1305 $s = wfFetchObject( $res );
1308 $newcomment = str_replace( "$1", $s->old_user_text
, wfMsg( "revertpage" ) );
1309 $wgOut->setPagetitle( wfMsg( "actioncomplete" ) );
1310 $wgOut->setRobotpolicy( "noindex,nofollow" );
1311 $wgOut->addHTML( "<h2>" . $newcomment . "</h2>\n<hr>\n" );
1312 $this->updateArticle( $s->old_text
, $newcomment, 1, $wgTitle->userIsWatching() );
1314 $wgOut->returnToMain( false );
1318 # Do standard deferred updates after page view
1320 /* private */ function viewUpdates()
1322 global $wgDeferredUpdateList, $wgTitle;
1324 if ( 0 != $this->getID() ) {
1325 $u = new ViewCountUpdate( $this->getID() );
1326 array_push( $wgDeferredUpdateList, $u );
1327 $u = new SiteStatsUpdate( 1, 0, 0 );
1328 array_push( $wgDeferredUpdateList, $u );
1330 $u = new UserTalkUpdate( 0, $wgTitle->getNamespace(),
1331 $wgTitle->getDBkey() );
1332 array_push( $wgDeferredUpdateList, $u );
1336 # Do standard deferred updates after page edit.
1337 # Every 1000th edit, prune the recent changes table.
1339 /* private */ function editUpdates( $text )
1341 global $wgDeferredUpdateList, $wgTitle;
1344 if ( 0 == mt_rand( 0, 999 ) ) {
1345 $cutoff = wfUnix2Timestamp( time() - ( 7 * 86400 ) );
1346 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1349 $id = $this->getID();
1350 $title = $wgTitle->getPrefixedDBkey();
1351 $adj = $this->mCountAdjustment
;
1354 $u = new LinksUpdate( $id, $title );
1355 array_push( $wgDeferredUpdateList, $u );
1356 $u = new SiteStatsUpdate( 0, 1, $adj );
1357 array_push( $wgDeferredUpdateList, $u );
1358 $u = new SearchUpdate( $id, $title, $text );
1359 array_push( $wgDeferredUpdateList, $u );
1361 $u = new UserTalkUpdate( 1, $wgTitle->getNamespace(),
1362 $wgTitle->getDBkey() );
1363 array_push( $wgDeferredUpdateList, $u );
1367 /* private */ function setOldSubtitle()
1369 global $wgLang, $wgOut;
1371 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
1372 $r = str_replace( "$1", "{$td}", wfMsg( "revisionasof" ) );
1373 $wgOut->setSubtitle( "({$r})" );
1376 function blockedIPpage()
1378 global $wgOut, $wgUser, $wgLang;
1380 $wgOut->setPageTitle( wfMsg( "blockedtitle" ) );
1381 $wgOut->setRobotpolicy( "noindex,nofollow" );
1382 $wgOut->setArticleFlag( false );
1384 $id = $wgUser->blockedBy();
1385 $reason = $wgUser->blockedFor();
1387 $name = User
::whoIs( $id );
1388 $link = "[[" . $wgLang->getNsText( Namespace::getUser() ) .
1389 ":{$name}|{$name}]]";
1391 $text = str_replace( "$1", $link, wfMsg( "blockedtext" ) );
1392 $text = str_replace( "$2", $reason, $text );
1393 $wgOut->addWikiText( $text );
1394 $wgOut->returnToMain( false );
1397 # This function is called right before saving the wikitext,
1398 # so we can do things like signatures and links-in-context.
1400 function preSaveTransform( $text )
1403 while ( "" != $text ) {
1404 $p = preg_split( "/<\\s*nowiki\\s*>/i", $text, 2 );
1405 $s .= $this->pstPass2( $p[0] );
1407 if ( ( count( $p ) < 2 ) ||
( "" == $p[1] ) ) { $text = ""; }
1409 $q = preg_split( "/<\\/\\s*nowiki\\s*>/i", $p[1], 2 );
1410 $s .= "<nowiki>{$q[0]}</nowiki>";
1417 /* private */ function pstPass2( $text )
1419 global $wgUser, $wgLang, $wgTitle, $wgLocaltimezone;
1423 $n = $wgUser->getName();
1424 $k = $wgUser->getOption( "nickname" );
1425 if ( "" == $k ) { $k = $n; }
1426 if(isset($wgLocaltimezone)) {
1427 $oldtz = getenv("TZ"); putenv("TZ=$wgLocaltimezone");
1429 $d = $wgLang->timeanddate( wfTimestampNow(), false ) .
1430 " (" . date( "T" ) . ")";
1431 if(isset($wgLocaltimezone)) putenv("TZ=$oldtz");
1433 $text = preg_replace( "/~~~~/", "[[" . $wgLang->getNsText(
1434 Namespace::getUser() ) . ":$n|$k]] $d", $text );
1435 $text = preg_replace( "/~~~/", "[[" . $wgLang->getNsText(
1436 Namespace::getUser() ) . ":$n|$k]]", $text );
1438 # Context links: [[|name]] and [[name (context)|]]
1440 $tc = "[&;%\\-,.\\(\\)' _0-9A-Za-z\\/:\\x80-\\xff]";
1441 $np = "[&;%\\-,.' _0-9A-Za-z\\/:\\x80-\\xff]"; # No parens
1442 $conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
1444 $p1 = "/\[\[({$np}+) \\(({$np}+)\\)\\|]]/"; # [[page (context)|]]
1445 $p2 = "/\[\[\\|({$tc}+)]]/"; # [[|page]]
1446 $p3 = "/\[\[([A-Za-z _]+):({$np}+)\\|]]/"; # [[namespace:page|]]
1447 $p4 = "/\[\[([A-Aa-z _]+):({$np}+) \\(({$np}+)\\)\\|]]/";
1448 # [[ns:page (cont)|]]
1450 $t = $wgTitle->getText();
1451 if ( preg_match( $conpat, $t, $m ) ) {
1454 $text = preg_replace( $p4, "[[\\1:\\2 (\\3)|\\2]]", $text );
1455 $text = preg_replace( $p1, "[[\\1 (\\2)|\\1]]", $text );
1456 $text = preg_replace( $p3, "[[\\1:\\2|\\2]]", $text );
1458 if ( "" == $context ) {
1459 $text = preg_replace( $p2, "[[\\1]]", $text );
1461 $text = preg_replace( $p2, "[[\\1 ({$context})|\\1]]", $text );
1463 # Replace local image links with new [[image:]] style
1465 $text = preg_replace(
1466 "/(^|[^[])http:\/\/(www.|)wikipedia.com\/upload\/" .
1467 "([a-zA-Z0-9_:.~\%\-]+)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)/",
1468 "\\1[[image:\\3.\\4]]", $text );
1469 $text = preg_replace(
1470 "/(^|[^[])http:\/\/(www.|)wikipedia.com\/images\/uploads\/" .
1471 "([a-zA-Z0-9_:.~\%\-]+)\.(png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF)/",
1472 "\\1[[image:\\3.\\4]]", $text );