Ejemplo n.º 1
0
 /**
  * @covers lw_getTitle
  */
 public function test_lw_getTitle()
 {
     $this->assertEquals(lw_getTitle("the who:baba o'riley"), "The_Who:Baba_O'Riley", "Capitalize the R in Irish stuff like O'Riley");
     $this->assertEquals(lw_getTitle("the who:i'm cool"), "The_Who:I'm_Cool", "Don't capitalize the m in I'm");
     $this->assertEquals(lw_getTitle("the who:don't"), "The_Who:Don't", "Don't capitalize the t in Don't");
     $this->assertEquals(lw_getTitle("the who:cant skip apostrophes"), "The_Who:Can't_Skip_Apostrophes", "Automatically contracting 'cant'");
 }
Ejemplo n.º 2
0
function wfImpliedRedirects_articleFromTitle(Title &$title, &$article)
{
    // We only want to mess with titles for pages that don't already exist.
    if (!$title->exists() && $title->getNamespace() == NS_MAIN) {
        $origTitle = $title->getDBkey();
        // this format has the characters as we need them already
        // If there is more than one colon, the vast majority of the time it seems to be in the name of the song rather than the artist so we
        // use strpos instead of strrpos (this query was used to create this assumption: "SELECT page_title FROM wiki_page WHERE page_title LIKE '%:%:%'").
        $index = mb_strpos($origTitle, ":");
        if ($index !== false) {
            $artist = mb_substr($origTitle, 0, $index);
            $song = mb_substr($origTitle, $index + 1);
            // Borrow functions from the SOAP
            define('LYRICWIKI_SOAP_FUNCS_ONLY', true);
            // so we can borrow functions from server.php w/o initializing a SOAP request.
            $debug = false;
            global $IP;
            include_once $IP . '/extensions/3rdparty/LyricWiki/server.php';
            // If the artist has a redirect on their own page, that generally means that all songs belong to that finalized name...
            // so try to grab the song using that version of the artist's name.
            $artistTitle = lw_getTitle($artist);
            // leaves the original version in tact
            $finalName = $artistTitle;
            $page = lw_getPage($artistTitle, $finalName, $debug);
            print !$debug ? "" : "found:\n{$page}";
            if ($finalName != $artistTitle) {
                print !$debug ? "" : "Artist redirect found to \"{$finalName}\". Applying to song \"{$song}\".\n";
            }
            $titleStr = utf8_decode(lw_getTitle($finalName, $song));
            // decode is used to prevent double-encode calls that would otherwise happen.  I'm skeptical as to whether this would always work (assuming the special char was in the original title instead of the redirected artist as tested).
            print !$debug ? "" : "Title \"{$titleStr}\"\n";
            // If the song was still not found... chop off any trailing parentheses and try again. - SWC 20070101
            if (!lw_pageExists($titleStr)) {
                print !$debug ? "" : "{$titleStr} not found.\n";
                $finalSong = preg_replace("/\\s*\\(.*\$/", "", $song);
                if ($song != $finalSong) {
                    $titleStr = lw_getTitle($finalName, $finalSong);
                    print !$debug ? "" : "Looking without parentheses for \"{$titleStr}\"\n";
                }
            } else {
                print !$debug ? "" : "{$titleStr} found.\n";
            }
            // We successfully found a page using implied redirects... change this request around.
            if ($titleStr != $origTitle) {
                if (!class_exists('LW_ImpliedRedirect')) {
                    // TODO: move to a separate file
                    class LW_ImpliedRedirect extends Article
                    {
                        var $mTarget;
                        function __construct($source, $target)
                        {
                            Article::__construct($source);
                            $this->mTarget = $target;
                            $this->mIsRedirect = true;
                        }
                        function followRedirect()
                        {
                            return $this->mTarget;
                        }
                        function loadPageData($data = 'fromdb')
                        {
                            Article::loadPageData($data);
                            $this->mIsRedirect = true;
                        }
                        // since we're certain the target exists, we might as well say so
                        // this fools Our404Handler into following the redirect
                        function exists()
                        {
                            return true;
                        }
                    }
                }
                $target = Title::newFromDBkey($titleStr);
                if ($target && $target->exists()) {
                    $article = new LW_ImpliedRedirect($title, $target);
                    //trigger redirect to implied page.
                }
            }
        }
    }
    return true;
}
Ejemplo n.º 3
0
function lw_tracksToWiki($artistName, $songs)
{
    $retVal = "";
    if (is_array($songs) && count($songs) > 0) {
        foreach ($songs as $currSong) {
            // If no artist is specified, default to the artist who makes the album.
            // This makes most cases easy and allows overriding of artist for compilations, etc.
            if (false === strpos($currSong, ":")) {
                $currSong = lw_getTitle($artistName, $currSong);
            }
            $justSong = $currSong;
            if ($index = strrpos($currSong, ":")) {
                $justSong = substr($currSong, $index + 1);
            }
            $justSong = lw_fmtSong($justSong);
            $retVal .= "# '''[[{$currSong}|{$justSong}]]'''\n";
        }
    }
    return $retVal;
}