Tell regexp parser to use extra analysis on external link regexp;
[lhc/web/wiklou.git] / includes / Article.php
index 0f18585..5437d46 100644 (file)
@@ -69,6 +69,9 @@ class Article {
          * @return string $text|false the text requested
        */
        function getRevisionText( $row, $prefix = 'old_' ) {
+               $fname = 'Article::getRevisionText';
+               wfProfileIn( $fname );
+               
                # Get data
                $textField = $prefix . 'text';
                $flagsField = $prefix . 'flags';
@@ -111,6 +114,7 @@ class Article {
                        global $wgInputEncoding, $wgContLang;
                        $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
                }
+               wfProfileOut( $fname );
                return $text;
        }
 
@@ -292,25 +296,21 @@ class Article {
        }
 
        /**
-        * Load the revision (including cur_text) into this object
-       */
-       function loadContent( $noredir = false ) {
-               global $wgOut, $wgRequest;
-
-               if ( $this->mContentLoaded ) return;
-               
-               $dbr =& $this->getDB();
-               # Query variables :P
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $redirect = $wgRequest->getVal( 'redirect' );
-
-               $fname = 'Article::loadContent';
+        * Return the oldid of the article that is to be shown.
+        * For requests with a "direction", this is not the oldid of the
+        * query
+        */
+       function getOldID() {
+               global $wgRequest, $wgOut;
+               static $lastid;
 
-               # Pre-fill content with error message so that if something
-               # fails we'll have something telling us what we intended.
+               if ( isset( $lastid ) ) {
+                       return $lastid;
+               }
 
-               $t = $this->mTitle->getPrefixedText();
+               $oldid = $wgRequest->getVal( 'oldid' );
                if ( isset( $oldid ) ) {
+                       $dbr =& $this->getDB();
                        $oldid = IntVal( $oldid );
                        if ( $wgRequest->getVal( 'direction' ) == 'next' ) {
                                $nextid = $this->mTitle->getNextRevisionID( $oldid );
@@ -327,7 +327,32 @@ class Article {
                                        # TODO
                                }
                        }
+                       $lastid = $oldid;
                }
+               return @$oldid; # "@" to be able to return "unset" without PHP complaining
+       }
+
+
+       /**
+        * Load the revision (including cur_text) into this object
+       */
+       function loadContent( $noredir = false ) {
+               global $wgOut, $wgRequest;
+
+               if ( $this->mContentLoaded ) return;
+               
+               $dbr =& $this->getDB();
+               # Query variables :P
+               $oldid = $this->getOldID();
+               $redirect = $wgRequest->getVal( 'redirect' );
+
+               $fname = 'Article::loadContent';
+
+               # Pre-fill content with error message so that if something
+               # fails we'll have something telling us what we intended.
+
+               $t = $this->mTitle->getPrefixedText();
+
                if ( isset( $oldid ) ) {
                        $t .= ',oldid='.$oldid;
                }
@@ -386,8 +411,7 @@ class Article {
                        $this->mCounter = $s->cur_counter;
                        $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
                        $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
-                       $this->mTitle->mRestrictionsLoaded = true;
+                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
                } else { # oldid set, retrieve historical version
                        $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
                                $fname, $this->getSelectOptions() );
@@ -465,8 +489,7 @@ class Article {
                        $this->mCounter = $s->cur_counter;
                        $this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
                        $this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
-                       $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
-                       $this->mTitle->mRestrictionsLoaded = true;
+                       $this->mTitle->loadRestrictions( $s->cur_restrictions );
                } else { # oldid set, retrieve historical version
                        $s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
                                $fname, $this->getSelectOptions() );
@@ -658,14 +681,14 @@ class Article {
         * the given title.
        */
        function view() {
-               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol;
+               global $wgUser, $wgOut, $wgRequest, $wgOnlySysopsCanPatrol, $wgLang;
                global $wgLinkCache, $IP, $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol;
                $sk = $wgUser->getSkin();
 
                $fname = 'Article::view';
                wfProfileIn( $fname );
                # Get variables from query string
-               $oldid = $wgRequest->getVal( 'oldid' );
+               $oldid = $this->getOldID();
                $diff = $wgRequest->getVal( 'diff' );
                $rcid = $wgRequest->getVal( 'rcid' );
 
@@ -753,8 +776,10 @@ class Article {
                                $targetUrl = $rt->escapeLocalURL();
                                $titleText = htmlspecialchars( $rt->getPrefixedText() );
                                $link = $sk->makeLinkObj( $rt );
-                               $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" />' .
+
+                               $wgOut->addHTML( '<img valign="center" src="'.$imageUrl.'" alt="#REDIRECT" />' .
                                  '<span class="redirectText">'.$link.'</span>' );
+
                        } else if ( $pcache ) {
                                # Display content and save to parser cache
                                $wgOut->addPrimaryWikiText( $text, $this );
@@ -1252,14 +1277,20 @@ class Article {
                }
 
                $confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
+               $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
                $reason = $wgRequest->getText( 'wpReasonProtect' );
 
                if ( $confirm ) {
+                       $restrictions = "move=" . $limit;
+                       if( !$moveonly ) {
+                               $restrictions .= ":edit=" . $limit;
+                       }
+                       
                        $dbw =& wfGetDB( DB_MASTER );
                        $dbw->update( 'cur',
                                array( /* SET */
                                        'cur_touched' => $dbw->timestamp(),
-                                       'cur_restrictions' => (string)$limit
+                                       'cur_restrictions' => $restrictions
                                ), array( /* WHERE */
                                        'cur_id' => $id
                                ), 'Article::protect'
@@ -1292,6 +1323,7 @@ class Article {
 
                $check = '';
                $protcom = '';
+               $moveonly = '';
 
                if ( $limit === '' ) {
                        $wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
@@ -1305,6 +1337,7 @@ class Article {
                        $wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
                        $wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
                        $check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
+                       $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
                        $protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
                        $formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
                }
@@ -1332,7 +1365,19 @@ class Article {
                        <td>
                                <label for='wpConfirmProtect'>{$check}</label>
                        </td>
-               </tr>
+               </tr> " );
+               if($moveonly != '') {
+                       $wgOut->AddHTML( "
+               <tr>
+                       <td align='right'>
+                               <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
+                       </td>
+                       <td>
+                               <label for='wpMoveOnly'>{$moveonly}</label>
+                       </td>
+               </tr> " );
+               }
+               $wgOut->addHTML( "
                <tr>
                        <td>&nbsp;</td>
                        <td>