Remove unused private "filterPage" function from specials/SpecialExport.php
[lhc/web/wiklou.git] / includes / Article.php
index 105425a..cde5f47 100644 (file)
@@ -60,7 +60,9 @@ class Article {
         */
        public static function newFromID( $id ) {
                $t = Title::newFromID( $id );
-               return $t == null ? null : new Article( $t );
+               # FIXME: doesn't inherit right
+               return $t == null ? null : new self( $t );
+               #return $t == null ? null : new static( $t ); // PHP 5.3
        }
 
        /**
@@ -205,7 +207,7 @@ class Article {
         * the shortcut in Article::followContent()
         *
         * @return Return the text of this revision
-       */
+        */
        public function getContent() {
                global $wgUser, $wgContLang, $wgOut, $wgMessageCache;
                wfProfileIn( __METHOD__ );
@@ -235,7 +237,7 @@ class Article {
         * Get the text of the current revision. No side-effects...
         *
         * @return Return the text of the current revision
-       */
+        */
        public function getRawText() {
                // Check process cache for current revision
                if( $this->mContentLoaded && $this->mOldId == 0 ) {
@@ -497,7 +499,7 @@ class Article {
         *
         * @param $x Mixed: FIXME
         */
-       public function forUpdate( $x = NULL ) {
+       public function forUpdate( $x = null ) {
                return wfSetVar( $this->mForUpdate, $x );
        }
 
@@ -612,7 +614,7 @@ class Article {
                } else {
                        $titleObj = Title::newFromRedirect( $text );
                }
-               return $titleObj !== NULL;
+               return $titleObj !== null;
        }
 
        /**
@@ -726,9 +728,9 @@ class Article {
        }
 
        /**
-        * This is the default action of the index.php entry point: just view the 
+        * This is the default action of the index.php entry point: just view the
         * page of the given title.
-       */
+        */
        public function view() {
                global $wgUser, $wgOut, $wgRequest, $wgContLang;
                global $wgEnableParserCache, $wgStylePath, $wgParser;
@@ -938,7 +940,7 @@ class Article {
         */
        public function showDiffPage() {
                global $wgOut, $wgRequest, $wgUser;
-               
+
                $diff = $wgRequest->getVal( 'diff' );
                $rcid = $wgRequest->getVal( 'rcid' );
                $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
@@ -960,10 +962,10 @@ class Article {
        }
 
        /**
-        * Show a page view for a page formatted as CSS or JavaScript. To be called by 
+        * Show a page view for a page formatted as CSS or JavaScript. To be called by
         * Article::view() only.
         *
-        * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these 
+        * This is hooked by SyntaxHighlight_GeSHi to do syntax highlighting of these
         * page views.
         */
        public function showCssOrJsPage() {
@@ -991,7 +993,7 @@ class Article {
                $policy = $this->getRobotPolicy( 'view' );
                return $policy['index'] . ',' . $policy['follow'];
        }
-       
+
        /**
         * Get the robot policy to be used for the current view
         * @param $action String the action= GET parameter
@@ -999,7 +1001,7 @@ class Article {
         * TODO: actions other than 'view'
         */
        public function getRobotPolicy( $action ){
-               
+
                global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
                global $wgDefaultRobotPolicy, $wgRequest;
 
@@ -1083,8 +1085,8 @@ class Article {
        }
 
        /**
-        * If this request is a redirect view, send "redirected from" subtitle to 
-        * $wgOut. Returns true if the header was needed, false if this is not a 
+        * If this request is a redirect view, send "redirected from" subtitle to
+        * $wgOut. Returns true if the header was needed, false if this is not a
         * redirect view. Handles both local and remote redirects.
         */
        public function showRedirectedFromHeader() {
@@ -1132,7 +1134,7 @@ class Article {
        }
 
        /**
-        * Show a header specific to the namespace currently being viewed, like 
+        * Show a header specific to the namespace currently being viewed, like
         * [[MediaWiki:Talkpagetext]]. For Article::view().
         */
        public function showNamespaceHeader() {
@@ -1166,8 +1168,8 @@ class Article {
        }
 
        /**
-        * If patrol is possible, output a patrol UI box. This is called from the 
-        * footer section of ordinary page views. If patrol is not possible or not 
+        * If patrol is possible, output a patrol UI box. This is called from the
+        * footer section of ordinary page views. If patrol is not possible or not
         * desired, does nothing.
         */
        public function showPatrolFooter() {
@@ -1197,10 +1199,10 @@ class Article {
                                ) .
                        '</div>'
                );
-       }               
+       }
 
        /**
-        * Show the error text for a missing article. For articles in the MediaWiki 
+        * Show the error text for a missing article. For articles in the MediaWiki
         * namespace, show the default message text. To be called from Article::view().
         */
        public function showMissingArticle() {
@@ -1223,13 +1225,13 @@ class Article {
                        array(  'lim' => 10,
                                'conds' => array( "log_action != 'revision'" ),
                                'showIfEmpty' => false,
-                               'msgKey' => array( 'moveddeleted-notice' ) ) 
+                               'msgKey' => array( 'moveddeleted-notice' ) )
                );
 
                # Show error message
                $oldid = $this->getOldID();
                if( $oldid ) {
-                       $text = wfMsgNoTrans( 'missing-article', 
+                       $text = wfMsgNoTrans( 'missing-article',
                                $this->mTitle->getPrefixedText(),
                                wfMsgNoTrans( 'missingarticle-rev', $oldid ) );
                } elseif ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) {
@@ -1239,7 +1241,7 @@ class Article {
                        $createErrors = $this->mTitle->getUserPermissionsErrors( 'create', $wgUser );
                        $editErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser );
                        $errors = array_merge( $createErrors, $editErrors );
-                       
+
                        if ( !count($errors) )
                                $text = wfMsgNoTrans( 'noarticletext' );
                        else
@@ -1255,7 +1257,7 @@ class Article {
        }
 
        /**
-        * If the revision requested for view is deleted, check permissions. 
+        * If the revision requested for view is deleted, check permissions.
         * Send either an error message or a warning header to $wgOut.
         * Returns true if the view is allowed, false if not.
         */
@@ -1320,9 +1322,9 @@ class Article {
        }
 
        /**
-        * Try to fetch an expired entry from the parser cache. If it is present, 
-        * output it and return true. If it is not present, output nothing and 
-        * return false. This is used as a callback function for 
+        * Try to fetch an expired entry from the parser cache. If it is present,
+        * output it and return true. If it is not present, output nothing and
+        * return false. This is used as a callback function for
         * PoolCounter::executeProtected().
         */
        public function tryDirtyCache() {
@@ -1356,7 +1358,7 @@ class Article {
                $wgOut->enableClientCache( false );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiText(
-                       '<div class="errorbox">' . 
+                       '<div class="errorbox">' .
                        $status->getWikiText( false, 'view-pool-error' ) .
                        '</div>'
                );
@@ -1507,7 +1509,7 @@ class Article {
                if( $wgUseSquid ) {
                        // Commit the transaction before the purge is sent
                        $dbw = wfGetDB( DB_MASTER );
-                       $dbw->immediateCommit();
+                       $dbw->commit();
 
                        // Send purge
                        $update = SquidUpdate::newSimplePurge( $this->mTitle );
@@ -1573,7 +1575,7 @@ class Article {
         *                      Giving 0 indicates the new page flag should be set
         *                      on.
         * @param $lastRevIsRedirect Boolean: if given, will optimize adding and
-        *                                                       removing rows in redirect table.
+        *                           removing rows in redirect table.
         * @return bool true on success, false on failure
         * @private
         */
@@ -1594,7 +1596,7 @@ class Article {
                                'page_latest'      => $revision->getId(),
                                'page_touched'     => $dbw->timestamp(),
                                'page_is_new'      => ($lastRevision === 0) ? 1 : 0,
-                               'page_is_redirect' => $rt !== NULL ? 1 : 0,
+                               'page_is_redirect' => $rt !== null ? 1 : 0,
                                'page_len'         => strlen( $text ),
                        ),
                        $conditions,
@@ -1614,9 +1616,9 @@ class Article {
         *
         * @param $dbw Database
         * @param $redirectTitle a title object pointing to the redirect target,
-        *                                               or NULL if this is not a redirect
+        *                       or NULL if this is not a redirect
         * @param $lastRevIsRedirect If given, will optimize adding and
-        *                                                       removing rows in redirect table.
+        *                           removing rows in redirect table.
         * @return bool true on success, false on failure
         * @private
         */
@@ -1686,7 +1688,7 @@ class Article {
         * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
         * @return string Complete article text, or null if error
         */
-       public function replaceSection( $section, $text, $summary = '', $edittime = NULL ) {
+       public function replaceSection( $section, $text, $summary = '', $edittime = null ) {
                wfProfileIn( __METHOD__ );
                if( strval( $section ) == '' ) {
                        // Whole-page edit; let the whole text through
@@ -2157,7 +2159,6 @@ class Article {
        /**
         * User-interface handler for the "watch" action
         */
-
        public function watch() {
                global $wgUser, $wgOut;
                if( $wgUser->isAnon() ) {
@@ -2254,7 +2255,9 @@ class Article {
         * @return bool true on success
         */
        public function updateRestrictions( $limit = array(), $reason = '', &$cascade = 0, $expiry = array() ) {
-               global $wgUser, $wgRestrictionTypes, $wgContLang;
+               global $wgUser, $wgContLang;
+
+               $restrictionTypes = $this->mTitle->getRestrictionTypes();
 
                $id = $this->mTitle->getArticleID();
                if ( $id <= 0 ) {
@@ -2284,7 +2287,7 @@ class Article {
                $current = array();
                $updated = Article::flattenRestrictions( $limit );
                $changed = false;
-               foreach( $wgRestrictionTypes as $action ) {
+               foreach( $restrictionTypes as $action ) {
                        if( isset( $expiry[$action] ) ) {
                                # Get current restrictions on $action
                                $aLimits = $this->mTitle->getRestrictions( $action );
@@ -2583,7 +2586,7 @@ class Article {
 
                if( $confirm ) {
                        $this->doDelete( $reason, $suppress );
-                       if( $wgRequest->getCheck( 'wpWatch' ) ) {
+                       if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
                                $this->doWatch();
                        } elseif( $this->mTitle->userIsWatching() ) {
                                $this->doUnwatch();
@@ -2601,8 +2604,8 @@ class Article {
                        $skin = $wgUser->getSkin();
                        $revisions = $this->estimateRevisionCount();
                        $wgOut->addHTML( '<strong class="mw-delete-warning-revisions">' .
-                               wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .' ' .
-                               $skin->historyLink() .
+                               wfMsgExt( 'historywarning', array( 'parseinline' ), $wgLang->formatNum( $revisions ) ) .
+                               wfMsgHtml( 'word-separator' ) . $skin->historyLink() .
                                '</strong>'
                        );
                        if( $bigHistory ) {
@@ -2636,7 +2639,7 @@ class Article {
                //return $dbr->selectField( 'revision', 'COUNT(*)',
                //      array( 'rev_page' => $this->getId() ), __METHOD__ );
                return $dbr->estimateRowCount( 'revision', '*',
-                       array( 'rev_page' => $this->getId() ), __METHOD__ );
+                       array( 'rev_page' => $this->getId() ), __METHOD__ );
        }
 
        /**
@@ -2703,7 +2706,7 @@ class Article {
                $wgOut->setSubtitle( wfMsgHtml( 'delete-backlink', $deleteBackLink ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->addWikiMsg( 'confirmdeletetext' );
-               
+
                wfRunHooks( 'ArticleConfirmDelete', array( $this, $wgOut, &$reason ) );
 
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
@@ -2747,14 +2750,19 @@ class Article {
                                        'autofocus'
                                ) ) .
                                "</td>
-                       </tr>
+                       </tr>";
+               # Dissalow watching is user is not logged in
+               if( $wgUser->isLoggedIn() ) {
+                       $form .= "
                        <tr>
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'watchthis' ),
                                                'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
                                "</td>
-                       </tr>
+                       </tr>";
+               }
+               $form .= "
                        $suppress
                        <tr>
                                <td></td>
@@ -3051,10 +3059,10 @@ class Article {
                $user_text = $dbw->addQuotes( $current->getRawUserText() );
                $s = $dbw->selectRow( 'revision',
                        array( 'rev_id', 'rev_timestamp', 'rev_deleted' ),
-                       array(  'rev_page' => $current->getPage(),
+                       array( 'rev_page' => $current->getPage(),
                                "rev_user != {$user} OR rev_user_text != {$user_text}"
                        ), __METHOD__,
-                       array(  'USE INDEX' => 'page_timestamp',
+                       array( 'USE INDEX' => 'page_timestamp',
                                'ORDER BY'  => 'rev_timestamp DESC' )
                        );
                if( $s === false ) {
@@ -3188,8 +3196,12 @@ class Article {
                $newId = $details['newid'];
                $wgOut->setPageTitle( wfMsg( 'actioncomplete' ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
-                       . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
+               if ( $current->getUserText() === '' ) {
+                       $old = wfMsg( 'rev-deleted-user' );
+               } else {
+                       $old = $wgUser->getSkin()->userLink( $current->getUser(), $current->getUserText() )
+                               . $wgUser->getSkin()->userToolLinks( $current->getUser(), $current->getUserText() );
+               }
                $new = $wgUser->getSkin()->userLink( $target->getUser(), $target->getUserText() )
                        . $wgUser->getSkin()->userToolLinks( $target->getUser(), $target->getUserText() );
                $wgOut->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
@@ -3482,7 +3494,7 @@ class Article {
                $r = "\n\t\t\t\t<div id=\"mw-{$infomsg}\">" .
                        wfMsgExt(
                                $infomsg,
-                               array( 'parseinline', 'replaceafter' ), 
+                               array( 'parseinline', 'replaceafter' ),
                                $td,
                                $userlinks,
                                $revision->getID(),
@@ -3685,7 +3697,6 @@ class Article {
         *
         * @param $title a title object
         */
-
        public static function onArticleCreate( $title ) {
                # Update existence markers on article/talk tabs...
                if( $title->isTalkPage() ) {
@@ -3967,7 +3978,7 @@ class Article {
                $this->mParserOutput = $this->getOutputFromWikitext( $text, $cache, $parserOptions );
                $wgOut->addParserOutput( $this->mParserOutput );
        }
-       
+
        /**
         * This does all the heavy lifting for outputWikitext, except it returns the parser
         * output instead of sending it straight to $wgOut. Makes things nice and simple for,
@@ -4090,8 +4101,10 @@ class Article {
                }
                $insertRows = array();
                foreach( $insertCats as $cat ) {
-                       $insertRows[] = array(  'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
-                                                                                                                       'cat_title' => $cat );
+                       $insertRows[] = array(
+                               'cat_id' => $dbw->nextSequenceValue( 'category_cat_id_seq' ),
+                               'cat_title' => $cat
+                       );
                }
                $dbw->insert( 'category', $insertRows, __METHOD__, 'IGNORE' );
 
@@ -4122,10 +4135,11 @@ class Article {
                        );
                }
        }
-       
+
        /** Lightweight method to get the parser output for a page, checking the parser cache
-         * and so on. Doesn't consider most of the stuff that Article::view is forced to
-         * consider, so it's not appropriate to use there. */
+        * and so on. Doesn't consider most of the stuff that Article::view is forced to
+        * consider, so it's not appropriate to use there.
+        */
        function getParserOutput( $oldid = null ) {
                global $wgEnableParserCache, $wgUser, $wgOut;
 
@@ -4133,8 +4147,8 @@ class Article {
                $useParserCache = $wgEnableParserCache &&
                          intval( $wgUser->getOption( 'stubthreshold' ) ) == 0 &&
                          $this->exists() &&
-                                 $oldid === null;
-                                 
+                         $oldid === null;
+
                wfDebug( __METHOD__.': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
                if ( $wgUser->getOption( 'stubthreshold' ) ) {
                        wfIncrStats( 'pcache_miss_stub' );
@@ -4148,7 +4162,7 @@ class Article {
                if ( $parserOutput === false ) {
                        // Cache miss; parse and output it.
                        $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
-                       
+
                        return $this->getOutputFromWikitext( $rev->getText(), $useParserCache );
                } else {
                        return $parserOutput;