Example #1
0
 /**
  * @return array|null
  *
  * @todo Fix this so it works again.
  * This has changed with MW1.19 so we need to re-fix this issue
  * Original ticket: https://wikia.fogbugz.com/default.asp?26737
  * Currently broken in places like this: http://glee.wikia.com/wiki/File:Glee_Sugar%27s_Audition-3x01
  *
  */
 public function getDuplicates()
 {
     /*wfProfileIn( __METHOD__ );
     		$img =  $this->getDisplayedFile();
     		$handler = $img->getHandler();
     		if ( $handler instanceof VideoHandler && $handler->isBroken() ) {
     			$res = $this->dupes = array();
     		} else {
     			$dupes = parent::getDuplicates();
     			$finalDupes = array();
     			foreach( $dupes as $dupe ) {
     		                if ( WikiaFileHelper::isFileTypeVideo( $dupe ) && $dupe instanceof WikiaLocalFile ) {
     		                    if ( $dupe->getProviderName() != $img->getProviderName() ) continue;
     		                    if ( $dupe->getVideoId() != $img->getVideoId() ) continue;
     		                    $finalDupes[] = $dupe;
     		                }
     			}
     			$res = $finalDupes;
     		}
     		wfProfileOut( __METHOD__ );
     		return $res;*/
     return parent::getDuplicates();
 }
Example #2
0
 /**
  * Record a file upload in the upload log and the image table
  * @param string $oldver
  * @param string $comment
  * @param string $pageText
  * @param bool|array $props
  * @param string|bool $timestamp
  * @param null|User $user
  * @return bool
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     wfProfileIn(__METHOD__);
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin(__METHOD__);
     if (!$props) {
         wfProfileIn(__METHOD__ . '-getProps');
         $props = $this->repo->getFileProps($this->getVirtualUrl());
         wfProfileOut(__METHOD__ . '-getProps');
     }
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         wfProfileOut(__METHOD__);
         return false;
     }
     $reupload = false;
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         # (bug 34993) Note: $oldver can be empty here, if the previous
         # version of the file was broken. Allow registration of the new
         # version to continue anyway, because that's better than having
         # an image that's not fixable by user operations.
         $reupload = true;
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file, so update the image count
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(array('images' => 1)));
     }
     $descTitle = $this->getTitle();
     $wikiPage = new WikiFilePage($descTitle);
     $wikiPage->setFile($this);
     # Add the log entry
     $action = $reupload ? 'overwrite' : 'upload';
     $logEntry = new ManualLogEntry('upload', $action);
     $logEntry->setPerformer($user);
     $logEntry->setComment($comment);
     $logEntry->setTarget($descTitle);
     // Allow people using the api to associate log entries with the upload.
     // Log has a timestamp, but sometimes different from upload timestamp.
     $logEntry->setParameters(array('img_sha1' => $this->sha1, 'img_timestamp' => $timestamp));
     // Note we keep $logId around since during new image
     // creation, page doesn't exist yet, so log_page = 0
     // but we want it to point to the page we're making,
     // so we later modify the log entry.
     // For a similar reason, we avoid making an RC entry
     // now and wait until the page exists.
     $logId = $logEntry->insert();
     $exists = $descTitle->exists();
     if ($exists) {
         // Page exists, do RC entry now (otherwise we wait for later).
         $logEntry->publish($logId);
     }
     wfProfileIn(__METHOD__ . '-edit');
     if ($exists) {
         # Create a null revision
         $latest = $descTitle->getLatestRevID();
         $editSummary = LogFormatter::newFromEntry($logEntry)->getPlainActionText();
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleID(), $editSummary, false);
         if (!is_null($nullRevision)) {
             $nullRevision->insertOn($dbw);
             wfRunHooks('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $latest, $user));
             $wikiPage->updateRevisionOn($dbw, $nullRevision);
         }
     }
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     # NOTE: once we have support for nested transactions, the commit may be moved
     #       to after $wikiPage->doEdit has been called.
     $dbw->commit(__METHOD__);
     # Save to memcache.
     # We shall not saveToCache before the commit since otherwise
     # in case of a rollback there is an usable file from memcached
     # which in fact doesn't really exist (bug 24978)
     $this->saveToCache();
     if ($exists) {
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         # New file; create the description page.
         # There's already a log entry, so don't make a second RC entry
         # Squid and file cache for the description page are purged by doEditContent.
         $content = ContentHandler::makeContent($pageText, $descTitle);
         $status = $wikiPage->doEditContent($content, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
         $dbw->begin(__METHOD__);
         // XXX; doEdit() uses a transaction
         // Now that the page exists, make an RC entry.
         $logEntry->publish($logId);
         if (isset($status->value['revision'])) {
             $dbw->update('logging', array('log_page' => $status->value['revision']->getPage()), array('log_id' => $logId), __METHOD__);
         }
         $dbw->commit(__METHOD__);
         // commit before anything bad can happen
     }
     wfProfileOut(__METHOD__ . '-edit');
     if ($reupload) {
         # Delete old thumbnails
         wfProfileIn(__METHOD__ . '-purge');
         $this->purgeThumbnails();
         wfProfileOut(__METHOD__ . '-purge');
         # Remove the old file from the squid cache
         SquidUpdate::purge(array($this->getURL()));
     }
     # Hooks, hooks, the magic of hooks...
     wfProfileIn(__METHOD__ . '-hooks');
     wfRunHooks('FileUpload', array($this, $reupload, $descTitle->exists()));
     wfProfileOut(__METHOD__ . '-hooks');
     # Invalidate cache for all pages using this file
     $update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
     $update->doUpdate();
     if (!$reupload) {
         LinksUpdate::queueRecursiveJobsForTable($this->getTitle(), 'imagelinks');
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Example #3
0
 /**
  * Record a file upload in the upload log and the image table
  * @param string $oldver
  * @param string $comment
  * @param string $pageText
  * @param bool|array $props
  * @param string|bool $timestamp
  * @param null|User $user
  * @param string[] $tags
  * @return bool
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = array())
 {
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     # Imports or such might force a certain timestamp; otherwise we generate
     # it and can fudge it slightly to keep (name,timestamp) unique on re-upload.
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
         $allowTimeKludge = true;
     } else {
         $allowTimeKludge = false;
     }
     $props = $props ?: $this->repo->getFileProps($this->getVirtualUrl());
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         return false;
     }
     $dbw->startAtomic(__METHOD__);
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     $reupload = $dbw->affectedRows() == 0;
     if ($reupload) {
         if ($allowTimeKludge) {
             # Use LOCK IN SHARE MODE to ignore any transaction snapshotting
             $ltimestamp = $dbw->selectField('image', 'img_timestamp', array('img_name' => $this->getName()), __METHOD__, array('LOCK IN SHARE MODE'));
             $lUnixtime = $ltimestamp ? wfTimestamp(TS_UNIX, $ltimestamp) : false;
             # Avoid a timestamp that is not newer than the last version
             # TODO: the image/oldimage tables should be like page/revision with an ID field
             if ($lUnixtime && wfTimestamp(TS_UNIX, $timestamp) <= $lUnixtime) {
                 sleep(1);
                 // fast enough re-uploads would go far in the future otherwise
                 $timestamp = $dbw->timestamp($lUnixtime + 1);
                 $this->timestamp = wfTimestamp(TS_MW, $timestamp);
                 // DB -> TS_MW
             }
         }
         # (bug 34993) Note: $oldver can be empty here, if the previous
         # version of the file was broken. Allow registration of the new
         # version to continue anyway, because that's better than having
         # an image that's not fixable by user operations.
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     }
     $descTitle = $this->getTitle();
     $descId = $descTitle->getArticleID();
     $wikiPage = new WikiFilePage($descTitle);
     $wikiPage->setFile($this);
     // Add the log entry...
     $logEntry = new ManualLogEntry('upload', $reupload ? 'overwrite' : 'upload');
     $logEntry->setTimestamp($this->timestamp);
     $logEntry->setPerformer($user);
     $logEntry->setComment($comment);
     $logEntry->setTarget($descTitle);
     // Allow people using the api to associate log entries with the upload.
     // Log has a timestamp, but sometimes different from upload timestamp.
     $logEntry->setParameters(array('img_sha1' => $this->sha1, 'img_timestamp' => $timestamp));
     // Note we keep $logId around since during new image
     // creation, page doesn't exist yet, so log_page = 0
     // but we want it to point to the page we're making,
     // so we later modify the log entry.
     // For a similar reason, we avoid making an RC entry
     // now and wait until the page exists.
     $logId = $logEntry->insert();
     if ($descTitle->exists()) {
         // Use own context to get the action text in content language
         $formatter = LogFormatter::newFromEntry($logEntry);
         $formatter->setContext(RequestContext::newExtraneousContext($descTitle));
         $editSummary = $formatter->getPlainActionText();
         $nullRevision = Revision::newNullRevision($dbw, $descId, $editSummary, false, $user);
         if ($nullRevision) {
             $nullRevision->insertOn($dbw);
             Hooks::run('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $nullRevision->getParentId(), $user));
             $wikiPage->updateRevisionOn($dbw, $nullRevision);
             // Associate null revision id
             $logEntry->setAssociatedRevId($nullRevision->getId());
         }
         $newPageContent = null;
     } else {
         // Make the description page and RC log entry post-commit
         $newPageContent = ContentHandler::makeContent($pageText, $descTitle);
     }
     # Defer purges, page creation, and link updates in case they error out.
     # The most important thing is that files and the DB registry stay synced.
     $dbw->endAtomic(__METHOD__);
     # Do some cache purges after final commit so that:
     # a) Changes are more likely to be seen post-purge
     # b) They won't cause rollback of the log publish/update above
     $that = $this;
     $dbw->onTransactionIdle(function () use($that, $reupload, $wikiPage, $newPageContent, $comment, $user, $logEntry, $logId, $descId, $tags) {
         # Update memcache after the commit
         $that->invalidateCache();
         $updateLogPage = false;
         if ($newPageContent) {
             # New file page; create the description page.
             # There's already a log entry, so don't make a second RC entry
             # CDN and file cache for the description page are purged by doEditContent.
             $status = $wikiPage->doEditContent($newPageContent, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
             if (isset($status->value['revision'])) {
                 // Associate new page revision id
                 $logEntry->setAssociatedRevId($status->value['revision']->getId());
             }
             // This relies on the resetArticleID() call in WikiPage::insertOn(),
             // which is triggered on $descTitle by doEditContent() above.
             if (isset($status->value['revision'])) {
                 /** @var $rev Revision */
                 $rev = $status->value['revision'];
                 $updateLogPage = $rev->getPage();
             }
         } else {
             # Existing file page: invalidate description page cache
             $wikiPage->getTitle()->invalidateCache();
             $wikiPage->getTitle()->purgeSquid();
             # Allow the new file version to be patrolled from the page footer
             Article::purgePatrolFooterCache($descId);
         }
         # Update associated rev id. This should be done by $logEntry->insert() earlier,
         # but setAssociatedRevId() wasn't called at that point yet...
         $logParams = $logEntry->getParameters();
         $logParams['associated_rev_id'] = $logEntry->getAssociatedRevId();
         $update = array('log_params' => LogEntryBase::makeParamBlob($logParams));
         if ($updateLogPage) {
             # Also log page, in case where we just created it above
             $update['log_page'] = $updateLogPage;
         }
         $that->getRepo()->getMasterDB()->update('logging', $update, array('log_id' => $logId), __METHOD__);
         $that->getRepo()->getMasterDB()->insert('log_search', array('ls_field' => 'associated_rev_id', 'ls_value' => $logEntry->getAssociatedRevId(), 'ls_log_id' => $logId), __METHOD__);
         # Now that the log entry is up-to-date, make an RC entry.
         $recentChange = $logEntry->publish($logId);
         if ($tags) {
             ChangeTags::addTags($tags, $recentChange ? $recentChange->getAttribute('rc_id') : null, $logEntry->getAssociatedRevId(), $logId);
         }
         # Run hook for other updates (typically more cache purging)
         Hooks::run('FileUpload', array($that, $reupload, !$newPageContent));
         if ($reupload) {
             # Delete old thumbnails
             $that->purgeThumbnails();
             # Remove the old file from the CDN cache
             DeferredUpdates::addUpdate(new CdnCacheUpdate(array($that->getUrl())), DeferredUpdates::PRESEND);
         } else {
             # Update backlink pages pointing to this title if created
             LinksUpdate::queueRecursiveJobsForTable($that->getTitle(), 'imagelinks');
         }
     });
     if (!$reupload) {
         # This is a new file, so update the image count
         DeferredUpdates::addUpdate(SiteStatsUpdate::factory(array('images' => 1)));
     }
     # Invalidate cache for all pages using this file
     DeferredUpdates::addUpdate(new HTMLCacheUpdate($this->getTitle(), 'imagelinks'));
     return true;
 }
Example #4
0
 /**
  * Record a file upload in the upload log and the image table
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin();
     if (!$props) {
         $props = $this->repo->getFileProps($this->getVirtualUrl());
     }
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Delete thumbnails
     $this->purgeThumbnails();
     # The file is already on its final location, remove it from the squid cache
     SquidUpdate::purge(array($this->getURL()));
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         return false;
     }
     $reupload = false;
     # Test to see if the row exists using INSERT IGNORE
     # This avoids race conditions by locking the row until the commit, and also
     # doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
     $dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
     if ($dbw->affectedRows() == 0) {
         if ($oldver == '') {
             // XXX
             # (bug 34993) publish() can displace the current file and yet fail to save
             # a new one. The next publish attempt will treat the file as a brand new file
             # and pass an empty $oldver. Allow this bogus value so we can displace the
             # `image` row to `oldimage`, leaving room for the new current file `image` row.
             #throw new MWException( "Empty oi_archive_name. Database and storage out of sync?" );
         }
         $reupload = true;
         # Collision, this is an update of a file
         # Insert previous contents into oldimage
         $dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
         # Update the current image row
         $dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
     } else {
         # This is a new file
         # Update the image count
         $dbw->begin(__METHOD__);
         $dbw->update('site_stats', array('ss_images = ss_images+1'), '*', __METHOD__);
         $dbw->commit(__METHOD__);
     }
     $descTitle = $this->getTitle();
     $wikiPage = new WikiFilePage($descTitle);
     $wikiPage->setFile($this);
     # Add the log entry
     $log = new LogPage('upload');
     $action = $reupload ? 'overwrite' : 'upload';
     $log->addEntry($action, $descTitle, $comment, array(), $user);
     if ($descTitle->exists()) {
         # Create a null revision
         $latest = $descTitle->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleId(), $log->getRcComment(), false);
         if (!is_null($nullRevision)) {
             $nullRevision->insertOn($dbw);
             wfRunHooks('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $latest, $user));
             $wikiPage->updateRevisionOn($dbw, $nullRevision);
         }
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         # New file; create the description page.
         # There's already a log entry, so don't make a second RC entry
         # Squid and file cache for the description page are purged by doEdit.
         $wikiPage->doEdit($pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
     }
     # Commit the transaction now, in case something goes wrong later
     # The most important thing is that files don't get lost, especially archives
     $dbw->commit();
     # Save to cache and purge the squid
     # We shall not saveToCache before the commit since otherwise
     # in case of a rollback there is an usable file from memcached
     # which in fact doesn't really exist (bug 24978)
     $this->saveToCache();
     # Hooks, hooks, the magic of hooks...
     wfRunHooks('FileUpload', array($this, $reupload, $descTitle->exists()));
     # Invalidate cache for all pages using this file
     $update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
     $update->doUpdate();
     # Invalidate cache for all pages that redirects on this page
     $redirs = $this->getTitle()->getRedirectsHere();
     foreach ($redirs as $redir) {
         $update = new HTMLCacheUpdate($redir, 'imagelinks');
         $update->doUpdate();
     }
     return true;
 }
    function execute($par)
    {
        if (!$this->userCanExecute($this->getUser())) {
            $this->displayRestrictionError();
            return;
        }
        $output = $this->getOutput();
        $this->setHeaders();
        $output->addModules('ext.createteams.SpecialPage');
        $report = '';
        $e = '';
        $log = '';
        $preview = '';
        $this->getTemplates();
        # Get request data from, e.g.
        # Do stuff
        # ...
        //$wgOut->setPageTitle( "create team templates" );
        $output->addWikiText('==' . wfMessage('createteams-create-teams-heading')->inContentLanguage()->text() . '==');
        $output->addWikiText(wfMessage('createteams-create-teams-desc')->inContentLanguage()->text());
        global $wgUser, $wgUploadNavigationUrl;
        if ($wgUploadNavigationUrl) {
            $uploadMessage = wfMessage('createteams-create-teams-image-helper-remote')->params($wgUploadNavigationUrl)->inContentLanguage()->parse();
        } else {
            $uploadMessage = wfMessage('createteams-create-teams-image-helper')->inContentLanguage()->parse();
        }
        $request = $this->getRequest();
        $reqTeam = $request->getText('team');
        $reqTeamslug = $request->getText('teamslug');
        $reqPagetitle = $request->getText('pagetitle');
        $reqImage = $request->getText('image');
        $reqTeamshort = $request->getText('teamshort');
        $reqOverwrite = $request->getBool('overwrite');
        $output->addHTML('<form name="createform" id="createform" method="post">
<table>
	<tr>
		<td class="input-label"><label for="team">' . wfMessage('createteams-create-teams-team-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="team" id="team" value="' . $reqTeam . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-team-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="team">' . wfMessage('createteams-create-teams-team-slug-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="teamslug" id="teamslug" value="' . $reqTeamslug . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-team-slug-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="pagetitle">' . wfMessage('createteams-create-teams-pagetitle-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="pagetitle" id="pagetitle" value="' . $reqPagetitle . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-pagetitle-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="teamshort">' . wfMessage('createteams-create-teams-teamshort-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="teamshort" id="teamshort" value="' . $reqTeamshort . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-teamshort-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="image">' . wfMessage('createteams-create-teams-image-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="image" id="image" value="' . $reqImage . '"></td>
		<td class="input-helper">' . $uploadMessage . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="overwrite">' . wfMessage('createteams-create-teams-overwrite-label')->inContentLanguage()->parse() . '</label></td>
		<td><input type="checkbox" name="overwrite" id="overwrite"' . ($reqOverwrite ? ' checked=""' : '') . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-overwrite-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td> </td>
		<td colspan="2">
			<input type="submit" name="createbutton" value="' . wfMessage('createteams-create-teams-create-button')->inContentLanguage()->text() . '"> 
			<input type="submit" name="createpreviewbutton" value="' . wfMessage('createteams-create-teams-preview-button')->inContentLanguage()->text() . '">
		</td>
	</tr>
</table>
</form>');
        if ($request->getBool('createbutton') || $request->getBool('createpreviewbutton')) {
            if ($reqImage == '') {
                $reqImage = $reqTeam . 'logo std.png';
            }
            $wikiimage = 'File:' . $reqImage;
            $imagetitle = Title::newFromText($wikiimage);
            $imagewikipage = new WikiFilePage($imagetitle);
            $imagefile = $imagewikipage->getFile();
            $test = $imagefile->exists();
            if ($reqTeam == '') {
                $e = wfMessage('createteams-create-teams-error-team-name-empty')->inContentLanguage()->text();
            } else {
                if (preg_match('/[a-z]*:\\/\\//', $reqTeam) == 1) {
                    $e = wfMessage('createteams-create-teams-error-team-name-url')->inContentLanguage()->text();
                } else {
                    if ($imagefile->exists() == false) {
                        $e = wfMessage('createteams-create-teams-error-image-not-found')->inContentLanguage()->text();
                    } else {
                        $lcname = strtolower($reqTeam);
                        $lcslug = strtolower($reqTeamslug);
                        if ($lcslug != '') {
                            $lcname = $lcslug;
                        }
                        $vars = array('name' => $reqTeam, 'shortname' => $reqTeamshort, 'link' => '', 'namewithlink' => '', 'image' => $reqImage);
                        if ($reqPagetitle != $reqTeam && $reqPagetitle != '') {
                            $vars['namewithlink'] = '[[' . $reqPagetitle . '|' . $reqTeam . ']]';
                            $vars['link'] = $reqPagetitle;
                        } else {
                            $vars['namewithlink'] = '[[' . $reqTeam . ']]';
                            $vars['link'] = $reqTeam;
                        }
                        if ($vars['image'] == '') {
                            $vars['image'] = $reqTeam . 'logo_std.png';
                        }
                        foreach ($this->templates as $prefix => $template) {
                            $contents["Template:{$prefix}/{$lcname}"] = self::makeTeamTemplate($template, $vars);
                        }
                        $preview = '{| class="createteams-preview"' . "\n";
                        foreach ($contents as $key => $value) {
                            $title = Title::newFromText($key);
                            $page = WikiPage::factory($title);
                            $content = \ContentHandler::makeContent($value, $page->getTitle(), CONTENT_MODEL_WIKITEXT);
                            if ($request->getBool('createpreviewbutton')) {
                                $preview .= '|-' . "\n" . '![[' . $key . ']]' . "\n" . '|' . $value . "\n";
                            } else {
                                $errors = $title->getUserPermissionsErrors('edit', $wgUser);
                                if (!$title->exists()) {
                                    $errors = array_merge($errors, $title->getUserPermissionsErrors('create', $wgUser));
                                }
                                if (count($errors)) {
                                    $e .= '*' . wfMessage('createteams-create-error-permission')->params($key)->inContentLanguage()->text() . "\n";
                                } else {
                                    if ($title->exists()) {
                                        if ($reqOverwrite) {
                                            $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-edit')->inContentLanguage()->text(), EDIT_UPDATE, false, $wgUser, null);
                                            if ($status->isOK()) {
                                                $log .= '*' . wfMessage('createteams-create-log-edit-success')->params($key)->inContentLanguage()->text() . "\n";
                                            } else {
                                                $e .= '*' . wfMessage('createteams-create-error-edit')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                            }
                                        } else {
                                            $e .= '*' . wfMessage('createteams-create-error-edit-already-exists')->params($key)->inContentLanguage()->text() . "\n";
                                        }
                                    } else {
                                        $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-creation')->inContentLanguage()->text(), EDIT_NEW, false, $wgUser, null);
                                        if ($status->isOK()) {
                                            $log .= '*' . wfMessage('createteams-create-log-create-success')->params($key)->inContentLanguage()->text() . "\n";
                                        } else {
                                            $e .= '*' . wfMessage('createteams-create-error-create')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                        }
                                    }
                                }
                            }
                        }
                        $preview .= '|}';
                    }
                }
            }
            if ($e == '') {
                $report = wfMessage('createteams-create-teams-report-success')->params(htmlspecialchars($reqTeam))->inContentLanguage()->text();
            } else {
                $report = $e;
            }
            $report .= '<div class="log">' . "\n" . $log . '</div>';
            if ($request->getBool('createpreviewbutton')) {
                $output->addWikiText('===' . wfMessage('createteams-preview-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($preview);
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            } else {
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            }
        }
        $reqHistoricaltemplate = $request->getText('historicaltemplate');
        $reqHistoricalteam = $request->getArray('historicalteam');
        $reqHistoricaltime = $request->getArray('historicaltime');
        if (is_array($reqHistoricalteam)) {
            foreach ($reqHistoricalteam as $index => $value) {
                if ($value == '') {
                    unset($reqHistoricalteam[$index]);
                }
            }
            $reqHistoricalteam = array_values($reqHistoricalteam);
        }
        if (is_array($reqHistoricaltime)) {
            foreach ($reqHistoricaltime as $index => $value) {
                if ($value == '') {
                    unset($reqHistoricaltime[$index]);
                }
            }
            $reqHistoricaltime = array_values($reqHistoricaltime);
        }
        $reqHistoricalteamlength = count($reqHistoricalteam);
        $reqHistoricaltimelength = count($reqHistoricaltime);
        $reqHistoricaloverwrite = $request->getBool('historicaloverwrite');
        $output->addWikiText('==' . wfMessage('createteams-create-historicalteam-heading')->inContentLanguage()->text() . '==');
        $historicalteamform = '<form name="createhistoricalform" id="createhistoricalform" method="post">
<table>
	<tr>
		<td> </td>
		<td colspan="2" class="input-helper">' . wfMessage('createteams-create-teams-historicaltemplate-info')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="historicaltemplate">' . wfMessage('createteams-create-teams-historicaltemplate-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="historicaltemplate" id="historicaltemplate" value="' . $reqHistoricaltemplate . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-historicaltemplate-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="historicalteam">' . wfMessage('createteams-create-teams-historicalteam-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="historicalteam[]" value="' . $reqHistoricalteam[0] . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-historicalteam-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="historicaltime">' . wfMessage('createteams-create-teams-historicaltime-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="historicaltime[]" value="' . $reqHistoricaltime[0] . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-historicaltime-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="historicalteam">' . wfMessage('createteams-create-teams-historicalteam-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="historicalteam[]" value="' . $reqHistoricalteam[1] . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-historicalteam-helper')->inContentLanguage()->parse() . '</td>
	</tr>';
        if ($reqHistoricalteamlength > 2) {
            for ($i = 2; $i < $reqHistoricalteamlength; $i++) {
                if ($reqHistoricaltime[$i - 1] != '' || $reqHistoricalteam[$i] != '') {
                    $historicalteamform .= '<tr>
						<td class="input-label"><label for="historicaltime">' . wfMessage('createteams-create-teams-historicaltime-label')->inContentLanguage()->parse() . '</label></td>
						<td class="input-container"><input type="text" name="historicaltime[]" value="' . $reqHistoricaltime[$i - 1] . '"></td>
						<td class="input-helper">' . wfMessage('createteams-create-teams-historicaltime-helper')->inContentLanguage()->parse() . '</td>
					</tr>
					<tr>
						<td class="input-label"><label for="historicalteam">' . wfMessage('createteams-create-teams-historicalteam-label')->inContentLanguage()->parse() . '</label></td>
						<td class="input-container"><input type="text" name="historicalteam[]" value="' . strtolower($reqHistoricalteam[$i]) . '"></td>
						<td class="input-helper">' . wfMessage('createteams-create-teams-historicalteam-helper')->inContentLanguage()->parse() . '</td>
					</tr>';
                }
            }
        }
        $historicalteamform .= '<tr id="historicaloverwriteline">
		<td class="input-label"><label for="historicaloverwrite">' . wfMessage('createteams-create-teams-historicaloverwrite-label')->inContentLanguage()->parse() . '</label></td>
		<td><input type="checkbox" name="historicaloverwrite" id="historicaloverwrite"' . ($reqHistoricaloverwrite ? ' checked=""' : '') . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-teams-historicaloverwrite-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td> </td>
		<td colspan="2">
			<input type="button" name="createhistoricaladd" id="createhistoricaladd" value="' . wfMessage('createteams-create-teams-historicaladd-button')->inContentLanguage()->text() . '"> 
			<input type="submit" name="createhistoricalbutton" value="' . wfMessage('createteams-create-teams-historicalcreate-button')->inContentLanguage()->text() . '"> 
			<input type="submit" name="createhistoricalpreviewbutton" value="' . wfMessage('createteams-create-teams-historicalpreview-button')->inContentLanguage()->text() . '">
		</td>
	</tr>
</table>
</form>';
        $output->addHTML($historicalteamform);
        if ($request->getBool('createhistoricalbutton') || $request->getBool('createhistoricalpreviewbutton')) {
            if ($reqHistoricalteamlength == $reqHistoricaltimelength + 1) {
                if ($reqHistoricaltemplate == '') {
                    $e = wfMessage('createteams-create-teams-error-team-name-empty')->inContentLanguage()->text();
                } else {
                    if (preg_match('/[a-z]*:\\/\\//', $reqHistoricaltemplate) == 1) {
                        $e = wfMessage('createteams-create-teams-error-team-name-url')->inContentLanguage()->text();
                    } else {
                        $lcname = strtolower($reqHistoricaltemplate);
                        foreach ($this->templates as $prefix => $template) {
                            $contents["Template:{$prefix}/{$lcname}"] = self::makeHistoricalTeamTemplate($prefix, $lcname, $reqHistoricalteam, $reqHistoricaltime, $reqHistoricalteamlength, $reqHistoricaltimelength);
                        }
                        $preview = '{| class="createteams-preview"' . "\n";
                        foreach ($contents as $key => $value) {
                            $title = Title::newFromText($key);
                            $page = WikiPage::factory($title);
                            $content = \ContentHandler::makeContent($value, $page->getTitle(), CONTENT_MODEL_WIKITEXT);
                            if ($request->getBool('createhistoricalpreviewbutton')) {
                                $preview .= '|-' . "\n" . '![[' . $key . ']]' . "\n" . '|' . $value . "\n";
                            } else {
                                $errors = $title->getUserPermissionsErrors('edit', $wgUser);
                                if (!$title->exists()) {
                                    $errors = array_merge($errors, $title->getUserPermissionsErrors('create', $wgUser));
                                }
                                if (count($errors)) {
                                    $e .= '*' . wfMessage('createteams-create-error-permission')->params($key)->inContentLanguage()->text() . "\n";
                                } else {
                                    if ($title->exists()) {
                                        if ($reqHistoricaloverwrite) {
                                            $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-edit')->inContentLanguage()->text(), EDIT_UPDATE, false, $wgUser, null);
                                            if ($status->isOK()) {
                                                $log .= '*' . wfMessage('createteams-create-log-edit-success')->params($key)->inContentLanguage()->text() . "\n";
                                            } else {
                                                $e .= '*' . wfMessage('createteams-create-error-edit')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                            }
                                        } else {
                                            $e .= '*' . wfMessage('createteams-create-error-edit-already-exists')->params($key)->inContentLanguage()->text() . "\n";
                                        }
                                    } else {
                                        $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-creation')->inContentLanguage()->text(), EDIT_NEW, false, $wgUser, null);
                                        if ($status->isOK()) {
                                            $log .= '*' . wfMessage('createteams-create-log-create-success')->params($key)->inContentLanguage()->text() . "\n";
                                        } else {
                                            $e .= '*' . wfMessage('createteams-create-error-create')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $preview .= '|}';
            } else {
                $e .= '*' . wfMessage('createteams-create-error-historical-number-error')->inContentLanguage()->text() . "\n";
            }
            if ($e == '') {
                $report = wfMessage('createteams-create-teams-report-success')->params(htmlspecialchars($reqHistoricaltemplate))->inContentLanguage()->text();
            } else {
                $report = $e;
            }
            $report .= '<div class="log">' . "\n" . $log . '</div>';
            if ($request->getBool('createhistoricalpreviewbutton')) {
                $output->addWikiText('===' . wfMessage('createteams-preview-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($preview);
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            } else {
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            }
        }
        // Redirects
        $reqRedirect = $request->getText('redirect');
        $reqRedirectteam = $request->getText('redirectteam');
        $reqRedirectoverwrite = $request->getText('redirectoverwrite');
        $output->addWikiText('==' . wfMessage('createteams-create-redirects-heading')->inContentLanguage()->text() . '==');
        $redirectform = '<form name="redirectform" method="post">
<table>
	<tr>
		<td class="input-label"><label for="redirect">' . wfMessage('createteams-create-redirects-redirect-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="redirect" id="redirect" value="' . $reqRedirect . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-redirects-redirect-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="redirectteam">' . wfMessage('createteams-create-redirects-redirectteam-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="redirectteam" id="redirectteam" value="' . $reqRedirectteam . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-redirects-redirectteam-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="redirectoverwrite">' . wfMessage('createteams-create-redirects-redirectoverwrite-label')->inContentLanguage()->parse() . '</label></td>
		<td><input type="checkbox" name="redirectoverwrite" id="redirectoverwrite"' . ($reqRedirectoverwrite ? ' checked=""' : '') . '"></td>
		<td class="input-helper">' . wfMessage('createteams-create-redirects-redirectoverwrite-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td> </td>
		<td colspan="2">
			<input type="submit" name="redirectbutton" value="' . wfMessage('createteams-create-redirects-create-button')->inContentLanguage()->text() . '"> 
			<input type="submit" name="redirectpreviewbutton" value="' . wfMessage('createteams-create-redirects-preview-button')->inContentLanguage()->text() . '">
		</td>
	</tr>
</table>
</form>';
        $output->addHTML($redirectform);
        if ($request->getBool('redirectbutton') || $request->getBool('redirectpreviewbutton')) {
            if ($reqRedirect == '' || $reqRedirectteam == '') {
                $e = wfMessage('createteams-create-redirects-error-source-or-destination-empty')->inContentLanguage()->text();
            } else {
                foreach (array_keys($this->templates) as $prefix) {
                    $contents["Template:{$prefix}/" . strtolower($reqRedirect)] = "#REDIRECT [[Template:{$prefix}/" . strtolower($reqRedirectteam) . "]]";
                }
                $preview = '{| class="createteams-preview"' . "\n";
                foreach ($contents as $key => $value) {
                    $title = Title::newFromText($key);
                    $page = WikiPage::factory($title);
                    $content = \ContentHandler::makeContent($value, $page->getTitle(), CONTENT_MODEL_WIKITEXT);
                    if ($request->getBool('redirectpreviewbutton')) {
                        $preview .= '|-' . "\n" . '![[' . $key . ']]' . "\n" . '|<nowiki>' . $value . '</nowiki>' . "\n";
                    } else {
                        $errors = $title->getUserPermissionsErrors('edit', $wgUser);
                        if (!$title->exists()) {
                            $errors = array_merge($errors, $title->getUserPermissionsErrors('create', $wgUser));
                        }
                        if (count($errors)) {
                            $e .= '*' . wfMessage('createteams-create-error-permission')->params($key)->inContentLanguage()->text() . "\n";
                        } else {
                            if ($title->exists()) {
                                if ($reqRedirectoverwrite) {
                                    $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-edit')->inContentLanguage()->text(), EDIT_UPDATE, false, $wgUser, null);
                                    if ($status->isOK()) {
                                        $log .= '*' . wfMessage('createteams-create-log-edit-success')->params($key)->inContentLanguage()->text() . "\n";
                                    } else {
                                        $e .= '*' . wfMessage('createteams-create-error-edit')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                    }
                                } else {
                                    $e .= '*' . wfMessage('createteams-create-error-edit-already-exists')->params($key)->inContentLanguage()->text() . "\n";
                                }
                            } else {
                                $status = $page->doeditcontent($content, wfMessage('createteams-create-summary-creation')->inContentLanguage()->text(), EDIT_NEW, false, $wgUser, null);
                                if ($status->isOK()) {
                                    $log .= '*' . wfMessage('createteams-create-log-create-success')->params($key)->inContentLanguage()->text() . "\n";
                                } else {
                                    $e .= '*' . wfMessage('createteams-create-error-create')->params($key)->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                }
                            }
                        }
                    }
                }
                $preview .= '|}';
            }
            if ($e == '') {
                $report = wfMessage('createteams-create-redirects-report-success')->params(array(htmlspecialchars($reqRedirect), htmlspecialchars($reqRedirectteam)))->inContentLanguage()->text();
            } else {
                $report = $e;
            }
            $report .= '<div class="log">' . "\n" . $log . '</div>';
            if ($request->getBool('redirectpreviewbutton')) {
                $output->addWikiText('===' . wfMessage('createteams-preview-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($preview);
            } else {
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            }
        }
        // Moves
        $reqMove = $request->getText('move');
        $reqMoveto = $request->getText('moveto');
        $output->addWikiText('==' . wfMessage('createteams-move-heading')->inContentLanguage()->text() . '==');
        $moveform = '<form name="moveform" method="post">
<table>
	<tr>
		<td class="input-label"><label for="move">' . wfMessage('createteams-move-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="move" id="move" value="' . $reqMove . '"></td>
		<td class="input-helper">' . wfMessage('createteams-move-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td class="input-label"><label for="moveto">' . wfMessage('createteams-move-moveto-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container"><input type="text" name="moveto" id="moveto" value="' . $reqMoveto . '"></td>
		<td class="input-helper">' . wfMessage('createteams-move-moveto-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td> </td>
		<td colspan="2">
			<input type="submit" name="movebutton" value="' . wfMessage('createteams-move-button')->inContentLanguage()->text() . '"> 
			<input type="submit" name="movepreviewbutton" value="' . wfMessage('createteams-move-preview-button')->inContentLanguage()->text() . '">
		</td>
	</tr>
</table>
</form>';
        $output->addHTML($moveform);
        if ($request->getBool('movebutton') || $request->getBool('movepreviewbutton')) {
            if ($reqMove == '' || $reqMoveto == '') {
                $e = wfMessage('createteams-move-error-source-or-destination-empty')->inContentLanguage()->text();
            } else {
                $preview = '{| class="createteams-preview"' . "\n";
                foreach (array_keys($this->templates) as $prefix) {
                    $oldTitle = Title::newFromText("Template:{$prefix}/" . strtolower($reqMove));
                    $newTitle = Title::newFromText("Template:{$prefix}/" . strtolower($reqMoveto));
                    if ($request->getBool('movepreviewbutton')) {
                        $preview .= '|-' . "\n" . "![[Template:{$prefix}/" . strtolower($reqMove) . ']]' . "\n" . '|&rarr;' . "\n" . "|[[Template:{$prefix}/" . strtolower($reqMoveto) . ']]' . "\n";
                    } else {
                        $errors = $oldTitle->getUserPermissionsErrors('move', $wgUser);
                        if (!$oldTitle->exists() || !$newTitle->exists()) {
                            $errors = array_merge($errors, $oldTitle->getUserPermissionsErrors('create', $wgUser));
                        }
                        if (count($errors)) {
                            $e .= '*' . wfMessage('createteams-move-error-permission')->params("Template:{$prefix}/" . strtolower($reqMove))->inContentLanguage()->text() . "\n";
                        } else {
                            if (!$oldTitle->exists()) {
                                $e .= '*' . wfMessage('createteams-move-error-source-does-not-exists')->params("Template:{$prefix}/" . strtolower($reqMove))->inContentLanguage()->text() . "\n";
                            } elseif ($newTitle->exists()) {
                                $e .= '*' . wfMessage('createteams-move-error-target-already-exists')->params("Template:{$prefix}/" . strtolower($reqMoveto))->inContentLanguage()->text() . "\n";
                            } else {
                                $movePage = new MovePage($oldTitle, $newTitle);
                                $status = $movePage->move($wgUser, wfMessage('createteams-move-summary')->inContentLanguage()->text(), false);
                                if ($status->isOK()) {
                                    $log .= '*' . wfMessage('createteams-move-log-create-success')->params("Template:{$prefix}/" . strtolower($reqMove), "Template:{$prefix}/" . strtolower($reqMoveto))->inContentLanguage()->text() . "\n";
                                } else {
                                    $e .= '*' . wfMessage('createteams-move-error-move')->params("Template:{$prefix}/" . strtolower($reqMove))->inContentLanguage()->text() . $status->getWikiText() . "\n";
                                }
                            }
                        }
                    }
                }
                $preview .= '|}';
            }
            if ($e == '') {
                $report = wfMessage('createteams-move-report-success')->params(array(htmlspecialchars($reqMove), htmlspecialchars($reqMoveto)))->inContentLanguage()->text();
            } else {
                $report = $e;
            }
            $report .= '<div class="log">' . "\n" . $log . '</div>';
            if ($request->getBool('movepreviewbutton')) {
                $output->addWikiText('===' . wfMessage('createteams-preview-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($preview);
            } else {
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            }
        }
        // Deletions
        if ($wgUser->isAllowed('delete')) {
            // stuff only admins are allowed to see
            $reqDeletepreviewteam = $request->getText('deletepreviewteam');
            $reqDeleteteam = $request->getText('deleteteam');
            $output->addWikiText('==' . wfMessage('createteams-delete-teams-heading')->inContentLanguage()->text() . '==');
            $deleteForm = '<form name="delete-form" method="post">
<table>
	<tr>
		<td class="input-label"><label for="deletepreviewteam">' . wfMessage('createteams-delete-teams-deletepreviewteam-label')->inContentLanguage()->parse() . '</label></td>
		<td class="input-container">
			<input type="text" name="deletepreviewteam" id="deletepreviewteam" value="' . $reqDeletepreviewteam . '">
		</td>
		<td class="input-helper">' . wfMessage('createteams-delete-teams-deletepreviewteam-helper')->inContentLanguage()->parse() . '</td>
	</tr>
	<tr>
		<td> </td>
		<td>
			<input type="submit" name="deletepreviewbutton" value="' . wfMessage('createteams-delete-teams-preview-button')->inContentLanguage()->text() . '">
		</td>
		<td class="input-helper">' . wfMessage('createteams-delete-teams-deletebutton-helper')->inContentLanguage()->parse() . '</td>
	</tr>
</table>
</form>';
            $output->addHTML($deleteForm);
            if ($request->getBool('deletebutton')) {
                if ($reqDeleteteam == '') {
                    $e = wfMessage('createteams-delete-teams-error-team-name-empty')->inContentLanguage()->text();
                } else {
                    foreach (array_keys($this->templates) as $prefix) {
                        $deltemplate[$prefix] = "Template:{$prefix}/" . strtolower($reqDeleteteam);
                    }
                    foreach ($deltemplate as $value) {
                        $title = Title::newFromText($value);
                        $page = WikiPage::factory($title);
                        $id = $page->getId();
                        $errors = $title->getUserPermissionsErrors('delete', $wgUser);
                        if (count($errors)) {
                            $e .= '*' . wfMessage('createteams-delete-error-permission')->params($value)->inContentLanguage()->text() . "\n";
                        } else {
                            if (!$title->exists()) {
                                $e .= '*' . wfMessage('createteams-delete-error-does-not-exist')->params($value)->inContentLanguage()->text() . "\n";
                            } else {
                                if ($page->doDeleteArticle(wfMessage('createteams-delete-summary-deletion')->inContentLanguage()->text(), false, $id, '', $wgUser)) {
                                    $log .= '*' . wfMessage('createteams-delete-log-deletion-success')->params($value)->inContentLanguage()->text() . "\n";
                                } else {
                                    $e .= '*' . wfMessage('createteams-delete-error-deletion')->params($value)->inContentLanguage()->text() . "\n";
                                }
                            }
                        }
                    }
                }
                if ($e == '') {
                    $report = $report = wfMessage('createteams-delete-teams-report-success')->params(htmlspecialchars($reqDeleteteam))->inContentLanguage()->text();
                } else {
                    $report = $e;
                }
                $report .= '<div class="log">' . "\n" . $log . '</div>';
                $output->addWikiText('===' . wfMessage('createteams-report-heading')->inContentLanguage()->text() . '===');
                $output->addWikiText($report);
            } else {
                if ($request->getBool('deletepreviewbutton')) {
                    if ($reqDeletepreviewteam == '') {
                        $preview = wfMessage('createteams-delete-teams-error-team-name-empty')->inContentLanguage()->text();
                    } else {
                        foreach (array_keys($this->templates) as $prefix) {
                            $deltemplate[$prefix] = "Template:{$prefix}/" . strtolower($reqDeletepreviewteam);
                        }
                        foreach ($deltemplate as $value) {
                            $title = Title::newFromText($value);
                            $page = WikiPage::factory($title);
                            $id = $page->getId();
                            $errors = $title->getUserPermissionsErrors('delete', $wgUser);
                            if (count($errors)) {
                                $preview .= '*' . wfMessage('createteams-delete-error-permission')->params($value)->inContentLanguage()->text() . "\n";
                            } else {
                                if (!$title->exists()) {
                                    $preview .= '*' . wfMessage('createteams-delete-error-does-not-exist')->params($value)->inContentLanguage()->text() . "\n";
                                } else {
                                    $preview .= '*' . wfMessage('createteams-delete-teams-preview-deletion')->params($value)->inContentLanguage()->text() . "\n";
                                }
                            }
                        }
                    }
                    $output->addWikiText('===' . wfMessage('createteams-preview-heading')->inContentLanguage()->text() . '===');
                    $output->addWikiText($preview);
                    if ($reqDeletepreviewteam != '') {
                        $deleteConfirmForm = '<form name="delete-confirm-form" method="post">
	<input type="text" name="deleteteam" value="' . $reqDeletepreviewteam . '" readonly>
	<input type="submit" name="deletebutton" value="' . wfMessage('createteams-delete-teams-delete-button')->inContentLanguage()->text() . '">
	<p class="warning">' . wfMessage('createteams-delete-teams-warning-deletion')->params($value)->inContentLanguage()->text() . '</p>
</form>';
                        $output->addWikiText('===' . wfMessage('createteams-delete-teams-confirm-deletion-heading')->inContentLanguage()->text() . '===');
                        $output->addHTML($deleteConfirmForm);
                    }
                }
            }
        }
    }
Example #6
0
 /**
  * @see WikiFilePage::getForeignCategories
  * @return TitleArray|Title[]
  */
 public function getForeignCategories()
 {
     $this->mPage->getForeignCategories();
 }