/**
  * main()
  */
 public function execute($par)
 {
     global $wgOut;
     $fname = 'SpecialAdvancedRandom::execute';
     wfProfileIn($fname);
     list($page, $namespace) = $this->extractParamaters($par);
     $ft = Title::newFromText($page);
     if (is_null($ft)) {
         $this->redirect(Title::newMainPage());
         wfProfileOut($fname);
         return;
     }
     $rand = wfRandom();
     $dbr = wfGetDB(DB_SLAVE);
     if ($ft->getNamespace() == NS_TEMPLATE) {
         $res = $dbr->selectRow(array('page', 'templatelinks'), array('page_namespace', 'page_title', 'page_random'), array('page_id = tl_from', 'tl_namespace' => NS_TEMPLATE, 'page_namespace' => $namespace, 'tl_title' => $ft->getDBkey(), "page_random > {$rand}"), $fname, array('ORDER BY' => 'page_random', 'USE INDEX' => array('page' => 'page_random')));
     } else {
         $res = $dbr->selectRow(array('page', 'pagelinks'), array('page_namespace', 'page_title', 'page_random'), array('page_id = pl_from', 'pl_namespace' => $ft->getNamespace(), 'page_namespace' => $namespace, 'pl_title' => $ft->getDBkey(), "page_random > {$rand}"), $fname, array('ORDER BY' => 'page_random', 'USE INDEX' => array('page' => 'page_random')));
     }
     $title =& Title::makeTitle(MWNamespace::getSubject($namespace), $res->page_title);
     if (is_null($title) || $title->getText() == '') {
         $title = Title::newMainPage();
     }
     $this->redirect($title);
     wfProfileOut($fname);
 }
 public static function onGetNotificationMessage($nc, &$msg, $isMain, $data, $authors, $userCount, $myName)
 {
     if (empty($data->article_title_ns) || MWNamespace::getSubject($data->article_title_ns) != NS_WIKIA_FORUM_BOARD) {
         return true;
     }
     if (!$isMain) {
         if ($data->parent_username == $myName) {
             $replyTo = "your";
         } else {
             $replyTo = "someone";
         }
         $secondUser = '';
         if ($userCount == 2) {
             $secondUser = $nc->getDisplayname($authors[1]['displayname']);
         }
         $params = [$nc->getDisplayname($data->msg_author_displayname), $secondUser, $data->article_title_text, $myName];
         // Messages that can be used here:
         // * forum-notification-user1-reply-to-your
         // * forum-notification-user2-reply-to-your
         // * forum-notification-user3-reply-to-your
         // * forum-notification-user1-reply-to-someone
         // * forum-notification-user2-reply-to-someone
         // * forum-notification-user3-reply-to-someone
         $msgKey = "forum-notification-user{$userCount}-reply-to-{$replyTo}";
     } else {
         $msgKey = 'forum-notification-newmsg-on-followed-wall';
         $params = [$nc->getDisplayname($data->msg_author_displayname), $data->wall_displayname];
     }
     $msg = wfMessage($msgKey, $params)->text();
     return true;
 }
 public function thread()
 {
     wfProfileIn(__METHOD__);
     $this->addAsset();
     $title = $this->request->getVal('title', $this->app->wg->Title);
     $id = $this->request->getVal('id', null);
     $this->getThread($id);
     $this->response->setVal('showNewMessage', false);
     $this->response->setVal('type', 'Thread');
     $this->response->setVal('condenseMessage', false);
     if (count($this->threads) > 0) {
         $wn = new WallNotifications();
         foreach ($this->threads as $key => $val) {
             $all = $wn->markRead($this->wg->User->getId(), $this->wg->CityId, $key);
             break;
         }
     }
     $this->response->setVal('renderUserTalkArchiveAnchor', false);
     $this->response->setVal('greeting', '');
     $title = Title::newFromId($id);
     if (!empty($title) && $title->exists() && in_array(MWNamespace::getSubject($title->getNamespace()), $this->app->wg->WallNS)) {
         $wallMessage = WallMessage::newFromTitle($title);
         $wallMessage->load();
         $this->app->wg->Out->setPageTitle($wallMessage->getMetaTitle());
     }
     // TODO: keep the varnish cache and do purging on post
     $this->response->setCacheValidity(WikiaResponse::CACHE_DISABLED);
     wfProfileOut(__METHOD__);
 }
 public function thread()
 {
     wfProfileIn(__METHOD__);
     $this->addAsset();
     $title = $this->request->getVal('title', $this->app->wg->Title);
     $id = $this->request->getVal('id', null);
     $this->getThread($id);
     $this->response->setVal('showNewMessage', false);
     $this->response->setVal('type', 'Thread');
     $this->response->setVal('condenseMessage', false);
     if (count($this->threads) > 0) {
         $wn = F::build('WallNotifications', array());
         foreach ($this->threads as $key => $val) {
             $all = $wn->markRead($this->wg->User->getId(), $this->wg->CityId, $key);
             break;
         }
     }
     $this->response->setVal('renderUserTalkArchiveAnchor', false);
     $this->response->setVal('greeting', '');
     $title = F::build('Title', array($id), 'newFromId');
     if (!empty($title) && $title->exists() && in_array(MWNamespace::getSubject($title->getNamespace()), $this->app->wg->WallNS)) {
         $wallMessage = F::build('WallMessage', array($title), 'newFromTitle');
         $wallMessage->load();
         $this->app->wg->Out->setPageTitle($wallMessage->getMetaTitle());
     }
     wfProfileOut(__METHOD__);
 }
예제 #5
0
 /**
  * @covers MWNamespace::getSubject
  */
 public function testGetSubject()
 {
     // Special namespaces are their own subjects
     $this->assertEquals(NS_MEDIA, MWNamespace::getSubject(NS_MEDIA));
     $this->assertEquals(NS_SPECIAL, MWNamespace::getSubject(NS_SPECIAL));
     $this->assertEquals(NS_MAIN, MWNamespace::getSubject(NS_TALK));
     $this->assertEquals(NS_USER, MWNamespace::getSubject(NS_USER_TALK));
 }
 public function onGetMailNotificationMessage($notification, &$data, $key, $watcherName, $author_signature, $textNoHtml, $text)
 {
     if (empty($notification->data->article_title_ns) || MWNamespace::getSubject($notification->data->article_title_ns) != NS_WIKIA_FORUM_BOARD) {
         return true;
     }
     $data = array('$WATCHER' => $watcherName, '$BOARDNAME' => $notification->data->article_title_text, '$WIKI' => $notification->data->wikiname, '$AUTHOR_NAME' => $notification->data->msg_author_displayname, '$AUTHOR' => $notification->data->msg_author_username, '$AUTHOR_SIGNATURE' => $author_signature, '$MAIL_SUBJECT' => wfMsg('forum-mail-notification-subject', array('$1' => $notification->data->thread_title, '$2' => $notification->data->wikiname)), '$METATITLE' => $notification->data->thread_title, '$MESSAGE_LINK' => $notification->data->url, '$MESSAGE_NO_HTML' => $textNoHtml, '$MESSAGE_HTML' => $text, '$MSG_KEY_SUBJECT' => 'forum-' . $key, '$MSG_KEY_BODY' => 'forum-mail-notification-body', '$MSG_KEY_GREETING' => 'forum-mail-notification-html-greeting');
     return true;
 }
예제 #7
0
 /**
  * change the message in WikiActivity for forum namespace
  */
 public function onAfterWallWikiActivityFilter(&$item, $wmessage)
 {
     if (!empty($item['ns']) && MWNamespace::getSubject($item['ns']) == NS_WIKIA_FORUM_BOARD) {
         $app = F::App();
         $board = $wmessage->getArticleTitle();
         $item['wall-msg'] = wfMsg('forum-wiki-activity-msg', '<a href="' . $board->getFullURL() . '">' . wfMsg('forum-wiki-activity-msg-name', $board->getText()) . '</a>');
     }
     return true;
 }
예제 #8
0
 /**
  * Same as addFavorite, only the opposite.
  * @return bool
  */
 public function removeFavorite()
 {
     $success = false;
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('favoritelist', array('fl_user' => $this->id, 'fl_namespace' => MWNamespace::getSubject($this->ns), 'fl_title' => $this->ti), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     return $success;
 }
예제 #9
0
function getParentPage($articleComment)
{
    $titleText = $articleComment->getTitle()->getDBkey();
    $parts = explode('/@', $titleText);
    $titleText = $parts[0];
    $namespace = MWNamespace::getSubject($articleComment->getTitle()->getNamespace());
    $title = Title::newFromText($titleText, $namespace);
    if ($title instanceof Title) {
        // create message wall if not exist
        if (!$title->exists() && $namespace == NS_USER_WALL) {
            $title = WallMessage::addMessageWall($title);
            echo ".....Wall message NOT found.\n\tAdded wall message '{$titleText}' (" . $title->getArticleID() . ")";
            return $title->getArticleId();
        }
    }
    return $title->getArticleID();
}
예제 #10
0
 /**
  * Same as addWatch, only the opposite.
  * @return bool
  */
 public function removeWatch()
 {
     $success = false;
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('watchlist', array('wl_user' => $this->id, 'wl_namespace' => MWNamespace::getSubject($this->ns), 'wl_title' => $this->ti), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     # the following code compensates the new behaviour, introduced by the
     # enotif patch, that every single watched page needs now to be listed
     # in watchlist namespace:page and namespace_talk:page had separate
     # entries: clear them
     $dbw->delete('watchlist', array('wl_user' => $this->id, 'wl_namespace' => MWNamespace::getTalk($this->ns), 'wl_title' => $this->ti), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     return $success;
 }
예제 #11
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgNonincludableNamespaces;
     $lib = array('loadSiteStats' => array($this, 'loadSiteStats'), 'getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !($wgNonincludableNamespaces && in_array($ns, $wgNonincludableNamespaces)), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->text();
         self::$namespacesCache = $namespaces;
     }
     $info['namespaces'] = self::$namespacesCache;
     if (self::$siteStatsLoaded) {
         $stats = $this->loadSiteStats();
         $info['stats'] = $stats[0];
     }
     $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
예제 #12
0
 function register()
 {
     global $wgContLang, $wgNamespaceAliases, $wgDisableCounters;
     $lib = array('getNsIndex' => array($this, 'getNsIndex'), 'pagesInCategory' => array($this, 'pagesInCategory'), 'pagesInNamespace' => array($this, 'pagesInNamespace'), 'usersInGroup' => array($this, 'usersInGroup'), 'interwikiMap' => array($this, 'interwikiMap'));
     $info = array('siteName' => $GLOBALS['wgSitename'], 'server' => $GLOBALS['wgServer'], 'scriptPath' => $GLOBALS['wgScriptPath'], 'stylePath' => $GLOBALS['wgStylePath'], 'currentVersion' => SpecialVersion::getVersion());
     if (!self::$namespacesCache || self::$namespacesCacheLang !== $wgContLang->getCode()) {
         $namespaces = array();
         $namespacesByName = array();
         foreach ($wgContLang->getFormattedNamespaces() as $ns => $title) {
             $canonical = MWNamespace::getCanonicalName($ns);
             $namespaces[$ns] = array('id' => $ns, 'name' => $title, 'canonicalName' => strtr($canonical, '_', ' '), 'hasSubpages' => MWNamespace::hasSubpages($ns), 'hasGenderDistinction' => MWNamespace::hasGenderDistinction($ns), 'isCapitalized' => MWNamespace::isCapitalized($ns), 'isContent' => MWNamespace::isContent($ns), 'isIncludable' => !MWNamespace::isNonincludable($ns), 'isMovable' => MWNamespace::isMovable($ns), 'isSubject' => MWNamespace::isSubject($ns), 'isTalk' => MWNamespace::isTalk($ns), 'defaultContentModel' => MWNamespace::getNamespaceContentModel($ns), 'aliases' => array());
             if ($ns >= NS_MAIN) {
                 $namespaces[$ns]['subject'] = MWNamespace::getSubject($ns);
                 $namespaces[$ns]['talk'] = MWNamespace::getTalk($ns);
                 $namespaces[$ns]['associated'] = MWNamespace::getAssociated($ns);
             } else {
                 $namespaces[$ns]['subject'] = $ns;
             }
             $namespacesByName[strtr($title, ' ', '_')] = $ns;
             if ($canonical) {
                 $namespacesByName[$canonical] = $ns;
             }
         }
         $aliases = array_merge($wgNamespaceAliases, $wgContLang->getNamespaceAliases());
         foreach ($aliases as $title => $ns) {
             if (!isset($namespacesByName[$title]) && isset($namespaces[$ns])) {
                 $ct = count($namespaces[$ns]['aliases']);
                 $namespaces[$ns]['aliases'][$ct + 1] = $title;
                 $namespacesByName[$title] = $ns;
             }
         }
         $namespaces[NS_MAIN]['displayName'] = wfMessage('blanknamespace')->inContentLanguage()->text();
         self::$namespacesCache = $namespaces;
         self::$namespacesCacheLang = $wgContLang->getCode();
     }
     $info['namespaces'] = self::$namespacesCache;
     $info['stats'] = array('pages' => (int) SiteStats::pages(), 'articles' => (int) SiteStats::articles(), 'files' => (int) SiteStats::images(), 'edits' => (int) SiteStats::edits(), 'views' => $wgDisableCounters ? null : (int) SiteStats::views(), 'users' => (int) SiteStats::users(), 'activeUsers' => (int) SiteStats::activeUsers(), 'admins' => (int) SiteStats::numberingroup('sysop'));
     return $this->getEngine()->registerInterface('mw.site.lua', $lib, $info);
 }
예제 #13
0
 /**
  * Regenerate / invalidate service cache for current page
  */
 public function regenerateData()
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": page #{$this->pageId}\n");
     // invalidate cached data from getMostLinkedCategories()
     $wgMemc->delete($this->getKey('mostlinkedcategories'));
     // invalidate cached data from getCurrentRevision()
     $wgMemc->delete($this->getKey('current-revision'));
     // invalidate cached data from getPreviousEdits()
     $wgMemc->delete($this->getKey('previous-edits'));
     // invalidate cached data from getCommentsCount()
     $title = Title::newFromId($this->pageId, Title::GAID_FOR_UPDATE);
     if (!empty($title)) {
         $pageName = $title->getPrefixedText();
         wfDebug(__METHOD__ . ": page '{$pageName}' has been touched\n");
         // invalidate cache with number of comments / talk page revisions
         if ($title->isTalkPage()) {
             if (self::isArticleCommentsEnabled() && ArticleComment::isTitleComment($title)) {
                 // get subject page for this article comment
                 $parts = ArticleComment::explode($title->getText());
                 $title = Title::newFromText($parts['title'], MWNamespace::getSubject($title->getNamespace()));
                 wfDebug(__METHOD__ . ": article comment added\n");
             } else {
                 // get subject page for this talk page
                 $title = $title->getSubjectPage();
             }
             $contentPageName = $title->getPrefixedText();
             wfDebug(__METHOD__ . ": talk page / article comment for '{$contentPageName}' has been touched\n");
             $contentPageService = new self($title->getArticleId());
             $contentPageService->regenerateCommentsCount();
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
예제 #14
0
 /**
  * Same as addWatch, only the opposite.
  * @return bool
  */
 public function removeWatch()
 {
     wfProfileIn(__METHOD__);
     // Only loggedin user can have a watchlist
     if (wfReadOnly() || $this->mUser->isAnon() || !$this->isAllowed('editmywatchlist')) {
         wfProfileOut(__METHOD__);
         return false;
     }
     $success = false;
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('watchlist', array('wl_user' => $this->getUserId(), 'wl_namespace' => MWNamespace::getSubject($this->getTitleNs()), 'wl_title' => $this->getTitleDBkey()), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     # the following code compensates the new behavior, introduced by the
     # enotif patch, that every single watched page needs now to be listed
     # in watchlist namespace:page and namespace_talk:page had separate
     # entries: clear them
     $dbw->delete('watchlist', array('wl_user' => $this->getUserId(), 'wl_namespace' => MWNamespace::getTalk($this->getTitleNs()), 'wl_title' => $this->getTitleDBkey()), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     $this->watched = false;
     wfProfileOut(__METHOD__);
     return $success;
 }
예제 #15
0
	/**
	 * Generates the power search box at [[Special:Search]]
	 *
	 * @param string $term search term
	 * @param $opts array
	 * @return String: HTML form
	 */
	protected function powerSearchBox( $term, $opts ) {
		global $wgContLang;

		// Groups namespaces into rows according to subject
		$rows = array();
		foreach ( SearchEngine::searchableNamespaces() as $namespace => $name ) {
			$subject = MWNamespace::getSubject( $namespace );
			if ( !array_key_exists( $subject, $rows ) ) {
				$rows[$subject] = "";
			}

			$name = $wgContLang->getConverter()->convertNamespace( $namespace );
			if ( $name == '' ) {
				$name = $this->msg( 'blanknamespace' )->text();
			}

			$rows[$subject] .=
				Xml::openElement(
					'td', array( 'style' => 'white-space: nowrap' )
				) .
				Xml::checkLabel(
					$name,
					"ns{$namespace}",
					"mw-search-ns{$namespace}",
					in_array( $namespace, $this->namespaces )
				) .
				Xml::closeElement( 'td' );
		}

		$rows = array_values( $rows );
		$numRows = count( $rows );

		// Lays out namespaces in multiple floating two-column tables so they'll
		// be arranged nicely while still accommodating different screen widths
		$namespaceTables = '';
		for ( $i = 0; $i < $numRows; $i += 4 ) {
			$namespaceTables .= Xml::openElement(
				'table',
				array( 'cellpadding' => 0, 'cellspacing' => 0 )
			);

			for ( $j = $i; $j < $i + 4 && $j < $numRows; $j++ ) {
				$namespaceTables .= Xml::tags( 'tr', null, $rows[$j] );
			}

			$namespaceTables .= Xml::closeElement( 'table' );
		}

		$showSections = array( 'namespaceTables' => $namespaceTables );

		// Show redirects check only if backend supports it
		if ( $this->getSearchEngine()->supports( 'list-redirects' ) ) {
			$showSections['redirects'] =
				Xml::checkLabel( $this->msg( 'powersearch-redir' )->text(), 'redirs', 'redirs', $this->searchRedirects );
		}

		wfRunHooks( 'SpecialSearchPowerBox', array( &$showSections, $term, $opts ) );

		$hidden = '';
		unset( $opts['redirs'] );
		foreach ( $opts as $key => $value ) {
			$hidden .= Html::hidden( $key, $value );
		}
		// Return final output
		return Xml::openElement(
				'fieldset',
				array( 'id' => 'mw-searchoptions', 'style' => 'margin:0em;' )
			) .
			Xml::element( 'legend', null, $this->msg( 'powersearch-legend' )->text() ) .
			Xml::tags( 'h4', null, $this->msg( 'powersearch-ns' )->parse() ) .
			Html::element( 'div', array( 'id' => 'mw-search-togglebox' ) ) .
			Xml::element( 'div', array( 'class' => 'divider' ), '', false ) .
			implode( Xml::element( 'div', array( 'class' => 'divider' ), '', false ), $showSections ) .
			$hidden .
			Xml::closeElement( 'fieldset' );
	}
	/**
	 * Copied almost exactly from MediaWiki's SpecialSearch class, i.e.
	 * the search page
	 */
	function namespaceTables( $namespaces, $rowsPerTable = 3 ) {
		global $wgContLang;
		// Group namespaces into rows according to subject.
		// Try not to make too many assumptions about namespace numbering.
		$rows = array();
		$tables = "";
		foreach ( $namespaces as $ns => $name ) {
			$subj = MWNamespace::getSubject( $ns );
			if ( !array_key_exists( $subj, $rows ) ) {
				$rows[$subj] = "";
			}
			$name = str_replace( '_', ' ', $name );
			if ( '' == $name ) {
				$name = wfMsg( 'blanknamespace' );
			}
			$rows[$subj] .= Xml::openElement( 'td', array( 'style' => 'white-space: nowrap' ) ) .
				Xml::checkLabel( $name, "ns{$ns}", "mw-search-ns{$ns}", in_array( $ns, $namespaces ) ) .
				Xml::closeElement( 'td' ) . "\n";
		}
		$rows = array_values( $rows );
		$numRows = count( $rows );
		// Lay out namespaces in multiple floating two-column tables so they'll
		// be arranged nicely while still accommodating different screen widths
		// Float to the right on RTL wikis
		$tableStyle = $wgContLang->isRTL() ?
			'float: right; margin: 0 0 0em 1em' : 'float: left; margin: 0 1em 0em 0';
		// Build the final HTML table...
		for ( $i = 0; $i < $numRows; $i += $rowsPerTable ) {
			$tables .= Xml::openElement( 'table', array( 'style' => $tableStyle ) );
			for ( $j = $i; $j < $i + $rowsPerTable && $j < $numRows; $j++ ) {
				$tables .= "<tr>\n" . $rows[$j] . "</tr>";
			}
			$tables .= Xml::closeElement( 'table' ) . "\n";
		}
		return $tables;
	}
예제 #17
0
 /**
  * Builds an array with tab definition
  *
  * @param Title $title Page Where the tab links to
  * @param string|array $message Message key or an array of message keys (will fall back)
  * @param bool $selected Display the tab as selected
  * @param string $query Query string attached to tab URL
  * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
  *
  * @return array
  */
 function tabAction($title, $message, $selected, $query = '', $checkEdit = false)
 {
     $classes = array();
     if ($selected) {
         $classes[] = 'selected';
     }
     if ($checkEdit && !$title->isKnown()) {
         $classes[] = 'new';
         if ($query !== '') {
             $query = 'action=edit&redlink=1&' . $query;
         } else {
             $query = 'action=edit&redlink=1';
         }
     }
     // wfMessageFallback will nicely accept $message as an array of fallbacks
     // or just a single key
     $msg = wfMessageFallback($message)->setContext($this->getContext());
     if (is_array($message)) {
         // for hook compatibility just keep the last message name
         $message = end($message);
     }
     if ($msg->exists()) {
         $text = $msg->text();
     } else {
         global $wgContLang;
         $text = $wgContLang->getConverter()->convertNamespace(MWNamespace::getSubject($title->getNamespace()));
     }
     $result = array();
     if (!Hooks::run('SkinTemplateTabAction', array(&$this, $title, $message, $selected, $checkEdit, &$classes, &$query, &$text, &$result))) {
         return $result;
     }
     return array('class' => implode(' ', $classes), 'text' => $text, 'href' => $title->getLocalURL($query), 'primary' => true);
 }
예제 #18
0
파일: Title.php 프로젝트: ErdemA/wikihow
 /**
  * Get a title object associated with the subject page of this
  * talk page
  *
  * @return Title the object for the subject page
  */
 public function getSubjectPage()
 {
     return Title::makeTitle(MWNamespace::getSubject($this->getNamespace()), $this->getDBkey());
 }
예제 #19
0
 /**
  * Add a list of targets to a user's watchlist
  *
  * @param string[]|LinkTarget[] $targets
  */
 private function watchTitles($targets)
 {
     $expandedTargets = [];
     foreach ($targets as $target) {
         if (!$target instanceof LinkTarget) {
             try {
                 $target = $this->titleParser->parseTitle($target, NS_MAIN);
             } catch (MalformedTitleException $e) {
                 continue;
             }
         }
         $ns = $target->getNamespace();
         $dbKey = $target->getDBkey();
         $expandedTargets[] = new TitleValue(MWNamespace::getSubject($ns), $dbKey);
         $expandedTargets[] = new TitleValue(MWNamespace::getTalk($ns), $dbKey);
     }
     MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser($this->getUser(), $expandedTargets);
 }
예제 #20
0
 /**
  * Generate strings used for xml 'id' names in monobook tabs
  *
  * @param string $prepend Defaults to 'nstab-'
  * @return string XML 'id' name
  */
 public function getNamespaceKey($prepend = 'nstab-')
 {
     global $wgContLang;
     // Gets the subject namespace if this title
     $namespace = MWNamespace::getSubject($this->getNamespace());
     // Checks if canonical namespace name exists for namespace
     if (MWNamespace::exists($this->getNamespace())) {
         // Uses canonical namespace name
         $namespaceKey = MWNamespace::getCanonicalName($namespace);
     } else {
         // Uses text of namespace
         $namespaceKey = $this->getSubjectNsText();
     }
     // Makes namespace key lowercase
     $namespaceKey = $wgContLang->lc($namespaceKey);
     // Uses main
     if ($namespaceKey == '') {
         $namespaceKey = 'main';
     }
     // Changes file to image for backwards compatibility
     if ($namespaceKey == 'file') {
         $namespaceKey = 'image';
     }
     return $prepend . $namespaceKey;
 }
예제 #21
0
 /**
  * Generates the power search box at [[Special:Search]]
  *
  * @param string $term Search term
  * @param array $opts
  * @return string HTML form
  */
 protected function powerSearchBox($term, $opts)
 {
     global $wgContLang;
     // Groups namespaces into rows according to subject
     $rows = array();
     foreach (SearchEngine::searchableNamespaces() as $namespace => $name) {
         $subject = MWNamespace::getSubject($namespace);
         if (!array_key_exists($subject, $rows)) {
             $rows[$subject] = "";
         }
         $name = $wgContLang->getConverter()->convertNamespace($namespace);
         if ($name == '') {
             $name = $this->msg('blanknamespace')->text();
         }
         $rows[$subject] .= Xml::openElement('td') . Xml::checkLabel($name, "ns{$namespace}", "mw-search-ns{$namespace}", in_array($namespace, $this->namespaces)) . Xml::closeElement('td');
     }
     $rows = array_values($rows);
     $numRows = count($rows);
     // Lays out namespaces in multiple floating two-column tables so they'll
     // be arranged nicely while still accommodating different screen widths
     $namespaceTables = '';
     for ($i = 0; $i < $numRows; $i += 4) {
         $namespaceTables .= Xml::openElement('table', array('cellpadding' => 0, 'cellspacing' => 0));
         for ($j = $i; $j < $i + 4 && $j < $numRows; $j++) {
             $namespaceTables .= Xml::tags('tr', null, $rows[$j]);
         }
         $namespaceTables .= Xml::closeElement('table');
     }
     $showSections = array('namespaceTables' => $namespaceTables);
     wfRunHooks('SpecialSearchPowerBox', array(&$showSections, $term, $opts));
     $hidden = '';
     foreach ($opts as $key => $value) {
         $hidden .= Html::hidden($key, $value);
     }
     # Stuff to feed saveNamespaces()
     $remember = '';
     $user = $this->getUser();
     if ($user->isLoggedIn()) {
         $remember .= Xml::checkLabel(wfMessage('powersearch-remember')->text(), 'nsRemember', 'mw-search-powersearch-remember', false, array('value' => $user->getEditToken('searchnamespace', $this->getRequest())));
     }
     // Return final output
     return Xml::openElement('fieldset', array('id' => 'mw-searchoptions')) . Xml::element('legend', null, $this->msg('powersearch-legend')->text()) . Xml::tags('h4', null, $this->msg('powersearch-ns')->parse()) . Xml::element('div', array('id' => 'mw-search-togglebox'), '', false) . Xml::element('div', array('class' => 'divider'), '', false) . implode(Xml::element('div', array('class' => 'divider'), '', false), $showSections) . $hidden . Xml::element('div', array('class' => 'divider'), '', false) . $remember . Xml::closeElement('fieldset');
 }
예제 #22
0
 function upgradeWatchlist()
 {
     $chunksize = 100;
     list($watchlist, $watchlist_temp) = $this->dbw->tableNamesN('watchlist', 'watchlist_temp');
     $this->log('Migrating watchlist table to watchlist_temp...');
     $this->dbw->query("CREATE TABLE {$watchlist_temp} (\n  -- Key to user_id\n  wl_user int(5) unsigned NOT NULL,\n\n  -- Key to page_namespace/page_title\n  -- Note that users may watch patches which do not exist yet,\n  -- or existed in the past but have been deleted.\n  wl_namespace int NOT NULL default '0',\n  wl_title varchar(255) binary NOT NULL default '',\n\n  -- Timestamp when user was last sent a notification e-mail;\n  -- cleared when the user visits the page.\n  -- FIXME: add proper null support etc\n  wl_notificationtimestamp varchar(14) binary NOT NULL default '0',\n\n  UNIQUE KEY (wl_user, wl_namespace, wl_title),\n  KEY namespace_title (wl_namespace,wl_title)\n\n) TYPE=InnoDB;", __METHOD__);
     // Fix encoding for Latin-1 upgrades, add some fields,
     // and double article to article+talk pairs
     $numwatched = $this->dbw->selectField('watchlist', 'count(*)', '', __METHOD__);
     $this->setChunkScale($chunksize, $numwatched * 2, 'watchlist_temp', __METHOD__);
     $result = $this->dbr->select('watchlist', array('wl_user', 'wl_namespace', 'wl_title'), '', __METHOD__);
     $add = array();
     foreach ($result as $row) {
         $add[] = array('wl_user' => $row->wl_user, 'wl_namespace' => MWNamespace::getSubject($row->wl_namespace), 'wl_title' => $this->conv($row->wl_title), 'wl_notificationtimestamp' => '0');
         $this->addChunk($add);
         $add[] = array('wl_user' => $row->wl_user, 'wl_namespace' => MWNamespace::getTalk($row->wl_namespace), 'wl_title' => $this->conv($row->wl_title), 'wl_notificationtimestamp' => '0');
         $this->addChunk($add);
     }
     $this->lastChunk($add);
     $this->log('Done converting watchlist.');
     $this->cleanupSwaps[] = 'watchlist';
 }
예제 #23
0
 /**
  * get Title object of article page
  *
  * @access public
  */
 public function getArticleTitle()
 {
     if (!isset($this->mTitle)) {
         return null;
     }
     $title = null;
     $parts = self::explode($this->mTitle->getDBkey());
     if ($parts['title'] != '') {
         $title = Title::makeTitle(MWNamespace::getSubject($this->mNamespace), $parts['title']);
     }
     return $title;
 }
예제 #24
0
 public function onArticleBeforeVote(&$user_id, &$page, $vote)
 {
     $app = F::app();
     $title = Title::newFromId($page);
     if ($title instanceof Title && in_array(MWNamespace::getSubject($title->getNamespace()), $app->wg->WallNS)) {
         return false;
     }
     return true;
 }
 public static function onArticleRobotPolicy(&$policy, Title $title)
 {
     $ns = MWNamespace::getSubject($title->getNamespace());
     if (in_array($ns, [NS_MEDIAWIKI, NS_TEMPLATE])) {
         $policy = ['index' => 'noindex', 'follow' => 'follow'];
     }
     return true;
 }
예제 #26
0
 /**
  * Get talk page IDs (if requested) and subject page IDs (if requested)
  * and put them in $talkids and $subjectids 
  */
 private function getTSIDs()
 {
     $getTitles = $this->talkids = $this->subjectids = array();
     $db = $this->getDB();
     foreach ($this->everything as $t) {
         if (MWNamespace::isTalk($t->getNamespace())) {
             if ($this->fld_subjectid) {
                 $getTitles[] = $t->getSubjectPage();
             }
         } else {
             if ($this->fld_talkid) {
                 $getTitles[] = $t->getTalkPage();
             }
         }
     }
     if (!count($getTitles)) {
         return;
     }
     // Construct a custom WHERE clause that matches
     // all titles in $getTitles
     $lb = new LinkBatch($getTitles);
     $this->resetQueryParams();
     $this->addTables('page');
     $this->addFields(array('page_title', 'page_namespace', 'page_id'));
     $this->addWhere($lb->constructSet('page', $db));
     $res = $this->select(__METHOD__);
     while ($row = $db->fetchObject($res)) {
         if (MWNamespace::isTalk($row->page_namespace)) {
             $this->talkids[MWNamespace::getSubject($row->page_namespace)][$row->page_title] = intval($row->page_id);
         } else {
             $this->subjectids[MWNamespace::getTalk($row->page_namespace)][$row->page_title] = intval($row->page_id);
         }
     }
 }
 /**
  * Remove a list of titles from a user's watchlist
  *
  * $titles can be an array of strings or Title objects; the former
  * is preferred, since Titles are very memory-heavy
  *
  * @param array $titles Array of strings, or Title objects
  */
 private function unwatchTitles($titles)
 {
     $dbw = wfGetDB(DB_MASTER);
     foreach ($titles as $title) {
         if (!$title instanceof Title) {
             $title = Title::newFromText($title);
         }
         if ($title instanceof Title) {
             $dbw->delete('watchlist', array('wl_user' => $this->getUser()->getId(), 'wl_namespace' => MWNamespace::getSubject($title->getNamespace()), 'wl_title' => $title->getDBkey()), __METHOD__);
             $dbw->delete('watchlist', array('wl_user' => $this->getUser()->getId(), 'wl_namespace' => MWNamespace::getTalk($title->getNamespace()), 'wl_title' => $title->getDBkey()), __METHOD__);
             $page = WikiPage::factory($title);
             Hooks::run('UnwatchArticleComplete', array($this->getUser(), &$page));
         }
     }
 }
 /**
  * Generates the power search box at bottom of [[Special:Search]]
  * @param $term string: search term
  * @return $out string: HTML form
  */
 protected function powerSearchBox($term)
 {
     global $wgScript, $wgContLang;
     // Groups namespaces into rows according to subject
     $rows = array();
     foreach (SearchEngine::searchableNamespaces() as $namespace => $name) {
         $subject = MWNamespace::getSubject($namespace);
         if (!array_key_exists($subject, $rows)) {
             $rows[$subject] = "";
         }
         $name = str_replace('_', ' ', $name);
         if ($name == '') {
             $name = wfMsg('blanknamespace');
         }
         $rows[$subject] .= Xml::openElement('td', array('style' => 'white-space: nowrap')) . Xml::checkLabel($name, "ns{$namespace}", "mw-search-ns{$namespace}", in_array($namespace, $this->namespaces)) . Xml::closeElement('td');
     }
     $rows = array_values($rows);
     $numRows = count($rows);
     // Lays out namespaces in multiple floating two-column tables so they'll
     // be arranged nicely while still accommodating different screen widths
     $namespaceTables = '';
     for ($i = 0; $i < $numRows; $i += 4) {
         $namespaceTables .= Xml::openElement('table', array('cellpadding' => 0, 'cellspacing' => 0, 'border' => 0));
         for ($j = $i; $j < $i + 4 && $j < $numRows; $j++) {
             $namespaceTables .= Xml::tags('tr', null, $rows[$j]);
         }
         $namespaceTables .= Xml::closeElement('table');
     }
     // Show redirects check only if backend supports it
     $redirects = '';
     if ($this->searchEngine->acceptListRedirects()) {
         $redirects = Xml::check('redirs', $this->searchRedirects, array('value' => '1', 'id' => 'redirs')) . ' ' . Xml::label(wfMsg('powersearch-redir'), 'redirs');
     }
     // Return final output
     return Xml::openElement('fieldset', array('id' => 'mw-searchoptions', 'style' => 'margin:0em;')) . Xml::element('legend', null, wfMsg('powersearch-legend')) . Xml::tags('h4', null, wfMsgExt('powersearch-ns', array('parseinline'))) . Xml::tags('div', array('id' => 'mw-search-togglebox'), Xml::label(wfMsg('powersearch-togglelabel'), 'mw-search-togglelabel') . Xml::element('input', array('type' => 'button', 'id' => 'mw-search-toggleall', 'onclick' => 'mwToggleSearchCheckboxes("all");', 'value' => wfMsg('powersearch-toggleall'))) . Xml::element('input', array('type' => 'button', 'id' => 'mw-search-togglenone', 'onclick' => 'mwToggleSearchCheckboxes("none");', 'value' => wfMsg('powersearch-togglenone')))) . Xml::element('div', array('class' => 'divider'), '', false) . $namespaceTables . Xml::element('div', array('class' => 'divider'), '', false) . $redirects . Xml::hidden('title', SpecialPage::getTitleFor('Search')->getPrefixedText()) . Xml::hidden('advanced', $this->searchAdvanced) . Xml::hidden('fulltext', 'Advanced search') . Xml::closeElement('fieldset');
 }
예제 #29
0
 /**
  * Hook handler
  *
  * @static
  * @param Title $title
  * @param User $user
  * @param $action
  * @param $result
  * @return bool
  */
 public static function userCan($title, $user, $action, &$result)
 {
     $namespace = $title->getNamespace();
     // we only care if this is a talk namespace
     if (MWNamespace::getSubject($namespace) == $namespace) {
         return true;
     }
     //for blog comments BlogLockdown is checking rights
     if (ArticleComment::isBlog()) {
         return true;
     }
     $parts = ArticleComment::explode($title->getText());
     //not article comment
     if (count($parts['partsStripped']) == 0) {
         return true;
     }
     $firstRev = $title->getFirstRevision();
     if ($firstRev && $user->getName() == $firstRev->getUserText()) {
         return true;
     }
     switch ($action) {
         case 'move':
         case 'move-target':
             return $user->isAllowed('commentmove');
             break;
         case 'edit':
             return $user->isAllowed('commentedit');
             break;
         case 'delete':
             return $user->isAllowed('commentdelete');
             break;
     }
     return true;
 }
예제 #30
0
 /**
  * Same as addWatch, only the opposite.
  * @return bool
  */
 public function removeWatch()
 {
     // Only loggedin user can have a watchlist
     if (wfReadOnly() || $this->mUser->isAnon()) {
         return false;
     }
     $success = false;
     $dbw = wfGetDB(DB_MASTER);
     $dbw->delete('watchlist', array('wl_user' => $this->userID, 'wl_namespace' => MWNamespace::getSubject($this->nameSpace), 'wl_title' => $this->databaseKey), __METHOD__);
     if ($dbw->affectedRows()) {
         $success = true;
     }
     # the following code compensates the new behaviour, introduced by the
     # enotif patch, that every single watched page needs now to be listed
     # in watchlist namespace:page and namespace_talk:page had separate
     # entries: clear them
     $dbw->delete('watchlist', array('wl_user' => $this->userID, 'wl_namespace' => MWNamespace::getTalk($this->nameSpace), 'wl_title' => $this->databaseKey), __METHOD__);
     // No errors, update the global_watchlist table.
     if ($dbw->affectedRows()) {
         wfRunHooks('WatchedItem::updateWatch', array($this, $this->userID));
     }
     return $success;
 }