* (bug 8437) Make Title::loadRestrictions() initialise $mRestrictions properly
[lhc/web/wiklou.git] / includes / Article.php
index d85a24b..e17aad7 100644 (file)
@@ -691,6 +691,12 @@ class Article {
                                $redir = $sk->makeKnownLinkObj( $this->mRedirectedFrom, '', 'redirect=no' );
                                $s = wfMsg( 'redirectedfrom', $redir );
                                $wgOut->setSubtitle( $s );
+
+                               // Set the fragment if one was specified in the redirect
+                               if ( strval( $this->mTitle->getFragment() ) != '' ) {
+                                       $fragment = Xml::escapeJsString( $this->mTitle->getFragmentForURL() );
+                                       $wgOut->addInlineScript( "redirectToFragment(\"$fragment\");" );
+                               }
                                $wasRedirected = true;
                        }
                } elseif ( !empty( $rdfrom ) ) {
@@ -778,9 +784,9 @@ class Article {
                                if( !$wasRedirected && $this->isCurrent() ) {
                                        $wgOut->setSubtitle( wfMsgHtml( 'redirectpagesub' ) );
                                }
-                               $link = $sk->makeLinkObj( $rt );
+                               $link = $sk->makeLinkObj( $rt, $rt->getFullText() );
 
-                               $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT" />' .
+                               $wgOut->addHTML( '<img src="'.$imageUrl.'" alt="#REDIRECT " />' .
                                  '<span class="redirectText">'.$link.'</span>' );
 
                                $parseout = $wgParser->parse($text, $this->mTitle, ParserOptions::newFromUser($wgUser));
@@ -1128,13 +1134,18 @@ class Article {
                        }
                        $oldtext = $rev->getText();
 
-                       if($section=='new') {
-                               if($summary) $subject="== {$summary} ==\n\n";
-                               $text=$oldtext."\n\n".$subject.$text;
+                       if( $section == 'new' ) {
+                               # Inserting a new section
+                               $subject = $summary ? "== {$summary} ==\n\n" : '';
+                               $text = strlen( trim( $oldtext ) ) > 0
+                                               ? "{$oldtext}\n\n{$subject}{$text}"
+                                               : "{$subject}{$text}";
                        } else {
+                               # Replacing an existing section; roll out the big guns
                                global $wgParser;
                                $text = $wgParser->replaceSection( $oldtext, $section, $text );
                        }
+
                }
 
                wfProfileOut( __METHOD__ );
@@ -1267,13 +1278,13 @@ class Article {
 
                $oldtext = $this->getContent();
                $oldsize = strlen( $oldtext );
-               $newsize = strlen( $text );
 
                # Provide autosummaries if one is not provided.
                if ($flags & EDIT_AUTOSUMMARY && $summary == '')
                        $summary = $this->getAutosummary( $oldtext, $text, $flags );
 
                $text = $this->preSaveTransform( $text );
+               $newsize = strlen( $text );
 
                $dbw =& wfGetDB( DB_MASTER );
                $now = wfTimestampNow();
@@ -1328,11 +1339,12 @@ class Article {
                                                        $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
                                                        $revisionId );
                                                        
-                                               # Mark as patrolled if the user can do so and has it set in their options
-                                               if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
+                                               # Mark as patrolled if the user can do so
+                                               if( $wgUser->isAllowed( 'autopatrol' ) ) {
                                                        RecentChange::markPatrolled( $rcid );
                                                }
                                        }
+                                       $wgUser->incEditCount();
                                        $dbw->commit();
                                }
                        } else {
@@ -1388,11 +1400,12 @@ class Article {
                        if( !( $flags & EDIT_SUPPRESS_RC ) ) {
                                $rcid = RecentChange::notifyNew( $now, $this->mTitle, $isminor, $wgUser, $summary, $bot,
                                  '', strlen( $text ), $revisionId );
-                               # Mark as patrolled if the user can and has the option set
-                               if( $wgUser->isAllowed( 'patrol' ) && $wgUser->getOption( 'autopatrol' ) ) {
+                               # Mark as patrolled if the user can
+                               if( $wgUser->isAllowed( 'autopatrol' ) ) {
                                        RecentChange::markPatrolled( $rcid );
                                }
                        }
+                       $wgUser->incEditCount();
                        $dbw->commit();
 
                        # Update links, etc.
@@ -1448,7 +1461,7 @@ class Article {
         */
        function markpatrolled() {
                global $wgOut, $wgRequest, $wgUseRCPatrol, $wgUser;
-               $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->setRobotPolicy( 'noindex,nofollow' );
 
                # Check RC patrol config. option
                if( !$wgUseRCPatrol ) {
@@ -1462,20 +1475,45 @@ class Article {
                        return;
                }
                
+               # If we haven't been given an rc_id value, we can't do anything
                $rcid = $wgRequest->getVal( 'rcid' );
-               if ( !is_null ( $rcid ) ) {
-                       if( wfRunHooks( 'MarkPatrolled', array( &$rcid, &$wgUser, false ) ) ) {
-                               RecentChange::markPatrolled( $rcid );
-                               wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
-                               $wgOut->setPagetitle( wfMsg( 'markedaspatrolled' ) );
-                               $wgOut->addWikiText( wfMsg( 'markedaspatrolledtext' ) );
-                       }
-                       $rcTitle = SpecialPage::getTitleFor( 'Recentchanges' );
-                       $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
+               if( !$rcid ) {
+                       $wgOut->errorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+                       return;
                }
-               else {
-                       $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+               
+               # Handle the 'MarkPatrolled' hook
+               if( !wfRunHooks( 'MarkPatrolled', array( $rcid, &$wgUser, false ) ) ) {
+                       return;
+               }
+               
+               $return = SpecialPage::getTitleFor( 'Recentchanges' );
+               # If it's left up to us, check that the user is allowed to patrol this edit
+               # If the user has the "autopatrol" right, then we'll assume there are no
+               # other conditions stopping them doing so
+               if( !$wgUser->isAllowed( 'autopatrol' ) ) {
+                       $rc = RecentChange::newFromId( $rcid );
+                       # Graceful error handling, as we've done before here...
+                       # (If the recent change doesn't exist, then it doesn't matter whether
+                       # the user is allowed to patrol it or not; nothing is going to happen
+                       if( is_object( $rc ) && $wgUser->getName() == $rc->getAttribute( 'rc_user_text' ) ) {
+                               # The user made this edit, and can't patrol it
+                               # Tell them so, and then back off
+                               $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
+                               $wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrollederror-noautopatrol' ) );
+                               $wgOut->returnToMain( false, $return );
+                               return;
+                       }
                }
+               
+               # Mark the edit as patrolled
+               RecentChange::markPatrolled( $rcid );
+               wfRunHooks( 'MarkPatrolledComplete', array( &$rcid, &$wgUser, false ) );
+               
+               # Inform the user
+               $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
+               $wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrolledtext' ) );
+               $wgOut->returnToMain( false, $return );
        }
 
        /**
@@ -1717,6 +1755,11 @@ class Article {
 
                if( $confirm ) {
                        $this->doDelete( $reason );
+                       if( $wgRequest->getCheck( 'wpWatch' ) ) {
+                               $this->doWatch();
+                       } elseif( $this->mTitle->userIsWatching() ) {
+                               $this->doUnwatch();
+                       }
                        return;
                }
 
@@ -1856,6 +1899,7 @@ class Article {
                $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
                $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
                $token = htmlspecialchars( $wgUser->editToken() );
+               $watch = Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '2' ) );
 
                $wgOut->addHTML( "
 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
@@ -1865,13 +1909,17 @@ class Article {
                                <label for='wpReason'>{$delcom}:</label>
                        </td>
                        <td align='left'>
-                               <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" />
+                               <input type='text' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" tabindex=\"1\" />
                        </td>
                </tr>
+               <tr>
+                       <td>&nbsp;</td>
+                       <td>$watch</td>
+               </tr>
                <tr>
                        <td>&nbsp;</td>
                        <td>
-                               <input type='submit' name='wpConfirmB' id='wpConfirmB' value=\"{$confirm}\" />
+                               <input type='submit' name='wpConfirmB' id='wpConfirmB' value=\"{$confirm}\" tabindex=\"3\" />
                        </td>
                </tr>
        </table>
@@ -1952,6 +2000,8 @@ class Article {
                                'ar_minor_edit' => 'rev_minor_edit',
                                'ar_rev_id'     => 'rev_id',
                                'ar_text_id'    => 'rev_text_id',
+                               'ar_text'       => '\'\'', // Be explicit to appease
+                               'ar_flags'      => '\'\'', // MySQL's "strict mode"...
                        ), array(
                                'page_id' => $id,
                                'page_id = rev_page'
@@ -2330,7 +2380,11 @@ class Article {
         */
        function isFileCacheable() {
                global $wgUser, $wgUseFileCache, $wgShowIPinHeader, $wgRequest;
-               extract( $wgRequest->getValues( 'action', 'oldid', 'diff', 'redirect', 'printable' ) );
+               $action    = $wgRequest->getVal( 'action'    );
+               $oldid     = $wgRequest->getVal( 'oldid'     );
+               $diff      = $wgRequest->getVal( 'diff'      );
+               $redirect  = $wgRequest->getVal( 'redirect'  );
+               $printable = $wgRequest->getVal( 'printable' );
 
                return $wgUseFileCache
                        and (!$wgShowIPinHeader)
@@ -2420,7 +2474,7 @@ class Article {
                $hitcounterTable = $dbw->tableName( 'hitcounter' );
                $acchitsTable = $dbw->tableName( 'acchits' );
 
-               if( $wgHitcounterUpdateFreq <= 1 ){ //
+               if( $wgHitcounterUpdateFreq <= 1 ) {
                        $dbw->query( "UPDATE $pageTable SET page_counter = page_counter + 1 WHERE page_id = $id" );
                        return;
                }
@@ -2451,10 +2505,15 @@ class Article {
                                "SELECT hc_id,COUNT(*) AS hc_n FROM $hitcounterTable ".
                                'GROUP BY hc_id');
                        $dbw->query("DELETE FROM $hitcounterTable");
-                       if ($wgDBtype == 'mysql')
+                       if ($wgDBtype == 'mysql') {
                                $dbw->query('UNLOCK TABLES');
-                       $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
-                               'WHERE page_id = hc_id');
+                               $dbw->query("UPDATE $pageTable,$acchitsTable SET page_counter=page_counter + hc_n ".
+                                       'WHERE page_id = hc_id');
+                       }
+                       else {
+                               $dbw->query("UPDATE $pageTable SET page_counter=page_counter + hc_n ".
+                                       "FROM $acchitsTable WHERE page_id = hc_id");
+                       }
                        $dbw->query("DROP TABLE $acchitsTable");
 
                        ignore_user_abort( $old_user_abort );
@@ -2657,7 +2716,7 @@ class Article {
        public static function getRedirectAutosummary( $text ) {
                $rt = Title::newFromRedirect( $text );
                if( is_object( $rt ) )
-                       return wfMsgForContent( 'autoredircomment', $rt->getPrefixedText() );
+                       return wfMsgForContent( 'autoredircomment', $rt->getFullText() );
                else
                        return '';
        }
@@ -2695,30 +2754,28 @@ class Article {
                # This code is UGLY UGLY UGLY.
                # Somebody PLEASE come up with a more elegant way to do it.
 
-               $summary = '';
-
-               #Blanking autosummaries
-               if (!($flags & EDIT_NEW))
-                       $summary = self::getBlankingAutosummary( $oldtext, $newtext );
+               #Redirect autosummaries
+               $summary = self::getRedirectAutosummary( $newtext );
 
                if ($summary)
                        return $summary;
 
-               #New redirect autosummaries.
-               if ( $flags & EDIT_NEW ) {
-                       $summary = self::getRedirectAutosummary( $newtext );
-               }
+               #Blanking autosummaries
+               if (!($flags & EDIT_NEW))
+                       $summary = self::getBlankingAutosummary( $oldtext, $newtext );
 
                if ($summary)
                        return $summary;
 
                #New page autosummaries
-               if ($flags & EDIT_NEW && strlen($newtext) <= 500) {
-                       #If they're making a new short article, give its text in the summary.
+               if ($flags & EDIT_NEW && strlen($newtext)) {
+                       #If they're making a new article, give its text, truncated, in the summary.
                        global $wgContLang;
-                       $truncatedtext = $wgContLang->truncate( $newtext, max( 0, 200 - 
-                               strlen( wfMsgForContent( 'autosumm-shortnew') ) ), '...' );
-                       $summary = wfMsgForContent( 'autosumm-shortnew', $truncatedtext );
+                       $truncatedtext = $wgContLang->truncate(
+                               str_replace("\n", ' ', $newtext),
+                               max( 0, 200 - strlen( wfMsgForContent( 'autosumm-new') ) ),
+                               '...' );
+                       $summary = wfMsgForContent( 'autosumm-new', $truncatedtext );
                }
 
                if ($summary)