8 * Need the CacheManager to be loaded
10 require_once ( 'CacheManager.php' );
12 $wgArticleCurContentFields = false;
13 $wgArticleOldContentFields = false;
16 * Class representing a Wikipedia article and history.
18 * See design.doc for an overview.
19 * Note: edit user interface and cache support functions have been
20 * moved to separate EditPage and CacheManager classes.
28 var $mContent, $mContentLoaded;
29 var $mUser, $mTimestamp, $mUserText;
30 var $mCounter, $mComment, $mCountAdjustment;
31 var $mMinorEdit, $mRedirectedFrom;
32 var $mTouched, $mFileCache, $mTitle;
39 * Constructor and clear the article
40 * @param mixed &$title
42 function Article( &$title ) {
43 $this->mTitle
=& $title;
52 $this->mContentLoaded
= false;
53 $this->mCurID
= $this->mUser
= $this->mCounter
= -1; # Not loaded
54 $this->mRedirectedFrom
= $this->mUserText
=
55 $this->mTimestamp
= $this->mComment
= $this->mFileCache
= '';
56 $this->mCountAdjustment
= 0;
57 $this->mTouched
= '19700101000000';
58 $this->mForUpdate
= false;
62 * Get revision text associated with an old or archive row
63 * $row is usually an object from wfFetchRow(), both the flags and the text
64 * field must be included
66 * @param integer $row Id of a row
67 * @param string $prefix table prefix (default 'old_')
68 * @return string $text|false the text requested
70 function getRevisionText( $row, $prefix = 'old_' ) {
71 $fname = 'Article::getRevisionText';
72 wfProfileIn( $fname );
75 $textField = $prefix . 'text';
76 $flagsField = $prefix . 'flags';
78 if( isset( $row->$flagsField ) ) {
79 $flags = explode( ',', $row->$flagsField );
84 if( isset( $row->$textField ) ) {
85 $text = $row->$textField;
87 wfProfileOut( $fname );
91 if( in_array( 'gzip', $flags ) ) {
92 # Deal with optional compression of archived pages.
93 # This can be done periodically via maintenance/compressOld.php, and
94 # as pages are saved if $wgCompressRevisions is set.
95 $text = gzinflate( $text );
98 if( in_array( 'object', $flags ) ) {
99 # Generic compressed storage
100 $obj = unserialize( $text );
102 # Bugger, corrupted my test database by double-serializing
103 if ( !is_object( $obj ) ) {
104 $obj = unserialize( $obj );
107 $text = $obj->getText();
110 global $wgLegacyEncoding;
111 if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
112 # Old revisions kept around in a legacy encoding?
113 # Upconvert on demand.
114 global $wgInputEncoding, $wgContLang;
115 $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
117 wfProfileOut( $fname );
122 * If $wgCompressRevisions is enabled, we will compress data.
123 * The input string is modified in place.
124 * Return value is the flags field: contains 'gzip' if the
125 * data is compressed, and 'utf-8' if we're saving in UTF-8
129 * @param mixed $text reference to a text
132 function compressRevisionText( &$text ) {
133 global $wgCompressRevisions, $wgUseLatin1;
135 if( !$wgUseLatin1 ) {
136 # Revisions not marked this way will be converted
137 # on load if $wgLegacyCharset is set in the future.
140 if( $wgCompressRevisions ) {
141 if( function_exists( 'gzdeflate' ) ) {
142 $text = gzdeflate( $text );
145 wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
148 return implode( ',', $flags );
152 * Note that getContent/loadContent may follow redirects if
153 * not told otherwise, and so may cause a change to mTitle.
156 * @return Return the text of this revision
158 function getContent( $noredir ) {
161 # Get variables from query string :P
162 $action = $wgRequest->getText( 'action', 'view' );
163 $section = $wgRequest->getText( 'section' );
165 $fname = 'Article::getContent';
166 wfProfileIn( $fname );
168 if ( 0 == $this->getID() ) {
169 if ( 'edit' == $action ) {
170 wfProfileOut( $fname );
171 return ''; # was "newarticletext", now moved above the box)
173 wfProfileOut( $fname );
174 return wfMsg( 'noarticletext' );
176 $this->loadContent( $noredir );
177 # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
178 if ( $this->mTitle
->getNamespace() == NS_USER_TALK
&&
179 preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle
->getText()) &&
182 wfProfileOut( $fname );
183 return $this->mContent
. "\n" .wfMsg('anontalkpagetext');
185 if($action=='edit') {
187 if($section=='new') {
188 wfProfileOut( $fname );
192 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
193 # comments to be stripped as well)
194 $rv=$this->getSection($this->mContent
,$section);
195 wfProfileOut( $fname );
199 wfProfileOut( $fname );
200 return $this->mContent
;
206 * This function returns the text of a section, specified by a number ($section).
207 * A section is text under a heading like == Heading == or <h1>Heading</h1>, or
208 * the first section before any such heading (section 0).
210 * If a section contains subsections, these are also returned.
212 * @param string $text text to look in
213 * @param integer $section section number
214 * @return string text of the requested section
216 function getSection($text,$section) {
218 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
219 # comments to be stripped as well)
221 $parser=new Parser();
222 $parser->mOutputType
=OT_WIKI
;
223 $striptext=$parser->strip($text, $striparray, true);
225 # now that we can be sure that no pseudo-sections are in the source,
226 # split it up by section
229 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
231 PREG_SPLIT_DELIM_CAPTURE
);
235 $headline=$secs[$section*2-1];
236 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
239 # translate wiki heading into level
240 if(strpos($hlevel,'=')!==false) {
241 $hlevel=strlen($hlevel);
244 $rv=$headline. $secs[$section*2];
248 while(!empty($secs[$count*2-1]) && !$break) {
250 $subheadline=$secs[$count*2-1];
251 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
252 $subhlevel=$matches[1];
253 if(strpos($subhlevel,'=')!==false) {
254 $subhlevel=strlen($subhlevel);
256 if($subhlevel > $hlevel) {
257 $rv.=$subheadline.$secs[$count*2];
259 if($subhlevel <= $hlevel) {
266 # reinsert stripped tags
267 $rv=$parser->unstrip($rv,$striparray);
268 $rv=$parser->unstripNoWiki($rv,$striparray);
275 * Return an array of the columns of the "cur"-table
277 function getContentFields() {
278 return $wgArticleContentFields = array(
279 'old_text','old_flags',
280 'rev_timestamp','rev_user', 'rev_user_text', 'rev_comment','page_counter',
281 'page_namespace', 'page_title', 'page_restrictions','page_touched','page_is_redirect' );
285 * Return the oldid of the article that is to be shown.
286 * For requests with a "direction", this is not the oldid of the
289 function getOldID() {
290 global $wgRequest, $wgOut;
293 if ( isset( $lastid ) ) {
297 $oldid = $wgRequest->getVal( 'oldid' );
298 if ( isset( $oldid ) ) {
299 $dbr =& $this->getDB();
300 $oldid = IntVal( $oldid );
301 if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
302 $nextid = $this->mTitle
->getNextRevisionID( $oldid );
306 $wgOut->redirect( $this->mTitle
->getFullURL( 'redirect=no' ) );
308 } elseif ( $wgRequest->getVal( 'direction' ) == 'prev' ) {
309 $previd = $this->mTitle
->getPreviousRevisionID( $oldid );
318 return @$oldid; # "@" to be able to return "unset" without PHP complaining
323 * Load the revision (including cur_text) into this object
325 function loadContent( $noredir = false ) {
326 global $wgOut, $wgRequest;
328 if ( $this->mContentLoaded
) return;
330 $dbr =& $this->getDB();
332 $oldid = $this->getOldID();
333 $redirect = $wgRequest->getVal( 'redirect' );
335 $fname = 'Article::loadContent';
337 # Pre-fill content with error message so that if something
338 # fails we'll have something telling us what we intended.
340 $t = $this->mTitle
->getPrefixedText();
342 $noredir = $noredir ||
($wgRequest->getVal( 'redirect' ) == 'no');
343 $this->mOldId
= $oldid;
344 $this->fetchContent( $oldid, $noredir, true );
348 * @param int $oldid 0 for whatever the latest revision is
349 * @param bool $noredir Set to true to avoid following redirects
350 * @param bool $globalTitle Set to true to change the global $wgTitle object when following redirects or other unexpected title changes
353 function fetchContent( $oldid = 0, $noredir = false, $globalTitle = false ) {
354 if ( $this->mContentLoaded
) {
355 return $this->mContent
;
357 $dbr =& $this->getDB();
358 $fname = 'Article::fetchContent';
360 # Pre-fill content with error message so that if something
361 # fails we'll have something telling us what we intended.
362 $t = $this->mTitle
->getPrefixedText();
364 $t .= ',oldid='.$oldid;
366 if( isset( $redirect ) ) {
367 $redirect = ($redirect == 'no') ?
'no' : 'yes';
368 $t .= ',redirect='.$redirect;
370 $this->mContent
= wfMsg( 'missingarticle', $t );
373 # Retrieve current version
374 $id = $this->getID();
379 $s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
380 $this->getContentFields(),
381 "page_id='$id' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
382 $fname, $this->getSelectOptions() );
384 # Historical revision
385 $s = $dbr->selectRow( array( 'text', 'revision', 'page' ),
386 $this->getContentFields(),
387 "rev_page=page_id AND rev_id='$oldid' AND old_id=rev_id",
388 $fname, $this->getSelectOptions() );
390 if ( $s === false ) {
394 # If we got a redirect, follow it (unless we've been told
395 # not to by either the function parameter or the query
396 if ( !$oldid && !$noredir ) {
397 $rt = Title
::newFromRedirect( Article
::getRevisionText( $s ) );
398 # process if title object is valid and not special:userlogout
399 if ( $rt && ! ( $rt->getNamespace() == NS_SPECIAL
&& $rt->getText() == 'Userlogout' ) ) {
400 # Gotta hand redirects to special pages differently:
401 # Fill the HTTP response "Location" header and ignore
402 # the rest of the page we're on.
405 if ( $rt->getInterwiki() != '' ) {
406 $wgOut->redirect( $rt->getFullURL() ) ;
409 if ( $rt->getNamespace() == NS_SPECIAL
) {
410 $wgOut->redirect( $rt->getFullURL() );
414 $rid = $rt->getArticleID();
416 $redirRow = $dbr->selectRow( array( 'text', 'revision', 'page' ),
417 $this->getContentFields(),
418 "page_id='$rid' AND rev_page=page_id AND rev_id=page_latest AND old_id=rev_id",
419 $fname, $this->getSelectOptions() );
421 if ( $redirRow !== false ) {
422 $this->mRedirectedFrom
= $this->mTitle
->getPrefixedText();
430 # if the title's different from expected, update...
432 ( $this->mTitle
->getNamespace() != $s->page_namespace ||
433 $this->mTitle
->getDBkey() != $s->page_title
) ) {
434 $oldTitle = Title
::makeTitle( $s->page_namesapce
, $s->page_title
);
435 $this->mTitle
= $oldTitle;
437 $wgTitle = $oldTitle;
440 # Back to the business at hand...
441 $this->mCounter
= $s->page_counter
;
442 $this->mTitle
->mRestrictions
= explode( ',', trim( $s->page_restrictions
) );
443 $this->mTitle
->mRestrictionsLoaded
= true;
444 $this->mTouched
= wfTimestamp( TS_MW
, $s->page_touched
);
446 $this->mContent
= Article
::getRevisionText( $s );
448 $this->mUser
= $s->rev_user
;
449 $this->mUserText
= $s->rev_user_text
;
450 $this->mComment
= $s->rev_comment
;
451 $this->mTimestamp
= wfTimestamp( TS_MW
, $s->rev_timestamp
);
453 $this->mContentLoaded
= true;
454 return $this->mContent
;
458 * Gets the article text without using so many damn globals
459 * Returns false on error
461 * @param integer $oldid
463 function getContentWithoutUsingSoManyDamnGlobals( $oldid = 0, $noredir = false ) {
464 return $this->fetchContent( $oldid, $noredir, false );
468 * Read/write accessor to select FOR UPDATE
470 function forUpdate( $x = NULL ) {
471 return wfSetVar( $this->mForUpdate
, $x );
475 * Get the database which should be used for reads
478 if ( $this->mForUpdate
) {
479 return wfGetDB( DB_MASTER
);
481 return wfGetDB( DB_SLAVE
);
486 * Get options for all SELECT statements
487 * Can pass an option array, to which the class-wide options will be appended
489 function getSelectOptions( $options = '' ) {
490 if ( $this->mForUpdate
) {
492 $options[] = 'FOR UPDATE';
494 $options = 'FOR UPDATE';
501 * Return the Article ID
504 if( $this->mTitle
) {
505 return $this->mTitle
->getArticleID();
512 * Get the view count for this article
514 function getCount() {
515 if ( -1 == $this->mCounter
) {
516 $id = $this->getID();
517 $dbr =& $this->getDB();
518 $this->mCounter
= $dbr->selectField( 'page', 'page_counter', array( 'page_id' => $id ),
519 'Article::getCount', $this->getSelectOptions() );
521 return $this->mCounter
;
525 * Would the given text make this article a "good" article (i.e.,
526 * suitable for including in the article count)?
528 function isCountable( $text ) {
529 global $wgUseCommaCount;
531 if ( 0 != $this->mTitle
->getNamespace() ) { return 0; }
532 if ( $this->isRedirect( $text ) ) { return 0; }
533 $token = ($wgUseCommaCount ?
',' : '[[' );
534 if ( false === strstr( $text, $token ) ) { return 0; }
539 * Tests if the article text represents a redirect
541 function isRedirect( $text = false ) {
542 if ( $text === false ) {
543 $this->loadContent();
544 $titleObj = Title
::newFromRedirect( $this->mText
);
546 $titleObj = Title
::newFromRedirect( $text );
548 return $titleObj !== NULL;
552 * Loads everything except the text
553 * This isn't necessary for all uses, so it's only done if needed.
556 function loadLastEdit() {
559 if ( -1 != $this->mUser
)
562 $fname = 'Article::loadLastEdit';
564 $dbr =& $this->getDB();
565 $s = $dbr->selectRow( array( 'revision', 'page') ,
566 array( 'rev_user','rev_user_text','rev_timestamp', 'rev_comment','rev_minor_edit' ),
567 array( 'page_id' => $this->getID(), 'page_latest=rev_id' ), $fname, $this->getSelectOptions() );
569 if ( $s !== false ) {
570 $this->mUser
= $s->rev_user
;
571 $this->mUserText
= $s->rev_user_text
;
572 $this->mTimestamp
= wfTimestamp(TS_MW
,$s->rev_timestamp
);
573 $this->mComment
= $s->rev_comment
;
574 $this->mMinorEdit
= $s->rev_minor_edit
;
578 function getTimestamp() {
579 $this->loadLastEdit();
580 return $this->mTimestamp
;
584 $this->loadLastEdit();
588 function getUserText() {
589 $this->loadLastEdit();
590 return $this->mUserText
;
593 function getComment() {
594 $this->loadLastEdit();
595 return $this->mComment
;
598 function getMinorEdit() {
599 $this->loadLastEdit();
600 return $this->mMinorEdit
;
603 function getContributors($limit = 0, $offset = 0) {
604 $fname = 'Article::getContributors';
606 # XXX: this is expensive; cache this info somewhere.
608 $title = $this->mTitle
;
610 $dbr =& $this->getDB();
611 $revTable = $dbr->tableName( 'revision' );
612 $userTable = $dbr->tableName( 'user' );
613 $encDBkey = $dbr->addQuotes( $title->getDBkey() );
614 $ns = $title->getNamespace();
615 $user = $this->getUser();
617 $sql = "SELECT rev_user, rev_user_text, user_real_name, MAX(rev_timestamp) as timestamp
618 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
619 WHERE rev_page = $pageId
620 AND old_user != $user
621 GROUP BY rev_user, rev_user_text, user_real_name
622 ORDER BY timestamp DESC";
624 if ($limit > 0) { $sql .= ' LIMIT '.$limit; }
625 $sql .= ' '. $this->getSelectOptions();
627 $res = $dbr->query($sql, $fname);
629 while ( $line = $dbr->fetchObject( $res ) ) {
630 $contribs[] = array($line->rev_user
, $line->rev_user_text
, $line->user_real_name
);
633 $dbr->freeResult($res);
638 * This is the default action of the script: just view the page of
642 global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
643 global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
645 $sk = $wgUser->getSkin();
647 $fname = 'Article::view';
648 wfProfileIn( $fname );
649 # Get variables from query string
650 $oldid = $this->getOldID();
651 $diff = $wgRequest->getVal( 'diff' );
652 $rcid = $wgRequest->getVal( 'rcid' );
654 $wgOut->setArticleFlag( true );
655 $wgOut->setRobotpolicy( 'index,follow' );
656 # If we got diff and oldid in the query, we want to see a
657 # diff page instead of the article.
659 if ( !is_null( $diff ) ) {
660 require_once( 'DifferenceEngine.php' );
661 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
662 $de = new DifferenceEngine( $oldid, $diff, $rcid );
665 # Run view updates for current revision only
666 $this->viewUpdates();
668 wfProfileOut( $fname );
671 if ( empty( $oldid ) && $this->checkTouched() ) {
672 if( $wgOut->checkLastModified( $this->mTouched
) ){
673 wfProfileOut( $fname );
675 } else if ( $this->tryFileCache() ) {
676 # tell wgOut that output is taken care of
678 $this->viewUpdates();
679 wfProfileOut( $fname );
683 # Should the parser cache be used?
684 if ( $wgEnableParserCache && intval($wgUser->getOption( 'stubthreshold' )) == 0 && empty( $oldid ) ) {
692 if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
696 if ( !$outputDone ) {
697 $text = $this->getContent( false ); # May change mTitle by following a redirect
699 # Another whitelist check in case oldid or redirects are altering the title
700 if ( !$this->mTitle
->userCanRead() ) {
701 $wgOut->loginToUse();
707 # We're looking at an old revision
709 if ( !empty( $oldid ) ) {
710 $this->setOldSubtitle( isset($this->mOldId
) ?
$this->mOldId
: $oldid );
711 $wgOut->setRobotpolicy( 'noindex,follow' );
713 if ( '' != $this->mRedirectedFrom
) {
714 $sk = $wgUser->getSkin();
715 $redir = $sk->makeKnownLink( $this->mRedirectedFrom
, '',
717 $s = wfMsg( 'redirectedfrom', $redir );
718 $wgOut->setSubtitle( $s );
720 # Can't cache redirects
724 # wrap user css and user js in pre and don't parse
725 # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found
727 $this->mTitle
->getNamespace() == NS_USER
&&
728 preg_match('/\\/[\\w]+\\.(css|js)$/', $this->mTitle
->getDBkey())
730 $wgOut->addWikiText( wfMsg('clearyourcache'));
731 $wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent
)."\n</pre>" );
732 } else if ( $rt = Title
::newFromRedirect( $text ) ) {
734 $imageUrl = $wgStylePath.'/common/images/redirect.png';
735 $targetUrl = $rt->escapeLocalURL();
736 $titleText = htmlspecialchars( $rt->getPrefixedText() );
737 $link = $sk->makeLinkObj( $rt );
739 $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
740 '<span class="redirectText">'.$link.'</span>' );
742 } else if ( $pcache ) {
743 # Display content and save to parser cache
744 $wgOut->addPrimaryWikiText( $text, $this );
746 # Display content, don't attempt to save to parser cache
747 $wgOut->addWikiText( $text );
750 $wgOut->setPageTitle( $this->mTitle
->getPrefixedText() );
751 # If we have been passed an &rcid= parameter, we want to give the user a
752 # chance to mark this new article as patrolled.
753 if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->getID() != 0 &&
754 ( $wgUser->isAllowed('patrol') ||
!$wgOnlySysopsCanPatrol ) )
756 $wgOut->addHTML( wfMsg ( 'markaspatrolledlink',
757 $sk->makeKnownLinkObj ( $this->mTitle
, wfMsg ( 'markaspatrolledtext' ),
758 'action=markpatrolled&rcid='.$rcid )
762 # Put link titles into the link cache
763 $wgOut->transformBuffer();
765 # Add link titles as META keywords
766 $wgOut->addMetaTags() ;
768 $this->viewUpdates();
769 wfProfileOut( $fname );
771 $wgUser->clearNotification( $this->mTitle
);
775 * Theoretically we could defer these whole insert and update
776 * functions for after display, but that's taking a big leap
777 * of faith, and we want to be able to report database
778 * errors at some point.
781 function insertNewArticle( $text, $summary, $isminor, $watchthis ) {
782 global $wgOut, $wgUser;
783 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
785 $fname = 'Article::insertNewArticle';
787 $this->mCountAdjustment
= $this->isCountable( $text );
789 $ns = $this->mTitle
->getNamespace();
790 $ttl = $this->mTitle
->getDBkey();
791 $text = $this->preSaveTransform( $text );
792 if ( $this->isRedirect( $text ) ) { $redir = 1; }
795 $now = wfTimestampNow();
796 $won = wfInvertTimestamp( $now );
799 $isminor = ( $isminor && $wgUser->getID() ) ?
1 : 0;
802 $flags = Article
::compressRevisionText( $mungedText );
804 $dbw =& wfGetDB( DB_MASTER
);
806 $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
807 $dbw->insert( 'text', array(
809 'old_text' => $mungedText,
810 'old_flags' => $flags,
812 $revisionId = $dbw->insertId();
814 $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
815 $dbw->insert( 'page', array(
816 'page_id' => $page_id,
817 'page_namespace' => $ns,
818 'page_title' => $ttl,
820 'page_restrictions' => '',
821 'page_is_redirect' => $redir,
823 'page_random' => $rand,
824 'page_touched' => $dbw->timestamp($now),
825 'page_latest' => $revisionId,
827 $newid = $dbw->insertId();
829 $dbw->insert( 'revision', array(
830 'rev_page' => $newid,
831 'rev_id' => $revisionId,
832 'rev_comment' => $summary,
833 'rev_user' => $wgUser->getID(),
834 'rev_timestamp' => $dbw->timestamp($now),
835 'rev_minor_edit' => $isminor,
836 'rev_user_text' => $wgUser->getName(),
837 'inverse_timestamp' => $won,
840 $this->mTitle
->resetArticleID( $newid );
842 Article
::onArticleCreate( $this->mTitle
);
843 RecentChange
::notifyNew( $now, $this->mTitle
, $isminor, $wgUser, $summary );
846 if(!$this->mTitle
->userIsWatching()) $this->watch();
848 if ( $this->mTitle
->userIsWatching() ) {
853 # The talk page isn't in the regular link tables, so we need to update manually:
854 $talkns = $ns ^
1; # talk -> normal; normal -> talk
855 $dbw->update( 'page',
856 array( 'page_touched' => $dbw->timestamp($now) ),
857 array( 'page_namespace' => $talkns,
858 'page_title' => $ttl ),
861 # standard deferred updates
862 $this->editUpdates( $text, $summary, $isminor, $now );
864 $oldid = 0; # new article
865 $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
869 * Fetch and uncompress the text for a given revision.
870 * Can ask by rev_id number or timestamp (set $field)
872 function fetchRevisionText( $revId = null, $field = 'rev_id' ) {
873 $fname = 'Article::fetchRevisionText';
874 $dbw =& wfGetDB( DB_MASTER
);
876 $rev = $dbw->addQuotes( $revId );
878 $rev = 'page_latest';
880 $result = $dbw->query(
881 sprintf( "SELECT old_text, old_flags
883 WHERE old_id=rev_id AND rev_page=page_id AND page_id=%d
885 $dbw->tableName( 'page' ),
886 $dbw->tableName( 'revision' ),
887 $dbw->tableName( 'text' ),
888 IntVal( $this->mTitle
->getArticleId() ),
892 $obj = $dbw->fetchObject( $result );
893 $dbw->freeResult( $result );
894 $oldtext = Article
::getRevisionText( $obj );
898 function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) {
899 $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded';
900 if( is_null( $edittime ) ) {
901 $oldtext = $this->fetchRevisionText();
903 $oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' );
905 if ($section != '') {
906 if($section=='new') {
907 if($summary) $subject="== {$summary} ==\n\n";
908 $text=$oldtext."\n\n".$subject.$text;
911 # strip NOWIKI etc. to avoid confusion (true-parameter causes HTML
912 # comments to be stripped as well)
914 $parser=new Parser();
915 $parser->mOutputType
=OT_WIKI
;
916 $oldtext=$parser->strip($oldtext, $striparray, true);
918 # now that we can be sure that no pseudo-sections are in the source,
920 # Unfortunately we can't simply do a preg_replace because that might
921 # replace the wrong section, so we have to use the section counter instead
922 $secs=preg_split('/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
923 $oldtext,-1,PREG_SPLIT_DELIM_CAPTURE
);
924 $secs[$section*2]=$text."\n\n"; // replace with edited
926 # section 0 is top (intro) section
929 # headline of old section - we need to go through this section
930 # to determine if there are any subsections that now need to
931 # be erased, as the mother section has been replaced with
932 # the text of all subsections.
933 $headline=$secs[$section*2-1];
934 preg_match( '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$headline,$matches);
937 # determine headline level for wikimarkup headings
938 if(strpos($hlevel,'=')!==false) {
939 $hlevel=strlen($hlevel);
942 $secs[$section*2-1]=''; // erase old headline
945 while(!empty($secs[$count*2-1]) && !$break) {
947 $subheadline=$secs[$count*2-1];
949 '/^(=+).+?=+|^<h([1-6]).*?' . '>.*?<\/h[1-6].*?' . '>(?!\S)/mi',$subheadline,$matches);
950 $subhlevel=$matches[1];
951 if(strpos($subhlevel,'=')!==false) {
952 $subhlevel=strlen($subhlevel);
954 if($subhlevel > $hlevel) {
955 // erase old subsections
956 $secs[$count*2-1]='';
959 if($subhlevel <= $hlevel) {
967 $text=join('',$secs);
968 # reinsert the stuff that we stripped out earlier
969 $text=$parser->unstrip($text,$striparray);
970 $text=$parser->unstripNoWiki($text,$striparray);
978 * Change an existing article. Puts the previous version back into the old table, updates RC
979 * and all necessary caches, mostly via the deferred update array.
981 * It is possible to call this function from a command-line script, but note that you should
982 * first set $wgUser, and clean up $wgDeferredUpdates after each edit.
984 function updateArticle( $text, $summary, $minor, $watchthis, $forceBot = false, $sectionanchor = '' ) {
985 global $wgOut, $wgUser;
986 global $wgDBtransactions, $wgMwRedir;
987 global $wgUseSquid, $wgInternalServer;
989 $fname = 'Article::updateArticle';
992 if ( $this->mMinorEdit
) { $me1 = 1; } else { $me1 = 0; }
993 if ( $minor && $wgUser->getID() ) { $me2 = 1; } else { $me2 = 0; }
994 if ( $this->isRedirect( $text ) ) {
995 # Remove all content but redirect
996 # This could be done by reconstructing the redirect from a title given by
997 # Title::newFromRedirect(), but then we wouldn't know which synonym the user
999 if ( preg_match( "/^((" . $wgMwRedir->getBaseRegex() . ')[^\\n]+)/i', $text, $m ) ) {
1001 $text = $m[1] . "\n";
1004 else { $redir = 0; }
1006 $text = $this->preSaveTransform( $text );
1007 $dbw =& wfGetDB( DB_MASTER
);
1009 # Update article, but only if changed.
1011 # It's important that we either rollback or complete, otherwise an attacker could
1012 # overwrite cur entries by sending precisely timed user aborts. Random bored users
1013 # could conceivably have the same effect, especially if cur is locked for long periods.
1014 if( $wgDBtransactions ) {
1015 $dbw->query( 'BEGIN', $fname );
1017 $userAbort = ignore_user_abort( true );
1020 $oldtext = $this->getContent( true );
1022 if ( 0 != strcmp( $text, $oldtext ) ) {
1023 $this->mCountAdjustment
= $this->isCountable( $text )
1024 - $this->isCountable( $oldtext );
1025 $now = wfTimestampNow();
1026 $won = wfInvertTimestamp( $now );
1028 $mungedText = $text;
1029 $flags = Article
::compressRevisionText( $newtext );
1031 $lastRevision = $dbw->selectField(
1032 'page', 'page_latest', array( 'page_id' => $this->getId() ) );
1034 # Record the text to the text table
1035 $old_id = $dbw->nextSequenceValue( 'text_old_id_val' );
1036 $dbw->insert( 'text',
1038 'old_id' => $old_id,
1039 'old_text' => $mungedText,
1040 'old_flags' => $flags,
1043 $revisionId = $dbw->insertId();
1045 # Record the edit in revisions
1046 $dbw->insert( 'revision',
1048 'rev_id' => $revisionId,
1049 'rev_page' => $this->getID(),
1050 'rev_comment' => $summary,
1051 'rev_minor_edit' => $me2,
1052 'rev_user' => $wgUser->getID(),
1053 'rev_user_text' => $wgUser->getName(),
1054 'rev_timestamp' => $dbw->timestamp( $now ),
1055 'inverse_timestamp' => $won
1060 $dbw->update( 'page',
1062 'page_latest' => $revisionId,
1063 'page_touched' => $dbw->timestamp( $now ),
1065 'page_is_redirect' => $redir,
1066 ), array( /* WHERE */
1067 'page_id' => $this->getID(),
1068 'page_latest' => $lastRevision, # Paranoia
1072 if( $dbw->affectedRows() == 0 ) {
1073 /* Belated edit conflict! Run away!! */
1076 # Update recentchanges and purge cache and whatnot
1077 $bot = (int)($wgUser->isBot() ||
$forceBot);
1078 RecentChange
::notifyEdit( $now, $this->mTitle
, $me2, $wgUser, $summary,
1079 $lastRevision, $this->getTimestamp(), $bot );
1080 Article
::onArticleEdit( $this->mTitle
);
1084 if( $wgDBtransactions ) {
1085 $dbw->query( 'COMMIT', $fname );
1087 ignore_user_abort( $userAbort );
1092 if (!$this->mTitle
->userIsWatching()) $this->watch();
1094 if ( $this->mTitle
->userIsWatching() ) {
1098 # standard deferred updates
1099 $this->editUpdates( $text, $summary, $minor, $now );
1103 # Template namespace
1104 # Purge all articles linking here
1105 if ( $this->mTitle
->getNamespace() == NS_TEMPLATE
) {
1106 $titles = $this->mTitle
->getLinksTo();
1107 Title
::touchArray( $titles );
1108 if ( $wgUseSquid ) {
1109 foreach ( $titles as $title ) {
1110 $urls[] = $title->getInternalURL();
1116 if ( $wgUseSquid ) {
1117 $urls = array_merge( $urls, $this->mTitle
->getSquidURLs() );
1118 $u = new SquidUpdate( $urls );
1122 $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $me2, $now, $summary, $revisionId );
1128 * After we've either updated or inserted the article, update
1129 * the link tables and redirect to the new page.
1131 function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
1132 global $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
1134 $wgLinkCache = new LinkCache();
1136 $wgLinkCache->forUpdate( true );
1138 # Get old version of link table to allow incremental link updates
1139 $wgLinkCache->preFill( $this->mTitle
);
1140 $wgLinkCache->clear();
1142 # Parse the text and replace links with placeholders
1143 $wgOut = new OutputPage();
1144 $wgOut->addWikiText( $text );
1146 # Look up the links in the DB and add them to the link cache
1147 $wgOut->transformBuffer( RLH_FOR_UPDATE
);
1149 if( $this->isRedirect( $text ) )
1153 $wgOut->redirect( $this->mTitle
->getFullURL( $r ).$sectionanchor );
1155 # this call would better fit into RecentChange::notifyEdit and RecentChange::notifyNew .
1156 # this will be improved later (to-do)
1158 include_once( "UserMailer.php" );
1159 $wgEnotif = new EmailNotification ();
1160 $wgEnotif->NotifyOnPageChange( $wgUser->getID(), $this->mTitle
->getDBkey(), $this->mTitle
->getNamespace(),$now, $summary, $me2, $oldid );
1165 * @todo document this function a bit more
1167 function validate () {
1168 global $wgOut, $wgUseValidation;
1169 if( $wgUseValidation ) {
1170 require_once ( 'SpecialValidate.php' ) ;
1171 $wgOut->setPagetitle( wfMsg( 'validate' ) . ': ' . $this->mTitle
->getPrefixedText() );
1172 $wgOut->setRobotpolicy( 'noindex,follow' );
1173 if( $this->mTitle
->getNamespace() != 0 ) {
1174 $wgOut->addHTML( wfMsg( 'val_validate_article_namespace_only' ) );
1177 $v = new Validation
;
1178 $v->validate_form( $this->mTitle
->getDBkey() );
1180 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
1185 * Mark this particular edit as patrolled
1187 function markpatrolled() {
1188 global $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgUseRCPatrol, $wgUser;
1189 $wgOut->setRobotpolicy( 'noindex,follow' );
1191 if ( !$wgUseRCPatrol )
1193 $wgOut->errorpage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1196 if ( $wgUser->getID() == 0 )
1198 $wgOut->loginToUse();
1201 if ( $wgOnlySysopsCanPatrol && !$wgUser->isAllowed('patrol') )
1203 $wgOut->sysopRequired();
1206 $rcid = $wgRequest->getVal( 'rcid' );
1207 if ( !is_null ( $rcid ) )
1209 RecentChange
::markPatrolled( $rcid );
1210 $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
1211 $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
1213 $rcTitle = Title
::makeTitle( NS_SPECIAL
, 'Recentchanges' );
1214 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
1218 $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1224 * Add this page to $wgUser's watchlist
1229 global $wgUser, $wgOut;
1231 if ( 0 == $wgUser->getID() ) {
1232 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1235 if ( wfReadOnly() ) {
1236 $wgOut->readOnlyPage();
1240 if (wfRunHooks('WatchArticle', $wgUser, $this)) {
1242 $wgUser->addWatch( $this->mTitle
);
1243 $wgUser->saveSettings();
1245 wfRunHooks('WatchArticleComplete', $wgUser, $this);
1247 $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
1248 $wgOut->setRobotpolicy( 'noindex,follow' );
1250 $link = $this->mTitle
->getPrefixedText();
1251 $text = wfMsg( 'addedwatchtext', $link );
1252 $wgOut->addWikiText( $text );
1255 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1259 * Stop watching a page
1262 function unwatch() {
1264 global $wgUser, $wgOut;
1266 if ( 0 == $wgUser->getID() ) {
1267 $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
1270 if ( wfReadOnly() ) {
1271 $wgOut->readOnlyPage();
1275 if (wfRunHooks('UnwatchArticle', $wgUser, $this)) {
1277 $wgUser->removeWatch( $this->mTitle
);
1278 $wgUser->saveSettings();
1280 wfRunHooks('UnwatchArticleComplete', $wgUser, $this);
1282 $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
1283 $wgOut->setRobotpolicy( 'noindex,follow' );
1285 $link = $this->mTitle
->getPrefixedText();
1286 $text = wfMsg( 'removedwatchtext', $link );
1287 $wgOut->addWikiText( $text );
1290 $wgOut->returnToMain( true, $this->mTitle
->getPrefixedText() );
1296 function protect( $limit = 'sysop' ) {
1297 global $wgUser, $wgOut, $wgRequest;
1299 if ( ! $wgUser->isAllowed('protect') ) {
1300 $wgOut->sysopRequired();
1303 if ( wfReadOnly() ) {
1304 $wgOut->readOnlyPage();
1307 $id = $this->mTitle
->getArticleID();
1309 $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
1313 $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
1314 $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
1315 $reason = $wgRequest->getText( 'wpReasonProtect' );
1318 $dbw =& wfGetDB( DB_MASTER
);
1319 $dbw->update( 'page',
1321 'page_touched' => $dbw->timestamp(),
1322 'page_restrictions' => (string)$limit
1323 ), array( /* WHERE */
1325 ), 'Article::protect'
1328 $restrictions = "move=" . $limit;
1330 $restrictions .= ":edit=" . $limit;
1332 if (wfRunHooks('ArticleProtect', $this, $wgUser, $limit == 'sysop', $reason, $moveonly)) {
1334 $dbw =& wfGetDB( DB_MASTER
);
1335 $dbw->update( 'cur',
1337 'cur_touched' => $dbw->timestamp(),
1338 'cur_restrictions' => $restrictions
1339 ), array( /* WHERE */
1341 ), 'Article::protect'
1344 wfRunHooks('ArticleProtectComplete', $this, $wgUser, $limit == 'sysop', $reason, $moveonly);
1346 $log = new LogPage( 'protect' );
1347 if ( $limit === '' ) {
1348 $log->addEntry( 'unprotect', $this->mTitle
, $reason );
1350 $log->addEntry( 'protect', $this->mTitle
, $reason );
1352 $wgOut->redirect( $this->mTitle
->getFullURL() );
1356 $reason = htmlspecialchars( wfMsg( 'protectreason' ) );
1357 return $this->confirmProtect( '', $reason, $limit );
1362 * Output protection confirmation dialog
1364 function confirmProtect( $par, $reason, $limit = 'sysop' ) {
1367 wfDebug( "Article::confirmProtect\n" );
1369 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1370 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1376 if ( $limit === '' ) {
1377 $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
1378 $wgOut->setSubtitle( wfMsg( 'unprotectsub', $sub ) );
1379 $wgOut->addWikiText( wfMsg( 'confirmunprotecttext' ) );
1380 $check = htmlspecialchars( wfMsg( 'confirmunprotect' ) );
1381 $protcom = htmlspecialchars( wfMsg( 'unprotectcomment' ) );
1382 $formaction = $this->mTitle
->escapeLocalURL( 'action=unprotect' . $par );
1384 $wgOut->setPageTitle( wfMsg( 'confirmprotect' ) );
1385 $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
1386 $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
1387 $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
1388 $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
1389 $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
1390 $formaction = $this->mTitle
->escapeLocalURL( 'action=protect' . $par );
1393 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1396 <form id='protectconfirm' method='post' action=\"{$formaction}\">
1400 <label for='wpReasonProtect'>{$protcom}:</label>
1403 <input type='text' size='60' name='wpReasonProtect' id='wpReasonProtect' value=\"" . htmlspecialchars( $reason ) . "\" />
1411 <input type='checkbox' name='wpConfirmProtect' value='1' id='wpConfirmProtect' />
1414 <label for='wpConfirmProtect'>{$check}</label>
1417 if($moveonly != '') {
1421 <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
1424 <label for='wpMoveOnly'>{$moveonly}</label>
1432 <input type='submit' name='wpConfirmProtectB' value=\"{$confirm}\" />
1438 $wgOut->returnToMain( false );
1442 * Unprotect the pages
1444 function unprotect() {
1445 return $this->protect( '' );
1449 * UI entry point for page deletion
1452 global $wgUser, $wgOut, $wgMessageCache, $wgRequest;
1453 $fname = 'Article::delete';
1454 $confirm = $wgRequest->getBool( 'wpConfirm' ) && $wgRequest->wasPosted();
1455 $reason = $wgRequest->getText( 'wpReason' );
1457 # This code desperately needs to be totally rewritten
1460 if ( ( ! $wgUser->isAllowed('delete') ) ) {
1461 $wgOut->sysopRequired();
1464 if ( wfReadOnly() ) {
1465 $wgOut->readOnlyPage();
1469 # Better double-check that it hasn't been deleted yet!
1470 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
1471 if ( ( '' == trim( $this->mTitle
->getText() ) )
1472 or ( $this->mTitle
->getArticleId() == 0 ) ) {
1473 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1478 $this->doDelete( $reason );
1482 # determine whether this page has earlier revisions
1483 # and insert a warning if it does
1484 # we select the text because it might be useful below
1485 $dbr =& $this->getDB();
1486 $ns = $this->mTitle
->getNamespace();
1487 $title = $this->mTitle
->getDBkey();
1488 $old = $dbr->selectRow( 'old',
1489 array( 'old_text', 'old_flags' ),
1491 'old_namespace' => $ns,
1492 'old_title' => $title,
1493 ), $fname, $this->getSelectOptions( array( 'ORDER BY' => 'inverse_timestamp' ) )
1496 if( $old !== false && !$confirm ) {
1497 $skin=$wgUser->getSkin();
1498 $wgOut->addHTML('<b>'.wfMsg('historywarning'));
1499 $wgOut->addHTML( $skin->historyLink() .'</b>');
1503 $s = $dbr->selectRow( 'cur',
1504 array( 'cur_text' ),
1506 'cur_namespace' => $ns,
1507 'cur_title' => $title,
1508 ), $fname, $this->getSelectOptions()
1511 if( $s !== false ) {
1512 # if this is a mini-text, we can paste part of it into the deletion reason
1514 #if this is empty, an earlier revision may contain "useful" text
1516 if($s->cur_text
!= '') {
1520 $text = Article
::getRevisionText( $old );
1526 $length=strlen($text);
1528 # this should not happen, since it is not possible to store an empty, new
1529 # page. Let's insert a standard text in case it does, though
1530 if($length == 0 && $reason === '') {
1531 $reason = wfMsg('exblank');
1534 if($length < 500 && $reason === '') {
1536 # comment field=255, let's grep the first 150 to have some user
1538 $text=substr($text,0,150);
1539 # let's strip out newlines and HTML tags
1540 $text=preg_replace('/\"/',"'",$text);
1541 $text=preg_replace('/\</','<',$text);
1542 $text=preg_replace('/\>/','>',$text);
1543 $text=preg_replace("/[\n\r]/",'',$text);
1545 $reason=wfMsg('excontent'). " '".$text;
1547 $reason=wfMsg('exbeforeblank') . " '".$text;
1549 if($length>150) { $reason .= '...'; } # we've only pasted part of the text
1554 return $this->confirmDelete( '', $reason );
1558 * Output deletion confirmation dialog
1560 function confirmDelete( $par, $reason ) {
1563 wfDebug( "Article::confirmDelete\n" );
1565 $sub = htmlspecialchars( $this->mTitle
->getPrefixedText() );
1566 $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
1567 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1568 $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
1570 $formaction = $this->mTitle
->escapeLocalURL( 'action=delete' . $par );
1572 $confirm = htmlspecialchars( wfMsg( 'confirm' ) );
1573 $check = htmlspecialchars( wfMsg( 'confirmcheck' ) );
1574 $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
1577 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
1581 <label for='wpReason'>{$delcom}:</label>
1584 <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
1592 <input type='checkbox' name='wpConfirm' value='1' id='wpConfirm' />
1595 <label for='wpConfirm'>{$check}</label>
1601 <input type='submit' name='wpConfirmB' value=\"{$confirm}\" />
1607 $wgOut->returnToMain( false );
1612 * Perform a deletion and output success or failure messages
1614 function doDelete( $reason ) {
1615 global $wgOut, $wgUser, $wgContLang;
1616 $fname = 'Article::doDelete';
1617 wfDebug( $fname."\n" );
1619 if (wfRunHooks('ArticleDelete', $this, $wgUser, $reason)) {
1620 if ( $this->doDeleteArticle( $reason ) ) {
1621 $deleted = $this->mTitle
->getPrefixedText();
1623 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1624 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1626 $sk = $wgUser->getSkin();
1627 $loglink = $sk->makeKnownLink( $wgContLang->getNsText( NS_PROJECT
) .
1628 ':' . wfMsgForContent( 'dellogpage' ),
1629 wfMsg( 'deletionlog' ) );
1631 $text = wfMsg( 'deletedtext', $deleted, $loglink );
1633 $wgOut->addHTML( '<p>' . $text . "</p>\n" );
1634 $wgOut->returnToMain( false );
1635 wfRunHooks('ArticleDeleteComplete', $this, $wgUser, $reason);
1637 $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
1643 * Back-end article deletion
1644 * Deletes the article with database consistency, writes logs, purges caches
1647 function doDeleteArticle( $reason ) {
1649 global $wgUseSquid, $wgDeferredUpdateList, $wgInternalServer;
1651 $fname = 'Article::doDeleteArticle';
1652 wfDebug( $fname."\n" );
1654 $dbw =& wfGetDB( DB_MASTER
);
1655 $ns = $this->mTitle
->getNamespace();
1656 $t = $this->mTitle
->getDBkey();
1657 $id = $this->mTitle
->getArticleID();
1659 if ( $t == '' ||
$id == 0 ) {
1663 $u = new SiteStatsUpdate( 0, 1, -$this->isCountable( $this->getContent( true ) ) );
1664 array_push( $wgDeferredUpdateList, $u );
1666 $linksTo = $this->mTitle
->getLinksTo();
1669 if ( $wgUseSquid ) {
1671 $this->mTitle
->getInternalURL(),
1672 $this->mTitle
->getInternalURL( 'history' )
1674 foreach ( $linksTo as $linkTo ) {
1675 $urls[] = $linkTo->getInternalURL();
1678 $u = new SquidUpdate( $urls );
1679 array_push( $wgDeferredUpdateList, $u );
1683 # Client and file cache invalidation
1684 Title
::touchArray( $linksTo );
1686 # Move article and history to the "archive" table
1687 $archiveTable = $dbw->tableName( 'archive' );
1688 $oldTable = $dbw->tableName( 'old' );
1689 $curTable = $dbw->tableName( 'cur' );
1690 $recentchangesTable = $dbw->tableName( 'recentchanges' );
1691 $linksTable = $dbw->tableName( 'links' );
1692 $brokenlinksTable = $dbw->tableName( 'brokenlinks' );
1694 $dbw->insertSelect( 'archive', 'cur',
1696 'ar_namespace' => 'cur_namespace',
1697 'ar_title' => 'cur_title',
1698 'ar_text' => 'cur_text',
1699 'ar_comment' => 'cur_comment',
1700 'ar_user' => 'cur_user',
1701 'ar_user_text' => 'cur_user_text',
1702 'ar_timestamp' => 'cur_timestamp',
1703 'ar_minor_edit' => 'cur_minor_edit',
1706 'cur_namespace' => $ns,
1711 $dbw->insertSelect( 'archive', 'old',
1713 'ar_namespace' => 'old_namespace',
1714 'ar_title' => 'old_title',
1715 'ar_text' => 'old_text',
1716 'ar_comment' => 'old_comment',
1717 'ar_user' => 'old_user',
1718 'ar_user_text' => 'old_user_text',
1719 'ar_timestamp' => 'old_timestamp',
1720 'ar_minor_edit' => 'old_minor_edit',
1721 'ar_flags' => 'old_flags'
1723 'old_namespace' => $ns,
1728 # Now that it's safely backed up, delete it
1730 $dbw->delete( 'cur', array( 'cur_namespace' => $ns, 'cur_title' => $t ), $fname );
1731 $dbw->delete( 'old', array( 'old_namespace' => $ns, 'old_title' => $t ), $fname );
1732 $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname );
1734 # Finally, clean up the link tables
1735 $t = $this->mTitle
->getPrefixedDBkey();
1737 Article
::onArticleDelete( $this->mTitle
);
1739 # Insert broken links
1740 $brokenLinks = array();
1741 foreach ( $linksTo as $titleObj ) {
1742 # Get article ID. Efficient because it was loaded into the cache by getLinksTo().
1743 $linkID = $titleObj->getArticleID();
1744 $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t );
1746 $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' );
1749 $dbw->delete( 'links', array( 'l_to' => $id ) );
1750 $dbw->delete( 'links', array( 'l_from' => $id ) );
1751 $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
1752 $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) );
1753 $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
1756 $log = new LogPage( 'delete' );
1757 $log->addEntry( 'delete', $this->mTitle
, $reason );
1759 # Clear the cached article id so the interface doesn't act like we exist
1760 $this->mTitle
->resetArticleID( 0 );
1761 $this->mTitle
->mArticleID
= 0;
1766 * Revert a modification
1768 function rollback() {
1769 global $wgUser, $wgOut, $wgRequest;
1770 $fname = 'Article::rollback';
1772 if ( ! $wgUser->isAllowed('rollback') ) {
1773 $wgOut->sysopRequired();
1776 if ( wfReadOnly() ) {
1777 $wgOut->readOnlyPage( $this->getContent( true ) );
1780 $dbw =& wfGetDB( DB_MASTER
);
1782 # Enhanced rollback, marks edits rc_bot=1
1783 $bot = $wgRequest->getBool( 'bot' );
1785 # Replace all this user's current edits with the next one down
1786 $tt = $this->mTitle
->getDBKey();
1787 $n = $this->mTitle
->getNamespace();
1789 # Get the last editor, lock table exclusively
1790 $s = $dbw->selectRow( 'cur',
1791 array( 'cur_id','cur_user','cur_user_text','cur_comment' ),
1792 array( 'cur_title' => $tt, 'cur_namespace' => $n ),
1793 $fname, 'FOR UPDATE'
1795 if( $s === false ) {
1797 $wgOut->addHTML( wfMsg( 'notanarticle' ) );
1800 $ut = $dbw->strencode( $s->cur_user_text
);
1801 $uid = $s->cur_user
;
1804 $from = str_replace( '_', ' ', $wgRequest->getVal( 'from' ) );
1805 if( $from != $s->cur_user_text
) {
1806 $wgOut->setPageTitle(wfmsg('rollbackfailed'));
1807 $wgOut->addWikiText( wfMsg( 'alreadyrolled',
1808 htmlspecialchars( $this->mTitle
->getPrefixedText()),
1809 htmlspecialchars( $from ),
1810 htmlspecialchars( $s->cur_user_text
) ) );
1811 if($s->cur_comment
!= '') {
1813 wfMsg('editcomment',
1814 htmlspecialchars( $s->cur_comment
) ) );
1819 # Get the last edit not by this guy
1820 $s = $dbw->selectRow( 'old',
1821 array( 'old_text','old_user','old_user_text','old_timestamp','old_flags' ),
1823 'old_namespace' => $n,
1825 "old_user <> {$uid} OR old_user_text <> '{$ut}'"
1826 ), $fname, array( 'FOR UPDATE', 'USE INDEX' => 'name_title_timestamp' )
1828 if( $s === false ) {
1830 $wgOut->setPageTitle(wfMsg('rollbackfailed'));
1831 $wgOut->addHTML( wfMsg( 'cantrollback' ) );
1836 # Mark all reverted edits as bot
1837 $dbw->update( 'recentchanges',
1840 ), array( /* WHERE */
1842 "rc_timestamp > '{$s->old_timestamp}'",
1848 $newcomment = wfMsg( 'revertpage', $s->old_user_text
, $from );
1849 $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
1850 $wgOut->setRobotpolicy( 'noindex,nofollow' );
1851 $wgOut->addHTML( '<h2>' . htmlspecialchars( $newcomment ) . "</h2>\n<hr />\n" );
1852 $this->updateArticle( Article
::getRevisionText( $s ), $newcomment, 1, $this->mTitle
->userIsWatching(), $bot );
1853 Article
::onArticleEdit( $this->mTitle
);
1854 $wgOut->returnToMain( false );
1859 * Do standard deferred updates after page view
1862 function viewUpdates() {
1863 global $wgDeferredUpdateList;
1865 if ( 0 != $this->getID() ) {
1866 global $wgDisableCounters;
1867 if( !$wgDisableCounters ) {
1868 Article
::incViewCount( $this->getID() );
1869 $u = new SiteStatsUpdate( 1, 0, 0 );
1870 array_push( $wgDeferredUpdateList, $u );
1874 # Update newtalk status if user is reading their own
1878 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
1879 $this->mTitle
->getText() == $wgUser->getName()) {
1880 require_once( 'UserTalkUpdate.php' );
1881 $u = new UserTalkUpdate( 0, $this->mTitle
->getNamespace(), $this->mTitle
->getDBkey(), false, false, false );
1886 * Do standard deferred updates after page edit.
1887 * Every 1000th edit, prune the recent changes table.
1889 * @param string $text
1891 function editUpdates( $text, $summary, $minoredit, $timestamp_of_pagechange) {
1892 global $wgDeferredUpdateList, $wgDBname, $wgMemc;
1893 global $wgMessageCache, $wgUser;
1896 if ( 0 == mt_rand( 0, 999 ) ) {
1897 $dbw =& wfGetDB( DB_MASTER
);
1898 $cutoff = $dbw->timestamp( time() - ( 7 * 86400 ) );
1899 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$cutoff}'";
1900 $dbw->query( $sql );
1902 $id = $this->getID();
1903 $title = $this->mTitle
->getPrefixedDBkey();
1904 $shortTitle = $this->mTitle
->getDBkey();
1906 $adj = $this->mCountAdjustment
;
1909 $u = new LinksUpdate( $id, $title );
1910 array_push( $wgDeferredUpdateList, $u );
1911 $u = new SiteStatsUpdate( 0, 1, $adj );
1912 array_push( $wgDeferredUpdateList, $u );
1913 $u = new SearchUpdate( $id, $title, $text );
1914 array_push( $wgDeferredUpdateList, $u );
1916 # If this is another user's talk page,
1917 # create a watchlist entry for this page
1919 if ($this->mTitle
->getNamespace() == NS_USER_TALK
&&
1920 $shortTitle != $wgUser->getName()) {
1921 require_once( 'UserTalkUpdate.php' );
1922 $u = new UserTalkUpdate( 1, $this->mTitle
->getNamespace(), $shortTitle, $summary, $minoredit, $timestamp_of_pagechange);
1925 if ( $this->mTitle
->getNamespace() == NS_MEDIAWIKI
) {
1926 $wgMessageCache->replace( $shortTitle, $text );
1932 * @todo document this function
1934 * @param string $oldid Revision ID of this article revision
1936 function setOldSubtitle( $oldid=0 ) {
1937 global $wgLang, $wgOut, $wgUser;
1939 $td = $wgLang->timeanddate( $this->mTimestamp
, true );
1940 $sk = $wgUser->getSkin();
1941 $lnk = $sk->makeKnownLinkObj ( $this->mTitle
, wfMsg( 'currentrevisionlink' ) );
1942 $prevlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'previousrevision' ), 'direction=prev&oldid='.$oldid );
1943 $nextlink = $sk->makeKnownLinkObj( $this->mTitle
, wfMsg( 'nextrevision' ), 'direction=next&oldid='.$oldid );
1944 $r = wfMsg( 'revisionasofwithlink', $td, $lnk, $prevlink, $nextlink );
1945 $wgOut->setSubtitle( $r );
1949 * This function is called right before saving the wikitext,
1950 * so we can do things like signatures and links-in-context.
1952 * @param string $text
1954 function preSaveTransform( $text ) {
1955 global $wgParser, $wgUser;
1956 return $wgParser->preSaveTransform( $text, $this->mTitle
, $wgUser, ParserOptions
::newFromUser( $wgUser ) );
1959 /* Caching functions */
1962 * checkLastModified returns true if it has taken care of all
1963 * output to the client that is necessary for this request.
1964 * (that is, it has sent a cached version of the page)
1966 function tryFileCache() {
1967 static $called = false;
1969 wfDebug( " tryFileCache() -- called twice!?\n" );
1973 if($this->isFileCacheable()) {
1974 $touched = $this->mTouched
;
1975 $cache = new CacheManager( $this->mTitle
);
1976 if($cache->isFileCacheGood( $touched )) {
1978 wfDebug( " tryFileCache() - about to load\n" );
1979 $cache->loadFromFileCache();
1982 wfDebug( " tryFileCache() - starting buffer\n" );
1983 ob_start( array(&$cache, 'saveToFileCache' ) );
1986 wfDebug( " tryFileCache() - not cacheable\n" );
1991 * Check if the page can be cached
1994 function isFileCacheable() {
1995 global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
1996 extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
1998 return $wgUseFileCache
1999 and (!$wgShowIPinHeader)
2000 and ($this->getID() != 0)
2001 and ($wgUser->getId() == 0)
2002 and (!$wgUser->getNewtalk())
2003 and ($this->mTitle
->getNamespace() != NS_SPECIAL
)
2004 and (empty( $action ) ||
$action == 'view')
2005 and (!isset($oldid))
2007 and (!isset($redirect))
2008 and (!isset($printable))
2009 and (!$this->mRedirectedFrom
);
2013 * Loads cur_touched and returns a value indicating if it should be used
2016 function checkTouched() {
2017 $fname = 'Article::checkTouched';
2018 $id = $this->getID();
2019 $dbr =& $this->getDB();
2020 $s = $dbr->selectRow( 'page', array( 'page_touched', 'page_is_redirect' ),
2021 array( 'page_id' => $id ), $fname, $this->getSelectOptions() );
2022 if( $s !== false ) {
2023 $this->mTouched
= wfTimestamp( TS_MW
, $s->page_touched
);
2024 return !$s->page_is_redirect
;
2031 * Edit an article without doing all that other stuff
2033 * @param string $text text submitted
2034 * @param string $comment comment submitted
2035 * @param integer $minor whereas it's a minor modification
2037 function quickEdit( $text, $comment = '', $minor = 0 ) {
2039 $fname = 'Article::quickEdit';
2041 #wfDebugDieBacktrace( "$fname called." );
2043 wfProfileIn( $fname );
2045 $dbw =& wfGetDB( DB_MASTER
);
2046 $ns = $this->mTitle
->getNamespace();
2047 $dbkey = $this->mTitle
->getDBkey();
2048 $encDbKey = $dbw->strencode( $dbkey );
2049 $timestamp = wfTimestampNow();
2051 $dbw->insert( 'text', array(
2052 'old_text' => $text,
2053 'old_flags' => "" ), $fname );
2054 $text_id = $dbw->insertID();
2057 $dbw->update( 'page', array(
2059 'page_touched' => $timestamp,
2060 'page_is_redirect' => $this->isRedirect( $text ) ?
1 : 0,
2061 'page_latest' => $text_id ),
2062 array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
2064 $page_id = $dbw->selectField( 'page', 'page_id', array( 'page_namespace' => $ns, 'page_title' => $dbkey ), $fname );
2067 $dbw->insert( 'revision', array(
2068 'rev_id' => $text_id,
2069 'rev_page' => $page_id,
2070 'rev_comment' => $comment,
2071 'rev_user' => $wgUser->getID(),
2072 'rev_user_text' => $wgUser->getName(),
2073 'rev_timestamp' => $timestamp,
2074 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
2075 'rev_minor_edit' => intval($minor) ),
2079 $dbw->insertSelect( 'old', 'cur',
2081 'old_namespace' => 'cur_namespace',
2082 'old_title' => 'cur_title',
2083 'old_text' => 'cur_text',
2084 'old_comment' => 'cur_comment',
2085 'old_user' => 'cur_user',
2086 'old_user_text' => 'cur_user_text',
2087 'old_timestamp' => 'cur_timestamp',
2088 'inverse_timestamp' => '99999999999999-cur_timestamp',
2090 'cur_namespace' => $ns,
2091 'cur_title' => $dbkey,
2095 # Use the affected row count to determine if the article is new
2096 $numRows = $dbw->affectedRows();
2098 # Make an array of fields to be inserted
2100 'cur_text' => $text,
2101 'cur_timestamp' => $timestamp,
2102 'cur_user' => $wgUser->getID(),
2103 'cur_user_text' => $wgUser->getName(),
2104 'inverse_timestamp' => wfInvertTimestamp( $timestamp ),
2105 'cur_comment' => $comment,
2106 'cur_is_redirect' => $this->isRedirect( $text ) ? 1 : 0,
2107 'cur_minor_edit' => intval($minor),
2108 'cur_touched' => $dbw->timestamp($timestamp),
2113 $fields['cur_is_new'] = 0;
2114 $dbw->update( 'cur', $fields, array( 'cur_namespace' => $ns, 'cur_title' => $dbkey ), $fname );
2116 # Insert new article
2117 $fields['cur_is_new'] = 1;
2118 $fields['cur_namespace'] = $ns;
2119 $fields['cur_title'] = $dbkey;
2120 $fields['cur_random'] = $rand = wfRandom();
2121 $dbw->insert( 'cur', $fields, $fname );
2124 wfProfileOut( $fname );
2128 * Used to increment the view counter
2131 * @param integer $id article id
2133 function incViewCount( $id ) {
2134 $id = intval( $id );
2135 global $wgHitcounterUpdateFreq;
2137 $dbw =& wfGetDB( DB_MASTER
);
2138 $pageTable = $dbw->tableName( 'page' );
2139 $hitcounterTable = $dbw->tableName( 'hitcounter' );
2140 $acchitsTable = $dbw->tableName( 'acchits' );
2142 if( $wgHitcounterUpdateFreq <= 1 ){ //
2143 $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
2147 # Not important enough to warrant an error page in case of failure
2148 $oldignore = $dbw->ignoreErrors( true );
2150 $dbw->query( "INSERT INTO $hitcounterTable (hc_id) VALUES ({$id})" );
2152 $checkfreq = intval( $wgHitcounterUpdateFreq/25 +
1 );
2153 if( (rand() %
$checkfreq != 0) or ($dbw->lastErrno() != 0) ){
2154 # Most of the time (or on SQL errors), skip row count check
2155 $dbw->ignoreErrors( $oldignore );
2159 $res = $dbw->query("SELECT COUNT(*) as n FROM $hitcounterTable");
2160 $row = $dbw->fetchObject( $res );
2161 $rown = intval( $row->n
);
2162 if( $rown >= $wgHitcounterUpdateFreq ){
2163 wfProfileIn( 'Article::incViewCount-collect' );
2164 $old_user_abort = ignore_user_abort( true );
2166 $dbw->query("LOCK TABLES $hitcounterTable WRITE");
2167 $dbw->query("CREATE TEMPORARY TABLE $acchitsTable TYPE=HEAP ".
2168 "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
2170 $dbw->query("DELETE FROM $hitcounterTable");
2171 $dbw->query('UNLOCK TABLES');
2172 $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ".
2173 'WHERE cur_id = hc_id');
2174 $dbw->query("DROP TABLE $acchitsTable");
2176 ignore_user_abort( $old_user_abort );
2177 wfProfileOut( 'Article::incViewCount-collect' );
2179 $dbw->ignoreErrors( $oldignore );
2183 * The onArticle*() functions are supposed to be a kind of hooks
2184 * which should be called whenever any of the specified actions
2187 * This is a good place to put code to clear caches, for instance.
2189 * This is called on page move and undelete, as well as edit
2191 * @param $title_obj a title object
2194 function onArticleCreate($title_obj) {
2195 global $wgUseSquid, $wgDeferredUpdateList;
2197 $titles = $title_obj->getBrokenLinksTo();
2200 if ( $wgUseSquid ) {
2201 $urls = $title_obj->getSquidURLs();
2202 foreach ( $titles as $linkTitle ) {
2203 $urls[] = $linkTitle->getInternalURL();
2205 $u = new SquidUpdate( $urls );
2206 array_push( $wgDeferredUpdateList, $u );
2209 # Clear persistent link cache
2210 LinkCache
::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() );
2213 function onArticleDelete($title_obj) {
2214 LinkCache
::linksccClearLinksTo( $title_obj->getArticleID() );
2216 function onArticleEdit($title_obj) {
2217 LinkCache
::linksccClearPage( $title_obj->getArticleID() );
2222 * Info about this page
2225 global $wgUser, $wgTitle, $wgOut, $wgAllowPageInfo;
2226 $fname = 'Article::info';
2228 if ( !$wgAllowPageInfo ) {
2229 $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
2233 $dbr =& $this->getDB();
2235 $basenamespace = $wgTitle->getNamespace() & (~
1);
2236 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace );
2237 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace );
2238 $wl_clause = array( 'wl_title' => $wgTitle->getDBkey(), 'wl_namespace' => $basenamespace );
2239 $fullTitle = $wgTitle->makeName($basenamespace, $wgTitle->getDBKey());
2240 $wgOut->setPagetitle( $fullTitle );
2241 $wgOut->setSubtitle( wfMsg( 'infosubtitle' ));
2243 # first, see if the page exists at all.
2244 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
2246 $wgOut->addHTML( wfMsg('noarticletext') );
2248 $numwatchers = $dbr->selectField( 'watchlist', 'COUNT(*)', $wl_clause, $fname,
2249 $this->getSelectOptions() );
2250 $wgOut->addHTML( "<ul><li>" . wfMsg("numwatchers", $numwatchers) . '</li>' );
2251 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
2252 $wgOut->addHTML( "<li>" . wfMsg('numedits', $old +
1) . '</li>');
2254 # to find number of distinct authors, we need to do some
2255 # funny stuff because of the cur/old table split:
2256 # - first, find the name of the 'cur' author
2257 # - then, find the number of *other* authors in 'old'
2260 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname,
2261 $this->getSelectOptions() );
2263 # find number of 'old' authors excluding 'cur' author
2264 $authors = $dbr->selectField( 'old', 'COUNT(DISTINCT old_user_text)',
2265 $old_clause +
array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ), $fname,
2266 $this->getSelectOptions() ) +
1;
2268 # now for the Talk page ...
2269 $cur_clause = array( 'cur_title' => $wgTitle->getDBkey(), 'cur_namespace' => $basenamespace+
1 );
2270 $old_clause = array( 'old_title' => $wgTitle->getDBkey(), 'old_namespace' => $basenamespace+
1 );
2273 $exists = $dbr->selectField( 'cur', 'COUNT(*)', $cur_clause, $fname, $this->getSelectOptions() );
2277 $old = $dbr->selectField( 'old', 'COUNT(*)', $old_clause, $fname, $this->getSelectOptions() );
2278 $wgOut->addHTML( '<li>' . wfMsg("numtalkedits", $old +
1) . '</li>');
2280 $wgOut->addHTML( '<li>' . wfMsg("numauthors", $authors) . '</li>' );
2284 $cur_author = $dbr->selectField( 'cur', 'cur_user_text', $cur_clause, $fname,
2285 $this->getSelectOptions() );
2286 $authors = $dbr->selectField( 'cur', 'COUNT(DISTINCT old_user_text)',
2287 $old_clause +
array( 'old_user_text<>' . $dbr->addQuotes( $cur_author ) ),
2288 $fname, $this->getSelectOptions() );
2290 $wgOut->addHTML( '<li>' . wfMsg('numtalkauthors', $authors) . '</li></ul>' );
2297 * Check whether an article is a stub
2300 * @param integer $articleID ID of the article that is to be checked
2302 function wfArticleIsStub( $articleID ) {
2304 $fname = 'wfArticleIsStub';
2306 $threshold = $wgUser->getOption('stubthreshold') ;
2307 if ( $threshold > 0 ) {
2308 $dbr =& wfGetDB( DB_SLAVE
);
2309 $s = $dbr->selectRow( array('page', 'text'),
2310 array( 'LENGTH(old_text) AS len', 'page_namespace', 'page_is_redirect' ),
2311 array( 'page_id' => $articleID, "page.page_latest=text.old_id" ),
2313 if ( $s == false OR $s->page_is_redirect
OR $s->page_namespace
!= 0 ) {
2317 return ( $size < $threshold );