* Display the anon talk page info message on anon talk pages again (moved outside...
[lhc/web/wiklou.git] / includes / Article.php
1 <?php
2 /**
3 * File for articles
4 * @package MediaWiki
5 */
6
7 /**
8 * Need the CacheManager to be loaded
9 */
10 require_once( 'CacheManager.php' );
11 require_once( 'Revision.php' );
12
13 $wgArticleCurContentFields = false;
14 $wgArticleOldContentFields = false;
15
16 /**
17 * Class representing a MediaWiki article and history.
18 *
19 * See design.txt for an overview.
20 * Note: edit user interface and cache support functions have been
21 * moved to separate EditPage and CacheManager classes.
22 *
23 * @package MediaWiki
24 */
25 class Article {
26 /**#@+
27 * @access private
28 */
29 var $mContent, $mContentLoaded;
30 var $mUser, $mTimestamp, $mUserText;
31 var $mCounter, $mComment, $mGoodAdjustment, $mTotalAdjustment;
32 var $mMinorEdit, $mRedirectedFrom;
33 var $mTouched, $mFileCache, $mTitle;
34 var $mId, $mTable;
35 var $mForUpdate;
36 var $mOldId;
37 var $mRevIdFetched;
38 var $mRevision;
39 var $mRedirectUrl;
40 var $mLatest;
41 /**#@-*/
42
43 /**
44 * Constructor and clear the article
45 * @param Title &$title
46 * @param integer $oldId Revision ID, null to fetch from request, zero for current
47 */
48 function Article( &$title, $oldId = null ) {
49 $this->mTitle =& $title;
50 $this->mOldId = $oldId;
51 $this->clear();
52 }
53
54 /**
55 * Tell the page view functions that this view was redirected
56 * from another page on the wiki.
57 * @param Title $from
58 */
59 function setRedirectedFrom( $from ) {
60 $this->mRedirectedFrom = $from;
61 }
62
63 /**
64 * @return mixed false, Title of in-wiki target, or string with URL
65 */
66 function followRedirect() {
67 $text = $this->getContent();
68 $rt = Title::newFromRedirect( $text );
69
70 # process if title object is valid and not special:userlogout
71 if( $rt ) {
72 if( $rt->getInterwiki() != '' ) {
73 if( $rt->isLocal() ) {
74 // Offsite wikis need an HTTP redirect.
75 //
76 // This can be hard to reverse and may produce loops,
77 // so they may be disabled in the site configuration.
78
79 $source = $this->mTitle->getFullURL( 'redirect=no' );
80 return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
81 }
82 } else {
83 if( $rt->getNamespace() == NS_SPECIAL ) {
84 // Gotta hand redirects to special pages differently:
85 // Fill the HTTP response "Location" header and ignore
86 // the rest of the page we're on.
87 //
88 // This can be hard to reverse, so they may be disabled.
89
90 if( $rt->getNamespace() == NS_SPECIAL && $rt->getText() == 'Userlogout' ) {
91 // rolleyes
92 } else {
93 return $rt->getFullURL();
94 }
95 }
96 return $rt;
97 }
98 }
99
100 // No or invalid redirect
101 return false;
102 }
103
104 /**
105 * get the title object of the article
106 */
107 function getTitle() {
108 return $this->mTitle;
109 }
110
111 /**
112 * Clear the object
113 * @access private
114 */
115 function clear() {
116 $this->mDataLoaded = false;
117 $this->mContentLoaded = false;
118
119 $this->mCurID = $this->mUser = $this->mCounter = -1; # Not loaded
120 $this->mRedirectedFrom = null; # Title object if set
121 $this->mUserText =
122 $this->mTimestamp = $this->mComment = $this->mFileCache = '';
123 $this->mGoodAdjustment = $this->mTotalAdjustment = 0;
124 $this->mTouched = '19700101000000';
125 $this->mForUpdate = false;
126 $this->mIsRedirect = false;
127 $this->mRevIdFetched = 0;
128 $this->mRedirectUrl = false;
129 $this->mLatest = false;
130 }
131
132 /**
133 * Note that getContent/loadContent do not follow redirects anymore.
134 * If you need to fetch redirectable content easily, try
135 * the shortcut in Article::followContent()
136 *
137 * @fixme There are still side-effects in this!
138 * In general, you should use the Revision class, not Article,
139 * to fetch text for purposes other than page views.
140 *
141 * @return Return the text of this revision
142 */
143 function getContent() {
144 global $wgRequest, $wgUser, $wgOut;
145
146 # Get variables from query string :P
147 $action = $wgRequest->getText( 'action', 'view' );
148 $section = $wgRequest->getText( 'section' );
149 $preload = $wgRequest->getText( 'preload' );
150
151 $fname = 'Article::getContent';
152 wfProfileIn( $fname );
153
154 if ( 0 == $this->getID() ) {
155 if ( 'edit' == $action ) {
156 wfProfileOut( $fname );
157
158 # If requested, preload some text.
159 $text=$this->getPreloadedText($preload);
160
161 # We used to put MediaWiki:Newarticletext here if
162 # $text was empty at this point.
163 # This is now shown above the edit box instead.
164 return $text;
165 }
166 wfProfileOut( $fname );
167 $wgOut->setRobotpolicy( 'noindex,nofollow' );
168
169 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
170 $ret = wfMsgWeirdKey ( $this->mTitle->getText() ) ;
171 } else {
172 $ret = wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' );
173 }
174
175 return "<div class='noarticletext'>$ret</div>";
176 } else {
177 $this->loadContent();
178 if($action=='edit') {
179 if($section!='') {
180 if($section=='new') {
181 wfProfileOut( $fname );
182 $text=$this->getPreloadedText($preload);
183 return $text;
184 }
185
186 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
187 # comments to be stripped as well)
188 $rv=$this->getSection($this->mContent,$section);
189 wfProfileOut( $fname );
190 return $rv;
191 }
192 }
193 wfProfileOut( $fname );
194 return $this->mContent;
195 }
196 }
197
198 /**
199 * Get the contents of a page from its title and remove includeonly tags
200 *
201 * @param string The title of the page
202 * @return string The contents of the page
203 */
204 function getPreloadedText($preload) {
205 if ( $preload === '' )
206 return '';
207 else {
208 $preloadTitle = Title::newFromText( $preload );
209 if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) {
210 $rev=Revision::newFromTitle($preloadTitle);
211 if ( is_object( $rev ) ) {
212 $text = $rev->getText();
213 // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing
214 // its own mini-parser! -ævar
215 $text = preg_replace( '~</?includeonly>~', '', $text );
216 return $text;
217 } else
218 return '';
219 }
220 }
221 }
222
223 /**
224 * This function returns the text of a section, specified by a number ($section).
225 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
226 * the first section before any such heading (section 0).
227 *
228 * If a section contains subsections, these are also returned.
229 *
230 * @param string $text text to look in
231 * @param integer $section section number
232 * @return string text of the requested section
233 */
234 function getSection($text,$section) {
235
236 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
237 # comments to be stripped as well)
238 $striparray=array();
239 $parser=new Parser();
240 $parser->mOutputType=OT_WIKI;
241 $parser->mOptions = new ParserOptions();
242 $striptext=$parser->strip($text, $striparray, true);
243
244 # now that we can be sure that no pseudo-sections are in the source,
245 # split it up by section
246 $secs =
247 preg_split(
248 '/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
249 $striptext, -1,
250 PREG_SPLIT_DELIM_CAPTURE);
251 if($section==0) {
252 $rv=$secs[0];
253 } else {
254 $headline=$secs[$section*2-1];
255 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
256 $hlevel=$matches[1];
257
258 # translate wiki heading into level
259 if(strpos($hlevel,'=')!==false) {
260 $hlevel=strlen($hlevel);
261 }
262
263 $rv=$headline. $secs[$section*2];
264 $count=$section+1;
265
266 $break=false;
267 while(!empty($secs[$count*2-1]) && !$break) {
268
269 $subheadline=$secs[$count*2-1];
270 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
271 $subhlevel=$matches[1];
272 if(strpos($subhlevel,'=')!==false) {
273 $subhlevel=strlen($subhlevel);
274 }
275 if($subhlevel > $hlevel) {
276 $rv.=$subheadline.$secs[$count*2];
277 }
278 if($subhlevel <= $hlevel) {
279 $break=true;
280 }
281 $count++;
282
283 }
284 }
285 # reinsert stripped tags
286 $rv=$parser->unstrip($rv,$striparray);
287 $rv=$parser->unstripNoWiki($rv,$striparray);
288 $rv=trim($rv);
289 return $rv;
290
291 }
292
293 /**
294 * @return int The oldid of the article that is to be shown, 0 for the
295 * current revision
296 */
297 function getOldID() {
298 if ( is_null( $this->mOldId ) ) {
299 $this->mOldId = $this->getOldIDFromRequest();
300 }
301 return $this->mOldId;
302 }
303
304 /**
305 * Sets $this->mRedirectUrl to a correct URL if the query parameters are incorrect
306 *
307 * @return int The old id for the request
308 */
309 function getOldIDFromRequest() {
310 global $wgRequest;
311 $this->mRedirectUrl = false;
312 $oldid = $wgRequest->getVal( 'oldid' );
313 if ( isset( $oldid ) ) {
314 $oldid = intval( $oldid );
315 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
316 $nextid = $this->mTitle->getNextRevisionID( $oldid );
317 if ( $nextid ) {
318 $oldid = $nextid;
319 } else {
320 $this->mRedirectUrl = $this->mTitle->getFullURL( 'redirect=no' );
321 }
322 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
323 $previd = $this->mTitle->getPreviousRevisionID( $oldid );
324 if ( $previd ) {
325 $oldid = $previd;
326 } else {
327 # TODO
328 }
329 }
330 $lastid = $oldid;
331 }
332 if ( !$oldid ) {
333 $oldid = 0;
334 }
335 return $oldid;
336 }
337
338 /**
339 * Load the revision (including text) into this object
340 */
341 function loadContent() {
342 if ( $this->mContentLoaded ) return;
343
344 # Query variables :P
345 $oldid = $this->getOldID();
346
347 $fname = 'Article::loadContent';
348
349 # Pre-fill content with error message so that if something
350 # fails we'll have something telling us what we intended.
351
352 $t = $this->mTitle->getPrefixedText();
353
354 $this->mOldId = $oldid;
355 $this->fetchContent( $oldid );
356 }
357
358
359 /**
360 * Fetch a page record with the given conditions
361 * @param Database $dbr
362 * @param array $conditions
363 * @access private
364 */
365 function pageData( &$dbr, $conditions ) {
366 $fields = array(
367 'page_id',
368 'page_namespace',
369 'page_title',
370 'page_restrictions',
371 'page_counter',
372 'page_is_redirect',
373 'page_is_new',
374 'page_random',
375 'page_touched',
376 'page_latest',
377 'page_len' ) ;
378 wfRunHooks( 'ArticlePageDataBefore', array( &$this , &$fields ) ) ;
379 $row = $dbr->selectRow( 'page',
380 $fields,
381 $conditions,
382 'Article::pageData' );
383 wfRunHooks( 'ArticlePageDataAfter', array( &$this , &$row ) ) ;
384 return $row ;
385 }
386
387 /**
388 * @param Database $dbr
389 * @param Title $title
390 */
391 function pageDataFromTitle( &$dbr, $title ) {
392 return $this->pageData( $dbr, array(
393 'page_namespace' => $title->getNamespace(),
394 'page_title' => $title->getDBkey() ) );
395 }
396
397 /**
398 * @param Database $dbr
399 * @param int $id
400 */
401 function pageDataFromId( &$dbr, $id ) {
402 return $this->pageData( $dbr, array( 'page_id' => $id ) );
403 }
404
405 /**
406 * Set the general counter, title etc data loaded from
407 * some source.
408 *
409 * @param object $data
410 * @access private
411 */
412 function loadPageData( $data = 'fromdb' ) {
413 if ( $data === 'fromdb' ) {
414 $dbr =& $this->getDB();
415 $data = $this->pageDataFromId( $dbr, $this->getId() );
416 }
417
418 $lc =& LinkCache::singleton();
419 if ( $data ) {
420 $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
421
422 $this->mTitle->mArticleID = $data->page_id;
423 $this->mTitle->loadRestrictions( $data->page_restrictions );
424 $this->mTitle->mRestrictionsLoaded = true;
425
426 $this->mCounter = $data->page_counter;
427 $this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
428 $this->mIsRedirect = $data->page_is_redirect;
429 $this->mLatest = $data->page_latest;
430 } else {
431 if ( is_object( $this->mTitle ) ) {
432 $lc->addBadLinkObj( $this->mTitle );
433 }
434 $this->mTitle->mArticleID = 0;
435 }
436
437 $this->mDataLoaded = true;
438 }
439
440 /**
441 * Get text of an article from database
442 * Does *NOT* follow redirects.
443 * @param int $oldid 0 for whatever the latest revision is
444 * @return string
445 */
446 function fetchContent( $oldid = 0 ) {
447 if ( $this->mContentLoaded ) {
448 return $this->mContent;
449 }
450
451 $dbr =& $this->getDB();
452 $fname = 'Article::fetchContent';
453
454 # Pre-fill content with error message so that if something
455 # fails we'll have something telling us what we intended.
456 $t = $this->mTitle->getPrefixedText();
457 if( $oldid ) {
458 $t .= ',oldid='.$oldid;
459 }
460 $this->mContent = wfMsg( 'missingarticle', $t ) ;
461
462 if( $oldid ) {
463 $revision = Revision::newFromId( $oldid );
464 if( is_null( $revision ) ) {
465 wfDebug( "$fname failed to retrieve specified revision, id $oldid\n" );
466 return false;
467 }
468 $data = $this->pageDataFromId( $dbr, $revision->getPage() );
469 if( !$data ) {
470 wfDebug( "$fname failed to get page data linked to revision id $oldid\n" );
471 return false;
472 }
473 $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
474 $this->loadPageData( $data );
475 } else {
476 if( !$this->mDataLoaded ) {
477 $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
478 if( !$data ) {
479 wfDebug( "$fname failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
480 return false;
481 }
482 $this->loadPageData( $data );
483 }
484 $revision = Revision::newFromId( $this->mLatest );
485 if( is_null( $revision ) ) {
486 wfDebug( "$fname failed to retrieve current page, rev_id {$data->page_latest}\n" );
487 return false;
488 }
489 }
490
491 // FIXME: Horrible, horrible! This content-loading interface just plain sucks.
492 // We should instead work with the Revision object when we need it...
493 $this->mContent = $revision->userCan( MW_REV_DELETED_TEXT ) ? $revision->getRawText() : "";
494 //$this->mContent = $revision->getText();
495
496 $this->mUser = $revision->getUser();
497 $this->mUserText = $revision->getUserText();
498 $this->mComment = $revision->getComment();
499 $this->mTimestamp = wfTimestamp( TS_MW, $revision->getTimestamp() );
500
501 $this->mRevIdFetched = $revision->getID();
502 $this->mContentLoaded = true;
503 $this->mRevision =& $revision;
504
505 wfRunHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) ) ;
506
507 return $this->mContent;
508 }
509
510 /**
511 * Read/write accessor to select FOR UPDATE
512 *
513 * @param mixed $x
514 */
515 function forUpdate( $x = NULL ) {
516 return wfSetVar( $this->mForUpdate, $x );
517 }
518
519 /**
520 * Get the database which should be used for reads
521 *
522 * @return Database
523 */
524 function &getDB() {
525 $ret =& wfGetDB( DB_MASTER );
526 return $ret;
527 }
528
529 /**
530 * Get options for all SELECT statements
531 *
532 * @param array $options an optional options array which'll be appended to
533 * the default
534 * @return array Options
535 */
536 function getSelectOptions( $options = '' ) {
537 if ( $this->mForUpdate ) {
538 if ( is_array( $options ) ) {
539 $options[] = 'FOR UPDATE';
540 } else {
541 $options = 'FOR UPDATE';
542 }
543 }
544 return $options;
545 }
546
547 /**
548 * @return int Page ID
549 */
550 function getID() {
551 if( $this->mTitle ) {
552 return $this->mTitle->getArticleID();
553 } else {
554 return 0;
555 }
556 }
557
558 /**
559 * @return bool Whether or not the page exists in the database
560 */
561 function exists() {
562 return $this->getId() != 0;
563 }
564
565 /**
566 * @return int The view count for the page
567 */
568 function getCount() {
569 if ( -1 == $this->mCounter ) {
570 $id = $this->getID();
571 if ( $id == 0 ) {
572 $this->mCounter = 0;
573 } else {
574 $dbr =& wfGetDB( DB_SLAVE );
575 $this->mCounter = $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
576 'Article::getCount', $this->getSelectOptions() );
577 }
578 }
579 return $this->mCounter;
580 }
581
582 /**
583 * Determine whether a page would be suitable for being counted as an
584 * article in the site_stats table based on the title & its content
585 *
586 * @param string $text Text to analyze
587 * @return bool
588 */
589 function isCountable( $text ) {
590 global $wgUseCommaCount;
591
592 $token = $wgUseCommaCount ? ',' : '[[';
593 return
594 $this->mTitle->getNamespace() == NS_MAIN
595 && ! $this->isRedirect( $text )
596 && in_string( $token, $text );
597 }
598
599 /**
600 * Tests if the article text represents a redirect
601 *
602 * @param string $text
603 * @return bool
604 */
605 function isRedirect( $text = false ) {
606 if ( $text === false ) {
607 $this->loadContent();
608 $titleObj = Title::newFromRedirect( $this->fetchContent() );
609 } else {
610 $titleObj = Title::newFromRedirect( $text );
611 }
612 return $titleObj !== NULL;
613 }
614
615 /**
616 * Returns true if the currently-referenced revision is the current edit
617 * to this page (and it exists).
618 * @return bool
619 */
620 function isCurrent() {
621 return $this->exists() &&
622 isset( $this->mRevision ) &&
623 $this->mRevision->isCurrent();
624 }
625
626 /**
627 * Loads everything except the text
628 * This isn't necessary for all uses, so it's only done if needed.
629 * @access private
630 */
631 function loadLastEdit() {
632 if ( -1 != $this->mUser )
633 return;
634
635 # New or non-existent articles have no user information
636 $id = $this->getID();
637 if ( 0 == $id ) return;
638
639 $this->mLastRevision = Revision::loadFromPageId( $this->getDB(), $id );
640 if( !is_null( $this->mLastRevision ) ) {
641 $this->mUser = $this->mLastRevision->getUser();
642 $this->mUserText = $this->mLastRevision->getUserText();
643 $this->mTimestamp = $this->mLastRevision->getTimestamp();
644 $this->mComment = $this->mLastRevision->getComment();
645 $this->mMinorEdit = $this->mLastRevision->isMinor();
646 $this->mRevIdFetched = $this->mLastRevision->getID();
647 }
648 }
649
650 function getTimestamp() {
651 // Check if the field has been filled by ParserCache::get()
652 if ( !$this->mTimestamp ) {
653 $this->loadLastEdit();
654 }
655 return wfTimestamp(TS_MW, $this->mTimestamp);
656 }
657
658 function getUser() {
659 $this->loadLastEdit();
660 return $this->mUser;
661 }
662
663 function getUserText() {
664 $this->loadLastEdit();
665 return $this->mUserText;
666 }
667
668 function getComment() {
669 $this->loadLastEdit();
670 return $this->mComment;
671 }
672
673 function getMinorEdit() {
674 $this->loadLastEdit();
675 return $this->mMinorEdit;
676 }
677
678 function getRevIdFetched() {
679 $this->loadLastEdit();
680 return $this->mRevIdFetched;
681 }
682
683 function getContributors($limit = 0, $offset = 0) {
684 $fname = 'Article::getContributors';
685
686 # XXX: this is expensive; cache this info somewhere.
687
688 $title = $this->mTitle;
689 $contribs = array();
690 $dbr =& wfGetDB( DB_SLAVE );
691 $revTable = $dbr->tableName( 'revision' );
692 $userTable = $dbr->tableName( 'user' );
693 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
694 $ns = $title->getNamespace();
695 $user = $this->getUser();
696 $pageId = $this->getId();
697
698 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
699 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
700 WHERE rev_page = $pageId
701 AND rev_user != $user
702 GROUP BY rev_user, rev_user_text, user_real_name
703 ORDER BY timestamp DESC";
704
705 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
706 $sql .= ' '. $this->getSelectOptions();
707
708 $res = $dbr->query($sql, $fname);
709
710 while ( $line = $dbr->fetchObject( $res ) ) {
711 $contribs[] = array($line->rev_user, $line->rev_user_text, $line->user_real_name);
712 }
713
714 $dbr->freeResult($res);
715 return $contribs;
716 }
717
718 /**
719 * This is the default action of the script: just view the page of
720 * the given title.
721 */
722 function view() {
723 global $wgUser, $wgOut, $wgRequest, $wgContLang;
724 global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser;
725 global $wgUseTrackbacks;
726 $sk = $wgUser->getSkin();
727
728 $fname = 'Article::view';
729 wfProfileIn( $fname );
730 $parserCache =& ParserCache::singleton();
731 # Get variables from query string
732 $oldid = $this->getOldID();
733
734 # getOldID may want us to redirect somewhere else
735 if ( $this->mRedirectUrl ) {
736 $wgOut->redirect( $this->mRedirectUrl );
737 wfProfileOut( $fname );
738 return;
739 }
740
741 $diff = $wgRequest->getVal( 'diff' );
742 $rcid = $wgRequest->getVal( 'rcid' );
743 $rdfrom = $wgRequest->getVal( 'rdfrom' );
744
745 $wgOut->setArticleFlag( true );
746 $wgOut->setRobotpolicy( 'index,follow' );
747 # If we got diff and oldid in the query, we want to see a
748 # diff page instead of the article.
749
750 if ( !is_null( $diff ) ) {
751 require_once( 'DifferenceEngine.php' );
752 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
753
754 $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid );
755 // DifferenceEngine directly fetched the revision:
756 $this->mRevIdFetched = $de->mNewid;
757 $de->showDiffPage();
758
759 if( $diff == 0 ) {
760 # Run view updates for current revision only
761 $this->viewUpdates();
762 }
763 wfProfileOut( $fname );
764 return;
765 }
766
767 if ( empty( $oldid ) && $this->checkTouched() ) {
768 $wgOut->setETag($parserCache->getETag($this, $wgUser));
769
770 if( $wgOut->checkLastModified( $this->mTouched ) ){
771 wfProfileOut( $fname );
772 return;
773 } else if ( $this->tryFileCache() ) {
774 # tell wgOut that output is taken care of
775 $wgOut->disable();
776 $this->viewUpdates();
777 wfProfileOut( $fname );
778 return;
779 }
780 }
781 # Should the parser cache be used?
782 $pcache = $wgEnableParserCache &&
783 intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
784 $this->exists() &&
785 empty( $oldid );
786 wfDebug( 'Article::view using parser cache: ' . ($pcache ? 'yes' : 'no' ) . "\n" );
787 if ( $wgUser->getOption( 'stubthreshold' ) ) {
788 wfIncrStats( 'pcache_miss_stub' );
789 }
790
791 $wasRedirected = false;
792 if ( isset( $this->mRedirectedFrom ) ) {
793 // This is an internally redirected page view.
794 // We'll need a backlink to the source page for navigation.
795 if ( wfRunHooks( 'ArticleViewRedirect', array( &$this ) ) ) {
796 $sk = $wgUser->getSkin();
797 $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
798 $s = wfMsg( 'redirectedfrom', $redir );
799 $wgOut->setSubtitle( $s );
800 $wasRedirected = true;
801 }
802 } elseif ( !empty( $rdfrom ) ) {
803 // This is an externally redirected view, from some other wiki.
804 // If it was reported from a trusted site, supply a backlink.
805 global $wgRedirectSources;
806 if( $wgRedirectSources && preg_match( $wgRedirectSources, $rdfrom ) ) {
807 $sk = $wgUser->getSkin();
808 $redir = $sk->makeExternalLink( $rdfrom, $rdfrom );
809 $s = wfMsg( 'redirectedfrom', $redir );
810 $wgOut->setSubtitle( $s );
811 $wasRedirected = true;
812 }
813 }
814
815 $outputDone = false;
816 if ( $pcache ) {
817 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
818 $outputDone = true;
819 }
820 }
821 if ( !$outputDone ) {
822 $text = $this->getContent();
823 if ( $text === false ) {
824 # Failed to load, replace text with error message
825 $t = $this->mTitle->getPrefixedText();
826 if( $oldid ) {
827 $t .= ',oldid='.$oldid;
828 $text = wfMsg( 'missingarticle', $t );
829 } else {
830 $text = wfMsg( 'noarticletext', $t );
831 }
832 }
833
834 # Another whitelist check in case oldid is altering the title
835 if ( !$this->mTitle->userCanRead() ) {
836 $wgOut->loginToUse();
837 $wgOut->output();
838 exit;
839 }
840
841 # We're looking at an old revision
842
843 if ( !empty( $oldid ) ) {
844 $wgOut->setRobotpolicy( 'noindex,nofollow' );
845 if( is_null( $this->mRevision ) ) {
846 // FIXME: This would be a nice place to load the 'no such page' text.
847 } else {
848 $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
849 if( $this->mRevision->isDeleted( MW_REV_DELETED_TEXT ) ) {
850 if( !$this->mRevision->userCan( MW_REV_DELETED_TEXT ) ) {
851 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
852 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
853 return;
854 } else {
855 $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
856 // and we are allowed to see...
857 }
858 }
859 }
860
861 }
862 }
863 if( !$outputDone ) {
864 /**
865 * @fixme: this hook doesn't work most of the time, as it doesn't
866 * trigger when the parser cache is used.
867 */
868 wfRunHooks( 'ArticleViewHeader', array( &$this ) ) ;
869 $wgOut->setRevisionId( $this->getRevIdFetched() );
870 # wrap user css and user js in pre and don't parse
871 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
872 if (
873 $this->mTitle->getNamespace() == NS_USER &&
874 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle->getDBkey())
875 ) {
876 $wgOut->addWikiText( wfMsg('clearyourcache'));
877 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
878 } else if ( $rt = Title::newFromRedirect( $text ) ) {
879 # Display redirect
880 $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
881 $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png';
882 if( !$wasRedirected ) {
883 $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
884 }
885 $targetUrl = $rt->escapeLocalURL();
886 $titleText = htmlspecialchars( $rt->getPrefixedText() );
887 $link = $sk->makeLinkObj( $rt );
888
889 $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
890 '<span class="redirectText">'.$link.'</span>' );
891
892 $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
893 $wgOut->addParserOutputNoText( $parseout );
894 } else if ( $pcache ) {
895 # Display content and save to parser cache
896 $wgOut->addPrimaryWikiText( $text, $this );
897 } else {
898 # Display content, don't attempt to save to parser cache
899
900 # Don't show section-edit links on old revisions... this way lies madness.
901 if( !$this->isCurrent() ) {
902 $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
903 }
904 # Display content and don't save to parser cache
905 $wgOut->addPrimaryWikiText( $text, $this, false );
906
907 if( !$this->isCurrent() ) {
908 $wgOut->mParserOptions->setEditSection( $oldEditSectionSetting );
909 }
910 }
911 }
912 /* title may have been set from the cache */
913 $t = $wgOut->getPageTitle();
914 if( empty( $t ) ) {
915 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
916 }
917
918 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
919 if( $this->mTitle->getNamespace() == NS_USER_TALK &&
920 User::isIP( $this->mTitle->getText() ) ) {
921 $wgOut->addWikiText( wfMsg('anontalkpagetext') );
922 }
923
924 # If we have been passed an &rcid= parameter, we want to give the user a
925 # chance to mark this new article as patrolled.
926 if ( $wgUseRCPatrol && !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
927 $wgOut->addHTML(
928 "<div class='patrollink'>" .
929 wfMsg ( 'markaspatrolledlink',
930 $sk->makeKnownLinkObj( $this->mTitle, wfMsg('markaspatrolledtext'), "action=markpatrolled&rcid=$rcid" )
931 ) .
932 '</div>'
933 );
934 }
935
936 # Trackbacks
937 if ($wgUseTrackbacks)
938 $this->addTrackbacks();
939
940 $this->viewUpdates();
941 wfProfileOut( $fname );
942 }
943
944 function addTrackbacks() {
945 global $wgOut, $wgUser;
946
947 $dbr =& wfGetDB(DB_SLAVE);
948 $tbs = $dbr->select(
949 /* FROM */ 'trackbacks',
950 /* SELECT */ array('tb_id', 'tb_title', 'tb_url', 'tb_ex', 'tb_name'),
951 /* WHERE */ array('tb_page' => $this->getID())
952 );
953
954 if (!$dbr->numrows($tbs))
955 return;
956
957 $tbtext = "";
958 while ($o = $dbr->fetchObject($tbs)) {
959 $rmvtxt = "";
960 if ($wgUser->isSysop()) {
961 $delurl = $this->mTitle->getFullURL("action=deletetrackback&tbid="
962 . $o->tb_id . "&token=" . $wgUser->editToken());
963 $rmvtxt = wfMsg('trackbackremove', $delurl);
964 }
965 $tbtext .= wfMsg(strlen($o->tb_ex) ? 'trackbackexcerpt' : 'trackback',
966 $o->tb_title,
967 $o->tb_url,
968 $o->tb_ex,
969 $o->tb_name,
970 $rmvtxt);
971 }
972 $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
973 }
974
975 function deletetrackback() {
976 global $wgUser, $wgRequest, $wgOut, $wgTitle;
977
978 if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
979 $wgOut->addWikitext(wfMsg('sessionfailure'));
980 return;
981 }
982
983 if ((!$wgUser->isAllowed('delete'))) {
984 $wgOut->sysopRequired();
985 return;
986 }
987
988 if (wfReadOnly()) {
989 $wgOut->readOnlyPage();
990 return;
991 }
992
993 $db =& wfGetDB(DB_MASTER);
994 $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
995 $wgTitle->invalidateCache();
996 $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
997 }
998
999 function render() {
1000 global $wgOut;
1001
1002 $wgOut->setArticleBodyOnly(true);
1003 $this->view();
1004 }
1005
1006 /**
1007 * Handle action=purge
1008 */
1009 function purge() {
1010 global $wgUser, $wgRequest, $wgOut;
1011
1012 if ( $wgUser->isLoggedIn() || $wgRequest->wasPosted() ) {
1013 if( wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
1014 $this->doPurge();
1015 }
1016 } else {
1017 $msg = $wgOut->parse( wfMsg( 'confirm_purge' ) );
1018 $action = $this->mTitle->escapeLocalURL( 'action=purge' );
1019 $button = htmlspecialchars( wfMsg( 'confirm_purge_button' ) );
1020 $msg = str_replace( '$1',
1021 "<form method=\"post\" action=\"$action\">\n" .
1022 "<input type=\"submit\" name=\"submit\" value=\"$button\" />\n" .
1023 "</form>\n", $msg );
1024
1025 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
1026 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1027 $wgOut->addHTML( $msg );
1028 }
1029 }
1030
1031 /**
1032 * Perform the actions of a page purging
1033 */
1034 function doPurge() {
1035 global $wgUseSquid;
1036 // Invalidate the cache
1037 $this->mTitle->invalidateCache();
1038
1039 if ( $wgUseSquid ) {
1040 // Commit the transaction before the purge is sent
1041 $dbw = wfGetDB( DB_MASTER );
1042 $dbw->immediateCommit();
1043
1044 // Send purge
1045 $update = SquidUpdate::newSimplePurge( $this->mTitle );
1046 $update->doUpdate();
1047 }
1048 $this->view();
1049 }
1050
1051 /**
1052 * Insert a new empty page record for this article.
1053 * This *must* be followed up by creating a revision
1054 * and running $this->updateToLatest( $rev_id );
1055 * or else the record will be left in a funky state.
1056 * Best if all done inside a transaction.
1057 *
1058 * @param Database $dbw
1059 * @param string $restrictions
1060 * @return int The newly created page_id key
1061 * @access private
1062 */
1063 function insertOn( &$dbw, $restrictions = '' ) {
1064 $fname = 'Article::insertOn';
1065 wfProfileIn( $fname );
1066
1067 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
1068 $dbw->insert( 'page', array(
1069 'page_id' => $page_id,
1070 'page_namespace' => $this->mTitle->getNamespace(),
1071 'page_title' => $this->mTitle->getDBkey(),
1072 'page_counter' => 0,
1073 'page_restrictions' => $restrictions,
1074 'page_is_redirect' => 0, # Will set this shortly...
1075 'page_is_new' => 1,
1076 'page_random' => wfRandom(),
1077 'page_touched' => $dbw->timestamp(),
1078 'page_latest' => 0, # Fill this in shortly...
1079 'page_len' => 0, # Fill this in shortly...
1080 ), $fname );
1081 $newid = $dbw->insertId();
1082
1083 $this->mTitle->resetArticleId( $newid );
1084
1085 wfProfileOut( $fname );
1086 return $newid;
1087 }
1088
1089 /**
1090 * Update the page record to point to a newly saved revision.
1091 *
1092 * @param Database $dbw
1093 * @param Revision $revision For ID number, and text used to set
1094 length and redirect status fields
1095 * @param int $lastRevision If given, will not overwrite the page field
1096 * when different from the currently set value.
1097 * Giving 0 indicates the new page flag should
1098 * be set on.
1099 * @return bool true on success, false on failure
1100 * @access private
1101 */
1102 function updateRevisionOn( &$dbw, $revision, $lastRevision = null ) {
1103 $fname = 'Article::updateToRevision';
1104 wfProfileIn( $fname );
1105
1106 $conditions = array( 'page_id' => $this->getId() );
1107 if( !is_null( $lastRevision ) ) {
1108 # An extra check against threads stepping on each other
1109 $conditions['page_latest'] = $lastRevision;
1110 }
1111
1112 $text = $revision->getText();
1113 $dbw->update( 'page',
1114 array( /* SET */
1115 'page_latest' => $revision->getId(),
1116 'page_touched' => $dbw->timestamp(),
1117 'page_is_new' => ($lastRevision === 0) ? 1 : 0,
1118 'page_is_redirect' => Article::isRedirect( $text ) ? 1 : 0,
1119 'page_len' => strlen( $text ),
1120 ),
1121 $conditions,
1122 $fname );
1123
1124 wfProfileOut( $fname );
1125 return ( $dbw->affectedRows() != 0 );
1126 }
1127
1128 /**
1129 * If the given revision is newer than the currently set page_latest,
1130 * update the page record. Otherwise, do nothing.
1131 *
1132 * @param Database $dbw
1133 * @param Revision $revision
1134 */
1135 function updateIfNewerOn( &$dbw, $revision ) {
1136 $fname = 'Article::updateIfNewerOn';
1137 wfProfileIn( $fname );
1138
1139 $row = $dbw->selectRow(
1140 array( 'revision', 'page' ),
1141 array( 'rev_id', 'rev_timestamp' ),
1142 array(
1143 'page_id' => $this->getId(),
1144 'page_latest=rev_id' ),
1145 $fname );
1146 if( $row ) {
1147 if( wfTimestamp(TS_MW, $row->rev_timestamp) >= $revision->getTimestamp() ) {
1148 wfProfileOut( $fname );
1149 return false;
1150 }
1151 $prev = $row->rev_id;
1152 } else {
1153 # No or missing previous revision; mark the page as new
1154 $prev = 0;
1155 }
1156
1157 $ret = $this->updateRevisionOn( $dbw, $revision, $prev );
1158 wfProfileOut( $fname );
1159 return $ret;
1160 }
1161
1162 /**
1163 * Insert a new article into the database
1164 * @access private
1165 */
1166 function insertNewArticle( $text, $summary, $isminor, $watchthis, $suppressRC=false, $comment=false ) {
1167 global $wgUser;
1168
1169 $fname = 'Article::insertNewArticle';
1170 wfProfileIn( $fname );
1171
1172 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1173 &$summary, &$isminor, &$watchthis, NULL ) ) ) {
1174 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1175 wfProfileOut( $fname );
1176 return false;
1177 }
1178
1179 $ns = $this->mTitle->getNamespace();
1180 $ttl = $this->mTitle->getDBkey();
1181
1182 # If this is a comment, add the summary as headline
1183 if($comment && $summary!="") {
1184 $text="== {$summary} ==\n\n".$text;
1185 }
1186 $text = $this->preSaveTransform( $text );
1187
1188
1189 # Set statistics members
1190 # We work out if it's countable after PST to avoid counter drift
1191 # when articles are created with {{subst:}}
1192 $this->mGoodAdjustment = (int)$this->isCountable( $text );
1193 $this->mTotalAdjustment = 1;
1194
1195 /* Silently ignore minoredit if not allowed */
1196 $isminor = $isminor && $wgUser->isAllowed('minoredit');
1197 $now = wfTimestampNow();
1198
1199 $dbw =& wfGetDB( DB_MASTER );
1200
1201 # Add the page record; stake our claim on this title!
1202 $newid = $this->insertOn( $dbw );
1203
1204 # Save the revision text...
1205 $revision = new Revision( array(
1206 'page' => $newid,
1207 'comment' => $summary,
1208 'minor_edit' => $isminor,
1209 'text' => $text
1210 ) );
1211 $revisionId = $revision->insertOn( $dbw );
1212
1213 $this->mTitle->resetArticleID( $newid );
1214
1215 # Update the page record with revision data
1216 $this->updateRevisionOn( $dbw, $revision, 0 );
1217
1218 Article::onArticleCreate( $this->mTitle );
1219 if(!$suppressRC) {
1220 require_once( 'RecentChange.php' );
1221 $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, 'default',
1222 '', strlen( $text ), $revisionId );
1223 # Mark as patrolled if the user can and has the option set
1224 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1225 RecentChange::markPatrolled( $rcid );
1226 }
1227 }
1228
1229 if ($watchthis) {
1230 if(!$this->mTitle->userIsWatching()) $this->doWatch();
1231 } else {
1232 if ( $this->mTitle->userIsWatching() ) {
1233 $this->doUnwatch();
1234 }
1235 }
1236
1237 # The talk page isn't in the regular link tables, so we need to update manually:
1238 $talkns = $ns ^ 1; # talk -> normal; normal -> talk
1239 $dbw->update( 'page',
1240 array( 'page_touched' => $dbw->timestamp($now) ),
1241 array( 'page_namespace' => $talkns,
1242 'page_title' => $ttl ),
1243 $fname );
1244
1245 # standard deferred updates
1246 $this->editUpdates( $text, $summary, $isminor, $now, $revisionId );
1247
1248 $oldid = 0; # new article
1249 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
1250
1251 wfRunHooks( 'ArticleInsertComplete', array( &$this, &$wgUser, $text,
1252 $summary, $isminor,
1253 $watchthis, NULL ) );
1254 wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
1255 $summary, $isminor,
1256 $watchthis, NULL ) );
1257 wfProfileOut( $fname );
1258 }
1259
1260 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
1261 $this->replaceSection( $section, $text, $summary, $edittime );
1262 }
1263
1264 /**
1265 * @return string Complete article text, or null if error
1266 */
1267 function replaceSection($section, $text, $summary = '', $edittime = NULL) {
1268 $fname = 'Article::replaceSection';
1269 wfProfileIn( $fname );
1270
1271 if ($section != '') {
1272 if( is_null( $edittime ) ) {
1273 $rev = Revision::newFromTitle( $this->mTitle );
1274 } else {
1275 $dbw =& wfGetDB( DB_MASTER );
1276 $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
1277 }
1278 if( is_null( $rev ) ) {
1279 wfDebug( "Article::replaceSection asked for bogus section (page: " .
1280 $this->getId() . "; section: $section; edittime: $edittime)\n" );
1281 return null;
1282 }
1283 $oldtext = $rev->getText();
1284
1285 if($section=='new') {
1286 if($summary) $subject="== {$summary} ==\n\n";
1287 $text=$oldtext."\n\n".$subject.$text;
1288 } else {
1289
1290 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
1291 # comments to be stripped as well)
1292 $striparray=array();
1293 $parser=new Parser();
1294 $parser->mOutputType=OT_WIKI;
1295 $parser->mOptions = new ParserOptions();
1296 $oldtext=$parser->strip($oldtext, $striparray, true);
1297
1298 # now that we can be sure that no pseudo-sections are in the source,
1299 # split it up
1300 # Unfortunately we can't simply do a preg_replace because that might
1301 # replace the wrong section, so we have to use the section counter instead
1302 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?>.*?<\/h[1-6].*?>)(?!\S)/mi',
1303 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE);
1304 $secs[$section*2]=$text."\n\n"; // replace with edited
1305
1306 # section 0 is top (intro) section
1307 if($section!=0) {
1308
1309 # headline of old section - we need to go through this section
1310 # to determine if there are any subsections that now need to
1311 # be erased, as the mother section has been replaced with
1312 # the text of all subsections.
1313 $headline=$secs[$section*2-1];
1314 preg_match( '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$headline,$matches);
1315 $hlevel=$matches[1];
1316
1317 # determine headline level for wikimarkup headings
1318 if(strpos($hlevel,'=')!==false) {
1319 $hlevel=strlen($hlevel);
1320 }
1321
1322 $secs[$section*2-1]=''; // erase old headline
1323 $count=$section+1;
1324 $break=false;
1325 while(!empty($secs[$count*2-1]) && !$break) {
1326
1327 $subheadline=$secs[$count*2-1];
1328 preg_match(
1329 '/^(=+).+?=+|^<h([1-6]).*?>.*?<\/h[1-6].*?>(?!\S)/mi',$subheadline,$matches);
1330 $subhlevel=$matches[1];
1331 if(strpos($subhlevel,'=')!==false) {
1332 $subhlevel=strlen($subhlevel);
1333 }
1334 if($subhlevel > $hlevel) {
1335 // erase old subsections
1336 $secs[$count*2-1]='';
1337 $secs[$count*2]='';
1338 }
1339 if($subhlevel <= $hlevel) {
1340 $break=true;
1341 }
1342 $count++;
1343
1344 }
1345
1346 }
1347 $text=join('',$secs);
1348 # reinsert the stuff that we stripped out earlier
1349 $text=$parser->unstrip($text,$striparray);
1350 $text=$parser->unstripNoWiki($text,$striparray);
1351 }
1352
1353 }
1354 wfProfileOut( $fname );
1355 return $text;
1356 }
1357
1358 /**
1359 * Change an existing article. Puts the previous version back into the old table, updates RC
1360 * and all necessary caches, mostly via the deferred update array.
1361 *
1362 * It is possible to call this function from a command-line script, but note that you should
1363 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
1364 */
1365 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
1366 global $wgUser, $wgDBtransactions, $wgUseSquid;
1367 global $wgPostCommitUpdateList, $wgUseFileCache;
1368
1369 $fname = 'Article::updateArticle';
1370 wfProfileIn( $fname );
1371 $good = true;
1372
1373 if( !wfRunHooks( 'ArticleSave', array( &$this, &$wgUser, &$text,
1374 &$summary, &$minor,
1375 &$watchthis, &$sectionanchor ) ) ) {
1376 wfDebug( "$fname: ArticleSave hook aborted save!\n" );
1377 wfProfileOut( $fname );
1378 return false;
1379 }
1380
1381 $isminor = $minor && $wgUser->isAllowed('minoredit');
1382 $redir = (int)$this->isRedirect( $text );
1383
1384 $text = $this->preSaveTransform( $text );
1385 $dbw =& wfGetDB( DB_MASTER );
1386 $now = wfTimestampNow();
1387
1388 # Update article, but only if changed.
1389
1390 # It's important that we either rollback or complete, otherwise an attacker could
1391 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1392 # could conceivably have the same effect, especially if cur is locked for long periods.
1393 if( !$wgDBtransactions ) {
1394 $userAbort = ignore_user_abort( true );
1395 }
1396
1397 $oldtext = $this->getContent();
1398 $oldsize = strlen( $oldtext );
1399 $newsize = strlen( $text );
1400 $lastRevision = 0;
1401 $revisionId = 0;
1402
1403 if ( 0 != strcmp( $text, $oldtext ) ) {
1404 $this->mGoodAdjustment = (int)$this->isCountable( $text )
1405 - (int)$this->isCountable( $oldtext );
1406 $this->mTotalAdjustment = 0;
1407 $now = wfTimestampNow();
1408
1409 $lastRevision = $dbw->selectField(
1410 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1411
1412 $revision = new Revision( array(
1413 'page' => $this->getId(),
1414 'comment' => $summary,
1415 'minor_edit' => $isminor,
1416 'text' => $text
1417 ) );
1418
1419 $dbw->immediateCommit();
1420 $dbw->begin();
1421 $revisionId = $revision->insertOn( $dbw );
1422
1423 # Update page
1424 $ok = $this->updateRevisionOn( $dbw, $revision, $lastRevision );
1425
1426 if( !$ok ) {
1427 /* Belated edit conflict! Run away!! */
1428 $good = false;
1429 $dbw->rollback();
1430 } else {
1431 # Update recentchanges and purge cache and whatnot
1432 require_once( 'RecentChange.php' );
1433 $bot = (int)($wgUser->isBot() || $forceBot);
1434 $rcid = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $wgUser, $summary,
1435 $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
1436 $revisionId );
1437
1438 # Mark as patrolled if the user can do so and has it set in their options
1439 if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
1440 RecentChange::markPatrolled( $rcid );
1441 }
1442
1443 $dbw->commit();
1444
1445 // Update caches outside the main transaction
1446 Article::onArticleEdit( $this->mTitle );
1447 }
1448 } else {
1449 // Keep the same revision ID, but do some updates on it
1450 $revisionId = $this->getRevIdFetched();
1451 }
1452
1453 if( !$wgDBtransactions ) {
1454 ignore_user_abort( $userAbort );
1455 }
1456
1457 if ( $good ) {
1458 if ($watchthis) {
1459 if (!$this->mTitle->userIsWatching()) {
1460 $dbw->immediateCommit();
1461 $dbw->begin();
1462 $this->doWatch();
1463 $dbw->commit();
1464 }
1465 } else {
1466 if ( $this->mTitle->userIsWatching() ) {
1467 $dbw->immediateCommit();
1468 $dbw->begin();
1469 $this->doUnwatch();
1470 $dbw->commit();
1471 }
1472 }
1473 # standard deferred updates
1474 $this->editUpdates( $text, $summary, $minor, $now, $revisionId );
1475
1476
1477 $urls = array();
1478 # Invalidate caches of all articles using this article as a template
1479
1480 # Template namespace
1481 # Purge all articles linking here
1482 $titles = $this->mTitle->getTemplateLinksTo();
1483 Title::touchArray( $titles );
1484 if ( $wgUseSquid ) {
1485 foreach ( $titles as $title ) {
1486 $urls[] = $title->getInternalURL();
1487 }
1488 }
1489
1490 # Squid updates
1491 if ( $wgUseSquid ) {
1492 $urls = array_merge( $urls, $this->mTitle->getSquidURLs() );
1493 $u = new SquidUpdate( $urls );
1494 array_push( $wgPostCommitUpdateList, $u );
1495 }
1496
1497 # File cache
1498 if ( $wgUseFileCache ) {
1499 $cm = new CacheManager($this->mTitle);
1500 @unlink($cm->fileCacheName());
1501 }
1502
1503 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
1504 }
1505 wfRunHooks( 'ArticleSaveComplete',
1506 array( &$this, &$wgUser, $text,
1507 $summary, $minor,
1508 $watchthis, $sectionanchor ) );
1509 wfProfileOut( $fname );
1510 return $good;
1511 }
1512
1513 /**
1514 * After we've either updated or inserted the article, update
1515 * the link tables and redirect to the new page.
1516 */
1517 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1518 global $wgOut;
1519
1520 $fname = 'Article::showArticle';
1521 wfProfileIn( $fname );
1522
1523 # Output the redirect
1524 if( $this->isRedirect( $text ) )
1525 $r = 'redirect=no';
1526 else
1527 $r = '';
1528 $wgOut->redirect( $this->mTitle->getFullURL( $r ).$sectionanchor );
1529
1530 wfProfileOut( $fname );
1531 }
1532
1533 /**
1534 * Mark this particular edit as patrolled
1535 */
1536 function markpatrolled() {
1537 global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
1538 $wgOut->setRobotpolicy( 'noindex,follow' );
1539
1540 # Check RC patrol config. option
1541 if( !$wgUseRCPatrol ) {
1542 $wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1543 return;
1544 }
1545
1546 # Check permissions
1547 if( !$wgUser->isAllowed( 'patrol' ) ) {
1548 $wgOut->permissionRequired( 'patrol' );
1549 return;
1550 }
1551
1552 $rcid = $wgRequest->getVal( 'rcid' );
1553 if ( !is_null ( $rcid ) ) {
1554 if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
1555 require_once( 'RecentChange.php' );
1556 RecentChange::markPatrolled( $rcid );
1557 wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
1558 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1559 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1560 }
1561 $rcTitle = Title::makeTitle( NS_SPECIAL, 'Recentchanges' );
1562 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1563 }
1564 else {
1565 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1566 }
1567 }
1568
1569 /**
1570 * User-interface handler for the "watch" action
1571 */
1572
1573 function watch() {
1574
1575 global $wgUser, $wgOut;
1576
1577 if ( $wgUser->isAnon() ) {
1578 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1579 return;
1580 }
1581 if ( wfReadOnly() ) {
1582 $wgOut->readOnlyPage();
1583 return;
1584 }
1585
1586 if( $this->doWatch() ) {
1587 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1588 $wgOut->setRobotpolicy( 'noindex,follow' );
1589
1590 $link = $this->mTitle->getPrefixedText();
1591 $text = wfMsg( 'addedwatchtext', $link );
1592 $wgOut->addWikiText( $text );
1593 }
1594
1595 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1596 }
1597
1598 /**
1599 * Add this page to $wgUser's watchlist
1600 * @return bool true on successful watch operation
1601 */
1602 function doWatch() {
1603 global $wgUser;
1604 if( $wgUser->isAnon() ) {
1605 return false;
1606 }
1607
1608 if (wfRunHooks('WatchArticle', array(&$wgUser, &$this))) {
1609 $wgUser->addWatch( $this->mTitle );
1610 $wgUser->saveSettings();
1611
1612 return wfRunHooks('WatchArticleComplete', array(&$wgUser, &$this));
1613 }
1614
1615 return false;
1616 }
1617
1618 /**
1619 * User interface handler for the "unwatch" action.
1620 */
1621 function unwatch() {
1622
1623 global $wgUser, $wgOut;
1624
1625 if ( $wgUser->isAnon() ) {
1626 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1627 return;
1628 }
1629 if ( wfReadOnly() ) {
1630 $wgOut->readOnlyPage();
1631 return;
1632 }
1633
1634 if( $this->doUnwatch() ) {
1635 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1636 $wgOut->setRobotpolicy( 'noindex,follow' );
1637
1638 $link = $this->mTitle->getPrefixedText();
1639 $text = wfMsg( 'removedwatchtext', $link );
1640 $wgOut->addWikiText( $text );
1641 }
1642
1643 $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
1644 }
1645
1646 /**
1647 * Stop watching a page
1648 * @return bool true on successful unwatch
1649 */
1650 function doUnwatch() {
1651 global $wgUser;
1652 if( $wgUser->isAnon() ) {
1653 return false;
1654 }
1655
1656 if (wfRunHooks('UnwatchArticle', array(&$wgUser, &$this))) {
1657 $wgUser->removeWatch( $this->mTitle );
1658 $wgUser->saveSettings();
1659
1660 return wfRunHooks('UnwatchArticleComplete', array(&$wgUser, &$this));
1661 }
1662
1663 return false;
1664 }
1665
1666 /**
1667 * action=protect handler
1668 */
1669 function protect() {
1670 require_once 'ProtectionForm.php';
1671 $form = new ProtectionForm( $this );
1672 $form->show();
1673 }
1674
1675 /**
1676 * action=unprotect handler (alias)
1677 */
1678 function unprotect() {
1679 $this->protect();
1680 }
1681
1682 /**
1683 * Update the article's restriction field, and leave a log entry.
1684 *
1685 * @param array $limit set of restriction keys
1686 * @param string $reason
1687 * @return bool true on success
1688 */
1689 function updateRestrictions( $limit = array(), $reason = '' ) {
1690 global $wgUser, $wgRestrictionTypes, $wgContLang;
1691
1692 $id = $this->mTitle->getArticleID();
1693 if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
1694 return false;
1695 }
1696
1697 # FIXME: Same limitations as described in ProtectionForm.php (line 37);
1698 # we expect a single selection, but the schema allows otherwise.
1699 $current = array();
1700 foreach( $wgRestrictionTypes as $action )
1701 $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
1702
1703 $current = Article::flattenRestrictions( $current );
1704 $updated = Article::flattenRestrictions( $limit );
1705
1706 $changed = ( $current != $updated );
1707 $protect = ( $updated != '' );
1708
1709 # If nothing's changed, do nothing
1710 if( $changed ) {
1711 if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) {
1712
1713 $dbw =& wfGetDB( DB_MASTER );
1714
1715 # Prepare a null revision to be added to the history
1716 $comment = $wgContLang->ucfirst( wfMsgForContent( $protect ? 'protectedarticle' : 'unprotectedarticle', $this->mTitle->getPrefixedText() ) );
1717 if( $reason )
1718 $comment .= ": $reason";
1719 if( $protect )
1720 $comment .= " [$updated]";
1721 $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
1722 $nullRevId = $nullRevision->insertOn( $dbw );
1723
1724 # Update page record
1725 $dbw->update( 'page',
1726 array( /* SET */
1727 'page_touched' => $dbw->timestamp(),
1728 'page_restrictions' => $updated,
1729 'page_latest' => $nullRevId
1730 ), array( /* WHERE */
1731 'page_id' => $id
1732 ), 'Article::protect'
1733 );
1734 wfRunHooks( 'ArticleProtectComplete', array( &$this, &$wgUser, $limit, $reason ) );
1735
1736 # Update the protection log
1737 $log = new LogPage( 'protect' );
1738 if( $protect ) {
1739 $log->addEntry( 'protect', $this->mTitle, trim( $reason . " [$updated]" ) );
1740 } else {
1741 $log->addEntry( 'unprotect', $this->mTitle, $reason );
1742 }
1743
1744 } # End hook
1745 } # End "changed" check
1746
1747 return true;
1748 }
1749
1750 /**
1751 * Take an array of page restrictions and flatten it to a string
1752 * suitable for insertion into the page_restrictions field.
1753 * @param array $limit
1754 * @return string
1755 * @access private
1756 */
1757 function flattenRestrictions( $limit ) {
1758 if( !is_array( $limit ) ) {
1759 wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
1760 }
1761 $bits = array();
1762 ksort( $limit );
1763 foreach( $limit as $action => $restrictions ) {
1764 if( $restrictions != '' ) {
1765 $bits[] = "$action=$restrictions";
1766 }
1767 }
1768 return implode( ':', $bits );
1769 }
1770
1771 /*
1772 * UI entry point for page deletion
1773 */
1774 function delete() {
1775 global $wgUser, $wgOut, $wgRequest;
1776 $fname = 'Article::delete';
1777 $confirm = $wgRequest->wasPosted() &&
1778 $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
1779 $reason = $wgRequest->getText( 'wpReason' );
1780
1781 # This code desperately needs to be totally rewritten
1782
1783 # Check permissions
1784 if( $wgUser->isAllowed( 'delete' ) ) {
1785 if( $wgUser->isBlocked() ) {
1786 $wgOut->blockedPage();
1787 return;
1788 }
1789 } else {
1790 $wgOut->permissionRequired( 'delete' );
1791 return;
1792 }
1793
1794 if( wfReadOnly() ) {
1795 $wgOut->readOnlyPage();
1796 return;
1797 }
1798
1799 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1800
1801 # Better double-check that it hasn't been deleted yet!
1802 $dbw =& wfGetDB( DB_MASTER );
1803 $conds = $this->mTitle->pageCond();
1804 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
1805 if ( $latest === false ) {
1806 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1807 return;
1808 }
1809
1810 if( $confirm ) {
1811 $this->doDelete( $reason );
1812 return;
1813 }
1814
1815 # determine whether this page has earlier revisions
1816 # and insert a warning if it does
1817 $maxRevisions = 20;
1818 $authors = $this->getLastNAuthors( $maxRevisions, $latest );
1819
1820 if( count( $authors ) > 1 && !$confirm ) {
1821 $skin=$wgUser->getSkin();
1822 $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
1823 }
1824
1825 # If a single user is responsible for all revisions, find out who they are
1826 if ( count( $authors ) == $maxRevisions ) {
1827 // Query bailed out, too many revisions to find out if they're all the same
1828 $authorOfAll = false;
1829 } else {
1830 $authorOfAll = reset( $authors );
1831 foreach ( $authors as $author ) {
1832 if ( $authorOfAll != $author ) {
1833 $authorOfAll = false;
1834 break;
1835 }
1836 }
1837 }
1838 # Fetch article text
1839 $rev = Revision::newFromTitle( $this->mTitle );
1840
1841 if( !is_null( $rev ) ) {
1842 # if this is a mini-text, we can paste part of it into the deletion reason
1843 $text = $rev->getText();
1844
1845 #if this is empty, an earlier revision may contain "useful" text
1846 $blanked = false;
1847 if( $text == '' ) {
1848 $prev = $rev->getPrevious();
1849 if( $prev ) {
1850 $text = $prev->getText();
1851 $blanked = true;
1852 }
1853 }
1854
1855 $length = strlen( $text );
1856
1857 # this should not happen, since it is not possible to store an empty, new
1858 # page. Let's insert a standard text in case it does, though
1859 if( $length == 0 && $reason === '' ) {
1860 $reason = wfMsgForContent( 'exblank' );
1861 }
1862
1863 if( $length < 500 && $reason === '' ) {
1864 # comment field=255, let's grep the first 150 to have some user
1865 # space left
1866 global $wgContLang;
1867 $text = $wgContLang->truncate( $text, 150, '...' );
1868
1869 # let's strip out newlines
1870 $text = preg_replace( "/[\n\r]/", '', $text );
1871
1872 if( !$blanked ) {
1873 if( $authorOfAll === false ) {
1874 $reason = wfMsgForContent( 'excontent', $text );
1875 } else {
1876 $reason = wfMsgForContent( 'excontentauthor', $text, $authorOfAll );
1877 }
1878 } else {
1879 $reason = wfMsgForContent( 'exbeforeblank', $text );
1880 }
1881 }
1882 }
1883
1884 return $this->confirmDelete( '', $reason );
1885 }
1886
1887 /**
1888 * Get the last N authors
1889 * @param int $num Number of revisions to get
1890 * @param string $revLatest The latest rev_id, selected from the master (optional)
1891 * @return array Array of authors, duplicates not removed
1892 */
1893 function getLastNAuthors( $num, $revLatest = 0 ) {
1894 $fname = 'Article::getLastNAuthors';
1895 wfProfileIn( $fname );
1896
1897 // First try the slave
1898 // If that doesn't have the latest revision, try the master
1899 $continue = 2;
1900 $db =& wfGetDB( DB_SLAVE );
1901 do {
1902 $res = $db->select( array( 'page', 'revision' ),
1903 array( 'rev_id', 'rev_user_text' ),
1904 array(
1905 'page_namespace' => $this->mTitle->getNamespace(),
1906 'page_title' => $this->mTitle->getDBkey(),
1907 'rev_page = page_id'
1908 ), $fname, $this->getSelectOptions( array(
1909 'ORDER BY' => 'rev_timestamp DESC',
1910 'LIMIT' => $num
1911 ) )
1912 );
1913 if ( !$res ) {
1914 wfProfileOut( $fname );
1915 return array();
1916 }
1917 $row = $db->fetchObject( $res );
1918 if ( $continue == 2 && $revLatest && $row->rev_id != $revLatest ) {
1919 $db =& wfGetDB( DB_MASTER );
1920 $continue--;
1921 } else {
1922 $continue = 0;
1923 }
1924 } while ( $continue );
1925
1926 $authors = array( $row->rev_user_text );
1927 while ( $row = $db->fetchObject( $res ) ) {
1928 $authors[] = $row->rev_user_text;
1929 }
1930 wfProfileOut( $fname );
1931 return $authors;
1932 }
1933
1934 /**
1935 * Output deletion confirmation dialog
1936 */
1937 function confirmDelete( $par, $reason ) {
1938 global $wgOut, $wgUser;
1939
1940 wfDebug( "Article::confirmDelete\n" );
1941
1942 $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
1943 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1944 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1945 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1946
1947 $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
1948
1949 $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
1950 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1951 $token = htmlspecialchars( $wgUser->editToken() );
1952
1953 $wgOut->addHTML( "
1954 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1955 <table border='0'>
1956 <tr>
1957 <td align='right'>
1958 <label for='wpReason'>{$delcom}:</label>
1959 </td>
1960 <td align='left'>
1961 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1962 </td>
1963 </tr>
1964 <tr>
1965 <td>&nbsp;</td>
1966 <td>
1967 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1968 </td>
1969 </tr>
1970 </table>
1971 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
1972 </form>\n" );
1973
1974 $wgOut->returnToMain( false );
1975 }
1976
1977
1978 /**
1979 * Perform a deletion and output success or failure messages
1980 */
1981 function doDelete( $reason ) {
1982 global $wgOut, $wgUser;
1983 $fname = 'Article::doDelete';
1984 wfDebug( $fname."\n" );
1985
1986 if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
1987 if ( $this->doDeleteArticle( $reason ) ) {
1988 $deleted = $this->mTitle->getPrefixedText();
1989
1990 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1991 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1992
1993 $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
1994 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1995
1996 $wgOut->addWikiText( $text );
1997 $wgOut->returnToMain( false );
1998 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
1999 } else {
2000 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
2001 }
2002 }
2003 }
2004
2005 /**
2006 * Back-end article deletion
2007 * Deletes the article with database consistency, writes logs, purges caches
2008 * Returns success
2009 */
2010 function doDeleteArticle( $reason ) {
2011 global $wgUseSquid, $wgDeferredUpdateList;
2012 global $wgPostCommitUpdateList, $wgUseTrackbacks;
2013
2014 $fname = 'Article::doDeleteArticle';
2015 wfDebug( $fname."\n" );
2016
2017 $dbw =& wfGetDB( DB_MASTER );
2018 $ns = $this->mTitle->getNamespace();
2019 $t = $this->mTitle->getDBkey();
2020 $id = $this->mTitle->getArticleID();
2021
2022 if ( $t == '' || $id == 0 ) {
2023 return false;
2024 }
2025
2026 $u = new SiteStatsUpdate( 0, 1, -(int)$this->isCountable( $this->getContent() ), -1 );
2027 array_push( $wgDeferredUpdateList, $u );
2028
2029 $linksTo = $this->mTitle->getLinksTo();
2030
2031 # Squid purging
2032 if ( $wgUseSquid ) {
2033 $urls = array(
2034 $this->mTitle->getInternalURL(),
2035 $this->mTitle->getInternalURL( 'history' )
2036 );
2037
2038 $u = SquidUpdate::newFromTitles( $linksTo, $urls );
2039 array_push( $wgPostCommitUpdateList, $u );
2040
2041 }
2042
2043 # Client and file cache invalidation
2044 Title::touchArray( $linksTo );
2045
2046
2047 // For now, shunt the revision data into the archive table.
2048 // Text is *not* removed from the text table; bulk storage
2049 // is left intact to avoid breaking block-compression or
2050 // immutable storage schemes.
2051 //
2052 // For backwards compatibility, note that some older archive
2053 // table entries will have ar_text and ar_flags fields still.
2054 //
2055 // In the future, we may keep revisions and mark them with
2056 // the rev_deleted field, which is reserved for this purpose.
2057 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
2058 array(
2059 'ar_namespace' => 'page_namespace',
2060 'ar_title' => 'page_title',
2061 'ar_comment' => 'rev_comment',
2062 'ar_user' => 'rev_user',
2063 'ar_user_text' => 'rev_user_text',
2064 'ar_timestamp' => 'rev_timestamp',
2065 'ar_minor_edit' => 'rev_minor_edit',
2066 'ar_rev_id' => 'rev_id',
2067 'ar_text_id' => 'rev_text_id',
2068 ), array(
2069 'page_id' => $id,
2070 'page_id = rev_page'
2071 ), $fname
2072 );
2073
2074 # Now that it's safely backed up, delete it
2075 $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname );
2076 $dbw->delete( 'page', array( 'page_id' => $id ), $fname);
2077
2078 if ($wgUseTrackbacks)
2079 $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), $fname );
2080
2081 # Clean up recentchanges entries...
2082 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
2083
2084 # Finally, clean up the link tables
2085 $t = $this->mTitle->getPrefixedDBkey();
2086
2087 Article::onArticleDelete( $this->mTitle );
2088
2089 # Delete outgoing links
2090 $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
2091 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
2092 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
2093 $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
2094 $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
2095
2096 # Log the deletion
2097 $log = new LogPage( 'delete' );
2098 $log->addEntry( 'delete', $this->mTitle, $reason );
2099
2100 # Clear the cached article id so the interface doesn't act like we exist
2101 $this->mTitle->resetArticleID( 0 );
2102 $this->mTitle->mArticleID = 0;
2103 return true;
2104 }
2105
2106 /**
2107 * Revert a modification
2108 */
2109 function rollback() {
2110 global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
2111 $fname = 'Article::rollback';
2112
2113 if( $wgUser->isAllowed( 'rollback' ) ) {
2114 if( $wgUser->isBlocked() ) {
2115 $wgOut->blockedPage();
2116 return;
2117 }
2118 } else {
2119 $wgOut->permissionRequired( 'rollback' );
2120 return;
2121 }
2122
2123 if ( wfReadOnly() ) {
2124 $wgOut->readOnlyPage( $this->getContent() );
2125 return;
2126 }
2127 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ),
2128 array( $this->mTitle->getPrefixedText(),
2129 $wgRequest->getVal( 'from' ) ) ) ) {
2130 $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
2131 $wgOut->addWikiText( wfMsg( 'sessionfailure' ) );
2132 return;
2133 }
2134 $dbw =& wfGetDB( DB_MASTER );
2135
2136 # Enhanced rollback, marks edits rc_bot=1
2137 $bot = $wgRequest->getBool( 'bot' );
2138
2139 # Replace all this user's current edits with the next one down
2140 $tt = $this->mTitle->getDBKey();
2141 $n = $this->mTitle->getNamespace();
2142
2143 # Get the last editor, lock table exclusively
2144 $dbw->begin();
2145 $current = Revision::newFromTitle( $this->mTitle );
2146 if( is_null( $current ) ) {
2147 # Something wrong... no page?
2148 $dbw->rollback();
2149 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
2150 return;
2151 }
2152
2153 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
2154 if( $from != $current->getUserText() ) {
2155 $wgOut->setPageTitle( wfMsg('rollbackfailed') );
2156 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
2157 htmlspecialchars( $this->mTitle->getPrefixedText()),
2158 htmlspecialchars( $from ),
2159 htmlspecialchars( $current->getUserText() ) ) );
2160 if( $current->getComment() != '') {
2161 $wgOut->addHTML(
2162 wfMsg( 'editcomment',
2163 htmlspecialchars( $current->getComment() ) ) );
2164 }
2165 return;
2166 }
2167
2168 # Get the last edit not by this guy
2169 $user = intval( $current->getUser() );
2170 $user_text = $dbw->addQuotes( $current->getUserText() );
2171 $s = $dbw->selectRow( 'revision',
2172 array( 'rev_id', 'rev_timestamp' ),
2173 array(
2174 'rev_page' => $current->getPage(),
2175 "rev_user <> {$user} OR rev_user_text <> {$user_text}"
2176 ), $fname,
2177 array(
2178 'USE INDEX' => 'page_timestamp',
2179 'ORDER BY' => 'rev_timestamp DESC' )
2180 );
2181 if( $s === false ) {
2182 # Something wrong
2183 $dbw->rollback();
2184 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
2185 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
2186 return;
2187 }
2188
2189 $set = array();
2190 if ( $bot ) {
2191 # Mark all reverted edits as bot
2192 $set['rc_bot'] = 1;
2193 }
2194 if ( $wgUseRCPatrol ) {
2195 # Mark all reverted edits as patrolled
2196 $set['rc_patrolled'] = 1;
2197 }
2198
2199 if ( $set ) {
2200 $dbw->update( 'recentchanges', $set,
2201 array( /* WHERE */
2202 'rc_cur_id' => $current->getPage(),
2203 'rc_user_text' => $current->getUserText(),
2204 "rc_timestamp > '{$s->rev_timestamp}'",
2205 ), $fname
2206 );
2207 }
2208
2209 # Get the edit summary
2210 $target = Revision::newFromId( $s->rev_id );
2211 $newComment = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
2212 $newComment = $wgRequest->getText( 'summary', $newComment );
2213
2214 # Save it!
2215 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
2216 $wgOut->setRobotpolicy( 'noindex,nofollow' );
2217 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newComment ) . "</h2>\n<hr />\n" );
2218
2219 $this->updateArticle( $target->getText(), $newComment, 1, $this->mTitle->userIsWatching(), $bot );
2220 Article::onArticleEdit( $this->mTitle );
2221
2222 $dbw->commit();
2223 $wgOut->returnToMain( false );
2224 }
2225
2226
2227 /**
2228 * Do standard deferred updates after page view
2229 * @access private
2230 */
2231 function viewUpdates() {
2232 global $wgDeferredUpdateList;
2233
2234 if ( 0 != $this->getID() ) {
2235 global $wgDisableCounters;
2236 if( !$wgDisableCounters ) {
2237 Article::incViewCount( $this->getID() );
2238 $u = new SiteStatsUpdate( 1, 0, 0 );
2239 array_push( $wgDeferredUpdateList, $u );
2240 }
2241 }
2242
2243 # Update newtalk / watchlist notification status
2244 global $wgUser;
2245 $wgUser->clearNotification( $this->mTitle );
2246 }
2247
2248 /**
2249 * Do standard deferred updates after page edit.
2250 * Every 1000th edit, prune the recent changes table.
2251 * @access private
2252 * @param string $text
2253 */
2254 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange, $newid) {
2255 global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
2256
2257 $fname = 'Article::editUpdates';
2258 wfProfileIn( $fname );
2259
2260 # Parse the text
2261 $options = new ParserOptions;
2262 $options->setTidy(true);
2263 $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
2264
2265 # Save it to the parser cache
2266 $parserCache =& ParserCache::singleton();
2267 $parserCache->save( $poutput, $this, $wgUser );
2268
2269 # Update the links tables
2270 $u = new LinksUpdate( $this->mTitle, $poutput );
2271 $u->doUpdate();
2272
2273 if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
2274 wfSeedRandom();
2275 if ( 0 == mt_rand( 0, 999 ) ) {
2276 # Periodically flush old entries from the recentchanges table.
2277 global $wgRCMaxAge;
2278
2279 $dbw =& wfGetDB( DB_MASTER );
2280 $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
2281 $recentchanges = $dbw->tableName( 'recentchanges' );
2282 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$cutoff}'";
2283 $dbw->query( $sql );
2284 }
2285 }
2286
2287 $id = $this->getID();
2288 $title = $this->mTitle->getPrefixedDBkey();
2289 $shortTitle = $this->mTitle->getDBkey();
2290
2291 if ( 0 == $id ) {
2292 wfProfileOut( $fname );
2293 return;
2294 }
2295
2296 $u = new SiteStatsUpdate( 0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment );
2297 array_push( $wgDeferredUpdateList, $u );
2298 $u = new SearchUpdate( $id, $title, $text );
2299 array_push( $wgDeferredUpdateList, $u );
2300
2301 # If this is another user's talk page, update newtalk
2302
2303 if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getName()) {
2304 if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this)) ) {
2305 $other = User::newFromName( $shortTitle );
2306 if( is_null( $other ) && User::isIP( $shortTitle ) ) {
2307 // An anonymous user
2308 $other = new User();
2309 $other->setName( $shortTitle );
2310 }
2311 if( $other ) {
2312 $other->setNewtalk( true );
2313 }
2314 }
2315 }
2316
2317 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2318 $wgMessageCache->replace( $shortTitle, $text );
2319 }
2320
2321 wfProfileOut( $fname );
2322 }
2323
2324 /**
2325 * Generate the navigation links when browsing through an article revisions
2326 * It shows the information as:
2327 * Revision as of <date>; view current revision
2328 * <- Previous version | Next Version ->
2329 *
2330 * @access private
2331 * @param string $oldid Revision ID of this article revision
2332 */
2333 function setOldSubtitle( $oldid=0 ) {
2334 global $wgLang, $wgOut, $wgUser;
2335
2336 $current = ( $oldid == $this->mLatest );
2337 $td = $wgLang->timeanddate( $this->mTimestamp, true );
2338 $sk = $wgUser->getSkin();
2339 $lnk = $current
2340 ? wfMsg( 'currentrevisionlink' )
2341 : $lnk = $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'currentrevisionlink' ) );
2342 $prev = $this->mTitle->getPreviousRevisionID( $oldid ) ;
2343 $prevlink = $prev
2344 ? $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid )
2345 : wfMsg( 'previousrevision' );
2346 $nextlink = $current
2347 ? wfMsg( 'nextrevision' )
2348 : $sk->makeKnownLinkObj( $this->mTitle, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
2349 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
2350 $wgOut->setSubtitle( $r );
2351 }
2352
2353 /**
2354 * This function is called right before saving the wikitext,
2355 * so we can do things like signatures and links-in-context.
2356 *
2357 * @param string $text
2358 */
2359 function preSaveTransform( $text ) {
2360 global $wgParser, $wgUser;
2361 return $wgParser->preSaveTransform( $text, $this->mTitle, $wgUser, ParserOptions::newFromUser( $wgUser ) );
2362 }
2363
2364 /* Caching functions */
2365
2366 /**
2367 * checkLastModified returns true if it has taken care of all
2368 * output to the client that is necessary for this request.
2369 * (that is, it has sent a cached version of the page)
2370 */
2371 function tryFileCache() {
2372 static $called = false;
2373 if( $called ) {
2374 wfDebug( " tryFileCache() -- called twice!?\n" );
2375 return;
2376 }
2377 $called = true;
2378 if($this->isFileCacheable()) {
2379 $touched = $this->mTouched;
2380 $cache = new CacheManager( $this->mTitle );
2381 if($cache->isFileCacheGood( $touched )) {
2382 wfDebug( " tryFileCache() - about to load\n" );
2383 $cache->loadFromFileCache();
2384 return true;
2385 } else {
2386 wfDebug( " tryFileCache() - starting buffer\n" );
2387 ob_start( array(&$cache, 'saveToFileCache' ) );
2388 }
2389 } else {
2390 wfDebug( " tryFileCache() - not cacheable\n" );
2391 }
2392 }
2393
2394 /**
2395 * Check if the page can be cached
2396 * @return bool
2397 */
2398 function isFileCacheable() {
2399 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
2400 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
2401
2402 return $wgUseFileCache
2403 and (!$wgShowIPinHeader)
2404 and ($this->getID() != 0)
2405 and ($wgUser->isAnon())
2406 and (!$wgUser->getNewtalk())
2407 and ($this->mTitle->getNamespace() != NS_SPECIAL )
2408 and (empty( $action ) || $action == 'view')
2409 and (!isset($oldid))
2410 and (!isset($diff))
2411 and (!isset($redirect))
2412 and (!isset($printable))
2413 and (!$this->mRedirectedFrom);
2414 }
2415
2416 /**
2417 * Loads page_touched and returns a value indicating if it should be used
2418 *
2419 */
2420 function checkTouched() {
2421 $fname = 'Article::checkTouched';
2422 if( !$this->mDataLoaded ) {
2423 $this->loadPageData();
2424 }
2425 return !$this->mIsRedirect;
2426 }
2427
2428 /**
2429 * Get the page_touched field
2430 */
2431 function getTouched() {
2432 # Ensure that page data has been loaded
2433 if( !$this->mDataLoaded ) {
2434 $this->loadPageData();
2435 }
2436 return $this->mTouched;
2437 }
2438
2439 /**
2440 * Get the page_latest field
2441 */
2442 function getLatest() {
2443 if ( !$this->mDataLoaded ) {
2444 $this->loadPageData();
2445 }
2446 return $this->mLatest;
2447 }
2448
2449 /**
2450 * Edit an article without doing all that other stuff
2451 * The article must already exist; link tables etc
2452 * are not updated, caches are not flushed.
2453 *
2454 * @param string $text text submitted
2455 * @param string $comment comment submitted
2456 * @param bool $minor whereas it's a minor modification
2457 */
2458 function quickEdit( $text, $comment = '', $minor = 0 ) {
2459 $fname = 'Article::quickEdit';
2460 wfProfileIn( $fname );
2461
2462 $dbw =& wfGetDB( DB_MASTER );
2463 $dbw->begin();
2464 $revision = new Revision( array(
2465 'page' => $this->getId(),
2466 'text' => $text,
2467 'comment' => $comment,
2468 'minor_edit' => $minor ? 1 : 0,
2469 ) );
2470 $revisionId = $revision->insertOn( $dbw );
2471 $this->updateRevisionOn( $dbw, $revision );
2472 $dbw->commit();
2473
2474 wfProfileOut( $fname );
2475 }
2476
2477 /**
2478 * Used to increment the view counter
2479 *
2480 * @static
2481 * @param integer $id article id
2482 */
2483 function incViewCount( $id ) {
2484 $id = intval( $id );
2485 global $wgHitcounterUpdateFreq;
2486
2487 $dbw =& wfGetDB( DB_MASTER );
2488 $pageTable = $dbw->tableName( 'page' );
2489 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2490 $acchitsTable = $dbw->tableName( 'acchits' );
2491
2492 if( $wgHitcounterUpdateFreq <= 1 ){ //
2493 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2494 return;
2495 }
2496
2497 # Not important enough to warrant an error page in case of failure
2498 $oldignore = $dbw->ignoreErrors( true );
2499
2500 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2501
2502 $checkfreq = intval( $wgHitcounterUpdateFreq/25 + 1 );
2503 if( (rand() % $checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2504 # Most of the time (or on SQL errors), skip row count check
2505 $dbw->ignoreErrors( $oldignore );
2506 return;
2507 }
2508
2509 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2510 $row = $dbw->fetchObject( $res );
2511 $rown = intval( $row->n );
2512 if( $rown >= $wgHitcounterUpdateFreq ){
2513 wfProfileIn( 'Article::incViewCount-collect' );
2514 $old_user_abort = ignore_user_abort( true );
2515
2516 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2517 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2518 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2519 'GROUP BY hc_id');
2520 $dbw->query("DELETE FROM $hitcounterTable");
2521 $dbw->query('UNLOCK TABLES');
2522 $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
2523 'WHERE page_id = hc_id');
2524 $dbw->query("DROP TABLE $acchitsTable");
2525
2526 ignore_user_abort( $old_user_abort );
2527 wfProfileOut( 'Article::incViewCount-collect' );
2528 }
2529 $dbw->ignoreErrors( $oldignore );
2530 }
2531
2532 /**#@+
2533 * The onArticle*() functions are supposed to be a kind of hooks
2534 * which should be called whenever any of the specified actions
2535 * are done.
2536 *
2537 * This is a good place to put code to clear caches, for instance.
2538 *
2539 * This is called on page move and undelete, as well as edit
2540 * @static
2541 * @param $title_obj a title object
2542 */
2543
2544 function onArticleCreate($title_obj) {
2545 global $wgUseSquid, $wgPostCommitUpdateList;
2546
2547 $title_obj->touchLinks();
2548 $titles = $title_obj->getLinksTo();
2549
2550 # Purge squid
2551 if ( $wgUseSquid ) {
2552 $urls = $title_obj->getSquidURLs();
2553 foreach ( $titles as $linkTitle ) {
2554 $urls[] = $linkTitle->getInternalURL();
2555 }
2556 $u = new SquidUpdate( $urls );
2557 array_push( $wgPostCommitUpdateList, $u );
2558 }
2559 }
2560
2561 function onArticleDelete( $title ) {
2562 global $wgMessageCache;
2563
2564 $title->touchLinks();
2565
2566 if( $title->getNamespace() == NS_MEDIAWIKI) {
2567 $wgMessageCache->replace( $title->getDBkey(), false );
2568 }
2569 }
2570
2571 /**
2572 * Purge caches on page update etc
2573 */
2574 function onArticleEdit( $title ) {
2575 global $wgUseSquid, $wgPostCommitUpdateList, $wgUseFileCache;
2576
2577 $urls = array();
2578
2579 // Template namespace? Purge all articles linking here.
2580 // FIXME: When a templatelinks table arrives, use it for all includes.
2581 if ( $title->getNamespace() == NS_TEMPLATE) {
2582 $titles = $title->getLinksTo();
2583 Title::touchArray( $titles );
2584 if ( $wgUseSquid ) {
2585 foreach ( $titles as $link ) {
2586 $urls[] = $link->getInternalURL();
2587 }
2588 }
2589 }
2590
2591 # Squid updates
2592 if ( $wgUseSquid ) {
2593 $urls = array_merge( $urls, $title->getSquidURLs() );
2594 $u = new SquidUpdate( $urls );
2595 array_push( $wgPostCommitUpdateList, $u );
2596 }
2597
2598 # File cache
2599 if ( $wgUseFileCache ) {
2600 $cm = new CacheManager( $title );
2601 @unlink( $cm->fileCacheName() );
2602 }
2603 }
2604
2605 /**#@-*/
2606
2607 /**
2608 * Info about this page
2609 * Called for ?action=info when $wgAllowPageInfo is on.
2610 *
2611 * @access public
2612 */
2613 function info() {
2614 global $wgLang, $wgOut, $wgAllowPageInfo, $wgUser;
2615 $fname = 'Article::info';
2616
2617 if ( !$wgAllowPageInfo ) {
2618 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2619 return;
2620 }
2621
2622 $page = $this->mTitle->getSubjectPage();
2623
2624 $wgOut->setPagetitle( $page->getPrefixedText() );
2625 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2626
2627 # first, see if the page exists at all.
2628 $exists = $page->getArticleId() != 0;
2629 if( !$exists ) {
2630 if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2631 $wgOut->addHTML(wfMsgWeirdKey ( $this->mTitle->getText() ) );
2632 } else {
2633 $wgOut->addHTML(wfMsg( $wgUser->isLoggedIn() ? 'noarticletext' : 'noarticletextanon' ) );
2634 }
2635 } else {
2636 $dbr =& wfGetDB( DB_SLAVE );
2637 $wl_clause = array(
2638 'wl_title' => $page->getDBkey(),
2639 'wl_namespace' => $page->getNamespace() );
2640 $numwatchers = $dbr->selectField(
2641 'watchlist',
2642 'COUNT(*)',
2643 $wl_clause,
2644 $fname,
2645 $this->getSelectOptions() );
2646
2647 $pageInfo = $this->pageCountInfo( $page );
2648 $talkInfo = $this->pageCountInfo( $page->getTalkPage() );
2649
2650 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $wgLang->formatNum( $numwatchers ) ) . '</li>' );
2651 $wgOut->addHTML( "<li>" . wfMsg('numedits', $wgLang->formatNum( $pageInfo['edits'] ) ) . '</li>');
2652 if( $talkInfo ) {
2653 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $wgLang->formatNum( $talkInfo['edits'] ) ) . '</li>');
2654 }
2655 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $wgLang->formatNum( $pageInfo['authors'] ) ) . '</li>' );
2656 if( $talkInfo ) {
2657 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $wgLang->formatNum( $talkInfo['authors'] ) ) . '</li>' );
2658 }
2659 $wgOut->addHTML( '</ul>' );
2660
2661 }
2662 }
2663
2664 /**
2665 * Return the total number of edits and number of unique editors
2666 * on a given page. If page does not exist, returns false.
2667 *
2668 * @param Title $title
2669 * @return array
2670 * @access private
2671 */
2672 function pageCountInfo( $title ) {
2673 $id = $title->getArticleId();
2674 if( $id == 0 ) {
2675 return false;
2676 }
2677
2678 $dbr =& wfGetDB( DB_SLAVE );
2679
2680 $rev_clause = array( 'rev_page' => $id );
2681 $fname = 'Article::pageCountInfo';
2682
2683 $edits = $dbr->selectField(
2684 'revision',
2685 'COUNT(rev_page)',
2686 $rev_clause,
2687 $fname,
2688 $this->getSelectOptions() );
2689
2690 $authors = $dbr->selectField(
2691 'revision',
2692 'COUNT(DISTINCT rev_user_text)',
2693 $rev_clause,
2694 $fname,
2695 $this->getSelectOptions() );
2696
2697 return array( 'edits' => $edits, 'authors' => $authors );
2698 }
2699
2700 /**
2701 * Return a list of templates used by this article.
2702 * Uses the templatelinks table
2703 *
2704 * @return array Array of Title objects
2705 */
2706 function getUsedTemplates() {
2707 $result = array();
2708 $id = $this->mTitle->getArticleID();
2709 if( $id == 0 ) {
2710 return array();
2711 }
2712
2713 $dbr =& wfGetDB( DB_SLAVE );
2714 $res = $dbr->select( array( 'templatelinks' ),
2715 array( 'tl_namespace', 'tl_title' ),
2716 array( 'tl_from' => $id ),
2717 'Article:getUsedTemplates' );
2718 if ( false !== $res ) {
2719 if ( $dbr->numRows( $res ) ) {
2720 while ( $row = $dbr->fetchObject( $res ) ) {
2721 $result[] = Title::makeTitle( $row->tl_namespace, $row->tl_title );
2722 }
2723 }
2724 }
2725 $dbr->freeResult( $res );
2726 return $result;
2727 }
2728 }
2729
2730 ?>