Merge "Generalizing LinksUpdate to allow extensions to add arbitrary update handlers."
[lhc/web/wiklou.git] / includes / WikiPage.php
index df610f1..b326eb4 100644 (file)
@@ -1,4 +1,25 @@
 <?php
+/**
+ * Base representation for a MediaWiki page.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
 /**
  * Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
  */
@@ -473,6 +494,49 @@ class WikiPage extends Page {
                return (int)$this->mLatest;
        }
 
+       /**
+        * Get the Revision object of the oldest revision
+        * @return Revision|null
+        */
+       public function getOldestRevision() {
+               wfProfileIn( __METHOD__ );
+
+               // Try using the slave database first, then try the master
+               $continue = 2;
+               $db = wfGetDB( DB_SLAVE );
+               $revSelectFields = Revision::selectFields();
+
+               while ( $continue ) {
+                       $row = $db->selectRow(
+                               array( 'page', 'revision' ),
+                               $revSelectFields,
+                               array(
+                                       'page_namespace' => $this->mTitle->getNamespace(),
+                                       'page_title' => $this->mTitle->getDBkey(),
+                                       'rev_page = page_id'
+                               ),
+                               __METHOD__,
+                               array(
+                                       'ORDER BY' => 'rev_timestamp ASC'
+                               )
+                       );
+
+                       if ( $row ) {
+                               $continue = 0;
+                       } else {
+                               $db = wfGetDB( DB_MASTER );
+                               $continue--;
+                       }
+               }
+
+               wfProfileOut( __METHOD__ );
+               if ( $row ) {
+                       return Revision::newFromRow( $row );
+               } else {
+                       return null;
+               }
+       }
+
        /**
         * Loads everything except the text
         * This isn't necessary for all uses, so it's only done if needed.
@@ -580,6 +644,24 @@ class WikiPage extends Page {
                }
        }
 
+       /**
+        * Get the User object of the user who created the page
+        * @param $audience Integer: one of:
+        *      Revision::FOR_PUBLIC       to be displayed to all users
+        *      Revision::FOR_THIS_USER    to be displayed to $wgUser
+        *      Revision::RAW              get the text regardless of permissions
+        * @return User|null
+        */
+       public function getCreator( $audience = Revision::FOR_PUBLIC ) {
+               $revision = $this->getOldestRevision();
+               if ( $revision ) {
+                       $userName = $revision->getUserText( $audience );
+                       return User::newFromName( $userName, false );
+               } else {
+                       return null;
+               }
+       }
+
        /**
         * @param $audience Integer: one of:
         *      Revision::FOR_PUBLIC       to be displayed to all users