X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FArticle.php;h=b02b7679df96486cecdb640d4d78114fe87c8867;hb=7fb4f4d58efb99ed3427008a6cebf448423e9450;hp=9666c98030c17060dd89084921fda9a39a1e614b;hpb=a437d6e20529f3389921dd4c9faf628587af6e53;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Article.php b/includes/Article.php index 9666c98030..b02b7679df 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -80,7 +80,7 @@ class Article { * @return Return the text of this revision */ function getContent( $noredir ) { - global $wgRequest; + global $wgRequest, $wgUser; # Get variables from query string :P $action = $wgRequest->getText( 'action', 'view' ); @@ -100,7 +100,7 @@ class Article { $this->loadContent( $noredir ); # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page if ( $this->mTitle->getNamespace() == NS_USER_TALK && - preg_match('/^\d{1,3}\.\d{1,3}.\d{1,3}\.\d{1,3}$/',$this->mTitle->getText()) && + $wgUser->isIP($this->mTitle->getText()) && $action=='view' ) { wfProfileOut( $fname ); @@ -758,13 +758,19 @@ class Article { # If we have been passed an &rcid= parameter, we want to give the user a # chance to mark this new article as patrolled. - if ( $wgUseRCPatrol && !is_null ( $rcid ) && $rcid != 0 && $wgUser->isLoggedIn() && - ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) + if ( $wgUseRCPatrol + && !is_null($rcid) + && $rcid != 0 + && $wgUser->isLoggedIn() + && ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) ) { - $wgOut->addHTML( wfMsg ( 'markaspatrolledlink', - $sk->makeKnownLinkObj ( $this->mTitle, wfMsg ( 'markaspatrolledtext' ), - 'action=markpatrolled&rcid='.$rcid ) - ) ); + $wgOut->addHTML( + "' + ); } # Put link titles into the link cache @@ -957,6 +963,8 @@ class Article { /** * Fetch and uncompress the text for a given revision. * Can ask by rev_id number or timestamp (set $field) + * FIXME: This function is broken. Eliminate all uses and remove. + * Use Revision class in place. */ function fetchRevisionText( $revId = null, $field = 'rev_id' ) { $fname = 'Article::fetchRevisionText'; @@ -986,12 +994,15 @@ class Article { function getTextOfLastEditWithSectionReplacedOrAdded($section, $text, $summary = '', $edittime = NULL) { $fname = 'Article::getTextOfLastEditWithSectionReplacedOrAdded'; - if( is_null( $edittime ) ) { - $oldtext = $this->fetchRevisionText(); - } else { - $oldtext = $this->fetchRevisionText( $edittime, 'rev_timestamp' ); - } if ($section != '') { + if( is_null( $edittime ) ) { + $rev = Revision::newFromTitle( $this->mTitle ); + } else { + $dbw =& wfGetDB( DB_MASTER ); + $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime ); + } + $oldtext = $rev->getText(); + if($section=='new') { if($summary) $subject="== {$summary} ==\n\n"; $text=$oldtext."\n\n".$subject.$text; @@ -1196,7 +1207,12 @@ class Article { # Parse the text and replace links with placeholders $wgOut = new OutputPage(); - $wgOut->addWikiText( $text ); + + # Pass the current title along in case we're creating a wiki page + # which is different than the currently displayed one (e.g. image + # pages created on file uploads); otherwise, link updates will + # go wrong. + $wgOut->addWikiTextWithTitle( $text, $this->mTitle ); # Look up the links in the DB and add them to the link cache $wgOut->transformBuffer( RLH_FOR_UPDATE ); @@ -1212,7 +1228,7 @@ class Article { include_once( "UserMailer.php" ); $wgEnotif = new EmailNotification (); - $wgEnotif->NotifyOnPageChange( $wgUser->getID(), $this->mTitle->getDBkey(), $this->mTitle->getNamespace(),$now, $summary, $me2, $oldid ); + $wgEnotif->notifyOnPageChange( $this->mTitle, $now, $summary, $me2, $oldid ); } /** @@ -1273,6 +1289,8 @@ class Article { $v = new Validation ; if ( $wgRequest->getVal ( "mode" , "" ) == "list" ) $t = $v->showList ( $this ) ; + else if ( $wgRequest->getVal ( "mode" , "" ) == "details" ) + $t = $v->showDetails ( $this , $wgRequest->getVal( 'revision' ) ) ; else $t = $v->validatePageForm ( $this , $revision ) ; @@ -1536,7 +1554,7 @@ class Article { $ns = $this->mTitle->getNamespace(); $title = $this->mTitle->getDBkey(); $revisions = $dbr->select( array( 'page', 'revision' ), - array( 'rev_id' ), + array( 'rev_id', 'rev_user_text' ), array( 'page_namespace' => $ns, 'page_title' => $title, @@ -1551,28 +1569,32 @@ class Article { } # Fetch cur_text - $s = $dbr->selectRow( array( 'page', 'text' ), - array( 'old_text' ), - array( - 'page_namespace' => $ns, - 'page_title' => $title, - 'page_latest = old_id' - ), $fname, $this->getSelectOptions() - ); - - if( $s !== false ) { + $rev =& Revision::newFromTitle( $this->mTitle ); + + # Fetch name(s) of contributors + $rev_name = ''; + $all_same_user = true; + while ( $row = $dbr->fetchObject( $revisions ) ) { + if ( $rev_name != '' && $rev_name != $row->rev_user_text ) { + $all_same_user = false; + } else { + $rev_name = $row->rev_user_text; + } + } + + if( !is_null( $rev ) ) { # if this is a mini-text, we can paste part of it into the deletion reason + $text = $rev->getText(); #if this is empty, an earlier revision may contain "useful" text $blanked = false; - if($s->old_text != '') { - $text=$s->old_text; - } else { - if($old) { # TODO - $text = Revision::getRevisionText( $old ); + if($text == '') { + $prevId = $this->mTitle->getPreviousRevisionID( $rev->getId() ); + $rev = Revision::newFromId( $prevId ); + if ( $rev ) { + $text = $rev->getText(); $blanked = true; } - } $length=strlen($text); @@ -1593,13 +1615,18 @@ class Article { $text=preg_replace('/\/','>',$text); $text=preg_replace("/[\n\r]/",'',$text); + + if( $length > 150 ) { $text .= '...'; } # we've only pasted part of the text + if(!$blanked) { - $reason=wfMsg('excontent'). " '".$text; + if(!$all_same_user) { + $reason = wfMsg ( 'excontent', $text ); + } else { + $reason = wfMsg ( 'excontentauthor', $text, $rev_name ); + } } else { - $reason=wfMsg('exbeforeblank') . " '".$text; + $reason = wfMsg ( 'exbeforeblank', $text ); } - if($length>150) { $reason .= '...'; } # we've only pasted part of the text - $reason.="'"; } } @@ -1722,33 +1749,39 @@ class Article { # Client and file cache invalidation Title::touchArray( $linksTo ); - # Move article and history to the "archive" table - $dbw->insertSelect( 'archive', array( 'page','revision', 'text' ), + // For now, shunt the revision data into the archive table. + // Text is *not* removed from the text table; bulk storage + // is left intact to avoid breaking block-compression or + // immutable storage schemes. + // + // For backwards compatibility, note that some older archive + // table entries will have ar_text and ar_flags fields still. + // + // In the future, we may keep revisions and mark them with + // the rev_deleted field, which is reserved for this purpose. + $dbw->insertSelect( 'archive', array( 'page', 'revision' ), array( 'ar_namespace' => 'page_namespace', 'ar_title' => 'page_title', - 'ar_text' => 'old_text', 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', - 'ar_flags' => 'old_flags', 'ar_rev_id' => 'rev_id', + 'ar_text_id' => 'rev_text_id', ), array( - 'page_namespace' => $ns, - 'page_title' => $t, - 'page_id = rev_page AND old_id = rev_id' + 'page_id' => $id, + 'page_id = rev_page' ), $fname ); - + # Now that it's safely backed up, delete it - - $dbw->deleteJoin( 'text', 'revision', 'old_id', 'rev_id', array( "rev_page = {$id}" ), $fname ); $dbw->delete( 'revision', array( 'rev_page' => $id ), $fname ); $dbw->delete( 'page', array( 'page_id' => $id ), $fname); - + + # Clean up recentchanges entries... $dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), $fname ); # Finally, clean up the link tables @@ -1756,20 +1789,9 @@ class Article { Article::onArticleDelete( $this->mTitle ); - # Insert broken links - $brokenLinks = array(); - foreach ( $linksTo as $titleObj ) { - # Get article ID. Efficient because it was loaded into the cache by getLinksTo(). - $linkID = $titleObj->getArticleID(); - $brokenLinks[] = array( 'bl_from' => $linkID, 'bl_to' => $t ); - } - $dbw->insert( 'brokenlinks', $brokenLinks, $fname, 'IGNORE' ); - - # Delete live links - $dbw->delete( 'links', array( 'l_to' => $id ) ); - $dbw->delete( 'links', array( 'l_from' => $id ) ); + # Delete outgoing links + $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) ); $dbw->delete( 'imagelinks', array( 'il_from' => $id ) ); - $dbw->delete( 'brokenlinks', array( 'bl_from' => $id ) ); $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) ); # Log the deletion @@ -1909,7 +1931,8 @@ class Article { global $wgUser; if ($this->mTitle->getNamespace() == NS_USER_TALK && - $this->mTitle->getText() == $wgUser->getName()) { + $this->mTitle->getText() == $wgUser->getName()) + { require_once( 'UserTalkUpdate.php' ); $u = new UserTalkUpdate( 0, $this->mTitle->getNamespace(), $this->mTitle->getDBkey(), false, false, false ); } else { @@ -1943,7 +1966,6 @@ class Article { $shortTitle = $this->mTitle->getDBkey(); $adj = $this->mCountAdjustment; - if ( 0 != $id ) { $u = new LinksUpdate( $id, $title ); array_push( $wgDeferredUpdateList, $u ); @@ -2137,8 +2159,8 @@ class Article { 'GROUP BY hc_id'); $dbw->query("DELETE FROM $hitcounterTable"); $dbw->query('UNLOCK TABLES'); - $dbw->query("UPDATE $curTable,$acchitsTable SET cur_counter=cur_counter + hc_n ". - 'WHERE cur_id = hc_id'); + $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ". + 'WHERE page_id = hc_id'); $dbw->query("DROP TABLE $acchitsTable"); ignore_user_abort( $old_user_abort ); @@ -2162,7 +2184,8 @@ class Article { function onArticleCreate($title_obj) { global $wgUseSquid, $wgPostCommitUpdateList; - $titles = $title_obj->getBrokenLinksTo(); + $title_obj->touchLinks(); + $titles = $title_obj->getLinksTo(); # Purge squid if ( $wgUseSquid ) { @@ -2175,11 +2198,12 @@ class Article { } # Clear persistent link cache - LinkCache::linksccClearBrokenLinksTo( $title_obj->getPrefixedDBkey() ); + LinkCache::linksccClearLinksTo( $title_obj ); } function onArticleDelete($title_obj) { - LinkCache::linksccClearLinksTo( $title_obj->getArticleID() ); + $title_obj->touchLinks(); + LinkCache::linksccClearLinksTo( $title_obj ); } function onArticleEdit($title_obj) { LinkCache::linksccClearPage( $title_obj->getArticleID() ); @@ -2286,15 +2310,16 @@ class Article { $id = $this->mTitle->getArticleID(); $db =& wfGetDB( DB_SLAVE ); - $page = $db->tableName( 'page' ); - $links = $db->tableName( 'links' ); - $sql = "SELECT page_title ". - "FROM $page,$links WHERE l_to=page_id AND l_from={$id} and page_namespace=".NS_TEMPLATE; - $res = $db->query( $sql, "Article:getUsedTemplates" ); + $res = $db->select( array( 'pagelinks' ), + array( 'pl_title' ), + array( + 'pl_from' => $id, + 'pl_namespace' => NS_TEMPLATE ), + 'Article:getUsedTemplates' ); if ( false !== $res ) { if ( $db->numRows( $res ) ) { while ( $row = $db->fetchObject( $res ) ) { - $result[] = $row->page_title; + $result[] = $row->pl_title; } } }